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