Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1 | class SdnBase: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 2 | |
| 3 | def __init__( self ): |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 4 | self.default = '' |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 5 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 6 | def initSetup( self ): |
| 7 | import json |
| 8 | import time |
| 9 | import os |
| 10 | from operator import eq |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 11 | try: |
| 12 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 13 | main.testSetUp = ONOSSetup() |
| 14 | except Exception: |
| 15 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 16 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 17 | main.testSetUp.envSetupDescription() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 18 | main.testSetUp.envSetup() |
| 19 | main.apps = main.params[ 'ENV' ][ 'appString' ] |
| 20 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 21 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 22 | main.step( "Copying config files" ) |
| 23 | src = os.path.dirname( main.testFile ) + "/network-cfg.json" |
| 24 | dst = main.ONOSbench.home + "/tools/package/config/network-cfg.json" |
| 25 | status = main.ONOSbench.scp( main.ONOSbench, src, dst, direction="to" ) |
| 26 | utilities.assert_equals( expect=main.TRUE, |
| 27 | actual=status, |
| 28 | onpass="Copy config file succeeded", |
| 29 | onfail="Copy config file failed" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 30 | main.testSetUp.ONOSSetUp( main.Mininet, |
| 31 | main.Cluster, |
| 32 | cellName=cellName ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 33 | |
| 34 | main.step( "Checking if ONOS CLI is ready for issuing commands" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 35 | ready = utilities.retry( main.Cluster.command, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 36 | False, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 37 | kwargs={ "function": "summary", "contentCheck": True }, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 38 | sleep=30, |
| 39 | attempts=10 ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 40 | utilities.assert_equals( expect=True, actual=ready, |
| 41 | onpass="ONOS summary command succeded", |
| 42 | onfail="ONOS summary command failed" ) |
| 43 | |
| 44 | if not ready: |
| 45 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 46 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 47 | |
| 48 | def pToPIntentTest( self, intentExpectedNum ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 49 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 50 | point-to-point intents test for each BGP peer and BGP speaker pair |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 51 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 52 | import time |
| 53 | main.case( "Check point-to-point intents" ) |
| 54 | main.log.info( "There are %s BGP peers in total " |
| 55 | % main.params[ 'config' ][ 'peerNum' ] ) |
| 56 | main.step( "Check P2P intents number from ONOS CLI" ) |
| 57 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 58 | getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 59 | bgpIntentsActualNum = \ |
| 60 | main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult ) |
| 61 | bgpIntentsExpectedNum = int( main.params[ 'config' ][ 'peerNum' ] ) * intentExpectedNum |
| 62 | if bgpIntentsActualNum != bgpIntentsExpectedNum: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 63 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 64 | getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 65 | bgpIntentsActualNum = \ |
| 66 | main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult ) |
| 67 | main.log.info( "bgpIntentsExpected num is:" ) |
| 68 | main.log.info( bgpIntentsExpectedNum ) |
| 69 | main.log.info( "bgpIntentsActual num is:" ) |
| 70 | main.log.info( bgpIntentsActualNum ) |
| 71 | utilities.assert_equals( expect=bgpIntentsExpectedNum, |
| 72 | actual=bgpIntentsActualNum, |
| 73 | onpass="PointToPointIntent Intent Num is correct!", |
| 74 | onfail="PointToPointIntent Intent Num is wrong!" ) |
| 75 | |
| 76 | def routeAndIntentCheck( self, allRoutesExpected, routeIntentsExpectedNum ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 77 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 78 | routes and intents check to all BGP peers |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 79 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 80 | import time |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 81 | getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 82 | allRoutesActual = \ |
| 83 | main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult ) |
| 84 | allRoutesStrExpected = str( sorted( allRoutesExpected ) ) |
| 85 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 86 | if allRoutesStrActual != allRoutesStrExpected: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 87 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 88 | getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 89 | allRoutesActual = \ |
| 90 | main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult ) |
| 91 | allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" ) |
| 92 | |
| 93 | main.step( "Check routes installed" ) |
| 94 | main.log.info( "Routes expected:" ) |
| 95 | main.log.info( allRoutesStrExpected ) |
| 96 | main.log.info( "Routes get from ONOS CLI:" ) |
| 97 | main.log.info( allRoutesStrActual ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 98 | utilities.assertEquals( |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 99 | expect=allRoutesStrExpected, actual=allRoutesStrActual, |
| 100 | onpass="Routes are correct!", |
| 101 | onfail="Routes are wrong!" ) |
| 102 | |
| 103 | main.step( "Check M2S intents installed" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 104 | getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 105 | routeIntentsActualNum = \ |
| 106 | main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult ) |
| 107 | if routeIntentsActualNum != routeIntentsExpectedNum: |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 108 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 109 | getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 110 | routeIntentsActualNum = \ |
| 111 | main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult ) |
| 112 | |
| 113 | main.log.info( "MultiPointToSinglePoint Intent Num expected is:" ) |
| 114 | main.log.info( routeIntentsExpectedNum ) |
| 115 | main.log.info( "MultiPointToSinglePoint Intent NUM Actual is:" ) |
| 116 | main.log.info( routeIntentsActualNum ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 117 | utilities.assertEquals( |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 118 | expect=routeIntentsExpectedNum, |
| 119 | actual=routeIntentsActualNum, |
| 120 | onpass="MultiPointToSinglePoint Intent Num is correct!", |
| 121 | onfail="MultiPointToSinglePoint Intent Num is wrong!" ) |
| 122 | |
| 123 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 124 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 125 | main.FALSE, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 126 | kwargs={ 'isPENDING': False }, |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 127 | attempts=10 ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 128 | utilities.assertEquals( |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 129 | expect=main.TRUE, |
| 130 | actual=flowCheck, |
| 131 | onpass="Flow status is correct!", |
| 132 | onfail="Flow status is wrong!" ) |
| 133 | |
| 134 | def linkUpDownCheck( self, link1Peer, link2Peer, link3Peer, |
| 135 | link1RouteNum, link1IntentNum, |
| 136 | link2RouteNum, link2IntentNum, |
| 137 | link3RouteNum, link3IntentNum, |
| 138 | speakers, hosts, upOrDown ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 139 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 140 | Cut/Recover links to peers one by one, check routes/intents |
| 141 | upOrDown - "up" or "down" |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 142 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 143 | import time |
| 144 | main.case( "Bring " + upOrDown + " links and check routes/intents" ) |
| 145 | main.step( "Bring " + upOrDown + " the link between sw32 and " + link1Peer ) |
| 146 | linkResult1 = main.Mininet.link( END1="sw32", END2=link1Peer, |
| 147 | OPTION=upOrDown ) |
| 148 | utilities.assert_equals( expect=main.TRUE, |
| 149 | actual=linkResult1, |
| 150 | onpass="Bring down link succeeded!", |
| 151 | onfail="Bring down link failed!" ) |
| 152 | |
| 153 | if linkResult1 == main.TRUE: |
| 154 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
| 155 | main.Functions.checkRouteNum( main, link1RouteNum ) |
| 156 | main.Functions.checkM2SintentNum( main, link1IntentNum ) |
| 157 | else: |
| 158 | main.log.error( "Bring " + upOrDown + " link failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 159 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 160 | |
| 161 | main.step( "Bring " + upOrDown + " the link between sw8 and " + link2Peer ) |
| 162 | linkResult2 = main.Mininet.link( END1="sw8", END2=link2Peer, |
| 163 | OPTION=upOrDown ) |
| 164 | utilities.assert_equals( expect=main.TRUE, |
| 165 | actual=linkResult2, |
| 166 | onpass="Bring " + upOrDown + " link succeeded!", |
| 167 | onfail="Bring " + upOrDown + " link failed!" ) |
| 168 | if linkResult2 == main.TRUE: |
| 169 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
| 170 | main.Functions.checkRouteNum( main, link2RouteNum ) |
| 171 | main.Functions.checkM2SintentNum( main, link2IntentNum ) |
| 172 | else: |
| 173 | main.log.error( "Bring " + upOrDown + " link failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 174 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 175 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 176 | main.step( "Bring " + upOrDown + " the link between sw28 and " + link3Peer ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 177 | linkResult3 = main.Mininet.link( END1="sw28", END2=link3Peer, |
| 178 | OPTION=upOrDown ) |
| 179 | utilities.assert_equals( expect=main.TRUE, |
| 180 | actual=linkResult3, |
| 181 | onpass="Bring " + upOrDown + " link succeeded!", |
| 182 | onfail="Bring " + upOrDown + " link failed!" ) |
| 183 | if linkResult3 == main.TRUE: |
| 184 | time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) ) |
| 185 | main.Functions.checkRouteNum( main, link3RouteNum ) |
| 186 | main.Functions.checkM2SintentNum( main, link3IntentNum ) |
| 187 | else: |
| 188 | main.log.error( "Bring " + upOrDown + " link failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 189 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 190 | |
| 191 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 192 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 193 | main.FALSE, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 194 | kwargs={ 'isPENDING': False }, |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 195 | attempts=10 ) |
| 196 | utilities.assert_equals( expect=main.TRUE, |
| 197 | actual=flowCheck, |
| 198 | onpass="Flow status is correct!", |
| 199 | onfail="Flow status is wrong!" ) |
| 200 | |
| 201 | # Ping test |
| 202 | main.Functions.pingSpeakerToPeer( main, speakers=[ speakers ], |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 203 | peers=[ link1Peer, link2Peer, link3Peer ], |
| 204 | expectAllSuccess=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 205 | main.Functions.pingHostToHost( main, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame^] | 206 | hosts=hosts, |
| 207 | expectAllSuccess=False ) |