1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from nose.tools import eq_
18 from nose.tools import ok_
20 from ryu.lib.packet import ospf
23 class Test_ospf(unittest.TestCase):
24 """ Test case for ryu.lib.packet.ospf
33 def test_router_lsa(self):
34 link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
35 type_=ospf.LSA_LINK_TYPE_STUB, metric=10)
36 msg = ospf.RouterLSA(id_='192.168.0.1', adv_router='192.168.0.2',
38 binmsg = msg.serialize()
39 msg2, cls, rest = ospf.LSA.parser(binmsg)
40 eq_(msg.header.checksum, msg2.header.checksum)
41 eq_(str(msg), str(msg2))
44 def test_network_lsa(self):
45 msg = ospf.NetworkLSA(id_='192.168.0.1', adv_router='192.168.0.2',
46 mask='255.255.255.0', routers=['192.168.0.2'])
47 binmsg = msg.serialize()
48 msg2, cls, rest = ospf.LSA.parser(binmsg)
49 eq_(msg.header.checksum, msg2.header.checksum)
50 eq_(str(msg), str(msg2))
53 def test_as_external_lsa(self):
54 extnw1 = ospf.ASExternalLSA.ExternalNetwork(mask='255.255.255.0',
57 msg = ospf.ASExternalLSA(id_='192.168.0.1', adv_router='192.168.0.2',
59 binmsg = msg.serialize()
60 msg2, cls, rest = ospf.LSA.parser(binmsg)
61 eq_(msg.header.checksum, msg2.header.checksum)
62 eq_(str(msg), str(msg2))
66 msg = ospf.OSPFHello(router_id='192.168.0.1',
67 neighbors=['192.168.0.2'])
68 binmsg = msg.serialize()
69 msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
70 eq_(msg.checksum, msg2.checksum)
71 eq_(str(msg), str(msg2))
74 def test_dbdesc(self):
75 link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
76 type_=ospf.LSA_LINK_TYPE_STUB, metric=10)
77 lsa1 = ospf.RouterLSA(id_='192.168.0.1', adv_router='192.168.0.2',
79 msg = ospf.OSPFDBDesc(router_id='192.168.0.1',
80 lsa_headers=[lsa1.header])
81 binmsg = msg.serialize()
82 msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
83 eq_(msg.checksum, msg2.checksum)
84 eq_(str(msg), str(msg2))
88 req = ospf.OSPFLSReq.Request(type_=ospf.OSPF_ROUTER_LSA,
90 adv_router='192.168.0.2')
91 msg = ospf.OSPFLSReq(router_id='192.168.0.1', lsa_requests=[req])
92 binmsg = msg.serialize()
93 msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
94 eq_(msg.checksum, msg2.checksum)
95 eq_(str(msg), str(msg2))
99 link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
100 type_=ospf.LSA_LINK_TYPE_STUB, metric=10)
101 lsa1 = ospf.RouterLSA(id_='192.168.0.1', adv_router='192.168.0.2',
103 msg = ospf.OSPFLSUpd(router_id='192.168.0.1', lsas=[lsa1])
104 binmsg = msg.serialize()
105 msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
106 eq_(msg.checksum, msg2.checksum)
107 eq_(str(msg), str(msg2))
110 def test_lsack(self):
111 link1 = ospf.RouterLSA.Link(id_='10.0.0.1', data='255.255.255.0',
112 type_=ospf.LSA_LINK_TYPE_STUB, metric=10)
113 lsa1 = ospf.RouterLSA(id_='192.168.0.1', adv_router='192.168.0.2',
115 msg = ospf.OSPFLSAck(router_id='192.168.0.1',
116 lsa_headers=[lsa1.header])
117 binmsg = msg.serialize()
118 msg2, cls, rest = ospf.OSPFMessage.parser(binmsg)
119 eq_(msg.checksum, msg2.checksum)
120 eq_(str(msg), str(msg2))