backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / unit / packet / test_ospf.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 #
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
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import unittest
17 from nose.tools import eq_
18 from nose.tools import ok_
19
20 from ryu.lib.packet import ospf
21
22
23 class Test_ospf(unittest.TestCase):
24     """ Test case for ryu.lib.packet.ospf
25     """
26
27     def setUp(self):
28         pass
29
30     def tearDown(self):
31         pass
32
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',
37                              links=[link1])
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))
42         eq_(rest, b'')
43
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))
51         eq_(rest, b'')
52
53     def test_as_external_lsa(self):
54         extnw1 = ospf.ASExternalLSA.ExternalNetwork(mask='255.255.255.0',
55                                                     metric=20,
56                                                     fwd_addr='10.0.0.1')
57         msg = ospf.ASExternalLSA(id_='192.168.0.1', adv_router='192.168.0.2',
58                                  extnws=[extnw1])
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))
63         eq_(rest, b'')
64
65     def test_hello(self):
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))
72         eq_(rest, b'')
73
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',
78                               links=[link1])
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))
85         eq_(rest, b'')
86
87     def test_lsreq(self):
88         req = ospf.OSPFLSReq.Request(type_=ospf.OSPF_ROUTER_LSA,
89                                      id_='192.168.0.1',
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))
96         eq_(rest, b'')
97
98     def test_lsupd(self):
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',
102                               links=[link1])
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))
108         eq_(rest, b'')
109
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',
114                               links=[link1])
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))
121         eq_(rest, b'')