blob: 796d5bd5087e17a9a5aea6ae6a13235b5140f786 [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" )
You Wanga0f6ff62018-01-11 15:46:30 -080030 main.testSetUp.ONOSSetUp( main.Cluster, cellName=cellName )
Devin Lim58046fa2017-07-05 16:55:00 -070031
32 main.step( "Checking if ONOS CLI is ready for issuing commands" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070033 ready = utilities.retry( main.Cluster.command,
Devin Lim142b5342017-07-20 15:22:39 -070034 False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070035 kwargs={ "function": "summary", "contentCheck": True },
Devin Lim142b5342017-07-20 15:22:39 -070036 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!" )
Devin Lim44075962017-08-11 10:56:37 -070044 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070045
46 def pToPIntentTest( self, intentExpectedNum ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070047 """
Devin Lim58046fa2017-07-05 16:55:00 -070048 point-to-point intents test for each BGP peer and BGP speaker pair
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070049 """
Devin Lim58046fa2017-07-05 16:55:00 -070050 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 Lim142b5342017-07-20 15:22:39 -070056 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070057 bgpIntentsActualNum = \
58 main.QuaggaCliSpeaker1.extractActualBgpIntentNum( getIntentsResult )
59 bgpIntentsExpectedNum = int( main.params[ 'config' ][ 'peerNum' ] ) * intentExpectedNum
60 if bgpIntentsActualNum != bgpIntentsExpectedNum:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070061 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -070062 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070063 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 Ronquillo23fb2162017-09-15 14:59:57 -070075 """
Devin Lim58046fa2017-07-05 16:55:00 -070076 routes and intents check to all BGP peers
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070077 """
Devin Lim58046fa2017-07-05 16:55:00 -070078 import time
Devin Lim142b5342017-07-20 15:22:39 -070079 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070080 allRoutesActual = \
81 main.QuaggaCliSpeaker1.extractActualRoutesMaster( getRoutesResult )
82 allRoutesStrExpected = str( sorted( allRoutesExpected ) )
83 allRoutesStrActual = str( allRoutesActual ).replace( 'u', "" )
84 if allRoutesStrActual != allRoutesStrExpected:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070085 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -070086 getRoutesResult = main.Cluster.active( 0 ).CLI.routes( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -070087 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 Ronquillo23fb2162017-09-15 14:59:57 -070096 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -070097 expect=allRoutesStrExpected, actual=allRoutesStrActual,
98 onpass="Routes are correct!",
99 onfail="Routes are wrong!" )
100
101 main.step( "Check M2S intents installed" )
Devin Lim142b5342017-07-20 15:22:39 -0700102 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700103 routeIntentsActualNum = \
104 main.QuaggaCliSpeaker1.extractActualRouteIntentNum( getIntentsResult )
105 if routeIntentsActualNum != routeIntentsExpectedNum:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700106 time.sleep( int( main.params[ 'timers' ][ 'RouteDelivery' ] ) )
Devin Lim142b5342017-07-20 15:22:39 -0700107 getIntentsResult = main.Cluster.active( 0 ).CLI.intents( jsonFormat=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700108 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 Ronquillo23fb2162017-09-15 14:59:57 -0700115 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -0700116 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 Lim142b5342017-07-20 15:22:39 -0700122 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700123 main.FALSE,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700124 kwargs={ 'isPENDING': False },
Devin Lim58046fa2017-07-05 16:55:00 -0700125 attempts=10 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700126 utilities.assertEquals(
Devin Lim58046fa2017-07-05 16:55:00 -0700127 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 Ronquillo23fb2162017-09-15 14:59:57 -0700137 """
Devin Lim58046fa2017-07-05 16:55:00 -0700138 Cut/Recover links to peers one by one, check routes/intents
139 upOrDown - "up" or "down"
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700140 """
Devin Lim58046fa2017-07-05 16:55:00 -0700141 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 Lim44075962017-08-11 10:56:37 -0700157 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700158
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 Lim44075962017-08-11 10:56:37 -0700172 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700173
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700174 main.step( "Bring " + upOrDown + " the link between sw28 and " + link3Peer )
Devin Lim58046fa2017-07-05 16:55:00 -0700175 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 Lim44075962017-08-11 10:56:37 -0700187 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700188
189 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700190 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Devin Lim58046fa2017-07-05 16:55:00 -0700191 main.FALSE,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700192 kwargs={ 'isPENDING': False },
Devin Lim58046fa2017-07-05 16:55:00 -0700193 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 Ronquillo23fb2162017-09-15 14:59:57 -0700201 peers=[ link1Peer, link2Peer, link3Peer ],
202 expectAllSuccess=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700203 main.Functions.pingHostToHost( main,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700204 hosts=hosts,
205 expectAllSuccess=False )