blob: 5f7889623c8f93c6c9efb193f5c26a84c3532769 [file] [log] [blame]
pingping-linea32cf82015-10-08 22:37:37 -07001
Jon Hall6e9897d2016-02-29 14:41:32 -08002def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ):
3 import time
pingping-linea32cf82015-10-08 22:37:37 -07004 main.step( "Check routes installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -08005 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -07006 main.log.info( "Route number expected:" )
7 main.log.info( routeNumExpected )
8 main.log.info( "Route number from ONOS CLI:" )
9
pingping-lin3f932a72015-10-09 16:44:50 -070010 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080011 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070012 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080013 cli = main.ONOScli2
14 routeNumActual = cli.ipv4RouteNumber()
15 if routeNumActual != routeNumExpected:
16 time.sleep( wait )
17 routeNumActual = cli.ipv4RouteNumber()
pingping-lina14c7c82015-10-09 15:44:36 -070018
pingping-linea32cf82015-10-08 22:37:37 -070019 main.log.info( routeNumActual )
20 utilities.assertEquals( \
21 expect = routeNumExpected, actual = routeNumActual,
22 onpass = "Route number is correct!",
23 onfail = "Route number is wrong!" )
24
pingping-lina14c7c82015-10-09 15:44:36 -070025def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080026 import time
pingping-linea32cf82015-10-08 22:37:37 -070027 main.step( "Check M2S intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080028 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070029 main.log.info( "Intent number expected:" )
30 main.log.info( intentNumExpected )
31 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070032 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080033 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070034 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080035 cli = main.ONOScli2
36 jsonResult = cli.intents( jsonFormat = True, summary = True,
37 TYPE = "multiPointToSinglePoint" )
pingping-linea32cf82015-10-08 22:37:37 -070038 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080039 if intentNumActual != intentNumExpected:
40 time.sleep( wait )
41 jsonResult = cli.intents( jsonFormat = True, summary = True,
42 TYPE = "multiPointToSinglePoint" )
43 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070044 main.log.info( intentNumActual )
45 utilities.assertEquals( \
46 expect = intentNumExpected, actual = intentNumActual,
47 onpass = "M2S intent number is correct!",
48 onfail = "M2S intent number is wrong!" )
49
pingping-lina14c7c82015-10-09 15:44:36 -070050def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
Jon Hall6e9897d2016-02-29 14:41:32 -080051 import time
pingping-linea32cf82015-10-08 22:37:37 -070052 main.step( "Check P2P intents installed" )
Jon Hall6e9897d2016-02-29 14:41:32 -080053 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070054 main.log.info( "Intent number expected:" )
55 main.log.info( intentNumExpected )
56 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070057 if ONOScli == "ONOScli1":
Jon Hall6e9897d2016-02-29 14:41:32 -080058 cli = main.ONOScli1
pingping-lina14c7c82015-10-09 15:44:36 -070059 else:
Jon Hall6e9897d2016-02-29 14:41:32 -080060 cli = main.ONOScli2
61 jsonResult = cli.intents( jsonFormat = True, summary = True,
62 TYPE = "pointToPoint" )
pingping-linea32cf82015-10-08 22:37:37 -070063 intentNumActual = jsonResult['installed']
Jon Hall6e9897d2016-02-29 14:41:32 -080064
65 if intentNumActual != intentNumExpected:
66 time.sleep( wait )
67 jsonResult = cli.intents( jsonFormat = True, summary = True,
68 TYPE = "pointToPoint" )
69 intentNumActual = jsonResult['installed']
pingping-linea32cf82015-10-08 22:37:37 -070070 main.log.info( intentNumActual )
71 utilities.assertEquals( \
72 expect = intentNumExpected, actual = intentNumActual,
73 onpass = "P2P intent number is correct!",
74 onfail = "P2P intent number is wrong!" )
75
76def checkFlowNum( main, switch, flowNumExpected ):
Jon Hall6e9897d2016-02-29 14:41:32 -080077 import time
pingping-linea32cf82015-10-08 22:37:37 -070078 main.step( "Check flow entry number in " + switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080079 wait = int( main.params['timers']['PathAvailable'] )
pingping-linea32cf82015-10-08 22:37:37 -070080 main.log.info( "Flow number expected:" )
81 main.log.info( flowNumExpected )
82 main.log.info( "Flow number actual:" )
83 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
Jon Hall6e9897d2016-02-29 14:41:32 -080084 if flowNumActual != flowNumExpected :
85 time.sleep( wait )
86 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
pingping-linea32cf82015-10-08 22:37:37 -070087 main.log.info( flowNumActual )
88 utilities.assertEquals( \
89 expect = flowNumExpected, actual = flowNumActual,
90 onpass = "Flow number in " + switch + " is correct!",
91 onfail = "Flow number in " + switch + " is wrong!" )
92
93
94def pingSpeakerToPeer( main, speakers = ["speaker1"],
95 peers = ["peer64514", "peer64515", "peer64516"],
96 expectAllSuccess = True ):
97 """
98 Carry out ping test between each BGP speaker and peer pair
99 Optional argument:
100 * speakers - BGP speakers
101 * peers - BGP peers
102 * expectAllSuccess - boolean indicating if you expect all results
103 succeed if True, otherwise expect all results fail if False
104 """
105 if len( speakers ) == 0:
106 main.log.error( "Parameter speakers can not be empty." )
107 main.cleanup()
108 main.exit()
109 if len( peers ) == 0:
110 main.log.error( "Parameter speakers can not be empty." )
111 main.cleanup()
112 main.exit()
113
114 if expectAllSuccess:
115 main.step( "BGP speakers ping peers, expect all tests to succeed" )
116 else:
117 main.step( "BGP speakers ping peers, expect all tests to fail" )
118
119 result = True
120 if expectAllSuccess:
121 for speaker in speakers:
122 for peer in peers:
123 tmpResult = main.Mininet.pingHost( src = speaker,
124 target = peer )
125 result = result and ( tmpResult == main.TRUE )
126 else:
127 for speaker in speakers:
128 for peer in peers:
129 tmpResult = main.Mininet.pingHost( src = speaker,
130 target = peer )
131
132 utilities.assert_equals( expect = True, actual = result,
133 onpass = "Ping test results are expected",
134 onfail = "Ping test results are Not expected" )
135
136 if result == False:
137 main.cleanup()
138 main.exit()
139
140
141def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"],
142 expectAllSuccess = True ):
143 """
144 Carry out ping test between each BGP host pair
145 Optional argument:
146 * hosts - hosts behind BGP peer routers
147 * expectAllSuccess - boolean indicating if you expect all results
148 succeed if True, otherwise expect all results fail if False
149 """
Jon Hall6e9897d2016-02-29 14:41:32 -0800150 main.step( "Check ping between each host pair, expect all to succede=" +
151 str( expectAllSuccess ) )
pingping-linea32cf82015-10-08 22:37:37 -0700152 if len( hosts ) == 0:
153 main.log.error( "Parameter hosts can not be empty." )
154 main.cleanup()
155 main.exit()
156
157 result = True
158 if expectAllSuccess:
159 for srcHost in hosts:
160 for targetHost in hosts:
161 if srcHost != targetHost:
162 tmpResult = main.Mininet.pingHost( src = srcHost,
163 target = targetHost )
164 result = result and ( tmpResult == main.TRUE )
165 else:
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.FALSE )
172
173 utilities.assert_equals( expect = True, actual = result,
174 onpass = "Ping test results are expected",
175 onfail = "Ping test results are Not expected" )
176
177 '''
178 if result == False:
179 main.cleanup()
180 main.exit()
181 '''
182
183
184def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ):
185 """
186 Create a tunnel from Mininet host to host outside Mininet
187 """
188 main.step( "Set up tunnel from Mininet node " +
189 str( srcIp ) + ":" + str( srcPort ) + " to ONOS node "
190 + str(dstIp) + ":" + str(dstPort) )
191 forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort )
192 command = 'ssh -nNT -o "PasswordAuthentication no" \
193 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp )
194
195
196 tunnelResult = main.TRUE
197 tunnelResult = main.Mininet.node( "root", command )
198 utilities.assert_equals( expect = True,
199 actual = ( "PasswordAuthentication" in tunnelResult ),
200 onpass = "Created tunnel succeeded",
201 onfail = "Create tunnel failed" )
202 if ( "PasswordAuthentication" not in tunnelResult ) :
203 main.cleanup()
204 main.exit()
205