blob: e29c23aad5d29ab8673c1ee6549bf1eef7ea87c8 [file] [log] [blame]
Jon Hallbc401252016-03-03 14:44:04 -08001
2def checkRouteNum( main, routeNumExpected, ONOScli="ONOScli1" ):
3 import time
4 main.step( "Check routes installed" )
5 wait = int( main.params['timers']['PathAvailable'] )
6 main.log.info( "Route number expected:" )
7 main.log.info( routeNumExpected )
8 main.log.info( "Route number from ONOS CLI:" )
9
10 if ONOScli == "ONOScli1":
11 cli = main.ONOScli1
12 else:
13 cli = main.ONOScli2
14 routeNumActual = cli.ipv4RouteNumber()
15 if routeNumActual != routeNumExpected:
16 time.sleep( wait )
17 routeNumActual = cli.ipv4RouteNumber()
18
19 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
25def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
26 import time
27 main.step( "Check M2S intents installed" )
28 wait = int( main.params['timers']['PathAvailable'] )
29 main.log.info( "Intent number expected:" )
30 main.log.info( intentNumExpected )
31 main.log.info( "Intent number from ONOS CLI:" )
32 if ONOScli == "ONOScli1":
33 cli = main.ONOScli1
34 else:
35 cli = main.ONOScli2
36 jsonResult = cli.intents( jsonFormat = True, summary = True,
37 TYPE = "multiPointToSinglePoint" )
38 intentNumActual = jsonResult['installed']
39 if intentNumActual != intentNumExpected:
40 time.sleep( wait )
41 jsonResult = cli.intents( jsonFormat = True, summary = True,
42 TYPE = "multiPointToSinglePoint" )
43 intentNumActual = jsonResult['installed']
44 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
50def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
51 import time
52 main.step( "Check P2P intents installed" )
53 wait = int( main.params['timers']['PathAvailable'] )
54 main.log.info( "Intent number expected:" )
55 main.log.info( intentNumExpected )
56 main.log.info( "Intent number from ONOS CLI:" )
57 if ONOScli == "ONOScli1":
58 cli = main.ONOScli1
59 else:
60 cli = main.ONOScli2
61 jsonResult = cli.intents( jsonFormat = True, summary = True,
62 TYPE = "pointToPoint" )
63 intentNumActual = jsonResult['installed']
64
65 if intentNumActual != intentNumExpected:
66 time.sleep( wait )
67 jsonResult = cli.intents( jsonFormat = True, summary = True,
68 TYPE = "pointToPoint" )
69 intentNumActual = jsonResult['installed']
70 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 ):
77 import time
78 main.step( "Check flow entry number in " + switch )
79 wait = int( main.params['timers']['PathAvailable'] )
80 main.log.info( "Flow number expected:" )
81 main.log.info( flowNumExpected )
82 main.log.info( "Flow number actual:" )
83 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
84 if flowNumActual != flowNumExpected :
85 time.sleep( wait )
86 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
87 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 """
150 main.step( "Check ping between each host pair, expect all to succede=" +
151 str( expectAllSuccess ) )
152 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()