pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 1 | |
| 2 | #Testing the basic functionality of SDN-IP |
| 3 | |
| 4 | class SdnIpTest: |
| 5 | def __init__(self): |
| 6 | self.default = '' |
| 7 | |
| 8 | def CASE1(self, main): |
| 9 | |
| 10 | ''' |
| 11 | Test the SDN-IP functionality |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 12 | allRoutes_expected: all expected routes for all BGP peers |
| 13 | routeIntents_expected: all expected MultiPointToSinglePointIntent intents |
| 14 | bgpIntents_expected: expected PointToPointIntent intents |
| 15 | allRoutes_actual: all routes from ONOS LCI |
| 16 | routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI |
| 17 | bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 18 | ''' |
| 19 | import time |
| 20 | import json |
| 21 | from operator import eq |
| 22 | |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 23 | main.case("The test case is to help to setup the TestON environment and test new drivers") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 24 | SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json" |
| 25 | # all expected routes for all BGP peers |
| 26 | allRoutes_expected = [] |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 27 | main.step("Start to generate routes for BGP peer on host1") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 28 | prefixes = main.Quaggacli.generate_prefixes(1, 3) |
| 29 | main.log.info(prefixes) |
| 30 | |
| 31 | # TODO: delete the static prefix below after integration with Demo Mininet script |
| 32 | prefixes = [] |
| 33 | prefixes.append("172.16.30.0/24") |
| 34 | prefixes.append("1.0.0.0/24") |
| 35 | prefixes.append("2.0.0.0/24") |
| 36 | prefixes.append("3.0.0.0/24") |
| 37 | |
| 38 | |
| 39 | for prefix in prefixes: |
| 40 | # generate route with next hop |
| 41 | allRoutes_expected.append(prefix + "/" + "1.1.1.1") |
| 42 | |
| 43 | routeIntents_expected = main.Quaggacli.generate_expected_onePeerRouteIntents(prefixes, "192.168.30.1", "00:00:00:00:03:01", SDNIP_JSON_FILE_PATH) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 44 | |
| 45 | # start to insert routes into the bgp peer |
| 46 | main.step("Start Quagga-cli on host1") |
| 47 | main.Quaggacli.loginQuagga("1.1.1.1") |
| 48 | |
| 49 | main.step("Start to configure Quagga on host1") |
| 50 | main.Quaggacli.enter_config(64513) |
| 51 | |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 52 | main.step("Start to generate and add routes for BGP peer on host1") |
| 53 | routes = main.Quaggacli.generate_prefixes(8, 3) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 54 | main.Quaggacli.add_routes(routes, 1) |
| 55 | |
| 56 | # add generates routes to allRoutes |
| 57 | for route in routes: |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 58 | allRoutes_expected.append(route + "/" + "1.1.1.1") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 59 | |
| 60 | cell_name = main.params['ENV']['cellName'] |
| 61 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 62 | |
| 63 | main.step("Starting ONOS service") |
| 64 | # TODO: start ONOS from Mininet Script |
| 65 | # start_result = main.ONOSbench.onos_start("127.0.0.1") |
| 66 | |
| 67 | main.step("Set cell for ONOS-cli environment") |
| 68 | main.ONOScli.set_cell(cell_name) |
| 69 | |
| 70 | main.step("Start ONOS-cli") |
| 71 | # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver |
| 72 | time.sleep(5) |
| 73 | main.ONOScli.start_onos_cli(ONOS1_ip) |
| 74 | |
| 75 | main.step("Get devices in the network") |
| 76 | list_result = main.ONOScli.devices(json_format=False) |
| 77 | main.log.info(list_result) |
| 78 | |
| 79 | #get all routes inside SDN-IP |
| 80 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 81 | |
| 82 | # parse routes from ONOS CLI |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 83 | allRoutes_actual = main.Quaggacli.extract_actual_routes(get_routes_result) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 84 | |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 85 | main.step("Check routes installed") |
| 86 | main.log.info("Routes expected:") |
| 87 | main.log.info(sorted(allRoutes_expected)) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 88 | main.log.info("Routes get from ONOS CLI:") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 89 | main.log.info(allRoutes_actual) |
| 90 | utilities.assert_equals(expect=sorted(allRoutes_expected), actual=allRoutes_actual, |
| 91 | onpass="***Routes in SDN-IP are correct!***", |
| 92 | onfail="***Routes in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 93 | |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 94 | time.sleep(2) |
| 95 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 96 | |
| 97 | |
| 98 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 99 | # route_intents_expected are generated when generating routes |
| 100 | # get rpoute intents from ONOS CLI |
| 101 | routeIntents_actual = main.Quaggacli.extract_actual_routeIntents(get_intents_result) |
| 102 | main.log.info("MultiPointToSinglePoint intents expected:") |
| 103 | main.log.info(routeIntents_expected) |
| 104 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
| 105 | main.log.info(routeIntents_actual) |
| 106 | utilities.assert_equals(expect=True, actual=eq(routeIntents_expected, routeIntents_actual), |
| 107 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 108 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 109 | |
| 110 | |
| 111 | main.step("Check BGP PointToPointIntent intents installed") |
| 112 | # bgp intents expected |
| 113 | bgpIntents_expected = main.Quaggacli.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
| 114 | # get BGP intents from ONOS CLI |
| 115 | bgpIntents_actual = main.Quaggacli.extract_actual_bgpIntents(get_intents_result) |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 116 | |
| 117 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u',"") |
| 118 | bgpIntents_str_actual = str(bgpIntents_actual) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 119 | main.log.info("PointToPointIntent intents expected:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 120 | main.log.info(bgpIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 121 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 122 | main.log.info(bgpIntents_str_actual) |
| 123 | |
| 124 | utilities.assert_equals(expect=True, actual=eq(bgpIntents_str_expected, bgpIntents_str_actual), |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 125 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 126 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 127 | |
| 128 | #main.step("Test whether Mininet is started") |
| 129 | #main.Mininet2.handle.sendline("xterm host1") |
| 130 | #main.Mininet2.handle.expect("mininet>") |
| 131 | |