示例#1
0
文件: action.go 项目: hkwi/gopenflow
func (self *actionList) UnmarshalBinary(data []byte) error {
	var actions []action
	for _, msg := range ofp4.ActionHeader(data).Iter() {
		var act action
		switch msg.Type() {
		default:
			return errors.New("unknown ofp4.Action type")
		case ofp4.OFPAT_COPY_TTL_OUT,
			ofp4.OFPAT_COPY_TTL_IN,
			ofp4.OFPAT_DEC_MPLS_TTL,
			ofp4.OFPAT_POP_VLAN,
			ofp4.OFPAT_DEC_NW_TTL,
			ofp4.OFPAT_POP_PBB:
			act = actionGeneric{
				Type: msg.Type(),
			}
		case ofp4.OFPAT_OUTPUT:
			a := ofp4.ActionOutput(msg)
			act = actionOutput{
				Port:   a.Port(),
				MaxLen: a.MaxLen(),
			}
		case ofp4.OFPAT_SET_MPLS_TTL:
			act = actionMplsTtl{
				MplsTtl: ofp4.ActionMplsTtl(msg).MplsTtl(),
			}
		case ofp4.OFPAT_PUSH_VLAN,
			ofp4.OFPAT_PUSH_MPLS,
			ofp4.OFPAT_PUSH_PBB:
			act = actionPush{
				Type:      msg.Type(),
				Ethertype: ofp4.ActionPush(msg).Ethertype(),
			}
		case ofp4.OFPAT_POP_MPLS:
			act = actionPopMpls{
				Ethertype: ofp4.ActionPopMpls(msg).Ethertype(),
			}
		case ofp4.OFPAT_SET_QUEUE:
			act = actionSetQueue{
				QueueId: ofp4.ActionSetQueue(msg).QueueId(),
			}
		case ofp4.OFPAT_GROUP:
			act = actionGroup{
				GroupId: ofp4.ActionGroup(msg).GroupId(),
			}
		case ofp4.OFPAT_SET_NW_TTL:
			act = actionNwTtl{
				NwTtl: ofp4.ActionNwTtl(msg).NwTtl(),
			}
		case ofp4.OFPAT_SET_FIELD:
			f := ofp4.ActionSetField(msg).Field()
			act = actionSetField{
				Field: f[:f.Header().Length()+4],
			}
		case ofp4.OFPAT_EXPERIMENTER:
			a := ofp4.ActionExperimenterHeader(msg)
			if handler, ok := actionHandlers[a.Experimenter()]; ok {
				act = actionExperimenter{
					Experimenter: a.Experimenter(),
					Data:         msg[8:],
					Handler:      handler,
				}
			} else {
				return ofp4.MakeErrorMsg(
					ofp4.OFPET_BAD_ACTION,
					ofp4.OFPBAC_BAD_EXPERIMENTER,
				)
			}
		}
		actions = append(actions, act)
	}
	*self = actions
	return nil
}
示例#2
0
func (self *flowTableFeature) importProps(props ofp4.TableFeaturePropHeader) error {
	for _, prop := range props.Iter() {
		switch prop.Type() {
		case ofp4.OFPTFPT_INSTRUCTIONS, ofp4.OFPTFPT_INSTRUCTIONS_MISS:
			var ids []instructionKey
			for _, inst := range ofp4.TableFeaturePropInstructions(prop).InstructionIds().Iter() {
				if inst.Type() == ofp4.OFPIT_EXPERIMENTER {
					ids = append(ids, ofp4.InstructionExperimenter(inst).Experimenter())
				} else {
					ids = append(ids, inst.Type())
				}
			}
			switch prop.Type() {
			case ofp4.OFPTFPT_INSTRUCTIONS:
				self.hit.inst = ids
			case ofp4.OFPTFPT_INSTRUCTIONS_MISS:
				self.miss.inst = ids
			}
		case ofp4.OFPTFPT_NEXT_TABLES:
			self.hit.next = ofp4.TableFeaturePropNextTables(prop).NextTableIds()
		case ofp4.OFPTFPT_NEXT_TABLES_MISS:
			self.miss.next = ofp4.TableFeaturePropNextTables(prop).NextTableIds()
		case ofp4.OFPTFPT_WRITE_ACTIONS, ofp4.OFPTFPT_WRITE_ACTIONS_MISS,
			ofp4.OFPTFPT_APPLY_ACTIONS, ofp4.OFPTFPT_APPLY_ACTIONS_MISS:
			var ids []actionKey
			for _, act := range ofp4.TableFeaturePropActions(prop).ActionIds().Iter() {
				if act.Type() == ofp4.OFPAT_EXPERIMENTER {
					ids = append(ids, ofp4.ActionExperimenterHeader(act).Experimenter())
				} else {
					ids = append(ids, act.Type())
				}
			}
			switch prop.Type() {
			case ofp4.OFPTFPT_WRITE_ACTIONS:
				self.hit.writeActions = ids
			case ofp4.OFPTFPT_WRITE_ACTIONS_MISS:
				self.miss.writeActions = ids
			case ofp4.OFPTFPT_APPLY_ACTIONS:
				self.hit.applyActions = ids
			case ofp4.OFPTFPT_APPLY_ACTIONS_MISS:
				self.miss.applyActions = ids
			}
		case ofp4.OFPTFPT_MATCH, ofp4.OFPTFPT_WILDCARDS,
			ofp4.OFPTFPT_WRITE_SETFIELD, ofp4.OFPTFPT_WRITE_SETFIELD_MISS,
			ofp4.OFPTFPT_APPLY_SETFIELD, ofp4.OFPTFPT_APPLY_SETFIELD_MISS:
			var ids []oxmId
			for _, oxm := range ofp4.TableFeaturePropOxm(prop).OxmIds().Iter() {
				hdr := oxm.Header()
				if hdr.Class() == ofp4.OFPXMC_EXPERIMENTER {
					exp := ofp4.OxmExperimenterHeader(oxm).Experimenter()
					ids = append(ids, [...]uint32{oxmHandlers[exp].OxmId(uint32(oxm.Header())), exp})
				} else {
					ids = append(ids, hdr.Type())
				}
			}
			switch prop.Type() {
			case ofp4.OFPTFPT_MATCH:
				self.match = ids
			case ofp4.OFPTFPT_WILDCARDS:
				self.wildcards = ids
			case ofp4.OFPTFPT_WRITE_SETFIELD:
				self.hit.writeSetfield = ids
			case ofp4.OFPTFPT_WRITE_SETFIELD_MISS:
				self.miss.writeSetfield = ids
			case ofp4.OFPTFPT_APPLY_SETFIELD:
				self.hit.applySetfield = ids
			case ofp4.OFPTFPT_APPLY_SETFIELD_MISS:
				self.miss.applySetfield = ids
			}
		case ofp4.OFPTFPT_EXPERIMENTER, ofp4.OFPTFPT_EXPERIMENTER_MISS:
			msg := ofp4.TableFeaturePropExperimenter(prop)
			eKey := experimenterKey{
				Experimenter: msg.Experimenter(),
				ExpType:      msg.ExpType(),
			}
			if _, ok := tableHandlers[eKey]; !ok {
				return ofp4.MakeErrorMsg(
					ofp4.OFPET_TABLE_FEATURES_FAILED,
					ofp4.OFPTFFC_BAD_ARGUMENT,
				)
			}
			exp := experimenterProp{
				experimenterKey: eKey,
				Data:            msg.ExperimenterData(),
			}
			switch prop.Type() {
			case ofp4.OFPTFPT_EXPERIMENTER:
				self.hit.experimenter = append(self.hit.experimenter, exp)
			case ofp4.OFPTFPT_EXPERIMENTER_MISS:
				self.miss.experimenter = append(self.hit.experimenter, exp)
			}
		}
	}
	return nil
}
示例#3
0
文件: action.go 项目: hkwi/gopenflow
func (self actionExperimenter) MarshalBinary() ([]byte, error) {
	return ofp4.ActionExperimenterHeader(ofp4.MakeActionExperimenterHeader(self.Experimenter)).AppendData(self.Data), nil
}