blob: b7e36946787fbfd98639363835af38dcf472cf5d [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 Hall6094a362014-04-11 14:46:56 -0700113 except pexpect.EOF:
114 main.log.error(self.name + ": EOF exception found")
115 main.log.error(self.name + ": " + self.handle.before)
116 main.cleanup()
117 main.exit()
Jon Hallf4c8d012014-10-09 19:35:08 -0400118 pattern = 'Results\:\s0\%\sdropped\s'
andrew@onlab.us59e8f692014-10-09 21:41:48 -0400119 #FIXME:Pending Mininet Pull Request #408
Jon Hallf4c8d012014-10-09 19:35:08 -0400120 #pattern = 'Results\:\s0\.00\%\sdropped\s'
121 print response
Jon Hallf2942ce2014-04-10 16:00:16 -0700122 #if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"):
123 if re.search(pattern,response):
124 main.log.info(self.name+": All hosts are reachable")
adminbae64d82013-08-01 10:50:15 -0700125 return main.TRUE
126 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700127 main.log.error(self.name+": Unable to reach all the hosts")
adminbae64d82013-08-01 10:50:15 -0700128 return main.FALSE
129 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700130 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700131 return main.FALSE
adminaeedddd2013-08-02 15:14:15 -0700132
133 def fpingHost(self,**pingParams):
134 '''
135 Uses the fping package for faster pinging...
136 *requires fping to be installed on machine running mininet
137 '''
138 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
admin530b4c92013-08-14 16:54:35 -0700139 command = args["SRC"] + " fping -i 100 -t 20 -C 1 -q "+args["TARGET"]
adminaeedddd2013-08-02 15:14:15 -0700140 self.handle.sendline(command)
Jon Hall333fa8c2014-04-11 11:24:58 -0700141 self.handle.expect([args["TARGET"],pexpect.EOF,pexpect.TIMEOUT])
142 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
adminaeedddd2013-08-02 15:14:15 -0700143 response = self.handle.before
144 if re.search(":\s-" ,response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700145 main.log.info(self.name+": Ping fail")
adminaeedddd2013-08-02 15:14:15 -0700146 return main.FALSE
admin530b4c92013-08-14 16:54:35 -0700147 elif re.search(":\s\d{1,2}\.\d\d", response):
Jon Hallf2942ce2014-04-10 16:00:16 -0700148 main.log.info(self.name+": Ping good!")
adminaeedddd2013-08-02 15:14:15 -0700149 return main.TRUE
Jon Hallf2942ce2014-04-10 16:00:16 -0700150 main.log.info(self.name+": Install fping on mininet machine... ")
151 main.log.info(self.name+": \n---\n"+response)
adminaeedddd2013-08-02 15:14:15 -0700152 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700153
154 def pingHost(self,**pingParams):
Jon Hallf2942ce2014-04-10 16:00:16 -0700155 '''
156 Ping from one mininet host to another
157 Currently the only supported Params: SRC and TARGET
158 '''
adminbae64d82013-08-01 10:50:15 -0700159 args = utilities.parse_args(["SRC","TARGET"],**pingParams)
160 #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"]
Jon Hall0819fd92014-05-23 12:08:13 -0700161 command = args["SRC"] + " ping "+args ["TARGET"]+" -c 1 -i 1 -W 8"
Jon Hall6094a362014-04-11 14:46:56 -0700162 try:
Jon Hall6e18c7b2014-04-23 16:26:33 -0700163 main.log.warn("Sending: " + command)
164 #response = self.execute(cmd=command,prompt="mininet",timeout=10 )
165 self.handle.sendline(command)
166 i = self.handle.expect([command,pexpect.TIMEOUT])
167 if i == 1:
168 main.log.error(self.name + ": timeout when waiting for response from mininet")
169 main.log.error("response: " + str(self.handle.before))
170 i = self.handle.expect(["mininet>",pexpect.TIMEOUT])
171 if i == 1:
172 main.log.error(self.name + ": timeout when waiting for response from mininet")
173 main.log.error("response: " + str(self.handle.before))
174 response = self.handle.before
Jon Hall6094a362014-04-11 14:46:56 -0700175 except pexpect.EOF:
176 main.log.error(self.name + ": EOF exception found")
177 main.log.error(self.name + ": " + self.handle.before)
178 main.cleanup()
179 main.exit()
Jon Hallf2942ce2014-04-10 16:00:16 -0700180 main.log.info(self.name+": Ping Response: "+ response )
181 #if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
182 if re.search(',\s0\%\spacket\sloss',response):
Jon Hall6e18c7b2014-04-23 16:26:33 -0700183 main.log.info(self.name+": no packets lost, host is reachable")
adminbae64d82013-08-01 10:50:15 -0700184 main.last_result = main.TRUE
185 return main.TRUE
186 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700187 main.log.error(self.name+": PACKET LOST, HOST IS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700188 main.last_result = main.FALSE
189 return main.FALSE
adminbae64d82013-08-01 10:50:15 -0700190
191 def checkIP(self,host):
192 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700193 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700194 '''
195 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700196 try:
197 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
198 except pexpect.EOF:
199 main.log.error(self.name + ": EOF exception found")
200 main.log.error(self.name + ": " + self.handle.before)
201 main.cleanup()
202 main.exit()
adminbae64d82013-08-01 10:50:15 -0700203
204 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 -0700205 #pattern = "inet addr:10.0.0.6"
Jon Hallf2942ce2014-04-10 16:00:16 -0700206 #if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP not found") :
207 if re.search(pattern,response):
208 main.log.info(self.name+": Host Ip configured properly")
adminbae64d82013-08-01 10:50:15 -0700209 return main.TRUE
210 else:
Jon Hallf2942ce2014-04-10 16:00:16 -0700211 main.log.error(self.name+": Host IP not found")
adminbae64d82013-08-01 10:50:15 -0700212 return main.FALSE
213 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700214 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700215
216 def verifySSH(self,**connectargs):
Jon Hall6094a362014-04-11 14:46:56 -0700217 try:
218 response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
219 response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
220 for key in connectargs:
221 vars(self)[key] = connectargs[key]
222 response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10)
223 except pexpect.EOF:
224 main.log.error(self.name + ": EOF exception found")
225 main.log.error(self.name + ": " + self.handle.before)
226 main.cleanup()
227 main.exit()
adminbae64d82013-08-01 10:50:15 -0700228 import time
229 time.sleep(20)
230 if self.flag == 0:
231 self.flag = 1
232 return main.FALSE
233 else :
234 return main.TRUE
235
236 def getMacAddress(self,host):
237 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700238 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700239 '''
240 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700241 try:
242 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
243 except pexpect.EOF:
244 main.log.error(self.name + ": EOF exception found")
245 main.log.error(self.name + ": " + self.handle.before)
246 main.cleanup()
247 main.exit()
adminbae64d82013-08-01 10:50:15 -0700248
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700249 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
250 mac_address_search = re.search(pattern, response, re.I)
251 mac_address = mac_address_search.group().split(" ")[1]
Jon Hallf2942ce2014-04-10 16:00:16 -0700252 main.log.info(self.name+": Mac-Address of Host "+ host + " is " + mac_address)
Ahmed El-Hassanyf720e202014-04-04 16:11:36 -0700253 return mac_address
adminbae64d82013-08-01 10:50:15 -0700254 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700255 main.log.error(self.name+": Connection failed to the host")
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700256
257 def getInterfaceMACAddress(self,host, interface):
258 '''
259 Return the IP address of the interface on the given host
260 '''
261 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700262 try:
263 response = self.execute(cmd=host+" ifconfig " + interface,
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700264 prompt="mininet>",timeout=10)
Jon Hall6094a362014-04-11 14:46:56 -0700265 except pexpect.EOF:
266 main.log.error(self.name + ": EOF exception found")
267 main.log.error(self.name + ": " + self.handle.before)
268 main.cleanup()
269 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700270
271 pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
272 mac_address_search = re.search(pattern, response, re.I)
273 if mac_address_search is None:
274 main.log.info("No mac address found in %s" % response)
275 return main.FALSE
276 mac_address = mac_address_search.group().split(" ")[1]
277 main.log.info("Mac-Address of "+ host + ":"+ interface + " is " + mac_address)
278 return mac_address
279 else:
280 main.log.error("Connection failed to the host")
281
adminbae64d82013-08-01 10:50:15 -0700282 def getIPAddress(self,host):
283 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700284 Verifies the host's ip configured or not.
adminbae64d82013-08-01 10:50:15 -0700285 '''
286 if self.handle :
Jon Hall6094a362014-04-11 14:46:56 -0700287 try:
288 response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
289 except pexpect.EOF:
290 main.log.error(self.name + ": EOF exception found")
291 main.log.error(self.name + ": " + self.handle.before)
292 main.cleanup()
293 main.exit()
adminbae64d82013-08-01 10:50:15 -0700294
295 pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
296 ip_address_search = re.search(pattern, response)
Jon Hallf2942ce2014-04-10 16:00:16 -0700297 main.log.info(self.name+": IP-Address of Host "+host +" is "+ip_address_search.group(1))
adminbae64d82013-08-01 10:50:15 -0700298 return ip_address_search.group(1)
299 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700300 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700301
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700302 def getSwitchDPID(self,switch):
303 '''
304 return the datapath ID of the switch
305 '''
306 if self.handle :
307 cmd = "py %s.dpid" % switch
Jon Hall6094a362014-04-11 14:46:56 -0700308 try:
309 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
310 except pexpect.EOF:
311 main.log.error(self.name + ": EOF exception found")
312 main.log.error(self.name + ": " + self.handle.before)
313 main.cleanup()
314 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700315 pattern = r'^(?P<dpid>\d)+'
316 result = re.search(pattern, response, re.MULTILINE)
317 if result is None:
318 main.log.info("Couldn't find DPID for switch '', found: %s" % (switch, response))
319 return main.FALSE
Jon Hallc1a1d242014-07-21 16:03:33 -0700320 return str(result.group(0))
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700321 else:
322 main.log.error("Connection failed to the host")
323
admin2580a0e2014-07-29 11:24:34 -0700324 def getDPID(self, switch):
325 if self.handle:
326 self.handle.sendline("")
327 self.expect("mininet>")
328 cmd = "py %s.dpid" %switch
329 try:
330 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
331 self.handle.expect("mininet>")
332 response = self.handle.before
333 return response
334 except pexpect.EOF:
335 main.log.error(self.name + ": EOF exception found")
336 main.log.error(self.name + ": " + self.handle.before)
337 main.cleanup()
338 main.exit()
339
340
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700341 def getInterfaces(self, node):
342 '''
343 return information dict about interfaces connected to the node
344 '''
345 if self.handle :
346 cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,isUp=%s" % (i.name, i.MAC(), i.IP(), i.isUp())'
347 cmd += ' for i in %s.intfs.values()])' % node
Jon Hall6094a362014-04-11 14:46:56 -0700348 try:
349 response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
350 except pexpect.EOF:
351 main.log.error(self.name + ": EOF exception found")
352 main.log.error(self.name + ": " + self.handle.before)
353 main.cleanup()
354 main.exit()
Ahmed El-Hassanyfd329182014-04-10 11:38:16 -0700355 return response
356 else:
357 main.log.error("Connection failed to the node")
358
adminbae64d82013-08-01 10:50:15 -0700359 def dump(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700360 main.log.info(self.name+": Dump node info")
Jon Hall6094a362014-04-11 14:46:56 -0700361 try:
362 response = self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
363 except pexpect.EOF:
364 main.log.error(self.name + ": EOF exception found")
365 main.log.error(self.name + ": " + self.handle.before)
366 main.cleanup()
367 main.exit()
Ahmed El-Hassanyd1f71702014-04-04 16:12:45 -0700368 return response
adminbae64d82013-08-01 10:50:15 -0700369
370 def intfs(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700371 main.log.info(self.name+": List interfaces")
Jon Hall6094a362014-04-11 14:46:56 -0700372 try:
373 response = self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
374 except pexpect.EOF:
375 main.log.error(self.name + ": EOF exception found")
376 main.log.error(self.name + ": " + self.handle.before)
377 main.cleanup()
378 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700379 return response
adminbae64d82013-08-01 10:50:15 -0700380
381 def net(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700382 main.log.info(self.name+": List network connections")
Jon Hall6094a362014-04-11 14:46:56 -0700383 try:
384 response = self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
385 except pexpect.EOF:
386 main.log.error(self.name + ": EOF exception found")
387 main.log.error(self.name + ": " + self.handle.before)
388 main.cleanup()
389 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700390 return response
adminbae64d82013-08-01 10:50:15 -0700391
392 def iperf(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700393 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700394 try:
395 response = self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
396 except pexpect.EOF:
397 main.log.error(self.name + ": EOF exception found")
398 main.log.error(self.name + ": " + self.handle.before)
399 main.cleanup()
400 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700401 return response
adminbae64d82013-08-01 10:50:15 -0700402
403 def iperfudp(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700404 main.log.info(self.name+": Simple iperf TCP test between two (optionally specified) hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700405 try:
406 response = self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
407 except pexpect.EOF:
408 main.log.error(self.name + ": EOF exception found")
409 main.log.error(self.name + ": " + self.handle.before)
410 main.cleanup()
411 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700412 return response
adminbae64d82013-08-01 10:50:15 -0700413
414 def nodes(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700415 main.log.info(self.name+": List all nodes.")
Jon Hall6094a362014-04-11 14:46:56 -0700416 try:
417 response = self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
418 except pexpect.EOF:
419 main.log.error(self.name + ": EOF exception found")
420 main.log.error(self.name + ": " + self.handle.before)
421 main.cleanup()
422 main.exit()
Jon Hall668ed802014-04-08 17:17:59 -0700423 return response
adminbae64d82013-08-01 10:50:15 -0700424
425 def pingpair(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700426 main.log.info(self.name+": Ping between first two hosts")
Jon Hall6094a362014-04-11 14:46:56 -0700427 try:
428 response = self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
429 except pexpect.EOF:
430 main.log.error(self.name + ": EOF exception found")
431 main.log.error(self.name + ": " + self.handle.before)
432 main.cleanup()
433 main.exit()
adminbae64d82013-08-01 10:50:15 -0700434
Jon Hallf2942ce2014-04-10 16:00:16 -0700435 #if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
436 if re.search(',\s0\%\spacket\sloss',response):
437 main.log.info(self.name+": Ping between two hosts SUCCESSFUL")
adminbae64d82013-08-01 10:50:15 -0700438 main.last_result = main.TRUE
439 return main.TRUE
440 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700441 main.log.error(self.name+": PACKET LOST, HOSTS NOT REACHABLE")
adminbae64d82013-08-01 10:50:15 -0700442 main.last_result = main.FALSE
443 return main.FALSE
444
445 def link(self,**linkargs):
446 '''
447 Bring link(s) between two nodes up or down
448 '''
449 main.log.info('Bring link(s) between two nodes up or down')
450 args = utilities.parse_args(["END1","END2","OPTION"],**linkargs)
451 end1 = args["END1"] if args["END1"] != None else ""
452 end2 = args["END2"] if args["END2"] != None else ""
453 option = args["OPTION"] if args["OPTION"] != None else ""
454 command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
Jon Hall6094a362014-04-11 14:46:56 -0700455 try:
Jon Halle80ef8c2014-04-29 15:29:13 -0700456 #response = self.execute(cmd=command,prompt="mininet>",timeout=10)
457 self.handle.sendline(command)
458 self.handle.expect("mininet>")
Jon Hall6094a362014-04-11 14:46:56 -0700459 except pexpect.EOF:
460 main.log.error(self.name + ": EOF exception found")
461 main.log.error(self.name + ": " + self.handle.before)
462 main.cleanup()
463 main.exit()
adminbae64d82013-08-01 10:50:15 -0700464 return main.TRUE
465
466
admin530b4c92013-08-14 16:54:35 -0700467 def yank(self,**yankargs):
adminaeedddd2013-08-02 15:14:15 -0700468 '''
admin530b4c92013-08-14 16:54:35 -0700469 yank a mininet switch interface to a host
adminaeedddd2013-08-02 15:14:15 -0700470 '''
admin530b4c92013-08-14 16:54:35 -0700471 main.log.info('Yank the switch interface attached to a host')
472 args = utilities.parse_args(["SW","INTF"],**yankargs)
adminaeedddd2013-08-02 15:14:15 -0700473 sw = args["SW"] if args["SW"] !=None else ""
474 intf = args["INTF"] if args["INTF"] != None else ""
475 command = "py "+ str(sw) + '.detach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700476 try:
477 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
478 except pexpect.EOF:
479 main.log.error(self.name + ": EOF exception found")
480 main.log.error(self.name + ": " + self.handle.before)
481 main.cleanup()
482 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700483 return main.TRUE
484
485 def plug(self, **plugargs):
486 '''
487 plug the yanked mininet switch interface to a switch
488 '''
489 main.log.info('Plug the switch interface attached to a switch')
admin530b4c92013-08-14 16:54:35 -0700490 args = utilities.parse_args(["SW","INTF"],**plugargs)
adminaeedddd2013-08-02 15:14:15 -0700491 sw = args["SW"] if args["SW"] !=None else ""
492 intf = args["INTF"] if args["INTF"] != None else ""
493 command = "py "+ str(sw) + '.attach("' + str(intf) + '")'
Jon Hall6094a362014-04-11 14:46:56 -0700494 try:
495 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
496 except pexpect.EOF:
497 main.log.error(self.name + ": EOF exception found")
498 main.log.error(self.name + ": " + self.handle.before)
499 main.cleanup()
500 main.exit()
adminaeedddd2013-08-02 15:14:15 -0700501 return main.TRUE
502
503
504
adminbae64d82013-08-01 10:50:15 -0700505 def dpctl(self,**dpctlargs):
506 '''
Jon Hall41f40e82014-04-08 16:43:17 -0700507 Run dpctl command on all switches.
adminbae64d82013-08-01 10:50:15 -0700508 '''
509 main.log.info('Run dpctl command on all switches')
510 args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
511 cmd = args["CMD"] if args["CMD"] != None else ""
512 cmdargs = args["ARGS"] if args["ARGS"] != None else ""
513 command = "dpctl "+cmd + " " + str(cmdargs)
Jon Hall6094a362014-04-11 14:46:56 -0700514 try:
515 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
516 except pexpect.EOF:
517 main.log.error(self.name + ": EOF exception found")
518 main.log.error(self.name + ": " + self.handle.before)
519 main.cleanup()
520 main.exit()
adminbae64d82013-08-01 10:50:15 -0700521 return main.TRUE
522
523
524 def get_version(self):
525 file_input = path+'/lib/Mininet/INSTALL'
526 version = super(Mininet, self).get_version()
527 pattern = 'Mininet\s\w\.\w\.\w\w*'
528 for line in open(file_input,'r').readlines():
529 result = re.match(pattern, line)
530 if result:
531 version = result.group(0)
532 return version
533
admin2a9548d2014-06-17 14:08:07 -0700534 def get_sw_controller_sanity(self, sw):
535 command = "sh ovs-vsctl get-controller "+str(sw)
536 try:
537 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
538 if response:
539 return main.TRUE
540 else:
541 return main.FALSE
542 except pexpect.EOF:
543 main.log.error(self.name + ": EOF exception found")
544 main.log.error(self.name + ": " + self.handle.before)
545 main.cleanup()
546 main.exit()
547 else:
548 main.log.info(response)
549
adminbae64d82013-08-01 10:50:15 -0700550 def get_sw_controller(self,sw):
551 command = "sh ovs-vsctl get-controller "+str(sw)
Jon Hall6094a362014-04-11 14:46:56 -0700552 try:
553 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
admin2a9548d2014-06-17 14:08:07 -0700554 print(response)
555 if response:
admindc1c5072014-06-24 15:57:19 -0700556 print("**********************")
admin2a9548d2014-06-17 14:08:07 -0700557 return response
558 else:
559 return main.FALSE
Jon Hall6094a362014-04-11 14:46:56 -0700560 except pexpect.EOF:
561 main.log.error(self.name + ": EOF exception found")
562 main.log.error(self.name + ": " + self.handle.before)
563 main.cleanup()
564 main.exit()
565 else:
566 main.log.info(response)
adminbae64d82013-08-01 10:50:15 -0700567
568 def assign_sw_controller(self,**kwargs):
Jon Hallf89c8552014-04-02 13:14:06 -0700569 '''
570 count is only needed if there is more than 1 controller
571 '''
572 args = utilities.parse_args(["COUNT"],**kwargs)
573 count = args["COUNT"] if args!={} else 1
574
575 argstring = "SW"
576 for j in range(count):
577 argstring = argstring + ",IP" + str(j+1) + ",PORT" + str(j+1)
578 args = utilities.parse_args(argstring.split(","),**kwargs)
579
adminbae64d82013-08-01 10:50:15 -0700580 sw = args["SW"] if args["SW"] != None else ""
admin530b4c92013-08-14 16:54:35 -0700581 ptcpA = int(args["PORT1"])+int(sw) if args["PORT1"] != None else ""
Jon Hallf89c8552014-04-02 13:14:06 -0700582 ptcpB = "ptcp:"+str(ptcpA) if ptcpA != "" else ""
583
584 command = "sh ovs-vsctl set-controller s" + str(sw) + " " + ptcpB + " "
585 for j in range(count):
586 i=j+1
587 args = utilities.parse_args(["IP"+str(i),"PORT"+str(i)],**kwargs)
588 ip = args["IP"+str(i)] if args["IP"+str(i)] != None else ""
589 port = args["PORT" + str(i)] if args["PORT" + str(i)] != None else ""
590 tcp = "tcp:" + str(ip) + ":" + str(port) + " " if ip != "" else ""
591 command = command + tcp
Jon Hall6094a362014-04-11 14:46:56 -0700592 try:
593 self.execute(cmd=command,prompt="mininet>",timeout=5)
594 except pexpect.EOF:
595 main.log.error(self.name + ": EOF exception found")
596 main.log.error(self.name + ": " + self.handle.before)
597 main.cleanup()
598 main.exit()
599 except:
600 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
601 main.log.error( traceback.print_exc() )
602 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
603 main.cleanup()
604 main.exit()
adminbae64d82013-08-01 10:50:15 -0700605
Jon Hall0819fd92014-05-23 12:08:13 -0700606 def delete_sw_controller(self,sw):
607 '''
608 Removes the controller target from sw
609 '''
610
611 command = "sh ovs-vsctl del-controller "+str(sw)
612 try:
613 response = self.execute(cmd=command,prompt="mininet>",timeout=10)
614 except pexpect.EOF:
615 main.log.error(self.name + ": EOF exception found")
616 main.log.error(self.name + ": " + self.handle.before)
617 main.cleanup()
618 main.exit()
619 else:
620 main.log.info(response)
621
622
adminbae64d82013-08-01 10:50:15 -0700623 def disconnect(self):
Jon Hallf2942ce2014-04-10 16:00:16 -0700624 main.log.info(self.name+": Disconnecting mininet...")
adminbae64d82013-08-01 10:50:15 -0700625 response = ''
626 if self.handle:
Jon Hall6094a362014-04-11 14:46:56 -0700627 try:
628 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
629 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
Jon Halle80ef8c2014-04-29 15:29:13 -0700630 self.handle.sendline("sudo mn -c")
Jon Hall6094a362014-04-11 14:46:56 -0700631 except pexpect.EOF:
632 main.log.error(self.name + ": EOF exception found")
633 main.log.error(self.name + ": " + self.handle.before)
634 main.cleanup()
635 main.exit()
adminbae64d82013-08-01 10:50:15 -0700636 else :
Jon Hallf2942ce2014-04-10 16:00:16 -0700637 main.log.error(self.name+": Connection failed to the host")
adminbae64d82013-08-01 10:50:15 -0700638 response = main.FALSE
639 return response
admin07529932013-11-22 14:58:28 -0800640
641 def arping(self, src, dest, destmac):
642 self.handle.sendline('')
Jon Hall333fa8c2014-04-11 11:24:58 -0700643 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800644
645 self.handle.sendline(src + ' arping ' + dest)
646 try:
Jon Hall333fa8c2014-04-11 11:24:58 -0700647 self.handle.expect([destmac,pexpect.EOF,pexpect.TIMEOUT])
Jon Hallf2942ce2014-04-10 16:00:16 -0700648 main.log.info(self.name+": ARP successful")
Jon Hall333fa8c2014-04-11 11:24:58 -0700649 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800650 return main.TRUE
651 except:
Jon Hallf2942ce2014-04-10 16:00:16 -0700652 main.log.warn(self.name+": ARP FAILURE")
Jon Hall333fa8c2014-04-11 11:24:58 -0700653 self.handle.expect(["mininet",pexpect.EOF,pexpect.TIMEOUT])
admin07529932013-11-22 14:58:28 -0800654 return main.FALSE
655
656 def decToHex(num):
657 return hex(num).split('x')[1]
admin2a9548d2014-06-17 14:08:07 -0700658
659 def getSwitchFlowCount(self, switch):
660 '''
661 return the Flow Count of the switch
662 '''
663 if self.handle:
664 cmd = "sh ovs-ofctl dump-aggregate %s" % switch
665 try:
666 response = self.execute(cmd=cmd, prompt="mininet>", timeout=10)
667 except pexpect.EOF:
668 main.log.error(self.name + ": EOF exception found")
669 main.log.error(self.name + " " + self.handle.before)
670 main.cleanup()
671 main.exit()
672 pattern = "flow_count=(\d+)"
673 result = re.search(pattern, response, re.MULTILINE)
674 if result is None:
675 print "no flow on switch print test"
676 main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response))
677 return main.FALSE
678 return result.group(1)
679 else:
680 main.log.error("Connection failed to the Mininet host")
681
Ahmed El-Hassanyb6545eb2014-08-01 11:32:10 -0700682 def check_flows(self, sw, dump_format=None):
683 if dump_format:
684 command = "sh ovs-ofctl -F " + dump_format + " dump-flows " + str(sw)
685 else:
686 command = "sh ovs-ofctl dump-flows "+str(sw)
admin2a9548d2014-06-17 14:08:07 -0700687 try:
688 response=self.execute(cmd=command,prompt="mininet>",timeout=10)
689 return response
690 except pexpect.EOF:
691 main.log.error(self.name + ": EOF exception found")
692 main.log.error(self.name + ": " + self.handle.before)
693 main.cleanup()
694 main.exit()
695 else:
696 main.log.info(response)
697
698 def start_tcpdump(self, filename, intf = "eth0", port = "port 6633"):
699 '''
700 Runs tpdump on an intferface and saves the file
701 intf can be specified, or the default eth0 is used
702 '''
703 try:
704 self.handle.sendline("")
705 self.handle.expect("mininet>")
706 self.handle.sendline("sh sudo tcpdump -n -i "+ intf + " " + port + " -w " + filename.strip() + " &")
707 self.handle.sendline("")
708 self.handle.sendline("")
709 i=self.handle.expect(['No\ssuch\device','listening\son',pexpect.TIMEOUT,"mininet>"],timeout=10)
710 main.log.warn(self.handle.before + self.handle.after)
711 if i == 0:
712 main.log.error(self.name + ": tcpdump - No such device exists. tcpdump attempted on: " + intf)
713 return main.FALSE
714 elif i == 1:
715 main.log.info(self.name + ": tcpdump started on " + intf)
716 return main.TRUE
717 elif i == 2:
718 main.log.error(self.name + ": tcpdump command timed out! Check interface name, given interface was: " + intf)
719 return main.FALSE
720 elif i ==3:
721 main.log.info(self.name +": " + self.handle.before)
722 return main.TRUE
723 else:
724 main.log.error(self.name + ": tcpdump - unexpected response")
725 return main.FALSE
726 except pexpect.EOF:
727 main.log.error(self.name + ": EOF exception found")
728 main.log.error(self.name + ": " + self.handle.before)
729 main.cleanup()
730 main.exit()
731 except:
732 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
733 main.log.error( traceback.print_exc() )
734 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
735 main.cleanup()
736 main.exit()
737
738 def stop_tcpdump(self):
739 "pkills tcpdump"
740 try:
741 self.handle.sendline("sh sudo pkill tcpdump")
742 self.handle.sendline("")
743 self.handle.sendline("")
744 self.handle.expect("mininet>")
745 except pexpect.EOF:
746 main.log.error(self.name + ": EOF exception found")
747 main.log.error(self.name + ": " + self.handle.before)
748 main.cleanup()
749 main.exit()
750 except:
751 main.log.info(self.name + ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
752 main.log.error( traceback.print_exc() )
753 main.log.info(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
754 main.cleanup()
755 main.exit()
756
Jon Hall7c3d1092014-08-11 15:08:31 -0700757 def compare_topo(self, topo, onos_json):
Jon Hall8412ed12014-07-24 16:33:58 -0700758 '''
759 compares mn topology with ONOS topology
760 onos_list is a list of ONOS controllers, each element of the list should be (handle, name, ip, port)
761 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 -0700762 Returns: True if MN and ONOS topology match and False if the differ.
763 Differences between ONOS and MN topology will be printed to the log.
764
765 Dependency: Requires STS to be installed on the TestON machine. STS can be pulled
766 from https://github.com/ucb-sts/sts.git . Currently the required functions from STS are located in the
767 topology_refactoring2 branch, but may be merged into the master branch soon. You may need to install some
768 python modules such as networkx to use the STS functions.
769
Jon Hall38f50122014-08-05 13:16:52 -0700770 To install sts:
771 $ git clone git://github.com/ucb-sts/sts.git
772 $ cd sts
773 $ git clone -b debugger git://github.com/ucb-sts/pox.git
774 $ sudo apt-get install python-dev
775 $ ./tools/install_hassel_python.sh
776 $ sudo pip install networkx
777
778 Include sts in your PYTHONPATH. it should looks comething like:
779 PYTHONPATH=/home/admin/TestON:/home/admin/sts
780
Jon Hall8412ed12014-07-24 16:33:58 -0700781 '''
admin680b78c2014-08-08 11:46:45 -0700782 import sys
783 sys.path.append("~/sts")
Jon Halle9341332014-08-07 10:09:36 -0700784 #NOTE: Create this once per Test and pass the TestONTopology object around. It takes too long to create this object.
785 # This will make it easier to use the sts methods for severing links and solve that issue
Jon Hall0d88a252014-07-25 11:22:40 -0700786 import json
admin2a9548d2014-06-17 14:08:07 -0700787
Jon Hall8412ed12014-07-24 16:33:58 -0700788 link_results = main.TRUE
789 switch_results = main.TRUE
790 port_results = main.TRUE
791
792 ########Switches#######
793 output = {"switches":[]}
Jon Hall0d88a252014-07-25 11:22:40 -0700794 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 -0700795 ports = []
796 for port in switch.ports.values():
Jon Hall38f50122014-08-05 13:16:52 -0700797 #print port.hw_addr.toStr(separator = '')
798 ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
799 output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
Jon Hall8412ed12014-07-24 16:33:58 -0700800 #print output
801
Jon Hall8412ed12014-07-24 16:33:58 -0700802 #print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
803
804
Jon Hall0d88a252014-07-25 11:22:40 -0700805 # created sorted list of dpid's in MN and ONOS for comparison
Jon Hall8412ed12014-07-24 16:33:58 -0700806 mnDPIDs=[]
807 for switch in output['switches']:
808 mnDPIDs.append(switch['dpid'])
809 mnDPIDs.sort()
Jon Halle9341332014-08-07 10:09:36 -0700810 #print mnDPIDs
Jon Hall0d88a252014-07-25 11:22:40 -0700811 if onos_json == "":#if rest call fails
Jon Hall8412ed12014-07-24 16:33:58 -0700812 main.log.error(self.name + ".compare_topo(): Empty JSON object given from ONOS rest call")
813 return main.FALSE
814 onos=onos_json
815 onosDPIDs=[]
816 for switch in onos['switches']:
817 onosDPIDs.append(switch['dpid'].replace(":",''))
818 onosDPIDs.sort()
Jon Halle9341332014-08-07 10:09:36 -0700819 #print onosDPIDs
Jon Hall8412ed12014-07-24 16:33:58 -0700820
821 if mnDPIDs!=onosDPIDs:
822 switch_results = main.FALSE
823 main.log.report( "Switches in MN but not in ONOS:")
824 main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs]))
825 main.log.report( "Switches in ONOS but not in MN:")
826 main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs]))
827 else:#list of dpid's match in onos and mn
828 switch_results = main.TRUE
829
830 ################ports#############
831 for switch in output['switches']:
832 mn_ports = []
833 onos_ports = []
834 for port in switch['ports']:
835 mn_ports.append(port['of_port'])
836 for onos_switch in onos['switches']:
837 if onos_switch['dpid'].replace(':','') == switch['dpid']:
838 for port in onos_switch['ports']:
839 onos_ports.append(port['portNumber'])
840 mn_ports.sort()
841 onos_ports.sort()
shahshreyaf4d4d0c2014-10-10 12:11:10 -0700842 #print "mn_ports[] = ", mn_ports
843 #print "onos_ports90 = ", onos_ports
844
845 #if mn_ports == onos_ports:
846 #pass #don't set results to true here as this is just one of many checks and it might override a failure
847
848 #For OF1.3, the OFP_local port number is 0xfffffffe or 4294967294 instead of 0xfffe or 65534 in OF1.0, ONOS topology
849 #sees the correct port number, however MN topolofy as read from line 151 of https://github.com/ucb-sts/sts/blob/
850 #topology_refactoring2/sts/entities/teston_entities.py is 0xfffe which doesn't work correctly with OF1.3 switches.
851 #So a short term fix is to ignore the case when mn_port == 65534 and onos_port ==4294967294.
852 for mn_port,onos_port in zip(mn_ports,onos_ports):
853 if mn_port == onos_port or (mn_port == 65534 and onos_port ==4294967294):
854 continue
855 else:
856 port_results = main.FALSE
857 break
Jon Hall8412ed12014-07-24 16:33:58 -0700858 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 -0700859 '''
Jon Hall8412ed12014-07-24 16:33:58 -0700860 else: #the ports of this switch don't match
861 port_results = main.FALSE
862 main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
863 main.log.report( str([port for port in mn_ports if port not in onos_ports]))
864 main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
865 main.log.report( str([port for port in onos_ports if port not in mn_ports]))
shahshreyaf4d4d0c2014-10-10 12:11:10 -0700866 '''
867 if port_results == main.FALSE:
868 main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
869 main.log.report( str([port for port in mn_ports if port not in onos_ports]))
870 main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
871 main.log.report( str([port for port in onos_ports if port not in mn_ports]))
Jon Hall8412ed12014-07-24 16:33:58 -0700872
873 #######Links########
Jon Hall0d88a252014-07-25 11:22:40 -0700874 # iterate through MN links and check if and ONOS link exists in both directions
Jon Halle9341332014-08-07 10:09:36 -0700875 # NOTE: Will currently only show mn links as down if they are cut through STS.
876 # We can either do everything through STS or wait for up_network_links
877 # and down_network_links to be fully implemented.
Jon Hall8412ed12014-07-24 16:33:58 -0700878 for link in topo.patch_panel.network_links:
879 #print "Link: %s" % link
880 #TODO: Find a more efficient search method
881 node1 = None
882 port1 = None
883 node2 = None
884 port2 = None
885 first_dir = main.FALSE
886 second_dir = main.FALSE
887 for switch in output['switches']:
888 if switch['name'] == link.node1.name:
889 node1 = switch['dpid']
890 for port in switch['ports']:
891 if str(port['name']) == str(link.port1):
892 port1 = port['of_port']
893 if node1 is not None and node2 is not None:
894 break
895 if switch['name'] == link.node2.name:
896 node2 = switch['dpid']
897 for port in switch['ports']:
898 if str(port['name']) == str(link.port2):
899 port2 = port['of_port']
900 if node1 is not None and node2 is not None:
901 break
902 # check onos link from node1 to node2
903 for onos_link in onos['links']:
904 if onos_link['src']['dpid'].replace(":",'') == node1 and onos_link['dst']['dpid'].replace(":",'') == node2:
905 if onos_link['src']['portNumber'] == port1 and onos_link['dst']['portNumber'] == port2:
906 first_dir = main.TRUE
907 else:
908 main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
909 #print node1, ' to ', node2
910 elif onos_link['src']['dpid'].replace(":",'') == node2 and onos_link['dst']['dpid'].replace(":",'') == node1:
911 if onos_link['src']['portNumber'] == port2 and onos_link['dst']['portNumber'] == port1:
912 second_dir = main.TRUE
913 else:
914 main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
915 #print node2, ' to ', node1
916 else:#this is not the link you're looking for
917 pass
918 if not first_dir:
919 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)+")")
920 if not second_dir:
921 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)+")")
922 link_results = link_results and first_dir and second_dir
923
924
925 results = switch_results and port_results and link_results
Jon Halle9341332014-08-07 10:09:36 -0700926# if not results: #To print out both topologies
927# main.log.error("Topology comparison failed, printing json objects, MN then ONOS")
928# main.log.error(str(json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))))
929# main.log.error('MN Links:')
930# for link in topo.patch_panel.network_links: main.log.error(str("\tLink: %s" % link))
931# main.log.error(str(json.dumps(onos, sort_keys=True,indent=4,separators=(',', ': '))))
Jon Hall8412ed12014-07-24 16:33:58 -0700932 return results
admin2a9548d2014-06-17 14:08:07 -0700933
934
935
936
adminbae64d82013-08-01 10:50:15 -0700937
938if __name__ != "__main__":
939 import sys
940 sys.modules[__name__] = MininetCliDriver()
admin2a9548d2014-06-17 14:08:07 -0700941