pingping-lin | 01355a6 | 2014-12-02 20:58: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 |
pingping-lin | 01355a6 | 2014-12-02 20:58:14 -0800 | [diff] [blame] | 24 | from time import localtime, strftime |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 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 | bc23094 | 2014-12-03 18:36:27 -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 | bc23094 | 2014-12-03 18:36:27 -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 | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 74 | |
| 75 | cell_name = main.params['ENV']['cellName'] |
| 76 | ONOS1_ip = main.params['CTRL']['ip1'] |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 77 | main.step("Set cell for ONOS-cli environment") |
| 78 | main.ONOScli.set_cell(cell_name) |
| 79 | verify_result = main.ONOSbench.verify_cell() |
| 80 | main.log.report("Removing raft logs") |
| 81 | main.ONOSbench.onos_remove_raft_logs() |
| 82 | main.log.report("Uninstalling ONOS") |
| 83 | main.ONOSbench.onos_uninstall(ONOS1_ip) |
| 84 | main.step("Creating ONOS package") |
| 85 | package_result = main.ONOSbench.onos_package() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 86 | |
| 87 | main.step("Starting ONOS service") |
| 88 | # TODO: start ONOS from Mininet Script |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 89 | #start_result = main.ONOSbench.onos_start("127.0.0.1") |
| 90 | main.step("Installing ONOS package") |
| 91 | onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip) |
| 92 | |
| 93 | main.step("Checking if ONOS is up yet") |
| 94 | time.sleep(60) |
| 95 | onos1_isup = main.ONOSbench.isup(ONOS1_ip) |
| 96 | if not onos1_isup: |
| 97 | main.log.report("ONOS1 didn't start!") |
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 | main.step("Start ONOS-cli") |
| 100 | # 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] | 101 | |
| 102 | main.ONOScli.start_onos_cli(ONOS1_ip) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 103 | |
| 104 | main.step("Get devices in the network") |
| 105 | list_result = main.ONOScli.devices(json_format=False) |
| 106 | main.log.info(list_result) |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 107 | time.sleep(10) |
| 108 | main.log.info("Installing sdn-ip feature") |
| 109 | main.ONOScli.feature_install("onos-app-sdnip") |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame^] | 110 | time.sleep(10) |
| 111 | main.step("Login all BGP peers and add routes into peers") |
| 112 | main.log.info("Login Quagga CLI on host3") |
| 113 | main.QuaggaCliHost3.loginQuagga("1.168.30.2") |
| 114 | main.log.info("Enter configuration model of Quagga CLI on host3") |
| 115 | main.QuaggaCliHost3.enter_config(64514) |
| 116 | main.log.info("Add routes to Quagga on host3") |
| 117 | main.QuaggaCliHost3.add_routes(prefixes_host3, 1) |
| 118 | |
| 119 | main.log.info("Login Quagga CLI on host4") |
| 120 | main.QuaggaCliHost4.loginQuagga("1.168.30.3") |
| 121 | main.log.info("Enter configuration model of Quagga CLI on host4") |
| 122 | main.QuaggaCliHost4.enter_config(64516) |
| 123 | main.log.info("Add routes to Quagga on host4") |
| 124 | main.QuaggaCliHost4.add_routes(prefixes_host4, 1) |
| 125 | time.sleep(60) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 126 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 127 | # get all routes inside SDN-IP |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 128 | get_routes_result = main.ONOScli.routes(json_format=True) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 129 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 130 | # parse routes from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 131 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 132 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 133 | allRoutes_str_expected = str(sorted(allRoutes_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 134 | allRoutes_str_actual = str(allRoutes_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 135 | main.step("Check routes installed") |
| 136 | main.log.info("Routes expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 137 | main.log.info(allRoutes_str_expected) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 138 | main.log.info("Routes get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 139 | main.log.info(allRoutes_str_actual) |
| 140 | utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual, |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 141 | onpass="***Routes in SDN-IP are correct!***", |
| 142 | onfail="***Routes in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 143 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 144 | time.sleep(20) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 145 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 146 | |
| 147 | |
| 148 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 149 | # route_intents_expected are generated when generating routes |
| 150 | # get rpoute intents from ONOS CLI |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 151 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 152 | routeIntents_str_expected = str(sorted(routeIntents_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 153 | routeIntents_str_actual = str(routeIntents_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 154 | main.log.info("MultiPointToSinglePoint intents expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 155 | main.log.info(routeIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 156 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 157 | main.log.info(routeIntents_str_actual) |
| 158 | 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] | 159 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 160 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 161 | |
| 162 | |
| 163 | main.step("Check BGP PointToPointIntent intents installed") |
| 164 | # bgp intents expected |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 165 | bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 166 | # get BGP intents from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 167 | bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result) |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 168 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 169 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u', "") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 170 | bgpIntents_str_actual = str(bgpIntents_actual) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 171 | main.log.info("PointToPointIntent intents expected:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 172 | main.log.info(bgpIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 173 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 174 | main.log.info(bgpIntents_str_actual) |
| 175 | |
| 176 | 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] | 177 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 178 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 179 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 180 | #============================= Ping Test ======================== |
| 181 | # wait until all MultiPointToSinglePoint |
| 182 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 183 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame^] | 184 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-before-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt" |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 185 | 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] | 186 | main.log.info(ping_test_results) |
| 187 | |
| 188 | # ping test |
| 189 | |
| 190 | #============================= Deleting Routes ================== |
| 191 | main.step("Check deleting routes installed") |
| 192 | main.QuaggaCliHost3.delete_routes(prefixes_host3, 1) |
| 193 | main.QuaggaCliHost4.delete_routes(prefixes_host4, 1) |
| 194 | |
| 195 | # main.log.info("main.ONOScli.get_routes_num() = " ) |
| 196 | # main.log.info(main.ONOScli.get_routes_num()) |
| 197 | # utilities.assert_equals(expect = "Total SDN-IP routes = 1", actual= main.ONOScli.get_routes_num(), |
| 198 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 199 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
| 200 | main.log.info("allRoutes_actual = ") |
| 201 | main.log.info(allRoutes_actual) |
| 202 | |
| 203 | utilities.assert_equals(expect="[]", actual=str(allRoutes_actual), |
| 204 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 205 | onfail="***Routes number in SDN-IP is not 0, wrong!***") |
| 206 | |
| 207 | main.step("Check intents after deleting routes") |
| 208 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 209 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 210 | main.log.info("main.ONOScli.intents()= ") |
| 211 | main.log.info(routeIntents_actual) |
| 212 | utilities.assert_equals(expect="[]", actual=str(routeIntents_actual), |
| 213 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***", |
| 214 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***") |
| 215 | |
| 216 | |
| 217 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 218 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame^] | 219 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-after-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt" |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 220 | 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] | 221 | main.log.info(ping_test_results) |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 222 | time.sleep(30) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 223 | |
| 224 | # main.step("Test whether Mininet is started") |
| 225 | # main.Mininet2.handle.sendline("xterm host1") |
| 226 | # main.Mininet2.handle.expect("mininet>") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 227 | |