Signed-off-by: itoyuichi <[email protected]>
---
ryu/tests/unit/packet/test_bgp.py | 198 +++++++++++++++++++++++++++++++++++++
1 file changed, 198 insertions(+)
diff --git a/ryu/tests/unit/packet/test_bgp.py
b/ryu/tests/unit/packet/test_bgp.py
index 808b2db..b5147cc 100644
--- a/ryu/tests/unit/packet/test_bgp.py
+++ b/ryu/tests/unit/packet/test_bgp.py
@@ -15,6 +15,7 @@
# limitations under the License.
import unittest
+import json
from nose.tools import eq_
from nose.tools import ok_
@@ -114,3 +115,200 @@ class Test_bgp(unittest.TestCase):
for m in sp.parse(b):
results.append(m)
eq_(str(results), str(msgs))
+
+
+class Test_bgpopen(unittest.TestCase):
+ msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.2',
+ opt_param=[bgp.BGPOptParam(type_=1, value='hoge'),
+ bgp.BGPOptParam(type_=2, value='fuga')])
+ jsonstr = '''
+ {
+ "BGPOpen": {
+ "my_as": 30000,
+ "bgp_identifier": "192.0.2.2",
+ "type": 1,
+ "opt_param_len": 0,
+ "opt_param": [
+ {
+ "BGPOptParam": {
+ "type": 1,
+ "value": "aG9nZQ==",
+ "length": null
+ }
+ },
+ {
+ "BGPOptParam": {
+ "type": 2,
+ "value": "ZnVnYQ==",
+ "length": null
+ }
+ }
+ ],
+ "version": 4,
+ "hold_time": 0,
+ "len": null,
+ "marker": "/////////////////////w=="
+ }
+ }
+ '''
+ jsondict = json.loads(jsonstr)
+
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.msg.to_jsondict())
+
+ def test_from_jsondict(self):
+ msg2 = bgp.BGPOpen.from_jsondict(self.jsondict['BGPOpen'])
+ eq_(str(msg2), str(self.msg))
+
+
+class Test_bgpupdate(unittest.TestCase):
+ withdrawn_routes = [bgp.BGPWithdrawnRoute(length=0,
+ ip_addr='192.0.2.13'),
+ bgp.BGPWithdrawnRoute(length=1,
+ ip_addr='192.0.2.13'),
+ bgp.BGPWithdrawnRoute(length=3,
+ ip_addr='192.0.2.13'),
+ bgp.BGPWithdrawnRoute(length=7,
+ ip_addr='192.0.2.13'),
+ bgp.BGPWithdrawnRoute(length=32,
+ ip_addr='192.0.2.13')]
+ path_attributes = [bgp.BGPPathAttribute(flags=0, type_=1, value='foo'),
+ bgp.BGPPathAttribute(flags=0, type_=2, value='bar')]
+ nlri = [
+ bgp.BGPNLRI(length=24, ip_addr='203.0.113.1'),
+ bgp.BGPNLRI(length=16, ip_addr='203.0.113.0')
+ ]
+ msg = bgp.BGPUpdate(withdrawn_routes=withdrawn_routes,
+ path_attributes=path_attributes,
+ nlri=nlri)
+ jsonstr = '''
+ {
+ "BGPUpdate": {
+ "type": 2,
+ "withdrawn_routes_len": null,
+ "withdrawn_routes": [
+ {
+ "BGPWithdrawnRoute": {
+ "length": 0,
+ "ip_addr": "192.0.2.13"
+ }
+ },
+ {
+ "BGPWithdrawnRoute": {
+ "length": 1,
+ "ip_addr": "192.0.2.13"
+ }
+ },
+ {
+ "BGPWithdrawnRoute": {
+ "length": 3,
+ "ip_addr": "192.0.2.13"
+ }
+ },
+ {
+ "BGPWithdrawnRoute": {
+ "length": 7,
+ "ip_addr": "192.0.2.13"
+ }
+ },
+ {
+ "BGPWithdrawnRoute": {
+ "length": 32,
+ "ip_addr": "192.0.2.13"
+ }
+ }
+ ],
+ "total_path_attribute_len": null,
+ "path_attributes": [
+ {
+ "BGPPathAttribute": {
+ "flags": 0,
+ "type": 1,
+ "value": "Zm9v",
+ "length": null
+ }
+ },
+ {
+ "BGPPathAttribute": {
+ "flags": 0,
+ "type": 2,
+ "value": "YmFy",
+ "length": null
+ }
+ }
+ ],
+ "nlri": [
+ {
+ "BGPNLRI": {
+ "length": 24,
+ "ip_addr": "203.0.113.1"
+ }
+ },
+ {
+ "BGPNLRI": {
+ "length": 16,
+ "ip_addr": "203.0.113.0"
+ }
+ }
+ ],
+ "len": null,
+ "marker": "/////////////////////w=="
+ }
+ }
+ '''
+ jsondict = json.loads(jsonstr)
+
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.msg.to_jsondict())
+
+ def test_from_jsondict(self):
+ msg2 = bgp.BGPUpdate.from_jsondict(self.jsondict['BGPUpdate'])
+ eq_(str(msg2), str(self.msg))
+
+
+class Test_bgpkeepalive(unittest.TestCase):
+ msg = bgp.BGPKeepAlive()
+ jsonstr = '''
+ {
+ "BGPKeepAlive": {
+ "type": 4,
+ "len": null,
+ "marker": "/////////////////////w=="
+ }
+ }
+ '''
+ jsondict = json.loads(jsonstr)
+
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.msg.to_jsondict())
+
+ def test_from_jsondict(self):
+ msg2 = bgp.BGPKeepAlive.from_jsondict(
+ self.jsondict['BGPKeepAlive'])
+ eq_(str(msg2), str(self.msg))
+
+
+class Test_bgpnotification(unittest.TestCase):
+ data = "hoge"
+ msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data)
+ jsonstr = '''
+ {
+ "BGPNotification": {
+ "error_code": 1,
+ "error_subcode": 2,
+ "data": "aG9nZQ==",
+ "type": 3,
+ "len": null,
+ "marker": "/////////////////////w=="
+ }
+ }
+ '''
+ jsondict = json.loads(jsonstr)
+
+ def test_to_jsondict(self):
+ eq_(self.jsondict, self.msg.to_jsondict())
+
+ def test_from_jsondict(self):
+ msg2 = bgp.BGPNotification.from_jsondict(
+ self.jsondict['BGPNotification'])
+ eq_(str(msg2), str(self.msg))
--
1.7.10.4
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel