blob: 36f1eb418fd4e6dceb3e5883bbe40aed4d63e28f [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
Devin Lim142b5342017-07-20 15:22:39 -070022def checkRouteNum( main, routeNumExpected, node=1 ):
Jon Hall6e9897d2016-02-29 14:41:32 -080023 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
Devin Lim142b5342017-07-20 15:22:39 -070030 cli = main.Cluster.active( node - 1 ).CLI
Jon Hall6e9897d2016-02-29 14:41:32 -080031 routeNumActual = cli.ipv4RouteNumber()
32 if routeNumActual != routeNumExpected:
33 time.sleep( wait )
34 routeNumActual = cli.ipv4RouteNumber()
pingping-lina14c7c82015-10-09 15:44:36 -070035
pingping-linea32cf82015-10-08 22:37:37 -070036 main.log.info( routeNumActual )
37 utilities.assertEquals( \
38 expect = routeNumExpected, actual = routeNumActual,
39 onpass = "Route number is correct!",
40 onfail = "Route number is wrong!" )
41
Devin Lim142b5342017-07-20 15:22:39 -070042def checkM2SintentNum( main, intentNumExpected, node=1 ):
Jon Hall6e9897d2016-02-29 14:41:32 -080043 import time
pingping-linea32cf82015-10-08 22:37:37 -070044 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080045 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070046 main.log.info( "Intent number expected:" )
47 main.log.info( intentNumExpected )
48 main.log.info( "Intent number from ONOS CLI:" )
Devin Lim142b5342017-07-20 15:22:39 -070049 cli = main.Cluster.active( node - 1 ).CLI
Jon Hall6e9897d2016-02-29 14:41:32 -080050 jsonResult = cli.intents( jsonFormat = True, summary = True,
51 TYPE = "multiPointToSinglePoint" )
pingping-linea32cf82015-10-08 22:37:37 -070052 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080053 if intentNumActual != intentNumExpected:
54 time.sleep( wait )
55 jsonResult = cli.intents( jsonFormat = True, summary = True,
56 TYPE = "multiPointToSinglePoint" )
57 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070058 main.log.info( intentNumActual )
59 utilities.assertEquals( \
60 expect = intentNumExpected, actual = intentNumActual,
61 onpass = "M2S intent number is correct!",
62 onfail = "M2S intent number is wrong!" )
63
Devin Lim142b5342017-07-20 15:22:39 -070064def checkP2PintentNum( main, intentNumExpected, node=1 ):
Jon Hall6e9897d2016-02-29 14:41:32 -080065 import time
pingping-linea32cf82015-10-08 22:37:37 -070066 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080067 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070068 main.log.info( "Intent number expected:" )
69 main.log.info( intentNumExpected )
70 main.log.info( "Intent number from ONOS CLI:" )
Devin Lim142b5342017-07-20 15:22:39 -070071 cli = main.Cluster.active( node - 1 ).CLI
Jon Hall6e9897d2016-02-29 14:41:32 -080072 jsonResult = cli.intents( jsonFormat = True, summary = True,
73 TYPE = "pointToPoint" )
pingping-linea32cf82015-10-08 22:37:37 -070074 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080075
76 if intentNumActual != intentNumExpected:
77 time.sleep( wait )
78 jsonResult = cli.intents( jsonFormat = True, summary = True,
79 TYPE = "pointToPoint" )
80 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070081 main.log.info( intentNumActual )
82 utilities.assertEquals( \
83 expect = intentNumExpected, actual = intentNumActual,
84 onpass = "P2P intent number is correct!",
85 onfail = "P2P intent number is wrong!" )
86
87def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080088 import time
pingping-linea32cf82015-10-08 22:37:37 -070089 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080090 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070091 main.log.info( "Flow number expected:" )
92 main.log.info( flowNumExpected )
93 main.log.info( "Flow number actual:" )
94 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080095 if flowNumActual != flowNumExpected :
96 time.sleep( wait )
97 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-linea32cf82015-10-08 22:37:37 -070098 main.log.info( flowNumActual )
99 utilities.assertEquals( \
100 expect = flowNumExpected, actual = flowNumActual,
101 onpass = "Flow number in " + switch + " is correct!",
102 onfail = "Flow number in " + switch + " is wrong!" )
103
104
alison62006dd2016-12-15 16:21:28 -0800105def pingSpeakerToPeer( main, speakers = ["spk1"],
106 peers = ["p64514", "p64515", "p64516"],
pingping-linea32cf82015-10-08 22:37:37 -0700107 expectAllSuccess = True ):
108 """
109 Carry out ping test between each BGP speaker and peer pair
110 Optional argument:
111 * speakers - BGP speakers
112 * peers - BGP peers
113 * expectAllSuccess - boolean indicating if you expect all results
114 succeed if True, otherwise expect all results fail if False
115 """
116 if len( speakers ) == 0:
117 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700118 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700119 if len( peers ) == 0:
120 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700121 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700122
123 if expectAllSuccess:
124 main.step( "BGP speakers ping peers, expect all tests to succeed" )
125 else:
126 main.step( "BGP speakers ping peers, expect all tests to fail" )
127
128 result = True
129 if expectAllSuccess:
130 for speaker in speakers:
131 for peer in peers:
132 tmpResult = main.Mininet.pingHost( src = speaker,
133 target = peer )
134 result = result and ( tmpResult == main.TRUE )
135 else:
136 for speaker in speakers:
137 for peer in peers:
138 tmpResult = main.Mininet.pingHost( src = speaker,
139 target = peer )
140
141 utilities.assert_equals( expect = True, actual = result,
142 onpass = "Ping test results are expected",
143 onfail = "Ping test results are Not expected" )
144
145 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700146 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700147
148
alison62006dd2016-12-15 16:21:28 -0800149def pingHostToHost( main, hosts = ["h64514", "h64515", "h64516"],
pingping-linea32cf82015-10-08 22:37:37 -0700150 expectAllSuccess = True ):
151 """
152 Carry out ping test between each BGP host pair
153 Optional argument:
154 * hosts - hosts behind BGP peer routers
155 * expectAllSuccess - boolean indicating if you expect all results
156 succeed if True, otherwise expect all results fail if False
157 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800158 main.step( "Check ping between each host pair, expect all to succede=" +
159 str( expectAllSuccess ) )
pingping-linea32cf82015-10-08 22:37:37 -0700160 if len( hosts ) == 0:
161 main.log.error( "Parameter hosts can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700162 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700163
164 result = True
165 if expectAllSuccess:
166 for srcHost in hosts:
167 for targetHost in hosts:
168 if srcHost != targetHost:
169 tmpResult = main.Mininet.pingHost( src = srcHost,
170 target = targetHost )
171 result = result and ( tmpResult == main.TRUE )
172 else:
173 for srcHost in hosts:
174 for targetHost in hosts:
175 if srcHost != targetHost:
176 tmpResult = main.Mininet.pingHost( src = srcHost,
177 target = targetHost )
178 result = result and ( tmpResult == main.FALSE )
179
180 utilities.assert_equals( expect = True, actual = result,
181 onpass = "Ping test results are expected",
182 onfail = "Ping test results are Not expected" )
183
184 '''
185 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700186 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700187 '''
188
189
190def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ):
191 """
192 Create a tunnel from Mininet host to host outside Mininet
193 """
194 main.step( "Set up tunnel from Mininet node " +
195 str( srcIp ) + ":" + str( srcPort ) + " to ONOS node "
196 + str(dstIp) + ":" + str(dstPort) )
197 forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort )
198 command = 'ssh -nNT -o "PasswordAuthentication no" \
199 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp )
200
201
202 tunnelResult = main.TRUE
203 tunnelResult = main.Mininet.node( "root", command )
204 utilities.assert_equals( expect = True,
205 actual = ( "PasswordAuthentication" in tunnelResult ),
206 onpass = "Created tunnel succeeded",
207 onfail = "Create tunnel failed" )
208 if ( "PasswordAuthentication" not in tunnelResult ) :
Devin Lim44075962017-08-11 10:56:37 -0700209 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700210