sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 1 | from unittest import TestCase, main |
| 2 | from of_protocol_handler import OpenFlowProtocolHandler |
| 3 | import loxi.of13 as ofp |
| 4 | |
| 5 | class TestOF_Protocol_handler(TestCase): |
| 6 | |
| 7 | def gen_packet_in(self): |
| 8 | packet_in = 1 |
| 9 | return packet_in |
| 10 | |
| 11 | def gen_device(self): |
| 12 | device =lambda: None |
| 13 | device.id = "1" |
| 14 | device.datapath_id = 1 |
| 15 | device.desc = '{mfr_desc: "cord porject" hw_desc: "simualted pon" sw_desc: "simualted pon"\ |
| 16 | serial_num: "2f150d56afa2405eba3ba24e33ce8df9" dp_desc: "n/a"}' |
| 17 | device.switch_features = '{ n_buffers: 256 n_tables: 2 capabilities: 15 }' |
| 18 | device.root_device_id = "a245bd8bb8b8" |
| 19 | return device |
| 20 | |
| 21 | def gen_generic_obj(self): |
| 22 | generic_obj = lambda: None |
| 23 | return generic_obj |
| 24 | |
| 25 | def gen_role_req(self): |
| 26 | req = self.gen_generic_obj() |
| 27 | req.role = ofp.OFPCR_ROLE_MASTER |
| 28 | return req |
| 29 | |
| 30 | def test_handle_flow_mod_request_role_salve(self): |
| 31 | generic_obj = self.gen_generic_obj() |
| 32 | device = self.gen_device() |
| 33 | of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj) |
| 34 | of_proto_handler.role = ofp.OFPCR_ROLE_SLAVE |
| 35 | with self.assertRaises(Exception) as context: |
| 36 | of_proto_handler.handle_flow_mod_request(generic_obj) |
| 37 | print context.exception |
sathishg | 23ac35c | 2017-10-14 03:21:43 +0530 | [diff] [blame] | 38 | self.assertTrue('\'function\' object has no attribute \'send\'' in str(context.exception)) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 39 | |
| 40 | def test_handle_flow_mod_request_role_master(self): |
| 41 | generic_obj = self.gen_generic_obj() |
| 42 | device = self.gen_device() |
| 43 | of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj) |
| 44 | of_proto_handler.role = ofp.OFPCR_ROLE_MASTER |
| 45 | of_proto_handler.handle_flow_mod_request(generic_obj) |
| 46 | |
| 47 | def test_handle_role_request(self): |
| 48 | generic_obj = self.gen_generic_obj() |
| 49 | req = self.gen_role_req() |
| 50 | device = self.gen_device() |
| 51 | of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj) |
| 52 | with self.assertRaises(Exception) as context: |
| 53 | of_proto_handler.handle_role_request(req) |
| 54 | self.assertEqual(of_proto_handler.role,req.role) |
| 55 | print context.exception |
sathishg | 23ac35c | 2017-10-14 03:21:43 +0530 | [diff] [blame] | 56 | self.assertTrue('\'function\' object has no attribute \'generation_is_defined\'' in str(context.exception)) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 57 | |
| 58 | def test_forward_packet_in_role_none(self): |
| 59 | packet_in = self.gen_packet_in() |
| 60 | generic_obj = self.gen_generic_obj() |
| 61 | device = self.gen_device() |
| 62 | of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj) |
| 63 | of_proto_handler.forward_packet_in(packet_in) |
| 64 | |
| 65 | def test_forward_packet_in_role_master(self): |
| 66 | packet_in = self.gen_packet_in() |
| 67 | generic_obj = self.gen_generic_obj() |
| 68 | device = self.gen_device() |
| 69 | of_proto_handler = OpenFlowProtocolHandler(device.datapath_id, device.id, generic_obj, generic_obj, generic_obj) |
| 70 | of_proto_handler.role = ofp.OFPCR_ROLE_MASTER |
| 71 | with self.assertRaises(Exception) as context: |
| 72 | of_proto_handler.forward_packet_in(packet_in) |
| 73 | print context.exception |
sathishg | 23ac35c | 2017-10-14 03:21:43 +0530 | [diff] [blame] | 74 | self.assertTrue('\'function\' object has no attribute \'send\'' in str(context.exception)) |
sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [diff] [blame] | 75 | |
| 76 | if __name__ == '__main__': |
sathishg | 23ac35c | 2017-10-14 03:21:43 +0530 | [diff] [blame] | 77 | main() |