blob: 844a127ffeb00c3e283579697c179083baebf7ce [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created on 26-Oct-2012
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
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
21
22MininetCliDriver is the basic driver which will handle the Mininet functions
23'''
admin2a9548d2014-06-17 14:08:07 -070024import traceback
adminbae64d82013-08-01 10:50:15 -070025import pexpect
26import struct
27import fcntl
28import os
29import signal
30import re
31import sys
32import core.teston
33sys.path.append("../")
34from drivers.common.cli.emulatordriver import Emulator
35from drivers.common.clidriver import CLI
36
37class MininetCliDriver(Emulator):
38 '''
Jon Hall41f40e82014-04-08 16:43:17 -070039 MininetCliDriver is the basic driver which will handle the Mininet functions
adminbae64d82013-08-01 10:50:15 -070040 '''
41 def __init__(self):
42 super(Emulator, self).__init__()
43 self.handle = self
44 self.wrapped = sys.modules[__name__]
45 self.flag = 0
46
47 def connect(self, **connectargs):
Jon Hall41f40e82014-04-08 16:43:17 -070048 '''
49 Here the main is the TestON instance after creating all the log handles.
50 '''
adminbae64d82013-08-01 10:50:15 -070051 for key in connectargs:
52 vars(self)[key] = connectargs[key]
53
54 self.name = self.options['name']
55 self.handle = super(MininetCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
56
57 self.ssh_handle = self.handle
58
adminbae64d82013-08-01 10:50:15 -070059 if self.handle :
Jon Hallf2942ce2014-04-10 16:00:16 -070060 main.log.info(self.name+": Clearing any residual state or processes")
adminbae64d82013-08-01 10:50:15 -070061 self.handle.sendline("sudo mn -c")
adminf939f8b2014-04-03 17:22:56 -070062 i=self.handle.expect(['password\sfor\s','Cleanup\scomplete',pexpect.EOF,pexpect.TIMEOUT],120)
adminbae64d82013-08-01 10:50:15 -070063 if i==0:
Jon Hallf2942ce2014-04-10 16:00:16 -070064 main.log.info(self.name+": Sending sudo password")
adminf939f8b2014-04-03 17:22:56 -070065 self.handle.sendline(self.pwd)
66 i=self.handle.expect(['%s:'%(self.user),'\$',pexpect.EOF,pexpect.TIMEOUT],120)
adminbae64d82013-08-01 10:50:15 -070067 if i==1:
Jon Hallf2942ce2014-04-10 16:00:16 -070068 main.log.info(self.name+": Clean")
adminbae64d82013-08-01 10:50:15 -070069 elif i==2:
Jon Hallf2942ce2014-04-10 16:00:16 -070070 main.log.error(self.name+": Connection terminated")
adminbae64d82013-08-01 10:50:15 -070071 elif i==3: #timeout
Jon Hallf2942ce2014-04-10 16:00:16 -070072 main.log.error(self.name+": Something while cleaning MN took too long... " )
adminbae64d82013-08-01 10:50:15 -070073
Jon Hallf2942ce2014-04-10 16:00:16 -070074 main.log.info(self.name+": building fresh mininet")
adminbeea0032014-01-23 14:54:13 -080075 #### for reactive/PARP enabled tests
shahshreyaf4d4d0c2014-10-10 12:11:10 -070076 cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --controller " + self.options['controller'] + " " + self.options['arg3']
adminbeea0032014-01-23 14:54:13 -080077 #### for proactive flow with static ARP entries
shahshreyaf4d4d0c2014-10-10 12:11:10 -070078 #cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --mac --arp --controller " + self.options['controller'] + " " + self.options['arg3']
adminbae64d82013-08-01 10:50:15 -070079 self.handle.sendline(cmdString)
Jon Hall333fa8c2014-04-11 11:24:58 -070080 self.handle.expect(["sudo mn",pexpect.EOF,pexpect.TIMEOUT])
adminbae64d82013-08-01 10:50:15 -070081 while 1:
82 i=self.handle.expect(['mininet>','\*\*\*','Exception',pexpect.EOF,pexpect.TIMEOUT],300)
83 if i==0:
Jon Hallf2942ce2014-04-10 16:00:16 -070084 main.log.info(self.name+": mininet built")
adminbae64d82013-08-01 10:50:15 -070085 return main.TRUE
86 if i==1:
Jon Hall333fa8c2014-04-11 11:24:58 -070087 self.handle.expect(["\n",pexpect.EOF,pexpect.TIMEOUT])
adminbae64d82013-08-01 10:50:15 -070088 main.log.info(self.handle.before)
89 elif i==2:
Jon Hallf2942ce2014-04-10 16:00:16 -070090 main.log.error(self.name+": Launching mininet failed...")
adminbae64d82013-08-01 10:50:15 -070091 return main.FALSE
92 elif i==3:
Jon Hallf2942ce2014-04-10 16:00:16 -070093 main.log.error(self.name+": Connection timeout")
adminbae64d82013-08-01 10:50:15 -070094 return main.FALSE
95 elif i==4: #timeout
Jon Hallf2942ce2014-04-10 16:00:16 -070096 main.log.error(self.name+": Something took too long... " )
adminbae64d82013-08-01 10:50:15 -070097 return main.FALSE
adminbae64d82013-08-01 10:50:15 -070098 #if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "):
99 return main.TRUE
Jon Hallf2942ce2014-04-10 16:00:16 -0700100 else:#if no handle
101 main.log.error(self.name+": Connection failed to the host "+self.user_name+"@"+self.ip_address)
102 main.log.error(self.name+": Failed to connect to the Mininet")
adminbae64d82013-08-01 10:50:15 -0700103 return main.FALSE
104
105 def pingall(self):
106 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700107 Verifies the reachability of the hosts using pingall command.
adminbae64d82013-08-01 10:50:15 -0700108 '''
109 if self.handle :
Jon Hallf2942ce2014-04-10 16:00:16 -0700110 main.log.info(self.name+": Checking reachabilty to the hosts using pingall")
Jon Hall6094a362014-04-11 14:46:56 -0700111 try:
Jon Hallefa4fa12014-04-14 11:40:21 -0700112 response = self.execute(cmd="pingall",prompt="mininet>",timeout=120)
Jon Hall77f53ce2014-10-13 18:02:06 -0400113 print "response: " + str(response)
Jon Hall6094a362014-04-11 14:46:56 -0700114 except pexpect.EOF:
115 main.log.error(self.name + ": EOF exception found")
116 main.log.error(self.name + ": " + self.handle.before)
117 main.cleanup()
118 main.exit()
Jon Hallf4c8d012014-10-09 19:35:08 -0400119 pattern = 'Results\:\s0\%\sdropped\s'
andrew@onlab.us59e8f692014-10-09 21:41:48 -0400120 #FIXME:Pending Mininet Pull Request #408
Jon Hallf4c8d012014-10-09 19:35:08 -0400121 #pattern = 'Results\:\s0\.00\%\sdropped\s'
122 print response
Jon Hallf2942ce2014-04-10 16:00:16 -0700123 #if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"):
124 if re.search(pattern,response):
125 main.log.info(self.name+": All hosts are reachable")
adminbae64d82013-08-01 10:50:15 -0700126 return main.TRUE
127 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700128 main.log.error(self.name+": Unable to reach all the hosts")
adminbae64d82013-08-01 10:50:15 -0700129 return main.FALSE
130 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700131 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700132 return main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700133
134 def fpingHost(self,**pingParams):
135 '''
136 Uses the fping package for faster pinging...
137 *requires fping to be installed on machine running mininet
138 '''
139 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
admin530b4c92013-08-14 16:54:35 -0700140 command = args["SRC"] + " fping -i 100 -t 20 -C 1 -q "+args["TARGET"]
adminaeedddd2013-08-02 15:14:15 -0700141 self.handle.sendline(command)
Jon Hall333fa8c2014-04-11 11:24:58 -0700142 self.handle.expect([args["TARGET"],pexpect.EOF,pexpect.TIMEOUT])
143 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
adminaeedddd2013-08-02 15:14:15 -0700144 response = self.handle.before
145 if re.search(":\s-" ,response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700146 main.log.info(self.name+": Ping fail")
adminaeedddd2013-08-02 15:14:15 -0700147 return main.FALSE
admin530b4c92013-08-14 16:54:35 -0700148 elif re.search(":\s\d{1,2}\.\d\d", response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700149 main.log.info(self.name+": Ping good!")
adminaeedddd2013-08-02 15:14:15 -0700150 return main.TRUE
Jon Hallf2942ce2014-04-10 16:00:16 -0700151 main.log.info(self.name+": Install fping on mininet machine... ")
152 main.log.info(self.name+": \n---\n"+response)
adminaeedddd2013-08-02 15:14:15 -0700153 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700154
155 def pingHost(self,**pingParams):
Jon Hallf2942ce2014-04-10 16:00:16 -0700156 '''
157 Ping from one mininet host to another
158 Currently the only supported Params: SRC and TARGET
159 '''
adminbae64d82013-08-01 10:50:15 -0700160 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
161 #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"]
Jon Hall0819fd92014-05-23 12:08:13 -0700162 command = args["SRC"] + " ping "+args ["TARGET"]+" -c 1 -i 1 -W 8"
Jon Hall6094a362014-04-11 14:46:56 -0700163 try:
Jon Hall6e18c7b2014-04-23 16:26:33 -0700164 main.log.warn("Sending: " + command)
165 #response = self.execute(cmd=command,prompt="mininet",timeout=10 )
166 self.handle.sendline(command)
167 i = self.handle.expect([command,pexpect.TIMEOUT])
168 if i == 1:
169 main.log.error(self.name + ": timeout when waiting for response from mininet")
170 main.log.error("response: " + str(self.handle.before))
171 i = self.handle.expect(["mininet>",pexpect.TIMEOUT])
172 if i == 1:
173 main.log.error(self.name + ": timeout when waiting for response from mininet")
174 main.log.error("response: " + str(self.handle.before))
175 response = self.handle.before
Jon Hall6094a362014-04-11 14:46:56 -0700176 except pexpect.EOF:
177 main.log.error(self.name + ": EOF exception found")
178 main.log.error(self.name + ": " + self.handle.before)
179 main.cleanup()
180 main.exit()
Jon Hallf2942ce2014-04-10 16:00:16 -0700181 main.log.info(self.name+": Ping Response: "+ response )
182 #if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
183 if re.search(',\s0\%\spacket\sloss',response):
Jon Hall6e18c7b2014-04-23 16:26:33 -0700184 main.log.info(self.name+": no packets lost, host is reachable")
adminbae64d82013-08-01 10:50:15 -0700185 main.last_result = main.TRUE
186 return main.TRUE
187 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700188 main.log.error(self.name+": PACKET LOST, HOST IS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700189 main.last_result = main.FALSE
190 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700191
192 def checkIP(self,host):
193 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700194 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700195 '''
196 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700197 try:
198 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
199 except pexpect.EOF:
200 main.log.error(self.name + ": EOF exception found")
201 main.log.error(self.name + ": " + self.handle.before)
202 main.cleanup()
203 main.exit()
adminbae64d82013-08-01 10:50:15 -0700204
205 pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})"
admin2a9548d2014-06-17 14:08:07 -0700206 #pattern = "inet addr:10.0.0.6"
Jon Hallf2942ce2014-04-10 16:00:16 -0700207 #if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP not found") :
208 if re.search(pattern,response):
209 main.log.info(self.name+": Host Ip configured properly")
adminbae64d82013-08-01 10:50:15 -0700210 return main.TRUE
211 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700212 main.log.error(self.name+": Host IP not found")
adminbae64d82013-08-01 10:50:15 -0700213 return main.FALSE
214 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700215 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700216
217 def verifySSH(self,**connectargs):
Jon Hall6094a362014-04-11 14:46:56 -0700218 try:
219 response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
220 response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
221 for key in connectargs:
222 vars(self)[key] = connectargs[key]
223 response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10)
224 except pexpect.EOF:
225 main.log.error(self.name + ": EOF exception found")
226 main.log.error(self.name + ": " + self.handle.before)
227 main.cleanup()
228 main.exit()
adminbae64d82013-08-01 10:50:15 -0700229 import time
230 time.sleep(20)
231 if self.flag == 0:
232 self.flag = 1
233 return main.FALSE
234 else :
235 return main.TRUE
236
237 def getMacAddress(self,host):
238 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700239 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700240 '''
241 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700242 try:
243 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
244 except pexpect.EOF:
245 main.log.error(self.name + ": EOF exception found")
246 main.log.error(self.name + ": " + self.handle.before)
247 main.cleanup()
248 main.exit()
adminbae64d82013-08-01 10:50:15 -0700249
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700250 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
251 mac_address_search = re.search(pattern, response, re.I)
252 mac_address = mac_address_search.group().split(" ")[1]
Jon Hallf2942ce2014-04-10 16:00:16 -0700253 main.log.info(self.name+": Mac-Address of Host "+ host + " is " + mac_address)
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700254 return mac_address
adminbae64d82013-08-01 10:50:15 -0700255 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700256 main.log.error(self.name+": Connection failed to the host")
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700257
258 def getInterfaceMACAddress(self,host, interface):
259 '''
260 Return the IP address of the interface on the given host
261 '''
262 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700263 try:
264 response = self.execute(cmd=host+" ifconfig " + interface,
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700265 prompt="mininet>",timeout=10)
Jon Hall6094a362014-04-11 14:46:56 -0700266 except pexpect.EOF:
267 main.log.error(self.name + ": EOF exception found")
268 main.log.error(self.name + ": " + self.handle.before)
269 main.cleanup()
270 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700271
272 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
273 mac_address_search = re.search(pattern, response, re.I)
274 if mac_address_search is None:
275 main.log.info("No mac address found in %s" % response)
276 return main.FALSE
277 mac_address = mac_address_search.group().split(" ")[1]
278 main.log.info("Mac-Address of "+ host + ":"+ interface + " is " + mac_address)
279 return mac_address
280 else:
281 main.log.error("Connection failed to the host")
282
adminbae64d82013-08-01 10:50:15 -0700283 def getIPAddress(self,host):
284 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700285 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700286 '''
287 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700288 try:
289 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
290 except pexpect.EOF:
291 main.log.error(self.name + ": EOF exception found")
292 main.log.error(self.name + ": " + self.handle.before)
293 main.cleanup()
294 main.exit()
adminbae64d82013-08-01 10:50:15 -0700295
296 pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
297 ip_address_search = re.search(pattern, response)
Jon Hallf2942ce2014-04-10 16:00:16 -0700298 main.log.info(self.name+": IP-Address of Host "+host +" is "+ip_address_search.group(1))
adminbae64d82013-08-01 10:50:15 -0700299 return ip_address_search.group(1)
300 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700301 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700302
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700303 def getSwitchDPID(self,switch):
304 '''
305 return the datapath ID of the switch
306 '''
307 if self.handle :
308 cmd = "py %s.dpid" % switch
Jon Hall6094a362014-04-11 14:46:56 -0700309 try:
310 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
311 except pexpect.EOF:
312 main.log.error(self.name + ": EOF exception found")
313 main.log.error(self.name + ": " + self.handle.before)
314 main.cleanup()
315 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700316 pattern = r'^(?P<dpid>\d)+'
317 result = re.search(pattern, response, re.MULTILINE)
318 if result is None:
319 main.log.info("Couldn't find DPID for switch '', found: %s" % (switch, response))
320 return main.FALSE
Jon Hallc1a1d242014-07-21 16:03:33 -0700321 return str(result.group(0))
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700322 else:
323 main.log.error("Connection failed to the host")
324
admin2580a0e2014-07-29 11:24:34 -0700325 def getDPID(self, switch):
326 if self.handle:
327 self.handle.sendline("")
328 self.expect("mininet>")
329 cmd = "py %s.dpid" %switch
330 try:
331 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
332 self.handle.expect("mininet>")
333 response = self.handle.before
334 return response
335 except pexpect.EOF:
336 main.log.error(self.name + ": EOF exception found")
337 main.log.error(self.name + ": " + self.handle.before)
338 main.cleanup()
339 main.exit()
340
341
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700342 def getInterfaces(self, node):
343 '''
344 return information dict about interfaces connected to the node
345 '''
346 if self.handle :
347 cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,isUp=%s" % (i.name, i.MAC(), i.IP(), i.isUp())'
348 cmd += ' for i in %s.intfs.values()])' % node
Jon Hall6094a362014-04-11 14:46:56 -0700349 try:
350 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
351 except pexpect.EOF:
352 main.log.error(self.name + ": EOF exception found")
353 main.log.error(self.name + ": " + self.handle.before)
354 main.cleanup()
355 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700356 return response
357 else:
358 main.log.error("Connection failed to the node")
359
adminbae64d82013-08-01 10:50:15 -0700360 def dump(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700361 main.log.info(self.name+": Dump node info")
Jon Hall6094a362014-04-11 14:46:56 -0700362 try:
363 response = self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
364 except pexpect.EOF:
365 main.log.error(self.name + ": EOF exception found")
366 main.log.error(self.name + ": " + self.handle.before)
367 main.cleanup()
368 main.exit()
Ahmed El-Hassanyd1f71702014-04-04 16:12:45 -0700369 return response
adminbae64d82013-08-01 10:50:15 -0700370
371 def intfs(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700372 main.log.info(self.name+": List interfaces")
Jon Hall6094a362014-04-11 14:46:56 -0700373 try:
374 response = self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
375 except pexpect.EOF:
376 main.log.error(self.name + ": EOF exception found")
377 main.log.error(self.name + ": " + self.handle.before)
378 main.cleanup()
379 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700380 return response
adminbae64d82013-08-01 10:50:15 -0700381
382 def net(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700383 main.log.info(self.name+": List network connections")
Jon Hall6094a362014-04-11 14:46:56 -0700384 try:
385 response = self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
386 except pexpect.EOF:
387 main.log.error(self.name + ": EOF exception found")
388 main.log.error(self.name + ": " + self.handle.before)
389 main.cleanup()
390 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700391 return response
adminbae64d82013-08-01 10:50:15 -0700392
393 def iperf(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700394 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700395 try:
396 response = self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
397 except pexpect.EOF:
398 main.log.error(self.name + ": EOF exception found")
399 main.log.error(self.name + ": " + self.handle.before)
400 main.cleanup()
401 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700402 return response
adminbae64d82013-08-01 10:50:15 -0700403
404 def iperfudp(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700405 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700406 try:
407 response = self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
408 except pexpect.EOF:
409 main.log.error(self.name + ": EOF exception found")
410 main.log.error(self.name + ": " + self.handle.before)
411 main.cleanup()
412 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700413 return response
adminbae64d82013-08-01 10:50:15 -0700414
415 def nodes(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700416 main.log.info(self.name+": List all nodes.")
Jon Hall6094a362014-04-11 14:46:56 -0700417 try:
418 response = self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
419 except pexpect.EOF:
420 main.log.error(self.name + ": EOF exception found")
421 main.log.error(self.name + ": " + self.handle.before)
422 main.cleanup()
423 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700424 return response
adminbae64d82013-08-01 10:50:15 -0700425
426 def pingpair(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700427 main.log.info(self.name+": Ping between first two hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700428 try:
429 response = self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
430 except pexpect.EOF:
431 main.log.error(self.name + ": EOF exception found")
432 main.log.error(self.name + ": " + self.handle.before)
433 main.cleanup()
434 main.exit()
adminbae64d82013-08-01 10:50:15 -0700435
Jon Hallf2942ce2014-04-10 16:00:16 -0700436 #if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
437 if re.search(',\s0\%\spacket\sloss',response):
438 main.log.info(self.name+": Ping between two hosts SUCCESSFUL")
adminbae64d82013-08-01 10:50:15 -0700439 main.last_result = main.TRUE
440 return main.TRUE
441 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700442 main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700443 main.last_result = main.FALSE
444 return main.FALSE
445
446 def link(self,**linkargs):
447 '''
448 Bring link(s) between two nodes up or down
449 '''
450 main.log.info('Bring link(s) between two nodes up or down')
451 args = utilities.parse_args(["END1","END2","OPTION"],**linkargs)
452 end1 = args["END1"] if args["END1"] != None else ""
453 end2 = args["END2"] if args["END2"] != None else ""
454 option = args["OPTION"] if args["OPTION"] != None else ""
455 command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
Jon Hall6094a362014-04-11 14:46:56 -0700456 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700457 #response = self.execute(cmd=command,prompt="mininet>",timeout=10)
458 self.handle.sendline(command)
459 self.handle.expect("mininet>")
Jon Hall6094a362014-04-11 14:46:56 -0700460 except pexpect.EOF:
461 main.log.error(self.name + ": EOF exception found")
462 main.log.error(self.name + ": " + self.handle.before)
463 main.cleanup()
464 main.exit()
adminbae64d82013-08-01 10:50:15 -0700465 return main.TRUE
466
467
admin530b4c92013-08-14 16:54:35 -0700468 def yank(self,**yankargs):
adminaeedddd2013-08-02 15:14:15 -0700469 '''
admin530b4c92013-08-14 16:54:35 -0700470 yank a mininet switch interface to a host
adminaeedddd2013-08-02 15:14:15 -0700471 '''
admin530b4c92013-08-14 16:54:35 -0700472 main.log.info('Yank the switch interface attached to a host')
473 args = utilities.parse_args(["SW","INTF"],**yankargs)
adminaeedddd2013-08-02 15:14:15 -0700474 sw = args["SW"] if args["SW"] !=None else ""
475 intf = args["INTF"] if args["INTF"] != None else ""
476 command = "py "+ str(sw) + '.detach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700477 try:
478 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
479 except pexpect.EOF:
480 main.log.error(self.name + ": EOF exception found")
481 main.log.error(self.name + ": " + self.handle.before)
482 main.cleanup()
483 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700484 return main.TRUE
485
486 def plug(self, **plugargs):
487 '''
488 plug the yanked mininet switch interface to a switch
489 '''
490 main.log.info('Plug the switch interface attached to a switch')
admin530b4c92013-08-14 16:54:35 -0700491 args = utilities.parse_args(["SW","INTF"],**plugargs)
adminaeedddd2013-08-02 15:14:15 -0700492 sw = args["SW"] if args["SW"] !=None else ""
493 intf = args["INTF"] if args["INTF"] != None else ""
494 command = "py "+ str(sw) + '.attach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700495 try:
496 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
497 except pexpect.EOF:
498 main.log.error(self.name + ": EOF exception found")
499 main.log.error(self.name + ": " + self.handle.before)
500 main.cleanup()
501 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700502 return main.TRUE
503
504
505
adminbae64d82013-08-01 10:50:15 -0700506 def dpctl(self,**dpctlargs):
507 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700508 Run dpctl command on all switches.
adminbae64d82013-08-01 10:50:15 -0700509 '''
510 main.log.info('Run dpctl command on all switches')
511 args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
512 cmd = args["CMD"] if args["CMD"] != None else ""
513 cmdargs = args["ARGS"] if args["ARGS"] != None else ""
514 command = "dpctl "+cmd + " " + str(cmdargs)
Jon Hall6094a362014-04-11 14:46:56 -0700515 try:
516 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
517 except pexpect.EOF:
518 main.log.error(self.name + ": EOF exception found")
519 main.log.error(self.name + ": " + self.handle.before)
520 main.cleanup()
521 main.exit()
adminbae64d82013-08-01 10:50:15 -0700522 return main.TRUE
523
524
525 def get_version(self):
526 file_input = path+'/lib/Mininet/INSTALL'
527 version = super(Mininet, self).get_version()
528 pattern = 'Mininet\s\w\.\w\.\w\w*'
529 for line in open(file_input,'r').readlines():
530 result = re.match(pattern, line)
531 if result:
532 version = result.group(0)
533 return version
534
admin2a9548d2014-06-17 14:08:07 -0700535 def get_sw_controller_sanity(self, sw):
536 command = "sh ovs-vsctl get-controller "+str(sw)
537 try:
538 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
539 if response:
540 return main.TRUE
541 else:
542 return main.FALSE
543 except pexpect.EOF:
544 main.log.error(self.name + ": EOF exception found")
545 main.log.error(self.name + ": " + self.handle.before)
546 main.cleanup()
547 main.exit()
548 else:
549 main.log.info(response)
550
adminbae64d82013-08-01 10:50:15 -0700551 def get_sw_controller(self,sw):
552 command = "sh ovs-vsctl get-controller "+str(sw)
Jon Hall6094a362014-04-11 14:46:56 -0700553 try:
554 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
admin2a9548d2014-06-17 14:08:07 -0700555 print(response)
556 if response:
admindc1c5072014-06-24 15:57:19 -0700557 print("**********************")
admin2a9548d2014-06-17 14:08:07 -0700558 return response
559 else:
560 return main.FALSE
Jon Hall6094a362014-04-11 14:46:56 -0700561 except pexpect.EOF:
562 main.log.error(self.name + ": EOF exception found")
563 main.log.error(self.name + ": " + self.handle.before)
564 main.cleanup()
565 main.exit()
566 else:
567 main.log.info(response)
adminbae64d82013-08-01 10:50:15 -0700568
569 def assign_sw_controller(self,**kwargs):
Jon Hallf89c8552014-04-02 13:14:06 -0700570 '''
571 count is only needed if there is more than 1 controller
572 '''
573 args = utilities.parse_args(["COUNT"],**kwargs)
574 count = args["COUNT"] if args!={} else 1
575
576 argstring = "SW"
577 for j in range(count):
578 argstring = argstring + ",IP" + str(j+1) + ",PORT" + str(j+1)
579 args = utilities.parse_args(argstring.split(","),**kwargs)
580
adminbae64d82013-08-01 10:50:15 -0700581 sw = args["SW"] if args["SW"] != None else ""
admin530b4c92013-08-14 16:54:35 -0700582 ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else ""
Jon Hallf89c8552014-04-02 13:14:06 -0700583 ptcpB = "ptcp:"+str(ptcpA) if ptcpA != "" else ""
584
585 command = "sh ovs-vsctl set-controller s" + str(sw) + " " + ptcpB + " "
586 for j in range(count):
587 i=j+1
588 args = utilities.parse_args(["IP"+str(i),"PORT"+str(i)],**kwargs)
589 ip = args["IP"+str(i)] if args["IP"+str(i)] != None else ""
590 port = args["PORT" + str(i)] if args["PORT" + str(i)] != None else ""
591 tcp = "tcp:" + str(ip) + ":" + str(port) + " " if ip != "" else ""
592 command = command + tcp
Jon Hall6094a362014-04-11 14:46:56 -0700593 try:
594 self.execute(cmd=command,prompt="mininet>",timeout=5)
595 except pexpect.EOF:
596 main.log.error(self.name + ": EOF exception found")
597 main.log.error(self.name + ": " + self.handle.before)
598 main.cleanup()
599 main.exit()
600 except:
601 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
602 main.log.error( traceback.print_exc() )
603 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
604 main.cleanup()
605 main.exit()
adminbae64d82013-08-01 10:50:15 -0700606
Jon Hall0819fd92014-05-23 12:08:13 -0700607 def delete_sw_controller(self,sw):
608 '''
609 Removes the controller target from sw
610 '''
611
612 command = "sh ovs-vsctl del-controller "+str(sw)
613 try:
614 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
615 except pexpect.EOF:
616 main.log.error(self.name + ": EOF exception found")
617 main.log.error(self.name + ": " + self.handle.before)
618 main.cleanup()
619 main.exit()
620 else:
621 main.log.info(response)
622
623
adminbae64d82013-08-01 10:50:15 -0700624 def disconnect(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700625 main.log.info(self.name+": Disconnecting mininet...")
adminbae64d82013-08-01 10:50:15 -0700626 response = ''
627 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700628 try:
629 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
630 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
Jon Halle80ef8c2014-04-29 15:29:13 -0700631 self.handle.sendline("sudo mn -c")
Jon Hall6094a362014-04-11 14:46:56 -0700632 except pexpect.EOF:
633 main.log.error(self.name + ": EOF exception found")
634 main.log.error(self.name + ": " + self.handle.before)
635 main.cleanup()
636 main.exit()
adminbae64d82013-08-01 10:50:15 -0700637 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700638 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700639 response = main.FALSE
640 return response
admin07529932013-11-22 14:58:28 -0800641
642 def arping(self, src, dest, destmac):
643 self.handle.sendline('')
Jon Hall333fa8c2014-04-11 11:24:58 -0700644 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800645
646 self.handle.sendline(src + ' arping ' + dest)
647 try:
Jon Hall333fa8c2014-04-11 11:24:58 -0700648 self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT])
Jon Hallf2942ce2014-04-10 16:00:16 -0700649 main.log.info(self.name+": ARP successful")
Jon Hall333fa8c2014-04-11 11:24:58 -0700650 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800651 return main.TRUE
652 except:
Jon Hallf2942ce2014-04-10 16:00:16 -0700653 main.log.warn(self.name+": ARP FAILURE")
Jon Hall333fa8c2014-04-11 11:24:58 -0700654 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800655 return main.FALSE
656
657 def decToHex(num):
658 return hex(num).split('x')[1]
admin2a9548d2014-06-17 14:08:07 -0700659
660 def getSwitchFlowCount(self, switch):
661 '''
662 return the Flow Count of the switch
663 '''
664 if self.handle:
665 cmd = "sh ovs-ofctl dump-aggregate %s" % switch
666 try:
667 response = self.execute(cmd=cmd, prompt="mininet>", timeout=10)
668 except pexpect.EOF:
669 main.log.error(self.name + ": EOF exception found")
670 main.log.error(self.name + " " + self.handle.before)
671 main.cleanup()
672 main.exit()
673 pattern = "flow_count=(\d+)"
674 result = re.search(pattern, response, re.MULTILINE)
675 if result is None:
676 print "no flow on switch print test"
677 main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response))
678 return main.FALSE
679 return result.group(1)
680 else:
681 main.log.error("Connection failed to the Mininet host")
682
Ahmed El-Hassanyb6545eb2014-08-01 11:32:10 -0700683 def check_flows(self, sw, dump_format=None):
684 if dump_format:
685 command = "sh ovs-ofctl -F " + dump_format + " dump-flows " + str(sw)
686 else:
687 command = "sh ovs-ofctl dump-flows "+str(sw)
admin2a9548d2014-06-17 14:08:07 -0700688 try:
689 response=self.execute(cmd=command,prompt="mininet>",timeout=10)
690 return response
691 except pexpect.EOF:
692 main.log.error(self.name + ": EOF exception found")
693 main.log.error(self.name + ": " + self.handle.before)
694 main.cleanup()
695 main.exit()
696 else:
697 main.log.info(response)
698
699 def start_tcpdump(self, filename, intf = "eth0", port = "port 6633"):
700 '''
701 Runs tpdump on an intferface and saves the file
702 intf can be specified, or the default eth0 is used
703 '''
704 try:
705 self.handle.sendline("")
706 self.handle.expect("mininet>")
707 self.handle.sendline("sh sudo tcpdump -n -i "+ intf + " " + port + " -w " + filename.strip() + " &")
708 self.handle.sendline("")
709 self.handle.sendline("")
710 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT,"mininet>"],timeout=10)
711 main.log.warn(self.handle.before + self.handle.after)
712 if i == 0:
713 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
714 return main.FALSE
715 elif i == 1:
716 main.log.info(self.name + ": tcpdump started on " + intf)
717 return main.TRUE
718 elif i == 2:
719 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
720 return main.FALSE
721 elif i ==3:
722 main.log.info(self.name +": " + self.handle.before)
723 return main.TRUE
724 else:
725 main.log.error(self.name + ": tcpdump - unexpected response")
726 return main.FALSE
727 except pexpect.EOF:
728 main.log.error(self.name + ": EOF exception found")
729 main.log.error(self.name + ": " + self.handle.before)
730 main.cleanup()
731 main.exit()
732 except:
733 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
734 main.log.error( traceback.print_exc() )
735 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
736 main.cleanup()
737 main.exit()
738
739 def stop_tcpdump(self):
740 "pkills tcpdump"
741 try:
742 self.handle.sendline("sh sudo pkill tcpdump")
743 self.handle.sendline("")
744 self.handle.sendline("")
745 self.handle.expect("mininet>")
746 except pexpect.EOF:
747 main.log.error(self.name + ": EOF exception found")
748 main.log.error(self.name + ": " + self.handle.before)
749 main.cleanup()
750 main.exit()
751 except:
752 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
753 main.log.error( traceback.print_exc() )
754 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
755 main.cleanup()
756 main.exit()
757
Jon Hall7c3d1092014-08-11 15:08:31 -0700758 def compare_topo(self, topo, onos_json):
Jon Hall8412ed12014-07-24 16:33:58 -0700759 '''
760 compares mn topology with ONOS topology
761 onos_list is a list of ONOS controllers, each element of the list should be (handle, name, ip, port)
762 onos_json is the output of the onos get_json function calling the /wm/onos/topology REST API
Jon Halle3a74502014-07-25 11:13:16 -0700763 Returns: True if MN and ONOS topology match and False if the differ.
764 Differences between ONOS and MN topology will be printed to the log.
765
766 Dependency: Requires STS to be installed on the TestON machine. STS can be pulled
767 from https://github.com/ucb-sts/sts.git . Currently the required functions from STS are located in the
768 topology_refactoring2 branch, but may be merged into the master branch soon. You may need to install some
769 python modules such as networkx to use the STS functions.
770
Jon Hall38f50122014-08-05 13:16:52 -0700771 To install sts:
772 $ git clone git://github.com/ucb-sts/sts.git
773 $ cd sts
774 $ git clone -b debugger git://github.com/ucb-sts/pox.git
775 $ sudo apt-get install python-dev
776 $ ./tools/install_hassel_python.sh
777 $ sudo pip install networkx
778
779 Include sts in your PYTHONPATH. it should looks comething like:
780 PYTHONPATH=/home/admin/TestON:/home/admin/sts
781
Jon Hall8412ed12014-07-24 16:33:58 -0700782 '''
admin680b78c2014-08-08 11:46:45 -0700783 import sys
784 sys.path.append("~/sts")
Jon Halle9341332014-08-07 10:09:36 -0700785 #NOTE: Create this once per Test and pass the TestONTopology object around. It takes too long to create this object.
786 # This will make it easier to use the sts methods for severing links and solve that issue
Jon Hall0d88a252014-07-25 11:22:40 -0700787 import json
admin2a9548d2014-06-17 14:08:07 -0700788
Jon Hall8412ed12014-07-24 16:33:58 -0700789 link_results = main.TRUE
790 switch_results = main.TRUE
791 port_results = main.TRUE
792
793 ########Switches#######
794 output = {"switches":[]}
Jon Hall0d88a252014-07-25 11:22:40 -0700795 for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
Jon Hall8412ed12014-07-24 16:33:58 -0700796 ports = []
797 for port in switch.ports.values():
Jon Hall38f50122014-08-05 13:16:52 -0700798 #print port.hw_addr.toStr(separator = '')
799 ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
800 output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
Jon Hall8412ed12014-07-24 16:33:58 -0700801 #print output
802
Jon Hall8412ed12014-07-24 16:33:58 -0700803 #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
804
805
Jon Hall0d88a252014-07-25 11:22:40 -0700806 # created sorted list of dpid's in MN and ONOS for comparison
Jon Hall8412ed12014-07-24 16:33:58 -0700807 mnDPIDs=[]
808 for switch in output['switches']:
809 mnDPIDs.append(switch['dpid'])
810 mnDPIDs.sort()
Jon Halle9341332014-08-07 10:09:36 -0700811 #print mnDPIDs
Jon Hall0d88a252014-07-25 11:22:40 -0700812 if onos_json == "":#if rest call fails
Jon Hall8412ed12014-07-24 16:33:58 -0700813 main.log.error(self.name + ".compare_topo(): Empty JSON object given from ONOS rest call")
814 return main.FALSE
815 onos=onos_json
816 onosDPIDs=[]
817 for switch in onos['switches']:
818 onosDPIDs.append(switch['dpid'].replace(":",''))
819 onosDPIDs.sort()
Jon Halle9341332014-08-07 10:09:36 -0700820 #print onosDPIDs
Jon Hall8412ed12014-07-24 16:33:58 -0700821
822 if mnDPIDs!=onosDPIDs:
823 switch_results = main.FALSE
824 main.log.report( "Switches in MN but not in ONOS:")
825 main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs]))
826 main.log.report( "Switches in ONOS but not in MN:")
827 main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs]))
828 else:#list of dpid's match in onos and mn
829 switch_results = main.TRUE
830
831 ################ports#############
832 for switch in output['switches']:
833 mn_ports = []
834 onos_ports = []
835 for port in switch['ports']:
836 mn_ports.append(port['of_port'])
837 for onos_switch in onos['switches']:
838 if onos_switch['dpid'].replace(':','') == switch['dpid']:
839 for port in onos_switch['ports']:
840 onos_ports.append(port['portNumber'])
841 mn_ports.sort()
842 onos_ports.sort()
shahshreyaf4d4d0c2014-10-10 12:11:10 -0700843 #print "mn_ports[] = ", mn_ports
844 #print "onos_ports90 = ", onos_ports
845
846 #if mn_ports == onos_ports:
847 #pass #don't set results to true here as this is just one of many checks and it might override a failure
848
849 #For OF1.3, the OFP_local port number is 0xfffffffe or 4294967294 instead of 0xfffe or 65534 in OF1.0, ONOS topology
850 #sees the correct port number, however MN topolofy as read from line 151 of https://github.com/ucb-sts/sts/blob/
851 #topology_refactoring2/sts/entities/teston_entities.py is 0xfffe which doesn't work correctly with OF1.3 switches.
852 #So a short term fix is to ignore the case when mn_port == 65534 and onos_port ==4294967294.
853 for mn_port,onos_port in zip(mn_ports,onos_ports):
854 if mn_port == onos_port or (mn_port == 65534 and onos_port ==4294967294):
855 continue
856 else:
857 port_results = main.FALSE
858 break
Jon Hall8412ed12014-07-24 16:33:58 -0700859 pass #don't set results to true here as this is just one of many checks and it might override a failure
shahshreyaf4d4d0c2014-10-10 12:11:10 -0700860 '''
Jon Hall8412ed12014-07-24 16:33:58 -0700861 else: #the ports of this switch don't match
862 port_results = main.FALSE
863 main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
864 main.log.report( str([port for port in mn_ports if port not in onos_ports]))
865 main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
866 main.log.report( str([port for port in onos_ports if port not in mn_ports]))
shahshreyaf4d4d0c2014-10-10 12:11:10 -0700867 '''
868 if port_results == main.FALSE:
869 main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
870 main.log.report( str([port for port in mn_ports if port not in onos_ports]))
871 main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
872 main.log.report( str([port for port in onos_ports if port not in mn_ports]))
Jon Hall8412ed12014-07-24 16:33:58 -0700873
874 #######Links########
Jon Hall0d88a252014-07-25 11:22:40 -0700875 # iterate through MN links and check if and ONOS link exists in both directions
Jon Halle9341332014-08-07 10:09:36 -0700876 # NOTE: Will currently only show mn links as down if they are cut through STS.
877 # We can either do everything through STS or wait for up_network_links
878 # and down_network_links to be fully implemented.
Jon Hall8412ed12014-07-24 16:33:58 -0700879 for link in topo.patch_panel.network_links:
880 #print "Link: %s" % link
881 #TODO: Find a more efficient search method
882 node1 = None
883 port1 = None
884 node2 = None
885 port2 = None
886 first_dir = main.FALSE
887 second_dir = main.FALSE
888 for switch in output['switches']:
889 if switch['name'] == link.node1.name:
890 node1 = switch['dpid']
891 for port in switch['ports']:
892 if str(port['name']) == str(link.port1):
893 port1 = port['of_port']
894 if node1 is not None and node2 is not None:
895 break
896 if switch['name'] == link.node2.name:
897 node2 = switch['dpid']
898 for port in switch['ports']:
899 if str(port['name']) == str(link.port2):
900 port2 = port['of_port']
901 if node1 is not None and node2 is not None:
902 break
903 # check onos link from node1 to node2
904 for onos_link in onos['links']:
905 if onos_link['src']['dpid'].replace(":",'') == node1 and onos_link['dst']['dpid'].replace(":",'') == node2:
906 if onos_link['src']['portNumber'] == port1 and onos_link['dst']['portNumber'] == port2:
907 first_dir = main.TRUE
908 else:
909 main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
910 #print node1, ' to ', node2
911 elif onos_link['src']['dpid'].replace(":",'') == node2 and onos_link['dst']['dpid'].replace(":",'') == node1:
912 if onos_link['src']['portNumber'] == port2 and onos_link['dst']['portNumber'] == port1:
913 second_dir = main.TRUE
914 else:
915 main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
916 #print node2, ' to ', node1
917 else:#this is not the link you're looking for
918 pass
919 if not first_dir:
920 main.log.report('ONOS has issues with the link from '+str(link.node1.name) +"(dpid: "+ str(node1)+"):"+str(link.port1)+"(portNumber: "+str(port1)+")"+ ' to ' + str(link.node2.name) +"(dpid: "+ str(node2)+"):"+str(link.port2)+"(portNumber: "+str(port2)+")")
921 if not second_dir:
922 main.log.report('ONOS has issues with the link from '+str(link.node2.name) +"(dpid: "+ str(node2)+"):"+str(link.port2)+"(portNumber: "+str(port2)+")"+ ' to ' + str(link.node1.name) +"(dpid: "+ str(node1)+"):"+str(link.port1)+"(portNumber: "+str(port1)+")")
923 link_results = link_results and first_dir and second_dir
924
925
926 results = switch_results and port_results and link_results
Jon Halle9341332014-08-07 10:09:36 -0700927# if not results: #To print out both topologies
928# main.log.error("Topology comparison failed, printing json objects, MN then ONOS")
929# main.log.error(str(json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))))
930# main.log.error('MN Links:')
931# for link in topo.patch_panel.network_links: main.log.error(str("\tLink: %s" % link))
932# main.log.error(str(json.dumps(onos, sort_keys=True,indent=4,separators=(',', ': '))))
Jon Hall8412ed12014-07-24 16:33:58 -0700933 return results
admin2a9548d2014-06-17 14:08:07 -0700934
935
936
937
adminbae64d82013-08-01 10:50:15 -0700938
939if __name__ != "__main__":
940 import sys
941 sys.modules[__name__] = MininetCliDriver()
admin2a9548d2014-06-17 14:08:07 -0700942