Add hosts and get_host command
Initial commit of multinode Test
minor text changes
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index ccf3baf..419ee06 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -808,6 +808,7 @@
'''
import json
+ #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)
@@ -818,7 +819,10 @@
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=(',', ': '))
+ #print "onos"
+ #print json.dumps(switches_json, sort_keys=True,indent=4,separators=(',', ': '))
# created sorted list of dpid's in MN and ONOS for comparison
@@ -828,7 +832,7 @@
mnDPIDs.sort()
#print mnDPIDs
if switches_json == "":#if rest call fails
- main.log.error(self.name + ".compare_topo(): Empty JSON object given from ONOS")
+ main.log.error(self.name + ".compare_switches(): Empty JSON object given from ONOS")
return main.FALSE
onos=switches_json
onosDPIDs=[]
@@ -1019,184 +1023,6 @@
return link_results
-
-
- def compare_topo(self, topo, onos_json):
- '''
- compares mn topology with ONOS topology
- onos_list is a list of ONOS controllers, each element of the list should be (handle, name, ip, port)
- onos_json is the output of the onos get_json function calling the /wm/onos/topology REST API
- Returns: True if MN and ONOS topology match and False if the differ.
- Differences between ONOS and MN topology will be printed to the log.
-
- Dependency: Requires STS to be installed on the TestON machine. STS can be pulled
- from https://github.com/ucb-sts/sts.git . Currently the required functions from STS are located in the
- topology_refactoring2 branch, but may be merged into the master branch soon. You may need to install some
- python modules such as networkx to use the STS functions.
-
- To install sts:
- $ git clone git://github.com/ucb-sts/sts.git
- $ cd sts
- $ git clone -b debugger git://github.com/ucb-sts/pox.git
- $ sudo apt-get install python-dev
- $ ./tools/install_hassel_python.sh
- $ sudo pip install networkx
-
- Include sts in your PYTHONPATH. it should looks comething like:
- PYTHONPATH=/home/admin/TestON:/home/admin/sts
-
- '''
- import sys
- sys.path.append("~/sts")
- #NOTE: Create this once per Test and pass the TestONTopology object around. It takes too long to create this object.
- # This will make it easier to use the sts methods for severing links and solve that issue
- import json
-
- link_results = main.TRUE
- switch_results = main.TRUE
- port_results = main.TRUE
-
- ########Switches#######
- output = {"switches":[]}
- for switch in topo.graph.switches: #iterate through the MN topology and pull out switches and and port info
- 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 json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))
-
-
- # created sorted list of dpid's in MN and ONOS for comparison
- mnDPIDs=[]
- for switch in output['switches']:
- mnDPIDs.append(switch['dpid'])
- mnDPIDs.sort()
- #print mnDPIDs
- if onos_json == "":#if rest call fails
- main.log.error(self.name + ".compare_topo(): Empty JSON object given from ONOS rest call")
- return main.FALSE
- onos=onos_json
- onosDPIDs=[]
- for switch in onos['switches']:
- onosDPIDs.append(switch['dpid'].replace(":",''))
- onosDPIDs.sort()
- #print onosDPIDs
-
- if mnDPIDs!=onosDPIDs:
- switch_results = main.FALSE
- main.log.report( "Switches in MN but not in ONOS:")
- main.log.report( str([switch for switch in mnDPIDs if switch not in onosDPIDs]))
- main.log.report( "Switches in ONOS but not in MN:")
- main.log.report( str([switch for switch in onosDPIDs if switch not in mnDPIDs]))
- else:#list of dpid's match in onos and mn
- switch_results = main.TRUE
-
- ################ports#############
- for switch in output['switches']:
- mn_ports = []
- onos_ports = []
- for port in switch['ports']:
- mn_ports.append(port['of_port'])
- for onos_switch in onos['switches']:
- if onos_switch['dpid'].replace(':','') == switch['dpid']:
- for port in onos_switch['ports']:
- onos_ports.append(port['portNumber'])
- mn_ports.sort()
- onos_ports.sort()
- #print "mn_ports[] = ", mn_ports
- #print "onos_ports90 = ", 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.
- for mn_port,onos_port in zip(mn_ports,onos_ports):
- if mn_port == onos_port or (mn_port == 65534 and onos_port ==4294967294):
- continue
- else:
- port_results = main.FALSE
- break
- '''
- else: #the ports of this switch don't match
- port_results = main.FALSE
- main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
- main.log.report( str([port for port in mn_ports if port not in onos_ports]))
- main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
- main.log.report( str([port for port in onos_ports if port not in mn_ports]))
- '''
- if port_results == main.FALSE:
- main.log.report("ports in MN switch %s(%s) but not in ONOS:" % (switch['name'],switch['dpid']))
- main.log.report( str([port for port in mn_ports if port not in onos_ports]))
- main.log.report("ports in ONOS switch %s(%s) but not in MN:" % (switch['name'],switch['dpid']))
- main.log.report( str([port for port in onos_ports if port not in mn_ports]))
-
- #######Links########
- # iterate through MN links and check if and 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 "Link: %s" % link
- #TODO: Find a more efficient search method
- node1 = None
- port1 = None
- node2 = None
- port2 = None
- first_dir = main.FALSE
- second_dir = main.FALSE
- for switch in output['switches']:
- if switch['name'] == link.node1.name:
- node1 = switch['dpid']
- for port in switch['ports']:
- if str(port['name']) == str(link.port1):
- port1 = port['of_port']
- if node1 is not None and node2 is not None:
- break
- if switch['name'] == link.node2.name:
- node2 = switch['dpid']
- for port in switch['ports']:
- if str(port['name']) == str(link.port2):
- port2 = port['of_port']
- if node1 is not None and node2 is not None:
- break
- # check onos link from node1 to node2
- for onos_link in onos['links']:
- if onos_link['src']['dpid'].replace(":",'') == node1 and onos_link['dst']['dpid'].replace(":",'') == node2:
- if onos_link['src']['portNumber'] == port1 and onos_link['dst']['portNumber'] == port2:
- first_dir = main.TRUE
- else:
- main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
- #print node1, ' to ', node2
- elif onos_link['src']['dpid'].replace(":",'') == node2 and onos_link['dst']['dpid'].replace(":",'') == node1:
- if onos_link['src']['portNumber'] == port2 and onos_link['dst']['portNumber'] == port1:
- second_dir = main.TRUE
- else:
- main.log.report('the port numbers do not match for ' +str(link) + ' between ONOS and MN')
- #print node2, ' to ', node1
- else:#this is not the link you're looking for
- pass
- if not first_dir:
- 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)+")")
- if not second_dir:
- 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)+")")
- link_results = link_results and first_dir and second_dir
-
-
- results = switch_results and port_results and link_results
-# if not results: #To print out both topologies
-# main.log.error("Topology comparison failed, printing json objects, MN then ONOS")
-# main.log.error(str(json.dumps(output, sort_keys=True,indent=4,separators=(',', ': '))))
-# main.log.error('MN Links:')
-# for link in topo.patch_panel.network_links: main.log.error(str("\tLink: %s" % link))
-# main.log.error(str(json.dumps(onos, sort_keys=True,indent=4,separators=(',', ': '))))
- return results
-
def get_hosts(self):
'''
Returns a list of all hosts