backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / lib / packet / linux.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 #
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
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import struct
17 from . import packet_base
18 from . import vlan
19 from . import mpls
20 from . import ether_types as ether
21 from ryu.lib import addrconv
22
23
24 class linuxcooked(packet_base.PacketBase):
25     _PACK_STR = '!HHH8sH'
26     _MIN_LEN = struct.calcsize(_PACK_STR)
27
28     def __init__(self, pkt_type, arphrd_type, address_length, address,
29                  proto_type):
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
36
37     @classmethod
38     def parser(cls, buf):
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:])
44
45     @classmethod
46     def get_packet_type(cls, type_):
47         """Override method for the ethernet IEEE802.3 Length/Type
48         field (self.ethertype).
49
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_)
56
57
58 # copy vlan _TYPES
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)