blob: fbcc654b272e3011d9a70e9d198bb0d194b3e00c [file] [log] [blame]
Zack Williams41513bf2018-07-07 20:08:35 -07001# Copyright 2017-present Open Networking Foundation
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 implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
sgovindacc736782017-05-02 20:06:37 +053014from unittest import TestCase, main
15from of_protocol_handler import OpenFlowProtocolHandler
16import loxi.of13 as ofp
17
18class TestOF_Protocol_handler(TestCase):
19
20 def gen_packet_in(self):
21 packet_in = 1
22 return packet_in
23
24 def gen_device(self):
25 device =lambda: None
26 device.id = "1"
27 device.datapath_id = 1
28 device.desc = '{mfr_desc: "cord porject" hw_desc: "simualted pon" sw_desc: "simualted pon"\
29 serial_num: "2f150d56afa2405eba3ba24e33ce8df9" dp_desc: "n/a"}'
30 device.switch_features = '{ n_buffers: 256 n_tables: 2 capabilities: 15 }'
31 device.root_device_id = "a245bd8bb8b8"
32 return device
33
34 def gen_generic_obj(self):
35 generic_obj = lambda: None
36 return generic_obj
37
38 def gen_role_req(self):
39 req = self.gen_generic_obj()
40 req.role = ofp.OFPCR_ROLE_MASTER
41 return req
42
Koray Kokten8592a232018-08-27 07:41:14 +000043 def test_handle_flow_mod_request_role_slave(self):
sgovindacc736782017-05-02 20:06:37 +053044 generic_obj = self.gen_generic_obj()
45 device = self.gen_device()
46 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
47 of_proto_handler.role = ofp.OFPCR_ROLE_SLAVE
48 with self.assertRaises(Exception) as context:
49 of_proto_handler.handle_flow_mod_request(generic_obj)
50 print context.exception
sathishg23ac35c2017-10-14 03:21:43 +053051 self.assertTrue('\'function\' object has no attribute \'send\'' in str(context.exception))
sgovindacc736782017-05-02 20:06:37 +053052
53 def test_handle_flow_mod_request_role_master(self):
54 generic_obj = self.gen_generic_obj()
55 device = self.gen_device()
56 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
57 of_proto_handler.role = ofp.OFPCR_ROLE_MASTER
58 of_proto_handler.handle_flow_mod_request(generic_obj)
59
Koray Kokten8592a232018-08-27 07:41:14 +000060 def test_handle_meter_mod_request_role_slave(self):
61 generic_obj = self.gen_generic_obj()
62 device = self.gen_device()
63 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
64 of_proto_handler.role = ofp.OFPCR_ROLE_SLAVE
65 with self.assertRaises(Exception) as context:
66 of_proto_handler.handle_meter_mod_request(generic_obj)
67 print context.exception
68 self.assertTrue('\'function\' object has no attribute \'send\'' in str(context.exception))
69
70 def test_handle_meter_mod_request_role_master(self):
71 generic_obj = self.gen_generic_obj()
72 device = self.gen_device()
73 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
74 of_proto_handler.role = ofp.OFPCR_ROLE_MASTER
75 of_proto_handler.handle_meter_mod_request(generic_obj)
76
sgovindacc736782017-05-02 20:06:37 +053077 def test_handle_role_request(self):
78 generic_obj = self.gen_generic_obj()
79 req = self.gen_role_req()
80 device = self.gen_device()
81 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
82 with self.assertRaises(Exception) as context:
83 of_proto_handler.handle_role_request(req)
84 self.assertEqual(of_proto_handler.role,req.role)
85 print context.exception
sathishg23ac35c2017-10-14 03:21:43 +053086 self.assertTrue('\'function\' object has no attribute \'generation_is_defined\'' in str(context.exception))
sgovindacc736782017-05-02 20:06:37 +053087
88 def test_forward_packet_in_role_none(self):
89 packet_in = self.gen_packet_in()
90 generic_obj = self.gen_generic_obj()
91 device = self.gen_device()
92 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
93 of_proto_handler.forward_packet_in(packet_in)
94
95 def test_forward_packet_in_role_master(self):
96 packet_in = self.gen_packet_in()
97 generic_obj = self.gen_generic_obj()
98 device = self.gen_device()
99 of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj)
100 of_proto_handler.role = ofp.OFPCR_ROLE_MASTER
101 with self.assertRaises(Exception) as context:
102 of_proto_handler.forward_packet_in(packet_in)
103 print context.exception
sathishg23ac35c2017-10-14 03:21:43 +0530104 self.assertTrue('\'function\' object has no attribute \'send\'' in str(context.exception))
sgovindacc736782017-05-02 20:06:37 +0530105
106if __name__ == '__main__':
sathishg23ac35c2017-10-14 03:21:43 +0530107 main()