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