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 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 3 | # Testing the basic functionality of SDN-IP |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 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 |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 23 | # from datetime import datetime |
| 24 | from time import gmtime, strftime |
| 25 | |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 26 | 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] | 27 | SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json" |
| 28 | # all expected routes for all BGP peers |
| 29 | allRoutes_expected = [] |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 30 | main.step("Start to generate routes for all BGP peers") |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 31 | # bgpPeerHosts = [] |
| 32 | # for i in range(3, 5): |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 33 | # bgpPeerHosts.append("host" + str(i)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 34 | # main.log.info("BGP Peer Hosts are:" + bgpPeerHosts) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 35 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 36 | # for i in range(3, 5): |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 37 | # QuaggaCliHost = "QuaggaCliHost" + str(i) |
| 38 | # prefixes = main.QuaggaCliHost.generate_prefixes(3, 10) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 39 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 40 | # main.log.info(prefixes) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 41 | # allRoutes_expected.append(prefixes) |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 42 | main.log.info("Generate prefixes for host3") |
| 43 | prefixes_host3 = main.QuaggaCliHost3.generate_prefixes(3, 10) |
| 44 | main.log.info(prefixes_host3) |
| 45 | # generate route with next hop |
| 46 | for prefix in prefixes_host3: |
| 47 | allRoutes_expected.append(prefix + "/" + "192.168.20.1") |
| 48 | 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] | 49 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 50 | main.log.info("Generate prefixes for host4") |
| 51 | prefixes_host4 = main.QuaggaCliHost4.generate_prefixes(4, 10) |
| 52 | main.log.info(prefixes_host4) |
| 53 | # generate route with next hop |
| 54 | for prefix in prefixes_host4: |
| 55 | allRoutes_expected.append(prefix + "/" + "192.168.30.1") |
| 56 | 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] | 57 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 58 | routeIntents_expected = routeIntents_expected_host3 + routeIntents_expected_host4 |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 59 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 60 | main.step("Login all BGP peers and add routes into peers") |
| 61 | main.log.info("Login Quagga CLI on host3") |
| 62 | main.QuaggaCliHost3.loginQuagga("1.168.30.2") |
| 63 | main.log.info("Enter configuration model of Quagga CLI on host3") |
| 64 | main.QuaggaCliHost3.enter_config(64514) |
| 65 | main.log.info("Add routes to Quagga on host3") |
| 66 | main.QuaggaCliHost3.add_routes(prefixes_host3, 1) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 67 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 68 | main.log.info("Login Quagga CLI on host4") |
| 69 | main.QuaggaCliHost4.loginQuagga("1.168.30.3") |
| 70 | main.log.info("Enter configuration model of Quagga CLI on host4") |
| 71 | main.QuaggaCliHost4.enter_config(64516) |
| 72 | main.log.info("Add routes to Quagga on host4") |
| 73 | main.QuaggaCliHost4.add_routes(prefixes_host4, 1) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 74 | time.sleep(30) |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 75 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 76 | |
| 77 | cell_name = main.params['ENV']['cellName'] |
| 78 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 79 | |
| 80 | main.step("Starting ONOS service") |
| 81 | # TODO: start ONOS from Mininet Script |
| 82 | # start_result = main.ONOSbench.onos_start("127.0.0.1") |
| 83 | |
| 84 | main.step("Set cell for ONOS-cli environment") |
| 85 | main.ONOScli.set_cell(cell_name) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 86 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 87 | main.step("Start ONOS-cli") |
| 88 | # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 89 | |
| 90 | main.ONOScli.start_onos_cli(ONOS1_ip) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 91 | |
| 92 | main.step("Get devices in the network") |
| 93 | list_result = main.ONOScli.devices(json_format=False) |
| 94 | main.log.info(list_result) |
| 95 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 96 | # get all routes inside SDN-IP |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 97 | get_routes_result = main.ONOScli.routes(json_format=True) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 98 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 99 | # parse routes from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 100 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 101 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 102 | allRoutes_str_expected = str(sorted(allRoutes_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 103 | allRoutes_str_actual = str(allRoutes_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 104 | main.step("Check routes installed") |
| 105 | main.log.info("Routes expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 106 | main.log.info(allRoutes_str_expected) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 107 | main.log.info("Routes get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 108 | main.log.info(allRoutes_str_actual) |
| 109 | utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual, |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 110 | onpass="***Routes in SDN-IP are correct!***", |
| 111 | onfail="***Routes in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 112 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 113 | time.sleep(20) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 114 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 115 | |
| 116 | |
| 117 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 118 | # route_intents_expected are generated when generating routes |
| 119 | # get rpoute intents from ONOS CLI |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 120 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 121 | routeIntents_str_expected = str(sorted(routeIntents_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 122 | routeIntents_str_actual = str(routeIntents_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 123 | main.log.info("MultiPointToSinglePoint intents expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 124 | main.log.info(routeIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 125 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 126 | main.log.info(routeIntents_str_actual) |
| 127 | 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] | 128 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 129 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 130 | |
| 131 | |
| 132 | main.step("Check BGP PointToPointIntent intents installed") |
| 133 | # bgp intents expected |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 134 | bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 135 | # get BGP intents from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 136 | bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result) |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 137 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 138 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u', "") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 139 | bgpIntents_str_actual = str(bgpIntents_actual) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 140 | main.log.info("PointToPointIntent intents expected:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 141 | main.log.info(bgpIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 142 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 143 | main.log.info(bgpIntents_str_actual) |
| 144 | |
| 145 | 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] | 146 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 147 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 148 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 149 | #============================= Ping Test ======================== |
| 150 | # wait until all MultiPointToSinglePoint |
| 151 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame^] | 152 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 153 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-results-before-delete-routes-" + strftime("%Y-%m-%d-%H:%M:%S", gmtime()) + ".txt" |
| 154 | ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 155 | main.log.info(ping_test_results) |
| 156 | |
| 157 | # ping test |
| 158 | |
| 159 | #============================= Deleting Routes ================== |
| 160 | main.step("Check deleting routes installed") |
| 161 | main.QuaggaCliHost3.delete_routes(prefixes_host3, 1) |
| 162 | main.QuaggaCliHost4.delete_routes(prefixes_host4, 1) |
| 163 | |
| 164 | # main.log.info("main.ONOScli.get_routes_num() = " ) |
| 165 | # main.log.info(main.ONOScli.get_routes_num()) |
| 166 | # utilities.assert_equals(expect = "Total SDN-IP routes = 1", actual= main.ONOScli.get_routes_num(), |
| 167 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 168 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
| 169 | main.log.info("allRoutes_actual = ") |
| 170 | main.log.info(allRoutes_actual) |
| 171 | |
| 172 | utilities.assert_equals(expect="[]", actual=str(allRoutes_actual), |
| 173 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 174 | onfail="***Routes number in SDN-IP is not 0, wrong!***") |
| 175 | |
| 176 | main.step("Check intents after deleting routes") |
| 177 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 178 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 179 | main.log.info("main.ONOScli.intents()= ") |
| 180 | main.log.info(routeIntents_actual) |
| 181 | utilities.assert_equals(expect="[]", actual=str(routeIntents_actual), |
| 182 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***", |
| 183 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***") |
| 184 | |
| 185 | |
| 186 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame^] | 187 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 188 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-results-after-delete-routes-" + strftime("%Y-%m-%d-%H:%M:%S", gmtime()) + ".txt" |
| 189 | ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 190 | main.log.info(ping_test_results) |
| 191 | |
| 192 | # main.step("Test whether Mininet is started") |
| 193 | # main.Mininet2.handle.sendline("xterm host1") |
| 194 | # main.Mininet2.handle.expect("mininet>") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 195 | |