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