pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 1 | from cupshelpers.config import prefix |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 2 | |
| 3 | #Testing the basic functionality of SDN-IP |
| 4 | |
| 5 | class SdnIpTest: |
| 6 | def __init__(self): |
| 7 | self.default = '' |
| 8 | |
| 9 | def CASE1(self, main): |
| 10 | |
| 11 | ''' |
| 12 | Test the SDN-IP functionality |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 13 | allRoutes_expected: all expected routes for all BGP peers |
| 14 | routeIntents_expected: all expected MultiPointToSinglePointIntent intents |
| 15 | bgpIntents_expected: expected PointToPointIntent intents |
| 16 | allRoutes_actual: all routes from ONOS LCI |
| 17 | routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI |
| 18 | bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 19 | ''' |
| 20 | import time |
| 21 | import json |
| 22 | from operator import eq |
| 23 | |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 24 | 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] | 25 | SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json" |
| 26 | # all expected routes for all BGP peers |
| 27 | allRoutes_expected = [] |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 28 | main.step("Start to generate routes for all BGP peers") |
| 29 | #bgpPeerHosts = [] |
| 30 | #for i in range(3, 5): |
| 31 | # bgpPeerHosts.append("host" + str(i)) |
| 32 | #main.log.info("BGP Peer Hosts are:" + bgpPeerHosts) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 33 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 34 | #for i in range(3, 5): |
| 35 | # QuaggaCliHost = "QuaggaCliHost" + str(i) |
| 36 | # prefixes = main.QuaggaCliHost.generate_prefixes(3, 10) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 37 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 38 | # main.log.info(prefixes) |
| 39 | #allRoutes_expected.append(prefixes) |
| 40 | main.log.info("Generate prefixes for host3") |
| 41 | prefixes_host3 = main.QuaggaCliHost3.generate_prefixes(3, 10) |
| 42 | main.log.info(prefixes_host3) |
| 43 | # generate route with next hop |
| 44 | for prefix in prefixes_host3: |
| 45 | allRoutes_expected.append(prefix + "/" + "192.168.20.1") |
| 46 | routeIntents_expected_host3 = main.QuaggaCliHost3.generate_expected_onePeerRouteIntents(prefixes_host3, "192.168.20.1", "00:00:00:00:02:02", SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 47 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 48 | main.log.info("Generate prefixes for host4") |
| 49 | prefixes_host4 = main.QuaggaCliHost4.generate_prefixes(4, 10) |
| 50 | main.log.info(prefixes_host4) |
| 51 | # generate route with next hop |
| 52 | for prefix in prefixes_host4: |
| 53 | allRoutes_expected.append(prefix + "/" + "192.168.30.1") |
| 54 | routeIntents_expected_host4 = main.QuaggaCliHost4.generate_expected_onePeerRouteIntents(prefixes_host4, "192.168.30.1", "00:00:00:00:03:01", SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 55 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 56 | routeIntents_expected = routeIntents_expected_host3 + routeIntents_expected_host4 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 57 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 58 | main.step("Login all BGP peers and add routes into peers") |
| 59 | main.log.info("Login Quagga CLI on host3") |
| 60 | main.QuaggaCliHost3.loginQuagga("1.168.30.2") |
| 61 | main.log.info("Enter configuration model of Quagga CLI on host3") |
| 62 | main.QuaggaCliHost3.enter_config(64514) |
| 63 | main.log.info("Add routes to Quagga on host3") |
| 64 | main.QuaggaCliHost3.add_routes(prefixes_host3, 1) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 65 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 66 | main.log.info("Login Quagga CLI on host4") |
| 67 | main.QuaggaCliHost4.loginQuagga("1.168.30.3") |
| 68 | main.log.info("Enter configuration model of Quagga CLI on host4") |
| 69 | main.QuaggaCliHost4.enter_config(64516) |
| 70 | main.log.info("Add routes to Quagga on host4") |
| 71 | main.QuaggaCliHost4.add_routes(prefixes_host4, 1) |
| 72 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 73 | |
| 74 | cell_name = main.params['ENV']['cellName'] |
| 75 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 76 | |
| 77 | main.step("Starting ONOS service") |
| 78 | # TODO: start ONOS from Mininet Script |
| 79 | # start_result = main.ONOSbench.onos_start("127.0.0.1") |
| 80 | |
| 81 | main.step("Set cell for ONOS-cli environment") |
| 82 | main.ONOScli.set_cell(cell_name) |
| 83 | |
| 84 | main.step("Start ONOS-cli") |
| 85 | # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver |
| 86 | time.sleep(5) |
| 87 | main.ONOScli.start_onos_cli(ONOS1_ip) |
| 88 | |
| 89 | main.step("Get devices in the network") |
| 90 | list_result = main.ONOScli.devices(json_format=False) |
| 91 | main.log.info(list_result) |
| 92 | |
| 93 | #get all routes inside SDN-IP |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 94 | get_routes_result = main.ONOScli.routes(json_format=True) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 95 | |
| 96 | # parse routes from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 97 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 98 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 99 | allRoutes_str_expected = str(sorted(allRoutes_expected)) |
| 100 | allRoutes_str_actual = str(allRoutes_actual).replace('u',"") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 101 | main.step("Check routes installed") |
| 102 | main.log.info("Routes expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 103 | main.log.info(allRoutes_str_expected) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 104 | main.log.info("Routes get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 105 | main.log.info(allRoutes_str_actual) |
| 106 | utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual, |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 107 | onpass="***Routes in SDN-IP are correct!***", |
| 108 | onfail="***Routes in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 109 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 110 | time.sleep(20) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 111 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 112 | |
| 113 | |
| 114 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 115 | # route_intents_expected are generated when generating routes |
| 116 | # get rpoute intents from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 117 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 118 | routeIntents_str_expected = str(sorted(routeIntents_expected)) |
| 119 | routeIntents_str_actual = str(routeIntents_actual).replace('u',"") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 120 | main.log.info("MultiPointToSinglePoint intents expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 121 | main.log.info(routeIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 122 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 123 | main.log.info(routeIntents_str_actual) |
| 124 | utilities.assert_equals(expect=True, actual=eq(routeIntents_str_expected, routeIntents_str_actual), |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 125 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 126 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 127 | |
| 128 | |
| 129 | main.step("Check BGP PointToPointIntent intents installed") |
| 130 | # bgp intents expected |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 131 | bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 132 | # get BGP intents from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 133 | bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result) |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 134 | |
| 135 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u',"") |
| 136 | bgpIntents_str_actual = str(bgpIntents_actual) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 137 | main.log.info("PointToPointIntent intents expected:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 138 | main.log.info(bgpIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 139 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 140 | main.log.info(bgpIntents_str_actual) |
| 141 | |
| 142 | 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] | 143 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 144 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 145 | |
| 146 | #main.step("Test whether Mininet is started") |
| 147 | #main.Mininet2.handle.sendline("xterm host1") |
| 148 | #main.Mininet2.handle.expect("mininet>") |
| 149 | |