diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-03-30 11:33:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-08-11 20:04:57 +0900 |
commit | bc5bf0dbb658d77a57cd2c2a524c1c53c0cbc4e4 (patch) | |
tree | f4e8658fc22c5cced86a1ab7518e3d99d02cace5 | |
parent | 807185470e3ae23297d2cc5ac6438b4bccdcd451 (diff) |
test_mrtlib: Test cases for ADD_PATH
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/unit/lib/test_mrtlib.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ryu/tests/unit/lib/test_mrtlib.py b/ryu/tests/unit/lib/test_mrtlib.py index e870f401..55c7cda0 100644 --- a/ryu/tests/unit/lib/test_mrtlib.py +++ b/ryu/tests/unit/lib/test_mrtlib.py @@ -19,6 +19,7 @@ import bz2 import io import logging import os +import struct import sys import unittest @@ -609,6 +610,66 @@ class TestMrtlibMrtPeer(unittest.TestCase): eq_(buf, output) +class TestMrtlibMrtRibEntry(unittest.TestCase): + """ + Test case for ryu.lib.mrtlib.MrtRibEntry. + """ + + def test_parse_add_path(self): + peer_index = 1 + originated_time = 2 + nexthop = '1.1.1.1' + bgp_attribute = bgp.BGPPathAttributeNextHop(nexthop) + path_id = 3 + bgp_attr_buf = bgp_attribute.serialize() + attr_len = len(bgp_attr_buf) + buf = ( + b'\x00\x01' # peer_index + b'\x00\x00\x00\x02' # originated_time + b'\x00\x00\x00\x03' # path_id + + struct.pack('!H', attr_len) # attr_len + + bgp_attribute.serialize() # bgp_attributes + ) + + rib, rest = mrtlib.MrtRibEntry.parse(buf, is_addpath=True) + + eq_(peer_index, rib.peer_index) + eq_(originated_time, rib.originated_time) + eq_(path_id, rib.path_id) + eq_(attr_len, rib.attr_len) + eq_(1, len(rib.bgp_attributes)) + eq_(nexthop, rib.bgp_attributes[0].value) + eq_(b'', rest) + + def test_serialize_add_path(self): + peer_index = 1 + originated_time = 2 + nexthop = '1.1.1.1' + bgp_attribute = bgp.BGPPathAttributeNextHop(nexthop) + path_id = 3 + bgp_attr_buf = bgp_attribute.serialize() + attr_len = len(bgp_attr_buf) + buf = ( + b'\x00\x01' # peer_index + b'\x00\x00\x00\x02' # originated_time + b'\x00\x00\x00\x03' # path_id + + struct.pack('!H', attr_len) # attr_len + + bgp_attribute.serialize() # bgp_attributes + ) + + rib = mrtlib.MrtRibEntry( + peer_index=peer_index, + originated_time=originated_time, + bgp_attributes=[bgp_attribute], + # attr_len=attr_len, + path_id=path_id, + ) + + output = rib.serialize() + + eq_(buf, output) + + class TestMrtlibBgp4MpMrtRecord(unittest.TestCase): """ Test case for ryu.lib.mrtlib.Bgp4MpMrtRecord. |