Merge branch 'ONOS-Next' of https://github.com/OPENNETWORKINGLAB/ONLabTest into ONOS-Next
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index 9875064..ad07d95 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -115,18 +115,18 @@
if fanout is None: #In tree topology, if fanout arg is not given, by default it is 2
fanout = 2
k = 0
- sum = 0
+ count = 0
while(k <= depth-1):
- sum = sum + pow(fanout,k)
+ count = count + pow(fanout,k)
k = k+1
- num_switches = sum
+ num_switches = count
while(k <= depth-2):
'''depth-2 gives you only core links and not considering edge links as seen by ONOS
If all the links including edge links are required, do depth-1
'''
- sum = sum + pow(fanout,k)
+ count = count + pow(fanout,k)
k = k+1
- num_links = sum * fanout
+ num_links = count * fanout
#print "num_switches for %s(%d,%d) = %d and links=%d" %(topoType,depth,fanout,num_switches,num_links)
elif topoType =='linear':
@@ -387,7 +387,7 @@
return information dict about interfaces connected to the node
'''
if self.handle :
- cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,isUp=%s" % (i.name, i.MAC(), i.IP(), i.isUp())'
+ cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s" % (i.name, i.MAC(), i.IP(), i.isUp())'
cmd += ' for i in %s.intfs.values()])' % node
try:
response = self.execute(cmd=cmd,prompt="mininet>",timeout=10)
@@ -490,11 +490,11 @@
'''
Bring link(s) between two nodes up or down
'''
- main.log.info('Bring link(s) between two nodes up or down')
args = utilities.parse_args(["END1","END2","OPTION"],**linkargs)
end1 = args["END1"] if args["END1"] != None else ""
end2 = args["END2"] if args["END2"] != None else ""
option = args["OPTION"] if args["OPTION"] != None else ""
+ main.log.info("Bring link between '"+ end1 +"' and '" + end2 + "' '" + option + "'")
command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
try:
#response = self.execute(cmd=command,prompt="mininet>",timeout=10)
@@ -716,7 +716,6 @@
pattern = "flow_count=(\d+)"
result = re.search(pattern, response, re.MULTILINE)
if result is None:
- print "no flow on switch print test"
main.log.info("Couldn't find flows on switch '', found: %s" % (switch, response))
return main.FALSE
return result.group(1)
@@ -811,13 +810,10 @@
#main.log.debug("Switches_json string: ", switches_json)
output = {"switches":[]}
for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
- #print vars(switch)
ports = []
for port in switch.ports.values():
- #print port.hw_addr.toStr(separator = '')
ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
- #print output
#print "mn"
#print json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
@@ -830,6 +826,7 @@
for switch in output['switches']:
mnDPIDs.append(switch['dpid'])
mnDPIDs.sort()
+ #print "List of Mininet switch DPID's"
#print mnDPIDs
if switches_json == "":#if rest call fails
main.log.error(self.name + ".compare_switches(): Empty JSON object given from ONOS")
@@ -837,9 +834,13 @@
onos=switches_json
onosDPIDs=[]
for switch in onos:
- onosDPIDs.append(switch['id'].replace(":",'').replace("of",''))
- #print switch
+ if switch['available'] == True:
+ onosDPIDs.append(switch['id'].replace(":",'').replace("of",''))
+ #else:
+ #print "Switch is unavailable:"
+ #print switch
onosDPIDs.sort()
+ #print "List of ONOS switch DPID's"
#print onosDPIDs
if mnDPIDs!=onosDPIDs:
@@ -872,51 +873,68 @@
port_results = main.TRUE
output = {"switches":[]}
for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
- #print vars(switch)
ports = []
for port in switch.ports.values():
#print port.hw_addr.toStr(separator = '')
- ports.append({'of_port': port.port_no, 'mac': str(port.hw_addr).replace('\'',''), 'name': port.name})
- output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
- #print "compare_ports 'output' variable:"
- #print output
+ tmp_port = {}
+ tmp_port['of_port'] = port.port_no
+ tmp_port['mac'] = str(port.hw_addr).replace('\'','')
+ tmp_port['name'] = port.name
+ tmp_port['enabled'] = port.enabled
+
+ ports.append(tmp_port)
+ tmp_switch = {}
+ tmp_switch['name'] = switch.name
+ tmp_switch['dpid'] = str(switch.dpid).zfill(16)
+ tmp_switch['ports'] = ports
+
+ output['switches'].append(tmp_switch)
################ports#############
- for switch in output['switches']:
+ for mn_switch in output['switches']:
mn_ports = []
onos_ports = []
- for port in switch['ports']:
- mn_ports.append(port['of_port'])
+ for port in mn_switch['ports']:
+ if port['enabled'] == True:
+ mn_ports.append(port['of_port'])
for onos_switch in ports_json:
- if onos_switch['device'].replace(':','').replace("of", '') == switch['dpid']:
- for port in onos_switch['ports']:
- onos_ports.append(int(port['port']))
+ #print "Iterating through a new switch as seen by ONOS"
+ #print onos_switch
+ if onos_switch['device']['available'] == True:
+ if onos_switch['device']['id'].replace(':','').replace("of", '') == mn_switch['dpid']:
+ for port in onos_switch['ports']:
+ if port['isEnabled']:
+ #print "Iterating through available ports on the switch"
+ #print port
+ onos_ports.append(int(port['port']))
mn_ports.sort(key=float)
onos_ports.sort(key=float)
#print "\nPorts for Switch %s:" % (switch['name'])
#print "\tmn_ports[] = ", mn_ports
#print "\tonos_ports[] = ", onos_ports
- #if mn_ports == onos_ports:
- #pass #don't set results to true here as this is just one of many checks and it might override a failure
-
- #For OF1.3, the OFP_local port number is 0xfffffffe or 4294967294 instead of 0xfffe or 65534 in OF1.0, ONOS topology
- #sees the correct port number, however MN topology as read from line 151 of https://github.com/ucb-sts/sts/blob/
- #topology_refactoring2/sts/entities/teston_entities.py is 0xfffe which doesn't work correctly with OF1.3 switches.
- #So a short term fix is to ignore the case when mn_port == 65534 and onos_port ==4294967294.
+ #NOTE:For OF1.3, the OFP_local port number is 0xfffffffe or 4294967294 instead of 0xfffe or 65534 in OF1.0,
+ # ONOS topology sees the correct port number, however MN topology as read from line 151 of
+ # https://github.com/ucb-sts/sts/blob/topology_refactoring2/sts/entities/teston_entities.py
+ # is 0xfffe which doesn't work correctly with OF1.3 switches.
- #ONOS-Next is abstracting port numbers to 64bit unsigned number. So we will be converting the OF reserved ports to these numbers
+ #NOTE: ONOS is abstracting port numbers to 64bit unsigned number(long). So we will be converting the
+ # OF reserved ports to these numbers
+
+
#TODO: handle other reserved port numbers besides LOCAL
for mn_port,onos_port in zip(mn_ports,onos_ports):
- if mn_port == onos_port or (mn_port == 65534 and onos_port ==int(uint64(-2))):
+ #print "mn == onos port?"
+ #print mn_port, onos_port
+ if mn_port == onos_port or (mn_port == 65534 and onos_port == long(uint64(-2))):
continue
#don't set results to true here as this is just one of many checks and it might override a failure
else: #the ports of this switch don't match
port_results = main.FALSE
break
if port_results == main.FALSE:
- main.log.report("The list of ports for switch %s(%s) does not match:" % (switch['name'], switch['dpid']) )
+ main.log.report("The list of ports for switch %s(%s) does not match:" % (mn_switch['name'], mn_switch['dpid']) )
main.log.report("mn_ports[] = " + str(mn_ports))
main.log.report("onos_ports[] = " + str(onos_ports))
return port_results
@@ -939,7 +957,8 @@
output = {"switches":[]}
onos = links_json
for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
- #print vars(switch)
+ # print "Iterating though switches as seen by Mininet"
+ # print switch
ports = []
for port in switch.ports.values():
#print port.hw_addr.toStr(separator = '')
@@ -947,19 +966,21 @@
output['switches'].append({"name": switch.name, "dpid": str(switch.dpid).zfill(16), "ports": ports })
#######Links########
- if 2*len(topo.patch_panel.network_links) == len(onos):
+ mn_links = [link for link in topo.patch_panel.network_links if (link.port1.enabled and link.port2.enabled)]
+ #print "mn_links:"
+ #print mn_links
+ if 2*len(mn_links) == len(onos):
link_results = main.TRUE
else:
link_results = main.FALSE
- main.log.report("Mininet has %i bidirectional links and ONOS has %i unidirectional links" % (len(topo.patch_panel.network_links), len(onos) ))
+ main.log.report("Mininet has %i bidirectional links and ONOS has %i unidirectional links" % (len(mn_links), len(onos) ))
# iterate through MN links and check if an ONOS link exists in both directions
# NOTE: Will currently only show mn links as down if they are cut through STS.
# We can either do everything through STS or wait for up_network_links
# and down_network_links to be fully implemented.
- for link in topo.patch_panel.network_links:
- #print "\n"
+ for link in mn_links:
#print "Link: %s" % link
#TODO: Find a more efficient search method
node1 = None
@@ -1050,6 +1071,26 @@
return host_list
+
+ def update(self):
+ '''
+ updates the port address and status information for each port in mn
+ '''
+ #TODO: Add error checking. currently the mininet command has no output
+ main.log.info("Updateing MN port information")
+ self.handle.sendline("")
+ self.handle.expect("mininet>")
+
+ self.handle.sendline("update")
+ self.handle.expect("mininet>")
+
+ self.handle.sendline("")
+ self.handle.expect("mininet>")
+
+ return main.TRUE
+
+
+
if __name__ != "__main__":
import sys
sys.modules[__name__] = MininetCliDriver()
diff --git a/TestON/drivers/common/cli/emulator/remotemininetdriver.py b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
index 2acddb4..ffb5151 100644
--- a/TestON/drivers/common/cli/emulator/remotemininetdriver.py
+++ b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
@@ -416,6 +416,15 @@
main.cleanup()
main.exit()
+ def run_optical_mn_script(self):
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("cd ~")
+ self.handle.expect("\$")
+ self.handle.sendline("sudo python optical.py")
+ self.handle.expect("\$")
+
+
def del_switch(self,sw):
self.handle.sendline("")
self.handle.expect("\$")
diff --git a/TestON/drivers/common/cli/onosdriver.py b/TestON/drivers/common/cli/onosdriver.py
index 75742cd..575de1c 100644
--- a/TestON/drivers/common/cli/onosdriver.py
+++ b/TestON/drivers/common/cli/onosdriver.py
@@ -257,7 +257,7 @@
pexpect.TIMEOUT],
timeout=300)
#debug
- #main.log.report(self.name +": \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
+ #main.log.report(self.name +": DEBUG: \n"+"git pull response: " + str(self.handle.before) + str(self.handle.after))
if i==0:
main.log.error(self.name + ": Git pull had some issue...")
return main.ERROR
@@ -317,63 +317,59 @@
'''
try:
- # main.log.info(self.name + ": Stopping ONOS")
- #self.stop()
self.handle.sendline("cd " + self.home)
self.handle.expect("ONOS\$")
- if branch != 'master':
- #self.handle.sendline('git stash')
- #self.handle.expect('ONOS\$')
- #print "After issuing git stash cmnd: ", self.handle.before
- cmd = "git checkout "+branch
- print "checkout cmd = ", cmd
- self.handle.sendline(cmd)
- uptodate = 0
- i=self.handle.expect(['fatal',
- 'Username\sfor\s(.*):\s',
- 'Already\son\s\'',
- 'Switched\sto\sbranch\s\'',
- pexpect.TIMEOUT],timeout=60)
- else:
- #self.handle.sendline('git stash apply')
- #self.handle.expect('ONOS\$')
- #print "After issuing git stash apply cmnd: ", self.handle.before
- cmd = "git checkout "+branch
- print "checkout cmd = ", cmd
- self.handle.sendline(cmd)
- uptodate = 0
- switchedToMaster = 0
- i=self.handle.expect(['fatal',
- 'Username\sfor\s(.*):\s',
- 'Already\son\s\'master\'',
- 'Switched\sto\sbranch\s\'master\'',
- pexpect.TIMEOUT],timeout=60)
-
+ main.log.info(self.name + ": Checking out git branch: " + branch + "...")
+ cmd = "git checkout "+branch
+ self.handle.sendline(cmd)
+ self.handle.expect(cmd)
+ i=self.handle.expect(['fatal',
+ 'Username\sfor\s(.*):\s',
+ 'Already\son\s\'',
+ 'Switched\sto\sbranch\s\'' + str(branch),
+ pexpect.TIMEOUT,
+ 'error: Your local changes to the following files would be overwritten by checkout:',
+ 'error: you need to resolve your current index first'],timeout=60)
if i==0:
main.log.error(self.name + ": Git checkout had some issue...")
+ main.log.error(self.name + ": " + self.handle.before)
return main.ERROR
elif i==1:
- main.log.error(self.name + ": Git checkout Asking for username!!! Bad!")
+ main.log.error(self.name + ": Git checkout asking for username."\
+ +" Please configure your local git repository to be able "\
+ +"to access your remote repository passwordlessly")
return main.ERROR
elif i==2:
main.log.info(self.name + ": Git Checkout %s : Already on this branch" %branch)
self.handle.expect("ONOS\$")
- print "after checkout cmd = ", self.handle.before
- switchedToMaster = 1
+ #main.log.info("DEBUG: after checkout cmd = "+ self.handle.before)
return main.TRUE
elif i==3:
main.log.info(self.name + ": Git checkout %s - Switched to this branch" %branch)
self.handle.expect("ONOS\$")
- print "after checkout cmd = ", self.handle.before
- switchedToMaster = 1
+ #main.log.info("DEBUG: after checkout cmd = "+ self.handle.before)
return main.TRUE
elif i==4:
main.log.error(self.name + ": Git Checkout- TIMEOUT")
main.log.error(self.name + " Response was: " + str(self.handle.before))
return main.ERROR
+ elif i==5:
+ self.handle.expect("Aborting")
+ main.log.error(self.name + ": Git checkout error: \n" + \
+ "Your local changes to the following files would be overwritten by checkout:" + \
+ str(self.handle.before))
+ self.handle.expect("ONOS\$")
+ return main.ERROR
+ elif i==6:
+ main.log.error(self.name + ": Git checkout error: \n" + \
+ "You need to resolve your current index first:" + \
+ str(self.handle.before))
+ self.handle.expect("ONOS\$")
+ return main.ERROR
else:
main.log.error(self.name + ": Git Checkout - Unexpected response, check for pull errors")
+ main.log.error(self.name + ": " + self.handle.before)
return main.ERROR
except pexpect.EOF:
@@ -388,7 +384,7 @@
main.cleanup()
main.exit()
- def get_version(self):
+ def get_version(self, report=False):
'''
Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
'''
@@ -406,9 +402,11 @@
self.handle.expect("\$")
lines=response.splitlines()
for line in lines:
- print "line = ",line
- returnValue = lines[2]+lines[4]
- return returnValue
+ print line
+ if report:
+ for line in lines[2:-1]:
+ main.log.report(line)
+ return lines[2]
except pexpect.EOF:
main.log.error(self.name + ": EOF exception found")
main.log.error(self.name + ": " + self.handle.before)
@@ -885,7 +883,7 @@
self.handle.sendline("onos-wait-for-start " + node )
self.handle.expect("onos-wait-for-start")
#NOTE: this timeout is arbitrary"
- i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 120)
+ i = self.handle.expect(["\$", pexpect.TIMEOUT], timeout = 300)
if i == 0:
main.log.info(self.name + ": " + node + " is up")
return main.TRUE
@@ -1044,6 +1042,22 @@
str(interface)+ " and saving to directory: "+
str(dir_file))
+
+ def run_onos_topo_cfg(self):
+ '''
+ On ONOS bench, run this command: ./~/ONOS/tools/test/bin/onos-topo-cfg
+ which starts the rest and copies the json file to the onos instance
+ '''
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("cd ~/ONOS/tools/test/bin")
+ self.handle.expect("/bin$")
+ self.handle.sendline("./onos-topo-cfg")
+ self.handle.expect("{}admin@onosTestBench")
+ self.handle.sendline("cd ~")
+ self.handle.expect("\$")
+
+
def tshark_grep(self, grep, directory, interface='eth0'):
'''
Required: