Ejemplo n.º 1
0
// Delete the flow
func (self *Flow) Delete() error {
	// Delete from ofswitch
	if self.isInstalled {
		// Create a flowmode entry
		flowMod := openflow13.NewFlowMod()
		flowMod.Command = openflow13.FC_DELETE
		flowMod.TableId = self.Table.TableId
		flowMod.Priority = self.Match.Priority
		flowMod.Cookie = self.flowId
		flowMod.CookieMask = 0xffffffffffffffff
		flowMod.OutPort = openflow13.P_ANY
		flowMod.OutGroup = openflow13.OFPG_ANY

		log.Debugf("Sending DELETE flowmod: %+v", flowMod)

		// Send the message
		self.Table.Switch.Send(flowMod)
	}

	// Delete it from the table
	flowKey := self.flowKey()
	self.Table.DeleteFlow(flowKey)

	return nil
}
Ejemplo n.º 2
0
// Install a flow entry
func (self *Flow) install() error {
	// Create a flowmode entry
	flowMod := openflow13.NewFlowMod()
	flowMod.TableId = self.Table.TableId
	flowMod.Priority = self.Match.Priority
	flowMod.Cookie = self.flowId

	// Add or modify
	if !self.isInstalled {
		flowMod.Command = openflow13.FC_ADD
	} else {
		flowMod.Command = openflow13.FC_MODIFY
	}

	// convert match fields to openflow 1.3 format
	flowMod.Match = self.xlateMatch()
	log.Debugf("flow install: Match: %+v", flowMod.Match)

	// Based on the next elem, decide what to install
	switch self.NextElem.Type() {
	case "table":
		// Get the instruction set from the element
		instr := self.NextElem.GetFlowInstr()

		// Check if there are any flow actions to perform
		self.installFlowActions(flowMod, instr)

		// Add the instruction to flowmod
		flowMod.AddInstruction(instr)

		log.Debugf("flow install: added goto table instr: %+v", instr)

	case "flood":
		fallthrough
	case "output":
		// Get the instruction set from the element
		instr := self.NextElem.GetFlowInstr()

		// Add the instruction to flowmod if its not nil
		// a nil instruction means drop action
		if instr != nil {

			// Check if there are any flow actions to perform
			self.installFlowActions(flowMod, instr)

			flowMod.AddInstruction(instr)

			log.Debugf("flow install: added output port instr: %+v", instr)
		}
	default:
		log.Fatalf("Unknown Fgraph element type %s", self.NextElem.Type())
	}

	log.Debugf("Sending flowmod: %+v", flowMod)

	// Send the message
	self.Table.Switch.Send(flowMod)

	// Mark it as installed
	self.isInstalled = true

	return nil
}