blob: 8edc284f36902c92f50a64a66e6746862bc018c7 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
Devin Lim142b5342017-07-20 15:22:39 -070021def checkRouteNum( main, routeNumExpected, node=1 ):
Jon Hall6e9897d2016-02-29 14:41:32 -080022 import time
pingping-linea32cf82015-10-08 22:37:37 -070023 main.step( "Check routes installed" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
pingping-linea32cf82015-10-08 22:37:37 -070025 main.log.info( "Route number expected:" )
26 main.log.info( routeNumExpected )
27 main.log.info( "Route number from ONOS CLI:" )
28
Devin Lim142b5342017-07-20 15:22:39 -070029 cli = main.Cluster.active( node - 1 ).CLI
Jon Hall6e9897d2016-02-29 14:41:32 -080030 routeNumActual = cli.ipv4RouteNumber()
31 if routeNumActual != routeNumExpected:
32 time.sleep( wait )
33 routeNumActual = cli.ipv4RouteNumber()
pingping-lina14c7c82015-10-09 15:44:36 -070034
pingping-linea32cf82015-10-08 22:37:37 -070035 main.log.info( routeNumActual )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070036 utilities.assertEquals(
37 expect=routeNumExpected, actual=routeNumActual,
38 onpass="Route number is correct!",
39 onfail="Route number is wrong!" )
40
pingping-linea32cf82015-10-08 22:37:37 -070041
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" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070045 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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070050 jsonResult = cli.intents( jsonFormat=True, summary=True,
51 TYPE="multiPointToSinglePoint" )
52 intentNumActual = jsonResult[ 'installed' ]
Jon Hall6e9897d2016-02-29 14:41:32 -080053 if intentNumActual != intentNumExpected:
54 time.sleep( wait )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070055 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 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070059 utilities.assertEquals(
60 expect=intentNumExpected, actual=intentNumActual,
61 onpass="M2S intent number is correct!",
62 onfail="M2S intent number is wrong!" )
63
pingping-linea32cf82015-10-08 22:37:37 -070064
Devin Lim142b5342017-07-20 15:22:39 -070065def checkP2PintentNum( main, intentNumExpected, node=1 ):
Jon Hall6e9897d2016-02-29 14:41:32 -080066 import time
pingping-linea32cf82015-10-08 22:37:37 -070067 main.step( "Check P2P intents installed" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070068 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
pingping-linea32cf82015-10-08 22:37:37 -070069 main.log.info( "Intent number expected:" )
70 main.log.info( intentNumExpected )
71 main.log.info( "Intent number from ONOS CLI:" )
Devin Lim142b5342017-07-20 15:22:39 -070072 cli = main.Cluster.active( node - 1 ).CLI
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070073 jsonResult = cli.intents( jsonFormat=True, summary=True,
74 TYPE="pointToPoint" )
75 intentNumActual = jsonResult[ 'installed' ]
Jon Hall6e9897d2016-02-29 14:41:32 -080076
77 if intentNumActual != intentNumExpected:
78 time.sleep( wait )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070079 jsonResult = cli.intents( jsonFormat=True, summary=True,
80 TYPE="pointToPoint" )
81 intentNumActual = jsonResult[ 'installed' ]
pingping-linea32cf82015-10-08 22:37:37 -070082 main.log.info( intentNumActual )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070083 utilities.assertEquals(
84 expect=intentNumExpected, actual=intentNumActual,
85 onpass="P2P intent number is correct!",
86 onfail="P2P intent number is wrong!" )
87
pingping-linea32cf82015-10-08 22:37:37 -070088
89def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080090 import time
pingping-linea32cf82015-10-08 22:37:37 -070091 main.step( "Check flow entry number in " + switch )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 wait = int( main.params[ 'timers' ][ 'PathAvailable' ] )
pingping-linea32cf82015-10-08 22:37:37 -070093 main.log.info( "Flow number expected:" )
94 main.log.info( flowNumExpected )
95 main.log.info( "Flow number actual:" )
96 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070097 if flowNumActual != flowNumExpected:
Jon Hall6e9897d2016-02-29 14:41:32 -080098 time.sleep( wait )
99 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-linea32cf82015-10-08 22:37:37 -0700100 main.log.info( flowNumActual )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700101 utilities.assertEquals(
102 expect=flowNumExpected, actual=flowNumActual,
103 onpass="Flow number in " + switch + " is correct!",
104 onfail="Flow number in " + switch + " is wrong!" )
pingping-linea32cf82015-10-08 22:37:37 -0700105
106
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700107def pingSpeakerToPeer( main, speakers=[ "spk1" ],
108 peers=[ "p64514", "p64515", "p64516" ],
109 expectAllSuccess=True ):
pingping-linea32cf82015-10-08 22:37:37 -0700110 """
111 Carry out ping test between each BGP speaker and peer pair
112 Optional argument:
113 * speakers - BGP speakers
114 * peers - BGP peers
115 * expectAllSuccess - boolean indicating if you expect all results
116 succeed if True, otherwise expect all results fail if False
117 """
118 if len( speakers ) == 0:
119 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700120 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700121 if len( peers ) == 0:
122 main.log.error( "Parameter speakers can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700123 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700124
125 if expectAllSuccess:
126 main.step( "BGP speakers ping peers, expect all tests to succeed" )
127 else:
128 main.step( "BGP speakers ping peers, expect all tests to fail" )
129
130 result = True
131 if expectAllSuccess:
132 for speaker in speakers:
133 for peer in peers:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700134 tmpResult = main.Mininet.pingHost( src=speaker,
135 target=peer )
pingping-linea32cf82015-10-08 22:37:37 -0700136 result = result and ( tmpResult == main.TRUE )
137 else:
138 for speaker in speakers:
139 for peer in peers:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700140 tmpResult = main.Mininet.pingHost( src=speaker,
141 target=peer )
pingping-linea32cf82015-10-08 22:37:37 -0700142
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700143 utilities.assert_equals( expect=True, actual=result,
144 onpass="Ping test results are expected",
145 onfail="Ping test results are Not expected" )
pingping-linea32cf82015-10-08 22:37:37 -0700146
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700147 if not result:
Devin Lim44075962017-08-11 10:56:37 -0700148 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700149
150
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700151def pingHostToHost( main, hosts=[ "h64514", "h64515", "h64516" ],
152 expectAllSuccess=True ):
pingping-linea32cf82015-10-08 22:37:37 -0700153 """
154 Carry out ping test between each BGP host pair
155 Optional argument:
156 * hosts - hosts behind BGP peer routers
157 * expectAllSuccess - boolean indicating if you expect all results
158 succeed if True, otherwise expect all results fail if False
159 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800160 main.step( "Check ping between each host pair, expect all to succede=" +
161 str( expectAllSuccess ) )
pingping-linea32cf82015-10-08 22:37:37 -0700162 if len( hosts ) == 0:
163 main.log.error( "Parameter hosts can not be empty." )
Devin Lim44075962017-08-11 10:56:37 -0700164 main.cleanAndExit()
pingping-linea32cf82015-10-08 22:37:37 -0700165
166 result = True
167 if expectAllSuccess:
168 for srcHost in hosts:
169 for targetHost in hosts:
170 if srcHost != targetHost:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700171 tmpResult = main.Mininet.pingHost( src=srcHost,
172 target=targetHost )
pingping-linea32cf82015-10-08 22:37:37 -0700173 result = result and ( tmpResult == main.TRUE )
174 else:
175 for srcHost in hosts:
176 for targetHost in hosts:
177 if srcHost != targetHost:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 tmpResult = main.Mininet.pingHost( src=srcHost,
179 target=targetHost )
pingping-linea32cf82015-10-08 22:37:37 -0700180 result = result and ( tmpResult == main.FALSE )
181
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700182 utilities.assert_equals( expect=True, actual=result,
183 onpass="Ping test results are expected",
184 onfail="Ping test results are Not expected" )
pingping-linea32cf82015-10-08 22:37:37 -0700185
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700186 """
pingping-linea32cf82015-10-08 22:37:37 -0700187 if result == False:
Devin Lim44075962017-08-11 10:56:37 -0700188 main.cleanAndExit()
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700189 """
pingping-linea32cf82015-10-08 22:37:37 -0700190def 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 "
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700196 + str( dstIp ) + ":" + str( dstPort ) )
pingping-linea32cf82015-10-08 22:37:37 -0700197 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
pingping-linea32cf82015-10-08 22:37:37 -0700201 tunnelResult = main.TRUE
202 tunnelResult = main.Mininet.node( "root", command )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700203 utilities.assert_equals( expect=True,
204 actual=( "PasswordAuthentication" in tunnelResult ),
pingping-linea32cf82015-10-08 22:37:37 -0700205 onpass = "Created tunnel succeeded",
206 onfail = "Create tunnel failed" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700207 if ( "PasswordAuthentication" not in tunnelResult ):
Devin Lim44075962017-08-11 10:56:37 -0700208 main.cleanAndExit()