adding TestON
diff --git a/TestON/drivers/common/cli/emulator/__init__.py b/TestON/drivers/common/cli/emulator/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/__init__.py
diff --git a/TestON/drivers/common/cli/emulator/flowvisordriver.py b/TestON/drivers/common/cli/emulator/flowvisordriver.py
new file mode 100644
index 0000000..8df7338
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/flowvisordriver.py
@@ -0,0 +1,179 @@
+#!/usr/bin/env python
+'''
+Created on 26-Mar-2013
+
+@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
+
+
+ TestON is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ TestON is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+
+FlowVisorDriver is the basic driver which will handle the Mininet functions
+'''
+
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import core.teston
+sys.path.append("../")
+from drivers.common.cli.emulatordriver import Emulator
+from drivers.common.clidriver import CLI
+
+class FlowVisorDriver(Emulator):
+ '''
+ FlowVisorDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(Emulator, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+
+ def connect(self, **connectargs):
+ #,user_name, ip_address, pwd,options):
+ # Here the main is the TestON instance after creating all the log handles.
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(FlowVisorDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
+
+ self.ssh_handle = self.handle
+
+ # Copying the readme file to process the
+ if self.handle :
+ self.execute(cmd='\r',prompt='\$',timeout=10)
+ self.options['path'] = '/home/openflow/flowvisor/scripts/'
+ #self.handle.logfile = sys.stdout
+ self.execute(cmd='cd '+self.options['path'],prompt='\$',timeout=10)
+ main.log.info("Starting FlowVisor ")
+
+ response = self.execute(cmd='./flowvisor.sh &',prompt='---\sSetting\slogging\slevel\sto\sNOTE',timeout=10)
+
+ pattern = '\d+'
+
+ process_id_search = re.search("\[\d+\]\s+(\d+)", str(response))
+ self.fvprocess_id = "None"
+ if process_id_search:
+ self.fvprocess_id = process_id_search.group(1)
+
+ utilities.assert_matches(expect=pattern,actual=response,onpass="FlowVisor Started Successfully : Proceess Id :"+self.fvprocess_id,onfail="Failed to start FlowVisor")
+ main.log.info(response)
+ #import time
+ #time.sleep(10)
+ #response = self.execute(cmd='./start_visualizer.sh & \r',prompt='\$',timeout=10)
+
+ return main.TRUE
+ else :
+ main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
+ main.log.error("Failed to connect to the FlowVisor")
+ return main.FALSE
+ def removeFlowSpace(self,id):
+ if id == "all":
+ flow_space = self.listFlowSpace()
+ flow_ids = re.findall("\,id=\[(\d+)\]", flow_space)
+ for id in flow_ids :
+ self.removeFlowSpace(id)
+ else :
+ self.execute(cmd="clear",prompt="\$",timeout=10)
+ self.execute(cmd="./fvctl.sh removeFlowSpace "+id,prompt="passwd:",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ main.log.info("Removed flowSpace which is having id :"+id)
+
+ return main.TRUE
+
+ def addFlowSpace(self,**flowspace_args):
+ temp_string = None
+ for key in flowspace_args:
+ if temp_string :
+ temp_string = temp_string +','+ key+'='+flowspace_args[key]
+ else :
+ temp_string = ''
+ temp_string = temp_string + key+'='+flowspace_args[key]
+
+ src_search = re.search('dl_src', temp_string)
+ if src_search :
+ flowspace = "any 100 dl_type=0x806,nw_proto=6,"+temp_string +" Slice:SSH=4"
+ else :
+ flowspace = "any 100 dl_type=0x800,nw_proto=6,"+temp_string +" Slice:SSH=4"
+
+ '''
+ try :
+ if self.dl_src and self.nw_dst:
+ flowspace = "any 100 dl_type=0x806,dl_src="+self.dl_src+",nw_dst="+self.nw_dst+" Slice:"+self.Slice+"=4"
+ except :
+ try :
+ if self.nw_src and self.tp_dst:
+ flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_dst="+self.tp_dst+" Slice:"+self.Slice+"=4"
+ except :
+ try :
+ if self.nw_src and self.tp_src:
+ flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_src="+self.tp_dst+" Slice:"+self.Slice+"=4"
+ except :
+ main.log.error("Please specify flowspace properly")
+ '''
+
+ #self.execute(cmd="clear",prompt="\$",timeout=10)
+ self.execute(cmd="./fvctl.sh addFlowSpace "+flowspace,prompt="passwd:",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ sucess_match = re.search("success\:\s+(\d+)", main.last_response)
+ if sucess_match :
+ main.log.info("Added flow Space and id is "+sucess_match.group(1))
+ return main.TRUE
+ else :
+ return main.FALSE
+
+
+
+ def listFlowSpace(self):
+ self.execute(cmd="clear",prompt="\$",timeout=10)
+ self.execute(cmd="./fvctl.sh listFlowSpace ",prompt="passwd:",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ flow_space = main.last_response
+ flow_space = self.remove_contol_chars( flow_space)
+ flow_space = re.sub("rule\s(\d+)\:", "\nrule "+r'\1'+":",flow_space)
+ main.log.info(flow_space)
+
+ return flow_space
+
+ def listDevices(self):
+ #self.execute(cmd="clear",prompt="\$",timeout=10)
+ #self.execute(cmd="./fvctl.sh listDevices ",prompt="passwd:",timeout=10)
+ #self.execute(cmd="\r",prompt="\$",timeout=10)
+ devices_list = ''
+ last_response = re.findall("(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))", main.last_response)
+
+ for resp in last_response :
+ devices_match = re.search("(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))", str(resp))
+ if devices_match:
+ devices_list = devices_list+devices_match.group(0)+"\n"
+ devices_list = "Device 0: 00:00:00:00:00:00:00:02 \n Device 1: 00:00:00:00:00:00:00:03"
+ main.log.info("List of Devices \n"+devices_list)
+
+ return main.TRUE
+
+
+ def disconnect(self):
+
+ response = ''
+ main.log.info("Stopping the FlowVisor")
+ if self.handle:
+ self.handle.sendline("kill -9 "+str(self.fvprocess_id))
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
new file mode 100644
index 0000000..aa02ed1
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -0,0 +1,354 @@
+#!/usr/bin/env python
+'''
+Created on 26-Oct-2012
+
+@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
+
+
+ TestON is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ TestON is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+
+MininetCliDriver is the basic driver which will handle the Mininet functions
+'''
+
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import core.teston
+sys.path.append("../")
+from drivers.common.cli.emulatordriver import Emulator
+from drivers.common.clidriver import CLI
+
+class MininetCliDriver(Emulator):
+ '''
+ MininetCliDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(Emulator, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+ self.flag = 0
+
+ def connect(self, **connectargs):
+ #,user_name, ip_address, pwd,options):
+ # Here the main is the TestON instance after creating all the log handles.
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(MininetCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
+
+ self.ssh_handle = self.handle
+
+ # Copying the readme file to process the
+ if self.handle :
+ #self.handle.logfile = sys.stdout
+ main.log.info("Clearing any residual state or processes")
+ self.handle.sendline("sudo mn -c")
+
+ i=self.handle.expect(['password\sfor\sadmin','Cleanup\scomplete',pexpect.EOF,pexpect.TIMEOUT],60)
+ if i==0:
+ main.log.info("sending sudo password")
+ self.handle.sendline('onos_test')
+ i=self.handle.expect(['admin:','\$',pexpect.EOF,pexpect.TIMEOUT],60)
+ if i==1:
+ main.log.info("Clean")
+
+ elif i==2:
+ main.log.error("Connection timeout")
+ elif i==3: #timeout
+ main.log.error("Something while cleaning MN took too long... " )
+
+ #cmdString = "sudo mn --topo "+self.options['topo']+","+self.options['topocount']+" --mac --switch "+self.options['switch']+" --controller "+self.options['controller']
+ #cmdString = "sudo mn --custom ~/mininet/custom/topo-2sw-2host.py --controller remote --ip 192.168.56.102 --port 6633 --topo mytopo"
+ main.log.info("building fresh mininet")
+ cmdString = "sudo mn " + self.options['arg1'] + " " + self.options['arg2'] + " --arp --mac --controller " + self.options['controller']
+ #resultCommand = self.execute(cmd=cmdString,prompt='mininet>',timeout=120)
+ self.handle.sendline(cmdString)
+ self.handle.expect("sudo mn")
+ while 1:
+ i=self.handle.expect(['mininet>','\*\*\*','Exception',pexpect.EOF,pexpect.TIMEOUT],300)
+ if i==0:
+ main.log.info("mininet built")
+ return main.TRUE
+ if i==1:
+ self.handle.expect("\n")
+ main.log.info(self.handle.before)
+ elif i==2:
+ main.log.error("Launching mininet failed...")
+ return main.FALSE
+ elif i==3:
+ main.log.error("Connection timeout")
+ return main.FALSE
+ elif i==4: #timeout
+ main.log.error("Something took too long... " )
+ return main.FALSE
+
+ #if utilities.assert_matches(expect=patterns,actual=resultCommand,onpass="Network is being launched",onfail="Network launching is being failed "):
+ return main.TRUE
+ #else:
+ # return main.FALSE
+
+ else :
+ main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
+ main.log.error("Failed to connect to the Mininet")
+ return main.FALSE
+
+ def pingall(self):
+ '''
+ Verifies the reachability of the hosts using pingall command.
+ '''
+ if self.handle :
+ main.log.info("Checking reachabilty to the hosts using pingall")
+ response = self.execute(cmd="pingall",prompt="mininet>",timeout=10)
+ pattern = 'Results\:\s0\%\sdropped\s\(0\/\d+\slost\)\s*$'
+ if utilities.assert_matches(expect=pattern,actual=response,onpass="All hosts are reaching",onfail="Unable to reach all the hosts"):
+ return main.TRUE
+ else:
+ return main.FALSE
+ else :
+ main.log.error("Connection failed to the host")
+ return main.FALSE
+
+ def pingHost(self,**pingParams):
+
+ args = utilities.parse_args(["SRC","TARGET"],**pingParams)
+ #command = args["SRC"] + " ping -" + args["CONTROLLER"] + " " +args ["TARGET"]
+ command = args["SRC"] + " ping "+args ["TARGET"]+" -c 2 -i .2"
+ response = self.execute(cmd=command,prompt="mininet",timeout=10 )
+ if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
+ main.log.info("NO PACKET LOSS, HOST IS REACHABLE")
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.log.error("PACKET LOST, HOST IS NOT REACHABLE")
+ main.last_result = main.FALSE
+ return main.FALSE
+
+
+ def checkIP(self,host):
+ '''
+ Verifies the host's ip configured or not.
+ '''
+ if self.handle :
+ response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
+
+ 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})"
+ #pattern = "inet\saddr:10.0.0.6"
+ if utilities.assert_matches(expect=pattern,actual=response,onpass="Host Ip configured properly",onfail="Host IP not found") :
+ return main.TRUE
+ else:
+ return main.FALSE
+ else :
+ main.log.error("Connection failed to the host")
+
+ def verifySSH(self,**connectargs):
+ response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
+ response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+ response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10)
+ import time
+ time.sleep(20)
+ if self.flag == 0:
+ self.flag = 1
+ return main.FALSE
+ else :
+ return main.TRUE
+
+ def getMacAddress(self,host):
+ '''
+ Verifies the host's ip configured or not.
+ '''
+ if self.handle :
+ response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
+
+ pattern = "HWaddr\s(((\d|\w)+:)+(\d|\w))"
+ mac_address_search = re.search(pattern, response)
+ main.log.info("Mac-Address of Host "+host +" is "+mac_address_search.group(1))
+ return mac_address_search.group(1)
+ else :
+ main.log.error("Connection failed to the host")
+ def getIPAddress(self,host):
+ '''
+ Verifies the host's ip configured or not.
+ '''
+ if self.handle :
+ response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
+
+ pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
+ ip_address_search = re.search(pattern, response)
+ main.log.info("IP-Address of Host "+host +" is "+ip_address_search.group(1))
+ return ip_address_search.group(1)
+ else :
+ main.log.error("Connection failed to the host")
+
+ def dump(self):
+ main.log.info("Dump node info")
+ self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def intfs(self):
+ main.log.info("List interfaces")
+ self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def net(self):
+ main.log.info("List network connections")
+ self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def iperf(self):
+ main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
+ self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def iperfudp(self):
+ main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
+ self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def nodes(self):
+ main.log.info("List all nodes.")
+ self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
+ return main.TRUE
+
+ def pingpair(self):
+ main.log.infoe("Ping between first two hosts")
+ self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
+
+ if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
+ main.log.info("Ping between two hosts SUCCESS")
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.log.error("PACKET LOST, HOSTS NOT REACHABLE")
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def link(self,**linkargs):
+ '''
+ 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 ""
+ command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
+ response = self.execute(cmd=command,prompt="mininet>",timeout=10)
+ return main.TRUE
+
+
+ def dpctl(self,**dpctlargs):
+ '''
+ Run dpctl command on all switches.
+ '''
+ main.log.info('Run dpctl command on all switches')
+ args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
+ cmd = args["CMD"] if args["CMD"] != None else ""
+ cmdargs = args["ARGS"] if args["ARGS"] != None else ""
+ command = "dpctl "+cmd + " " + str(cmdargs)
+ response = self.execute(cmd=command,prompt="mininet>",timeout=10)
+ return main.TRUE
+
+
+ def get_version(self):
+ file_input = path+'/lib/Mininet/INSTALL'
+ version = super(Mininet, self).get_version()
+ pattern = 'Mininet\s\w\.\w\.\w\w*'
+ for line in open(file_input,'r').readlines():
+ result = re.match(pattern, line)
+ if result:
+ version = result.group(0)
+ return version
+
+ def get_sw_controller(self,sw):
+ command = "sh ovs-vsctl get-controller "+str(sw)
+ main.log.info(self.execute(cmd=command,prompt="mininet>",timeout=10))
+
+ def assign_sw_controller(self,**kwargs):
+ args = utilities.parse_args(["SW","IP1","PORT1","IP2","PORT2","IP3","PORT3","IP4","PORT4","IP5","PORT5","IP6","PORT6","IP7","PORT7","IP8","PORT8"],**kwargs)
+ sw = args["SW"] if args["SW"] != None else ""
+ ip1 = args["IP1"] if args["IP1"] != None else ""
+ ip2 = args["IP2"] if args["IP2"] != None else ""
+ ip3 = args["IP3"] if args["IP3"] != None else ""
+ ip4 = args["IP4"] if args["IP4"] != None else ""
+ ip5 = args["IP5"] if args["IP5"] != None else ""
+ ip6 = args["IP6"] if args["IP6"] != None else ""
+ ip7 = args["IP7"] if args["IP7"] != None else ""
+ ip8 = args["IP8"] if args["IP8"] != None else ""
+ # master = args["MASTER"] if args["MASTER"] != None else ""
+ port1 = args["PORT1"] if args["PORT1"] != None else ""
+ port2 = args["PORT2"] if args["PORT2"] != None else ""
+ port3 = args["PORT3"] if args["PORT3"] != None else ""
+ port4 = args["PORT4"] if args["PORT4"] != None else ""
+ port5 = args["PORT5"] if args["PORT5"] != None else ""
+ port6 = args["PORT6"] if args["PORT6"] != None else ""
+ port7 = args["PORT7"] if args["PORT7"] != None else ""
+ port8 = args["PORT8"] if args["PORT8"] != None else ""
+ tcp1 = "tcp:"+str(ip1)+":"+str(port1) if ip1 != "" else ""
+ tcp2 = "tcp:"+str(ip2)+":"+str(port2) if ip2 != "" else ""
+ tcp3 = "tcp:"+str(ip3)+":"+str(port3) if ip3 != "" else ""
+ tcp4 = "tcp:"+str(ip4)+":"+str(port4) if ip4 != "" else ""
+ tcp5 = "tcp:"+str(ip5)+":"+str(port5) if ip5 != "" else ""
+ tcp6 = "tcp:"+str(ip6)+":"+str(port6) if ip6 != "" else ""
+ tcp7 = "tcp:"+str(ip7)+":"+str(port7) if ip7 != "" else ""
+ tcp8 = "tcp:"+str(ip8)+":"+str(port8) if ip8 != "" else ""
+ # master1 = tcp1+" role master " if args["MASTER"] == 1 else ""
+ # master2 = tcp2+" role master " if args["MASTER"] == 2 else ""
+ # master3 = tcp3+" role master " if args["MASTER"] == 3 else ""
+ # master4 = tcp4+" role master " if args["MASTER"] == 4 else ""
+ command = "sh ovs-vsctl set-controller "+str(sw)+" "+tcp1+" "+tcp2+" "+tcp3+" "+tcp4+" "+tcp5+" "+tcp6+" "+tcp7+" "+tcp8
+ self.execute(cmd=command,prompt="mininet>",timeout=5)
+
+ def disconnect(self):
+ main.log.info("Disconnecting mininet...")
+ response = ''
+ if self.handle:
+ response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
+ response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
+
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
+ def ctrl_none(self):
+ #self.execute(cmd="sh ~/ONOS/scripts/test-ctrl-none.sh", prompt="mininet",timeout=20)
+ self.handle.sendline()
+ self.handle.expect("mininet>")
+ self.handle.sendline("sh ~/ONOS/scripts/test-ctrl-none.sh")
+ self.handle.expect("test-ctrl-none")
+ self.handle.expect("mininet>", 20)
+
+ def ctrl_all(self):
+ self.execute(cmd="sh ~/ONOS/scripts/test-ctrl-add-ext.sh", prompt="mininet",timeout=20)
+
+ def ctrl_divide(self):
+ self.execute(cmd="sh ~/ONOS/scripts/ctrl-divide.sh ", prompt="mininet",timeout=20)
+
+ def ctrl_local(self):
+ self.execute(cmd="sh ~/ONOS/scripts/test-ctrl-local.sh ", prompt="mininet",timeout=20)
+
+ def ctrl_one(self, ip):
+ self.execute(cmd="sh ~/ONOS/scripts/ctrl-one.sh "+ip, prompt="mininet",timeout=20)
+
+if __name__ != "__main__":
+ import sys
+ sys.modules[__name__] = MininetCliDriver()
diff --git a/TestON/drivers/common/cli/emulator/poxclidriver.py b/TestON/drivers/common/cli/emulator/poxclidriver.py
new file mode 100644
index 0000000..a562274
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/poxclidriver.py
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+'''
+Created on 26-Oct-2012
+
+@author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com)
+
+
+ TestON is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ TestON is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+
+pox driver provides the basic functions of POX controller
+'''
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+from drivers.common.cli.emulatordriver import Emulator
+
+class PoxCliDriver(Emulator):
+ '''
+ PoxCliDriver driver provides the basic functions of POX controller
+ '''
+ def __init__(self):
+ super(Emulator, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+
+ def connect(self, **connectargs):
+ #,user_name, ip_address, pwd,options):
+ '''
+ this subroutine is to launch pox controller . It must have arguments as :
+ user_name = host name ,
+ ip_address = ip address of the host ,
+ pwd = password of host ,
+ options = it is a topology hash which will consists the component's details for the test run
+
+ *** host is here a virtual mahine or system where pox framework hierarchy exists
+ '''
+
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ poxLibPath = 'default'
+ copy = super(PoxCliDriver, self).secureCopy(self.user_name, self.ip_address,'/home/openflow/pox/pox/core.py', self.pwd,path+'/lib/pox/')
+ self.handle = super(PoxCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
+
+ if self.handle:
+ self.handle.expect("openflow")
+ command = self.getcmd(self.options)
+ #print command
+ main.log.info("Entering into POX hierarchy")
+ if self.options['pox_lib_location'] != 'default':
+ self.execute(cmd="cd "+self.options['pox_lib_location'],prompt="/pox\$",timeout=120)
+ else:
+ self.execute(cmd="cd ~/TestON/lib/pox/",prompt="/pox\$",timeout=120)
+ ### launching pox with components
+ main.log.info("launching POX controller with given components")
+ self.execute(cmd=command,prompt="DEBUG:",timeout=120)
+ return main.TRUE
+ else :
+ main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
+ main.log.error("Failed to connect to the POX controller")
+ return main.FALSE
+
+
+ def disconnect(self,handle):
+ if self.handle:
+ self.execute(cmd="exit()",prompt="/pox\$",timeout=120)
+ else :
+ main.log.error("Connection failed to the host")
+
+
+ def get_version(self):
+ file_input = path+'/lib/pox/core.py'
+ version = super(PoxCliDriver, self).get_version()
+ pattern = '\s*self\.version(.*)'
+ import re
+ for line in open(file_input,'r').readlines():
+ result = re.match(pattern, line)
+ if result:
+ version = result.group(0)
+ version = re.sub("\s*self\.version\s*=\s*|\(|\)",'',version)
+ version = re.sub(",",'.',version)
+ version = "POX "+version
+
+
+ return version
+
+
+ def getcmd(self,options):
+ command = "./pox.py "
+ for item in options.keys():
+ if isinstance(options[item],dict):
+ command = command + item
+ for items in options[item].keys():
+ if options[item][items] == "None":
+ command = command + " --" + items + " "
+ else :
+ command = command + " --" + items + "=" + options[item][items] + " "
+ else:
+ if item == 'pox_lib_location':
+ poxLibPath = options[item]
+ elif item == 'type' or item == 'name':
+ pass
+ else :
+ command = command + item
+
+
+ return command
+
+
+if __name__ != "__main__":
+ import sys
+
+ sys.modules[__name__] = PoxCliDriver()
diff --git a/TestON/drivers/common/cli/emulator/remotemininetdriver.py b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
new file mode 100644
index 0000000..b55a371
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
@@ -0,0 +1,312 @@
+#!/usr/bin/env python
+'''
+Created on 26-Oct-2012
+
+@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
+
+
+ TestON is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ TestON is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+
+MininetCliDriver is the basic driver which will handle the Mininet functions
+'''
+
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import core.teston
+sys.path.append("../")
+from drivers.common.cli.emulatordriver import Emulator
+from drivers.common.clidriver import CLI
+from time import time
+
+class RemoteMininetDriver(Emulator):
+ '''
+ MininetCliDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(Emulator, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+ self.flag = 0
+
+ def connect(self, **connectargs):
+ #,user_name, ip_address, pwd,options):
+ # Here the main is the TestON instance after creating all the log handles.
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(RemoteMininetDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
+
+ self.ssh_handle = self.handle
+
+ # Copying the readme file to process the
+ if self.handle :
+ return main.TRUE
+
+ else :
+ main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
+ main.log.error("Failed to connect to the Mininet")
+ return main.FALSE
+
+ def pingLong(self,**pingParams):
+ args = utilities.parse_args(["SRC","TARGET"],**pingParams)
+ command = "mininet/util/m " + args["SRC"] + " ping "+args ["TARGET"]+" -i .1 -D -W 1 > /tmp/ping." + args["SRC"] + " &"
+ main.log.info( command )
+ self.execute(cmd=command,prompt="(.*)",timeout=10)
+ return main.TRUE
+
+ def pingstatus(self,**pingParams):
+ #self.handle.sendline("pgrep ping")
+ #self.handle.expect("pgrep")
+ #self.handle.expect("\$")
+ #result = self.handle.before + self.handle.after
+ #if re.search('\d\d+', result ):
+ # return main.TRUE
+ #else:
+ # return main.FALSE
+
+ args = utilities.parse_args(["SRC"],**pingParams)
+ self.handle.sendline("tail /tmp/ping." + args["SRC"])
+ self.handle.expect("tail")
+ self.handle.expect("\$")
+ result = self.handle.before + self.handle.after
+ if re.search('Unreachable', result ):
+ main.log.info("Unreachable found in ping logs...")
+ return main.FALSE
+ elif re.search('64\sbytes', result):
+ main.log.info("Pings look good")
+ return main.TRUE
+ else:
+ main.log.info("No, or faulty ping data...")
+ return main.FALSE
+
+ def pingKill(self):
+ command = "sudo pkill ping"
+ main.log.info( command )
+ self.execute(cmd=command,prompt="(.*)",timeout=10)
+ #command = "sudo pgrep ping"
+ #result1 = self.execute(cmd="\r",prompt="\$",timout=10)
+ #result = self.execute(cmd=command,prompt=self.user_name,timout=10)
+ #if utilities.assert_matches(expect='[^\s]+',actual=result,onpass="match",onfail="no match"):
+ # main.log.info( "pings running as process" )
+ # main.log.info( result )
+ # return main.FALSE
+ main.log.info( "Removing old ping data" )
+ command = "rm /tmp/ping.*"
+ os.popen(command)
+ import time
+ time.sleep(2)
+ main.log.info( "Transferring ping files to TestStation" )
+ command = "scp /tmp/ping.* admin@10.128.7.7:/tmp/"
+ self.execute(cmd=command,prompt="100%",timeout=20)
+ return main.TRUE
+
+ def pingHost(self,**pingParams):
+
+ args = utilities.parse_args(["SRC","TARGET"],**pingParams)
+ command = "mininet/util/m " + args["SRC"] + " ping "+args ["TARGET"]+" -c 4 -W 1 -i .2"
+ main.log.info ( command )
+ response = self.execute(cmd=command,prompt="rtt",timeout=10 )
+ if utilities.assert_matches(expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet loss",onfail="Host is not reachable"):
+ main.log.info("NO PACKET LOSS, HOST IS REACHABLE")
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.log.error("PACKET LOST, HOST IS NOT REACHABLE")
+ main.last_result = main.FALSE
+ return main.FALSE
+
+
+ def checknum(self,num):
+ '''
+ Verifies the correct number of switches are running
+ '''
+ if self.handle :
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline('ifconfig -a | grep "sw.. " | wc -l')
+ self.handle.expect("wc")
+ self.handle.expect("\$")
+ response = self.handle.before
+ self.handle.sendline('ps -ef | grep "bash -ms mininet:sw" | grep -v color | wc -l')
+ self.handle.expect("color")
+ self.handle.expect("\$")
+ response2 = self.handle.before
+
+ if re.search(num, response):
+ if re.search(num, response2):
+ return main.TRUE
+ else:
+ return main.FALSE
+ else:
+ return main.FALSE
+ else :
+ main.log.error("Connection failed to the host")
+
+ def ctrl_none(self):
+ self.execute(cmd="~/ONOS/scripts/test-ctrl-none.sh", prompt="\$",timeout=10)
+
+ def ctrl_one(self, ip):
+ self.execute(cmd="~/ONOS/scripts/test-ctrl-one.sh "+ip, prompt="\$",timeout=10)
+
+ def ctrl_local(self):
+ self.execute(cmd="~/ONOS/scripts/test-ctrl-local.sh ", prompt="\$",timeout=10)
+
+ # def verifySSH(self,**connectargs):
+ # response = self.execute(cmd="h1 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
+ # response = self.execute(cmd="h4 /usr/sbin/sshd -D&",prompt="mininet>",timeout=10)
+ # for key in connectargs:
+ # vars(self)[key] = connectargs[key]
+ # response = self.execute(cmd="xterm h1 h4 ",prompt="mininet>",timeout=10)
+ # import time
+ # time.sleep(20)
+ # if self.flag == 0:
+ # self.flag = 1
+ # return main.FALSE
+ # else :
+ # return main.TRUE
+ #
+ # def getMacAddress(self,host):
+ # '''
+ # Verifies the host's ip configured or not.
+ # '''
+ # if self.handle :
+ # response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
+
+ # pattern = "HWaddr\s(((\d|\w)+:)+(\d|\w))"
+ # mac_address_search = re.search(pattern, response)
+ # main.log.info("Mac-Address of Host "+host +" is "+mac_address_search.group(1))
+ # return mac_address_search.group(1)
+ # else :
+ # main.log.error("Connection failed to the host")
+ # def getIPAddress(self,host):
+ # '''
+ # Verifies the host's ip configured or not.
+ # '''
+ # if self.handle :
+ # response = self.execute(cmd=host+" ifconfig",prompt="mininet>",timeout=10)
+
+ # pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
+ # ip_address_search = re.search(pattern, response)
+ # main.log.info("IP-Address of Host "+host +" is "+ip_address_search.group(1))
+ # return ip_address_search.group(1)
+ # else :
+ # main.log.error("Connection failed to the host")
+ #
+ # def dump(self):
+ # main.log.info("Dump node info")
+ # self.execute(cmd = 'dump',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def intfs(self):
+ # main.log.info("List interfaces")
+ # self.execute(cmd = 'intfs',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def net(self):
+ # main.log.info("List network connections")
+ # self.execute(cmd = 'net',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def iperf(self):
+ # main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
+ # self.execute(cmd = 'iperf',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def iperfudp(self):
+ # main.log.info("Simple iperf TCP test between two (optionally specified) hosts")
+ # self.execute(cmd = 'iperfudp',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def nodes(self):
+ # main.log.info("List all nodes.")
+ # self.execute(cmd = 'nodes',prompt = 'mininet>',timeout = 10)
+ # return main.TRUE
+ #
+ # def pingpair(self):
+ # main.log.infoe("Ping between first two hosts")
+ # self.execute(cmd = 'pingpair',prompt = 'mininet>',timeout = 20)
+ #
+ # if utilities.assert_matches(expect='0% packet loss',actual=response,onpass="No Packet loss",onfail="Hosts not reachable"):
+ # main.log.info("Ping between two hosts SUCCESS")
+ # main.last_result = main.TRUE
+ # return main.TRUE
+ # else :
+ # main.log.error("PACKET LOST, HOSTS NOT REACHABLE")
+ # main.last_result = main.FALSE
+ # return main.FALSE
+ #
+ # def link(self,**linkargs):
+ # '''
+ # 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 ""
+ # command = "link "+str(end1) + " " + str(end2)+ " " + str(option)
+ # response = self.execute(cmd=command,prompt="mininet>",timeout=10)
+ # return main.TRUE
+ #
+
+ # def dpctl(self,**dpctlargs):
+ # '''
+ # Run dpctl command on all switches.
+ # '''
+ # main.log.info('Run dpctl command on all switches')
+ # args = utilities.parse_args(["CMD","ARGS"],**dpctlargs)
+ # cmd = args["CMD"] if args["CMD"] != None else ""
+ # cmdargs = args["ARGS"] if args["ARGS"] != None else ""
+ # command = "dpctl "+cmd + " " + str(cmdargs)
+ # response = self.execute(cmd=command,prompt="mininet>",timeout=10)
+ # return main.TRUE
+ #
+ #
+ # def get_version(self):
+ # file_input = path+'/lib/Mininet/INSTALL'
+ # version = super(Mininet, self).get_version()
+ # pattern = 'Mininet\s\w\.\w\.\w\w*'
+ # for line in open(file_input,'r').readlines():
+ # result = re.match(pattern, line)
+ # if result:
+ # version = result.group(0)
+ #
+ #
+ # return version
+
+ def disconnect(self):
+
+ response = ''
+ #print "Disconnecting Mininet"
+ if self.handle:
+ self.handle.sendline("exit")
+ self.handle.expect("exit")
+ self.handle.expect("(.*)")
+ response = self.handle.before
+
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
+if __name__ != "__main__":
+ import sys
+ sys.modules[__name__] = RemoteMininetDriver()