Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1 | class SdnBase: |
| 2 | def __init__(self): |
| 3 | self.default = '' |
| 4 | def initSetup( self ): |
| 5 | import json |
| 6 | import time |
| 7 | import os |
| 8 | from operator import eq |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 9 | try: |
| 10 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 11 | main.testSetUp = ONOSSetup() |
| 12 | except Exception: |
| 13 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 14 | main.cleanAndExit() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 15 | main.testSetUp.envSetupDescription() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 16 | main.testSetUp.envSetup() |
| 17 | main.apps = main.params[ 'ENV' ][ 'appString' ] |
| 18 | cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 19 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 20 | main.step( "Copying config files" ) |
| 21 | src = os.path.dirname( main.testFile ) + "/network-cfg.json" |
| 22 | dst = main.ONOSbench.home + "/tools/package/config/network-cfg.json" |
| 23 | status = main.ONOSbench.scp( main.ONOSbench, src, dst, direction="to" ) |
| 24 | utilities.assert_equals( expect=main.TRUE, |
| 25 | actual=status, |
| 26 | onpass="Copy config file succeeded", |
| 27 | onfail="Copy config file failed" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 28 | main.testSetUp.ONOSSetUp( main.Mininet, |
| 29 | main.Cluster, |
| 30 | 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" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 33 | ready = utilities.retry( main.Cluster.command, |
| 34 | False, |
| 35 | kwargs={ "function":"summary", "contentCheck":True }, |
| 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 ): |
| 47 | ''' |
| 48 | point-to-point intents test for each BGP peer and BGP speaker pair |
| 49 | ''' |
| 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: |
| 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 ): |
| 75 | ''' |
| 76 | routes and intents check to all BGP peers |
| 77 | ''' |
| 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: |
| 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 ) |
| 96 | utilities.assertEquals( \ |
| 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: |
| 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 ) |
| 115 | utilities.assertEquals( \ |
| 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, |
| 124 | kwargs={'isPENDING':False}, |
| 125 | attempts=10 ) |
| 126 | utilities.assertEquals( \ |
| 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 ): |
| 137 | ''' |
| 138 | Cut/Recover links to peers one by one, check routes/intents |
| 139 | upOrDown - "up" or "down" |
| 140 | ''' |
| 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 | |
| 174 | main.step( "Bring " + upOrDown + " the link between sw28 and "+ link3Peer ) |
| 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, |
| 192 | kwargs={'isPENDING':False}, |
| 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 ], |
| 201 | peers=[ link1Peer, link2Peer, link3Peer ], |
| 202 | expectAllSuccess=False ) |
| 203 | main.Functions.pingHostToHost( main, |
| 204 | hosts=hosts, |
| 205 | expectAllSuccess=False ) |