Ejemplo n.º 1
0
func (self flowTableFeature) exportProps() []byte {
	var props []byte

	instExport := func(pType uint16, keys []instructionKey) {
		if keys == nil {
			return
		}
		var ids []byte
		for _, key := range keys {
			switch k := key.(type) {
			case uint16:
				ids = append(ids, ofp4.MakeInstruction(k)...)
			case uint32:
				ids = append(ids, ofp4.MakeInstructionExperimenter(k)...)
			default:
				panic("unexpected instruction key type")
			}
		}
		props = append(props, ofp4.MakeTableFeaturePropInstructions(pType, ids)...)
	}
	instExport(ofp4.OFPTFPT_INSTRUCTIONS, self.hit.inst)
	instExport(ofp4.OFPTFPT_INSTRUCTIONS_MISS, self.miss.inst)

	oxmExport := func(pType uint16, keys []oxmId) {
		if keys == nil {
			return
		}
		var ids []byte
		for _, key := range keys {
			switch k := key.(type) {
			case uint32:
				ids = append(ids, ofp4.MakeOxm(k)...)
			case [2]uint32:
				ids = append(ids, ofp4.MakeOxmExperimenterHeader(k)...)
			default:
				panic("unknown oxm key")
			}
		}
		props = append(props, ofp4.MakeTableFeaturePropOxm(pType, ids)...)
	}
	oxmExport(ofp4.OFPTFPT_MATCH, self.match)
	oxmExport(ofp4.OFPTFPT_WILDCARDS, self.wildcards)
	oxmExport(ofp4.OFPTFPT_WRITE_SETFIELD, self.hit.writeSetfield)
	oxmExport(ofp4.OFPTFPT_WRITE_SETFIELD_MISS, self.miss.writeSetfield)
	oxmExport(ofp4.OFPTFPT_APPLY_SETFIELD, self.hit.applySetfield)
	oxmExport(ofp4.OFPTFPT_APPLY_SETFIELD_MISS, self.miss.applySetfield)

	nextExport := func(pType uint16, keys []uint8) {
		if keys == nil {
			return
		}
		props = append(props, ofp4.MakeTableFeaturePropNextTables(pType, keys)...)
	}
	nextExport(ofp4.OFPTFPT_NEXT_TABLES, self.hit.next)
	nextExport(ofp4.OFPTFPT_NEXT_TABLES_MISS, self.miss.next)

	actionExport := func(pType uint16, keys []actionKey) {
		if keys == nil {
			return
		}
		var ids []byte
		for _, key := range keys {
			switch k := key.(type) {
			case uint16:
				ids = append(ids, ofp4.MakeActionHeader(k)...)
			case uint32:
				ids = append(ids, ofp4.MakeActionExperimenterHeader(k)...)
			default:
				panic("unexpected action key type")
			}
		}
		props = append(props, ofp4.MakeTableFeaturePropActions(pType, ids)...)
	}
	actionExport(ofp4.OFPTFPT_WRITE_ACTIONS, self.hit.writeActions)
	actionExport(ofp4.OFPTFPT_WRITE_ACTIONS_MISS, self.miss.writeActions)
	actionExport(ofp4.OFPTFPT_APPLY_ACTIONS, self.hit.applyActions)
	actionExport(ofp4.OFPTFPT_APPLY_ACTIONS_MISS, self.miss.applyActions)

	experimenterExport := func(pType uint16, exps []experimenterProp) {
		for _, exp := range exps {
			props = append(props, ofp4.MakeTableFeaturePropExperimenter(pType, exp.Experimenter, exp.ExpType, exp.Data)...)
		}
	}
	experimenterExport(ofp4.OFPTFPT_EXPERIMENTER, self.hit.experimenter)
	experimenterExport(ofp4.OFPTFPT_EXPERIMENTER_MISS, self.miss.experimenter)

	return props
}
Ejemplo n.º 2
0
func (self actionExperimenter) MarshalBinary() ([]byte, error) {
	return ofp4.ActionExperimenterHeader(ofp4.MakeActionExperimenterHeader(self.Experimenter)).AppendData(self.Data), nil
}