示例#1
0
// CreateBitset initializes a bit set with 2^numBitsWide bits
func CreateBitset(numBitsWide uint) *bitset.BitSet {
	maxSize := 1 << numBitsWide
	return bitset.New(uint(maxSize))
}
示例#2
0
	VlanRsrcAllocateID        = "VlanRsrcAllocateID"
	VlanRsrcAllocateExhaustID = "VlanRsrcAllocateExhaustID"
	VlanRsrcDeallocateID      = "VlanRsrcDeallocateID"
	VlanRsrcGetListID         = "VlanRsrcGetListID"

	vLANResourceOperWrite = iota
	vLANResourceOperRead
	vLANResourceOperClear
)

var vlanRsrcValidationStateMap = map[string]*vlanRsrcValidator{
	VlanRsrcValidInitID: {
		expCfg: []AutoVLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidInitID},
				VLANs:       bitset.New(1).Set(1),
			},
		},
		expOper: []AutoVLANOperResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidInitID},
				FreeVLANs:   bitset.New(1).Set(1),
			},
		},
	},
	VlanRsrcValidDeinitID: {
		expCfg: []AutoVLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidDeinitID},
				VLANs:       bitset.New(1).Set(0),
			},
	VXLANRsrcAllocateExhaustVXLANID = "VXLANRsrcAllocateExhaustVXLANID"
	VXLANRsrcAllocateExhaustVLANID  = "VXLANRsrcAllocateExhaustVLANID"
	VXLANRsrcDeallocateID           = "VXLANRsrcDeallocateID"
	VXLANRsrcGetListID              = "VXLANRsrcGetListID"

	vXLANResourceOpWrite = iota
	vXLANResourceOpRead
	vXLANResourceOpClear
)

var vxlanRsrcValidationStateMap = map[string]*vxlanRsrcValidator{
	VXLANRsrcValidInitID: &vxlanRsrcValidator{
		expCfg: []AutoVXLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VXLANRsrcValidInitID},
				VXLANs:      bitset.New(1).Set(0),
				LocalVLANs:  bitset.New(1).Set(0),
			},
		},
		expOper: []AutoVXLANOperResource{
			{
				CommonState:    core.CommonState{StateDriver: nil, ID: VXLANRsrcValidInitID},
				FreeVXLANs:     bitset.New(1).Set(0),
				FreeLocalVLANs: bitset.New(1).Set(0),
			},
		},
	},
	VXLANRsrcValidDeinitID: &vxlanRsrcValidator{
		expCfg: []AutoVXLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VXLANRsrcValidDeinitID},
示例#4
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.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
}
	VXLANRsrcAllocateID             = "VXLANRsrcAllocateID"
	VXLANRsrcAllocateExhaustVXLANID = "VXLANRsrcAllocateExhaustVXLANID"
	VXLANRsrcAllocateExhaustVLANID  = "VXLANRsrcAllocateExhaustVLANID"
	VXLANRsrcDeallocateID           = "VXLANRsrcDeallocateID"

	vXLANResourceOpWrite = iota
	vXLANResourceOpRead
	vXLANResourceOpClear
)

var vxlanRsrcValidationStateMap = map[string]*vxlanRsrcValidator{
	VXLANRsrcValidInitID: &vxlanRsrcValidator{
		expCfg: []AutoVXLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VXLANRsrcValidInitID},
				VXLANs:      bitset.New(1).Set(0),
				LocalVLANs:  bitset.New(1).Set(0),
			},
		},
		expOper: []AutoVXLANOperResource{
			{
				CommonState:    core.CommonState{StateDriver: nil, ID: VXLANRsrcValidInitID},
				FreeVXLANs:     bitset.New(1).Set(0),
				FreeLocalVLANs: bitset.New(1).Set(0),
			},
		},
	},
	VXLANRsrcValidDeinitID: &vxlanRsrcValidator{
		expCfg: []AutoVXLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VXLANRsrcValidDeinitID},
示例#6
0
	VlanRsrcValidDeinitID     = "VlanRsrcValidDeinitID"
	VlanRsrcAllocateID        = "VlanRsrcAllocateID"
	VlanRsrcAllocateExhaustID = "VlanRsrcAllocateExhaustID"
	VlanRsrcDeallocateID      = "VlanRsrcDeallocateID"

	vLANResourceOperWrite = iota
	vLANResourceOperRead
	vLANResourceOperClear
)

var vlanRsrcValidationStateMap = map[string]*vlanRsrcValidator{
	VlanRsrcValidInitID: &vlanRsrcValidator{
		expCfg: []AutoVLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidInitID},
				VLANs:       bitset.New(1).Set(1),
			},
		},
		expOper: []AutoVLANOperResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidInitID},
				FreeVLANs:   bitset.New(1).Set(1),
			},
		},
	},
	VlanRsrcValidDeinitID: &vlanRsrcValidator{
		expCfg: []AutoVLANCfgResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: VlanRsrcValidDeinitID},
				VLANs:       bitset.New(1).Set(0),
			},
)

var subnetRsrcValidationStateMap = map[string]*subnetRsrcValidator{
	SubnetRsrcValidInitID: &subnetRsrcValidator{
		expCfg: []AutoSubnetCfgResource{
			{
				CommonState:    core.CommonState{StateDriver: nil, ID: SubnetRsrcValidInitID},
				SubnetPool:     net.ParseIP("1.2.3.4"),
				SubnetPoolLen:  24,
				AllocSubnetLen: 24,
			},
		},
		expOper: []AutoSubnetOperResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: SubnetRsrcValidInitID},
				FreeSubnets: bitset.New(1).Set(0),
			},
		},
	},
	SubnetRsrcValidDeinitID: &subnetRsrcValidator{
		expCfg: []AutoSubnetCfgResource{
			{
				CommonState:    core.CommonState{StateDriver: nil, ID: SubnetRsrcValidDeinitID},
				SubnetPool:     net.ParseIP("1.2.3.4"),
				SubnetPoolLen:  24,
				AllocSubnetLen: 24,
			},
		},
		expOper: []AutoSubnetOperResource{
			{
				CommonState: core.CommonState{StateDriver: nil, ID: SubnetRsrcValidDeinitID},