示例#1
0
// Initialize the fgraph elements on the switch
func (self *OFSwitch) initFgraph() error {
	// Create the DBs
	self.tableDb = make(map[uint8]*Table)
	self.outputPorts = make(map[uint32]*Output)

	// Create the table 0
	table := new(Table)
	table.Switch = self
	table.TableId = 0
	table.flowDb = make(map[string]*Flow)
	self.tableDb[0] = table

	// Create drop action
	dropAction := new(Output)
	dropAction.outputType = "drop"
	dropAction.portNo = openflow13.P_ANY
	self.dropAction = dropAction

	// create send to controller action
	sendToCtrler := new(Output)
	sendToCtrler.outputType = "toController"
	sendToCtrler.portNo = openflow13.P_CONTROLLER
	self.sendToCtrler = sendToCtrler

	// Clear all existing flood lists
	groupMod := openflow13.NewGroupMod()
	groupMod.GroupId = openflow13.OFPG_ALL
	groupMod.Command = openflow13.OFPGC_DELETE
	groupMod.Type = openflow13.OFPGT_ALL
	self.Send(groupMod)

	return nil
}
// Install a group entry in OF switch
func (self *Flood) install() error {
	groupMod := openflow13.NewGroupMod()
	groupMod.GroupId = self.GroupId

	// Change the OP to modify if it was already installed
	if self.isInstalled {
		groupMod.Command = openflow13.OFPGC_MODIFY
	}

	// OF type for flood list
	groupMod.Type = openflow13.OFPGT_ALL

	// Loop thru all output ports and add it to group bucket
	for _, output := range self.FloodList {
		// Get the output action from output entry
		act := output.outPort.GetOutAction()
		if act != nil {
			// Create a new bucket for each port
			bkt := openflow13.NewBucket()

			// Set tunnel Id if required
			if output.isTunnel {
				tunnelField := openflow13.NewTunnelIdField(output.tunnelId)
				setTunnel := openflow13.NewActionSetField(*tunnelField)
				bkt.AddAction(setTunnel)
			}

			// Always remove vlan tag
			popVlan := openflow13.NewActionPopVlan()
			bkt.AddAction(popVlan)

			// Add the output action to the bucket
			bkt.AddAction(act)

			// Add the bucket to group
			groupMod.AddBucket(*bkt)
		}
	}

	log.Infof("Installing Group entry: %+v", groupMod)

	// Send it to the switch
	self.Switch.Send(groupMod)

	// Mark it as installed
	self.isInstalled = true

	return nil
}
// Delete a flood list
func (self *Flood) Delete() error {
	// Remove it from OVS if its installed
	if self.isInstalled {
		groupMod := openflow13.NewGroupMod()
		groupMod.GroupId = self.GroupId
		groupMod.Command = openflow13.OFPGC_DELETE

		log.Infof("Deleting Group entry: %+v", groupMod)

		// Send it to the switch
		self.Switch.Send(groupMod)
	}

	return nil
}