blob: 732da3e5277f692773019fe49d716172c86a1d70 [file] [log] [blame]
pingping-lin01355a62014-12-02 20:58:14 -08001#from cupshelpers.config import prefix
pingping-lin8b306ac2014-11-17 18:13:51 -08002
pingping-linc6b86fa2014-12-01 16:18:10 -08003# Testing the basic functionality of SDN-IP
pingping-lin8b306ac2014-11-17 18:13:51 -08004
5class SdnIpTest:
6 def __init__(self):
7 self.default = ''
8
9 def CASE1(self, main):
10
11 '''
12 Test the SDN-IP functionality
pingping-lin6f6332e2014-11-19 19:13:58 -080013 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-lin8b306ac2014-11-17 18:13:51 -080019 '''
20 import time
21 import json
22 from operator import eq
pingping-linc6b86fa2014-12-01 16:18:10 -080023 # from datetime import datetime
pingping-lin01355a62014-12-02 20:58:14 -080024 from time import localtime, strftime
pingping-linc6b86fa2014-12-01 16:18:10 -080025
pingping-lin3228e132014-11-20 17:49:02 -080026 main.case("The test case is to help to setup the TestON environment and test new drivers")
pingping-lin6f6332e2014-11-19 19:13:58 -080027 SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json"
28 # all expected routes for all BGP peers
29 allRoutes_expected = []
pingping-lin36fbe802014-11-25 16:01:14 -080030 main.step("Start to generate routes for all BGP peers")
pingping-linc6b86fa2014-12-01 16:18:10 -080031 # bgpPeerHosts = []
32 # for i in range(3, 5):
pingping-lin36fbe802014-11-25 16:01:14 -080033 # bgpPeerHosts.append("host" + str(i))
pingping-linc6b86fa2014-12-01 16:18:10 -080034 # main.log.info("BGP Peer Hosts are:" + bgpPeerHosts)
pingping-lin6f6332e2014-11-19 19:13:58 -080035
pingping-linc6b86fa2014-12-01 16:18:10 -080036 # for i in range(3, 5):
pingping-lin36fbe802014-11-25 16:01:14 -080037 # QuaggaCliHost = "QuaggaCliHost" + str(i)
38 # prefixes = main.QuaggaCliHost.generate_prefixes(3, 10)
pingping-lin6f6332e2014-11-19 19:13:58 -080039
pingping-lin36fbe802014-11-25 16:01:14 -080040 # main.log.info(prefixes)
pingping-linc6b86fa2014-12-01 16:18:10 -080041 # allRoutes_expected.append(prefixes)
pingping-lin36fbe802014-11-25 16:01:14 -080042 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-lin6f6332e2014-11-19 19:13:58 -080049
pingping-lin36fbe802014-11-25 16:01:14 -080050 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-lin6f6332e2014-11-19 19:13:58 -080057
pingping-lin36fbe802014-11-25 16:01:14 -080058 routeIntents_expected = routeIntents_expected_host3 + routeIntents_expected_host4
pingping-lin8b306ac2014-11-17 18:13:51 -080059
pingping-lin36fbe802014-11-25 16:01:14 -080060 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-lin8b306ac2014-11-17 18:13:51 -080067
pingping-lin36fbe802014-11-25 16:01:14 -080068 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-linc6b86fa2014-12-01 16:18:10 -080074 time.sleep(30)
pingping-lin36fbe802014-11-25 16:01:14 -080075
pingping-lin8b306ac2014-11-17 18:13:51 -080076
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-linc6b86fa2014-12-01 16:18:10 -080086
pingping-lin8b306ac2014-11-17 18:13:51 -080087 main.step("Start ONOS-cli")
88 # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver
pingping-linc6b86fa2014-12-01 16:18:10 -080089
90 main.ONOScli.start_onos_cli(ONOS1_ip)
pingping-lin8b306ac2014-11-17 18:13:51 -080091
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-linc6b86fa2014-12-01 16:18:10 -080096 # get all routes inside SDN-IP
pingping-lin36fbe802014-11-25 16:01:14 -080097 get_routes_result = main.ONOScli.routes(json_format=True)
pingping-linc6b86fa2014-12-01 16:18:10 -080098
pingping-lin8b306ac2014-11-17 18:13:51 -080099 # parse routes from ONOS CLI
pingping-lin36fbe802014-11-25 16:01:14 -0800100 allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(get_routes_result)
pingping-linc6b86fa2014-12-01 16:18:10 -0800101
pingping-lin36fbe802014-11-25 16:01:14 -0800102 allRoutes_str_expected = str(sorted(allRoutes_expected))
pingping-linc6b86fa2014-12-01 16:18:10 -0800103 allRoutes_str_actual = str(allRoutes_actual).replace('u', "")
pingping-lin6f6332e2014-11-19 19:13:58 -0800104 main.step("Check routes installed")
105 main.log.info("Routes expected:")
pingping-lin36fbe802014-11-25 16:01:14 -0800106 main.log.info(allRoutes_str_expected)
pingping-lin8b306ac2014-11-17 18:13:51 -0800107 main.log.info("Routes get from ONOS CLI:")
pingping-lin36fbe802014-11-25 16:01:14 -0800108 main.log.info(allRoutes_str_actual)
109 utilities.assert_equals(expect=allRoutes_str_expected, actual=allRoutes_str_actual,
pingping-lin6f6332e2014-11-19 19:13:58 -0800110 onpass="***Routes in SDN-IP are correct!***",
111 onfail="***Routes in SDN-IP are wrong!***")
pingping-lin8b306ac2014-11-17 18:13:51 -0800112
pingping-lin36fbe802014-11-25 16:01:14 -0800113 time.sleep(20)
pingping-lin6f6332e2014-11-19 19:13:58 -0800114 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-linc6b86fa2014-12-01 16:18:10 -0800120 routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(get_intents_result)
pingping-lin36fbe802014-11-25 16:01:14 -0800121 routeIntents_str_expected = str(sorted(routeIntents_expected))
pingping-linc6b86fa2014-12-01 16:18:10 -0800122 routeIntents_str_actual = str(routeIntents_actual).replace('u', "")
pingping-lin6f6332e2014-11-19 19:13:58 -0800123 main.log.info("MultiPointToSinglePoint intents expected:")
pingping-lin36fbe802014-11-25 16:01:14 -0800124 main.log.info(routeIntents_str_expected)
pingping-lin6f6332e2014-11-19 19:13:58 -0800125 main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:")
pingping-lin36fbe802014-11-25 16:01:14 -0800126 main.log.info(routeIntents_str_actual)
127 utilities.assert_equals(expect=True, actual=eq(routeIntents_str_expected, routeIntents_str_actual),
pingping-lin6f6332e2014-11-19 19:13:58 -0800128 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-lin36fbe802014-11-25 16:01:14 -0800134 bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH)
pingping-lin6f6332e2014-11-19 19:13:58 -0800135 # get BGP intents from ONOS CLI
pingping-lin36fbe802014-11-25 16:01:14 -0800136 bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(get_intents_result)
pingping-lin3228e132014-11-20 17:49:02 -0800137
pingping-linc6b86fa2014-12-01 16:18:10 -0800138 bgpIntents_str_expected = str(bgpIntents_expected).replace('u', "")
pingping-lin3228e132014-11-20 17:49:02 -0800139 bgpIntents_str_actual = str(bgpIntents_actual)
pingping-lin6f6332e2014-11-19 19:13:58 -0800140 main.log.info("PointToPointIntent intents expected:")
pingping-lin3228e132014-11-20 17:49:02 -0800141 main.log.info(bgpIntents_str_expected)
pingping-lin6f6332e2014-11-19 19:13:58 -0800142 main.log.info("PointToPointIntent intents get from ONOS CLI:")
pingping-lin3228e132014-11-20 17:49:02 -0800143 main.log.info(bgpIntents_str_actual)
144
145 utilities.assert_equals(expect=True, actual=eq(bgpIntents_str_expected, bgpIntents_str_actual),
pingping-lin6f6332e2014-11-19 19:13:58 -0800146 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
147 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***")
pingping-lin8b306ac2014-11-17 18:13:51 -0800148
pingping-linc6b86fa2014-12-01 16:18:10 -0800149 #============================= Ping Test ========================
150 # wait until all MultiPointToSinglePoint
151 time.sleep(20)
pingping-lindd3b0e42014-12-02 11:46:54 -0800152 ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin01355a62014-12-02 20:58:14 -0800153 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-results-before-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt"
pingping-lindd3b0e42014-12-02 11:46:54 -0800154 ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file)
pingping-linc6b86fa2014-12-01 16:18:10 -0800155 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-lindd3b0e42014-12-02 11:46:54 -0800187 ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin01355a62014-12-02 20:58:14 -0800188 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-results-after-delete-routes-" + strftime("%Y-%m-%d_%H:%M:%S", localtime()) + ".txt"
pingping-lindd3b0e42014-12-02 11:46:54 -0800189 ping_test_results = main.QuaggaCliHost.ping_test("1.168.30.100", ping_test_script, ping_test_results_file)
pingping-linc6b86fa2014-12-01 16:18:10 -0800190 main.log.info(ping_test_results)
pingping-lin01355a62014-12-02 20:58:14 -0800191 time.sleep(30)
pingping-linc6b86fa2014-12-01 16:18:10 -0800192
193 # main.step("Test whether Mininet is started")
194 # main.Mininet2.handle.sendline("xterm host1")
195 # main.Mininet2.handle.expect("mininet>")
pingping-lin8b306ac2014-11-17 18:13:51 -0800196