1 # Copyright (C) 2013 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 ryu.lib.packet import packet_base
20 class itag(packet_base.PacketBase):
21 """I-TAG (IEEE 802.1ah-2008) header encoder/decoder class.
23 An instance has the following attributes at least.
24 Most of them are same to the on-wire counterparts but in host byte order.
25 __init__ takes the corresponding args in this order.
27 ============== ====================
29 ============== ====================
30 pcp Priority Code Point
31 dei Drop Eligible Indication
32 uca Use Customer Address
33 sid Service Instance ID
34 ============== ====================
38 _MIN_LEN = struct.calcsize(_PACK_STR)
40 def __init__(self, pcp=0, dei=0, uca=0, sid=0):
41 super(itag, self).__init__()
49 (data, ) = struct.unpack_from(cls._PACK_STR, buf)
53 sid = data & 0x00ffffff
54 # circular import: ethernet -> vlan -> pbb
55 from ryu.lib.packet import ethernet
56 return (cls(pcp, dei, uca, sid), ethernet.ethernet,
59 def serialize(self, payload, prev):
60 data = self.pcp << 29 | self.dei << 28 | self.uca << 27 | self.sid
61 return struct.pack(self._PACK_STR, data)