Esempio n. 1
0
/*  routerInfo[0] -> Uplink nexthop interface
 */
func NewOfnetAgent(bridgeName string, dpName string, localIp net.IP, rpcPort uint16,
	ovsPort uint16, routerInfo ...string) (*OfnetAgent, error) {
	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 = make(map[string]*OfnetEndpoint)
	agent.localEndpointDb = make(map[uint32]*OfnetEndpoint)

	// Create an openflow controller
	agent.ctrler = ofctrl.NewController(agent)

	// Start listening to controller port
	go agent.ctrler.Listen(fmt.Sprintf(":%d", ovsPort))

	// 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)
	case "vxlan":
		agent.datapath = NewVxlan(agent, rpcServ)
	case "vlan":
		agent.datapath = NewVlanBridge(agent, rpcServ)
	case "vlrouter":
		agent.datapath = NewVlrouter(agent, rpcServ)
		agent.ovsDriver = ovsdbDriver.NewOvsDriver(bridgeName)
		agent.protopath = NewOfnetBgp(agent, routerInfo)

	default:
		log.Fatalf("Unknown Datapath %s", dpName)
	}

	// Return it
	return agent, nil
}
Esempio n. 2
0
// Create new Ofnet master
func NewOfnetMaster(portNo uint16) *OfnetMaster {
	// Create the master
	master := new(OfnetMaster)

	// Init params
	master.agentDb = make(map[string]*OfnetNode)
	master.endpointDb = make(map[string]*OfnetEndpoint)
	master.policyDb = make(map[string]*OfnetPolicyRule)

	// Create a new RPC server
	master.rpcServer, master.rpcListener = rpcHub.NewRpcServer(portNo)

	// Register RPC handler
	err := master.rpcServer.Register(master)
	if err != nil {
		log.Fatalf("Error Registering RPC callbacks. Err: %v", err)
		return nil
	}

	return master
}
Esempio n. 3
0
/*  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.arpMode = ArpProxy

	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
}