Signed-off-by: IWASE Yusuke <[email protected]>
---
 ryu/lib/packet/bgp.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 7eae712..937fdeb 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -1677,8 +1677,27 @@ class _BGPPathAttributeAggregatorCommon(_PathAttribute):
 
 @_PathAttribute.register_type(BGP_ATTR_TYPE_AGGREGATOR)
 class BGPPathAttributeAggregator(_BGPPathAttributeAggregatorCommon):
-    # XXX currently this implementation assumes 16 bit AS numbers.
-    _VALUE_PACK_STR = '!H4s'
+    # Note: AS numbers can be Two-Octet or Four-Octet.
+    # This class would detect it by the value length field.
+    # For example,
+    # - if the value field length is 6 (='!H4s'), AS number should
+    #   be Two-Octet.
+    # - else if the length is 8 (='!I4s'), AS number should be Four-Octet.
+    _TWO_OCTET_VALUE_PACK_STR = '!H4s'
+    _FOUR_OCTET_VALUE_PACK_STR = '!I4s'
+    _VALUE_PACK_STR = _TWO_OCTET_VALUE_PACK_STR  # Two-Octet by default
+    _FOUR_OCTET_VALUE_SIZE = struct.calcsize(_FOUR_OCTET_VALUE_PACK_STR)
+
+    @classmethod
+    def parse_value(cls, buf):
+        if len(buf) == cls._FOUR_OCTET_VALUE_SIZE:
+            cls._VALUE_PACK_STR = cls._FOUR_OCTET_VALUE_PACK_STR
+        return super(BGPPathAttributeAggregator, cls).parse_value(buf)
+
+    def serialize_value(self):
+        if self.as_number > 0xffff:
+            self._VALUE_PACK_STR = self._FOUR_OCTET_VALUE_PACK_STR
+        return super(BGPPathAttributeAggregator, self).serialize_value()
 
 
 @_PathAttribute.register_type(BGP_ATTR_TYPE_AS4_AGGREGATOR)
-- 
2.7.4


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to