diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2013-09-24 10:19:54 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-09-26 04:11:04 +0900 |
commit | 5ddbd7f1d03d58aaeb0483b444ac468c63a1df1b (patch) | |
tree | 00fff2593aec5c59cd421c110eec875f379ba67f | |
parent | ba92a9e634e8d60a4ea9b8f80d1a0b7a30fc0609 (diff) |
unit test for lib.packet.bgp
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/unit/packet/test_bgp.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/ryu/tests/unit/packet/test_bgp.py b/ryu/tests/unit/packet/test_bgp.py new file mode 100644 index 00000000..db5319dd --- /dev/null +++ b/ryu/tests/unit/packet/test_bgp.py @@ -0,0 +1,96 @@ +# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from nose.tools import eq_ +from nose.tools import ok_ + +from ryu.lib.packet import bgp + + +class Test_bgp(unittest.TestCase): + """ Test case for ryu.lib.packet.bgp + """ + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_open1(self): + msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.1') + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + eq_(len(msg), 29) + + def test_open2(self): + msg = bgp.BGPOpen(my_as=30000, bgp_identifier='192.0.2.2', + opt_param=[bgp.BGPOptParam(type_=1, value='hooge'), + bgp.BGPOptParam(type_=2, value='fuga')]) + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + ok_(len(msg) > 29) + + def test_update1(self): + msg = bgp.BGPUpdate() + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + eq_(len(msg), 23) + + def test_update2(self): + 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=300*'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) + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + ok_(len(msg) > 23) + + def test_keepalive(self): + msg = bgp.BGPKeepAlive() + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + eq_(len(msg), 19) + + def test_notification(self): + data = "hoge" + msg = bgp.BGPNotification(error_code=1, error_subcode=2, data=data) + binmsg = msg.serialize() + msg2 = bgp.BGPMessage.parser(binmsg) + eq_(str(msg), str(msg2)) + eq_(len(msg), 21 + len(data)) |