blob: e51318c62eb853976d1aea73878af0b4beb721af [file] [log] [blame]
Devin Lim58046fa2017-07-05 16:55:00 -07001class 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 Lim58046fa2017-07-05 16:55:00 -07009 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" )
14 main.exit()
Devin Lim142b5342017-07-20 15:22:39 -070015 main.testSetUp.envSetupDescription()
Devin Lim58046fa2017-07-05 16:55:00 -070016 main.testSetUp.envSetup()
17 main.apps = main.params[ 'ENV' ][ 'appString' ]
18 cellName = main.params[ 'ENV' ][ 'cellName' ]
19
Devin Lim58046fa2017-07-05 16:55:00 -070020 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 Lim142b5342017-07-20 15:22:39 -070028 main.testSetUp.ONOSSetUp( main.Mininet,
29 main.Cluster,
30 cellName=cellName )
Devin Lim58046fa2017-07-05 16:55:00 -070031
32 main.step( "Checking if ONOS CLI is ready for issuing commands" )
Devin Lim142b5342017-07-20 15:22:39 -070033 ready = utilities.retry( main.Cluster.command,
34 False,
35 kwargs={ "function":"summary", "contentCheck":True },
36 sleep=30,
37 attempts=10 )
Devin Lim58046fa2017-07-05 16:55:00 -070038 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!" )
44 main.cleanup()
45 main.exit()
46
47 def pToPIntentTest( self, intentExpectedNum ):
48 '''
49 point-to-point intents test for each BGP peer and BGP speaker pair
50 '''
51 import time
52 main.case( "Check point-to-point intents" )
53 main.log.info( "There are %s BGP peers in total "
54 % main.params[ 'config' ][ 'peerNum' ] )
55 main.step( "Check P2P intents number from ONOS CLI" )
56
Devin Lim142b5342017-07-20 15:22:39 -070057 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070058 bgpIntentsActualNum = \
59 main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
60 bgpIntentsExpectedNum = int( main.params[ 'config' ][ 'peerNum' ] ) * intentExpectedNum
61 if bgpIntentsActualNum != bgpIntentsExpectedNum:
62 time.sleep( int( main.params['timers']['RouteDelivery'] ) )
Devin Lim142b5342017-07-20 15:22:39 -070063 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070064 bgpIntentsActualNum = \
65 main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
66 main.log.info( "bgpIntentsExpected num is:" )
67 main.log.info( bgpIntentsExpectedNum )
68 main.log.info( "bgpIntentsActual num is:" )
69 main.log.info( bgpIntentsActualNum )
70 utilities.assert_equals( expect=bgpIntentsExpectedNum,
71 actual=bgpIntentsActualNum,
72 onpass="PointToPointIntent Intent Num is correct!",
73 onfail="PointToPointIntent Intent Num is wrong!" )
74
75 def routeAndIntentCheck( self, allRoutesExpected, routeIntentsExpectedNum ):
76 '''
77 routes and intents check to all BGP peers
78 '''
79 import time
Devin Lim142b5342017-07-20 15:22:39 -070080 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070081 allRoutesActual = \
82 main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
83 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
84 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
85 if allRoutesStrActual != allRoutesStrExpected:
86 time.sleep( int( main.params['timers']['RouteDelivery'] ) )
Devin Lim142b5342017-07-20 15:22:39 -070087 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070088 allRoutesActual = \
89 main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
90 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
91
92 main.step( "Check routes installed" )
93 main.log.info( "Routes expected:" )
94 main.log.info( allRoutesStrExpected )
95 main.log.info( "Routes get from ONOS CLI:" )
96 main.log.info( allRoutesStrActual )
97 utilities.assertEquals( \
98 expect=allRoutesStrExpected, actual=allRoutesStrActual,
99 onpass="Routes are correct!",
100 onfail="Routes are wrong!" )
101
102 main.step( "Check M2S intents installed" )
Devin Lim142b5342017-07-20 15:22:39 -0700103 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700104 routeIntentsActualNum = \
105 main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
106 if routeIntentsActualNum != routeIntentsExpectedNum:
107 time.sleep( int( main.params['timers']['RouteDelivery'] ) )
Devin Lim142b5342017-07-20 15:22:39 -0700108 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700109 routeIntentsActualNum = \
110 main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
111
112 main.log.info( "MultiPointToSinglePoint Intent Num expected is:" )
113 main.log.info( routeIntentsExpectedNum )
114 main.log.info( "MultiPointToSinglePoint Intent NUM Actual is:" )
115 main.log.info( routeIntentsActualNum )
116 utilities.assertEquals( \
117 expect=routeIntentsExpectedNum,
118 actual=routeIntentsActualNum,
119 onpass="MultiPointToSinglePoint Intent Num is correct!",
120 onfail="MultiPointToSinglePoint Intent Num is wrong!" )
121
122 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700123 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700124 main.FALSE,
125 kwargs={'isPENDING':False},
126 attempts=10 )
127 utilities.assertEquals( \
128 expect=main.TRUE,
129 actual=flowCheck,
130 onpass="Flow status is correct!",
131 onfail="Flow status is wrong!" )
132
133 def linkUpDownCheck( self, link1Peer, link2Peer, link3Peer,
134 link1RouteNum, link1IntentNum,
135 link2RouteNum, link2IntentNum,
136 link3RouteNum, link3IntentNum,
137 speakers, hosts, upOrDown ):
138 '''
139 Cut/Recover links to peers one by one, check routes/intents
140 upOrDown - "up" or "down"
141 '''
142 import time
143 main.case( "Bring " + upOrDown + " links and check routes/intents" )
144 main.step( "Bring " + upOrDown + " the link between sw32 and " + link1Peer )
145 linkResult1 = main.Mininet.link( END1="sw32", END2=link1Peer,
146 OPTION=upOrDown )
147 utilities.assert_equals( expect=main.TRUE,
148 actual=linkResult1,
149 onpass="Bring down link succeeded!",
150 onfail="Bring down link failed!" )
151
152 if linkResult1 == main.TRUE:
153 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
154 main.Functions.checkRouteNum( main, link1RouteNum )
155 main.Functions.checkM2SintentNum( main, link1IntentNum )
156 else:
157 main.log.error( "Bring " + upOrDown + " link failed!" )
158 main.cleanup()
159 main.exit()
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!" )
174 main.cleanup()
175 main.exit()
176
177 main.step( "Bring " + upOrDown + " the link between sw28 and "+ link3Peer )
178 linkResult3 = main.Mininet.link( END1="sw28", END2=link3Peer,
179 OPTION=upOrDown )
180 utilities.assert_equals( expect=main.TRUE,
181 actual=linkResult3,
182 onpass="Bring " + upOrDown + " link succeeded!",
183 onfail="Bring " + upOrDown + " link failed!" )
184 if linkResult3 == main.TRUE:
185 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
186 main.Functions.checkRouteNum( main, link3RouteNum )
187 main.Functions.checkM2SintentNum( main, link3IntentNum )
188 else:
189 main.log.error( "Bring " + upOrDown + " link failed!" )
190 main.cleanup()
191 main.exit()
192
193 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700194 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700195 main.FALSE,
196 kwargs={'isPENDING':False},
197 attempts=10 )
198 utilities.assert_equals( expect=main.TRUE,
199 actual=flowCheck,
200 onpass="Flow status is correct!",
201 onfail="Flow status is wrong!" )
202
203 # Ping test
204 main.Functions.pingSpeakerToPeer( main, speakers=[ speakers ],
205 peers=[ link1Peer, link2Peer, link3Peer ],
206 expectAllSuccess=False )
207 main.Functions.pingHostToHost( main,
208 hosts=hosts,
209 expectAllSuccess=False )