blob: 081b1ca5d2faf1d1ebb450aa299ffc4904254015 [file] [log] [blame]
pingping-lin3d87a132014-12-04 14:22:49 -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
kelvin-onlab8a832582015-01-16 17:06:11 -08005
pingping-lin8b306ac2014-11-17 18:13:51 -08006class SdnIpTest:
kelvin-onlab8a832582015-01-16 17:06:11 -08007
8 def __init__( self ):
pingping-lin8b306ac2014-11-17 18:13:51 -08009 self.default = ''
10
kelvin-onlab8a832582015-01-16 17:06:11 -080011 def CASE1( self, main ):
12 """
pingping-lin8b306ac2014-11-17 18:13:51 -080013 Test the SDN-IP functionality
pingping-lin6f6332e2014-11-19 19:13:58 -080014 allRoutes_expected: all expected routes for all BGP peers
pingping-lin3d87a132014-12-04 14:22:49 -080015 routeIntents_expected: all expected MultiPointToSinglePointIntent intents
16 bgpIntents_expected: expected PointToPointIntent intents
17 allRoutes_actual: all routes from ONOS LCI
18 routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI
19 bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -080020 """
pingping-lin8b306ac2014-11-17 18:13:51 -080021 import time
22 import json
23 from operator import eq
pingping-linc6b86fa2014-12-01 16:18:10 -080024 # from datetime import datetime
pingping-lin01355a62014-12-02 20:58:14 -080025 from time import localtime, strftime
pingping-linc6b86fa2014-12-01 16:18:10 -080026
kelvin-onlab8a832582015-01-16 17:06:11 -080027 main.case(
28 "The test case is to help to setup the TestON environment and test new drivers" )
pingping-lin6f6332e2014-11-19 19:13:58 -080029 SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json"
30 # all expected routes for all BGP peers
31 allRoutes_expected = []
kelvin-onlab8a832582015-01-16 17:06:11 -080032 main.step( "Start to generate routes for all BGP peers" )
pingping-linc6b86fa2014-12-01 16:18:10 -080033 # bgpPeerHosts = []
kelvin-onlab8a832582015-01-16 17:06:11 -080034 # for i in range( 3, 5 ):
35 # bgpPeerHosts.append( "host" + str( i ) )
36 # main.log.info( "BGP Peer Hosts are:" + bgpPeerHosts )
pingping-lin6f6332e2014-11-19 19:13:58 -080037
kelvin-onlab8a832582015-01-16 17:06:11 -080038 # for i in range( 3, 5 ):
39 # QuaggaCliHost = "QuaggaCliHost" + str( i )
40 # prefixes = main.QuaggaCliHost.generate_prefixes( 3, 10 )
pingping-lin6f6332e2014-11-19 19:13:58 -080041
kelvin-onlab8a832582015-01-16 17:06:11 -080042 # main.log.info( prefixes )
43 # allRoutes_expected.append( prefixes )
44 main.log.info( "Generate prefixes for host3" )
45 prefixes_host3 = main.QuaggaCliHost3.generate_prefixes( 3, 10 )
46 main.log.info( prefixes_host3 )
pingping-lin36fbe802014-11-25 16:01:14 -080047 # generate route with next hop
48 for prefix in prefixes_host3:
kelvin-onlab8a832582015-01-16 17:06:11 -080049 allRoutes_expected.append( prefix + "/" + "192.168.20.1" )
50 routeIntents_expected_host3 = main.QuaggaCliHost3.generate_expected_onePeerRouteIntents(
51 prefixes_host3,
52 "192.168.20.1",
53 "00:00:00:00:02:02",
54 SDNIP_JSON_FILE_PATH )
pingping-lin6f6332e2014-11-19 19:13:58 -080055
kelvin-onlab8a832582015-01-16 17:06:11 -080056 main.log.info( "Generate prefixes for host4" )
57 prefixes_host4 = main.QuaggaCliHost4.generate_prefixes( 4, 10 )
58 main.log.info( prefixes_host4 )
pingping-lin36fbe802014-11-25 16:01:14 -080059 # generate route with next hop
60 for prefix in prefixes_host4:
kelvin-onlab8a832582015-01-16 17:06:11 -080061 allRoutes_expected.append( prefix + "/" + "192.168.30.1" )
62 routeIntents_expected_host4 = main.QuaggaCliHost4.generate_expected_onePeerRouteIntents(
63 prefixes_host4,
64 "192.168.30.1",
65 "00:00:00:00:03:01",
66 SDNIP_JSON_FILE_PATH )
pingping-lin6f6332e2014-11-19 19:13:58 -080067
kelvin-onlab8a832582015-01-16 17:06:11 -080068 routeIntents_expected = routeIntents_expected_host3 + \
69 routeIntents_expected_host4
pingping-lin8b306ac2014-11-17 18:13:51 -080070
kelvin-onlab8a832582015-01-16 17:06:11 -080071 cell_name = main.params[ 'ENV' ][ 'cellName' ]
72 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
73 main.step( "Set cell for ONOS-cli environment" )
74 main.ONOScli.set_cell( cell_name )
pingping-lin81ef0652014-12-02 21:39:23 -080075 verify_result = main.ONOSbench.verify_cell()
kelvin-onlab8a832582015-01-16 17:06:11 -080076 main.log.report( "Removing raft logs" )
pingping-lin81ef0652014-12-02 21:39:23 -080077 main.ONOSbench.onos_remove_raft_logs()
kelvin-onlab8a832582015-01-16 17:06:11 -080078 main.log.report( "Uninstalling ONOS" )
79 main.ONOSbench.onos_uninstall( ONOS1_ip )
80 main.step( "Creating ONOS package" )
pingping-lin81ef0652014-12-02 21:39:23 -080081 package_result = main.ONOSbench.onos_package()
pingping-lin8b306ac2014-11-17 18:13:51 -080082
kelvin-onlab8a832582015-01-16 17:06:11 -080083 main.step( "Starting ONOS service" )
pingping-lin8b306ac2014-11-17 18:13:51 -080084 # TODO: start ONOS from Mininet Script
kelvin-onlab8a832582015-01-16 17:06:11 -080085 # start_result = main.ONOSbench.onos_start( "127.0.0.1" )
86 main.step( "Installing ONOS package" )
87 onos1_install_result = main.ONOSbench.onos_install(
88 options="-f",
89 node=ONOS1_ip )
pingping-lin3d87a132014-12-04 14:22:49 -080090
kelvin-onlab8a832582015-01-16 17:06:11 -080091 main.step( "Checking if ONOS is up yet" )
92 time.sleep( 60 )
93 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
pingping-lin81ef0652014-12-02 21:39:23 -080094 if not onos1_isup:
kelvin-onlab8a832582015-01-16 17:06:11 -080095 main.log.report( "ONOS1 didn't start!" )
pingping-linc6b86fa2014-12-01 16:18:10 -080096
kelvin-onlab8a832582015-01-16 17:06:11 -080097 main.step( "Start ONOS-cli" )
pingping-lin8b306ac2014-11-17 18:13:51 -080098 # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver
pingping-linc6b86fa2014-12-01 16:18:10 -080099
kelvin-onlab8a832582015-01-16 17:06:11 -0800100 main.ONOScli.start_onos_cli( ONOS1_ip )
pingping-lin8b306ac2014-11-17 18:13:51 -0800101
kelvin-onlab8a832582015-01-16 17:06:11 -0800102 main.step( "Get devices in the network" )
103 list_result = main.ONOScli.devices( json_format=False )
104 main.log.info( list_result )
105 time.sleep( 10 )
106 main.log.info( "Installing sdn-ip feature" )
107 main.ONOScli.feature_install( "onos-app-sdnip" )
108 time.sleep( 10 )
109 main.step( "Login all BGP peers and add routes into peers" )
110 main.log.info( "Login Quagga CLI on host3" )
111 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
112 main.log.info( "Enter configuration model of Quagga CLI on host3" )
113 main.QuaggaCliHost3.enter_config( 64514 )
114 main.log.info( "Add routes to Quagga on host3" )
115 main.QuaggaCliHost3.add_routes( prefixes_host3, 1 )
pingping-linbc230942014-12-03 18:36:27 -0800116
kelvin-onlab8a832582015-01-16 17:06:11 -0800117 main.log.info( "Login Quagga CLI on host4" )
118 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
119 main.log.info( "Enter configuration model of Quagga CLI on host4" )
120 main.QuaggaCliHost4.enter_config( 64516 )
121 main.log.info( "Add routes to Quagga on host4" )
122 main.QuaggaCliHost4.add_routes( prefixes_host4, 1 )
123 time.sleep( 60 )
pingping-lin8b306ac2014-11-17 18:13:51 -0800124
pingping-linc6b86fa2014-12-01 16:18:10 -0800125 # get all routes inside SDN-IP
kelvin-onlab8a832582015-01-16 17:06:11 -0800126 get_routes_result = main.ONOScli.routes( json_format=True )
pingping-linc6b86fa2014-12-01 16:18:10 -0800127
pingping-lin8b306ac2014-11-17 18:13:51 -0800128 # parse routes from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800129 allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(
130 get_routes_result )
pingping-linc6b86fa2014-12-01 16:18:10 -0800131
kelvin-onlab8a832582015-01-16 17:06:11 -0800132 allRoutes_str_expected = str( sorted( allRoutes_expected ) )
133 allRoutes_str_actual = str( allRoutes_actual ).replace( 'u', "" )
134 main.step( "Check routes installed" )
135 main.log.info( "Routes expected:" )
136 main.log.info( allRoutes_str_expected )
137 main.log.info( "Routes get from ONOS CLI:" )
138 main.log.info( allRoutes_str_actual )
139 utilities.assert_equals(
140 expect=allRoutes_str_expected,
141 actual=allRoutes_str_actual,
142 onpass="***Routes in SDN-IP are correct!***",
143 onfail="***Routes in SDN-IP are wrong!***" )
144 if( eq( allRoutes_str_expected, allRoutes_str_actual ) ):
145 main.log.report(
146 "***Routes in SDN-IP after adding routes are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800147 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800148 main.log.report(
149 "***Routes in SDN-IP after adding routes are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800150
kelvin-onlab8a832582015-01-16 17:06:11 -0800151 time.sleep( 20 )
152 get_intents_result = main.ONOScli.intents( json_format=True )
pingping-lin6f6332e2014-11-19 19:13:58 -0800153
kelvin-onlab8a832582015-01-16 17:06:11 -0800154 main.step( "Check MultiPointToSinglePointIntent intents installed" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800155 # route_intents_expected are generated when generating routes
156 # get rpoute intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800157 routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(
158 get_intents_result )
159 routeIntents_str_expected = str( sorted( routeIntents_expected ) )
160 routeIntents_str_actual = str( routeIntents_actual ).replace( 'u', "" )
161 main.log.info( "MultiPointToSinglePoint intents expected:" )
162 main.log.info( routeIntents_str_expected )
163 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
164 main.log.info( routeIntents_str_actual )
165 utilities.assert_equals(
166 expect=True,
167 actual=eq(
168 routeIntents_str_expected,
169 routeIntents_str_actual ),
170 onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***",
171 onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800172
kelvin-onlab8a832582015-01-16 17:06:11 -0800173 if( eq( routeIntents_str_expected, routeIntents_str_actual ) ):
174 main.log.report(
175 "***MultiPointToSinglePoint Intents before deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800176 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800177 main.log.report(
178 "***MultiPointToSinglePoint Intents before deleting routes wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800179
kelvin-onlab8a832582015-01-16 17:06:11 -0800180 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800181 # bgp intents expected
kelvin-onlab8a832582015-01-16 17:06:11 -0800182 bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(
183 SDNIP_JSON_FILE_PATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800184 # get BGP intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800185 bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(
186 get_intents_result )
pingping-lin3228e132014-11-20 17:49:02 -0800187
kelvin-onlab8a832582015-01-16 17:06:11 -0800188 bgpIntents_str_expected = str( bgpIntents_expected ).replace( 'u', "" )
189 bgpIntents_str_actual = str( bgpIntents_actual )
190 main.log.info( "PointToPointIntent intents expected:" )
191 main.log.info( bgpIntents_str_expected )
192 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
193 main.log.info( bgpIntents_str_actual )
pingping-lin3228e132014-11-20 17:49:02 -0800194
kelvin-onlab8a832582015-01-16 17:06:11 -0800195 utilities.assert_equals(
196 expect=True,
197 actual=eq(
198 bgpIntents_str_expected,
199 bgpIntents_str_actual ),
200 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
201 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800202
kelvin-onlab8a832582015-01-16 17:06:11 -0800203 if ( eq( bgpIntents_str_expected, bgpIntents_str_actual ) ):
204 main.log.report(
205 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800206 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800207 main.log.report(
208 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800209
pingping-linc6b86fa2014-12-01 16:18:10 -0800210 #============================= Ping Test ========================
211 # wait until all MultiPointToSinglePoint
kelvin-onlab8a832582015-01-16 17:06:11 -0800212 time.sleep( 20 )
pingping-lindd3b0e42014-12-02 11:46:54 -0800213 ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
kelvin-onlab8a832582015-01-16 17:06:11 -0800214 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-before-delete-routes-" + \
215 strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
216 ping_test_results = main.QuaggaCliHost.ping_test(
217 "1.168.30.100",
218 ping_test_script,
219 ping_test_results_file )
220 main.log.info( ping_test_results )
pingping-linc6b86fa2014-12-01 16:18:10 -0800221
222 # ping test
223
224 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -0800225 main.step( "Check deleting routes installed" )
226 main.QuaggaCliHost3.delete_routes( prefixes_host3, 1 )
227 main.QuaggaCliHost4.delete_routes( prefixes_host4, 1 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800228
kelvin-onlab8a832582015-01-16 17:06:11 -0800229 # main.log.info( "main.ONOScli.get_routes_num() = " )
230 # main.log.info( main.ONOScli.get_routes_num() )
231 # utilities.assert_equals( expect="Total SDN-IP routes = 1", actual=
232 # main.ONOScli.get_routes_num(),
233 get_routes_result = main.ONOScli.routes( json_format=True )
234 allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(
235 get_routes_result )
236 main.log.info( "allRoutes_actual = " )
237 main.log.info( allRoutes_actual )
pingping-linc6b86fa2014-12-01 16:18:10 -0800238
kelvin-onlab8a832582015-01-16 17:06:11 -0800239 utilities.assert_equals(
240 expect="[]",
241 actual=str( allRoutes_actual ),
242 onpass="***Route number in SDN-IP is 0, correct!***",
243 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800244
kelvin-onlab8a832582015-01-16 17:06:11 -0800245 if( eq( allRoutes_str_expected, allRoutes_str_actual ) ):
246 main.log.report( "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800247 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800248 main.log.report( "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800249
kelvin-onlab8a832582015-01-16 17:06:11 -0800250 main.step( "Check intents after deleting routes" )
251 get_intents_result = main.ONOScli.intents( json_format=True )
252 routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(
253 get_intents_result )
254 main.log.info( "main.ONOScli.intents()= " )
255 main.log.info( routeIntents_actual )
256 utilities.assert_equals(
257 expect="[]",
258 actual=str( routeIntents_actual ),
259 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***",
260 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800261
kelvin-onlab8a832582015-01-16 17:06:11 -0800262 if( eq( routeIntents_str_expected, routeIntents_str_actual ) ):
263 main.log.report(
264 "***MultiPointToSinglePoint Intents after deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800265 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800266 main.log.report(
267 "***MultiPointToSinglePoint Intents after deleting routes wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800268
kelvin-onlab8a832582015-01-16 17:06:11 -0800269 time.sleep( 20 )
pingping-lindd3b0e42014-12-02 11:46:54 -0800270 ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
kelvin-onlab8a832582015-01-16 17:06:11 -0800271 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-after-delete-routes-" + \
272 strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
273 ping_test_results = main.QuaggaCliHost.ping_test(
274 "1.168.30.100",
275 ping_test_script,
276 ping_test_results_file )
277 main.log.info( ping_test_results )
278 time.sleep( 30 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800279
kelvin-onlab8a832582015-01-16 17:06:11 -0800280 # main.step( "Test whether Mininet is started" )
281 # main.Mininet2.handle.sendline( "xterm host1" )
282 # main.Mininet2.handle.expect( "mininet>" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800283
kelvin-onlab8a832582015-01-16 17:06:11 -0800284 def CASE2( self, main ):
285 """
pingping-lin3d87a132014-12-04 14:22:49 -0800286 Test the SDN-IP functionality
287 allRoutes_expected: all expected routes for all BGP peers
288 routeIntents_expected: all expected MultiPointToSinglePointIntent intents
289 bgpIntents_expected: expected PointToPointIntent intents
290 allRoutes_actual: all routes from ONOS LCI
291 routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI
292 bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800293 """
pingping-lin3d87a132014-12-04 14:22:49 -0800294 import time
295 import json
296 from operator import eq
297 from time import localtime, strftime
298
kelvin-onlab8a832582015-01-16 17:06:11 -0800299 main.case(
300 "The test case is to help to setup the TestON environment and test new drivers" )
pingping-lin3d87a132014-12-04 14:22:49 -0800301 SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json"
302 # all expected routes for all BGP peers
303 allRoutes_expected = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800304 main.step( "Start to generate routes for all BGP peers" )
pingping-lin3d87a132014-12-04 14:22:49 -0800305
kelvin-onlab8a832582015-01-16 17:06:11 -0800306 main.log.info( "Generate prefixes for host3" )
307 prefixes_host3 = main.QuaggaCliHost3.generate_prefixes( 3, 10 )
308 main.log.info( prefixes_host3 )
pingping-lin3d87a132014-12-04 14:22:49 -0800309 # generate route with next hop
310 for prefix in prefixes_host3:
kelvin-onlab8a832582015-01-16 17:06:11 -0800311 allRoutes_expected.append( prefix + "/" + "192.168.20.1" )
312 routeIntents_expected_host3 = main.QuaggaCliHost3.generate_expected_onePeerRouteIntents(
313 prefixes_host3,
314 "192.168.20.1",
315 "00:00:00:00:02:02",
316 SDNIP_JSON_FILE_PATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800317
kelvin-onlab8a832582015-01-16 17:06:11 -0800318 main.log.info( "Generate prefixes for host4" )
319 prefixes_host4 = main.QuaggaCliHost4.generate_prefixes( 4, 10 )
320 main.log.info( prefixes_host4 )
pingping-lin3d87a132014-12-04 14:22:49 -0800321 # generate route with next hop
322 for prefix in prefixes_host4:
kelvin-onlab8a832582015-01-16 17:06:11 -0800323 allRoutes_expected.append( prefix + "/" + "192.168.30.1" )
324 routeIntents_expected_host4 = main.QuaggaCliHost4.generate_expected_onePeerRouteIntents(
325 prefixes_host4,
326 "192.168.30.1",
327 "00:00:00:00:03:01",
328 SDNIP_JSON_FILE_PATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800329
kelvin-onlab8a832582015-01-16 17:06:11 -0800330 routeIntents_expected = routeIntents_expected_host3 + \
331 routeIntents_expected_host4
pingping-lin3d87a132014-12-04 14:22:49 -0800332
kelvin-onlab8a832582015-01-16 17:06:11 -0800333 main.log.report( "Removing raft logs" )
pingping-lin3d87a132014-12-04 14:22:49 -0800334 main.ONOSbench.onos_remove_raft_logs()
kelvin-onlab8a832582015-01-16 17:06:11 -0800335 main.log.report( "Uninstalling ONOS" )
336 main.ONOSbench.onos_uninstall( ONOS1_ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800337
kelvin-onlab8a832582015-01-16 17:06:11 -0800338 cell_name = main.params[ 'ENV' ][ 'cellName' ]
339 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
340 main.step( "Set cell for ONOS-cli environment" )
341 main.ONOScli.set_cell( cell_name )
pingping-lin3d87a132014-12-04 14:22:49 -0800342 verify_result = main.ONOSbench.verify_cell()
kelvin-onlab8a832582015-01-16 17:06:11 -0800343 #main.log.report( "Removing raft logs" )
344 # main.ONOSbench.onos_remove_raft_logs()
345 #main.log.report( "Uninstalling ONOS" )
346 # main.ONOSbench.onos_uninstall( ONOS1_ip )
347 main.step( "Creating ONOS package" )
pingping-lin3d87a132014-12-04 14:22:49 -0800348 package_result = main.ONOSbench.onos_package()
349
kelvin-onlab8a832582015-01-16 17:06:11 -0800350 main.step( "Installing ONOS package" )
351 onos1_install_result = main.ONOSbench.onos_install(
352 options="-f",
353 node=ONOS1_ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800354
kelvin-onlab8a832582015-01-16 17:06:11 -0800355 main.step( "Checking if ONOS is up yet" )
356 time.sleep( 60 )
357 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800358 if not onos1_isup:
kelvin-onlab8a832582015-01-16 17:06:11 -0800359 main.log.report( "ONOS1 didn't start!" )
pingping-lin3d87a132014-12-04 14:22:49 -0800360
kelvin-onlab8a832582015-01-16 17:06:11 -0800361 main.step( "Start ONOS-cli" )
362 main.ONOScli.start_onos_cli( ONOS1_ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800363
kelvin-onlab8a832582015-01-16 17:06:11 -0800364 main.step( "Get devices in the network" )
365 list_result = main.ONOScli.devices( json_format=False )
366 main.log.info( list_result )
367 time.sleep( 10 )
368 main.log.info( "Installing sdn-ip feature" )
369 main.ONOScli.feature_install( "onos-app-sdnip" )
370 time.sleep( 10 )
pingping-lin3d87a132014-12-04 14:22:49 -0800371
kelvin-onlab8a832582015-01-16 17:06:11 -0800372 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin3d87a132014-12-04 14:22:49 -0800373 # bgp intents expected
kelvin-onlab8a832582015-01-16 17:06:11 -0800374 bgpIntents_expected = main.QuaggaCliHost3.generate_expected_bgpIntents(
375 SDNIP_JSON_FILE_PATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800376 # get BGP intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800377 get_intents_result = main.ONOScli.intents( json_format=True )
378 bgpIntents_actual = main.QuaggaCliHost3.extract_actual_bgpIntents(
379 get_intents_result )
pingping-lin3d87a132014-12-04 14:22:49 -0800380
kelvin-onlab8a832582015-01-16 17:06:11 -0800381 bgpIntents_str_expected = str( bgpIntents_expected ).replace( 'u', "" )
382 bgpIntents_str_actual = str( bgpIntents_actual )
383 main.log.info( "PointToPointIntent intents expected:" )
384 main.log.info( bgpIntents_str_expected )
385 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
386 main.log.info( bgpIntents_str_actual )
pingping-lin3d87a132014-12-04 14:22:49 -0800387
kelvin-onlab8a832582015-01-16 17:06:11 -0800388 utilities.assert_equals(
389 expect=True,
390 actual=eq(
391 bgpIntents_str_expected,
392 bgpIntents_str_actual ),
393 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
394 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800395
kelvin-onlab8a832582015-01-16 17:06:11 -0800396 if ( eq( bgpIntents_str_expected, bgpIntents_str_actual ) ):
397 main.log.report(
398 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800399 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800400 main.log.report(
401 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800402
kelvin-onlab8a832582015-01-16 17:06:11 -0800403 allRoutes_str_expected = str( sorted( allRoutes_expected ) )
404 routeIntents_str_expected = str( sorted( routeIntents_expected ) )
pingping-lin3d87a132014-12-04 14:22:49 -0800405 ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
406 # round_num = 0;
kelvin-onlab8a832582015-01-16 17:06:11 -0800407 # while( True ):
408 for round_num in range( 1, 6 ):
pingping-lin3d87a132014-12-04 14:22:49 -0800409 # round = round + 1;
kelvin-onlab8a832582015-01-16 17:06:11 -0800410 main.log.report(
411 "The Round " +
412 str( round_num ) +
413 " test starts........................................" )
pingping-lin3d87a132014-12-04 14:22:49 -0800414
kelvin-onlab8a832582015-01-16 17:06:11 -0800415 main.step( "Login all BGP peers and add routes into peers" )
416 main.log.info( "Login Quagga CLI on host3" )
417 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
418 main.log.info( "Enter configuration model of Quagga CLI on host3" )
419 main.QuaggaCliHost3.enter_config( 64514 )
420 main.log.info( "Add routes to Quagga on host3" )
421 main.QuaggaCliHost3.add_routes( prefixes_host3, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -0800422
kelvin-onlab8a832582015-01-16 17:06:11 -0800423 main.log.info( "Login Quagga CLI on host4" )
424 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
425 main.log.info( "Enter configuration model of Quagga CLI on host4" )
426 main.QuaggaCliHost4.enter_config( 64516 )
427 main.log.info( "Add routes to Quagga on host4" )
428 main.QuaggaCliHost4.add_routes( prefixes_host4, 1 )
429 time.sleep( 60 )
pingping-lin3d87a132014-12-04 14:22:49 -0800430
431 # get all routes inside SDN-IP
kelvin-onlab8a832582015-01-16 17:06:11 -0800432 get_routes_result = main.ONOScli.routes( json_format=True )
pingping-lin3d87a132014-12-04 14:22:49 -0800433
434 # parse routes from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800435 allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(
436 get_routes_result )
pingping-lin3d87a132014-12-04 14:22:49 -0800437
kelvin-onlab8a832582015-01-16 17:06:11 -0800438 # allRoutes_str_expected = str( sorted( allRoutes_expected ) )
439 allRoutes_str_actual = str( allRoutes_actual ).replace( 'u', "" )
440 main.step( "Check routes installed" )
441 main.log.info( "Routes expected:" )
442 main.log.info( allRoutes_str_expected )
443 main.log.info( "Routes get from ONOS CLI:" )
444 main.log.info( allRoutes_str_actual )
445 utilities.assert_equals(
446 expect=allRoutes_str_expected,
447 actual=allRoutes_str_actual,
448 onpass="***Routes in SDN-IP are correct!***",
449 onfail="***Routes in SDN-IP are wrong!***" )
450 if( eq( allRoutes_str_expected, allRoutes_str_actual ) ):
451 main.log.report(
452 "***Routes in SDN-IP after adding correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800453 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800454 main.log.report( "***Routes in SDN-IP after adding wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800455
kelvin-onlab8a832582015-01-16 17:06:11 -0800456 time.sleep( 20 )
457 get_intents_result = main.ONOScli.intents( json_format=True )
pingping-lin3d87a132014-12-04 14:22:49 -0800458
kelvin-onlab8a832582015-01-16 17:06:11 -0800459 main.step(
460 "Check MultiPointToSinglePointIntent intents installed" )
pingping-lin3d87a132014-12-04 14:22:49 -0800461 # route_intents_expected are generated when generating routes
462 # get route intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800463 routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(
464 get_intents_result )
465 # routeIntents_str_expected = str( sorted( routeIntents_expected ) )
466 routeIntents_str_actual = str(
467 routeIntents_actual ).replace( 'u', "" )
468 main.log.info( "MultiPointToSinglePoint intents expected:" )
469 main.log.info( routeIntents_str_expected )
470 main.log.info(
471 "MultiPointToSinglePoint intents get from ONOS CLI:" )
472 main.log.info( routeIntents_str_actual )
473 utilities.assert_equals(
474 expect=True,
475 actual=eq(
476 routeIntents_str_expected,
477 routeIntents_str_actual ),
478 onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***",
479 onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800480
kelvin-onlab8a832582015-01-16 17:06:11 -0800481 if( eq( routeIntents_str_expected, routeIntents_str_actual ) ):
482 main.log.report(
483 "***MultiPointToSinglePoint Intents after adding routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800484 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800485 main.log.report(
486 "***MultiPointToSinglePoint Intents after adding routes wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800487
488 #============================= Ping Test ========================
489 # wait until all MultiPointToSinglePoint
kelvin-onlab8a832582015-01-16 17:06:11 -0800490 time.sleep( 20 )
pingping-lin3d87a132014-12-04 14:22:49 -0800491 # ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
kelvin-onlab8a832582015-01-16 17:06:11 -0800492 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" + \
493 str( round_num ) + "-ping-results-before-delete-routes-" + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
494 ping_test_results = main.QuaggaCliHost.ping_test(
495 "1.168.30.100",
496 ping_test_script,
497 ping_test_results_file )
498 main.log.info( ping_test_results )
pingping-lin3d87a132014-12-04 14:22:49 -0800499 # ping test
500
501 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -0800502 main.step( "Check deleting routes installed" )
503 main.log.info( "Delete routes to Quagga on host3" )
504 main.QuaggaCliHost3.delete_routes( prefixes_host3, 1 )
505 main.log.info( "Delete routes to Quagga on host4" )
506 main.QuaggaCliHost4.delete_routes( prefixes_host4, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -0800507
kelvin-onlab8a832582015-01-16 17:06:11 -0800508 get_routes_result = main.ONOScli.routes( json_format=True )
509 allRoutes_actual = main.QuaggaCliHost3.extract_actual_routes(
510 get_routes_result )
511 main.log.info( "allRoutes_actual = " )
512 main.log.info( allRoutes_actual )
pingping-lin3d87a132014-12-04 14:22:49 -0800513
kelvin-onlab8a832582015-01-16 17:06:11 -0800514 utilities.assert_equals(
515 expect="[]",
516 actual=str( allRoutes_actual ),
517 onpass="***Route number in SDN-IP is 0, correct!***",
518 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800519
kelvin-onlab8a832582015-01-16 17:06:11 -0800520 if( eq( allRoutes_str_expected, allRoutes_str_actual ) ):
521 main.log.report(
522 "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800523 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800524 main.log.report(
525 "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800526
kelvin-onlab8a832582015-01-16 17:06:11 -0800527 main.step( "Check intents after deleting routes" )
528 get_intents_result = main.ONOScli.intents( json_format=True )
529 routeIntents_actual = main.QuaggaCliHost3.extract_actual_routeIntents(
530 get_intents_result )
531 main.log.info( "main.ONOScli.intents()= " )
532 main.log.info( routeIntents_actual )
533 utilities.assert_equals(
534 expect="[]",
535 actual=str( routeIntents_actual ),
536 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, correct!***",
537 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800538
kelvin-onlab8a832582015-01-16 17:06:11 -0800539 if( eq( routeIntents_str_expected, routeIntents_str_actual ) ):
540 main.log.report(
541 "***MultiPointToSinglePoint Intents after deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800542 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800543 main.log.report(
544 "***MultiPointToSinglePoint Intents after deleting routes wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800545
kelvin-onlab8a832582015-01-16 17:06:11 -0800546 time.sleep( 20 )
pingping-lin3d87a132014-12-04 14:22:49 -0800547 # ping_test_script = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
kelvin-onlab8a832582015-01-16 17:06:11 -0800548 ping_test_results_file = "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" + \
549 str( round_num ) + "-ping-results-after-delete-routes-" + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
550 ping_test_results = main.QuaggaCliHost.ping_test(
551 "1.168.30.100",
552 ping_test_script,
553 ping_test_results_file )
554 main.log.info( ping_test_results )
555 time.sleep( 30 )