pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -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 |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 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 | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 60 | |
| 61 | cell_name = main.params['ENV']['cellName'] |
| 62 | ONOS1_ip = main.params['CTRL']['ip1'] |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 63 | main.step("Set cell for ONOS-cli environment") |
| 64 | main.ONOScli.set_cell(cell_name) |
| 65 | verify_result = main.ONOSbench.verify_cell() |
| 66 | main.log.report("Removing raft logs") |
| 67 | main.ONOSbench.onos_remove_raft_logs() |
| 68 | main.log.report("Uninstalling ONOS") |
| 69 | main.ONOSbench.onos_uninstall(ONOS1_ip) |
| 70 | main.step("Creating ONOS package") |
| 71 | package_result = main.ONOSbench.onos_package() |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 72 | |
| 73 | main.step("Starting ONOS service") |
| 74 | # TODO: start ONOS from Mininet Script |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 75 | # start_result = main.ONOSbench.onos_start("127.0.0.1") |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 76 | main.step("Installing ONOS package") |
| 77 | onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip) |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 78 | |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 79 | main.step("Checking if ONOS is up yet") |
| 80 | time.sleep(60) |
| 81 | onos1_isup = main.ONOSbench.isup(ONOS1_ip) |
| 82 | if not onos1_isup: |
| 83 | main.log.report("ONOS1 didn't start!") |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 84 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 85 | main.step("Start ONOS-cli") |
| 86 | # 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] | 87 | |
| 88 | main.ONOScli.start_onos_cli(ONOS1_ip) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 89 | |
| 90 | main.step("Get devices in the network") |
| 91 | list_result = main.ONOScli.devices(json_format=False) |
| 92 | main.log.info(list_result) |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 93 | time.sleep(10) |
| 94 | main.log.info("Installing sdn-ip feature") |
| 95 | main.ONOScli.feature_install("onos-app-sdnip") |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame] | 96 | time.sleep(10) |
| 97 | main.step("Login all BGP peers and add routes into peers") |
| 98 | main.log.info("Login Quagga CLI on host3") |
| 99 | main.QuaggaCliHost3.loginQuagga("1.168.30.2") |
| 100 | main.log.info("Enter configuration model of Quagga CLI on host3") |
| 101 | main.QuaggaCliHost3.enter_config(64514) |
| 102 | main.log.info("Add routes to Quagga on host3") |
| 103 | main.QuaggaCliHost3.add_routes(prefixes_host3, 1) |
| 104 | |
| 105 | main.log.info("Login Quagga CLI on host4") |
| 106 | main.QuaggaCliHost4.loginQuagga("1.168.30.3") |
| 107 | main.log.info("Enter configuration model of Quagga CLI on host4") |
| 108 | main.QuaggaCliHost4.enter_config(64516) |
| 109 | main.log.info("Add routes to Quagga on host4") |
| 110 | main.QuaggaCliHost4.add_routes(prefixes_host4, 1) |
| 111 | time.sleep(60) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 112 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 113 | # get all routes inside SDN-IP |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 114 | get_routes_result = main.ONOScli.routes(json_format=True) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 115 | |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 116 | # parse routes from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 117 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 118 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 119 | allRoutes_str_expected = str(sorted(allRoutes_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 120 | allRoutes_str_actual = str(allRoutes_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 121 | main.step("Check routes installed") |
| 122 | main.log.info("Routes expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 123 | main.log.info(allRoutes_str_expected) |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 124 | main.log.info("Routes get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 125 | main.log.info(allRoutes_str_actual) |
| 126 | utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual, |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 127 | onpass="***Routes in SDN-IP are correct!***", |
| 128 | onfail="***Routes in SDN-IP are wrong!***") |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 129 | if(eq(allRoutes_str_expected, allRoutes_str_actual)): |
| 130 | main.log.report("***Routes in SDN-IP after adding routes are correct!***") |
| 131 | else: |
| 132 | main.log.report("***Routes in SDN-IP after adding routes are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 133 | |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 134 | time.sleep(20) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 135 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 136 | |
| 137 | |
| 138 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 139 | # route_intents_expected are generated when generating routes |
| 140 | # get rpoute intents from ONOS CLI |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 141 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 142 | routeIntents_str_expected = str(sorted(routeIntents_expected)) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 143 | routeIntents_str_actual = str(routeIntents_actual).replace('u', "") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 144 | main.log.info("MultiPointToSinglePoint intents expected:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 145 | main.log.info(routeIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 146 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 147 | main.log.info(routeIntents_str_actual) |
| 148 | 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] | 149 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 150 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 151 | |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 152 | if(eq(routeIntents_str_expected, routeIntents_str_actual)): |
| 153 | main.log.report("***MultiPointToSinglePoint Intents before deleting routes correct!***") |
| 154 | else: |
| 155 | main.log.report("***MultiPointToSinglePoint Intents before deleting routes wrong!***") |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 156 | |
| 157 | main.step("Check BGP PointToPointIntent intents installed") |
| 158 | # bgp intents expected |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 159 | bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 160 | # get BGP intents from ONOS CLI |
pingping-lin | 36fbe80 | 2014-11-25 16:01:14 -0800 | [diff] [blame] | 161 | bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result) |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 162 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 163 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u', "") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 164 | bgpIntents_str_actual = str(bgpIntents_actual) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 165 | main.log.info("PointToPointIntent intents expected:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 166 | main.log.info(bgpIntents_str_expected) |
pingping-lin | 6f6332e | 2014-11-19 19:13:58 -0800 | [diff] [blame] | 167 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
pingping-lin | 3228e13 | 2014-11-20 17:49:02 -0800 | [diff] [blame] | 168 | main.log.info(bgpIntents_str_actual) |
| 169 | |
| 170 | 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] | 171 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 172 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 173 | |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 174 | |
| 175 | if (eq(bgpIntents_str_expected, bgpIntents_str_actual)): |
| 176 | main.log.report("***PointToPointIntent Intents in SDN-IP are correct!***") |
| 177 | else: |
| 178 | main.log.report("***PointToPointIntent Intents in SDN-IP are wrong!***") |
| 179 | |
| 180 | |
| 181 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 182 | #============================= Ping Test ======================== |
| 183 | # wait until all MultiPointToSinglePoint |
| 184 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 185 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame] | 186 | 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] | 187 | 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] | 188 | main.log.info(ping_test_results) |
| 189 | |
| 190 | # ping test |
| 191 | |
| 192 | #============================= Deleting Routes ================== |
| 193 | main.step("Check deleting routes installed") |
| 194 | main.QuaggaCliHost3.delete_routes(prefixes_host3, 1) |
| 195 | main.QuaggaCliHost4.delete_routes(prefixes_host4, 1) |
| 196 | |
| 197 | # main.log.info("main.ONOScli.get_routes_num() = " ) |
| 198 | # main.log.info(main.ONOScli.get_routes_num()) |
| 199 | # utilities.assert_equals(expect = "Total SDN-IP routes = 1", actual= main.ONOScli.get_routes_num(), |
| 200 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 201 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
| 202 | main.log.info("allRoutes_actual = ") |
| 203 | main.log.info(allRoutes_actual) |
| 204 | |
| 205 | utilities.assert_equals(expect="[]", actual=str(allRoutes_actual), |
| 206 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 207 | onfail="***Routes number in SDN-IP is not 0, wrong!***") |
| 208 | |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 209 | if(eq(allRoutes_str_expected, allRoutes_str_actual)): |
| 210 | main.log.report("***Routes in SDN-IP after deleting correct!***") |
| 211 | else: |
| 212 | main.log.report("***Routes in SDN-IP after deleting wrong!***") |
| 213 | |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 214 | main.step("Check intents after deleting routes") |
| 215 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 216 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 217 | main.log.info("main.ONOScli.intents()= ") |
| 218 | main.log.info(routeIntents_actual) |
| 219 | utilities.assert_equals(expect="[]", actual=str(routeIntents_actual), |
| 220 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***", |
| 221 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***") |
| 222 | |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 223 | if(eq(routeIntents_str_expected, routeIntents_str_actual)): |
| 224 | main.log.report("***MultiPointToSinglePoint Intents after deleting routes correct!***") |
| 225 | else: |
| 226 | main.log.report("***MultiPointToSinglePoint Intents after deleting routes wrong!***") |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 227 | |
| 228 | time.sleep(20) |
pingping-lin | dd3b0e4 | 2014-12-02 11:46:54 -0800 | [diff] [blame] | 229 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
pingping-lin | bc23094 | 2014-12-03 18:36:27 -0800 | [diff] [blame] | 230 | 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] | 231 | 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] | 232 | main.log.info(ping_test_results) |
pingping-lin | 81ef065 | 2014-12-02 21:39:23 -0800 | [diff] [blame] | 233 | time.sleep(30) |
pingping-lin | c6b86fa | 2014-12-01 16:18:10 -0800 | [diff] [blame] | 234 | |
| 235 | # main.step("Test whether Mininet is started") |
| 236 | # main.Mininet2.handle.sendline("xterm host1") |
| 237 | # main.Mininet2.handle.expect("mininet>") |
pingping-lin | 8b306ac | 2014-11-17 18:13:51 -0800 | [diff] [blame] | 238 | |
pingping-lin | 3d87a13 | 2014-12-04 14:22:49 -0800 | [diff] [blame] | 239 | |
| 240 | def CASE2(self, main): |
| 241 | |
| 242 | ''' |
| 243 | Test the SDN-IP functionality |
| 244 | allRoutes_expected: all expected routes for all BGP peers |
| 245 | routeIntents_expected: all expected MultiPointToSinglePointIntent intents |
| 246 | bgpIntents_expected: expected PointToPointIntent intents |
| 247 | allRoutes_actual: all routes from ONOS LCI |
| 248 | routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI |
| 249 | bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI |
| 250 | ''' |
| 251 | import time |
| 252 | import json |
| 253 | from operator import eq |
| 254 | from time import localtime, strftime |
| 255 | |
| 256 | main.case("The test case is to help to setup the TestON environment and test new drivers") |
| 257 | SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json" |
| 258 | # all expected routes for all BGP peers |
| 259 | allRoutes_expected = [] |
| 260 | main.step("Start to generate routes for all BGP peers") |
| 261 | |
| 262 | main.log.info("Generate prefixes for host3") |
| 263 | prefixes_host3 = main.QuaggaCliHost3.generate_prefixes(3, 10) |
| 264 | main.log.info(prefixes_host3) |
| 265 | # generate route with next hop |
| 266 | for prefix in prefixes_host3: |
| 267 | allRoutes_expected.append(prefix + "/" + "192.168.20.1") |
| 268 | routeIntents_expected_host3 = main.QuaggaCliHost3.generate_expected_onePeerRouteIntents(prefixes_host3, "192.168.20.1", "00:00:00:00:02:02", SDNIP_JSON_FILE_PATH) |
| 269 | |
| 270 | main.log.info("Generate prefixes for host4") |
| 271 | prefixes_host4 = main.QuaggaCliHost4.generate_prefixes(4, 10) |
| 272 | main.log.info(prefixes_host4) |
| 273 | # generate route with next hop |
| 274 | for prefix in prefixes_host4: |
| 275 | allRoutes_expected.append(prefix + "/" + "192.168.30.1") |
| 276 | routeIntents_expected_host4 = main.QuaggaCliHost4.generate_expected_onePeerRouteIntents(prefixes_host4, "192.168.30.1", "00:00:00:00:03:01", SDNIP_JSON_FILE_PATH) |
| 277 | |
| 278 | routeIntents_expected = routeIntents_expected_host3 + routeIntents_expected_host4 |
| 279 | |
| 280 | main.log.report("Removing raft logs") |
| 281 | main.ONOSbench.onos_remove_raft_logs() |
| 282 | main.log.report("Uninstalling ONOS") |
| 283 | main.ONOSbench.onos_uninstall(ONOS1_ip) |
| 284 | |
| 285 | cell_name = main.params['ENV']['cellName'] |
| 286 | ONOS1_ip = main.params['CTRL']['ip1'] |
| 287 | main.step("Set cell for ONOS-cli environment") |
| 288 | main.ONOScli.set_cell(cell_name) |
| 289 | verify_result = main.ONOSbench.verify_cell() |
| 290 | #main.log.report("Removing raft logs") |
| 291 | #main.ONOSbench.onos_remove_raft_logs() |
| 292 | #main.log.report("Uninstalling ONOS") |
| 293 | #main.ONOSbench.onos_uninstall(ONOS1_ip) |
| 294 | main.step("Creating ONOS package") |
| 295 | package_result = main.ONOSbench.onos_package() |
| 296 | |
| 297 | main.step("Installing ONOS package") |
| 298 | onos1_install_result = main.ONOSbench.onos_install(options="-f", node=ONOS1_ip) |
| 299 | |
| 300 | main.step("Checking if ONOS is up yet") |
| 301 | time.sleep(60) |
| 302 | onos1_isup = main.ONOSbench.isup(ONOS1_ip) |
| 303 | if not onos1_isup: |
| 304 | main.log.report("ONOS1 didn't start!") |
| 305 | |
| 306 | main.step("Start ONOS-cli") |
| 307 | main.ONOScli.start_onos_cli(ONOS1_ip) |
| 308 | |
| 309 | main.step("Get devices in the network") |
| 310 | list_result = main.ONOScli.devices(json_format=False) |
| 311 | main.log.info(list_result) |
| 312 | time.sleep(10) |
| 313 | main.log.info("Installing sdn-ip feature") |
| 314 | main.ONOScli.feature_install("onos-app-sdnip") |
| 315 | time.sleep(10) |
| 316 | |
| 317 | |
| 318 | main.step("Check BGP PointToPointIntent intents installed") |
| 319 | # bgp intents expected |
| 320 | bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH) |
| 321 | # get BGP intents from ONOS CLI |
| 322 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 323 | bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result) |
| 324 | |
| 325 | bgpIntents_str_expected = str(bgpIntents_expected).replace('u', "") |
| 326 | bgpIntents_str_actual = str(bgpIntents_actual) |
| 327 | main.log.info("PointToPointIntent intents expected:") |
| 328 | main.log.info(bgpIntents_str_expected) |
| 329 | main.log.info("PointToPointIntent intents get from ONOS CLI:") |
| 330 | main.log.info(bgpIntents_str_actual) |
| 331 | |
| 332 | utilities.assert_equals(expect=True, actual=eq(bgpIntents_str_expected, bgpIntents_str_actual), |
| 333 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 334 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***") |
| 335 | |
| 336 | if (eq(bgpIntents_str_expected, bgpIntents_str_actual)): |
| 337 | main.log.report("***PointToPointIntent Intents in SDN-IP are correct!***") |
| 338 | else: |
| 339 | main.log.report("***PointToPointIntent Intents in SDN-IP are wrong!***") |
| 340 | |
| 341 | |
| 342 | allRoutes_str_expected = str(sorted(allRoutes_expected)) |
| 343 | routeIntents_str_expected = str(sorted(routeIntents_expected)) |
| 344 | ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 345 | # round_num = 0; |
| 346 | # while(True): |
| 347 | for round_num in range(1, 6): |
| 348 | # round = round + 1; |
| 349 | main.log.report("The Round " + str(round_num) + " test starts........................................") |
| 350 | |
| 351 | main.step("Login all BGP peers and add routes into peers") |
| 352 | main.log.info("Login Quagga CLI on host3") |
| 353 | main.QuaggaCliHost3.loginQuagga("1.168.30.2") |
| 354 | main.log.info("Enter configuration model of Quagga CLI on host3") |
| 355 | main.QuaggaCliHost3.enter_config(64514) |
| 356 | main.log.info("Add routes to Quagga on host3") |
| 357 | main.QuaggaCliHost3.add_routes(prefixes_host3, 1) |
| 358 | |
| 359 | main.log.info("Login Quagga CLI on host4") |
| 360 | main.QuaggaCliHost4.loginQuagga("1.168.30.3") |
| 361 | main.log.info("Enter configuration model of Quagga CLI on host4") |
| 362 | main.QuaggaCliHost4.enter_config(64516) |
| 363 | main.log.info("Add routes to Quagga on host4") |
| 364 | main.QuaggaCliHost4.add_routes(prefixes_host4, 1) |
| 365 | time.sleep(60) |
| 366 | |
| 367 | # get all routes inside SDN-IP |
| 368 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 369 | |
| 370 | # parse routes from ONOS CLI |
| 371 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
| 372 | |
| 373 | # allRoutes_str_expected = str(sorted(allRoutes_expected)) |
| 374 | allRoutes_str_actual = str(allRoutes_actual).replace('u', "") |
| 375 | main.step("Check routes installed") |
| 376 | main.log.info("Routes expected:") |
| 377 | main.log.info(allRoutes_str_expected) |
| 378 | main.log.info("Routes get from ONOS CLI:") |
| 379 | main.log.info(allRoutes_str_actual) |
| 380 | utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual, |
| 381 | onpass="***Routes in SDN-IP are correct!***", |
| 382 | onfail="***Routes in SDN-IP are wrong!***") |
| 383 | if(eq(allRoutes_str_expected, allRoutes_str_actual)): |
| 384 | main.log.report("***Routes in SDN-IP after adding correct!***") |
| 385 | else: |
| 386 | main.log.report("***Routes in SDN-IP after adding wrong!***") |
| 387 | |
| 388 | time.sleep(20) |
| 389 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 390 | |
| 391 | |
| 392 | main.step("Check MultiPointToSinglePointIntent intents installed") |
| 393 | # route_intents_expected are generated when generating routes |
| 394 | # get route intents from ONOS CLI |
| 395 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 396 | # routeIntents_str_expected = str(sorted(routeIntents_expected)) |
| 397 | routeIntents_str_actual = str(routeIntents_actual).replace('u', "") |
| 398 | main.log.info("MultiPointToSinglePoint intents expected:") |
| 399 | main.log.info(routeIntents_str_expected) |
| 400 | main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:") |
| 401 | main.log.info(routeIntents_str_actual) |
| 402 | utilities.assert_equals(expect=True, actual=eq(routeIntents_str_expected, routeIntents_str_actual), |
| 403 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***", |
| 404 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***") |
| 405 | |
| 406 | if(eq(routeIntents_str_expected, routeIntents_str_actual)): |
| 407 | main.log.report("***MultiPointToSinglePoint Intents after adding routes correct!***") |
| 408 | else: |
| 409 | main.log.report("***MultiPointToSinglePoint Intents after adding routes wrong!***") |
| 410 | |
| 411 | #============================= Ping Test ======================== |
| 412 | # wait until all MultiPointToSinglePoint |
| 413 | time.sleep(20) |
| 414 | # ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 415 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" + str(round_num) + "-ping-results-before-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt" |
| 416 | ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file) |
| 417 | main.log.info(ping_test_results) |
| 418 | # ping test |
| 419 | |
| 420 | #============================= Deleting Routes ================== |
| 421 | main.step("Check deleting routes installed") |
| 422 | main.log.info("Delete routes to Quagga on host3") |
| 423 | main.QuaggaCliHost3.delete_routes(prefixes_host3, 1) |
| 424 | main.log.info("Delete routes to Quagga on host4") |
| 425 | main.QuaggaCliHost4.delete_routes(prefixes_host4, 1) |
| 426 | |
| 427 | get_routes_result = main.ONOScli.routes(json_format=True) |
| 428 | allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result) |
| 429 | main.log.info("allRoutes_actual = ") |
| 430 | main.log.info(allRoutes_actual) |
| 431 | |
| 432 | utilities.assert_equals(expect="[]", actual=str(allRoutes_actual), |
| 433 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 434 | onfail="***Routes number in SDN-IP is not 0, wrong!***") |
| 435 | |
| 436 | if(eq(allRoutes_str_expected, allRoutes_str_actual)): |
| 437 | main.log.report("***Routes in SDN-IP after deleting correct!***") |
| 438 | else: |
| 439 | main.log.report("***Routes in SDN-IP after deleting wrong!***") |
| 440 | |
| 441 | main.step("Check intents after deleting routes") |
| 442 | get_intents_result = main.ONOScli.intents(json_format=True) |
| 443 | routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result) |
| 444 | main.log.info("main.ONOScli.intents()= ") |
| 445 | main.log.info(routeIntents_actual) |
| 446 | utilities.assert_equals(expect="[]", actual=str(routeIntents_actual), |
| 447 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***", |
| 448 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***") |
| 449 | |
| 450 | if(eq(routeIntents_str_expected, routeIntents_str_actual)): |
| 451 | main.log.report("***MultiPointToSinglePoint Intents after deleting routes correct!***") |
| 452 | else: |
| 453 | main.log.report("***MultiPointToSinglePoint Intents after deleting routes wrong!***") |
| 454 | |
| 455 | time.sleep(20) |
| 456 | # ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 457 | ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" + str(round_num) + "-ping-results-after-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt" |
| 458 | ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file) |
| 459 | main.log.info(ping_test_results) |
| 460 | time.sleep(30) |
| 461 | |
| 462 | |
| 463 | |