blob: 8d4007ae1e8440387c1b68d2072f24f840c65f11 [file] [log] [blame]
pingping-linea32cf82015-10-08 22:37:37 -07001
pingping-lina14c7c82015-10-09 15:44:36 -07002def checkRouteNum( main, routeNumExpected, ONOScli = "ONOScli1" ):
pingping-linea32cf82015-10-08 22:37:37 -07003 main.step( "Check routes installed" )
4 main.log.info( "Route number expected:" )
5 main.log.info( routeNumExpected )
6 main.log.info( "Route number from ONOS CLI:" )
7
pingping-lin3f932a72015-10-09 16:44:50 -07008 if ONOScli == "ONOScli1":
pingping-lina14c7c82015-10-09 15:44:36 -07009 routeNumActual = main.ONOScli1.ipv4RouteNumber()
10 else:
11 routeNumActual = main.ONOScli2.ipv4RouteNumber()
12
pingping-linea32cf82015-10-08 22:37:37 -070013 main.log.info( routeNumActual )
14 utilities.assertEquals( \
15 expect = routeNumExpected, actual = routeNumActual,
16 onpass = "Route number is correct!",
17 onfail = "Route number is wrong!" )
18
pingping-lina14c7c82015-10-09 15:44:36 -070019def checkM2SintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
pingping-linea32cf82015-10-08 22:37:37 -070020 main.step( "Check M2S intents installed" )
21 main.log.info( "Intent number expected:" )
22 main.log.info( intentNumExpected )
23 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070024 if ONOScli == "ONOScli1":
25 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
26 TYPE = "multiPointToSinglePoint" )
27 else:
28 jsonResult = main.ONOScli2.intents( jsonFormat = True, summary = True,
29 TYPE = "multiPointToSinglePoint" )
pingping-linea32cf82015-10-08 22:37:37 -070030 intentNumActual = jsonResult['installed']
31 main.log.info( intentNumActual )
32 utilities.assertEquals( \
33 expect = intentNumExpected, actual = intentNumActual,
34 onpass = "M2S intent number is correct!",
35 onfail = "M2S intent number is wrong!" )
36
pingping-lina14c7c82015-10-09 15:44:36 -070037def checkP2PintentNum( main, intentNumExpected, ONOScli = "ONOScli1" ):
pingping-linea32cf82015-10-08 22:37:37 -070038 main.step( "Check P2P intents installed" )
39 main.log.info( "Intent number expected:" )
40 main.log.info( intentNumExpected )
41 main.log.info( "Intent number from ONOS CLI:" )
pingping-lina14c7c82015-10-09 15:44:36 -070042 if ONOScli == "ONOScli1":
43 jsonResult = main.ONOScli1.intents( jsonFormat = True, summary = True,
44 TYPE = "pointToPoint" )
45 else:
46 jsonResult = main.ONOScli2.intents( jsonFormat = True, summary = True,
47 TYPE = "pointToPoint" )
pingping-linea32cf82015-10-08 22:37:37 -070048 intentNumActual = jsonResult['installed']
49 main.log.info( intentNumActual )
50 utilities.assertEquals( \
51 expect = intentNumExpected, actual = intentNumActual,
52 onpass = "P2P intent number is correct!",
53 onfail = "P2P intent number is wrong!" )
54
55def checkFlowNum( main, switch, flowNumExpected ):
56 main.step( "Check flow entry number in " + switch )
57 main.log.info( "Flow number expected:" )
58 main.log.info( flowNumExpected )
59 main.log.info( "Flow number actual:" )
60 flowNumActual = main.Mininet.getSwitchFlowCount( switch )
61 main.log.info( flowNumActual )
62 utilities.assertEquals( \
63 expect = flowNumExpected, actual = flowNumActual,
64 onpass = "Flow number in " + switch + " is correct!",
65 onfail = "Flow number in " + switch + " is wrong!" )
66
67
68def pingSpeakerToPeer( main, speakers = ["speaker1"],
69 peers = ["peer64514", "peer64515", "peer64516"],
70 expectAllSuccess = True ):
71 """
72 Carry out ping test between each BGP speaker and peer pair
73 Optional argument:
74 * speakers - BGP speakers
75 * peers - BGP peers
76 * expectAllSuccess - boolean indicating if you expect all results
77 succeed if True, otherwise expect all results fail if False
78 """
79 if len( speakers ) == 0:
80 main.log.error( "Parameter speakers can not be empty." )
81 main.cleanup()
82 main.exit()
83 if len( peers ) == 0:
84 main.log.error( "Parameter speakers can not be empty." )
85 main.cleanup()
86 main.exit()
87
88 if expectAllSuccess:
89 main.step( "BGP speakers ping peers, expect all tests to succeed" )
90 else:
91 main.step( "BGP speakers ping peers, expect all tests to fail" )
92
93 result = True
94 if expectAllSuccess:
95 for speaker in speakers:
96 for peer in peers:
97 tmpResult = main.Mininet.pingHost( src = speaker,
98 target = peer )
99 result = result and ( tmpResult == main.TRUE )
100 else:
101 for speaker in speakers:
102 for peer in peers:
103 tmpResult = main.Mininet.pingHost( src = speaker,
104 target = peer )
105
106 utilities.assert_equals( expect = True, actual = result,
107 onpass = "Ping test results are expected",
108 onfail = "Ping test results are Not expected" )
109
110 if result == False:
111 main.cleanup()
112 main.exit()
113
114
115def pingHostToHost( main, hosts = ["host64514", "host64515", "host64516"],
116 expectAllSuccess = True ):
117 """
118 Carry out ping test between each BGP host pair
119 Optional argument:
120 * hosts - hosts behind BGP peer routers
121 * expectAllSuccess - boolean indicating if you expect all results
122 succeed if True, otherwise expect all results fail if False
123 """
124 main.step( "Check ping between each host pair" )
125 if len( hosts ) == 0:
126 main.log.error( "Parameter hosts can not be empty." )
127 main.cleanup()
128 main.exit()
129
130 result = True
131 if expectAllSuccess:
132 for srcHost in hosts:
133 for targetHost in hosts:
134 if srcHost != targetHost:
135 tmpResult = main.Mininet.pingHost( src = srcHost,
136 target = targetHost )
137 result = result and ( tmpResult == main.TRUE )
138 else:
139 for srcHost in hosts:
140 for targetHost in hosts:
141 if srcHost != targetHost:
142 tmpResult = main.Mininet.pingHost( src = srcHost,
143 target = targetHost )
144 result = result and ( tmpResult == main.FALSE )
145
146 utilities.assert_equals( expect = True, actual = result,
147 onpass = "Ping test results are expected",
148 onfail = "Ping test results are Not expected" )
149
150 '''
151 if result == False:
152 main.cleanup()
153 main.exit()
154 '''
155
156
157def setupTunnel( main, srcIp, srcPort, dstIp, dstPort ):
158 """
159 Create a tunnel from Mininet host to host outside Mininet
160 """
161 main.step( "Set up tunnel from Mininet node " +
162 str( srcIp ) + ":" + str( srcPort ) + " to ONOS node "
163 + str(dstIp) + ":" + str(dstPort) )
164 forwarding = '%s:%s:%s:%s' % ( srcIp, srcPort, dstIp, dstPort )
165 command = 'ssh -nNT -o "PasswordAuthentication no" \
166 -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding, dstIp )
167
168
169 tunnelResult = main.TRUE
170 tunnelResult = main.Mininet.node( "root", command )
171 utilities.assert_equals( expect = True,
172 actual = ( "PasswordAuthentication" in tunnelResult ),
173 onpass = "Created tunnel succeeded",
174 onfail = "Create tunnel failed" )
175 if ( "PasswordAuthentication" not in tunnelResult ) :
176 main.cleanup()
177 main.exit()
178