blob: c5eb905e19cd7a1bcdca1864fc91bd72774bf2ad [file] [log] [blame]
Devin Lim58046fa2017-07-05 16:55:00 -07001class SdnBase:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002
3 def __init__( self ):
Devin Lim58046fa2017-07-05 16:55:00 -07004 self.default = ''
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07005
Devin Lim58046fa2017-07-05 16:55:00 -07006 def initSetup( self ):
7 import json
8 import time
9 import os
10 from operator import eq
Devin Lim58046fa2017-07-05 16:55:00 -070011 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 Lim44075962017-08-11 10:56:37 -070016 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070017 main.testSetUp.envSetupDescription()
Devin Lim58046fa2017-07-05 16:55:00 -070018 main.testSetUp.envSetup()
19 main.apps = main.params[ 'ENV' ][ 'appString' ]
20 cellName = main.params[ 'ENV' ][ 'cellName' ]
21
Devin Lim58046fa2017-07-05 16:55:00 -070022 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 Lim142b5342017-07-20 15:22:39 -070030 main.testSetUp.ONOSSetUp( main.Mininet,
31 main.Cluster,
32 cellName=cellName )
Devin Lim58046fa2017-07-05 16:55:00 -070033
34 main.step( "Checking if ONOS CLI is ready for issuing commands" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070035 ready = utilities.retry( main.Cluster.command,
Devin Lim142b5342017-07-20 15:22:39 -070036 False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070037 kwargs={ "function": "summary", "contentCheck": True },
Devin Lim142b5342017-07-20 15:22:39 -070038 sleep=30,
39 attempts=10 )
Devin Lim58046fa2017-07-05 16:55:00 -070040 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 Lim44075962017-08-11 10:56:37 -070046 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070047
48 def pToPIntentTest( self, intentExpectedNum ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070049 """
Devin Lim58046fa2017-07-05 16:55:00 -070050 point-to-point intents test for each BGP peer and BGP speaker pair
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070051 """
Devin Lim58046fa2017-07-05 16:55:00 -070052 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 Lim142b5342017-07-20 15:22:39 -070058 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070059 bgpIntentsActualNum = \
60 main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
61 bgpIntentsExpectedNum = int( main.params[ 'config' ][ 'peerNum' ] ) * intentExpectedNum
62 if bgpIntentsActualNum != bgpIntentsExpectedNum:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070063 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -070064 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070065 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 Ronquillo23fb2162017-09-15 14:59:57 -070077 """
Devin Lim58046fa2017-07-05 16:55:00 -070078 routes and intents check to all BGP peers
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079 """
Devin Lim58046fa2017-07-05 16:55:00 -070080 import time
Devin Lim142b5342017-07-20 15:22:39 -070081 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070082 allRoutesActual = \
83 main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
84 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
85 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
86 if allRoutesStrActual != allRoutesStrExpected:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070087 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -070088 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070089 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 Ronquillo23fb2162017-09-15 14:59:57 -070098 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -070099 expect=allRoutesStrExpected, actual=allRoutesStrActual,
100 onpass="Routes are correct!",
101 onfail="Routes are wrong!" )
102
103 main.step( "Check M2S intents installed" )
Devin Lim142b5342017-07-20 15:22:39 -0700104 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700105 routeIntentsActualNum = \
106 main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
107 if routeIntentsActualNum != routeIntentsExpectedNum:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700108 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -0700109 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700110 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 Ronquillo23fb2162017-09-15 14:59:57 -0700117 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -0700118 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 Lim142b5342017-07-20 15:22:39 -0700124 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700125 main.FALSE,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700126 kwargs={ 'isPENDING': False },
Devin Lim58046fa2017-07-05 16:55:00 -0700127 attempts=10 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700128 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -0700129 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 Ronquillo23fb2162017-09-15 14:59:57 -0700139 """
Devin Lim58046fa2017-07-05 16:55:00 -0700140 Cut/Recover links to peers one by one, check routes/intents
141 upOrDown - "up" or "down"
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700142 """
Devin Lim58046fa2017-07-05 16:55:00 -0700143 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 Lim44075962017-08-11 10:56:37 -0700159 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700160
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 Lim44075962017-08-11 10:56:37 -0700174 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700175
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700176 main.step( "Bring " + upOrDown + " the link between sw28 and " + link3Peer )
Devin Lim58046fa2017-07-05 16:55:00 -0700177 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 Lim44075962017-08-11 10:56:37 -0700189 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700190
191 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700192 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700193 main.FALSE,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700194 kwargs={ 'isPENDING': False },
Devin Lim58046fa2017-07-05 16:55:00 -0700195 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 Ronquillo23fb2162017-09-15 14:59:57 -0700203 peers=[ link1Peer, link2Peer, link3Peer ],
204 expectAllSuccess=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700205 main.Functions.pingHostToHost( main,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700206 hosts=hosts,
207 expectAllSuccess=False )