1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from . import packet_base
20 from . import ether_types as ether
21 from ryu.lib import addrconv
24 class linuxcooked(packet_base.PacketBase):
26 _MIN_LEN = struct.calcsize(_PACK_STR)
28 def __init__(self, pkt_type, arphrd_type, address_length, address,
30 super(linuxcooked, self).__init__()
31 self.pkt_type = pkt_type
32 self.arphrd_type = arphrd_type
33 self.address_length = address_length
34 self.address = address
35 self.proto_type = proto_type
39 (pkt_type, arphrd_type, address_length, addres,
40 proto_type) = struct.unpack_from(cls._PACK_STR, buf)
41 l = cls(pkt_type, arphrd_type, address_length, addres, proto_type)
42 return (l, linuxcooked.get_packet_type(proto_type),
43 buf[linuxcooked._MIN_LEN:])
46 def get_packet_type(cls, type_):
47 """Override method for the ethernet IEEE802.3 Length/Type
48 field (self.ethertype).
50 If the value of Length/Type field is less than or equal to
51 1500 decimal(05DC hexadecimal), it means Length interpretation
52 and be passed to the LLC sublayer."""
53 if type_ <= ether.ETH_TYPE_IEEE802_3:
54 type_ = ether.ETH_TYPE_IEEE802_3
55 return cls._TYPES.get(type_)
59 linuxcooked._TYPES = vlan.vlan._TYPES
60 linuxcooked.register_packet_type(vlan.vlan, ether.ETH_TYPE_8021Q)
61 linuxcooked.register_packet_type(vlan.svlan, ether.ETH_TYPE_8021AD)
62 linuxcooked.register_packet_type(mpls.mpls, ether.ETH_TYPE_MPLS)