blob: f291195e22eaf881f16e0992c62c7ac8e63e4fe1 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
pingping-linea32cf82015-10-08 22:37:37 -070021
Jon Hall6e9897d2016-02-29 14:41:32 -080022def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ):
23 import time
pingping-linea32cf82015-10-08 22:37:37 -070024 main.step( "Check routes installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080025 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070026 main.log.info( "Route number expected:" )
27 main.log.info( routeNumExpected )
28 main.log.info( "Route number from ONOS CLI:" )
29
pingping-lin3f932a72015-10-09 16:44:50 -070030 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080031 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070032 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080033 cli = main.ONOScli2
34 routeNumActual = cli.ipv4RouteNumber()
35 if routeNumActual != routeNumExpected:
36 time.sleep( wait )
37 routeNumActual = cli.ipv4RouteNumber()
pingping-lina14c7c82015-10-09 15:44:36 -070038
pingping-linea32cf82015-10-08 22:37:37 -070039 main.log.info( routeNumActual )
40 utilities.assertEquals( \
41 expect = routeNumExpected, actual = routeNumActual,
42 onpass = "Route number is correct!",
43 onfail = "Route number is wrong!" )
44
pingping-lina14c7c82015-10-09 15:44:36 -070045def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080046 import time
pingping-linea32cf82015-10-08 22:37:37 -070047 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080048 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070049 main.log.info( "Intent number expected:" )
50 main.log.info( intentNumExpected )
51 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070052 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080053 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070054 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080055 cli = main.ONOScli2
56 jsonResult = cli.intents( jsonFormat = True, summary = True,
57 TYPE = "multiPointToSinglePoint" )
pingping-linea32cf82015-10-08 22:37:37 -070058 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080059 if intentNumActual != intentNumExpected:
60 time.sleep( wait )
61 jsonResult = cli.intents( jsonFormat = True, summary = True,
62 TYPE = "multiPointToSinglePoint" )
63 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070064 main.log.info( intentNumActual )
65 utilities.assertEquals( \
66 expect = intentNumExpected, actual = intentNumActual,
67 onpass = "M2S intent number is correct!",
68 onfail = "M2S intent number is wrong!" )
69
pingping-lina14c7c82015-10-09 15:44:36 -070070def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080071 import time
pingping-linea32cf82015-10-08 22:37:37 -070072 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080073 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070074 main.log.info( "Intent number expected:" )
75 main.log.info( intentNumExpected )
76 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070077 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080078 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070079 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080080 cli = main.ONOScli2
81 jsonResult = cli.intents( jsonFormat = True, summary = True,
82 TYPE = "pointToPoint" )
pingping-linea32cf82015-10-08 22:37:37 -070083 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080084
85 if intentNumActual != intentNumExpected:
86 time.sleep( wait )
87 jsonResult = cli.intents( jsonFormat = True, summary = True,
88 TYPE = "pointToPoint" )
89 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070090 main.log.info( intentNumActual )
91 utilities.assertEquals( \
92 expect = intentNumExpected, actual = intentNumActual,
93 onpass = "P2P intent number is correct!",
94 onfail = "P2P intent number is wrong!" )
95
96def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080097 import time
pingping-linea32cf82015-10-08 22:37:37 -070098 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080099 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -0700100 main.log.info( "Flow number expected:" )
101 main.log.info( flowNumExpected )
102 main.log.info( "Flow number actual:" )
103 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -0800104 if flowNumActual != flowNumExpected :
105 time.sleep( wait )
106 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-linea32cf82015-10-08 22:37:37 -0700107 main.log.info( flowNumActual )
108 utilities.assertEquals( \
109 expect = flowNumExpected, actual = flowNumActual,
110 onpass = "Flow number in " + switch + " is correct!",
111 onfail = "Flow number in " + switch + " is wrong!" )
112
113
alison62006dd2016-12-15 16:21:28 -0800114def pingSpeakerToPeer( main, speakers = ["spk1"],
115 peers = ["p64514", "p64515", "p64516"],
pingping-linea32cf82015-10-08 22:37:37 -0700116 expectAllSuccess = True ):
117 """
118 Carry out ping test between each BGP speaker and peer pair
119 Optional argument:
120 * speakers - BGP speakers
121 * peers - BGP peers
122 * expectAllSuccess - boolean indicating if you expect all results
123 succeed if True, otherwise expect all results fail if False
124 """
125 if len( speakers ) == 0:
126 main.log.error( "Parameter speakers can not be empty." )
127 main.cleanup()
128 main.exit()
129 if len( peers ) == 0:
130 main.log.error( "Parameter speakers can not be empty." )
131 main.cleanup()
132 main.exit()
133
134 if expectAllSuccess:
135 main.step( "BGP speakers ping peers, expect all tests to succeed" )
136 else:
137 main.step( "BGP speakers ping peers, expect all tests to fail" )
138
139 result = True
140 if expectAllSuccess:
141 for speaker in speakers:
142 for peer in peers:
143 tmpResult = main.Mininet.pingHost( src = speaker,
144 target = peer )
145 result = result and ( tmpResult == main.TRUE )
146 else:
147 for speaker in speakers:
148 for peer in peers:
149 tmpResult = main.Mininet.pingHost( src = speaker,
150 target = peer )
151
152 utilities.assert_equals( expect = True, actual = result,
153 onpass = "Ping test results are expected",
154 onfail = "Ping test results are Not expected" )
155
156 if result == False:
157 main.cleanup()
158 main.exit()
159
160
alison62006dd2016-12-15 16:21:28 -0800161def pingHostToHost( main, hosts = ["h64514", "h64515", "h64516"],
pingping-linea32cf82015-10-08 22:37:37 -0700162 expectAllSuccess = True ):
163 """
164 Carry out ping test between each BGP host pair
165 Optional argument:
166 * hosts - hosts behind BGP peer routers
167 * expectAllSuccess - boolean indicating if you expect all results
168 succeed if True, otherwise expect all results fail if False
169 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800170 main.step( "Check ping between each host pair, expect all to succede=" +
171 str( expectAllSuccess ) )
pingping-linea32cf82015-10-08 22:37:37 -0700172 if len( hosts ) == 0:
173 main.log.error( "Parameter hosts can not be empty." )
174 main.cleanup()
175 main.exit()
176
177 result = True
178 if expectAllSuccess:
179 for srcHost in hosts:
180 for targetHost in hosts:
181 if srcHost != targetHost:
182 tmpResult = main.Mininet.pingHost( src = srcHost,
183 target = targetHost )
184 result = result and ( tmpResult == main.TRUE )
185 else:
186 for srcHost in hosts:
187 for targetHost in hosts:
188 if srcHost != targetHost:
189 tmpResult = main.Mininet.pingHost( src = srcHost,
190 target = targetHost )
191 result = result and ( tmpResult == main.FALSE )
192
193 utilities.assert_equals( expect = True, actual = result,
194 onpass = "Ping test results are expected",
195 onfail = "Ping test results are Not expected" )
196
197 '''
198 if result == False:
199 main.cleanup()
200 main.exit()
201 '''
202
203
204def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ):
205 """
206 Create a tunnel from Mininet host to host outside Mininet
207 """
208 main.step( "Set up tunnel from Mininet node " +
209 str( srcIp ) + ":" + str( srcPort ) + " to ONOS node "
210 + str(dstIp) + ":" + str(dstPort) )
211 forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort )
212 command = 'ssh -nNT -o "PasswordAuthentication no" \
213 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp )
214
215
216 tunnelResult = main.TRUE
217 tunnelResult = main.Mininet.node( "root", command )
218 utilities.assert_equals( expect = True,
219 actual = ( "PasswordAuthentication" in tunnelResult ),
220 onpass = "Created tunnel succeeded",
221 onfail = "Create tunnel failed" )
222 if ( "PasswordAuthentication" not in tunnelResult ) :
223 main.cleanup()
224 main.exit()
225