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