blob: ebbd57ef046fc15e63b04336ed845afbbf67708f [file] [log] [blame]
pingping-lin8b306ac2014-11-17 18:13:51 -08001
pingping-lin26521182015-01-30 14:52:39 -08002# Testing the functionality of SDN-IP with single ONOS instance
pingping-lin8b306ac2014-11-17 18:13:51 -08003class SdnIpTest:
kelvin-onlab8a832582015-01-16 17:06:11 -08004
5 def __init__( self ):
pingping-lin8b306ac2014-11-17 18:13:51 -08006 self.default = ''
pingping-lin529dad22015-02-02 16:57:35 -08007 global branchName
pingping-lin7048cb02015-01-30 15:09:46 -08008
pingping-lin26521182015-01-30 14:52:39 -08009 # This case is to setup ONOS
pingping-lina600d9b2015-01-30 13:57:26 -080010 def CASE100( self, main ):
pingping-lina600d9b2015-01-30 13:57:26 -080011 """
12 CASE100 is to compile ONOS and push it to the test machines
13 Startup sequence:
14 git pull
15 mvn clean install
16 onos-package
17 cell <name>
18 onos-verify-cell
19 onos-install -f
20 onos-wait-for-start
21 """
22 main.case( "Setting up test environment" )
pingping-lin8b306ac2014-11-17 18:13:51 -080023
pingping-lina600d9b2015-01-30 13:57:26 -080024 cellName = main.params[ 'ENV' ][ 'cellName' ]
25 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
pingping-linc1c696e2015-01-27 13:46:44 -080026
pingping-lina600d9b2015-01-30 13:57:26 -080027 main.step( "Applying cell variable to environment" )
28 cellResult = main.ONOSbench.setCell( cellName )
29 verifyResult = main.ONOSbench.verifyCell()
pingping-lin26521182015-01-30 14:52:39 -080030
pingping-lin529dad22015-02-02 16:57:35 -080031 branchName = main.ONOSbench.getBranchName()
32 main.log.info( "ONOS is on branch: " + branchName )
33
pingping-lina600d9b2015-01-30 13:57:26 -080034 main.log.report( "Uninstalling ONOS" )
35 main.ONOSbench.onosUninstall( ONOS1Ip )
pingping-linc1c696e2015-01-27 13:46:44 -080036
pingping-lina600d9b2015-01-30 13:57:26 -080037 cleanInstallResult = main.TRUE
38 gitPullResult = main.TRUE
pingping-lin26521182015-01-30 14:52:39 -080039
pingping-lina600d9b2015-01-30 13:57:26 -080040 main.step( "Git pull" )
pingping-lina600d9b2015-01-30 13:57:26 -080041 gitPullResult = main.ONOSbench.gitPull()
pingping-lin26521182015-01-30 14:52:39 -080042
pingping-lina600d9b2015-01-30 13:57:26 -080043 main.step( "Using mvn clean & install" )
44 cleanInstallResult = main.TRUE
pingping-lin529dad22015-02-02 16:57:35 -080045# if gitPullResult == main.TRUE:
46# cleanInstallResult = main.ONOSbench.cleanInstall()
47# else:
48# main.log.warn( "Did not pull new code so skipping mvn " +
49# "clean install" )
50 cleanInstallResult = main.ONOSbench.cleanInstall()
pingping-lina600d9b2015-01-30 13:57:26 -080051 main.ONOSbench.getVersion( report=True )
pingping-lin7048cb02015-01-30 15:09:46 -080052
pingping-lin26521182015-01-30 14:52:39 -080053 #cellResult = main.ONOSbench.setCell( cellName )
54 #verifyResult = main.ONOSbench.verifyCell()
pingping-lina600d9b2015-01-30 13:57:26 -080055 main.step( "Creating ONOS package" )
56 packageResult = main.ONOSbench.onosPackage()
pingping-lin7048cb02015-01-30 15:09:46 -080057
pingping-lina600d9b2015-01-30 13:57:26 -080058 main.step( "Installing ONOS package" )
59 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
60 node=ONOS1Ip )
pingping-lin7048cb02015-01-30 15:09:46 -080061
pingping-lina600d9b2015-01-30 13:57:26 -080062 main.step( "Checking if ONOS is up yet" )
63 for i in range( 2 ):
64 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
65 if onos1Isup:
66 break
67 if not onos1Isup:
68 main.log.report( "ONOS1 didn't start!" )
pingping-lin7048cb02015-01-30 15:09:46 -080069
pingping-lina600d9b2015-01-30 13:57:26 -080070 cliResult = main.ONOScli.startOnosCli( ONOS1Ip )
pingping-lin7048cb02015-01-30 15:09:46 -080071
pingping-lina600d9b2015-01-30 13:57:26 -080072 case1Result = ( cleanInstallResult and packageResult and
73 cellResult and verifyResult and
74 onos1InstallResult and
75 onos1Isup and cliResult )
pingping-lin7048cb02015-01-30 15:09:46 -080076
pingping-lina600d9b2015-01-30 13:57:26 -080077 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
pingping-lin26521182015-01-30 14:52:39 -080078 onpass="ONOS startup successful",
79 onfail="ONOS startup NOT successful" )
pingping-lin7048cb02015-01-30 15:09:46 -080080
pingping-lina600d9b2015-01-30 13:57:26 -080081 if case1Result == main.FALSE:
82 main.cleanup()
83 main.exit()
pingping-linc1c696e2015-01-27 13:46:44 -080084
85 def CASE4( self, main ):
kelvin-onlab8a832582015-01-16 17:06:11 -080086 """
pingping-lin8b306ac2014-11-17 18:13:51 -080087 Test the SDN-IP functionality
pingping-linc1c696e2015-01-27 13:46:44 -080088 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -080089 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
90 intents
pingping-linc1c696e2015-01-27 13:46:44 -080091 bgpIntentsExpected: expected PointToPointIntent intents
92 allRoutesActual: all routes from ONOS LCI
pingping-lin79011132015-01-27 15:27:27 -080093 routeIntentsActual: actual MultiPointToSinglePointIntent intents from \
94 ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -080095 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -080096 """
pingping-lin8b306ac2014-11-17 18:13:51 -080097 import time
98 import json
99 from operator import eq
pingping-lin01355a62014-12-02 20:58:14 -0800100 from time import localtime, strftime
pingping-linc6b86fa2014-12-01 16:18:10 -0800101
pingping-lin26521182015-01-30 14:52:39 -0800102 main.case("This case is to testing the functionality of SDN-IP with \
103 single ONOS instance" )
pingping-lin79011132015-01-27 15:27:27 -0800104 SDNIPJSONFILEPATH = \
pingping-lina600d9b2015-01-30 13:57:26 -0800105 "/home/admin/ONOS/tools/package/config/sdnip.json"
pingping-lin6f6332e2014-11-19 19:13:58 -0800106 # all expected routes for all BGP peers
pingping-linc1c696e2015-01-27 13:46:44 -0800107 allRoutesExpected = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800108 main.step( "Start to generate routes for all BGP peers" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800109 main.log.info( "Generate prefixes for host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800110 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
111 main.log.info( prefixesHost3 )
pingping-lin36fbe802014-11-25 16:01:14 -0800112 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800113 for prefix in prefixesHost3:
114 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800115 routeIntentsExpectedHost3 = \
116 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
117 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
118 SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800119
kelvin-onlab8a832582015-01-16 17:06:11 -0800120 main.log.info( "Generate prefixes for host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800121 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
122 main.log.info( prefixesHost4 )
pingping-lin36fbe802014-11-25 16:01:14 -0800123 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800124 for prefix in prefixesHost4:
125 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800126 routeIntentsExpectedHost4 = \
127 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
128 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
129 SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800130
pingping-linc1c696e2015-01-27 13:46:44 -0800131 main.log.info( "Generate prefixes for host5" )
132 prefixesHost5 = main.QuaggaCliHost5.generatePrefixes( 5, 10 )
133 main.log.info( prefixesHost5 )
134 for prefix in prefixesHost5:
135 allRoutesExpected.append( prefix + "/" + "192.168.60.2" )
pingping-lin79011132015-01-27 15:27:27 -0800136 routeIntentsExpectedHost5 = \
137 main.QuaggaCliHost5.generateExpectedOnePeerRouteIntents(
138 prefixesHost5, "192.168.60.1", "00:00:00:00:06:02",
139 SDNIPJSONFILEPATH )
pingping-lin8b306ac2014-11-17 18:13:51 -0800140
pingping-linc1c696e2015-01-27 13:46:44 -0800141 routeIntentsExpected = routeIntentsExpectedHost3 + \
142 routeIntentsExpectedHost4 + routeIntentsExpectedHost5
pingping-lin7048cb02015-01-30 15:09:46 -0800143
kelvin-onlab8a832582015-01-16 17:06:11 -0800144 main.step( "Get devices in the network" )
pingping-linc1c696e2015-01-27 13:46:44 -0800145 listResult = main.ONOScli.devices( jsonFormat=False )
146 main.log.info( listResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800147 time.sleep( 10 )
148 main.log.info( "Installing sdn-ip feature" )
pingping-linc1c696e2015-01-27 13:46:44 -0800149 main.ONOScli.featureInstall( "onos-app-sdnip" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800150 time.sleep( 10 )
151 main.step( "Login all BGP peers and add routes into peers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800152
kelvin-onlab8a832582015-01-16 17:06:11 -0800153 main.log.info( "Login Quagga CLI on host3" )
154 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
155 main.log.info( "Enter configuration model of Quagga CLI on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800156 main.QuaggaCliHost3.enterConfig( 64514 )
kelvin-onlab8a832582015-01-16 17:06:11 -0800157 main.log.info( "Add routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800158 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
pingping-linbc230942014-12-03 18:36:27 -0800159
kelvin-onlab8a832582015-01-16 17:06:11 -0800160 main.log.info( "Login Quagga CLI on host4" )
161 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
162 main.log.info( "Enter configuration model of Quagga CLI on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800163 main.QuaggaCliHost4.enterConfig( 64516 )
kelvin-onlab8a832582015-01-16 17:06:11 -0800164 main.log.info( "Add routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800165 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
166
167 main.log.info( "Login Quagga CLI on host5" )
168 main.QuaggaCliHost5.loginQuagga( "1.168.30.5" )
169 main.log.info( "Enter configuration model of Quagga CLI on host5" )
170 main.QuaggaCliHost5.enterConfig( 64521 )
171 main.log.info( "Add routes to Quagga on host5" )
172 main.QuaggaCliHost5.addRoutes( prefixesHost5, 1 )
173
174 for i in range( 101, 201 ):
175 prefixesHostX = main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
176 main.log.info( prefixesHostX )
177 for prefix in prefixesHostX:
pingping-lin7048cb02015-01-30 15:09:46 -0800178 allRoutesExpected.append( prefix + "/" + "192.168.40."
179 + str( i - 100 ) )
pingping-linc1c696e2015-01-27 13:46:44 -0800180
pingping-lin79011132015-01-27 15:27:27 -0800181 routeIntentsExpectedHostX = \
182 main.QuaggaCliHost.generateExpectedOnePeerRouteIntents(
183 prefixesHostX, "192.168.40." + str( i - 100 ),
184 "00:00:%02d:00:00:90" % ( i - 101 ), SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800185 routeIntentsExpected = routeIntentsExpected + \
186 routeIntentsExpectedHostX
187
188 main.log.info( "Login Quagga CLI on host" + str( i ) )
189 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
190 QuaggaCliHostX.loginQuagga( "1.168.30." + str( i ) )
191 main.log.info(
192 "Enter configuration model of Quagga CLI on host" + str( i ) )
193 QuaggaCliHostX.enterConfig( 65000 + i - 100 )
194 main.log.info( "Add routes to Quagga on host" + str( i ) )
195 QuaggaCliHostX.addRoutes( prefixesHostX, 1 )
196
kelvin-onlab8a832582015-01-16 17:06:11 -0800197 time.sleep( 60 )
pingping-linc1c696e2015-01-27 13:46:44 -0800198 # get routes inside SDN-IP
199 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-linc6b86fa2014-12-01 16:18:10 -0800200
pingping-lin8b306ac2014-11-17 18:13:51 -0800201 # parse routes from ONOS CLI
pingping-lin529dad22015-02-02 16:57:35 -0800202 if branchName == "master":
203 allRoutesActual = \
204 main.QuaggaCliHost3.extractActualRoutesMaster( getRoutesResult )
205 elif branchName == "onos-1.0":
206 allRoutesActual = \
207 main.QuaggaCliHost3.extractActualRoutesOneDotZero( getRoutesResult )
208 else:
209 main.log("ONOS is on wrong branch")
210 exit
pingping-lin7048cb02015-01-30 15:09:46 -0800211
pingping-linc1c696e2015-01-27 13:46:44 -0800212 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
213 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800214 main.step( "Check routes installed" )
215 main.log.info( "Routes expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800216 main.log.info( allRoutesStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800217 main.log.info( "Routes get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800218 main.log.info( allRoutesStrActual )
219 utilities.assertEquals(
220 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800221 onpass="***Routes in SDN-IP are correct!***",
222 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800223 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800224 main.log.report(
225 "***Routes in SDN-IP after adding routes are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800226 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800227 main.log.report(
228 "***Routes in SDN-IP after adding routes are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800229
kelvin-onlab8a832582015-01-16 17:06:11 -0800230 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800231 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin6f6332e2014-11-19 19:13:58 -0800232
kelvin-onlab8a832582015-01-16 17:06:11 -0800233 main.step( "Check MultiPointToSinglePointIntent intents installed" )
pingping-linc1c696e2015-01-27 13:46:44 -0800234 # routeIntentsExpected are generated when generating routes
pingping-lin26521182015-01-30 14:52:39 -0800235 # get route intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800236 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800237 main.QuaggaCliHost3.extractActualRouteIntents(
238 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800239 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
240 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800241 main.log.info( "MultiPointToSinglePoint intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800242 main.log.info( routeIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800243 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800244 main.log.info( routeIntentsStrActual )
245 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800246 expect=True,
247 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
248 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
249 correct!***",
250 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
251 wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800252
pingping-linc1c696e2015-01-27 13:46:44 -0800253 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
pingping-lin79011132015-01-27 15:27:27 -0800254 main.log.report( "***MultiPointToSinglePoint Intents before \
255 deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800256 else:
pingping-lin79011132015-01-27 15:27:27 -0800257 main.log.report( "***MultiPointToSinglePoint Intents before \
258 deleting routes wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800259
kelvin-onlab8a832582015-01-16 17:06:11 -0800260 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800261 # bgp intents expected
pingping-lin79011132015-01-27 15:27:27 -0800262 bgpIntentsExpected = \
263 main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800264 # get BGP intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800265 bgpIntentsActual = \
266 main.QuaggaCliHost3.extractActualBgpIntents( getIntentsResult )
pingping-lin3228e132014-11-20 17:49:02 -0800267
pingping-linc1c696e2015-01-27 13:46:44 -0800268 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
269 bgpIntentsStrActual = str( bgpIntentsActual )
kelvin-onlab8a832582015-01-16 17:06:11 -0800270 main.log.info( "PointToPointIntent intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800271 main.log.info( bgpIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800272 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800273 main.log.info( bgpIntentsStrActual )
pingping-lin3228e132014-11-20 17:49:02 -0800274
pingping-linc1c696e2015-01-27 13:46:44 -0800275 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800276 expect=True,
277 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
278 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
279 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800280
pingping-linc1c696e2015-01-27 13:46:44 -0800281 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800282 main.log.report(
283 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800284 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800285 main.log.report(
286 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800287
pingping-linc6b86fa2014-12-01 16:18:10 -0800288 #============================= Ping Test ========================
pingping-lin26521182015-01-30 14:52:39 -0800289 # Wait until all MultiPointToSinglePoint intents are in system
kelvin-onlab8a832582015-01-16 17:06:11 -0800290 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800291 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800292 pingTestResultsFile = \
293 "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-before-delete-routes-" \
294 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800295 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800296 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800297 main.log.info( pingTestResults )
298 time.sleep( 20 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800299
300 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -0800301 main.step( "Check deleting routes installed" )
pingping-linc1c696e2015-01-27 13:46:44 -0800302 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
303 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
304 main.QuaggaCliHost5.deleteRoutes( prefixesHost5, 1 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800305
pingping-linc1c696e2015-01-27 13:46:44 -0800306 for i in range( 101, 201 ):
307 prefixesHostX = main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
308 main.log.info( prefixesHostX )
309 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
310 QuaggaCliHostX.deleteRoutes( prefixesHostX, 1 )
311
312 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800313 allRoutesActual = \
314 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800315 main.log.info( "allRoutes_actual = " )
pingping-linc1c696e2015-01-27 13:46:44 -0800316 main.log.info( allRoutesActual )
pingping-linc6b86fa2014-12-01 16:18:10 -0800317
pingping-lin79011132015-01-27 15:27:27 -0800318 utilities.assertEquals(
319 expect="[]", actual=str( allRoutesActual ),
320 onpass="***Route number in SDN-IP is 0, correct!***",
321 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800322
pingping-linc1c696e2015-01-27 13:46:44 -0800323 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800324 main.log.report( "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800325 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800326 main.log.report( "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800327
kelvin-onlab8a832582015-01-16 17:06:11 -0800328 main.step( "Check intents after deleting routes" )
pingping-linc1c696e2015-01-27 13:46:44 -0800329 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800330 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800331 main.QuaggaCliHost3.extractActualRouteIntents(
332 getIntentsResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800333 main.log.info( "main.ONOScli.intents()= " )
pingping-linc1c696e2015-01-27 13:46:44 -0800334 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800335 utilities.assertEquals(
336 expect="[]", actual=str( routeIntentsActual ),
337 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \
338 correct!***",
339 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \
340 wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800341
pingping-linc1c696e2015-01-27 13:46:44 -0800342 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
pingping-lin79011132015-01-27 15:27:27 -0800343 main.log.report( "***MultiPointToSinglePoint Intents after \
344 deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800345 else:
pingping-lin79011132015-01-27 15:27:27 -0800346 main.log.report( "***MultiPointToSinglePoint Intents after \
347 deleting routes wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800348
kelvin-onlab8a832582015-01-16 17:06:11 -0800349 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800350 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800351 pingTestResultsFile = \
pingping-lin26521182015-01-30 14:52:39 -0800352 "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-after-delete-routes-"\
pingping-lin79011132015-01-27 15:27:27 -0800353 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800354 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800355 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800356 main.log.info( pingTestResults )
357 time.sleep( 100 )
358
pingping-linc1c696e2015-01-27 13:46:44 -0800359 def CASE3( self, main ):
360 """
361 Test the SDN-IP functionality
362 allRoutesExpected: all expected routes for all BGP peers
pingping-lin26521182015-01-30 14:52:39 -0800363 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
364 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800365 bgpIntentsExpected: expected PointToPointIntent intents
366 allRoutesActual: all routes from ONOS LCI
pingping-lin79011132015-01-27 15:27:27 -0800367 routeIntentsActual: actual MultiPointToSinglePointIntent intents from \
368 ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800369 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
370 """
371 import time
372 import json
373 from operator import eq
374 # from datetime import datetime
375 from time import localtime, strftime
376
pingping-lin00e4f7f2015-01-27 16:30:06 -0800377 main.case( "The test case is to help to setup the TestON \
378 environment and test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800379 # SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
pingping-lin79011132015-01-27 15:27:27 -0800380 SDNIPJSONFILEPATH = \
pingping-lina600d9b2015-01-30 13:57:26 -0800381 "/home/admin/ONOS/tools/package/config/sdnip.json"
pingping-linc1c696e2015-01-27 13:46:44 -0800382 # all expected routes for all BGP peers
383 allRoutesExpected = []
384 main.step( "Start to generate routes for all BGP peers" )
385 main.log.info( "Generate prefixes for host3" )
386 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
387 main.log.info( prefixesHost3 )
388 # generate route with next hop
389 for prefix in prefixesHost3:
390 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800391 routeIntentsExpectedHost3 = \
392 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
393 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
394 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800395
396 main.log.info( "Generate prefixes for host4" )
397 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
398 main.log.info( prefixesHost4 )
399 # generate route with next hop
400 for prefix in prefixesHost4:
401 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800402 routeIntentsExpectedHost4 = \
403 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
404 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
405 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800406
407 routeIntentsExpected = routeIntentsExpectedHost3 + \
408 routeIntentsExpectedHost4
409
pingping-linc1c696e2015-01-27 13:46:44 -0800410 cellName = main.params[ 'ENV' ][ 'cellName' ]
411 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
412 main.step( "Set cell for ONOS-cli environment" )
413 main.ONOScli.setCell( cellName )
414 verifyResult = main.ONOSbench.verifyCell()
415
416 main.log.report( "Removing raft logs" )
417 main.ONOSbench.onosRemoveRaftLogs()
418 main.log.report( "Uninstalling ONOS" )
419 main.ONOSbench.onosUninstall( ONOS1Ip )
420
421 main.step( "Installing ONOS package" )
422 onos1InstallResult = main.ONOSbench.onosInstall(
423 options="-f", node=ONOS1Ip )
424
425 main.step( "Checking if ONOS is up yet" )
426 time.sleep( 60 )
427 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
428 if not onos1Isup:
429 main.log.report( "ONOS1 didn't start!" )
430
431 main.step( "Start ONOS-cli" )
432
433 main.ONOScli.startOnosCli( ONOS1Ip )
434
435 main.step( "Get devices in the network" )
436 listResult = main.ONOScli.devices( jsonFormat=False )
437 main.log.info( listResult )
438 time.sleep( 10 )
439 main.log.info( "Installing sdn-ip feature" )
440 main.ONOScli.featureInstall( "onos-app-sdnip" )
441 time.sleep( 10 )
442 main.step( "Login all BGP peers and add routes into peers" )
443
444 main.log.info( "Login Quagga CLI on host3" )
445 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
446 main.log.info( "Enter configuration model of Quagga CLI on host3" )
447 main.QuaggaCliHost3.enterConfig( 64514 )
448 main.log.info( "Add routes to Quagga on host3" )
449 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
450
451 main.log.info( "Login Quagga CLI on host4" )
452 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
453 main.log.info( "Enter configuration model of Quagga CLI on host4" )
454 main.QuaggaCliHost4.enterConfig( 64516 )
455 main.log.info( "Add routes to Quagga on host4" )
456 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
457
458 for i in range( 101, 201 ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800459 prefixesHostX = \
460 main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
pingping-linc1c696e2015-01-27 13:46:44 -0800461 main.log.info( prefixesHostX )
462 for prefix in prefixesHostX:
463 allRoutesExpected.append(
464 prefix + "/" + "192.168.40." + str( i - 100 ) )
465
pingping-lin79011132015-01-27 15:27:27 -0800466 routeIntentsExpectedHostX = \
467 main.QuaggaCliHost.generateExpectedOnePeerRouteIntents(
468 prefixesHostX, "192.168.40." + str( i - 100 ),
469 "00:00:%02d:00:00:90" % ( i - 101 ), SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800470 routeIntentsExpected = routeIntentsExpected + \
471 routeIntentsExpectedHostX
472
473 main.log.info( "Login Quagga CLI on host" + str( i ) )
474 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
475 QuaggaCliHostX.loginQuagga( "1.168.30." + str( i ) )
476 main.log.info(
477 "Enter configuration model of Quagga CLI on host" + str( i ) )
478 QuaggaCliHostX.enterConfig( 65000 + i - 100 )
479 main.log.info( "Add routes to Quagga on host" + str( i ) )
480 QuaggaCliHostX.addRoutes( prefixesHostX, 1 )
481
482 time.sleep( 60 )
483
484 # get routes inside SDN-IP
485 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
486
487 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800488 allRoutesActual = \
489 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800490
491 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
492 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
493 main.step( "Check routes installed" )
494 main.log.info( "Routes expected:" )
495 main.log.info( allRoutesStrExpected )
496 main.log.info( "Routes get from ONOS CLI:" )
497 main.log.info( allRoutesStrActual )
498 utilities.assertEquals(
499 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800500 onpass="***Routes in SDN-IP are correct!***",
501 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800502 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
503 main.log.report(
504 "***Routes in SDN-IP after adding routes are correct!***" )
505 else:
506 main.log.report(
507 "***Routes in SDN-IP after adding routes are wrong!***" )
508
509 time.sleep( 20 )
510 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
511
512 main.step( "Check MultiPointToSinglePointIntent intents installed" )
513 # routeIntentsExpected are generated when generating routes
514 # get rpoute intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800515 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800516 main.QuaggaCliHost3.extractActualRouteIntents(
517 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800518 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
519 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
520 main.log.info( "MultiPointToSinglePoint intents expected:" )
521 main.log.info( routeIntentsStrExpected )
522 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
523 main.log.info( routeIntentsStrActual )
524 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800525 expect=True,
526 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
527 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
528 correct!***",
529 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
530 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800531
532 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
533 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800534 "***MultiPointToSinglePoint Intents before deleting routes \
535 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800536 else:
537 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800538 "***MultiPointToSinglePoint Intents before deleting routes \
539 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800540
541 main.step( "Check BGP PointToPointIntent intents installed" )
542 # bgp intents expected
543 bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents(
544 SDNIPJSONFILEPATH )
545 # get BGP intents from ONOS CLI
546 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
547 getIntentsResult )
548
549 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
550 bgpIntentsStrActual = str( bgpIntentsActual )
551 main.log.info( "PointToPointIntent intents expected:" )
552 main.log.info( bgpIntentsStrExpected )
553 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
554 main.log.info( bgpIntentsStrActual )
555
556 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800557 expect=True,
558 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
559 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
560 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800561
562 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
563 main.log.report(
564 "***PointToPointIntent Intents in SDN-IP are correct!***" )
565 else:
566 main.log.report(
567 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
568
569 #============================= Ping Test ========================
570 # wait until all MultiPointToSinglePoint
571 time.sleep( 20 )
572 pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800573 pingTestResultsFile = \
574 "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-before-delete-routes-" \
575 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800576 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800577 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800578 main.log.info( pingTestResults )
579 time.sleep( 20 )
580
581 #============================= Deleting Routes ==================
582 main.step( "Check deleting routes installed" )
583 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
584 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
585 for i in range( 101, 201 ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800586 prefixesHostX = \
587 main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
pingping-linc1c696e2015-01-27 13:46:44 -0800588 main.log.info( prefixesHostX )
589 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
590 QuaggaCliHostX.deleteRoutes( prefixesHostX, 1 )
591
592 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
593 allRoutesActual = main.QuaggaCliHost3.extractActualRoutes(
594 getRoutesResult )
595 main.log.info( "allRoutes_actual = " )
596 main.log.info( allRoutesActual )
597
pingping-lin79011132015-01-27 15:27:27 -0800598 utilities.assertEquals(
599 expect="[]", actual=str( allRoutesActual ),
600 onpass="***Route number in SDN-IP is 0, correct!***",
601 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800602
603 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800604 main.log.report(
605 "***Routes in SDN-IP after deleting correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800606 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -0800607 main.log.report(
608 "***Routes in SDN-IP after deleting wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800609
610 main.step( "Check intents after deleting routes" )
611 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800612 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800613 main.QuaggaCliHost3.extractActualRouteIntents(
614 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800615 main.log.info( "main.ONOScli.intents()= " )
616 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800617 utilities.assertEquals(
618 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -0800619 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \
620 0, correct!***",
621 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \
622 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800623
624 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
625 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800626 "***MultiPointToSinglePoint Intents after deleting routes \
627 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800628 else:
629 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800630 "***MultiPointToSinglePoint Intents after deleting routes \
631 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800632
633 time.sleep( 20 )
634 pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800635 pingTestResultsFile = \
636 "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-after-delete-routes-" \
637 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800638 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800639 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800640 main.log.info( pingTestResults )
641 time.sleep( 100 )
642
643 # main.step( "Test whether Mininet is started" )
644 # main.Mininet2.handle.sendline( "xterm host1" )
645 # main.Mininet2.handle.expect( "mininet>" )
646
647 def CASE1( self, main ):
648 """
649 Test the SDN-IP functionality
650 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -0800651 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
652 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800653 bgpIntentsExpected: expected PointToPointIntent intents
654 allRoutesActual: all routes from ONOS LCI
pingping-lin00e4f7f2015-01-27 16:30:06 -0800655 routeIntentsActual: actual MultiPointToSinglePointIntent intents \
656 from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800657 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
658 """
659 import time
660 import json
661 from operator import eq
662 # from datetime import datetime
663 from time import localtime, strftime
664
pingping-lin79011132015-01-27 15:27:27 -0800665 main.case("The test case is to help to setup the TestON environment \
666 and test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800667 SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
668 # all expected routes for all BGP peers
669 allRoutesExpected = []
670 main.step( "Start to generate routes for all BGP peers" )
671 # bgpPeerHosts = []
672 # for i in range( 3, 5 ):
673 # bgpPeerHosts.append( "host" + str( i ) )
674 # main.log.info( "BGP Peer Hosts are:" + bgpPeerHosts )
675
676 # for i in range( 3, 5 ):
677 # QuaggaCliHost = "QuaggaCliHost" + str( i )
678 # prefixes = main.QuaggaCliHost.generatePrefixes( 3, 10 )
679
680 # main.log.info( prefixes )
681 # allRoutesExpected.append( prefixes )
682 main.log.info( "Generate prefixes for host3" )
683 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
684 main.log.info( prefixesHost3 )
685 # generate route with next hop
686 for prefix in prefixesHost3:
687 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800688 routeIntentsExpectedHost3 = \
689 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
690 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
691 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800692
693 main.log.info( "Generate prefixes for host4" )
694 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
695 main.log.info( prefixesHost4 )
696 # generate route with next hop
697 for prefix in prefixesHost4:
698 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800699 routeIntentsExpectedHost4 = \
700 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
701 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
702 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800703
704 routeIntentsExpected = routeIntentsExpectedHost3 + \
705 routeIntentsExpectedHost4
706
707 cellName = main.params[ 'ENV' ][ 'cellName' ]
708 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
709 main.step( "Set cell for ONOS-cli environment" )
710 main.ONOScli.setCell( cellName )
711 verifyResult = main.ONOSbench.verifyCell()
712 main.log.report( "Removing raft logs" )
713 main.ONOSbench.onosRemoveRaftLogs()
714 main.log.report( "Uninstalling ONOS" )
715 main.ONOSbench.onosUninstall( ONOS1Ip )
716 main.step( "Creating ONOS package" )
717 packageResult = main.ONOSbench.onosPackage()
718
719 main.step( "Starting ONOS service" )
720 # TODO: start ONOS from Mininet Script
721 # startResult = main.ONOSbench.onosStart( "127.0.0.1" )
722 main.step( "Installing ONOS package" )
723 onos1InstallResult = main.ONOSbench.onosInstall(
724 options="-f", node=ONOS1Ip )
725
726 main.step( "Checking if ONOS is up yet" )
727 time.sleep( 60 )
728 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
729 if not onos1Isup:
730 main.log.report( "ONOS1 didn't start!" )
731
732 main.step( "Start ONOS-cli" )
733 # TODO: change the hardcode in startOnosCli method in ONOS CLI driver
734
735 main.ONOScli.startOnosCli( ONOS1Ip )
736
737 main.step( "Get devices in the network" )
738 listResult = main.ONOScli.devices( jsonFormat=False )
739 main.log.info( listResult )
740 time.sleep( 10 )
741 main.log.info( "Installing sdn-ip feature" )
742 main.ONOScli.featureInstall( "onos-app-sdnip" )
743 time.sleep( 10 )
744 main.step( "Login all BGP peers and add routes into peers" )
745 main.log.info( "Login Quagga CLI on host3" )
746 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
747 main.log.info( "Enter configuration model of Quagga CLI on host3" )
748 main.QuaggaCliHost3.enterConfig( 64514 )
749 main.log.info( "Add routes to Quagga on host3" )
750 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
751
752 main.log.info( "Login Quagga CLI on host4" )
753 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
754 main.log.info( "Enter configuration model of Quagga CLI on host4" )
755 main.QuaggaCliHost4.enterConfig( 64516 )
756 main.log.info( "Add routes to Quagga on host4" )
757 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
758 time.sleep( 60 )
759
760 # get all routes inside SDN-IP
761 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
762
763 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800764 allRoutesActual = \
765 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800766
767 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
768 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
769 main.step( "Check routes installed" )
770 main.log.info( "Routes expected:" )
771 main.log.info( allRoutesStrExpected )
772 main.log.info( "Routes get from ONOS CLI:" )
773 main.log.info( allRoutesStrActual )
774 utilities.assertEquals(
775 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800776 onpass="***Routes in SDN-IP are correct!***",
777 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800778 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
779 main.log.report(
780 "***Routes in SDN-IP after adding routes are correct!***" )
781 else:
782 main.log.report(
783 "***Routes in SDN-IP after adding routes are wrong!***" )
784
785 time.sleep( 20 )
786 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
787
788 main.step( "Check MultiPointToSinglePointIntent intents installed" )
789 # routeIntentsExpected are generated when generating routes
790 # get rpoute intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800791 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800792 main.QuaggaCliHost3.extractActualRouteIntents(
793 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800794 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
795 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
796 main.log.info( "MultiPointToSinglePoint intents expected:" )
797 main.log.info( routeIntentsStrExpected )
798 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
799 main.log.info( routeIntentsStrActual )
800 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800801 expect=True,
802 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
803 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
804 correct!***",
805 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
806 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800807
808 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
809 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800810 "***MultiPointToSinglePoint Intents before deleting routes \
811 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800812 else:
813 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800814 "***MultiPointToSinglePoint Intents before deleting routes \
815 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800816
817 main.step( "Check BGP PointToPointIntent intents installed" )
818 # bgp intents expected
pingping-lin79011132015-01-27 15:27:27 -0800819 bgpIntentsExpected = \
820 main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800821 # get BGP intents from ONOS CLI
822 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
823 getIntentsResult )
824
825 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
826 bgpIntentsStrActual = str( bgpIntentsActual )
827 main.log.info( "PointToPointIntent intents expected:" )
828 main.log.info( bgpIntentsStrExpected )
829 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
830 main.log.info( bgpIntentsStrActual )
831
832 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800833 expect=True,
834 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
835 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
836 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800837
838 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
839 main.log.report(
840 "***PointToPointIntent Intents in SDN-IP are correct!***" )
841 else:
842 main.log.report(
843 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
844
845 #============================= Ping Test ========================
846 # wait until all MultiPointToSinglePoint
847 time.sleep( 20 )
848 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800849 pingTestResultsFile = \
850 "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-before-delete-routes-" \
851 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800852 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800853 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800854 main.log.info( pingTestResults )
855
856 # ping test
857
858 #============================= Deleting Routes ==================
859 main.step( "Check deleting routes installed" )
860 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
861 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
862
863 # main.log.info( "main.ONOScli.get_routes_num() = " )
864 # main.log.info( main.ONOScli.getRoutesNum() )
865 # utilities.assertEquals( expect="Total SDN-IP routes = 1", actual=
866 # main.ONOScli.getRoutesNum(),
867 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800868 allRoutesActual = \
869 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800870 main.log.info( "allRoutes_actual = " )
871 main.log.info( allRoutesActual )
872
pingping-lin79011132015-01-27 15:27:27 -0800873 utilities.assertEquals(
874 expect="[]", actual=str( allRoutesActual ),
875 onpass="***Route number in SDN-IP is 0, correct!***",
876 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800877
878 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800879 main.log.report(
880 "***Routes in SDN-IP after deleting correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800881 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -0800882 main.log.report(
883 "***Routes in SDN-IP after deleting wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800884
885 main.step( "Check intents after deleting routes" )
886 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800887 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800888 main.QuaggaCliHost3.extractActualRouteIntents(
889 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800890 main.log.info( "main.ONOScli.intents()= " )
891 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800892 utilities.assertEquals(
893 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -0800894 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \
895 0, correct!***",
896 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \
897 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800898
899 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
900 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800901 "***MultiPointToSinglePoint Intents after deleting routes \
902 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800903 else:
904 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800905 "***MultiPointToSinglePoint Intents after deleting routes \
906 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800907
908 time.sleep( 20 )
909 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800910 pingTestResultsFile = \
911 "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-after-delete-routes-" \
912 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800913 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800914 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800915 main.log.info( pingTestResults )
kelvin-onlab8a832582015-01-16 17:06:11 -0800916 time.sleep( 30 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800917
kelvin-onlab8a832582015-01-16 17:06:11 -0800918 # main.step( "Test whether Mininet is started" )
919 # main.Mininet2.handle.sendline( "xterm host1" )
920 # main.Mininet2.handle.expect( "mininet>" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800921
kelvin-onlab8a832582015-01-16 17:06:11 -0800922 def CASE2( self, main ):
923 """
pingping-lin3d87a132014-12-04 14:22:49 -0800924 Test the SDN-IP functionality
pingping-linc1c696e2015-01-27 13:46:44 -0800925 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -0800926 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
927 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800928 bgpIntentsExpected: expected PointToPointIntent intents
929 allRoutesActual: all routes from ONOS LCI
pingping-lin00e4f7f2015-01-27 16:30:06 -0800930 routeIntentsActual: actual MultiPointToSinglePointIntent intents \
931 from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800932 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800933 """
pingping-lin3d87a132014-12-04 14:22:49 -0800934 import time
935 import json
936 from operator import eq
937 from time import localtime, strftime
938
kelvin-onlab8a832582015-01-16 17:06:11 -0800939 main.case(
pingping-lin00e4f7f2015-01-27 16:30:06 -0800940 "The test case is to help to setup the TestON environment and \
941 test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800942 SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
pingping-lin3d87a132014-12-04 14:22:49 -0800943 # all expected routes for all BGP peers
pingping-linc1c696e2015-01-27 13:46:44 -0800944 allRoutesExpected = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800945 main.step( "Start to generate routes for all BGP peers" )
pingping-lin3d87a132014-12-04 14:22:49 -0800946
kelvin-onlab8a832582015-01-16 17:06:11 -0800947 main.log.info( "Generate prefixes for host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800948 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
949 main.log.info( prefixesHost3 )
pingping-lin3d87a132014-12-04 14:22:49 -0800950 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800951 for prefix in prefixesHost3:
952 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800953 routeIntentsExpectedHost3 = \
954 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
955 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
956 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800957
kelvin-onlab8a832582015-01-16 17:06:11 -0800958 main.log.info( "Generate prefixes for host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800959 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
960 main.log.info( prefixesHost4 )
pingping-lin3d87a132014-12-04 14:22:49 -0800961 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800962 for prefix in prefixesHost4:
963 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800964 routeIntentsExpectedHost4 = \
965 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
966 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
967 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800968
pingping-linc1c696e2015-01-27 13:46:44 -0800969 routeIntentsExpected = routeIntentsExpectedHost3 + \
970 routeIntentsExpectedHost4
pingping-lin3d87a132014-12-04 14:22:49 -0800971
kelvin-onlab8a832582015-01-16 17:06:11 -0800972 main.log.report( "Removing raft logs" )
pingping-linc1c696e2015-01-27 13:46:44 -0800973 main.ONOSbench.onosRemoveRaftLogs()
kelvin-onlab8a832582015-01-16 17:06:11 -0800974 main.log.report( "Uninstalling ONOS" )
pingping-linc1c696e2015-01-27 13:46:44 -0800975 main.ONOSbench.onosUninstall( ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800976
pingping-linc1c696e2015-01-27 13:46:44 -0800977 cellName = main.params[ 'ENV' ][ 'cellName' ]
978 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
kelvin-onlab8a832582015-01-16 17:06:11 -0800979 main.step( "Set cell for ONOS-cli environment" )
pingping-linc1c696e2015-01-27 13:46:44 -0800980 main.ONOScli.setCell( cellName )
981 verifyResult = main.ONOSbench.verifyCell()
982 # main.log.report( "Removing raft logs" )
983 # main.ONOSbench.onosRemoveRaftLogs()
984 # main.log.report( "Uninstalling ONOS" )
985 # main.ONOSbench.onosUninstall( ONOS1Ip )
kelvin-onlab8a832582015-01-16 17:06:11 -0800986 main.step( "Creating ONOS package" )
pingping-linc1c696e2015-01-27 13:46:44 -0800987 # packageResult = main.ONOSbench.onosPackage()
pingping-lin3d87a132014-12-04 14:22:49 -0800988
kelvin-onlab8a832582015-01-16 17:06:11 -0800989 main.step( "Installing ONOS package" )
pingping-linc1c696e2015-01-27 13:46:44 -0800990 # onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
991 # node=ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800992
kelvin-onlab8a832582015-01-16 17:06:11 -0800993 main.step( "Checking if ONOS is up yet" )
pingping-linc1c696e2015-01-27 13:46:44 -0800994 # time.sleep( 60 )
995 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
996 if not onos1Isup:
kelvin-onlab8a832582015-01-16 17:06:11 -0800997 main.log.report( "ONOS1 didn't start!" )
pingping-lin3d87a132014-12-04 14:22:49 -0800998
kelvin-onlab8a832582015-01-16 17:06:11 -0800999 main.step( "Start ONOS-cli" )
pingping-linc1c696e2015-01-27 13:46:44 -08001000 main.ONOScli.startOnosCli( ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -08001001
kelvin-onlab8a832582015-01-16 17:06:11 -08001002 main.step( "Get devices in the network" )
pingping-linc1c696e2015-01-27 13:46:44 -08001003 listResult = main.ONOScli.devices( jsonFormat=False )
1004 main.log.info( listResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001005 time.sleep( 10 )
1006 main.log.info( "Installing sdn-ip feature" )
pingping-linc1c696e2015-01-27 13:46:44 -08001007 main.ONOScli.featureInstall( "onos-app-sdnip" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001008 time.sleep( 10 )
pingping-lin3d87a132014-12-04 14:22:49 -08001009
kelvin-onlab8a832582015-01-16 17:06:11 -08001010 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin3d87a132014-12-04 14:22:49 -08001011 # bgp intents expected
pingping-linc1c696e2015-01-27 13:46:44 -08001012 bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents(
1013 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -08001014 # get BGP intents from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -08001015 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
1016 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
1017 getIntentsResult )
pingping-lin3d87a132014-12-04 14:22:49 -08001018
pingping-linc1c696e2015-01-27 13:46:44 -08001019 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
1020 bgpIntentsStrActual = str( bgpIntentsActual )
kelvin-onlab8a832582015-01-16 17:06:11 -08001021 main.log.info( "PointToPointIntent intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001022 main.log.info( bgpIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001023 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001024 main.log.info( bgpIntentsStrActual )
pingping-lin3d87a132014-12-04 14:22:49 -08001025
pingping-linc1c696e2015-01-27 13:46:44 -08001026 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -08001027 expect=True,
1028 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
1029 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
1030 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001031
pingping-linc1c696e2015-01-27 13:46:44 -08001032 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001033 main.log.report(
1034 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001035 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001036 main.log.report(
1037 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001038
pingping-linc1c696e2015-01-27 13:46:44 -08001039 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
1040 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
1041 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
1042 # roundNum = 0;
kelvin-onlab8a832582015-01-16 17:06:11 -08001043 # while( True ):
pingping-linc1c696e2015-01-27 13:46:44 -08001044 for roundNum in range( 1, 6 ):
pingping-lin3d87a132014-12-04 14:22:49 -08001045 # round = round + 1;
pingping-linc1c696e2015-01-27 13:46:44 -08001046 main.log.report( "The Round " + str( roundNum ) +
pingping-lin00e4f7f2015-01-27 16:30:06 -08001047 " test starts................................" )
pingping-lin3d87a132014-12-04 14:22:49 -08001048
kelvin-onlab8a832582015-01-16 17:06:11 -08001049 main.step( "Login all BGP peers and add routes into peers" )
1050 main.log.info( "Login Quagga CLI on host3" )
1051 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
pingping-lin00e4f7f2015-01-27 16:30:06 -08001052 main.log.info(
1053 "Enter configuration model of Quagga CLI on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001054 main.QuaggaCliHost3.enterConfig( 64514 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001055 main.log.info( "Add routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001056 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -08001057
kelvin-onlab8a832582015-01-16 17:06:11 -08001058 main.log.info( "Login Quagga CLI on host4" )
1059 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
pingping-lin00e4f7f2015-01-27 16:30:06 -08001060 main.log.info(
1061 "Enter configuration model of Quagga CLI on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001062 main.QuaggaCliHost4.enterConfig( 64516 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001063 main.log.info( "Add routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001064 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001065 time.sleep( 60 )
pingping-lin3d87a132014-12-04 14:22:49 -08001066
1067 # get all routes inside SDN-IP
pingping-linc1c696e2015-01-27 13:46:44 -08001068 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin3d87a132014-12-04 14:22:49 -08001069
1070 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -08001071 allRoutesActual = \
1072 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-lin3d87a132014-12-04 14:22:49 -08001073
pingping-linc1c696e2015-01-27 13:46:44 -08001074 # allRoutesStrExpected = str( sorted( allRoutesExpected ) )
1075 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001076 main.step( "Check routes installed" )
1077 main.log.info( "Routes expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001078 main.log.info( allRoutesStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001079 main.log.info( "Routes get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001080 main.log.info( allRoutesStrActual )
1081 utilities.assertEquals(
1082 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -08001083 onpass="***Routes in SDN-IP are correct!***",
1084 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -08001085 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001086 main.log.report(
1087 "***Routes in SDN-IP after adding correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001088 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -08001089 main.log.report(
1090 "***Routes in SDN-IP after adding wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001091
kelvin-onlab8a832582015-01-16 17:06:11 -08001092 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001093 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin3d87a132014-12-04 14:22:49 -08001094
kelvin-onlab8a832582015-01-16 17:06:11 -08001095 main.step(
1096 "Check MultiPointToSinglePointIntent intents installed" )
pingping-linc1c696e2015-01-27 13:46:44 -08001097 # routeIntentsExpected are generated when generating routes
pingping-lin3d87a132014-12-04 14:22:49 -08001098 # get route intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -08001099 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -08001100 main.QuaggaCliHost3.extractActualRouteIntents(
1101 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -08001102 # routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
1103 routeIntentsStrActual = str(
pingping-lin79011132015-01-27 15:27:27 -08001104 routeIntentsActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001105 main.log.info( "MultiPointToSinglePoint intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001106 main.log.info( routeIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001107 main.log.info(
1108 "MultiPointToSinglePoint intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001109 main.log.info( routeIntentsStrActual )
1110 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -08001111 expect=True,
1112 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
1113 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
1114 correct!***",
1115 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
1116 wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001117
pingping-linc1c696e2015-01-27 13:46:44 -08001118 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001119 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -08001120 "***MultiPointToSinglePoint Intents after adding routes \
1121 correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001122 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001123 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -08001124 "***MultiPointToSinglePoint Intents after adding routes \
1125 wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001126
1127 #============================= Ping Test ========================
1128 # wait until all MultiPointToSinglePoint
kelvin-onlab8a832582015-01-16 17:06:11 -08001129 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001130 # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin00e4f7f2015-01-27 16:30:06 -08001131 pingTestResultsFile = \
1132 "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \
pingping-lin79011132015-01-27 15:27:27 -08001133 + str( roundNum ) + "-ping-results-before-delete-routes-" \
1134 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -08001135 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -08001136 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -08001137 main.log.info( pingTestResults )
pingping-lin3d87a132014-12-04 14:22:49 -08001138 # ping test
1139
1140 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -08001141 main.step( "Check deleting routes installed" )
1142 main.log.info( "Delete routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001143 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001144 main.log.info( "Delete routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001145 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -08001146
pingping-linc1c696e2015-01-27 13:46:44 -08001147 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -08001148 allRoutesActual = \
1149 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001150 main.log.info( "allRoutes_actual = " )
pingping-linc1c696e2015-01-27 13:46:44 -08001151 main.log.info( allRoutesActual )
pingping-lin3d87a132014-12-04 14:22:49 -08001152
pingping-lin79011132015-01-27 15:27:27 -08001153 utilities.assertEquals(
1154 expect="[]", actual=str( allRoutesActual ),
1155 onpass="***Route number in SDN-IP is 0, correct!***",
1156 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001157
pingping-linc1c696e2015-01-27 13:46:44 -08001158 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001159 main.log.report(
1160 "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001161 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001162 main.log.report(
1163 "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001164
kelvin-onlab8a832582015-01-16 17:06:11 -08001165 main.step( "Check intents after deleting routes" )
pingping-linc1c696e2015-01-27 13:46:44 -08001166 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -08001167 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -08001168 main.QuaggaCliHost3.extractActualRouteIntents(
1169 getIntentsResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001170 main.log.info( "main.ONOScli.intents()= " )
pingping-linc1c696e2015-01-27 13:46:44 -08001171 main.log.info( routeIntentsActual )
1172 utilities.assertEquals(
1173 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -08001174 onpass=
1175 "***MultiPointToSinglePoint Intents number in SDN-IP \
1176 is 0, correct!***",
1177 onfail="***MultiPointToSinglePoint Intents number in SDN-IP \
1178 is 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001179
pingping-linc1c696e2015-01-27 13:46:44 -08001180 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001181 main.log.report(
pingping-lin00e4f7f2015-01-27 16:30:06 -08001182 "***MultiPointToSinglePoint Intents after deleting \
1183 routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001184 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001185 main.log.report(
pingping-lin00e4f7f2015-01-27 16:30:06 -08001186 "***MultiPointToSinglePoint Intents after deleting \
1187 routes wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001188
kelvin-onlab8a832582015-01-16 17:06:11 -08001189 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001190 # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin00e4f7f2015-01-27 16:30:06 -08001191 pingTestResultsFile = \
1192 "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \
pingping-lin79011132015-01-27 15:27:27 -08001193 + str( roundNum ) + "-ping-results-after-delete-routes-" \
1194 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -08001195 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -08001196 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -08001197 main.log.info( pingTestResults )
kelvin-onlab8a832582015-01-16 17:06:11 -08001198 time.sleep( 30 )
pingping-linc1c696e2015-01-27 13:46:44 -08001199