blob: 3a766dd2d19328bf86255962b9de68d6c7f1ebd4 [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 """
pingping-linc8fcd0c2015-05-20 15:22:46 -070022 import time
pingping-lina600d9b2015-01-30 13:57:26 -080023 main.case( "Setting up test environment" )
pingping-lin8b306ac2014-11-17 18:13:51 -080024
pingping-lina600d9b2015-01-30 13:57:26 -080025 cellName = main.params[ 'ENV' ][ 'cellName' ]
26 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
pingping-linc1c696e2015-01-27 13:46:44 -080027
pingping-lina600d9b2015-01-30 13:57:26 -080028 main.step( "Applying cell variable to environment" )
29 cellResult = main.ONOSbench.setCell( cellName )
30 verifyResult = main.ONOSbench.verifyCell()
pingping-lin26521182015-01-30 14:52:39 -080031
pingping-lin529dad22015-02-02 16:57:35 -080032 branchName = main.ONOSbench.getBranchName()
33 main.log.info( "ONOS is on branch: " + branchName )
34
pingping-lina600d9b2015-01-30 13:57:26 -080035 main.log.report( "Uninstalling ONOS" )
36 main.ONOSbench.onosUninstall( ONOS1Ip )
pingping-linc1c696e2015-01-27 13:46:44 -080037
pingping-lina600d9b2015-01-30 13:57:26 -080038 cleanInstallResult = main.TRUE
39 gitPullResult = main.TRUE
pingping-lin26521182015-01-30 14:52:39 -080040
pingping-lina600d9b2015-01-30 13:57:26 -080041 main.step( "Git pull" )
pingping-lina600d9b2015-01-30 13:57:26 -080042 gitPullResult = main.ONOSbench.gitPull()
pingping-lin26521182015-01-30 14:52:39 -080043
pingping-lina600d9b2015-01-30 13:57:26 -080044 main.step( "Using mvn clean & install" )
45 cleanInstallResult = main.TRUE
pingping-lin529dad22015-02-02 16:57:35 -080046# if gitPullResult == main.TRUE:
47# cleanInstallResult = main.ONOSbench.cleanInstall()
48# else:
49# main.log.warn( "Did not pull new code so skipping mvn " +
50# "clean install" )
pingping-lin57a56ce2015-05-20 16:43:48 -070051 cleanInstallResult = main.ONOSbench.cleanInstall( mciTimeout= 1000 )
pingping-lina600d9b2015-01-30 13:57:26 -080052 main.ONOSbench.getVersion( report=True )
pingping-lin7048cb02015-01-30 15:09:46 -080053
pingping-lin26521182015-01-30 14:52:39 -080054 #cellResult = main.ONOSbench.setCell( cellName )
55 #verifyResult = main.ONOSbench.verifyCell()
pingping-lina600d9b2015-01-30 13:57:26 -080056 main.step( "Creating ONOS package" )
pingping-lin57a56ce2015-05-20 16:43:48 -070057 packageResult = main.ONOSbench.onosPackage( opTimeout=500 )
pingping-lin7048cb02015-01-30 15:09:46 -080058
pingping-lina600d9b2015-01-30 13:57:26 -080059 main.step( "Installing ONOS package" )
60 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
61 node=ONOS1Ip )
pingping-lin7048cb02015-01-30 15:09:46 -080062
pingping-lina600d9b2015-01-30 13:57:26 -080063 main.step( "Checking if ONOS is up yet" )
pingping-linc8fcd0c2015-05-20 15:22:46 -070064 #time.sleep( 300 )
pingping-lina600d9b2015-01-30 13:57:26 -080065 for i in range( 2 ):
pingping-lina0ac6922015-05-20 17:54:43 -070066 onos1Isup = main.ONOSbench.isup( ONOS1Ip, timeout=420 )
pingping-lina600d9b2015-01-30 13:57:26 -080067 if onos1Isup:
68 break
69 if not onos1Isup:
70 main.log.report( "ONOS1 didn't start!" )
pingping-lin7048cb02015-01-30 15:09:46 -080071
pingping-lin57a56ce2015-05-20 16:43:48 -070072 cliResult = main.ONOScli.startOnosCli( ONOS1Ip,
73 commandlineTimeout=100, onosStartTimeout=600)
pingping-lin7048cb02015-01-30 15:09:46 -080074
pingping-lina600d9b2015-01-30 13:57:26 -080075 case1Result = ( cleanInstallResult and packageResult and
76 cellResult and verifyResult and
77 onos1InstallResult and
78 onos1Isup and cliResult )
pingping-lin7048cb02015-01-30 15:09:46 -080079
pingping-lina600d9b2015-01-30 13:57:26 -080080 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
pingping-lin26521182015-01-30 14:52:39 -080081 onpass="ONOS startup successful",
82 onfail="ONOS startup NOT successful" )
pingping-lin7048cb02015-01-30 15:09:46 -080083
pingping-lina600d9b2015-01-30 13:57:26 -080084 if case1Result == main.FALSE:
85 main.cleanup()
86 main.exit()
pingping-linc1c696e2015-01-27 13:46:44 -080087
88 def CASE4( self, main ):
kelvin-onlab8a832582015-01-16 17:06:11 -080089 """
pingping-lin8b306ac2014-11-17 18:13:51 -080090 Test the SDN-IP functionality
pingping-linc1c696e2015-01-27 13:46:44 -080091 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -080092 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
93 intents
pingping-linc1c696e2015-01-27 13:46:44 -080094 bgpIntentsExpected: expected PointToPointIntent intents
95 allRoutesActual: all routes from ONOS LCI
pingping-lin79011132015-01-27 15:27:27 -080096 routeIntentsActual: actual MultiPointToSinglePointIntent intents from \
97 ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -080098 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -080099 """
pingping-lin8b306ac2014-11-17 18:13:51 -0800100 import time
101 import json
102 from operator import eq
pingping-lin01355a62014-12-02 20:58:14 -0800103 from time import localtime, strftime
pingping-linc6b86fa2014-12-01 16:18:10 -0800104
pingping-lin26521182015-01-30 14:52:39 -0800105 main.case("This case is to testing the functionality of SDN-IP with \
106 single ONOS instance" )
pingping-lin79011132015-01-27 15:27:27 -0800107 SDNIPJSONFILEPATH = \
pingping-lina600d9b2015-01-30 13:57:26 -0800108 "/home/admin/ONOS/tools/package/config/sdnip.json"
pingping-lin6f6332e2014-11-19 19:13:58 -0800109 # all expected routes for all BGP peers
pingping-linc1c696e2015-01-27 13:46:44 -0800110 allRoutesExpected = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800111 main.step( "Start to generate routes for all BGP peers" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800112 main.log.info( "Generate prefixes for host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800113 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
114 main.log.info( prefixesHost3 )
pingping-lin36fbe802014-11-25 16:01:14 -0800115 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800116 for prefix in prefixesHost3:
117 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800118 routeIntentsExpectedHost3 = \
119 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
120 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
121 SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800122
kelvin-onlab8a832582015-01-16 17:06:11 -0800123 main.log.info( "Generate prefixes for host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800124 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
125 main.log.info( prefixesHost4 )
pingping-lin36fbe802014-11-25 16:01:14 -0800126 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800127 for prefix in prefixesHost4:
128 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800129 routeIntentsExpectedHost4 = \
130 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
131 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
132 SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800133
pingping-linc1c696e2015-01-27 13:46:44 -0800134 main.log.info( "Generate prefixes for host5" )
135 prefixesHost5 = main.QuaggaCliHost5.generatePrefixes( 5, 10 )
136 main.log.info( prefixesHost5 )
137 for prefix in prefixesHost5:
138 allRoutesExpected.append( prefix + "/" + "192.168.60.2" )
pingping-lin79011132015-01-27 15:27:27 -0800139 routeIntentsExpectedHost5 = \
140 main.QuaggaCliHost5.generateExpectedOnePeerRouteIntents(
141 prefixesHost5, "192.168.60.1", "00:00:00:00:06:02",
142 SDNIPJSONFILEPATH )
pingping-lin8b306ac2014-11-17 18:13:51 -0800143
pingping-linc1c696e2015-01-27 13:46:44 -0800144 routeIntentsExpected = routeIntentsExpectedHost3 + \
145 routeIntentsExpectedHost4 + routeIntentsExpectedHost5
pingping-lin7048cb02015-01-30 15:09:46 -0800146
kelvin-onlab8a832582015-01-16 17:06:11 -0800147 main.step( "Get devices in the network" )
pingping-linc1c696e2015-01-27 13:46:44 -0800148 listResult = main.ONOScli.devices( jsonFormat=False )
149 main.log.info( listResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800150 time.sleep( 10 )
151 main.log.info( "Installing sdn-ip feature" )
pingping-linc1c696e2015-01-27 13:46:44 -0800152 main.ONOScli.featureInstall( "onos-app-sdnip" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800153 time.sleep( 10 )
154 main.step( "Login all BGP peers and add routes into peers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800155
kelvin-onlab8a832582015-01-16 17:06:11 -0800156 main.log.info( "Login Quagga CLI on host3" )
157 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
158 main.log.info( "Enter configuration model of Quagga CLI on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800159 main.QuaggaCliHost3.enterConfig( 64514 )
kelvin-onlab8a832582015-01-16 17:06:11 -0800160 main.log.info( "Add routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800161 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
pingping-linbc230942014-12-03 18:36:27 -0800162
kelvin-onlab8a832582015-01-16 17:06:11 -0800163 main.log.info( "Login Quagga CLI on host4" )
164 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
165 main.log.info( "Enter configuration model of Quagga CLI on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800166 main.QuaggaCliHost4.enterConfig( 64516 )
kelvin-onlab8a832582015-01-16 17:06:11 -0800167 main.log.info( "Add routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800168 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
169
170 main.log.info( "Login Quagga CLI on host5" )
171 main.QuaggaCliHost5.loginQuagga( "1.168.30.5" )
172 main.log.info( "Enter configuration model of Quagga CLI on host5" )
173 main.QuaggaCliHost5.enterConfig( 64521 )
174 main.log.info( "Add routes to Quagga on host5" )
175 main.QuaggaCliHost5.addRoutes( prefixesHost5, 1 )
176
177 for i in range( 101, 201 ):
178 prefixesHostX = main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
179 main.log.info( prefixesHostX )
180 for prefix in prefixesHostX:
pingping-lin7048cb02015-01-30 15:09:46 -0800181 allRoutesExpected.append( prefix + "/" + "192.168.40."
182 + str( i - 100 ) )
pingping-linc1c696e2015-01-27 13:46:44 -0800183
pingping-lin79011132015-01-27 15:27:27 -0800184 routeIntentsExpectedHostX = \
185 main.QuaggaCliHost.generateExpectedOnePeerRouteIntents(
186 prefixesHostX, "192.168.40." + str( i - 100 ),
187 "00:00:%02d:00:00:90" % ( i - 101 ), SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800188 routeIntentsExpected = routeIntentsExpected + \
189 routeIntentsExpectedHostX
190
191 main.log.info( "Login Quagga CLI on host" + str( i ) )
192 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
193 QuaggaCliHostX.loginQuagga( "1.168.30." + str( i ) )
194 main.log.info(
195 "Enter configuration model of Quagga CLI on host" + str( i ) )
196 QuaggaCliHostX.enterConfig( 65000 + i - 100 )
197 main.log.info( "Add routes to Quagga on host" + str( i ) )
198 QuaggaCliHostX.addRoutes( prefixesHostX, 1 )
199
kelvin-onlab8a832582015-01-16 17:06:11 -0800200 time.sleep( 60 )
pingping-linc1c696e2015-01-27 13:46:44 -0800201 # get routes inside SDN-IP
202 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-linc6b86fa2014-12-01 16:18:10 -0800203
pingping-lin8b306ac2014-11-17 18:13:51 -0800204 # parse routes from ONOS CLI
pingping-linc8fcd0c2015-05-20 15:22:46 -0700205 #if branchName == "master":
206 # allRoutesActual = \
207 # main.QuaggaCliHost3.extractActualRoutesMaster( getRoutesResult )
208 #elif branchName == "onos-1.0":
209 # allRoutesActual = \
210 # main.QuaggaCliHost3.extractActualRoutesOneDotZero( getRoutesResult )
211 #else:
212 # main.log("ONOS is on wrong branch")
213 # exit
214
215 allRoutesActual = \
pingping-lin529dad22015-02-02 16:57:35 -0800216 main.QuaggaCliHost3.extractActualRoutesMaster( getRoutesResult )
pingping-lin7048cb02015-01-30 15:09:46 -0800217
pingping-linc1c696e2015-01-27 13:46:44 -0800218 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
219 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800220 main.step( "Check routes installed" )
221 main.log.info( "Routes expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800222 main.log.info( allRoutesStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800223 main.log.info( "Routes get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800224 main.log.info( allRoutesStrActual )
225 utilities.assertEquals(
226 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800227 onpass="***Routes in SDN-IP are correct!***",
228 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800229 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800230 main.log.report(
231 "***Routes in SDN-IP after adding routes are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800232 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800233 main.log.report(
234 "***Routes in SDN-IP after adding routes are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800235
kelvin-onlab8a832582015-01-16 17:06:11 -0800236 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800237 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin6f6332e2014-11-19 19:13:58 -0800238
kelvin-onlab8a832582015-01-16 17:06:11 -0800239 main.step( "Check MultiPointToSinglePointIntent intents installed" )
pingping-linc1c696e2015-01-27 13:46:44 -0800240 # routeIntentsExpected are generated when generating routes
pingping-lin26521182015-01-30 14:52:39 -0800241 # get route intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800242 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800243 main.QuaggaCliHost3.extractActualRouteIntents(
244 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800245 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
246 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -0800247 main.log.info( "MultiPointToSinglePoint intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800248 main.log.info( routeIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800249 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800250 main.log.info( routeIntentsStrActual )
251 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800252 expect=True,
253 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
254 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
255 correct!***",
256 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
257 wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800258
pingping-linc1c696e2015-01-27 13:46:44 -0800259 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
pingping-lin79011132015-01-27 15:27:27 -0800260 main.log.report( "***MultiPointToSinglePoint Intents before \
261 deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800262 else:
pingping-lin79011132015-01-27 15:27:27 -0800263 main.log.report( "***MultiPointToSinglePoint Intents before \
264 deleting routes wrong!***" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800265
kelvin-onlab8a832582015-01-16 17:06:11 -0800266 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin6f6332e2014-11-19 19:13:58 -0800267 # bgp intents expected
pingping-lin79011132015-01-27 15:27:27 -0800268 bgpIntentsExpected = \
269 main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH )
pingping-lin6f6332e2014-11-19 19:13:58 -0800270 # get BGP intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800271 bgpIntentsActual = \
272 main.QuaggaCliHost3.extractActualBgpIntents( getIntentsResult )
pingping-lin3228e132014-11-20 17:49:02 -0800273
pingping-linc1c696e2015-01-27 13:46:44 -0800274 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
275 bgpIntentsStrActual = str( bgpIntentsActual )
kelvin-onlab8a832582015-01-16 17:06:11 -0800276 main.log.info( "PointToPointIntent intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800277 main.log.info( bgpIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -0800278 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -0800279 main.log.info( bgpIntentsStrActual )
pingping-lin3228e132014-11-20 17:49:02 -0800280
pingping-linc1c696e2015-01-27 13:46:44 -0800281 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800282 expect=True,
283 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
284 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
285 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800286
pingping-linc1c696e2015-01-27 13:46:44 -0800287 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800288 main.log.report(
289 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800290 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800291 main.log.report(
292 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800293
pingping-linc6b86fa2014-12-01 16:18:10 -0800294 #============================= Ping Test ========================
pingping-lin26521182015-01-30 14:52:39 -0800295 # Wait until all MultiPointToSinglePoint intents are in system
kelvin-onlab8a832582015-01-16 17:06:11 -0800296 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800297 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800298 pingTestResultsFile = \
299 "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-before-delete-routes-" \
300 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800301 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800302 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800303 main.log.info( pingTestResults )
304 time.sleep( 20 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800305
306 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -0800307 main.step( "Check deleting routes installed" )
pingping-linc1c696e2015-01-27 13:46:44 -0800308 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
309 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
310 main.QuaggaCliHost5.deleteRoutes( prefixesHost5, 1 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800311
pingping-linc1c696e2015-01-27 13:46:44 -0800312 for i in range( 101, 201 ):
313 prefixesHostX = main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
314 main.log.info( prefixesHostX )
315 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
316 QuaggaCliHostX.deleteRoutes( prefixesHostX, 1 )
317
318 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800319 allRoutesActual = \
320 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800321 main.log.info( "allRoutes_actual = " )
pingping-linc1c696e2015-01-27 13:46:44 -0800322 main.log.info( allRoutesActual )
pingping-linc6b86fa2014-12-01 16:18:10 -0800323
pingping-lin79011132015-01-27 15:27:27 -0800324 utilities.assertEquals(
325 expect="[]", actual=str( allRoutesActual ),
326 onpass="***Route number in SDN-IP is 0, correct!***",
327 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800328
pingping-linc1c696e2015-01-27 13:46:44 -0800329 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -0800330 main.log.report( "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800331 else:
kelvin-onlab8a832582015-01-16 17:06:11 -0800332 main.log.report( "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800333
kelvin-onlab8a832582015-01-16 17:06:11 -0800334 main.step( "Check intents after deleting routes" )
pingping-linc1c696e2015-01-27 13:46:44 -0800335 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800336 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800337 main.QuaggaCliHost3.extractActualRouteIntents(
338 getIntentsResult )
kelvin-onlab8a832582015-01-16 17:06:11 -0800339 main.log.info( "main.ONOScli.intents()= " )
pingping-linc1c696e2015-01-27 13:46:44 -0800340 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800341 utilities.assertEquals(
342 expect="[]", actual=str( routeIntentsActual ),
343 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \
344 correct!***",
345 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \
346 wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800347
pingping-linc1c696e2015-01-27 13:46:44 -0800348 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
pingping-lin79011132015-01-27 15:27:27 -0800349 main.log.report( "***MultiPointToSinglePoint Intents after \
350 deleting routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -0800351 else:
pingping-lin79011132015-01-27 15:27:27 -0800352 main.log.report( "***MultiPointToSinglePoint Intents after \
353 deleting routes wrong!***" )
pingping-linc6b86fa2014-12-01 16:18:10 -0800354
kelvin-onlab8a832582015-01-16 17:06:11 -0800355 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -0800356 pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800357 pingTestResultsFile = \
pingping-lin26521182015-01-30 14:52:39 -0800358 "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-after-delete-routes-"\
pingping-lin79011132015-01-27 15:27:27 -0800359 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800360 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800361 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800362 main.log.info( pingTestResults )
363 time.sleep( 100 )
364
pingping-linc1c696e2015-01-27 13:46:44 -0800365 def CASE3( self, main ):
366 """
367 Test the SDN-IP functionality
368 allRoutesExpected: all expected routes for all BGP peers
pingping-lin26521182015-01-30 14:52:39 -0800369 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
370 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800371 bgpIntentsExpected: expected PointToPointIntent intents
372 allRoutesActual: all routes from ONOS LCI
pingping-lin79011132015-01-27 15:27:27 -0800373 routeIntentsActual: actual MultiPointToSinglePointIntent intents from \
374 ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800375 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
376 """
377 import time
378 import json
379 from operator import eq
380 # from datetime import datetime
381 from time import localtime, strftime
382
pingping-lin00e4f7f2015-01-27 16:30:06 -0800383 main.case( "The test case is to help to setup the TestON \
384 environment and test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800385 # SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
pingping-lin79011132015-01-27 15:27:27 -0800386 SDNIPJSONFILEPATH = \
pingping-lina600d9b2015-01-30 13:57:26 -0800387 "/home/admin/ONOS/tools/package/config/sdnip.json"
pingping-linc1c696e2015-01-27 13:46:44 -0800388 # all expected routes for all BGP peers
389 allRoutesExpected = []
390 main.step( "Start to generate routes for all BGP peers" )
391 main.log.info( "Generate prefixes for host3" )
392 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
393 main.log.info( prefixesHost3 )
394 # generate route with next hop
395 for prefix in prefixesHost3:
396 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800397 routeIntentsExpectedHost3 = \
398 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
399 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
400 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800401
402 main.log.info( "Generate prefixes for host4" )
403 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
404 main.log.info( prefixesHost4 )
405 # generate route with next hop
406 for prefix in prefixesHost4:
407 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800408 routeIntentsExpectedHost4 = \
409 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
410 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
411 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800412
413 routeIntentsExpected = routeIntentsExpectedHost3 + \
414 routeIntentsExpectedHost4
415
pingping-linc1c696e2015-01-27 13:46:44 -0800416 cellName = main.params[ 'ENV' ][ 'cellName' ]
417 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
418 main.step( "Set cell for ONOS-cli environment" )
419 main.ONOScli.setCell( cellName )
420 verifyResult = main.ONOSbench.verifyCell()
421
422 main.log.report( "Removing raft logs" )
423 main.ONOSbench.onosRemoveRaftLogs()
424 main.log.report( "Uninstalling ONOS" )
425 main.ONOSbench.onosUninstall( ONOS1Ip )
426
427 main.step( "Installing ONOS package" )
428 onos1InstallResult = main.ONOSbench.onosInstall(
429 options="-f", node=ONOS1Ip )
430
431 main.step( "Checking if ONOS is up yet" )
432 time.sleep( 60 )
433 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
434 if not onos1Isup:
435 main.log.report( "ONOS1 didn't start!" )
436
437 main.step( "Start ONOS-cli" )
438
439 main.ONOScli.startOnosCli( ONOS1Ip )
440
441 main.step( "Get devices in the network" )
442 listResult = main.ONOScli.devices( jsonFormat=False )
443 main.log.info( listResult )
444 time.sleep( 10 )
445 main.log.info( "Installing sdn-ip feature" )
446 main.ONOScli.featureInstall( "onos-app-sdnip" )
447 time.sleep( 10 )
448 main.step( "Login all BGP peers and add routes into peers" )
449
450 main.log.info( "Login Quagga CLI on host3" )
451 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
452 main.log.info( "Enter configuration model of Quagga CLI on host3" )
453 main.QuaggaCliHost3.enterConfig( 64514 )
454 main.log.info( "Add routes to Quagga on host3" )
455 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
456
457 main.log.info( "Login Quagga CLI on host4" )
458 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
459 main.log.info( "Enter configuration model of Quagga CLI on host4" )
460 main.QuaggaCliHost4.enterConfig( 64516 )
461 main.log.info( "Add routes to Quagga on host4" )
462 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
463
464 for i in range( 101, 201 ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800465 prefixesHostX = \
466 main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
pingping-linc1c696e2015-01-27 13:46:44 -0800467 main.log.info( prefixesHostX )
468 for prefix in prefixesHostX:
469 allRoutesExpected.append(
470 prefix + "/" + "192.168.40." + str( i - 100 ) )
471
pingping-lin79011132015-01-27 15:27:27 -0800472 routeIntentsExpectedHostX = \
473 main.QuaggaCliHost.generateExpectedOnePeerRouteIntents(
474 prefixesHostX, "192.168.40." + str( i - 100 ),
475 "00:00:%02d:00:00:90" % ( i - 101 ), SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800476 routeIntentsExpected = routeIntentsExpected + \
477 routeIntentsExpectedHostX
478
479 main.log.info( "Login Quagga CLI on host" + str( i ) )
480 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
481 QuaggaCliHostX.loginQuagga( "1.168.30." + str( i ) )
482 main.log.info(
483 "Enter configuration model of Quagga CLI on host" + str( i ) )
484 QuaggaCliHostX.enterConfig( 65000 + i - 100 )
485 main.log.info( "Add routes to Quagga on host" + str( i ) )
486 QuaggaCliHostX.addRoutes( prefixesHostX, 1 )
487
488 time.sleep( 60 )
489
490 # get routes inside SDN-IP
491 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
492
493 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800494 allRoutesActual = \
495 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800496
497 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
498 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
499 main.step( "Check routes installed" )
500 main.log.info( "Routes expected:" )
501 main.log.info( allRoutesStrExpected )
502 main.log.info( "Routes get from ONOS CLI:" )
503 main.log.info( allRoutesStrActual )
504 utilities.assertEquals(
505 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800506 onpass="***Routes in SDN-IP are correct!***",
507 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800508 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
509 main.log.report(
510 "***Routes in SDN-IP after adding routes are correct!***" )
511 else:
512 main.log.report(
513 "***Routes in SDN-IP after adding routes are wrong!***" )
514
515 time.sleep( 20 )
516 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
517
518 main.step( "Check MultiPointToSinglePointIntent intents installed" )
519 # routeIntentsExpected are generated when generating routes
520 # get rpoute intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800521 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800522 main.QuaggaCliHost3.extractActualRouteIntents(
523 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800524 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
525 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
526 main.log.info( "MultiPointToSinglePoint intents expected:" )
527 main.log.info( routeIntentsStrExpected )
528 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
529 main.log.info( routeIntentsStrActual )
530 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800531 expect=True,
532 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
533 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
534 correct!***",
535 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
536 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800537
538 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
539 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800540 "***MultiPointToSinglePoint Intents before deleting routes \
541 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800542 else:
543 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800544 "***MultiPointToSinglePoint Intents before deleting routes \
545 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800546
547 main.step( "Check BGP PointToPointIntent intents installed" )
548 # bgp intents expected
549 bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents(
550 SDNIPJSONFILEPATH )
551 # get BGP intents from ONOS CLI
552 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
553 getIntentsResult )
554
555 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
556 bgpIntentsStrActual = str( bgpIntentsActual )
557 main.log.info( "PointToPointIntent intents expected:" )
558 main.log.info( bgpIntentsStrExpected )
559 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
560 main.log.info( bgpIntentsStrActual )
561
562 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800563 expect=True,
564 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
565 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
566 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800567
568 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
569 main.log.report(
570 "***PointToPointIntent Intents in SDN-IP are correct!***" )
571 else:
572 main.log.report(
573 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
574
575 #============================= Ping Test ========================
576 # wait until all MultiPointToSinglePoint
577 time.sleep( 20 )
578 pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800579 pingTestResultsFile = \
580 "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-before-delete-routes-" \
581 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800582 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800583 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800584 main.log.info( pingTestResults )
585 time.sleep( 20 )
586
587 #============================= Deleting Routes ==================
588 main.step( "Check deleting routes installed" )
589 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
590 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
591 for i in range( 101, 201 ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800592 prefixesHostX = \
593 main.QuaggaCliHost.generatePrefixes( str( i ), 10 )
pingping-linc1c696e2015-01-27 13:46:44 -0800594 main.log.info( prefixesHostX )
595 QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) )
596 QuaggaCliHostX.deleteRoutes( prefixesHostX, 1 )
597
598 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
599 allRoutesActual = main.QuaggaCliHost3.extractActualRoutes(
600 getRoutesResult )
601 main.log.info( "allRoutes_actual = " )
602 main.log.info( allRoutesActual )
603
pingping-lin79011132015-01-27 15:27:27 -0800604 utilities.assertEquals(
605 expect="[]", actual=str( allRoutesActual ),
606 onpass="***Route number in SDN-IP is 0, correct!***",
607 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800608
609 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800610 main.log.report(
611 "***Routes in SDN-IP after deleting correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800612 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -0800613 main.log.report(
614 "***Routes in SDN-IP after deleting wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800615
616 main.step( "Check intents after deleting routes" )
617 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800618 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800619 main.QuaggaCliHost3.extractActualRouteIntents(
620 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800621 main.log.info( "main.ONOScli.intents()= " )
622 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800623 utilities.assertEquals(
624 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -0800625 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \
626 0, correct!***",
627 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \
628 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800629
630 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
631 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800632 "***MultiPointToSinglePoint Intents after deleting routes \
633 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800634 else:
635 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800636 "***MultiPointToSinglePoint Intents after deleting routes \
637 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800638
639 time.sleep( 20 )
640 pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800641 pingTestResultsFile = \
642 "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-after-delete-routes-" \
643 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800644 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800645 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800646 main.log.info( pingTestResults )
647 time.sleep( 100 )
648
649 # main.step( "Test whether Mininet is started" )
650 # main.Mininet2.handle.sendline( "xterm host1" )
651 # main.Mininet2.handle.expect( "mininet>" )
652
653 def CASE1( self, main ):
654 """
655 Test the SDN-IP functionality
656 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -0800657 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
658 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800659 bgpIntentsExpected: expected PointToPointIntent intents
660 allRoutesActual: all routes from ONOS LCI
pingping-lin00e4f7f2015-01-27 16:30:06 -0800661 routeIntentsActual: actual MultiPointToSinglePointIntent intents \
662 from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800663 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
664 """
665 import time
666 import json
667 from operator import eq
668 # from datetime import datetime
669 from time import localtime, strftime
670
pingping-lin79011132015-01-27 15:27:27 -0800671 main.case("The test case is to help to setup the TestON environment \
672 and test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800673 SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
674 # all expected routes for all BGP peers
675 allRoutesExpected = []
676 main.step( "Start to generate routes for all BGP peers" )
677 # bgpPeerHosts = []
678 # for i in range( 3, 5 ):
679 # bgpPeerHosts.append( "host" + str( i ) )
680 # main.log.info( "BGP Peer Hosts are:" + bgpPeerHosts )
681
682 # for i in range( 3, 5 ):
683 # QuaggaCliHost = "QuaggaCliHost" + str( i )
684 # prefixes = main.QuaggaCliHost.generatePrefixes( 3, 10 )
685
686 # main.log.info( prefixes )
687 # allRoutesExpected.append( prefixes )
688 main.log.info( "Generate prefixes for host3" )
689 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
690 main.log.info( prefixesHost3 )
691 # generate route with next hop
692 for prefix in prefixesHost3:
693 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800694 routeIntentsExpectedHost3 = \
695 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
696 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
697 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800698
699 main.log.info( "Generate prefixes for host4" )
700 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
701 main.log.info( prefixesHost4 )
702 # generate route with next hop
703 for prefix in prefixesHost4:
704 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800705 routeIntentsExpectedHost4 = \
706 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
707 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
708 SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800709
710 routeIntentsExpected = routeIntentsExpectedHost3 + \
711 routeIntentsExpectedHost4
712
713 cellName = main.params[ 'ENV' ][ 'cellName' ]
714 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
715 main.step( "Set cell for ONOS-cli environment" )
716 main.ONOScli.setCell( cellName )
717 verifyResult = main.ONOSbench.verifyCell()
718 main.log.report( "Removing raft logs" )
719 main.ONOSbench.onosRemoveRaftLogs()
720 main.log.report( "Uninstalling ONOS" )
721 main.ONOSbench.onosUninstall( ONOS1Ip )
722 main.step( "Creating ONOS package" )
723 packageResult = main.ONOSbench.onosPackage()
724
725 main.step( "Starting ONOS service" )
726 # TODO: start ONOS from Mininet Script
727 # startResult = main.ONOSbench.onosStart( "127.0.0.1" )
728 main.step( "Installing ONOS package" )
729 onos1InstallResult = main.ONOSbench.onosInstall(
730 options="-f", node=ONOS1Ip )
731
732 main.step( "Checking if ONOS is up yet" )
733 time.sleep( 60 )
734 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
735 if not onos1Isup:
736 main.log.report( "ONOS1 didn't start!" )
737
738 main.step( "Start ONOS-cli" )
739 # TODO: change the hardcode in startOnosCli method in ONOS CLI driver
740
741 main.ONOScli.startOnosCli( ONOS1Ip )
742
743 main.step( "Get devices in the network" )
744 listResult = main.ONOScli.devices( jsonFormat=False )
745 main.log.info( listResult )
746 time.sleep( 10 )
747 main.log.info( "Installing sdn-ip feature" )
748 main.ONOScli.featureInstall( "onos-app-sdnip" )
749 time.sleep( 10 )
750 main.step( "Login all BGP peers and add routes into peers" )
751 main.log.info( "Login Quagga CLI on host3" )
752 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
753 main.log.info( "Enter configuration model of Quagga CLI on host3" )
754 main.QuaggaCliHost3.enterConfig( 64514 )
755 main.log.info( "Add routes to Quagga on host3" )
756 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
757
758 main.log.info( "Login Quagga CLI on host4" )
759 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
760 main.log.info( "Enter configuration model of Quagga CLI on host4" )
761 main.QuaggaCliHost4.enterConfig( 64516 )
762 main.log.info( "Add routes to Quagga on host4" )
763 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
764 time.sleep( 60 )
765
766 # get all routes inside SDN-IP
767 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
768
769 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800770 allRoutesActual = \
771 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800772
773 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
774 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
775 main.step( "Check routes installed" )
776 main.log.info( "Routes expected:" )
777 main.log.info( allRoutesStrExpected )
778 main.log.info( "Routes get from ONOS CLI:" )
779 main.log.info( allRoutesStrActual )
780 utilities.assertEquals(
781 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -0800782 onpass="***Routes in SDN-IP are correct!***",
783 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800784 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
785 main.log.report(
786 "***Routes in SDN-IP after adding routes are correct!***" )
787 else:
788 main.log.report(
789 "***Routes in SDN-IP after adding routes are wrong!***" )
790
791 time.sleep( 20 )
792 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
793
794 main.step( "Check MultiPointToSinglePointIntent intents installed" )
795 # routeIntentsExpected are generated when generating routes
796 # get rpoute intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -0800797 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800798 main.QuaggaCliHost3.extractActualRouteIntents(
799 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800800 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
801 routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" )
802 main.log.info( "MultiPointToSinglePoint intents expected:" )
803 main.log.info( routeIntentsStrExpected )
804 main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" )
805 main.log.info( routeIntentsStrActual )
806 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800807 expect=True,
808 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
809 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
810 correct!***",
811 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
812 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800813
814 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
815 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800816 "***MultiPointToSinglePoint Intents before deleting routes \
817 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800818 else:
819 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800820 "***MultiPointToSinglePoint Intents before deleting routes \
821 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800822
823 main.step( "Check BGP PointToPointIntent intents installed" )
824 # bgp intents expected
pingping-lin79011132015-01-27 15:27:27 -0800825 bgpIntentsExpected = \
826 main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH )
pingping-linc1c696e2015-01-27 13:46:44 -0800827 # get BGP intents from ONOS CLI
828 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
829 getIntentsResult )
830
831 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
832 bgpIntentsStrActual = str( bgpIntentsActual )
833 main.log.info( "PointToPointIntent intents expected:" )
834 main.log.info( bgpIntentsStrExpected )
835 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
836 main.log.info( bgpIntentsStrActual )
837
838 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -0800839 expect=True,
840 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
841 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
842 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800843
844 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
845 main.log.report(
846 "***PointToPointIntent Intents in SDN-IP are correct!***" )
847 else:
848 main.log.report(
849 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
850
851 #============================= Ping Test ========================
852 # wait until all MultiPointToSinglePoint
853 time.sleep( 20 )
854 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800855 pingTestResultsFile = \
856 "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-before-delete-routes-" \
857 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800858 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800859 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800860 main.log.info( pingTestResults )
861
862 # ping test
863
864 #============================= Deleting Routes ==================
865 main.step( "Check deleting routes installed" )
866 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
867 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
868
869 # main.log.info( "main.ONOScli.get_routes_num() = " )
870 # main.log.info( main.ONOScli.getRoutesNum() )
871 # utilities.assertEquals( expect="Total SDN-IP routes = 1", actual=
872 # main.ONOScli.getRoutesNum(),
873 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800874 allRoutesActual = \
875 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800876 main.log.info( "allRoutes_actual = " )
877 main.log.info( allRoutesActual )
878
pingping-lin79011132015-01-27 15:27:27 -0800879 utilities.assertEquals(
880 expect="[]", actual=str( allRoutesActual ),
881 onpass="***Route number in SDN-IP is 0, correct!***",
882 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800883
884 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
pingping-lin00e4f7f2015-01-27 16:30:06 -0800885 main.log.report(
886 "***Routes in SDN-IP after deleting correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800887 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -0800888 main.log.report(
889 "***Routes in SDN-IP after deleting wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800890
891 main.step( "Check intents after deleting routes" )
892 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -0800893 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -0800894 main.QuaggaCliHost3.extractActualRouteIntents(
895 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -0800896 main.log.info( "main.ONOScli.intents()= " )
897 main.log.info( routeIntentsActual )
pingping-lin79011132015-01-27 15:27:27 -0800898 utilities.assertEquals(
899 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -0800900 onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \
901 0, correct!***",
902 onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \
903 0, wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800904
905 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
906 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800907 "***MultiPointToSinglePoint Intents after deleting routes \
908 correct!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800909 else:
910 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -0800911 "***MultiPointToSinglePoint Intents after deleting routes \
912 wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -0800913
914 time.sleep( 20 )
915 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin79011132015-01-27 15:27:27 -0800916 pingTestResultsFile = \
917 "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-after-delete-routes-" \
918 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -0800919 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -0800920 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -0800921 main.log.info( pingTestResults )
kelvin-onlab8a832582015-01-16 17:06:11 -0800922 time.sleep( 30 )
pingping-linc6b86fa2014-12-01 16:18:10 -0800923
kelvin-onlab8a832582015-01-16 17:06:11 -0800924 # main.step( "Test whether Mininet is started" )
925 # main.Mininet2.handle.sendline( "xterm host1" )
926 # main.Mininet2.handle.expect( "mininet>" )
pingping-lin8b306ac2014-11-17 18:13:51 -0800927
kelvin-onlab8a832582015-01-16 17:06:11 -0800928 def CASE2( self, main ):
929 """
pingping-lin3d87a132014-12-04 14:22:49 -0800930 Test the SDN-IP functionality
pingping-linc1c696e2015-01-27 13:46:44 -0800931 allRoutesExpected: all expected routes for all BGP peers
pingping-lin00e4f7f2015-01-27 16:30:06 -0800932 routeIntentsExpected: all expected MultiPointToSinglePointIntent \
933 intents
pingping-linc1c696e2015-01-27 13:46:44 -0800934 bgpIntentsExpected: expected PointToPointIntent intents
935 allRoutesActual: all routes from ONOS LCI
pingping-lin00e4f7f2015-01-27 16:30:06 -0800936 routeIntentsActual: actual MultiPointToSinglePointIntent intents \
937 from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -0800938 bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI
kelvin-onlab8a832582015-01-16 17:06:11 -0800939 """
pingping-lin3d87a132014-12-04 14:22:49 -0800940 import time
941 import json
942 from operator import eq
943 from time import localtime, strftime
944
kelvin-onlab8a832582015-01-16 17:06:11 -0800945 main.case(
pingping-lin00e4f7f2015-01-27 16:30:06 -0800946 "The test case is to help to setup the TestON environment and \
947 test new drivers" )
pingping-linc1c696e2015-01-27 13:46:44 -0800948 SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json"
pingping-lin3d87a132014-12-04 14:22:49 -0800949 # all expected routes for all BGP peers
pingping-linc1c696e2015-01-27 13:46:44 -0800950 allRoutesExpected = []
kelvin-onlab8a832582015-01-16 17:06:11 -0800951 main.step( "Start to generate routes for all BGP peers" )
pingping-lin3d87a132014-12-04 14:22:49 -0800952
kelvin-onlab8a832582015-01-16 17:06:11 -0800953 main.log.info( "Generate prefixes for host3" )
pingping-linc1c696e2015-01-27 13:46:44 -0800954 prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 )
955 main.log.info( prefixesHost3 )
pingping-lin3d87a132014-12-04 14:22:49 -0800956 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800957 for prefix in prefixesHost3:
958 allRoutesExpected.append( prefix + "/" + "192.168.20.1" )
pingping-lin79011132015-01-27 15:27:27 -0800959 routeIntentsExpectedHost3 = \
960 main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents(
961 prefixesHost3, "192.168.20.1", "00:00:00:00:02:02",
962 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800963
kelvin-onlab8a832582015-01-16 17:06:11 -0800964 main.log.info( "Generate prefixes for host4" )
pingping-linc1c696e2015-01-27 13:46:44 -0800965 prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 )
966 main.log.info( prefixesHost4 )
pingping-lin3d87a132014-12-04 14:22:49 -0800967 # generate route with next hop
pingping-linc1c696e2015-01-27 13:46:44 -0800968 for prefix in prefixesHost4:
969 allRoutesExpected.append( prefix + "/" + "192.168.30.1" )
pingping-lin79011132015-01-27 15:27:27 -0800970 routeIntentsExpectedHost4 = \
971 main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents(
972 prefixesHost4, "192.168.30.1", "00:00:00:00:03:01",
973 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -0800974
pingping-linc1c696e2015-01-27 13:46:44 -0800975 routeIntentsExpected = routeIntentsExpectedHost3 + \
976 routeIntentsExpectedHost4
pingping-lin3d87a132014-12-04 14:22:49 -0800977
kelvin-onlab8a832582015-01-16 17:06:11 -0800978 main.log.report( "Removing raft logs" )
pingping-linc1c696e2015-01-27 13:46:44 -0800979 main.ONOSbench.onosRemoveRaftLogs()
kelvin-onlab8a832582015-01-16 17:06:11 -0800980 main.log.report( "Uninstalling ONOS" )
pingping-linc1c696e2015-01-27 13:46:44 -0800981 main.ONOSbench.onosUninstall( ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800982
pingping-linc1c696e2015-01-27 13:46:44 -0800983 cellName = main.params[ 'ENV' ][ 'cellName' ]
984 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
kelvin-onlab8a832582015-01-16 17:06:11 -0800985 main.step( "Set cell for ONOS-cli environment" )
pingping-linc1c696e2015-01-27 13:46:44 -0800986 main.ONOScli.setCell( cellName )
987 verifyResult = main.ONOSbench.verifyCell()
988 # main.log.report( "Removing raft logs" )
989 # main.ONOSbench.onosRemoveRaftLogs()
990 # main.log.report( "Uninstalling ONOS" )
991 # main.ONOSbench.onosUninstall( ONOS1Ip )
kelvin-onlab8a832582015-01-16 17:06:11 -0800992 main.step( "Creating ONOS package" )
pingping-linc1c696e2015-01-27 13:46:44 -0800993 # packageResult = main.ONOSbench.onosPackage()
pingping-lin3d87a132014-12-04 14:22:49 -0800994
kelvin-onlab8a832582015-01-16 17:06:11 -0800995 main.step( "Installing ONOS package" )
pingping-linc1c696e2015-01-27 13:46:44 -0800996 # onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
997 # node=ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -0800998
kelvin-onlab8a832582015-01-16 17:06:11 -0800999 main.step( "Checking if ONOS is up yet" )
pingping-linc1c696e2015-01-27 13:46:44 -08001000 # time.sleep( 60 )
1001 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
1002 if not onos1Isup:
kelvin-onlab8a832582015-01-16 17:06:11 -08001003 main.log.report( "ONOS1 didn't start!" )
pingping-lin3d87a132014-12-04 14:22:49 -08001004
kelvin-onlab8a832582015-01-16 17:06:11 -08001005 main.step( "Start ONOS-cli" )
pingping-linc1c696e2015-01-27 13:46:44 -08001006 main.ONOScli.startOnosCli( ONOS1Ip )
pingping-lin3d87a132014-12-04 14:22:49 -08001007
kelvin-onlab8a832582015-01-16 17:06:11 -08001008 main.step( "Get devices in the network" )
pingping-linc1c696e2015-01-27 13:46:44 -08001009 listResult = main.ONOScli.devices( jsonFormat=False )
1010 main.log.info( listResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001011 time.sleep( 10 )
1012 main.log.info( "Installing sdn-ip feature" )
pingping-linc1c696e2015-01-27 13:46:44 -08001013 main.ONOScli.featureInstall( "onos-app-sdnip" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001014 time.sleep( 10 )
pingping-lin3d87a132014-12-04 14:22:49 -08001015
kelvin-onlab8a832582015-01-16 17:06:11 -08001016 main.step( "Check BGP PointToPointIntent intents installed" )
pingping-lin3d87a132014-12-04 14:22:49 -08001017 # bgp intents expected
pingping-linc1c696e2015-01-27 13:46:44 -08001018 bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents(
1019 SDNIPJSONFILEPATH )
pingping-lin3d87a132014-12-04 14:22:49 -08001020 # get BGP intents from ONOS CLI
pingping-linc1c696e2015-01-27 13:46:44 -08001021 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
1022 bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents(
1023 getIntentsResult )
pingping-lin3d87a132014-12-04 14:22:49 -08001024
pingping-linc1c696e2015-01-27 13:46:44 -08001025 bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" )
1026 bgpIntentsStrActual = str( bgpIntentsActual )
kelvin-onlab8a832582015-01-16 17:06:11 -08001027 main.log.info( "PointToPointIntent intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001028 main.log.info( bgpIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001029 main.log.info( "PointToPointIntent intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001030 main.log.info( bgpIntentsStrActual )
pingping-lin3d87a132014-12-04 14:22:49 -08001031
pingping-linc1c696e2015-01-27 13:46:44 -08001032 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -08001033 expect=True,
1034 actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ),
1035 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
1036 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001037
pingping-linc1c696e2015-01-27 13:46:44 -08001038 if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001039 main.log.report(
1040 "***PointToPointIntent Intents in SDN-IP are correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001041 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001042 main.log.report(
1043 "***PointToPointIntent Intents in SDN-IP are wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001044
pingping-linc1c696e2015-01-27 13:46:44 -08001045 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
1046 routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
1047 pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
1048 # roundNum = 0;
kelvin-onlab8a832582015-01-16 17:06:11 -08001049 # while( True ):
pingping-linc1c696e2015-01-27 13:46:44 -08001050 for roundNum in range( 1, 6 ):
pingping-lin3d87a132014-12-04 14:22:49 -08001051 # round = round + 1;
pingping-linc1c696e2015-01-27 13:46:44 -08001052 main.log.report( "The Round " + str( roundNum ) +
pingping-lin00e4f7f2015-01-27 16:30:06 -08001053 " test starts................................" )
pingping-lin3d87a132014-12-04 14:22:49 -08001054
kelvin-onlab8a832582015-01-16 17:06:11 -08001055 main.step( "Login all BGP peers and add routes into peers" )
1056 main.log.info( "Login Quagga CLI on host3" )
1057 main.QuaggaCliHost3.loginQuagga( "1.168.30.2" )
pingping-lin00e4f7f2015-01-27 16:30:06 -08001058 main.log.info(
1059 "Enter configuration model of Quagga CLI on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001060 main.QuaggaCliHost3.enterConfig( 64514 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001061 main.log.info( "Add routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001062 main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -08001063
kelvin-onlab8a832582015-01-16 17:06:11 -08001064 main.log.info( "Login Quagga CLI on host4" )
1065 main.QuaggaCliHost4.loginQuagga( "1.168.30.3" )
pingping-lin00e4f7f2015-01-27 16:30:06 -08001066 main.log.info(
1067 "Enter configuration model of Quagga CLI on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001068 main.QuaggaCliHost4.enterConfig( 64516 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001069 main.log.info( "Add routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001070 main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001071 time.sleep( 60 )
pingping-lin3d87a132014-12-04 14:22:49 -08001072
1073 # get all routes inside SDN-IP
pingping-linc1c696e2015-01-27 13:46:44 -08001074 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin3d87a132014-12-04 14:22:49 -08001075
1076 # parse routes from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -08001077 allRoutesActual = \
1078 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
pingping-lin3d87a132014-12-04 14:22:49 -08001079
pingping-linc1c696e2015-01-27 13:46:44 -08001080 # allRoutesStrExpected = str( sorted( allRoutesExpected ) )
1081 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001082 main.step( "Check routes installed" )
1083 main.log.info( "Routes expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001084 main.log.info( allRoutesStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001085 main.log.info( "Routes get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001086 main.log.info( allRoutesStrActual )
1087 utilities.assertEquals(
1088 expect=allRoutesStrExpected, actual=allRoutesStrActual,
pingping-lin79011132015-01-27 15:27:27 -08001089 onpass="***Routes in SDN-IP are correct!***",
1090 onfail="***Routes in SDN-IP are wrong!***" )
pingping-linc1c696e2015-01-27 13:46:44 -08001091 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001092 main.log.report(
1093 "***Routes in SDN-IP after adding correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001094 else:
pingping-lin00e4f7f2015-01-27 16:30:06 -08001095 main.log.report(
1096 "***Routes in SDN-IP after adding wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001097
kelvin-onlab8a832582015-01-16 17:06:11 -08001098 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001099 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin3d87a132014-12-04 14:22:49 -08001100
kelvin-onlab8a832582015-01-16 17:06:11 -08001101 main.step(
1102 "Check MultiPointToSinglePointIntent intents installed" )
pingping-linc1c696e2015-01-27 13:46:44 -08001103 # routeIntentsExpected are generated when generating routes
pingping-lin3d87a132014-12-04 14:22:49 -08001104 # get route intents from ONOS CLI
pingping-lin79011132015-01-27 15:27:27 -08001105 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -08001106 main.QuaggaCliHost3.extractActualRouteIntents(
1107 getIntentsResult )
pingping-linc1c696e2015-01-27 13:46:44 -08001108 # routeIntentsStrExpected = str( sorted( routeIntentsExpected ) )
1109 routeIntentsStrActual = str(
pingping-lin79011132015-01-27 15:27:27 -08001110 routeIntentsActual ).replace( 'u', "" )
kelvin-onlab8a832582015-01-16 17:06:11 -08001111 main.log.info( "MultiPointToSinglePoint intents expected:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001112 main.log.info( routeIntentsStrExpected )
kelvin-onlab8a832582015-01-16 17:06:11 -08001113 main.log.info(
1114 "MultiPointToSinglePoint intents get from ONOS CLI:" )
pingping-linc1c696e2015-01-27 13:46:44 -08001115 main.log.info( routeIntentsStrActual )
1116 utilities.assertEquals(
pingping-lin79011132015-01-27 15:27:27 -08001117 expect=True,
1118 actual=eq( routeIntentsStrExpected, routeIntentsStrActual ),
1119 onpass="***MultiPointToSinglePoint Intents in SDN-IP are \
1120 correct!***",
1121 onfail="***MultiPointToSinglePoint Intents in SDN-IP are \
1122 wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001123
pingping-linc1c696e2015-01-27 13:46:44 -08001124 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001125 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -08001126 "***MultiPointToSinglePoint Intents after adding routes \
1127 correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001128 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001129 main.log.report(
pingping-lin79011132015-01-27 15:27:27 -08001130 "***MultiPointToSinglePoint Intents after adding routes \
1131 wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001132
1133 #============================= Ping Test ========================
1134 # wait until all MultiPointToSinglePoint
kelvin-onlab8a832582015-01-16 17:06:11 -08001135 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001136 # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin00e4f7f2015-01-27 16:30:06 -08001137 pingTestResultsFile = \
1138 "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \
pingping-lin79011132015-01-27 15:27:27 -08001139 + str( roundNum ) + "-ping-results-before-delete-routes-" \
1140 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -08001141 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -08001142 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -08001143 main.log.info( pingTestResults )
pingping-lin3d87a132014-12-04 14:22:49 -08001144 # ping test
1145
1146 #============================= Deleting Routes ==================
kelvin-onlab8a832582015-01-16 17:06:11 -08001147 main.step( "Check deleting routes installed" )
1148 main.log.info( "Delete routes to Quagga on host3" )
pingping-linc1c696e2015-01-27 13:46:44 -08001149 main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 )
kelvin-onlab8a832582015-01-16 17:06:11 -08001150 main.log.info( "Delete routes to Quagga on host4" )
pingping-linc1c696e2015-01-27 13:46:44 -08001151 main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 )
pingping-lin3d87a132014-12-04 14:22:49 -08001152
pingping-linc1c696e2015-01-27 13:46:44 -08001153 getRoutesResult = main.ONOScli.routes( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -08001154 allRoutesActual = \
1155 main.QuaggaCliHost3.extractActualRoutes( getRoutesResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001156 main.log.info( "allRoutes_actual = " )
pingping-linc1c696e2015-01-27 13:46:44 -08001157 main.log.info( allRoutesActual )
pingping-lin3d87a132014-12-04 14:22:49 -08001158
pingping-lin79011132015-01-27 15:27:27 -08001159 utilities.assertEquals(
1160 expect="[]", actual=str( allRoutesActual ),
1161 onpass="***Route number in SDN-IP is 0, correct!***",
1162 onfail="***Routes number in SDN-IP is not 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001163
pingping-linc1c696e2015-01-27 13:46:44 -08001164 if( eq( allRoutesStrExpected, allRoutesStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001165 main.log.report(
1166 "***Routes in SDN-IP after deleting correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001167 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001168 main.log.report(
1169 "***Routes in SDN-IP after deleting wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001170
kelvin-onlab8a832582015-01-16 17:06:11 -08001171 main.step( "Check intents after deleting routes" )
pingping-linc1c696e2015-01-27 13:46:44 -08001172 getIntentsResult = main.ONOScli.intents( jsonFormat=True )
pingping-lin79011132015-01-27 15:27:27 -08001173 routeIntentsActual = \
pingping-lin00e4f7f2015-01-27 16:30:06 -08001174 main.QuaggaCliHost3.extractActualRouteIntents(
1175 getIntentsResult )
kelvin-onlab8a832582015-01-16 17:06:11 -08001176 main.log.info( "main.ONOScli.intents()= " )
pingping-linc1c696e2015-01-27 13:46:44 -08001177 main.log.info( routeIntentsActual )
1178 utilities.assertEquals(
1179 expect="[]", actual=str( routeIntentsActual ),
pingping-lin00e4f7f2015-01-27 16:30:06 -08001180 onpass=
1181 "***MultiPointToSinglePoint Intents number in SDN-IP \
1182 is 0, correct!***",
1183 onfail="***MultiPointToSinglePoint Intents number in SDN-IP \
1184 is 0, wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001185
pingping-linc1c696e2015-01-27 13:46:44 -08001186 if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ):
kelvin-onlab8a832582015-01-16 17:06:11 -08001187 main.log.report(
pingping-lin00e4f7f2015-01-27 16:30:06 -08001188 "***MultiPointToSinglePoint Intents after deleting \
1189 routes correct!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001190 else:
kelvin-onlab8a832582015-01-16 17:06:11 -08001191 main.log.report(
pingping-lin00e4f7f2015-01-27 16:30:06 -08001192 "***MultiPointToSinglePoint Intents after deleting \
1193 routes wrong!***" )
pingping-lin3d87a132014-12-04 14:22:49 -08001194
kelvin-onlab8a832582015-01-16 17:06:11 -08001195 time.sleep( 20 )
pingping-linc1c696e2015-01-27 13:46:44 -08001196 # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh"
pingping-lin00e4f7f2015-01-27 16:30:06 -08001197 pingTestResultsFile = \
1198 "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \
pingping-lin79011132015-01-27 15:27:27 -08001199 + str( roundNum ) + "-ping-results-after-delete-routes-" \
1200 + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt"
pingping-linc1c696e2015-01-27 13:46:44 -08001201 pingTestResults = main.QuaggaCliHost.pingTest(
pingping-lin79011132015-01-27 15:27:27 -08001202 "1.168.30.100", pingTestScript, pingTestResultsFile )
pingping-linc1c696e2015-01-27 13:46:44 -08001203 main.log.info( pingTestResults )
kelvin-onlab8a832582015-01-16 17:06:11 -08001204 time.sleep( 30 )
pingping-linc1c696e2015-01-27 13:46:44 -08001205