summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorXiao Peng <penxiao@cisco.com>2014-08-14 16:55:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-08-14 17:09:27 +0900
commit6b28af2636b9747bc5d12b05152766eef622266f (patch)
tree75fe565ad41d663e9061a06f0d4d979aac9ff828
parentafbf024447ef0a444b5d3523f19de4becaec600f (diff)
bgp: add attribute ORIGINATOR_ID and CLUSTER_LIST
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bgp.py70
-rw-r--r--ryu/tests/unit/packet/test_bgp.py2
2 files changed, 72 insertions, 0 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 7c716b43..9cc98399 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -70,6 +70,8 @@ BGP_ATTR_TYPE_LOCAL_PREF = 5 # uint32
BGP_ATTR_TYPE_ATOMIC_AGGREGATE = 6 # 0 bytes
BGP_ATTR_TYPE_AGGREGATOR = 7 # AS number and IPv4 address
BGP_ATTR_TYPE_COMMUNITIES = 8 # RFC 1997
+BGP_ATTR_TYPE_ORIGINATOR_ID = 9 # RFC 4456
+BGP_ATTR_TYPE_CLUSTER_LIST = 10 # RFC 4456
BGP_ATTR_TYPE_MP_REACH_NLRI = 14 # RFC 4760
BGP_ATTR_TYPE_MP_UNREACH_NLRI = 15 # RFC 4760
BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16 # RFC 4360
@@ -1630,6 +1632,73 @@ class BGPPathAttributeCommunities(_PathAttribute):
return False
+@_PathAttribute.register_type(BGP_ATTR_TYPE_ORIGINATOR_ID)
+class BGPPathAttributeOriginatorId(_PathAttribute):
+ # ORIGINATOR_ID is a new optional, non-transitive BGP attribute of Type
+ # code 9. This attribute is 4 bytes long and it will be created by an
+ # RR in reflecting a route.
+ _VALUE_PACK_STR = '!4s'
+ _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
+ _TYPE = {
+ 'ascii': [
+ 'value'
+ ]
+ }
+
+ @classmethod
+ def parse_value(cls, buf):
+ (originator_id,) = struct.unpack_from(cls._VALUE_PACK_STR, buffer(buf))
+ return {
+ 'value': addrconv.ipv4.bin_to_text(originator_id),
+ }
+
+ def serialize_value(self):
+ buf = bytearray()
+ msg_pack_into(self._VALUE_PACK_STR, buf, 0,
+ addrconv.ipv4.text_to_bin(self.value))
+ return buf
+
+
+@_PathAttribute.register_type(BGP_ATTR_TYPE_CLUSTER_LIST)
+class BGPPathAttributeClusterList(_PathAttribute):
+ # CLUSTER_LIST is a new, optional, non-transitive BGP attribute of Type
+ # code 10. It is a sequence of CLUSTER_ID values representing the
+ # reflection path that the route has passed.
+ _VALUE_PACK_STR = '!4s'
+ _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL
+ _TYPE = {
+ 'ascii': [
+ 'value'
+ ]
+ }
+
+ @classmethod
+ def parse_value(cls, buf):
+ rest = buf
+ cluster_list = []
+ elem_size = struct.calcsize(cls._VALUE_PACK_STR)
+ while len(rest) >= elem_size:
+ (cluster_id, ) = struct.unpack_from(
+ cls._VALUE_PACK_STR, buffer(rest))
+ cluster_list.append(addrconv.ipv4.bin_to_text(cluster_id))
+ rest = rest[elem_size:]
+ return {
+ 'value': cluster_list,
+ }
+
+ def serialize_value(self):
+ buf = bytearray()
+ for cluster_id in self.value:
+ cluster_id_bin = bytearray()
+ msg_pack_into(
+ self._VALUE_PACK_STR,
+ cluster_id_bin,
+ 0,
+ addrconv.ipv4.text_to_bin(cluster_id))
+ buf += cluster_id_bin
+ return buf
+
+
# Extended Communities
# RFC 4360
# RFC 5668
@@ -1660,6 +1729,7 @@ class BGPPathAttributeCommunities(_PathAttribute):
# 00 03 Route Origin Community (two-octet AS specific)
# 01 03 Route Origin Community (IPv4 address specific)
# 02 03 Route Origin Community (four-octet AS specific, RFC 5668)
+
@_PathAttribute.register_type(BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
class BGPPathAttributeExtendedCommunities(_PathAttribute):
_ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANSITIVE
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py
index 057443f3..c2592252 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -113,6 +113,8 @@ class Test_bgp(unittest.TestCase):
bgp.BGPPathAttributeAggregator(as_number=40000,
addr='192.0.2.99'),
bgp.BGPPathAttributeCommunities(communities=communities),
+ bgp.BGPPathAttributeOriginatorId(value='10.1.1.1'),
+ bgp.BGPPathAttributeClusterList(value=['1.1.1.1', '2.2.2.2']),
bgp.BGPPathAttributeExtendedCommunities(communities=ecommunities),
bgp.BGPPathAttributeAs4Path(value=[[1000000], set([1000001, 1002]),
[1003, 1000004]]),