Srikanth Vavilapalli | 0abf3f6 | 2015-02-24 21:27:43 -0800 | [diff] [blame^] | 1 | # from cupshelpers.config import prefix |
| 2 | |
| 3 | # Testing the basic functionality of ONOS Peering Router/BGP Router |
| 4 | |
| 5 | |
| 6 | class PeeringRouterTest: |
| 7 | |
| 8 | def __init__( self ): |
| 9 | self.default = '' |
| 10 | |
| 11 | # from cupshelpers.config import prefix |
| 12 | |
| 13 | # Testing the basic functionality of SDN-IP |
| 14 | |
| 15 | |
| 16 | class PeeringRouterTest: |
| 17 | |
| 18 | def __init__( self ): |
| 19 | self.default = '' |
| 20 | |
| 21 | def CASE4( self, main ): |
| 22 | """ |
| 23 | Test the SDN-IP functionality |
| 24 | allRoutesExpected: all expected routes for all BGP peers |
| 25 | routeIntentsExpected: all expected MultiPointToSinglePointIntent \ |
| 26 | intents |
| 27 | bgpIntentsExpected: expected PointToPointIntent intents |
| 28 | allRoutesActual: all routes from ONOS LCI |
| 29 | routeIntentsActual: actual MultiPointToSinglePointIntent intents from \ |
| 30 | ONOS CLI |
| 31 | bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI |
| 32 | """ |
| 33 | import time |
| 34 | import json |
| 35 | from operator import eq |
| 36 | # from datetime import datetime |
| 37 | from time import localtime, strftime |
| 38 | |
| 39 | main.case("The test case is to help to setup the TestON environment \ |
| 40 | and test new drivers" ) |
| 41 | # SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json" |
| 42 | SDNIPJSONFILEPATH = \ |
| 43 | "/home/tutorial1/TestON/tests/PeeringRouterTest/sdnip.json" |
| 44 | # all expected routes for all BGP peers |
| 45 | allRoutesExpected = [] |
| 46 | main.step( "Start to generate routes for all BGP peers" ) |
| 47 | main.log.info( "Generate prefixes for host3" ) |
| 48 | prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 ) |
| 49 | main.log.info( prefixesHost3 ) |
| 50 | # generate route with next hop |
| 51 | for prefix in prefixesHost3: |
| 52 | allRoutesExpected.append( prefix + "/" + "192.168.20.1" ) |
| 53 | routeIntentsExpectedHost3 = \ |
| 54 | main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents( |
| 55 | prefixesHost3, "192.168.20.1", "00:00:00:00:02:02", |
| 56 | SDNIPJSONFILEPATH ) |
| 57 | |
| 58 | main.log.info( "Generate prefixes for host4" ) |
| 59 | prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 ) |
| 60 | main.log.info( prefixesHost4 ) |
| 61 | # generate route with next hop |
| 62 | for prefix in prefixesHost4: |
| 63 | allRoutesExpected.append( prefix + "/" + "192.168.30.1" ) |
| 64 | routeIntentsExpectedHost4 = \ |
| 65 | main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents( |
| 66 | prefixesHost4, "192.168.30.1", "00:00:00:00:03:01", |
| 67 | SDNIPJSONFILEPATH ) |
| 68 | |
| 69 | main.log.info( "Generate prefixes for host5" ) |
| 70 | prefixesHost5 = main.QuaggaCliHost5.generatePrefixes( 5, 10 ) |
| 71 | main.log.info( prefixesHost5 ) |
| 72 | for prefix in prefixesHost5: |
| 73 | allRoutesExpected.append( prefix + "/" + "192.168.60.2" ) |
| 74 | routeIntentsExpectedHost5 = \ |
| 75 | main.QuaggaCliHost5.generateExpectedOnePeerRouteIntents( |
| 76 | prefixesHost5, "192.168.60.1", "00:00:00:00:06:02", |
| 77 | SDNIPJSONFILEPATH ) |
| 78 | |
| 79 | routeIntentsExpected = routeIntentsExpectedHost3 + \ |
| 80 | routeIntentsExpectedHost4 + routeIntentsExpectedHost5 |
| 81 | |
| 82 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 83 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 84 | main.step( "Set cell for ONOS-cli environment" ) |
| 85 | main.ONOScli.setCell( cellName ) |
| 86 | verifyResult = main.ONOSbench.verifyCell() |
| 87 | |
| 88 | main.log.report( "Removing raft logs" ) |
| 89 | main.ONOSbench.onosRemoveRaftLogs() |
| 90 | main.log.report( "Uninstalling ONOS" ) |
| 91 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 92 | |
| 93 | main.step( "Installing ONOS package" ) |
| 94 | onos1InstallResult = main.ONOSbench.onosInstall( |
| 95 | options="-f", node=ONOS1Ip ) |
| 96 | |
| 97 | main.step( "Checking if ONOS is up yet" ) |
| 98 | time.sleep( 60 ) |
| 99 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 100 | if not onos1Isup: |
| 101 | main.log.report( "ONOS1 didn't start!" ) |
| 102 | |
| 103 | main.step( "Start ONOS-cli" ) |
| 104 | |
| 105 | main.ONOScli.startOnosCli( ONOS1Ip ) |
| 106 | |
| 107 | main.step( "Get devices in the network" ) |
| 108 | listResult = main.ONOScli.devices( jsonFormat=False ) |
| 109 | main.log.info( listResult ) |
| 110 | time.sleep( 10 ) |
| 111 | main.log.info( "Installing sdn-ip feature" ) |
| 112 | main.ONOScli.featureInstall( "onos-app-sdnip" ) |
| 113 | time.sleep( 10 ) |
| 114 | main.step( "Login all BGP peers and add routes into peers" ) |
| 115 | |
| 116 | main.log.info( "Login Quagga CLI on host3" ) |
| 117 | main.QuaggaCliHost3.loginQuagga( "1.168.30.2" ) |
| 118 | main.log.info( "Enter configuration model of Quagga CLI on host3" ) |
| 119 | main.QuaggaCliHost3.enterConfig( 64514 ) |
| 120 | main.log.info( "Add routes to Quagga on host3" ) |
| 121 | main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 ) |
| 122 | |
| 123 | main.log.info( "Login Quagga CLI on host4" ) |
| 124 | main.QuaggaCliHost4.loginQuagga( "1.168.30.3" ) |
| 125 | main.log.info( "Enter configuration model of Quagga CLI on host4" ) |
| 126 | main.QuaggaCliHost4.enterConfig( 64516 ) |
| 127 | main.log.info( "Add routes to Quagga on host4" ) |
| 128 | main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 ) |
| 129 | |
| 130 | main.log.info( "Login Quagga CLI on host5" ) |
| 131 | main.QuaggaCliHost5.loginQuagga( "1.168.30.5" ) |
| 132 | main.log.info( "Enter configuration model of Quagga CLI on host5" ) |
| 133 | main.QuaggaCliHost5.enterConfig( 64521 ) |
| 134 | main.log.info( "Add routes to Quagga on host5" ) |
| 135 | main.QuaggaCliHost5.addRoutes( prefixesHost5, 1 ) |
| 136 | |
| 137 | time.sleep( 60 ) |
| 138 | |
| 139 | # get routes inside SDN-IP |
| 140 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 141 | |
| 142 | # parse routes from ONOS CLI |
| 143 | allRoutesActual = \ |
| 144 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 145 | |
| 146 | allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 147 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 148 | main.step( "Check routes installed" ) |
| 149 | main.log.info( "Routes expected:" ) |
| 150 | main.log.info( allRoutesStrExpected ) |
| 151 | main.log.info( "Routes get from ONOS CLI:" ) |
| 152 | main.log.info( allRoutesStrActual ) |
| 153 | utilities.assertEquals( |
| 154 | expect=allRoutesStrExpected, actual=allRoutesStrActual, |
| 155 | onpass="***Routes in SDN-IP are correct!***", |
| 156 | onfail="***Routes in SDN-IP are wrong!***" ) |
| 157 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 158 | main.log.report( |
| 159 | "***Routes in SDN-IP after adding routes are correct!***" ) |
| 160 | else: |
| 161 | main.log.report( |
| 162 | "***Routes in SDN-IP after adding routes are wrong!***" ) |
| 163 | |
| 164 | time.sleep( 20 ) |
| 165 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 166 | |
| 167 | main.step( "Check MultiPointToSinglePointIntent intents installed" ) |
| 168 | # routeIntentsExpected are generated when generating routes |
| 169 | # get rpoute intents from ONOS CLI |
| 170 | routeIntentsActual = \ |
| 171 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 172 | getIntentsResult ) |
| 173 | routeIntentsStrExpected = str( sorted( routeIntentsExpected ) ) |
| 174 | routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" ) |
| 175 | main.log.info( "MultiPointToSinglePoint intents expected:" ) |
| 176 | main.log.info( routeIntentsStrExpected ) |
| 177 | main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" ) |
| 178 | main.log.info( routeIntentsStrActual ) |
| 179 | utilities.assertEquals( |
| 180 | expect=True, |
| 181 | actual=eq( routeIntentsStrExpected, routeIntentsStrActual ), |
| 182 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 183 | correct!***", |
| 184 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 185 | wrong!***" ) |
| 186 | |
| 187 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 188 | main.log.report( "***MultiPointToSinglePoint Intents before \ |
| 189 | deleting routes correct!***" ) |
| 190 | else: |
| 191 | main.log.report( "***MultiPointToSinglePoint Intents before \ |
| 192 | deleting routes wrong!***" ) |
| 193 | |
| 194 | main.step( "Check BGP PointToPointIntent intents installed" ) |
| 195 | # bgp intents expected |
| 196 | bgpIntentsExpected = \ |
| 197 | main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH ) |
| 198 | # get BGP intents from ONOS CLI |
| 199 | bgpIntentsActual = \ |
| 200 | main.QuaggaCliHost3.extractActualBgpIntents( getIntentsResult ) |
| 201 | |
| 202 | bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" ) |
| 203 | bgpIntentsStrActual = str( bgpIntentsActual ) |
| 204 | main.log.info( "PointToPointIntent intents expected:" ) |
| 205 | main.log.info( bgpIntentsStrExpected ) |
| 206 | main.log.info( "PointToPointIntent intents get from ONOS CLI:" ) |
| 207 | main.log.info( bgpIntentsStrActual ) |
| 208 | |
| 209 | utilities.assertEquals( |
| 210 | expect=True, |
| 211 | actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ), |
| 212 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 213 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 214 | |
| 215 | if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ): |
| 216 | main.log.report( |
| 217 | "***PointToPointIntent Intents in SDN-IP are correct!***" ) |
| 218 | else: |
| 219 | main.log.report( |
| 220 | "***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 221 | |
| 222 | #============================= Ping Test ======================== |
| 223 | # wait until all MultiPointToSinglePoint |
| 224 | time.sleep( 20 ) |
| 225 | pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh" |
| 226 | pingTestResultsFile = \ |
| 227 | "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-before-delete-routes-" \ |
| 228 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 229 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 230 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 231 | main.log.info( pingTestResults ) |
| 232 | time.sleep( 20 ) |
| 233 | |
| 234 | #============================= Deleting Routes ================== |
| 235 | main.step( "Check deleting routes installed" ) |
| 236 | main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 ) |
| 237 | main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 ) |
| 238 | main.QuaggaCliHost5.deleteRoutes( prefixesHost5, 1 ) |
| 239 | |
| 240 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 241 | allRoutesActual = \ |
| 242 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 243 | main.log.info( "allRoutes_actual = " ) |
| 244 | main.log.info( allRoutesActual ) |
| 245 | |
| 246 | utilities.assertEquals( |
| 247 | expect="[]", actual=str( allRoutesActual ), |
| 248 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 249 | onfail="***Routes number in SDN-IP is not 0, wrong!***" ) |
| 250 | |
| 251 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 252 | main.log.report( "***Routes in SDN-IP after deleting correct!***" ) |
| 253 | else: |
| 254 | main.log.report( "***Routes in SDN-IP after deleting wrong!***" ) |
| 255 | |
| 256 | main.step( "Check intents after deleting routes" ) |
| 257 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 258 | routeIntentsActual = \ |
| 259 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 260 | getIntentsResult ) |
| 261 | main.log.info( "main.ONOScli.intents()= " ) |
| 262 | main.log.info( routeIntentsActual ) |
| 263 | utilities.assertEquals( |
| 264 | expect="[]", actual=str( routeIntentsActual ), |
| 265 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \ |
| 266 | correct!***", |
| 267 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is 0, \ |
| 268 | wrong!***" ) |
| 269 | |
| 270 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 271 | main.log.report( "***MultiPointToSinglePoint Intents after \ |
| 272 | deleting routes correct!***" ) |
| 273 | else: |
| 274 | main.log.report( "***MultiPointToSinglePoint Intents after \ |
| 275 | deleting routes wrong!***" ) |
| 276 | |
| 277 | time.sleep( 20 ) |
| 278 | pingTestScript = "~/SDNIP/test-tools/CASE4-ping-as2host.sh" |
| 279 | pingTestResultsFile = \ |
| 280 | "~/SDNIP/SdnIpIntentDemo/log/CASE4-ping-results-after-delete-routes-" \ |
| 281 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 282 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 283 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 284 | main.log.info( pingTestResults ) |
| 285 | time.sleep( 100 ) |
| 286 | |
| 287 | # main.step( "Test whether Mininet is started" ) |
| 288 | # main.Mininet2.handle.sendline( "xterm host1" ) |
| 289 | # main.Mininet2.handle.expect( "mininet>" ) |
| 290 | |
| 291 | def CASE3( self, main ): |
| 292 | """ |
| 293 | Test the SDN-IP functionality |
| 294 | allRoutesExpected: all expected routes for all BGP peers |
| 295 | routeIntentsExpected: all expected MultiPointToSinglePointIntent intents |
| 296 | bgpIntentsExpected: expected PointToPointIntent intents |
| 297 | allRoutesActual: all routes from ONOS LCI |
| 298 | routeIntentsActual: actual MultiPointToSinglePointIntent intents from \ |
| 299 | ONOS CLI |
| 300 | bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI |
| 301 | """ |
| 302 | import time |
| 303 | import json |
| 304 | from operator import eq |
| 305 | # from datetime import datetime |
| 306 | from time import localtime, strftime |
| 307 | |
| 308 | main.case( "The test case is to help to setup the TestON \ |
| 309 | environment and test new drivers" ) |
| 310 | # SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json" |
| 311 | SDNIPJSONFILEPATH = \ |
| 312 | "/home/admin/workspace/onos/tools/package/config/sdnip.json" |
| 313 | # all expected routes for all BGP peers |
| 314 | allRoutesExpected = [] |
| 315 | main.step( "Start to generate routes for all BGP peers" ) |
| 316 | main.log.info( "Generate prefixes for host3" ) |
| 317 | prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 ) |
| 318 | main.log.info( prefixesHost3 ) |
| 319 | # generate route with next hop |
| 320 | for prefix in prefixesHost3: |
| 321 | allRoutesExpected.append( prefix + "/" + "192.168.20.1" ) |
| 322 | routeIntentsExpectedHost3 = \ |
| 323 | main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents( |
| 324 | prefixesHost3, "192.168.20.1", "00:00:00:00:02:02", |
| 325 | SDNIPJSONFILEPATH ) |
| 326 | |
| 327 | main.log.info( "Generate prefixes for host4" ) |
| 328 | prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 ) |
| 329 | main.log.info( prefixesHost4 ) |
| 330 | # generate route with next hop |
| 331 | for prefix in prefixesHost4: |
| 332 | allRoutesExpected.append( prefix + "/" + "192.168.30.1" ) |
| 333 | routeIntentsExpectedHost4 = \ |
| 334 | main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents( |
| 335 | prefixesHost4, "192.168.30.1", "00:00:00:00:03:01", |
| 336 | SDNIPJSONFILEPATH ) |
| 337 | |
| 338 | routeIntentsExpected = routeIntentsExpectedHost3 + \ |
| 339 | routeIntentsExpectedHost4 |
| 340 | |
| 341 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 342 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 343 | main.step( "Set cell for ONOS-cli environment" ) |
| 344 | main.ONOScli.setCell( cellName ) |
| 345 | verifyResult = main.ONOSbench.verifyCell() |
| 346 | |
| 347 | main.log.report( "Removing raft logs" ) |
| 348 | main.ONOSbench.onosRemoveRaftLogs() |
| 349 | main.log.report( "Uninstalling ONOS" ) |
| 350 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 351 | |
| 352 | main.step( "Installing ONOS package" ) |
| 353 | onos1InstallResult = main.ONOSbench.onosInstall( |
| 354 | options="-f", node=ONOS1Ip ) |
| 355 | |
| 356 | main.step( "Checking if ONOS is up yet" ) |
| 357 | time.sleep( 60 ) |
| 358 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 359 | if not onos1Isup: |
| 360 | main.log.report( "ONOS1 didn't start!" ) |
| 361 | |
| 362 | main.step( "Start ONOS-cli" ) |
| 363 | |
| 364 | main.ONOScli.startOnosCli( ONOS1Ip ) |
| 365 | |
| 366 | main.step( "Get devices in the network" ) |
| 367 | listResult = main.ONOScli.devices( jsonFormat=False ) |
| 368 | main.log.info( listResult ) |
| 369 | time.sleep( 10 ) |
| 370 | main.log.info( "Installing sdn-ip feature" ) |
| 371 | main.ONOScli.featureInstall( "onos-app-sdnip" ) |
| 372 | time.sleep( 10 ) |
| 373 | main.step( "Login all BGP peers and add routes into peers" ) |
| 374 | |
| 375 | main.log.info( "Login Quagga CLI on host3" ) |
| 376 | main.QuaggaCliHost3.loginQuagga( "1.168.30.2" ) |
| 377 | main.log.info( "Enter configuration model of Quagga CLI on host3" ) |
| 378 | main.QuaggaCliHost3.enterConfig( 64514 ) |
| 379 | main.log.info( "Add routes to Quagga on host3" ) |
| 380 | main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 ) |
| 381 | |
| 382 | main.log.info( "Login Quagga CLI on host4" ) |
| 383 | main.QuaggaCliHost4.loginQuagga( "1.168.30.3" ) |
| 384 | main.log.info( "Enter configuration model of Quagga CLI on host4" ) |
| 385 | main.QuaggaCliHost4.enterConfig( 64516 ) |
| 386 | main.log.info( "Add routes to Quagga on host4" ) |
| 387 | main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 ) |
| 388 | |
| 389 | for i in range( 101, 201 ): |
| 390 | prefixesHostX = \ |
| 391 | main.QuaggaCliHost.generatePrefixes( str( i ), 10 ) |
| 392 | main.log.info( prefixesHostX ) |
| 393 | for prefix in prefixesHostX: |
| 394 | allRoutesExpected.append( |
| 395 | prefix + "/" + "192.168.40." + str( i - 100 ) ) |
| 396 | |
| 397 | routeIntentsExpectedHostX = \ |
| 398 | main.QuaggaCliHost.generateExpectedOnePeerRouteIntents( |
| 399 | prefixesHostX, "192.168.40." + str( i - 100 ), |
| 400 | "00:00:%02d:00:00:90" % ( i - 101 ), SDNIPJSONFILEPATH ) |
| 401 | routeIntentsExpected = routeIntentsExpected + \ |
| 402 | routeIntentsExpectedHostX |
| 403 | |
| 404 | main.log.info( "Login Quagga CLI on host" + str( i ) ) |
| 405 | QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) ) |
| 406 | QuaggaCliHostX.loginQuagga( "1.168.30." + str( i ) ) |
| 407 | main.log.info( |
| 408 | "Enter configuration model of Quagga CLI on host" + str( i ) ) |
| 409 | QuaggaCliHostX.enterConfig( 65000 + i - 100 ) |
| 410 | main.log.info( "Add routes to Quagga on host" + str( i ) ) |
| 411 | QuaggaCliHostX.addRoutes( prefixesHostX, 1 ) |
| 412 | |
| 413 | time.sleep( 60 ) |
| 414 | |
| 415 | # get routes inside SDN-IP |
| 416 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 417 | |
| 418 | # parse routes from ONOS CLI |
| 419 | allRoutesActual = \ |
| 420 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 421 | |
| 422 | allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 423 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 424 | main.step( "Check routes installed" ) |
| 425 | main.log.info( "Routes expected:" ) |
| 426 | main.log.info( allRoutesStrExpected ) |
| 427 | main.log.info( "Routes get from ONOS CLI:" ) |
| 428 | main.log.info( allRoutesStrActual ) |
| 429 | utilities.assertEquals( |
| 430 | expect=allRoutesStrExpected, actual=allRoutesStrActual, |
| 431 | onpass="***Routes in SDN-IP are correct!***", |
| 432 | onfail="***Routes in SDN-IP are wrong!***" ) |
| 433 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 434 | main.log.report( |
| 435 | "***Routes in SDN-IP after adding routes are correct!***" ) |
| 436 | else: |
| 437 | main.log.report( |
| 438 | "***Routes in SDN-IP after adding routes are wrong!***" ) |
| 439 | |
| 440 | time.sleep( 20 ) |
| 441 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 442 | |
| 443 | main.step( "Check MultiPointToSinglePointIntent intents installed" ) |
| 444 | # routeIntentsExpected are generated when generating routes |
| 445 | # get rpoute intents from ONOS CLI |
| 446 | routeIntentsActual = \ |
| 447 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 448 | getIntentsResult ) |
| 449 | routeIntentsStrExpected = str( sorted( routeIntentsExpected ) ) |
| 450 | routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" ) |
| 451 | main.log.info( "MultiPointToSinglePoint intents expected:" ) |
| 452 | main.log.info( routeIntentsStrExpected ) |
| 453 | main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" ) |
| 454 | main.log.info( routeIntentsStrActual ) |
| 455 | utilities.assertEquals( |
| 456 | expect=True, |
| 457 | actual=eq( routeIntentsStrExpected, routeIntentsStrActual ), |
| 458 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 459 | correct!***", |
| 460 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 461 | wrong!***" ) |
| 462 | |
| 463 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 464 | main.log.report( |
| 465 | "***MultiPointToSinglePoint Intents before deleting routes \ |
| 466 | correct!***" ) |
| 467 | else: |
| 468 | main.log.report( |
| 469 | "***MultiPointToSinglePoint Intents before deleting routes \ |
| 470 | wrong!***" ) |
| 471 | |
| 472 | main.step( "Check BGP PointToPointIntent intents installed" ) |
| 473 | # bgp intents expected |
| 474 | bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents( |
| 475 | SDNIPJSONFILEPATH ) |
| 476 | # get BGP intents from ONOS CLI |
| 477 | bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents( |
| 478 | getIntentsResult ) |
| 479 | |
| 480 | bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" ) |
| 481 | bgpIntentsStrActual = str( bgpIntentsActual ) |
| 482 | main.log.info( "PointToPointIntent intents expected:" ) |
| 483 | main.log.info( bgpIntentsStrExpected ) |
| 484 | main.log.info( "PointToPointIntent intents get from ONOS CLI:" ) |
| 485 | main.log.info( bgpIntentsStrActual ) |
| 486 | |
| 487 | utilities.assertEquals( |
| 488 | expect=True, |
| 489 | actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ), |
| 490 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 491 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 492 | |
| 493 | if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ): |
| 494 | main.log.report( |
| 495 | "***PointToPointIntent Intents in SDN-IP are correct!***" ) |
| 496 | else: |
| 497 | main.log.report( |
| 498 | "***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 499 | |
| 500 | #============================= Ping Test ======================== |
| 501 | # wait until all MultiPointToSinglePoint |
| 502 | time.sleep( 20 ) |
| 503 | pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh" |
| 504 | pingTestResultsFile = \ |
| 505 | "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-before-delete-routes-" \ |
| 506 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 507 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 508 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 509 | main.log.info( pingTestResults ) |
| 510 | time.sleep( 20 ) |
| 511 | |
| 512 | #============================= Deleting Routes ================== |
| 513 | main.step( "Check deleting routes installed" ) |
| 514 | main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 ) |
| 515 | main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 ) |
| 516 | for i in range( 101, 201 ): |
| 517 | prefixesHostX = \ |
| 518 | main.QuaggaCliHost.generatePrefixes( str( i ), 10 ) |
| 519 | main.log.info( prefixesHostX ) |
| 520 | QuaggaCliHostX = getattr( main, ( 'QuaggaCliHost' + str( i ) ) ) |
| 521 | QuaggaCliHostX.deleteRoutes( prefixesHostX, 1 ) |
| 522 | |
| 523 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 524 | allRoutesActual = main.QuaggaCliHost3.extractActualRoutes( |
| 525 | getRoutesResult ) |
| 526 | main.log.info( "allRoutes_actual = " ) |
| 527 | main.log.info( allRoutesActual ) |
| 528 | |
| 529 | utilities.assertEquals( |
| 530 | expect="[]", actual=str( allRoutesActual ), |
| 531 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 532 | onfail="***Routes number in SDN-IP is not 0, wrong!***" ) |
| 533 | |
| 534 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 535 | main.log.report( |
| 536 | "***Routes in SDN-IP after deleting correct!***" ) |
| 537 | else: |
| 538 | main.log.report( |
| 539 | "***Routes in SDN-IP after deleting wrong!***" ) |
| 540 | |
| 541 | main.step( "Check intents after deleting routes" ) |
| 542 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 543 | routeIntentsActual = \ |
| 544 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 545 | getIntentsResult ) |
| 546 | main.log.info( "main.ONOScli.intents()= " ) |
| 547 | main.log.info( routeIntentsActual ) |
| 548 | utilities.assertEquals( |
| 549 | expect="[]", actual=str( routeIntentsActual ), |
| 550 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \ |
| 551 | 0, correct!***", |
| 552 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \ |
| 553 | 0, wrong!***" ) |
| 554 | |
| 555 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 556 | main.log.report( |
| 557 | "***MultiPointToSinglePoint Intents after deleting routes \ |
| 558 | correct!***" ) |
| 559 | else: |
| 560 | main.log.report( |
| 561 | "***MultiPointToSinglePoint Intents after deleting routes \ |
| 562 | wrong!***" ) |
| 563 | |
| 564 | time.sleep( 20 ) |
| 565 | pingTestScript = "~/SDNIP/test-tools/CASE3-ping-as2host.sh" |
| 566 | pingTestResultsFile = \ |
| 567 | "~/SDNIP/SdnIpIntentDemo/log/CASE3-ping-results-after-delete-routes-" \ |
| 568 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 569 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 570 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 571 | main.log.info( pingTestResults ) |
| 572 | time.sleep( 100 ) |
| 573 | |
| 574 | # main.step( "Test whether Mininet is started" ) |
| 575 | # main.Mininet2.handle.sendline( "xterm host1" ) |
| 576 | # main.Mininet2.handle.expect( "mininet>" ) |
| 577 | |
| 578 | def CASE1( self, main ): |
| 579 | """ |
| 580 | Test the SDN-IP functionality |
| 581 | allRoutesExpected: all expected routes for all BGP peers |
| 582 | routeIntentsExpected: all expected MultiPointToSinglePointIntent \ |
| 583 | intents |
| 584 | bgpIntentsExpected: expected PointToPointIntent intents |
| 585 | allRoutesActual: all routes from ONOS LCI |
| 586 | routeIntentsActual: actual MultiPointToSinglePointIntent intents \ |
| 587 | from ONOS CLI |
| 588 | bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI |
| 589 | """ |
| 590 | import time |
| 591 | import json |
| 592 | from operator import eq |
| 593 | # from datetime import datetime |
| 594 | from time import localtime, strftime |
| 595 | |
| 596 | main.case("The test case is to help to setup the TestON environment \ |
| 597 | and test new drivers" ) |
| 598 | SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json" |
| 599 | # all expected routes for all BGP peers |
| 600 | allRoutesExpected = [] |
| 601 | main.step( "Start to generate routes for all BGP peers" ) |
| 602 | # bgpPeerHosts = [] |
| 603 | # for i in range( 3, 5 ): |
| 604 | # bgpPeerHosts.append( "host" + str( i ) ) |
| 605 | # main.log.info( "BGP Peer Hosts are:" + bgpPeerHosts ) |
| 606 | |
| 607 | # for i in range( 3, 5 ): |
| 608 | # QuaggaCliHost = "QuaggaCliHost" + str( i ) |
| 609 | # prefixes = main.QuaggaCliHost.generatePrefixes( 3, 10 ) |
| 610 | |
| 611 | # main.log.info( prefixes ) |
| 612 | # allRoutesExpected.append( prefixes ) |
| 613 | main.log.info( "Generate prefixes for host3" ) |
| 614 | prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 ) |
| 615 | main.log.info( prefixesHost3 ) |
| 616 | # generate route with next hop |
| 617 | for prefix in prefixesHost3: |
| 618 | allRoutesExpected.append( prefix + "/" + "192.168.20.1" ) |
| 619 | routeIntentsExpectedHost3 = \ |
| 620 | main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents( |
| 621 | prefixesHost3, "192.168.20.1", "00:00:00:00:02:02", |
| 622 | SDNIPJSONFILEPATH ) |
| 623 | |
| 624 | main.log.info( "Generate prefixes for host4" ) |
| 625 | prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 ) |
| 626 | main.log.info( prefixesHost4 ) |
| 627 | # generate route with next hop |
| 628 | for prefix in prefixesHost4: |
| 629 | allRoutesExpected.append( prefix + "/" + "192.168.30.1" ) |
| 630 | routeIntentsExpectedHost4 = \ |
| 631 | main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents( |
| 632 | prefixesHost4, "192.168.30.1", "00:00:00:00:03:01", |
| 633 | SDNIPJSONFILEPATH ) |
| 634 | |
| 635 | routeIntentsExpected = routeIntentsExpectedHost3 + \ |
| 636 | routeIntentsExpectedHost4 |
| 637 | |
| 638 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 639 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 640 | main.step( "Set cell for ONOS-cli environment" ) |
| 641 | main.ONOScli.setCell( cellName ) |
| 642 | verifyResult = main.ONOSbench.verifyCell() |
| 643 | main.log.report( "Removing raft logs" ) |
| 644 | main.ONOSbench.onosRemoveRaftLogs() |
| 645 | main.log.report( "Uninstalling ONOS" ) |
| 646 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 647 | main.step( "Creating ONOS package" ) |
| 648 | packageResult = main.ONOSbench.onosPackage() |
| 649 | |
| 650 | main.step( "Starting ONOS service" ) |
| 651 | # TODO: start ONOS from Mininet Script |
| 652 | # startResult = main.ONOSbench.onosStart( "127.0.0.1" ) |
| 653 | main.step( "Installing ONOS package" ) |
| 654 | onos1InstallResult = main.ONOSbench.onosInstall( |
| 655 | options="-f", node=ONOS1Ip ) |
| 656 | |
| 657 | main.step( "Checking if ONOS is up yet" ) |
| 658 | time.sleep( 60 ) |
| 659 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 660 | if not onos1Isup: |
| 661 | main.log.report( "ONOS1 didn't start!" ) |
| 662 | |
| 663 | main.step( "Start ONOS-cli" ) |
| 664 | # TODO: change the hardcode in startOnosCli method in ONOS CLI driver |
| 665 | |
| 666 | main.ONOScli.startOnosCli( ONOS1Ip ) |
| 667 | |
| 668 | main.step( "Get devices in the network" ) |
| 669 | listResult = main.ONOScli.devices( jsonFormat=False ) |
| 670 | main.log.info( listResult ) |
| 671 | time.sleep( 10 ) |
| 672 | main.log.info( "Installing sdn-ip feature" ) |
| 673 | main.ONOScli.featureInstall( "onos-app-sdnip" ) |
| 674 | time.sleep( 10 ) |
| 675 | main.step( "Login all BGP peers and add routes into peers" ) |
| 676 | main.log.info( "Login Quagga CLI on host3" ) |
| 677 | main.QuaggaCliHost3.loginQuagga( "1.168.30.2" ) |
| 678 | main.log.info( "Enter configuration model of Quagga CLI on host3" ) |
| 679 | main.QuaggaCliHost3.enterConfig( 64514 ) |
| 680 | main.log.info( "Add routes to Quagga on host3" ) |
| 681 | main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 ) |
| 682 | |
| 683 | main.log.info( "Login Quagga CLI on host4" ) |
| 684 | main.QuaggaCliHost4.loginQuagga( "1.168.30.3" ) |
| 685 | main.log.info( "Enter configuration model of Quagga CLI on host4" ) |
| 686 | main.QuaggaCliHost4.enterConfig( 64516 ) |
| 687 | main.log.info( "Add routes to Quagga on host4" ) |
| 688 | main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 ) |
| 689 | time.sleep( 60 ) |
| 690 | |
| 691 | # get all routes inside SDN-IP |
| 692 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 693 | |
| 694 | # parse routes from ONOS CLI |
| 695 | allRoutesActual = \ |
| 696 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 697 | |
| 698 | allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 699 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 700 | main.step( "Check routes installed" ) |
| 701 | main.log.info( "Routes expected:" ) |
| 702 | main.log.info( allRoutesStrExpected ) |
| 703 | main.log.info( "Routes get from ONOS CLI:" ) |
| 704 | main.log.info( allRoutesStrActual ) |
| 705 | utilities.assertEquals( |
| 706 | expect=allRoutesStrExpected, actual=allRoutesStrActual, |
| 707 | onpass="***Routes in SDN-IP are correct!***", |
| 708 | onfail="***Routes in SDN-IP are wrong!***" ) |
| 709 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 710 | main.log.report( |
| 711 | "***Routes in SDN-IP after adding routes are correct!***" ) |
| 712 | else: |
| 713 | main.log.report( |
| 714 | "***Routes in SDN-IP after adding routes are wrong!***" ) |
| 715 | |
| 716 | time.sleep( 20 ) |
| 717 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 718 | |
| 719 | main.step( "Check MultiPointToSinglePointIntent intents installed" ) |
| 720 | # routeIntentsExpected are generated when generating routes |
| 721 | # get rpoute intents from ONOS CLI |
| 722 | routeIntentsActual = \ |
| 723 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 724 | getIntentsResult ) |
| 725 | routeIntentsStrExpected = str( sorted( routeIntentsExpected ) ) |
| 726 | routeIntentsStrActual = str( routeIntentsActual ).replace( 'u', "" ) |
| 727 | main.log.info( "MultiPointToSinglePoint intents expected:" ) |
| 728 | main.log.info( routeIntentsStrExpected ) |
| 729 | main.log.info( "MultiPointToSinglePoint intents get from ONOS CLI:" ) |
| 730 | main.log.info( routeIntentsStrActual ) |
| 731 | utilities.assertEquals( |
| 732 | expect=True, |
| 733 | actual=eq( routeIntentsStrExpected, routeIntentsStrActual ), |
| 734 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 735 | correct!***", |
| 736 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 737 | wrong!***" ) |
| 738 | |
| 739 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 740 | main.log.report( |
| 741 | "***MultiPointToSinglePoint Intents before deleting routes \ |
| 742 | correct!***" ) |
| 743 | else: |
| 744 | main.log.report( |
| 745 | "***MultiPointToSinglePoint Intents before deleting routes \ |
| 746 | wrong!***" ) |
| 747 | |
| 748 | main.step( "Check BGP PointToPointIntent intents installed" ) |
| 749 | # bgp intents expected |
| 750 | bgpIntentsExpected = \ |
| 751 | main.QuaggaCliHost3.generateExpectedBgpIntents( SDNIPJSONFILEPATH ) |
| 752 | # get BGP intents from ONOS CLI |
| 753 | bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents( |
| 754 | getIntentsResult ) |
| 755 | |
| 756 | bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" ) |
| 757 | bgpIntentsStrActual = str( bgpIntentsActual ) |
| 758 | main.log.info( "PointToPointIntent intents expected:" ) |
| 759 | main.log.info( bgpIntentsStrExpected ) |
| 760 | main.log.info( "PointToPointIntent intents get from ONOS CLI:" ) |
| 761 | main.log.info( bgpIntentsStrActual ) |
| 762 | |
| 763 | utilities.assertEquals( |
| 764 | expect=True, |
| 765 | actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ), |
| 766 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 767 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 768 | |
| 769 | if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ): |
| 770 | main.log.report( |
| 771 | "***PointToPointIntent Intents in SDN-IP are correct!***" ) |
| 772 | else: |
| 773 | main.log.report( |
| 774 | "***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 775 | |
| 776 | #============================= Ping Test ======================== |
| 777 | # wait until all MultiPointToSinglePoint |
| 778 | time.sleep( 20 ) |
| 779 | pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 780 | pingTestResultsFile = \ |
| 781 | "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-before-delete-routes-" \ |
| 782 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 783 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 784 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 785 | main.log.info( pingTestResults ) |
| 786 | |
| 787 | # ping test |
| 788 | |
| 789 | #============================= Deleting Routes ================== |
| 790 | main.step( "Check deleting routes installed" ) |
| 791 | main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 ) |
| 792 | main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 ) |
| 793 | |
| 794 | # main.log.info( "main.ONOScli.get_routes_num() = " ) |
| 795 | # main.log.info( main.ONOScli.getRoutesNum() ) |
| 796 | # utilities.assertEquals( expect="Total SDN-IP routes = 1", actual= |
| 797 | # main.ONOScli.getRoutesNum(), |
| 798 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 799 | allRoutesActual = \ |
| 800 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 801 | main.log.info( "allRoutes_actual = " ) |
| 802 | main.log.info( allRoutesActual ) |
| 803 | |
| 804 | utilities.assertEquals( |
| 805 | expect="[]", actual=str( allRoutesActual ), |
| 806 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 807 | onfail="***Routes number in SDN-IP is not 0, wrong!***" ) |
| 808 | |
| 809 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 810 | main.log.report( |
| 811 | "***Routes in SDN-IP after deleting correct!***" ) |
| 812 | else: |
| 813 | main.log.report( |
| 814 | "***Routes in SDN-IP after deleting wrong!***" ) |
| 815 | |
| 816 | main.step( "Check intents after deleting routes" ) |
| 817 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 818 | routeIntentsActual = \ |
| 819 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 820 | getIntentsResult ) |
| 821 | main.log.info( "main.ONOScli.intents()= " ) |
| 822 | main.log.info( routeIntentsActual ) |
| 823 | utilities.assertEquals( |
| 824 | expect="[]", actual=str( routeIntentsActual ), |
| 825 | onpass="***MultiPointToSinglePoint Intents number in SDN-IP is \ |
| 826 | 0, correct!***", |
| 827 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP is \ |
| 828 | 0, wrong!***" ) |
| 829 | |
| 830 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 831 | main.log.report( |
| 832 | "***MultiPointToSinglePoint Intents after deleting routes \ |
| 833 | correct!***" ) |
| 834 | else: |
| 835 | main.log.report( |
| 836 | "***MultiPointToSinglePoint Intents after deleting routes \ |
| 837 | wrong!***" ) |
| 838 | |
| 839 | time.sleep( 20 ) |
| 840 | pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 841 | pingTestResultsFile = \ |
| 842 | "~/SDNIP/SdnIpIntentDemo/log/CASE1-ping-results-after-delete-routes-" \ |
| 843 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 844 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 845 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 846 | main.log.info( pingTestResults ) |
| 847 | time.sleep( 30 ) |
| 848 | |
| 849 | # main.step( "Test whether Mininet is started" ) |
| 850 | # main.Mininet2.handle.sendline( "xterm host1" ) |
| 851 | # main.Mininet2.handle.expect( "mininet>" ) |
| 852 | |
| 853 | def CASE2( self, main ): |
| 854 | """ |
| 855 | Test the SDN-IP functionality |
| 856 | allRoutesExpected: all expected routes for all BGP peers |
| 857 | routeIntentsExpected: all expected MultiPointToSinglePointIntent \ |
| 858 | intents |
| 859 | bgpIntentsExpected: expected PointToPointIntent intents |
| 860 | allRoutesActual: all routes from ONOS LCI |
| 861 | routeIntentsActual: actual MultiPointToSinglePointIntent intents \ |
| 862 | from ONOS CLI |
| 863 | bgpIntentsActual: actual PointToPointIntent intents from ONOS CLI |
| 864 | """ |
| 865 | import time |
| 866 | import json |
| 867 | from operator import eq |
| 868 | from time import localtime, strftime |
| 869 | |
| 870 | main.case( |
| 871 | "The test case is to help to setup the TestON environment and \ |
| 872 | test new drivers" ) |
| 873 | SDNIPJSONFILEPATH = "../tests/SdnIpTest/sdnip.json" |
| 874 | # all expected routes for all BGP peers |
| 875 | allRoutesExpected = [] |
| 876 | main.step( "Start to generate routes for all BGP peers" ) |
| 877 | |
| 878 | main.log.info( "Generate prefixes for host3" ) |
| 879 | prefixesHost3 = main.QuaggaCliHost3.generatePrefixes( 3, 10 ) |
| 880 | main.log.info( prefixesHost3 ) |
| 881 | # generate route with next hop |
| 882 | for prefix in prefixesHost3: |
| 883 | allRoutesExpected.append( prefix + "/" + "192.168.20.1" ) |
| 884 | routeIntentsExpectedHost3 = \ |
| 885 | main.QuaggaCliHost3.generateExpectedOnePeerRouteIntents( |
| 886 | prefixesHost3, "192.168.20.1", "00:00:00:00:02:02", |
| 887 | SDNIPJSONFILEPATH ) |
| 888 | |
| 889 | main.log.info( "Generate prefixes for host4" ) |
| 890 | prefixesHost4 = main.QuaggaCliHost4.generatePrefixes( 4, 10 ) |
| 891 | main.log.info( prefixesHost4 ) |
| 892 | # generate route with next hop |
| 893 | for prefix in prefixesHost4: |
| 894 | allRoutesExpected.append( prefix + "/" + "192.168.30.1" ) |
| 895 | routeIntentsExpectedHost4 = \ |
| 896 | main.QuaggaCliHost4.generateExpectedOnePeerRouteIntents( |
| 897 | prefixesHost4, "192.168.30.1", "00:00:00:00:03:01", |
| 898 | SDNIPJSONFILEPATH ) |
| 899 | |
| 900 | routeIntentsExpected = routeIntentsExpectedHost3 + \ |
| 901 | routeIntentsExpectedHost4 |
| 902 | |
| 903 | main.log.report( "Removing raft logs" ) |
| 904 | main.ONOSbench.onosRemoveRaftLogs() |
| 905 | main.log.report( "Uninstalling ONOS" ) |
| 906 | main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 907 | |
| 908 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 909 | ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 910 | main.step( "Set cell for ONOS-cli environment" ) |
| 911 | main.ONOScli.setCell( cellName ) |
| 912 | verifyResult = main.ONOSbench.verifyCell() |
| 913 | # main.log.report( "Removing raft logs" ) |
| 914 | # main.ONOSbench.onosRemoveRaftLogs() |
| 915 | # main.log.report( "Uninstalling ONOS" ) |
| 916 | # main.ONOSbench.onosUninstall( ONOS1Ip ) |
| 917 | main.step( "Creating ONOS package" ) |
| 918 | # packageResult = main.ONOSbench.onosPackage() |
| 919 | |
| 920 | main.step( "Installing ONOS package" ) |
| 921 | # onos1InstallResult = main.ONOSbench.onosInstall( options="-f", |
| 922 | # node=ONOS1Ip ) |
| 923 | |
| 924 | main.step( "Checking if ONOS is up yet" ) |
| 925 | # time.sleep( 60 ) |
| 926 | onos1Isup = main.ONOSbench.isup( ONOS1Ip ) |
| 927 | if not onos1Isup: |
| 928 | main.log.report( "ONOS1 didn't start!" ) |
| 929 | |
| 930 | main.step( "Start ONOS-cli" ) |
| 931 | main.ONOScli.startOnosCli( ONOS1Ip ) |
| 932 | |
| 933 | main.step( "Get devices in the network" ) |
| 934 | listResult = main.ONOScli.devices( jsonFormat=False ) |
| 935 | main.log.info( listResult ) |
| 936 | time.sleep( 10 ) |
| 937 | main.log.info( "Installing sdn-ip feature" ) |
| 938 | main.ONOScli.featureInstall( "onos-app-sdnip" ) |
| 939 | time.sleep( 10 ) |
| 940 | |
| 941 | main.step( "Check BGP PointToPointIntent intents installed" ) |
| 942 | # bgp intents expected |
| 943 | bgpIntentsExpected = main.QuaggaCliHost3.generateExpectedBgpIntents( |
| 944 | SDNIPJSONFILEPATH ) |
| 945 | # get BGP intents from ONOS CLI |
| 946 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 947 | bgpIntentsActual = main.QuaggaCliHost3.extractActualBgpIntents( |
| 948 | getIntentsResult ) |
| 949 | |
| 950 | bgpIntentsStrExpected = str( bgpIntentsExpected ).replace( 'u', "" ) |
| 951 | bgpIntentsStrActual = str( bgpIntentsActual ) |
| 952 | main.log.info( "PointToPointIntent intents expected:" ) |
| 953 | main.log.info( bgpIntentsStrExpected ) |
| 954 | main.log.info( "PointToPointIntent intents get from ONOS CLI:" ) |
| 955 | main.log.info( bgpIntentsStrActual ) |
| 956 | |
| 957 | utilities.assertEquals( |
| 958 | expect=True, |
| 959 | actual=eq( bgpIntentsStrExpected, bgpIntentsStrActual ), |
| 960 | onpass="***PointToPointIntent Intents in SDN-IP are correct!***", |
| 961 | onfail="***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 962 | |
| 963 | if ( eq( bgpIntentsStrExpected, bgpIntentsStrActual ) ): |
| 964 | main.log.report( |
| 965 | "***PointToPointIntent Intents in SDN-IP are correct!***" ) |
| 966 | else: |
| 967 | main.log.report( |
| 968 | "***PointToPointIntent Intents in SDN-IP are wrong!***" ) |
| 969 | |
| 970 | allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 971 | routeIntentsStrExpected = str( sorted( routeIntentsExpected ) ) |
| 972 | pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 973 | # roundNum = 0; |
| 974 | # while( True ): |
| 975 | for roundNum in range( 1, 6 ): |
| 976 | # round = round + 1; |
| 977 | main.log.report( "The Round " + str( roundNum ) + |
| 978 | " test starts................................" ) |
| 979 | |
| 980 | main.step( "Login all BGP peers and add routes into peers" ) |
| 981 | main.log.info( "Login Quagga CLI on host3" ) |
| 982 | main.QuaggaCliHost3.loginQuagga( "1.168.30.2" ) |
| 983 | main.log.info( |
| 984 | "Enter configuration model of Quagga CLI on host3" ) |
| 985 | main.QuaggaCliHost3.enterConfig( 64514 ) |
| 986 | main.log.info( "Add routes to Quagga on host3" ) |
| 987 | main.QuaggaCliHost3.addRoutes( prefixesHost3, 1 ) |
| 988 | |
| 989 | main.log.info( "Login Quagga CLI on host4" ) |
| 990 | main.QuaggaCliHost4.loginQuagga( "1.168.30.3" ) |
| 991 | main.log.info( |
| 992 | "Enter configuration model of Quagga CLI on host4" ) |
| 993 | main.QuaggaCliHost4.enterConfig( 64516 ) |
| 994 | main.log.info( "Add routes to Quagga on host4" ) |
| 995 | main.QuaggaCliHost4.addRoutes( prefixesHost4, 1 ) |
| 996 | time.sleep( 60 ) |
| 997 | |
| 998 | # get all routes inside SDN-IP |
| 999 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 1000 | |
| 1001 | # parse routes from ONOS CLI |
| 1002 | allRoutesActual = \ |
| 1003 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 1004 | |
| 1005 | # allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 1006 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 1007 | main.step( "Check routes installed" ) |
| 1008 | main.log.info( "Routes expected:" ) |
| 1009 | main.log.info( allRoutesStrExpected ) |
| 1010 | main.log.info( "Routes get from ONOS CLI:" ) |
| 1011 | main.log.info( allRoutesStrActual ) |
| 1012 | utilities.assertEquals( |
| 1013 | expect=allRoutesStrExpected, actual=allRoutesStrActual, |
| 1014 | onpass="***Routes in SDN-IP are correct!***", |
| 1015 | onfail="***Routes in SDN-IP are wrong!***" ) |
| 1016 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 1017 | main.log.report( |
| 1018 | "***Routes in SDN-IP after adding correct!***" ) |
| 1019 | else: |
| 1020 | main.log.report( |
| 1021 | "***Routes in SDN-IP after adding wrong!***" ) |
| 1022 | |
| 1023 | time.sleep( 20 ) |
| 1024 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 1025 | |
| 1026 | main.step( |
| 1027 | "Check MultiPointToSinglePointIntent intents installed" ) |
| 1028 | # routeIntentsExpected are generated when generating routes |
| 1029 | # get route intents from ONOS CLI |
| 1030 | routeIntentsActual = \ |
| 1031 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 1032 | getIntentsResult ) |
| 1033 | # routeIntentsStrExpected = str( sorted( routeIntentsExpected ) ) |
| 1034 | routeIntentsStrActual = str( |
| 1035 | routeIntentsActual ).replace( 'u', "" ) |
| 1036 | main.log.info( "MultiPointToSinglePoint intents expected:" ) |
| 1037 | main.log.info( routeIntentsStrExpected ) |
| 1038 | main.log.info( |
| 1039 | "MultiPointToSinglePoint intents get from ONOS CLI:" ) |
| 1040 | main.log.info( routeIntentsStrActual ) |
| 1041 | utilities.assertEquals( |
| 1042 | expect=True, |
| 1043 | actual=eq( routeIntentsStrExpected, routeIntentsStrActual ), |
| 1044 | onpass="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 1045 | correct!***", |
| 1046 | onfail="***MultiPointToSinglePoint Intents in SDN-IP are \ |
| 1047 | wrong!***" ) |
| 1048 | |
| 1049 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 1050 | main.log.report( |
| 1051 | "***MultiPointToSinglePoint Intents after adding routes \ |
| 1052 | correct!***" ) |
| 1053 | else: |
| 1054 | main.log.report( |
| 1055 | "***MultiPointToSinglePoint Intents after adding routes \ |
| 1056 | wrong!***" ) |
| 1057 | |
| 1058 | #============================= Ping Test ======================== |
| 1059 | # wait until all MultiPointToSinglePoint |
| 1060 | time.sleep( 20 ) |
| 1061 | # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 1062 | pingTestResultsFile = \ |
| 1063 | "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \ |
| 1064 | + str( roundNum ) + "-ping-results-before-delete-routes-" \ |
| 1065 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 1066 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 1067 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 1068 | main.log.info( pingTestResults ) |
| 1069 | # ping test |
| 1070 | |
| 1071 | #============================= Deleting Routes ================== |
| 1072 | main.step( "Check deleting routes installed" ) |
| 1073 | main.log.info( "Delete routes to Quagga on host3" ) |
| 1074 | main.QuaggaCliHost3.deleteRoutes( prefixesHost3, 1 ) |
| 1075 | main.log.info( "Delete routes to Quagga on host4" ) |
| 1076 | main.QuaggaCliHost4.deleteRoutes( prefixesHost4, 1 ) |
| 1077 | |
| 1078 | getRoutesResult = main.ONOScli.routes( jsonFormat=True ) |
| 1079 | allRoutesActual = \ |
| 1080 | main.QuaggaCliHost3.extractActualRoutes( getRoutesResult ) |
| 1081 | main.log.info( "allRoutes_actual = " ) |
| 1082 | main.log.info( allRoutesActual ) |
| 1083 | |
| 1084 | utilities.assertEquals( |
| 1085 | expect="[]", actual=str( allRoutesActual ), |
| 1086 | onpass="***Route number in SDN-IP is 0, correct!***", |
| 1087 | onfail="***Routes number in SDN-IP is not 0, wrong!***" ) |
| 1088 | |
| 1089 | if( eq( allRoutesStrExpected, allRoutesStrActual ) ): |
| 1090 | main.log.report( |
| 1091 | "***Routes in SDN-IP after deleting correct!***" ) |
| 1092 | else: |
| 1093 | main.log.report( |
| 1094 | "***Routes in SDN-IP after deleting wrong!***" ) |
| 1095 | |
| 1096 | main.step( "Check intents after deleting routes" ) |
| 1097 | getIntentsResult = main.ONOScli.intents( jsonFormat=True ) |
| 1098 | routeIntentsActual = \ |
| 1099 | main.QuaggaCliHost3.extractActualRouteIntents( |
| 1100 | getIntentsResult ) |
| 1101 | main.log.info( "main.ONOScli.intents()= " ) |
| 1102 | main.log.info( routeIntentsActual ) |
| 1103 | utilities.assertEquals( |
| 1104 | expect="[]", actual=str( routeIntentsActual ), |
| 1105 | onpass= |
| 1106 | "***MultiPointToSinglePoint Intents number in SDN-IP \ |
| 1107 | is 0, correct!***", |
| 1108 | onfail="***MultiPointToSinglePoint Intents number in SDN-IP \ |
| 1109 | is 0, wrong!***" ) |
| 1110 | |
| 1111 | if( eq( routeIntentsStrExpected, routeIntentsStrActual ) ): |
| 1112 | main.log.report( |
| 1113 | "***MultiPointToSinglePoint Intents after deleting \ |
| 1114 | routes correct!***" ) |
| 1115 | else: |
| 1116 | main.log.report( |
| 1117 | "***MultiPointToSinglePoint Intents after deleting \ |
| 1118 | routes wrong!***" ) |
| 1119 | |
| 1120 | time.sleep( 20 ) |
| 1121 | # pingTestScript = "~/SDNIP/SdnIpIntentDemo/CASE1-ping-as2host.sh" |
| 1122 | pingTestResultsFile = \ |
| 1123 | "~/SDNIP/SdnIpIntentDemo/log/CASE2-Round" \ |
| 1124 | + str( roundNum ) + "-ping-results-after-delete-routes-" \ |
| 1125 | + strftime( "%Y-%m-%d_%H:%M:%S", localtime() ) + ".txt" |
| 1126 | pingTestResults = main.QuaggaCliHost.pingTest( |
| 1127 | "1.168.30.100", pingTestScript, pingTestResultsFile ) |
| 1128 | main.log.info( pingTestResults ) |
| 1129 | time.sleep( 30 ) |
| 1130 | |