コード例 #1
0
ファイル: multipart.go プロジェクト: jojimt/netplugin
func (s *MultipartRequest) UnmarshalBinary(data []byte) error {
	err := s.Header.UnmarshalBinary(data)
	n := s.Header.Len()

	s.Type = binary.BigEndian.Uint16(data[n:])
	n += 2
	s.Flags = binary.BigEndian.Uint16(data[n:])
	n += 2
	n += 4 // for padding

	var req util.Message
	switch s.Type {
	case MultipartType_Aggregate:
		req = s.Body.(*AggregateStatsRequest)
		err = req.UnmarshalBinary(data[n:])
	case MultipartType_Desc:
		break
	case MultipartType_Flow:
		req = s.Body.(*FlowStatsRequest)
		err = req.UnmarshalBinary(data[n:])
	case MultipartType_Port:
		req = s.Body.(*PortStatsRequest)
		err = req.UnmarshalBinary(data[n:])
	case MultipartType_Table:
		break
	case MultipartType_Queue:
		req = s.Body.(*QueueStatsRequest)
		err = req.UnmarshalBinary(data[n:])
	case MultipartType_Experimenter:
		break
	}
	return err
}
コード例 #2
0
ファイル: multipart.go プロジェクト: jojimt/netplugin
func (s *MultipartReply) UnmarshalBinary(data []byte) error {
	err := s.Header.UnmarshalBinary(data)
	n := s.Header.Len()

	s.Type = binary.BigEndian.Uint16(data[n:])
	n += 2
	s.Flags = binary.BigEndian.Uint16(data[n:])
	n += 2
	n += 4 // for padding
	var req []util.Message
	for n < s.Header.Length {
		var repl util.Message
		switch s.Type {
		case MultipartType_Aggregate:
			repl = new(AggregateStats)
		case MultipartType_Desc:
			repl = new(DescStats)
		case MultipartType_Flow:
			repl = new(FlowStats)
		case MultipartType_Port:
			repl = new(PortStats)
		case MultipartType_Table:
			repl = new(TableStats)
		case MultipartType_Queue:
			repl = new(QueueStats)
		// FIXME: Support all types
		case MultipartType_Experimenter:
			break
		}

		err = repl.UnmarshalBinary(data[n:])
		if err != nil {
			log.Printf("Error parsing stats reply")
		}
		n += repl.Len()
		req = append(req, repl)

	}

	s.Body = req

	return err
}
コード例 #3
0
ファイル: match.go プロジェクト: rtrentin73/netplugin
func DecodeMatchField(class uint16, field uint8, data []byte) util.Message {
	if class == OXM_CLASS_OPENFLOW_BASIC {
		var val util.Message
		switch field {
		case OXM_FIELD_IN_PORT:
			val = new(InPortField)
		case OXM_FIELD_IN_PHY_PORT:
		case OXM_FIELD_METADATA:
		case OXM_FIELD_ETH_DST:
			val = new(EthDstField)
		case OXM_FIELD_ETH_SRC:
			val = new(EthSrcField)
		case OXM_FIELD_ETH_TYPE:
			val = new(EthTypeField)
		case OXM_FIELD_VLAN_VID:
			val = new(VlanIdField)
		case OXM_FIELD_VLAN_PCP:
		case OXM_FIELD_IP_DSCP:
		case OXM_FIELD_IP_ECN:
		case OXM_FIELD_IP_PROTO:
			val = new(IpProtoField)
		case OXM_FIELD_IPV4_SRC:
			val = new(Ipv4SrcField)
		case OXM_FIELD_IPV4_DST:
			val = new(Ipv4DstField)
		case OXM_FIELD_TCP_SRC:
			val = new(PortField)
		case OXM_FIELD_TCP_DST:
			val = new(PortField)
		case OXM_FIELD_UDP_SRC:
			val = new(PortField)
		case OXM_FIELD_UDP_DST:
			val = new(PortField)
		case OXM_FIELD_SCTP_SRC:
		case OXM_FIELD_SCTP_DST:
		case OXM_FIELD_ICMPV4_TYPE:
		case OXM_FIELD_ICMPV4_CODE:
		case OXM_FIELD_ARP_OP:
		case OXM_FIELD_ARP_SPA:
		case OXM_FIELD_ARP_TPA:
		case OXM_FIELD_ARP_SHA:
		case OXM_FIELD_ARP_THA:
		case OXM_FIELD_IPV6_SRC:
		case OXM_FIELD_IPV6_DST:
		case OXM_FIELD_IPV6_FLABEL:
		case OXM_FIELD_ICMPV6_TYPE:
		case OXM_FIELD_ICMPV6_CODE:
		case OXM_FIELD_IPV6_ND_TARGET:
		case OXM_FIELD_IPV6_ND_SLL:
		case OXM_FIELD_IPV6_ND_TLL:
		case OXM_FIELD_MPLS_LABEL:
		case OXM_FIELD_MPLS_TC:
		case OXM_FIELD_MPLS_BOS:
		case OXM_FIELD_PBB_ISID:
		case OXM_FIELD_TUNNEL_ID:
			val = new(TunnelIdField)
		case OXM_FIELD_IPV6_EXTHDR:
		case OXM_FIELD_TCP_FLAGS:
			val = new(TcpFlagsField)
		}

		val.UnmarshalBinary(data)
		return val
	} else {
		log.Panic("Unsupported match field class")
	}

	return nil
}
コード例 #4
0
ファイル: match.go プロジェクト: jojimt/netplugin
func DecodeMatchField(class uint16, field uint8, data []byte) util.Message {
	if class == OXM_CLASS_OPENFLOW_BASIC {
		var val util.Message
		val = nil
		switch field {
		case OXM_FIELD_IN_PORT:
			val = new(InPortField)
		case OXM_FIELD_IN_PHY_PORT:
		case OXM_FIELD_METADATA:
			val = new(MetadataField)
		case OXM_FIELD_ETH_DST:
			val = new(EthDstField)
		case OXM_FIELD_ETH_SRC:
			val = new(EthSrcField)
		case OXM_FIELD_ETH_TYPE:
			val = new(EthTypeField)
		case OXM_FIELD_VLAN_VID:
			val = new(VlanIdField)
		case OXM_FIELD_VLAN_PCP:
		case OXM_FIELD_IP_DSCP:
			val = new(IpDscpField)
		case OXM_FIELD_IP_ECN:
		case OXM_FIELD_IP_PROTO:
			val = new(IpProtoField)
		case OXM_FIELD_IPV4_SRC:
			val = new(Ipv4SrcField)
		case OXM_FIELD_IPV4_DST:
			val = new(Ipv4DstField)
		case OXM_FIELD_TCP_SRC:
			val = new(PortField)
		case OXM_FIELD_TCP_DST:
			val = new(PortField)
		case OXM_FIELD_UDP_SRC:
			val = new(PortField)
		case OXM_FIELD_UDP_DST:
			val = new(PortField)
		case OXM_FIELD_SCTP_SRC:
		case OXM_FIELD_SCTP_DST:
		case OXM_FIELD_ICMPV4_TYPE:
		case OXM_FIELD_ICMPV4_CODE:
		case OXM_FIELD_ARP_OP:
			val = new(ArpOperField)
		case OXM_FIELD_ARP_SPA:
		case OXM_FIELD_ARP_TPA:
		case OXM_FIELD_ARP_SHA:
		case OXM_FIELD_ARP_THA:
		case OXM_FIELD_IPV6_SRC:
			val = new(Ipv6SrcField)
		case OXM_FIELD_IPV6_DST:
			val = new(Ipv6DstField)
		case OXM_FIELD_IPV6_FLABEL:
		case OXM_FIELD_ICMPV6_TYPE:
		case OXM_FIELD_ICMPV6_CODE:
		case OXM_FIELD_IPV6_ND_TARGET:
		case OXM_FIELD_IPV6_ND_SLL:
		case OXM_FIELD_IPV6_ND_TLL:
		case OXM_FIELD_MPLS_LABEL:
			val = new(MplsLabelField)
		case OXM_FIELD_MPLS_TC:
		case OXM_FIELD_MPLS_BOS:
			val = new(MplsBosField)
		case OXM_FIELD_PBB_ISID:
		case OXM_FIELD_TUNNEL_ID:
			val = new(TunnelIdField)
		case OXM_FIELD_IPV6_EXTHDR:
		case OXM_FIELD_TCP_FLAGS:
			val = new(TcpFlagsField)
		default:
			log.Printf("Unhandled Field: %d in Class: %d", field, class)
		}

		if val == nil {
			log.Printf("Bad pkt class: %v field: %v data: %v", class, field, data)
			return nil
		}

		val.UnmarshalBinary(data)
		return val
	} else if class == OXM_CLASS_NXM_1 {
		var val util.Message
		switch field {
		case NXM_NX_TUN_IPV4_SRC:
			val = new(TunnelIpv4SrcField)
		case NXM_NX_TUN_IPV4_DST:
			val = new(TunnelIpv4DstField)
		default:
			log.Printf("Unhandled Field: %d in Class: %d", field, class)
			return nil
		}

		val.UnmarshalBinary(data)
		return val
	} else {
		log.Panic("Unsupported match field: %d in class: %d", field, class)
	}

	return nil
}