//NewSync initialize new etcd sync func NewSync(etcdServers []string) *Sync { sync := &Sync{locks: cmap.New()} sync.etcdClient = etcd.NewClient(etcdServers) hostname, _ := os.Hostname() sync.processID = hostname + uuid.NewV4().String() return sync }
// Create a new vlrouter instance func NewVlrouter(agent *OfnetAgent, rpcServ *rpc.Server) *Vlrouter { vlrouter := new(Vlrouter) // Keep a reference to the agent vlrouter.agent = agent // Create policy agent vlrouter.policyAgent = NewPolicyAgent(agent, rpcServ) // Create a flow dbs and my router mac vlrouter.flowDb = make(map[string]*ofctrl.Flow) vlrouter.portVlanFlowDb = make(map[uint32]*ofctrl.Flow) vlrouter.myRouterMac, _ = net.ParseMAC("00:00:11:11:11:11") vlrouter.unresolvedEPs = cmap.New() return vlrouter }
//NewSync initialize new etcd sync func NewSync(etcdServers []string, timeout time.Duration) (*Sync, error) { sync := &Sync{ locks: cmap.New(), timeout: timeout, } client, err := etcd.New( etcd.Config{ Endpoints: etcdServers, DialTimeout: timeout, }, ) if err != nil { return nil, err } sync.etcdClient = client hostname, _ := os.Hostname() sync.processID = hostname + uuid.NewV4().String() return sync, nil }
package rtmp import ( "flag" "github.com/sdming/gosnow" cmap "github.com/streamrail/concurrent-map" "github.com/yingtu/bbllive/util" "net" "runtime" "sync" "time" ) var ( objects = cmap.New() log *util.FileLogger shandler ServerHandler = new(DefaultServerHandler) logfile string level int snow *gosnow.SnowFlake srvid int ) func init() { flag.StringVar(&logfile, "log", "stdout", "-log rtmp.log") flag.IntVar(&level, "level", 1, "-level 1") flag.IntVar(&srvid, "srvid", 1, "-srvid 1") } func ListenAndServe(addr string) error { logger, err := util.NewFileLogger("", logfile, level) if err != nil {
/* routerInfo[0] -> Uplink nexthop interface */ func NewOfnetAgent(bridgeName string, dpName string, localIp net.IP, rpcPort uint16, ovsPort uint16, routerInfo ...string) (*OfnetAgent, error) { log.Infof("Creating new ofnet agent for %s,%s,%d,%d,%d,%v \n", bridgeName, dpName, localIp, rpcPort, ovsPort, routerInfo) agent := new(OfnetAgent) // Init params agent.localIp = localIp agent.MyPort = rpcPort agent.MyAddr = localIp.String() agent.dpName = dpName agent.masterDb = make(map[string]*OfnetNode) agent.portVlanMap = make(map[uint32]*uint16) agent.vniVlanMap = make(map[uint32]*uint16) agent.vlanVniMap = make(map[uint16]*uint32) // Initialize vtep database agent.vtepTable = make(map[string]*uint32) // Initialize endpoint database agent.endpointDb = cmap.New() agent.localEndpointDb = cmap.New() // Initialize vrf database agent.vrfDb = make(map[string]*OfnetVrfInfo) agent.vrfIdNameMap = make(map[uint16]*string) agent.vrfNameIdMap = make(map[string]*uint16) agent.vrfIdBmp = bitset.New(256) agent.vlanVrf = make(map[uint16]*string) // stats db agent.stats = make(map[string]uint64) agent.errStats = make(map[string]uint64) // Create an openflow controller agent.ctrler = ofctrl.NewController(agent) // FIXME: Figure out how to handle multiple OVS bridges. rpcServ, listener := rpcHub.NewRpcServer(rpcPort) agent.rpcServ = rpcServ agent.rpcListener = listener // Register for Master add/remove events rpcServ.Register(agent) // Create the datapath switch dpName { case "vrouter": agent.datapath = NewVrouter(agent, rpcServ) agent.fwdMode = "routing" case "vxlan": agent.datapath = NewVxlan(agent, rpcServ) agent.fwdMode = "bridge" case "vlan": agent.datapath = NewVlanBridge(agent, rpcServ) agent.fwdMode = "bridge" case "vlrouter": agent.datapath = NewVlrouter(agent, rpcServ) agent.fwdMode = "routing" agent.ovsDriver = ovsdbDriver.NewOvsDriver(bridgeName) agent.protopath = NewOfnetBgp(agent, routerInfo) default: log.Fatalf("Unknown Datapath %s", dpName) } // Start listening to controller port go agent.ctrler.Listen(fmt.Sprintf(":%d", ovsPort)) // Return it return agent, nil }
func init() { switchDb = cmap.New() }