adding TestON
diff --git a/TestON/drivers/common/__init__.py b/TestON/drivers/common/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/__init__.py
diff --git a/TestON/drivers/common/api/__init__.py b/TestON/drivers/common/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/api/__init__.py
diff --git a/TestON/drivers/common/api/controller/__init__.py b/TestON/drivers/common/api/controller/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/api/controller/__init__.py
diff --git a/TestON/drivers/common/api/controllerdriver.py b/TestON/drivers/common/api/controllerdriver.py
new file mode 100644
index 0000000..f6b941f
--- /dev/null
+++ b/TestON/drivers/common/api/controllerdriver.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+'''
+Created on 29-Nov-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/>.
+
+'''
+import sys
+sys.path.append("../")
+from drivers.common.apidriver import API
+
+class Controller(API):
+ # The common functions for emulator included in emulatordriver
+ def __init__(self):
+ super(API, self).__init__()
+
diff --git a/TestON/drivers/common/api/fvtapidriver.py b/TestON/drivers/common/api/fvtapidriver.py
new file mode 100644
index 0000000..620b3e9
--- /dev/null
+++ b/TestON/drivers/common/api/fvtapidriver.py
@@ -0,0 +1,186 @@
+#!/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/>.
+
+
+fvtapidriver is the basic driver which will handle the fvtapidriver functions
+'''
+'''
+There are two changes required in flowvisor-test framework :
+
+1. In ~/flowvisortests/tests/templatetest.py line : 15 comment 'basic_logger = None'
+2. In ~/flowvisortests/tests/testutils.py line : 50 specify config file path CONFIG_FILE = "~/flowvisor-test/tests/tests-base.json"
+
+'''
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+sys.path.append("../")
+from common.apidriver import API
+import logging
+
+sys.path.append(path+"/lib/flowvisor-test/tests")
+sys.path.append(path+"/lib/flowvisor-test/src/python/")
+
+import templatetest
+import testutils
+import oftest.cstruct as ofp
+import oftest.message as message
+import oftest.parse as parse
+import oftest.action as action
+import oftest.error as error
+import socket
+import __builtin__
+
+config_default = {
+ "param" : None,
+ "fv_cmd" : "/home/openflow/flowvisor/scripts/flowvisor.sh",
+ "platform" : "local",
+ "controller_host" : "127.0.0.1",
+ "controller_port" : 6633,
+ "timeout" : 3,
+ "port_count" : 4,
+ "base_of_port" : 1,
+ "base_if_index" : 1,
+ "test_spec" : "all",
+ "test_dir" : ".",
+ "log_file" : "/home/openflow/fvt.log",
+ "list" : False,
+ "debug" : "debug",
+ "dbg_level" : logging.DEBUG,
+ "port_map" : {},
+ "test_params" : "None"
+}
+
+def test_set_init(config):
+ """
+ Set up function for basic test classes
+ @param config The configuration dictionary; see fvt
+ """
+ global basic_port_map
+ global basic_fv_cmd
+ global basic_logger
+ global basic_timeout
+ global basic_config
+ global baisc_logger
+
+ basic_fv_cmd = config["fv_cmd"]
+ basic_timeout = config["timeout"]
+ basic_port_map = config["port_map"]
+ basic_config = config
+
+class FvtApiDriver(API,templatetest.TemplateTest):
+
+ def __init__(self):
+ super(API, self).__init__()
+ print 'init'
+
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ connect_result = super(API,self).connect()
+ self.logFileName = main.logdir+"/"+self.name+".session"
+ config_default["log_file"] = self.logFileName
+ test_set_init(config_default)
+ __builtin__.basic_logger = vars(main)[self.name+'log']
+ __builtin__.basic_logger.info("Calling my test setup")
+ self.setUp(basic_logger)
+
+ (self.fv, self.sv, sv_ret, ctl_ret, sw_ret) = testutils.setUpTestEnv(self, fv_cmd=basic_fv_cmd)
+
+ self.chkSetUpCondition(self.fv, sv_ret, ctl_ret, sw_ret)
+ return main.TRUE
+
+ def simplePacket(self,dl_src):
+ dl_src = vars(testutils)[dl_src]
+ return testutils.simplePacket(dl_src = dl_src)
+
+ def genPacketIn(self, in_port, pkt):
+ return testutils.genPacketIn(in_port=in_port, pkt=pkt)
+
+ def ofmsgSndCmp(self, snd_list, exp_list, xid_ignore=True, hdr_only=True):
+ return testutils.ofmsgSndCmp(self, snd_list, exp_list, xid_ignore, hdr_only)
+
+ def setRule(self,sv,rule,num_try) :
+ return testutils.setRule(self,sv,rule,num_try)
+
+ def chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites) :
+ return testutils.chkFlowdb(self,controller_number,switch_number,exp_count,exp_rewrites)
+
+ def chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count):
+ return testutils.chkSwitchStats(self, switch_number, ofproto, exp_snd_count, exp_rcv_count)
+
+ def chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count) :
+ return testutils.chkSliceStats(self,controller_number,ofproto,exp_snd_count,exp_rcv_count)
+
+ def recvStats(self,swId,typ) :
+ return testutils.recvStats(self,swId,typ)
+
+ def ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only) :
+ return testutils.ofmsgSndCmpWithXid(self,snd_list,exp_list,xid_ignore,hdr_only)
+
+ def genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt) :
+ return testutils.genPacketOut(self,xid,buffer_id,in_port,action_ports,pkt)
+
+ def genFlowModFlush(self) :
+ return testutils.genFlowModFlush()
+
+ def genPhyPort(self,name,addr,port_no) :
+ return testutils.genPhyPort(name,addr,port_no)
+
+ def disconnect(self,handle):
+ response = ''
+ '''
+ if self.handle:
+ self.handle = handle
+ response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ '''
+ return response
+
+ def setUp(self,basic_logger):
+ self.logger = basic_logger
+ #basic_logger.info("** START TEST CASE " + str(self))
+ if basic_timeout == 0:
+ self.timeout = None
+ else:
+ self.timeout = basic_timeout
+ self.fv = None
+ self.sv = None
+ self.controllers = []
+ self.switches = []
+
+ def close_log_handles(self) :
+ self.tearDown()
+ vars(main)[self.name+'log'].removeHandler(self.log_handler)
+ #if self.logfile_handler:
+ # self.logfile_handler.close()
+
+ return main.TRUE
+
+
diff --git a/TestON/drivers/common/api/onosapi/__init__.py b/TestON/drivers/common/api/onosapi/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/api/onosapi/__init__.py
diff --git a/TestON/drivers/common/api/onosrestapidriver.py b/TestON/drivers/common/api/onosrestapidriver.py
new file mode 100644
index 0000000..31a8930
--- /dev/null
+++ b/TestON/drivers/common/api/onosrestapidriver.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python
+'''
+Created on 4-Jun-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/>.
+
+
+onosrestapidriver is the basic driver which will handle the onorestapi functions
+'''
+
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import time
+
+sys.path.append("../")
+from drivers.common.apidriver import API
+import urllib
+import __builtin__
+
+
+class OnosRestApiDriver(API):
+
+ def __init__(self):
+ super(API, self).__init__()
+
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(OnosRestApiDriver,self).connect()
+ main.log.info(self.options['topology_url'])
+ try :
+ self.handle = urllib.urlopen(self.options['topology_url'])
+ except Exception,e:
+ main.log.error(e)
+
+ self.logFileName = main.logdir+"/"+self.name+".session"
+
+ if self.handle:
+ return self.handle
+ else :
+ return main.FALSE
+
+ def execute(self):
+ main.log.info(self.options['topology_url'])
+ response = main.FALSE
+ for i in [1,2] :
+ time.sleep(2)
+ response = self.http_request()
+ return response
+
+ def http_request(self):
+ try :
+ self.handle = urllib.urlopen(self.options['topology_url'])
+
+ resonse_lines = self.handle.readlines()
+ print resonse_lines
+ return resonse_lines
+ except Exception,e:
+ main.log.error(e)
+ return "url error"
+
+ def disconnect(self,handle):
+ response = ''
+ '''
+ if self.handle:
+ self.handle = handle
+ response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ '''
+ return response
+
+
+
+
diff --git a/TestON/drivers/common/apidriver.py b/TestON/drivers/common/apidriver.py
new file mode 100644
index 0000000..254ab1b
--- /dev/null
+++ b/TestON/drivers/common/apidriver.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+'''
+Created on 22-Nov-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/>.
+
+
+'''
+
+import struct, fcntl, os, sys, signal
+import sys, re
+sys.path.append("../")
+
+from drivers.component import Component
+class API(Component):
+ '''
+ This will define common functions for CLI included.
+ '''
+ def __init__(self):
+ super(Component, self).__init__()
+
+ def connect(self):
+ '''
+ Connection will establish to the remote host using ssh.
+ It will take user_name ,ip_address and password as arguments<br>
+ and will return the handle.
+ '''
+ super(API, self).connect()
+
+ return main.TRUE
diff --git a/TestON/drivers/common/cli/__init__.py b/TestON/drivers/common/cli/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/__init__.py
diff --git a/TestON/drivers/common/cli/cassandraclidriver.py b/TestON/drivers/common/cli/cassandraclidriver.py
new file mode 100644
index 0000000..0b43d32
--- /dev/null
+++ b/TestON/drivers/common/cli/cassandraclidriver.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+'''
+Created on 31-May-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/>.
+
+
+CassandraCliDriver is the basic driver which will handle the Cassandra functions
+'''
+
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import core.teston
+import time
+
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class CassandraCliDriver(CLI):
+ '''
+ CassandraCliDriver is the basic driver which will handle the Cassandra's functions
+ '''
+ def __init__(self):
+ super(CLI, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+
+ def connect(self, **connectargs):
+ # Here the main is the TestON instance after creating all the log handles.
+ self.port = None
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(CassandraCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ self.ssh_handle = self.handle
+ if self.handle :
+ self.start()
+ 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 Onos system")
+ return main.FALSE
+
+
+ def start(self):
+ ''' This Function will start the Cassandra'''
+ main.log.info( "Starting Cassandra" )
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("~/ONOS/start-cassandra.sh start")
+ self.handle.expect("start-cassandra.sh start")
+ self.handle.expect("\$")
+ response = self.handle.before + self.handle.after
+ time.sleep(5)
+ if re.search("Starting\scassandra(.*)", response):
+ main.log.info("Cassandra Started ")
+ return main.TRUE
+ else:
+ main.log.error("Failed to start Cassandra"+ response)
+ return main.FALSE
+
+ def status(self):
+ '''This Function will return the Status of the Cassandra '''
+ time.sleep(5)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ response = self.execute(cmd="~/ONOS/start-cassandra.sh status ",prompt="\d+\sinstance\sof\scassandra\srunning(.*)",timeout=10)
+
+
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ return response
+
+ if re.search("0\sinstance\sof\scassandra\srunning(.*)") :
+ main.log.info("Cassandra not running")
+ return main.TRUE
+ elif re.search("1\sinstance\sof\scassandra\srunning(.*)"):
+ main.log.warn("Cassandra Running")
+ return main.TRUE
+
+ def stop(self):
+ '''This Function will stop the Cassandra if it is Running'''
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ time.sleep(5)
+ response = self.execute(cmd="~/ONOS/start-cassandra.sh stop ",prompt="Killed\sexisting\sprosess(.*)",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ if re.search("Killed\sexisting\sprosess(.*)",response):
+ main.log.info("Cassandra Stopped")
+ return main.TRUE
+ else:
+ main.log.warn("Cassndra is not Running")
+ return main.FALSE
+
+ def disconnect(self):
+
+ response = ''
+ if self.handle:
+ self.handle.sendline("exit")
+ self.handle.expect("closed")
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
+ def isup(self):
+ tries = 5
+ main.log.info("trying %i times" % tries )
+ for i in range(tries):
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("~/ONOS/start-cassandra.sh status")
+ self.handle.expect("sh status")
+ self.handle.expect("\$")
+ result = self.handle.before + self.handle.after
+ pattern = '(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)\n(.*)Up(.*)Normal(.*)'
+ if re.search(pattern, result):
+ return main.TRUE
+ return main.FALSE
diff --git a/TestON/drivers/common/cli/check_status.py b/TestON/drivers/common/cli/check_status.py
new file mode 100755
index 0000000..c725cec
--- /dev/null
+++ b/TestON/drivers/common/cli/check_status.py
@@ -0,0 +1,111 @@
+#! /usr/bin/env python
+import json
+import os
+import sys
+
+# http://localhost:8080/wm/core/topology/switches/all/json
+# http://localhost:8080/wm/core/topology/links/json
+# http://localhost:8080/wm/registry/controllers/json
+# http://localhost:8080/wm/registry/switches/json"
+
+def get_json(url):
+ try:
+ command = "curl -s %s" % (url)
+ result = os.popen(command).read()
+ parsedResult = json.loads(result)
+ except:
+ print "REST IF %s has issue" % command
+ parsedResult = ""
+
+ if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
+ print "REST %s returned code %s" % (command, parsedResult['code'])
+ parsedResult = ""
+
+ return parsedResult
+
+def check_switch(RestIP,correct_nr_switch ):
+ buf = ""
+ retcode = 0
+ RestPort="8080"
+
+ url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort)
+ parsedResult = get_json(url)
+
+ if parsedResult == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+
+ url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
+ registry = get_json(url)
+
+ if registry == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+
+
+ buf += "switch: total %d switches\n" % len(parsedResult)
+ cnt = 0
+ active = 0
+
+ for s in parsedResult:
+ cnt += 1
+
+ if s['state'] == "ACTIVE":
+ active += 1
+
+ if not s['dpid'] in registry:
+ buf += "switch: dpid %s lost controller\n" % (s['dpid'])
+
+ buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
+ if correct_nr_switch != cnt:
+ buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
+ retcode = 1
+
+ if correct_nr_switch != active:
+ buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
+ retcode = 1
+
+ return (retcode, buf)
+
+def check_link(RestIP, nr_links):
+ RestPort = "8080"
+ buf = ""
+ retcode = 0
+
+ url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
+ parsedResult = get_json(url)
+
+ if parsedResult == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+
+ buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
+ intra = 0
+ interlink=0
+
+ for s in parsedResult:
+ intra = intra + 1
+
+ if intra != nr_links:
+ buf += "link fail: network %d should have %d intra links but has %d\n" % (1, nr_links, intra)
+ retcode = 1
+
+ return (retcode, buf)
+
+#if __name__ == "__main__":
+def check_status(ip, numoswitch, numolink):
+
+ switch = check_switch(ip, numoswitch)
+ link = check_link(ip, numolink)
+ value = switch[0]
+ value += link[0]
+ if value != 0:
+ print "FAIL"
+ return 0
+ else:
+ print "PASS"
+ return 1
+ print "%s" % switch[1]
+ print "%s" % link[1]
+ # print "%s" % check_switch_local()[1]
+ # print "%s" % check_controllers(8)[1]
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()
diff --git a/TestON/drivers/common/cli/emulatordriver.py b/TestON/drivers/common/cli/emulatordriver.py
new file mode 100644
index 0000000..b561e9c
--- /dev/null
+++ b/TestON/drivers/common/cli/emulatordriver.py
@@ -0,0 +1,32 @@
+#!/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/>.
+
+
+'''
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class Emulator(CLI):
+ # The common functions for emulator included in emulatordriver
+ def __init__(self):
+ super(CLI, self).__init__()
+
diff --git a/TestON/drivers/common/cli/onoscli/__init__.py b/TestON/drivers/common/cli/onoscli/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/onoscli/__init__.py
diff --git a/TestON/drivers/common/cli/onosclidriver.py b/TestON/drivers/common/cli/onosclidriver.py
new file mode 100644
index 0000000..670a492
--- /dev/null
+++ b/TestON/drivers/common/cli/onosclidriver.py
@@ -0,0 +1,608 @@
+#!/usr/bin/env python
+'''
+Created on 31-May-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/>.
+
+
+'''
+import time
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+import re
+import json
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class OnosCliDriver(CLI):
+
+ def __init__(self):
+ super(CLI, self).__init__()
+
+ def connect(self,**connectargs):
+ '''
+ Creates ssh handle for ONOS.
+ '''
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+
+ self.name = self.options['name']
+ self.handle = super(OnosCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ if self.handle:
+ #self.start()
+ #self.start_rest()
+ return self.handle
+ else :
+ main.log.info("NO HANDLE")
+ return main.FALSE
+
+ def start(self):
+ '''
+ Starts ONOS on remote machine.
+ Returns false if any errors were encountered.
+ '''
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("cd ~/ONOS")
+ self.handle.expect("ONOS\$")
+ self.handle.sendline("./start-onos.sh start")
+ i=self.handle.expect(["Starting\sONOS\scontroller","Cassandra\sis\snot\srunning"])
+ if i==0:
+ if self.handle.expect("ONOS\$", 60):
+ main.log.info("ONOS Started ")
+ return main.TRUE
+ else:
+ main.log.info("ONOS NOT Started, stuck while waiting for it to start ")
+ return main.FALSE
+ elif i==1:
+ main.log.error("ONOS didn't start because cassandra wasn't running.")
+ return main.FALSE
+
+ main.log.error("ONOS expect script missed something... ")
+ return main.FALSE
+
+ def link_down(self, **linkParams):
+ '''
+ Specifically used for the ONOS demo on the HW.
+ Should be replaced by actual switch drivers in the future.
+ '''
+ args = utilities.parse_args(["SDPID","SPORT","DDPID","DPORT"], **linkParams)
+ sdpid = args["SDPID"] if args["SDPID"] != None else "00:00:00:00:ba:5e:ba:13"
+ sport = args["SPORT"] if args["SPORT"] != None else "22"
+ ddpid = args["DDPID"] if args["DDPID"] != None else "00:00:20:4e:7f:51:8a:35"
+ dport = args["DPORT"] if args["DPORT"] != None else "22"
+
+ cmd = "curl -s 10.128.4.11:9000/gui/link/down/" + sdpid + "/" + sport + "/" + ddpid + "/" + dport + " > /tmp/log &"
+ os.popen( cmd )
+
+ def link_up(self, **linkParams):
+ '''
+ Specifically used for the ONOS demo on the HW.
+ Should be replaced by actual switch drivers in the future.
+ '''
+ args = utilities.parse_args(["SDPID","SPORT","DDPID","DPORT"], **linkParams)
+ sdpid = args["SDPID"] if args["SDPID"] != None else "00:00:00:00:ba:5e:ba:13"
+ sport = args["SPORT"] if args["SPORT"] != None else "22"
+ ddpid = args["DDPID"] if args["DDPID"] != None else "00:00:20:4e:7f:51:8a:35"
+ dport = args["DPORT"] if args["DPORT"] != None else "22"
+
+ cmd = "curl -s 10.128.4.11:9000/gui/link/up/" + sdpid + "/" + sport + "/" + ddpid + "/" + dport + " > /tmp/log &"
+ os.popen( cmd )
+
+ def start_rest(self):
+ '''
+ Starts the rest server on ONOS.
+ '''
+ self.execute(cmd="cd ONOS",prompt="ONOS\$",timeout=10)
+ response = self.execute(cmd="start-rest.sh start",prompt="\$",timeout=10)
+ if re.search("admin",response):
+ main.log.info("Rest Server Started Successfully")
+ time.sleep(5)
+ return main.TRUE
+ else :
+ main.log.warn("Failed to start Rest Server")
+ return main.FALSE
+
+ def status(self):
+ '''
+ Called start-onos.sh status and returns TRUE/FALSE accordingly
+ '''
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ response = self.execute(cmd="~/ONOS/start-onos.sh status ",prompt="\d+\sinstance\sof\sonos\srunning",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ if re.search("1\sinstance\sof\sonos\srunning",response):
+ return main.TRUE
+ elif re.search("0\sinstance\sof\sonos\srunning",response):
+ return main.FALSE
+ else :
+ return main.FALSE
+
+ def isup(self):
+ '''
+ A more complete check to see if ONOS is up and running properly.
+ First, it checks if the process is up.
+ Second, it reads the logs for "Exception: Connection refused"
+ Third, it makes sure the logs are actually moving.
+ returns TRUE/FALSE accordingly.
+ '''
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ response = self.execute(cmd="~/ONOS/start-onos.sh status ",prompt="running",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ tail1 = self.execute(cmd="tail ~/ONOS/onos-logs/onos.*.log",prompt="\$",timeout=10)
+ time.sleep(2)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ tail2 = self.execute(cmd="tail ~/ONOS/onos-logs/onos.*.log",prompt="\$",timeout=10)
+ pattern = '(.*)1 instance(.*)'
+ pattern2 = '(.*)Exception: Connection refused(.*)'
+ if utilities.assert_matches(expect=pattern,actual=response,onpass="ONOS process is running...",onfail="ONOS process not running..."):
+ if tail1 == tail2:
+ main.log.error("ONOS is frozen...")
+ return main.FALSE
+ elif re.search( pattern2,tail1 ):
+ main.log.info("Connection Refused found in onos log")
+ return main.FALSE
+ elif re.search( pattern2,tail2 ):
+ main.log.info("Connection Refused found in onos log")
+ return main.FALSE
+ else:
+ main.log.info("Onos log is moving! It's looking good!")
+ return main.TRUE
+ else:
+ return main.FALSE
+
+
+ def rest_status(self):
+ '''
+ Checks if the rest server is running.
+ '''
+ response = self.execute(cmd="~/ONOS/start-rest.sh status ",prompt="running",timeout=10)
+ if re.search("rest\sserver\sis\srunning",response):
+ main.log.info("Rest Server is running")
+ elif re.search("rest\sserver\sis\snot\srunning",response):
+ main.log.warn("Rest Server is not Running")
+ else :
+ main.log.error("No response" +response)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+
+ return response
+
+ def stop(self):
+ '''
+ Runs ./start-onos.sh stop to stop ONOS
+ '''
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("cd ~/ONOS")
+ self.handle.expect("ONOS\$")
+ self.handle.sendline("./start-onos.sh stop")
+ self.handle.expect("stop", 2)
+ self.handle.expect("ONOS\$", 60)
+ if re.search("Killed",response):
+ main.log.info("ONOS Killed Successfully")
+ return main.TRUE
+ else :
+ main.log.warn("ONOS wasn't running")
+ return main.FALSE
+
+ def rest_stop(self):
+ '''
+ Runs ./start-rest.sh stop to stop ONOS rest server
+ '''
+ response = self.execute(cmd="~/ONOS/start-rest.sh stop ",prompt="killing",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ if re.search("killing", response):
+ main.log.info("Rest Server Stopped")
+ return main.TRUE
+ else :
+ main.log.error("Failed to Stop, Rest Server is not Running")
+ return main.FALSE
+
+ def disconnect(self):
+ '''
+ Called when Test is complete to dissconnect the ONOS handle.
+ '''
+ if self.handle:
+ self.handle.sendline("exit")
+ self.handle.expect("closed")
+ if self.handle.isalive():
+ response = main.TRUE
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
+ def get_version(self):
+ '''
+ Writes the COMMIT number to the report to be parsed by Jenkins data collecter.
+ '''
+ self.handle.sendline("cat /home/admin/ONOS/.git/ORIG_HEAD")
+ self.handle.expect("ORIG_HEAD")
+ self.handle.expect("\$")
+ main.log.report( "COMMIT: " + str(self.handle.before + self.handle.after))
+
+ def add_flow(self, path):
+ '''
+ Copies the flowdef file from TestStation -> ONOS machine
+ Then runs ./add_flow.py to add the flows to ONOS
+ '''
+ main.log.info("Adding Flows...")
+ self.handle.sendline("scp admin@10.128.7.7:%s /tmp/flowtmp" % path)
+ self.handle.expect("100%")
+ self.handle.expect("\$", 30)
+ self.handle.sendline("~/ONOS/web/add_flow.py -m onos -f /tmp/flowtmp")
+ self.handle.expect("add_flow")
+ self.handle.expect("\$", 1000)
+ main.log.info("Flows added")
+
+ def delete_flow(self, *delParams):
+ '''
+ Deletes a specific flow, a range of flows, or all flows.
+ '''
+ if len(delParams)==1:
+ if str(delParams[0])=="all":
+ main.log.info("Deleting ALL flows...")
+ #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh all",prompt="done",timeout=150)
+ self.handle.sendline("~/ONOS/web/delete_flow.py all")
+ self.handle.expect("delete_flow")
+ self.handle.expect("\$",1000)
+ self.handle.sendline("~/ONOS/web/clear_flow.py all")
+ self.handle.expect("clear_flow")
+ self.handle.expect("\$",1000)
+ main.log.info("Flows deleted")
+ else:
+ main.log.info("Deleting flow "+str(delParams[0])+"...")
+ #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0]),prompt="done",timeout=150)
+ #self.execute(cmd="\n",prompt="\$",timeout=60)
+ self.handle.sendline("~/ONOS/web/delete_flow.py %d" % int(delParams[0]))
+ self.handle.expect("delete_flow")
+ self.handle.expect("\$",60)
+ self.handle.sendline("~/ONOS/web/clear_flow.py %d" % int(delParams[0]))
+ self.handle.expect("clear_flow")
+ self.handle.expect("\$",60)
+ main.log.info("Flow deleted")
+ elif len(delParams)==2:
+ main.log.info("Deleting flows "+str(delParams[0])+" through "+str(delParams[1])+"...")
+ #self.execute(cmd="~/ONOS/scripts/TestON_delete_flow.sh "+str(delParams[0])+" "+str(delParams[1]),prompt="done",timeout=150)
+ #self.execute(cmd="\n",prompt="\$",timeout=60)
+ self.handle.sendline("~/ONOS/web/delete_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
+ self.handle.expect("delete_flow")
+ self.handle.expect("\$",600)
+ self.handle.sendline("~/ONOS/web/clear_flow.py %d %d" % (int(delParams[0]), int(delParams[1])))
+ self.handle.expect("clear_flow")
+ self.handle.expect("\$",600)
+ main.log.info("Flows deleted")
+
+ def check_flow(self):
+ '''
+ Calls the ./get_flow.py all and checks:
+ - If each FlowPath has at least one FlowEntry
+ - That there are no "NOT"s found
+ returns TRUE/FALSE
+ '''
+ flowEntryDetect = 1
+ count = 0
+ self.handle.sendline("clear")
+ time.sleep(1)
+ self.handle.sendline("~/ONOS/web/get_flow.py all")
+ self.handle.expect("get_flow")
+ while 1:
+ i=self.handle.expect(['FlowPath','FlowEntry','NOT','\$',pexpect.TIMEOUT],timeout=180)
+ if i==0:
+ count = count + 1
+ if flowEntryDetect == 0:
+ main.log.info("FlowPath without FlowEntry")
+ return main.FALSE
+ else:
+ flowEntryDetect = 0
+ elif i==1:
+ flowEntryDetect = 1
+ elif i==2:
+ main.log.error("Found a NOT")
+ return main.FALSE
+ elif i==3:
+ if count == 0:
+ main.log.info("There don't seem to be any flows here...")
+ return main.FALSE
+ else:
+ main.log.info("All flows pass")
+ main.log.info("Number of FlowPaths: "+str(count))
+ return main.TRUE
+ elif i==4:
+ main.log.error("Command Timeout!")
+ return main.FALSE
+
+ def get_flow(self, *flowParams):
+ '''
+ Returns verbose output of ./get_flow.py
+ '''
+ if len(flowParams)==1:
+ if str(flowParams[0])=="all":
+ self.execute(cmd="\n",prompt="\$",timeout=60)
+ main.log.info("Getting all flow data...")
+ data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh all",prompt="done",timeout=150)
+ self.execute(cmd="\n",prompt="\$",timeout=60)
+ return data
+ else:
+ main.log.info("Retrieving flow "+str(flowParams[0])+" data...")
+ data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0]),prompt="done",timeout=150)
+ self.execute(cmd="\n",prompt="\$",timeout=60)
+ return data
+ elif len(flowParams)==5:
+ main.log.info("Retrieving flow installer data...")
+ data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3])+" "+str(flowParams[4]),prompt="done",timeout=150)
+ self.execute(cmd="\n",prompt="\$",timeout=60)
+ return data
+ elif len(flowParams)==4:
+ main.log.info("Retrieving flow endpoints...")
+ data = self.execute(cmd="~/ONOS/scripts/TestON_get_flow.sh "+str(flowParams[0])+" "+str(flowParams[1])+" "+str(flowParams[2])+" "+str(flowParams[3]),prompt="done",timeout=150)
+ self.execute(cmd="\n",prompt="\$",timeout=60)
+ return data
+
+
+# http://localhost:8080/wm/core/topology/switches/all/json
+# http://localhost:8080/wm/core/topology/links/json
+# http://localhost:8080/wm/registry/controllers/json
+# http://localhost:8080/wm/registry/switches/json"
+
+ def get_json(self, url):
+ '''
+ Helper functions used to parse the json output of a rest call
+ '''
+ try:
+ command = "curl -s %s" % (url)
+ result = os.popen(command).read()
+ parsedResult = json.loads(result)
+ except:
+ print "REST IF %s has issue" % command
+ parsedResult = ""
+
+ if type(parsedResult) == 'dict' and parsedResult.has_key('code'):
+ print "REST %s returned code %s" % (command, parsedResult['code'])
+ parsedResult = ""
+ return parsedResult
+
+ def check_switch(self,RestIP,correct_nr_switch ):
+ '''
+ Used by check_status
+ '''
+ buf = ""
+ retcode = 0
+ RestPort="8080"
+ url="http://%s:%s/wm/core/topology/switches/all/json" % (RestIP, RestPort)
+ parsedResult = self.get_json(url)
+ if parsedResult == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+ url = "http://%s:%s/wm/registry/switches/json" % (RestIP, RestPort)
+ registry = self.get_json(url)
+
+ if registry == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+
+ cnt = 0
+ active = 0
+
+ for s in parsedResult:
+ cnt += 1
+ if s['state'] == "ACTIVE":
+ active += 1
+
+ buf += "switch: network %d : %d switches %d active\n" % (0+1, cnt, active)
+ if correct_nr_switch != cnt:
+ buf += "switch fail: network %d should have %d switches but has %d\n" % (1, correct_nr_switch, cnt)
+ retcode = 1
+
+ if correct_nr_switch != active:
+ buf += "switch fail: network %d should have %d active switches but has %d\n" % (1, correct_nr_switch, active)
+ retcode = 1
+
+ return (retcode, buf)
+
+ def check_link(self,RestIP, nr_links):
+ '''
+ Used by check_status
+ '''
+ RestPort = "8080"
+ buf = ""
+ retcode = 0
+
+ url = "http://%s:%s/wm/core/topology/links/json" % (RestIP, RestPort)
+ parsedResult = self.get_json(url)
+
+ if parsedResult == "":
+ retcode = 1
+ return (retcode, "Rest API has an issue")
+
+ buf += "link: total %d links (correct : %d)\n" % (len(parsedResult), nr_links)
+ intra = 0
+ interlink=0
+
+ for s in parsedResult:
+ intra = intra + 1
+
+ if intra != nr_links:
+ buf += "link fail\n"
+ retcode = 1
+
+ return (retcode, buf)
+
+ def check_status_report(self, ip, numoswitch, numolink):
+ '''
+ Checks the number of swithes & links that ONOS sees against the supplied values.
+ Writes to the report log.
+ '''
+ main.log.info("Making some rest calls...")
+ switch = self.check_switch(ip, int(numoswitch))
+ link = self.check_link(ip, int(numolink))
+ value = switch[0]
+ value += link[0]
+ main.log.report( "\n-----\n%s%s-----\n" % ( switch[1], link[1]) )
+ if value != 0:
+ return 0
+ else:
+ # "PASS"
+ return 1
+
+ def check_status(self, ip, numoswitch, numolink):
+ '''
+ Checks the number of swithes & links that ONOS sees against the supplied values.
+ Writes to the main log.
+ '''
+ main.log.info("Making some rest calls...")
+ switch = self.check_switch(ip, int(numoswitch))
+ link = self.check_link(ip, int(numolink))
+ value = switch[0]
+ value += link[0]
+ main.log.info( "\n-----\n%s%s-----\n" % ( switch[1], link[1]) )
+ if value != 0:
+ return 0
+ else:
+ # "PASS"
+ return 1
+
+ def drop_keyspace(self):
+ '''
+ Drops the ONOS keyspace
+ '''
+ self.handle.sendline("~/ONOS/scripts/test-drop-keyspace.sh")
+ self.handle.expect("keyspace")
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.expect("\$")
+
+ def ctrl_none(self):
+ '''
+ Points all the mininet swithces to no controllers
+ *NOTE will only work if CLUSTER is set up on ONOS nodes
+ '''
+ self.execute(cmd="switch none", prompt="\$",timeout=10)
+
+ def ctrl_one(self, ip):
+ '''
+ Points all the mininet swithces to all controllers
+ *NOTE will only work if CLUSTER is set up on ONOS nodes
+ '''
+ self.execute(cmd="switch one", prompt="\$",timeout=10)
+
+ def check_for_no_exceptions(self):
+ '''
+ Used by CassndraCheck.py to scan ONOS logs for Exceptions
+ '''
+ self.handle.sendline(r"dsh 'grep Exception ~/ONOS/onos-logs/onos.*.log'")
+ self.handle.expect("\$ dsh")
+ self.handle.expect("\$")
+ output = self.handle.before
+ main.log.info( output )
+ if re.search("Exception",output):
+ return main.FALSE
+ else :
+ return main.TRUE
+
+ def git_pull(self):
+ '''
+ Stops the ONOS, pulls the latest code, and builds with mvn.
+ Assumes that "git pull" works without login
+ '''
+ main.log.info("Stopping onos")
+ self.stop()
+ self.handle.sendline("cd ~/ONOS")
+ self.handle.expect("ONOS\$")
+ self.handle.sendline("git pull")
+
+ i=self.handle.expect(['fatal','Username\sfor\s(.*):\s','Unpacking\sobjects',pexpect.TIMEOUT,'Already up-to-date','Aborting'],timeout=180)
+ if i==0:
+ main.log.error("Git pull had some issue...")
+ return main.FALSE
+ elif i==1:
+ main.log.error("Asking for username!!! BADD!")
+ return false
+
+ self.handle.expect('Password\sfor\s(.*):\s')
+ j = self.handle.expect(['Unpacking\sobjects','Already up-to-date'])
+ if j == 0:
+ main.log.info("pulling repository now")
+ elif j == 1:
+ main.log.info("Up to date!")
+ else:
+ main.log.error("something went wrong")
+ return main.FALSE
+ self.handle.expect("ONOS\$", 30)
+ elif i==2:
+ main.log.info("pulling repository now")
+ self.handle.expect("ONOS\$", 30)
+ elif i==3:
+ main.log.error("TIMEOUT")
+ return main.FALSE
+ elif i==4:
+ main.log.info("Already up to date")
+ elif i==5:
+ main.log.info("Aborting... Are there conflicting git files?")
+ return main.FALSE
+
+
+ main.log.info("./setup-local-maven.sh")
+ self.handle.sendline("./setup-local-maven.sh")
+ self.handle.expect("local-maven.sh")
+ while 1:
+ i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=90)
+ if i == 0:
+ main.log.error("Build failure!")
+ return main.FALSE
+ elif i == 1:
+ main.log.info("Build success!")
+ elif i == 2:
+ main.log.info("Build complete")
+ break;
+ elif i == 3:
+ main.log.error("TIMEOUT!")
+ return main.FALSE
+
+ main.log.info("mvn clean")
+ self.handle.sendline("mvn clean")
+ while 1:
+ i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
+ if i == 0:
+ main.log.error("Build failure!")
+ return main.FALSE
+ elif i == 1:
+ main.log.info("Build success!")
+ elif i == 2:
+ main.log.info("Build complete")
+ break;
+ elif i == 3:
+ main.log.error("TIMEOUT!")
+ return main.FALSE
+
+ main.log.info("mvn compile")
+ self.handle.sendline("mvn compile")
+ while 1:
+ i=self.handle.expect(['BUILD\sFAILURE','BUILD\sSUCCESS','ONOS\$',pexpect.TIMEOUT],timeout=30)
+ if i == 0:
+ main.log.error("Build failure!")
+ return main.FALSE
+ elif i == 1:
+ main.log.info("Build success!")
+ elif i == 2:
+ main.log.info("Build complete")
+ break;
+ elif i == 3:
+ main.log.error("TIMEOUT!")
+ return main.FALSE
+
diff --git a/TestON/drivers/common/cli/remotesys/__init__.py b/TestON/drivers/common/cli/remotesys/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/remotesys/__init__.py
diff --git a/TestON/drivers/common/cli/remotesysdriver.py b/TestON/drivers/common/cli/remotesysdriver.py
new file mode 100644
index 0000000..ab11f6a
--- /dev/null
+++ b/TestON/drivers/common/cli/remotesysdriver.py
@@ -0,0 +1,55 @@
+#!/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/>.
+
+
+'''
+import time
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class RemoteSysDriver(CLI):
+ # The common functions for emulator included in emulatordriver
+ def __init__(self):
+ super(CLI, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(RemoteSysDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+ '''
+ if self.handle:
+ self.execute(cmd= "\r",prompt= "\$|>|#",timeout= 10)
+ self.execute(cmd= "ssh -l paxterra 10.128.4.1",prompt= "paxterra@10.128.4.1's password:",timeout= 10)
+ self.execute(cmd= "\r",prompt= "paxterra@10.128.4.1's password:",timeout= 10)
+ self.execute(cmd = "0nLab_gu3st",prompt = "\$",timeout = 10)
+ self.execute(cmd = "cd TestON/bin/",prompt = "\$",timeout = 10)
+ self.execute(cmd = "./cli.py run Assert example 1",prompt = "\$",timeout = 10)
+ self.execute(cmd= "\r",prompt= "$",timeout= 10)
+ #self.execute(cmd = "help",prompt = ">",timeout = 10)
+
+ #self.execute(cmd = "~.",prompt= ".*",timeout= 10)
+ return main.TRUE
+ '''
+
diff --git a/TestON/drivers/common/cli/remotetestbed/__init__.py b/TestON/drivers/common/cli/remotetestbed/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/__init__.py
diff --git a/TestON/drivers/common/cli/remotetestbed/floodlightclidriver.py b/TestON/drivers/common/cli/remotetestbed/floodlightclidriver.py
new file mode 100644
index 0000000..8b25b2f
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/floodlightclidriver.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+'''
+Created on 12-Feb-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/>.
+
+
+FloodLightCliDriver 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 time
+
+sys.path.append("../")
+
+from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver
+
+class FloodLightCliDriver(RemoteTestBedDriver):
+ '''
+ FloodLightCliDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(RemoteTestBedDriver, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(FloodLightCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+ if self.handle :
+ main.log.info("Connected "+self.name)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ self.execute(cmd="cd /home/openflow/floodlight/",prompt="floodlight\$",timeout=3)
+ self.execute(cmd="java -jar target/floodlight.jar &",prompt="\$",timeout=3)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ return self.handle
+ else :
+ return main.FALSE
diff --git a/TestON/drivers/common/cli/remotetestbed/flowvisorclidriver.py b/TestON/drivers/common/cli/remotetestbed/flowvisorclidriver.py
new file mode 100644
index 0000000..936ce9d
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/flowvisorclidriver.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+'''
+Created on 12-Feb-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/>.
+
+
+FlowVisorCliDriver 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 time
+
+sys.path.append("../")
+
+from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver
+
+class FlowVisorCliDriver(RemoteTestBedDriver):
+ '''
+ FlowVisorCliDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(RemoteTestBedDriver, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(FlowVisorCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+ if self.handle :
+ main.log.info(self.name+" connected successfully")
+ return self.handle
+ else :
+ main.log.error("Failed to connect "+self.name)
+ 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 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,flow_space):
+ self.execute(cmd="clear",prompt="\$",timeout=10)
+ self.execute(cmd="fvctl addFlowSpace "+flow_space,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 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 main.TRUE
+
+ def listDevices(self):
+ self.execute(cmd="clear",prompt="\$",timeout=10)
+ self.execute(cmd="fvctl 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"
+ main.log.info("List of Devices \n"+devices_list)
+ return main.TRUE
+
+
+
diff --git a/TestON/drivers/common/cli/remotetestbed/hpswitchclidriver.py b/TestON/drivers/common/cli/remotetestbed/hpswitchclidriver.py
new file mode 100644
index 0000000..24d9696
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/hpswitchclidriver.py
@@ -0,0 +1,230 @@
+#!/usr/bin/env python
+'''
+Created on 24-June-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/>.
+
+
+'''
+import time
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+import re
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class HPSwitch(CLI):
+
+ def __init__(self):
+ super(CLI, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(HPSwitch,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ return main.TRUE
+
+ def configure(self):
+ self.execute(cmd='configure', prompt = '\(config\)',timeout = 3)
+ if re.search('\(config\)', main.last_response):
+ main.log.info("Configure mode enabled"+main.last_response)
+ else :
+ main.log.warn("Fail to enable configure mode"+main.last_response)
+
+
+ def set_up_vlan(self,**vlanargs):
+ '''
+ Configure vlan.
+ '''
+ for key in vlanargs:
+ vars(self)[key] = vlanargs[key]
+
+ self.execute(cmd='vlan '+self.vlan_id, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("Configuring VLAN "+self.vlan_id)
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+
+ if self.vlan_name :
+ self.execute(cmd='name '+self.vlan_name, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("Configuring "+self.vlan_id)
+ return main.TRUE
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+ else :
+ main.log.error("Vlan Name not specified")
+ return main.FALSE
+
+ def vlan_tagged(self, **taggedargs):
+ for key in taggedargs:
+ vars(self)[key] = taggedargs[key]
+ if self.vlan_id :
+ self.execute(cmd='vlan '+self.vlan_id, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("Configuring "+self.vlan_id)
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+ if self.tagged :
+ self.execute(cmd='tagged '+self.vlan_id, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("VLAN tagged done "+self.tagged)
+ return main.TRUE
+ else :
+ main.log.warn("Fail to tagged Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+
+ def vlan_untagged(self, **untaggedargs):
+ for key in untaggedargs:
+ vars(self)[key] = untaggedargs[key]
+ if self.vlan_id :
+ self.execute(cmd='vlan '+self.vlan_id, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("Configuring "+self.vlan_id)
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+ if self.tagged :
+ self.execute(cmd='untagged '+self.vlan_id, prompt = '\(vlan-'+self.vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+self.vlan_id+'\)', main.last_response):
+ main.log.info("VLAN untagged done "+self.tagged)
+ return main.TRUE
+ else :
+ main.log.warn("Fail to untagged Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+
+ def openflow_mode(self):
+ self.configure()
+ self.execute(cmd='openflow', prompt = '\(openflow\)',timeout = 3)
+ if re.search('\(openflow\)', main.last_response):
+ main.log.info("Openflow mode enabled"+main.last_response)
+ return main.TRUE
+ else :
+ main.log.warn("Fail to enable Openflow mode"+main.last_response)
+ return main.FALSE
+
+
+ def add_openflow_controller(self,**controllerargs):
+ for key in controllerargs:
+ vars(self)[key] = controllerargs[key]
+
+ if not self.openflow_mode():
+ return main.FALSE
+
+ contoller_details = 'controller-id '+ self.controller_id+'ip '+self.controller_ip + 'controller-interface vlan '+self.interface_vlan_id
+ self.execute(cmd=contoller_details, prompt = '\(openflow\)',timeout = 3)
+
+ if re.search('already\sconfigured', main.last_response):
+ main.log.warn("A controller is already configured with this ID."+main.last_response)
+ return main.FALSE
+ elif re.search('Incomplete\sinput',main.last_response ) :
+ main.log.warn("Incomplete\sinput"+main.last_response)
+ return main.FALSE
+ else:
+ main.log.info("Successfully added Openflow Controller")
+ return main.TRUE
+
+
+ def create_openflow_instance(self,**instanceargs):
+ for key in instanceargs:
+ vars(self)[key] = instanceargs[key]
+
+ if not self.openflow_mode():
+ return main.FALSE
+
+ if self.instance_name :
+ self.execute(cmd='instance '+self.instance_name, prompt = '\(of-inst-'+self.instance_name+'\)',timeout = 3)
+
+ if re.search('\(of-inst-'+self.instance_name+'\)', main.last_response):
+ main.log.info("Configuring Openflow instance "+self.instance_name)
+ else :
+ main.log.warn("Fail to configure Openflow instance"+self.instance_name+"\n\n"+main.last_response)
+ return main.FALSE
+ if self.controller_id :
+ self.execute(cmd='controller-id '+self.controller_id, prompt = '\(of-inst-'+self.instance_name+'\)',timeout = 3)
+ main.log.info(main.last_response)
+
+ if self.member :
+ self.execute(cmd='member vlan '+self.member_vlan_id, prompt = '\(of-inst-'+self.instance_name+'\)',timeout = 3)
+ main.log.info(main.last_response)
+
+ if self.execute(cmd='enable', prompt = '\(of-inst-'+self.instance_name+'\)',timeout = 3):
+ return main.TRUE
+ else :
+ return main.FALSE
+
+ def pair_vlan_with_openflow_instance(self,vlan_id):
+ self.configure()
+ self.execute(cmd='vlan '+vlan_id, prompt = '\(vlan-'+vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+vlan_id+'\)', main.last_response):
+ main.log.info("Configuring VLAN "+vlan_id)
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+
+ self.execute(cmd='openflow enable', prompt = '\(vlan-'+vlan_id+'\)',timeout = 3)
+ if re.search('\(vlan-'+vlan_id+'\)', main.last_response):
+ main.log.info("Configuring VLAN "+vlan_id)
+ else :
+ main.log.warn("Fail to configure Vlan"+self.vlan_id+main.last_response)
+ return main.FALSE
+
+ def show_openflow_instance(self,instance_name):
+
+ self.execute(cmd='show openflow instance '+instance_name, prompt = '#',timeout = 3)
+ return main.TRUE
+
+ def show(self, command):
+ self.execute(cmd=command, prompt = '#',timeout = 3)
+ return main.TRUE
+
+
+ def openflow_enable(self):
+ self.configure()
+ self.execute(cmd='openflow enable', prompt = '#',timeout = 3)
+ return main.TRUE
+
+ def openflow_disable(self):
+ self.configure()
+ self.execute(cmd='openflow enable', prompt = '#',timeout = 3)
+ return main.TRUE
+
+ def remove_controller(self,controller_id):
+ self.configure()
+ self.execute(cmd='no controller-id '+controller_id, prompt = '#',timeout = 3)
+ return main.TRUE
+
+ def remove_vlan(self,vlan_id):
+ self.configure()
+ if self.execute(cmd='no vlan '+vlan_id, prompt = '#',timeout = 3):
+ return main.TRUE
+ else :
+ self.execute(cmd=' '+vlan_id, prompt = '#',timeout = 3)
+ return main.TRUE
+
+ def remove_openflow_instance(self,instance_name):
+ self.configure()
+ self.execute(cmd='no openflow instance '+instance_name, prompt = '#',timeout = 3)
+ return main.TRUE
diff --git a/TestON/drivers/common/cli/remotetestbed/necswitchdriver.py b/TestON/drivers/common/cli/remotetestbed/necswitchdriver.py
new file mode 100644
index 0000000..f5e652a
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/necswitchdriver.py
@@ -0,0 +1,545 @@
+class NEC:
+ def __init__( self ):
+ self.prompt = '(.*)'
+ self.timeout = 60
+
+ def show(self, *options, **def_args ):
+ '''Possible Options :[' access-filter ', ' accounting ', ' acknowledgments ', ' auto-config ', ' axrp ', ' cfm ', ' channel-group ', ' clock ', ' config-lock-status ', ' cpu ', ' dhcp ', ' dot1x ', ' dumpfile ', ' efmoam ', ' environment ', ' file ', ' flash ', ' gsrp ', ' history ', ' igmp-snooping ', ' interfaces ', ' ip ', ' ip-dual ', ' ipv6-dhcp ', ' license ', ' lldp ', ' logging ', ' loop-detection ', ' mac-address-table ', ' mc ', ' memory ', ' mld-snooping ', ' netconf ', ' netstat ', ' ntp ', ' oadp ', ' openflow ', ' port ', ' power ', ' processes ', ' qos ', ' qos-flow ', ' sessions ', ' sflow ', ' spanning-tree ', ' ssh ', ' system ', ' tcpdump ', ' tech-support ', ' track ', ' version ', ' vlan ', ' vrrpstatus ', ' whoami ']'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_ip(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show ip "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_mc(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show mc "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_cfm(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show cfm "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_ntp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show ntp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_ssh(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show ssh "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_qos(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show qos "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_cpu(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show cpu "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_vlan(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show vlan "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_lldp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show lldp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_dhcp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show dhcp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_axrp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show axrp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_oadp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show oadp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_gsrp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show gsrp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_port(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show port "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_file(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show file "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_power(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show power "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_clock(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show clock "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_dot1x(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show dot1x "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_sflow(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show sflow "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_track(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show track "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_flash(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show flash "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_system(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show system "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_whoami(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show whoami "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_efmoam(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show efmoam "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_memory(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show memory "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_tcpdump(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show tcpdump "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_history(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show history "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_logging(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show logging "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_license(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show license "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_netstat(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show netstat "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_version(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show version "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_netconf(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show netconf "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_ipdual(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show ip-dual "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_sessions(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show sessions "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_qosflow(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show qos-flow "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_openflow(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show openflow "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_dumpfile(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show dumpfile "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_ipv6dhcp(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show ipv6-dhcp "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_processes(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show processes "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_vrrpstatus(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show vrrpstatus "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_interfaces(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show interfaces "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_environment(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show environment "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_autoconfig(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show auto-config "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_techsupport(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show tech-support "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_mldsnooping(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show mld-snooping "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_igmpsnooping(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show igmp-snooping "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_channelgroup(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show channel-group "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_spanningtree(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show spanning-tree "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_loopdetection(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show loop-detection "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_acknowledgments(self, *options, **def_args ):
+ '''Possible Options :[' interface ']'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show acknowledgments "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_macaddresstable(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show mac-address-table "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_configlockstatus(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show config-lock-status "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
+ def show_acknowledgments_interface(self, *options, **def_args ):
+ '''Possible Options :[]'''
+ arguments= ''
+ for option in options:
+ arguments = arguments + option +' '
+ prompt = def_args.setdefault('prompt',self.prompt)
+ timeout = def_args.setdefault('timeout',self.timeout)
+ self.execute( cmd= "show acknowledgments interface "+ arguments, prompt = prompt, timeout = timeout )
+ return main.TRUE
+
diff --git a/TestON/drivers/common/cli/remotetestbed/remotepoxdriver.py b/TestON/drivers/common/cli/remotetestbed/remotepoxdriver.py
new file mode 100644
index 0000000..f0d2a16
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/remotepoxdriver.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+'''
+Created on 12-Feb-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/>.
+
+
+RemoteVMDriver 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 time
+
+sys.path.append("../")
+
+from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver
+
+class RemotePoxDriver(RemoteTestBedDriver):
+ '''
+ RemoteVMDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(RemoteTestBedDriver, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(RemotePoxDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+ if self.handle :
+ main.log.info(self.name+" connected successfully ")
+
+ self.execute(cmd="cd "+self.options['pox_lib_location'],prompt="/pox\$",timeout=120)
+ self.execute(cmd='./pox.py samples.of_tutorial',prompt="DEBUG:",timeout=120)
+ return self.handle
+ return main.TRUE
+
+ def disconnect(self,handle):
+ if self.handle:
+ self.execute(cmd="exit()",prompt="/pox\$",timeout=120)
+ else :
+ main.log.error("Connection failed to the host")
diff --git a/TestON/drivers/common/cli/remotetestbed/remotevmdriver.py b/TestON/drivers/common/cli/remotetestbed/remotevmdriver.py
new file mode 100644
index 0000000..4592e71
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbed/remotevmdriver.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+'''
+Created on 12-Feb-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/>.
+
+
+RemoteVMDriver 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 time
+
+sys.path.append("../")
+
+from drivers.common.cli.remotetestbeddriver import RemoteTestBedDriver
+
+class RemoteVMDriver(RemoteTestBedDriver):
+ '''
+ RemoteVMDriver is the basic driver which will handle the Mininet functions
+ '''
+ def __init__(self):
+ super(RemoteTestBedDriver, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(RemoteVMDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+ if self.handle :
+ main.log.info(self.name+" connected successfully ")
+ return self.handle
+ return main.TRUE
+ def SSH(self,**connectargs):
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ '''
+ Connection will establish to the remote host using ssh.
+ It will take user_name ,ip_address and password as arguments<br>
+ and will return the handle.
+ '''
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ ssh_newkey = 'Are you sure you want to continue connecting'
+ refused = "ssh: connect to host "+self.ip_address+" port 22: Connection refused"
+ if self.port:
+ self.handle.sendline('ssh -p '+self.port+' '+self.user_name+'@'+self.ip_address)
+ else :
+ self.handle.sendline('ssh '+self.user_name+'@'+self.ip_address)
+ self.handle.sendline("\r")
+
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF,pexpect.TIMEOUT,refused],120)
+
+ if i==0:
+ main.log.info("ssh key confirmation received, send yes")
+ self.handle.sendline('yes')
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF])
+ if i==1:
+ main.log.info("ssh connection asked for password, gave password")
+ self.handle.sendline(self.pwd)
+ self.handle.expect('>|#|$')
+
+ elif i==2:
+ main.log.error("Connection timeout")
+ return main.FALSE
+ elif i==3: #timeout
+ main.log.error("No route to the Host "+self.user_name+"@"+self.ip_address)
+ return main.FALSE
+ elif i==4:
+ main.log.error("ssh: connect to host "+self.ip_address+" port 22: Connection refused")
+ return main.FALSE
+
+ self.handle.sendline("\r")
+ return main.TRUE
diff --git a/TestON/drivers/common/cli/remotetestbeddriver.py b/TestON/drivers/common/cli/remotetestbeddriver.py
new file mode 100644
index 0000000..5ade2ec
--- /dev/null
+++ b/TestON/drivers/common/cli/remotetestbeddriver.py
@@ -0,0 +1,58 @@
+#!/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/>.
+
+
+'''
+import time
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class RemoteTestBedDriver(CLI):
+ # The common functions for emulator included in RemoteTestBedDriver
+ def __init__(self):
+ super(CLI, self).__init__()
+
+ def connect(self,**connectargs):
+ for key in connectargs:
+ vars(self)['vm_'+key] = connectargs[key]
+
+ remote_user_name = main.componentDictionary[self.name]['remote_user_name']
+ remote_ip_address = main.componentDictionary[self.name]['remote_ip_address']
+ remote_port = main.componentDictionary[self.name]['remote_port']
+ remote_pwd = main.componentDictionary[self.name]['remote_pwd']
+
+ self.handle = super(RemoteTestBedDriver,self).connect(user_name = remote_user_name,
+ ip_address = remote_ip_address,
+ port = remote_port, pwd = remote_pwd)
+
+ if self.handle:
+ self.execute(cmd= "\r",prompt= "\$|>|#",timeout= 10)
+ self.execute(cmd= "SET CYGWIN=notty",prompt= "\$|>|#",timeout= 10)
+ self.execute(cmd= "\r",prompt= "\$|>|#",timeout= 10)
+ main.log.info("ssh "+self.vm_user_name+'@'+self.vm_ip_address)
+ self.execute(cmd= "ssh "+self.vm_user_name+'@'+self.vm_ip_address,prompt= "(.*)",timeout= 10)
+ self.execute(cmd= "\r",prompt= "assword:",timeout= 10)
+ self.execute(cmd = self.vm_pwd,prompt = "\$",timeout = 10)
+
+ return self.handle
+ else :
+ return main.FALSE
diff --git a/TestON/drivers/common/cli/tool/__init__.py b/TestON/drivers/common/cli/tool/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/drivers/common/cli/tool/__init__.py
diff --git a/TestON/drivers/common/cli/tool/dpctlclidriver.py b/TestON/drivers/common/cli/tool/dpctlclidriver.py
new file mode 100644
index 0000000..3ad5bba
--- /dev/null
+++ b/TestON/drivers/common/cli/tool/dpctlclidriver.py
@@ -0,0 +1,245 @@
+#/usr/bin/env python
+'''
+Created on 26-Nov-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/>.
+
+
+
+DPCTL driver class provides the basic functions of DPCTL controller
+'''
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+from drivers.common.cli.toolsdriver import Tools
+import pydoc
+from drivers.common.clidriver import CLI
+import re
+import os
+import sys
+
+class DpctlCliDriver(Tools):
+ '''
+ DpctlCliDriver driver class provides the basic functions of DPCTL controller
+ '''
+ def __init__(self):
+ super(DpctlCliDriver, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+
+ def connect(self,**connectargs):
+
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+
+ self.handle = super(DpctlCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd)
+ if self.handle :
+ main.log.info("Connected to the host")
+ return main.TRUE
+ else :
+ main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address)
+ return main.FALSE
+
+ def addFlow(self,**flowParameters):
+ '''
+ addFlow create a new flow entry into flow table using "dpctl"
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","INPORT","ACTION","TIMEOUT"],**flowParameters)
+ cmd = "dpctl add-flow tcp:"
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ timeOut = args["TIMEOUT"] if args["TIMEOUT"] != None else 120
+ cmd = cmd + tcpIP + ":" + tcpPort + " in_port=" + str(args["INPORT"]) + ",idle_timeout=" + str(args["TIMEOUT"]) +",actions=" + args["ACTION"]
+ response = self.execute(cmd=cmd,prompt="\~\$",timeout=60 )
+ if utilities.assert_matches(expect="openflow",actual=response,onpass="Flow Added Successfully",onfail="Adding Flow Failed!!!"):
+ return main.TRUE
+ else :
+ return main.FALSE
+
+ def showFlow(self,**flowParameters):
+ '''
+ showFlow dumps the flow entries of flow table using "dpctl"
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl show tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="get_config_reply",timeout=240)
+ if utilities.assert_matches(expect='features_reply',actual=response,onpass="Show flow executed",onfail="Show flow execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def dumpFlow(self,**flowParameters):
+ '''
+ dumpFlow gives installed flow information
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl dump-flows tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="type=",timeout=240)
+ if utilities.assert_matches(expect='stats_reply',actual=response,onpass="Dump flow executed",onfail="Dump flow execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+
+ def dumpTables(self,**flowParameters):
+ '''
+ dumpTables gives statistics for each of the flow tables used by datapath switch.
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl dump-tables tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="matched",timeout=240)
+ if utilities.assert_matches(expect='lookup=3',actual=response,onpass="Dump Tables executed",onfail="Dump Tables execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def dumpPorts(self,**flowParameters):
+ '''
+ dumpPorts gives ports information
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl dump-ports tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="rx pkts",timeout=240)
+ if utilities.assert_matches(expect='ports',actual=response,onpass="Dump Ports executed",onfail="Dump Ports execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+
+ def dumpAggregate(self,**flowParameters):
+ '''
+ dumpAggregate gives installed flow information.ggregate statistics for flows in datapath WITCH's tables that match flows.
+ If flows is omitted, the statistics are aggregated across all flows in the datapath's flow tables
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","FLOW"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ flow = args["FLOW"] if args["FLOW"] != None else ""
+ command = "dpctl dump-aggregate tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " + str (flow)
+ response = self.execute(cmd=command,prompt="flow_count=",timeout=240)
+ if utilities.assert_matches(expect='stats_reply',actual=response,onpass="Dump Aggregate executed",onfail="Dump Aggregate execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def delFlow(self,**flowParameters):
+ '''
+ delFlow Deletes entries from the datapath switch's tables that match flow
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","FLOW"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ flow = args["FLOW"] if args["FLOW"] != None else ""
+ command = "dpctl del-flows tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " +str(flow)
+ response = self.execute(cmd=command,prompt="ETH-Tutorial",timeout=240)
+ if utilities.assert_matches(expect='@',actual=response,onpass="Delete flow executed",onfail="Delete flow execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def show(self,**flowParameters):
+ '''
+ show gives information on datapath switch including information on its flow tables and ports.
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl show tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="miss_send_len=",timeout=240)
+ if utilities.assert_matches(expect='get_config_reply',actual=response,onpass="show command executed",onfail="show command execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def showStatus(self,**flowParameters):
+ '''
+ showStatus gives a series of key-value pairs that report the status of switch.
+ If key is specified, only the key-value pairs whose key names begin with key are printed.
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","KEY"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ key = args["KEY"] if args["KEY"] != None else ""
+ command = "dpctl status tcp:" + str(tcpIP) + ":" + str(tcpPort) + " " + key
+ response = self.execute(cmd=command,prompt="(.*)",timeout=240)
+ if utilities.assert_matches(expect='(.*)',actual=response,onpass="show command executed",onfail="show command execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def desc_set(self,**flowParameters):
+ '''
+ desc_set Sets the switch description (as returned in ofp_desc_stats) to string (max length is DESC_STR_LEN)
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","STRING"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ string = " " + args["STRING"] if args["STRING"] != None else " DESC_STR_LEN"
+ command = "dpctl desc tcp:" + str(tcpIP) + ":" + str(tcpPort) + str(string)
+ response = self.execute(cmd=command,prompt="ETH-Tutorial",timeout=240)
+ if utilities.assert_matches(expect='@',actual=response,onpass="desc command executed",onfail="desc command execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+ def dumpDesc(self,**flowParameters):
+ '''
+ dumpDesc Sets the switch description (as returned in ofp_desc_stats) to string (max length is DESC_STR_LEN)
+ '''
+ args = utilities.parse_args(["TCPIP","TCPPORT","STRING"],**flowParameters)
+ tcpIP = args["TCPIP"] if args["TCPIP"] != None else "127.0.0.1"
+ tcpPort = args["TCPPORT"] if args["TCPPORT"] != None else "6634"
+ command = "dpctl dump-desc tcp:" + str(tcpIP) + ":" + str(tcpPort)
+ response = self.execute(cmd=command,prompt="Serial Num:",timeout=240)
+ if utilities.assert_matches(expect='stats_reply',actual=response,onpass="desc command executed",onfail="desc command execution Failed"):
+ main.last_result = main.TRUE
+ return main.TRUE
+ else :
+ main.last_result = main.FALSE
+ return main.FALSE
+
+if __name__ != "__main__":
+ import sys
+ sys.modules[__name__] = DpctlCliDriver()
diff --git a/TestON/drivers/common/cli/toolsdriver.py b/TestON/drivers/common/cli/toolsdriver.py
new file mode 100644
index 0000000..2c165f9
--- /dev/null
+++ b/TestON/drivers/common/cli/toolsdriver.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+'''
+Created on 26-Nov-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/>.
+
+
+'''
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+
+class Tools(CLI):
+ # The common functions for Tools included in toolsdriver
+ def __init__(self):
+ super(CLI, self).__init__()
diff --git a/TestON/drivers/common/cli/zookeeperclidriver.py b/TestON/drivers/common/cli/zookeeperclidriver.py
new file mode 100644
index 0000000..60ac65e
--- /dev/null
+++ b/TestON/drivers/common/cli/zookeeperclidriver.py
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+'''
+Created on 31-May-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/>.
+
+
+ZookeeperCliDriver is the basic driver which will handle the Zookeeper functions
+'''
+
+import pexpect
+import struct
+import fcntl
+import os
+import signal
+import re
+import sys
+import core.teston
+import time
+
+sys.path.append("../")
+from drivers.common.clidriver import CLI
+
+class ZookeeperCliDriver(CLI):
+ '''
+ ZookeeperCliDriver is the basic driver which will handle the Zookeeper's functions
+ '''
+ def __init__(self):
+ super(CLI, self).__init__()
+ self.handle = self
+ self.wrapped = sys.modules[__name__]
+
+ def connect(self, **connectargs):
+ # Here the main is the TestON instance after creating all the log handles.
+ self.port = None
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ self.name = self.options['name']
+ self.handle = super(ZookeeperCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ self.ssh_handle = self.handle
+ if self.handle :
+ self.start()
+ 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 Onos system")
+ return main.FALSE
+
+
+ def start(self):
+ ''' This Function will start the Zookeeper'''
+ main.log.info( "Starting Zookeeper" )
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ self.handle.sendline("~/zookeeper-3.4.5/bin/zkServer.sh start")
+ self.handle.expect("zkServer.sh start")
+ self.handle.expect("\$")
+ response = self.handle.before + self.handle.after
+ if re.search("STARTED", response):
+ main.log.info("Zookeeper Started ")
+ return main.TRUE
+ elif re.search("running", response):
+ main.log.warn("zookeeper ... already running")
+ else:
+ main.log.error("Failed to start Zookeeper"+ response)
+ return main.FALSE
+
+ def status(self):
+ '''This Function will return the Status of the Zookeeper '''
+ time.sleep(5)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh status ",prompt="JMX",timeout=10)
+
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ return response
+
+ def stop(self):
+ '''This Function will stop the Zookeeper if it is Running'''
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ time.sleep(5)
+ response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh stop ",prompt="STOPPED",timeout=10)
+ self.execute(cmd="\r",prompt="\$",timeout=10)
+ if re.search("STOPPED",response):
+ main.log.info("Zookeeper Stopped")
+ return main.TRUE
+ else:
+ main.log.warn("No zookeeper to stop")
+ return main.FALSE
+
+ def disconnect(self):
+
+ response = ''
+ if self.handle:
+ self.handle.sendline("exit")
+ self.handle.expect("closed")
+ else :
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
+ def isup(self):
+ self.execute(cmd="\n",prompt="\$",timeout=10)
+ response = self.execute(cmd="~/zookeeper-3.4.5/bin/zkServer.sh status ",prompt="Mode",timeout=10)
+ pattern = '(.*)Mode(.*)'
+ if re.search(pattern, response):
+ return main.TRUE
+ else:
+ return main.FALSE
+
+
diff --git a/TestON/drivers/common/clidriver.py b/TestON/drivers/common/clidriver.py
new file mode 100644
index 0000000..0406e48
--- /dev/null
+++ b/TestON/drivers/common/clidriver.py
@@ -0,0 +1,218 @@
+#!/usr/bin/env python
+'''
+Created on 24-Oct-2012
+
+@authors: Anil Kumar (anilkumar.s@paxterrasolutions.com),
+ 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/>.
+
+
+
+'''
+import pexpect
+import struct, fcntl, os, sys, signal
+import sys, re
+sys.path.append("../")
+
+from drivers.component import Component
+class CLI(Component):
+ '''
+ This will define common functions for CLI included.
+ '''
+ def __init__(self):
+ super(Component, self).__init__()
+
+ def connect(self,**connectargs):
+ '''
+ Connection will establish to the remote host using ssh.
+ It will take user_name ,ip_address and password as arguments<br>
+ and will return the handle.
+ '''
+ for key in connectargs:
+ vars(self)[key] = connectargs[key]
+
+ connect_result = super(CLI, self).connect()
+ ssh_newkey = 'Are you sure you want to continue connecting'
+ refused = "ssh: connect to host "+self.ip_address+" port 22: Connection refused"
+ if self.port:
+ self.handle =pexpect.spawn('ssh -p '+self.port+' '+self.user_name+'@'+self.ip_address,maxread=50000)
+ else :
+ self.handle =pexpect.spawn('ssh -X '+self.user_name+'@'+self.ip_address,maxread=50000)
+
+ self.handle.logfile = self.logfile_handler
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF,pexpect.TIMEOUT,refused,'>|#|$'],120)
+
+ if i==0:
+ main.log.info("ssh key confirmation received, send yes")
+ self.handle.sendline('yes')
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF])
+ if i==1:
+ main.log.info("ssh connection asked for password, gave password")
+ self.handle.sendline(self.pwd)
+ self.handle.expect('>|#|$')
+
+ elif i==2:
+ main.log.error("Connection timeout")
+ return main.FALSE
+ elif i==3: #timeout
+ main.log.error("No route to the Host "+self.user_name+"@"+self.ip_address)
+ return main.FALSE
+ elif i==4:
+ main.log.error("ssh: connect to host "+self.ip_address+" port 22: Connection refused")
+ return main.FALSE
+ elif i==5:
+ main.log.info("Password not required logged in")
+
+ self.handle.sendline("\r")
+ self.handle.expect('>|#|$', 2)
+ return self.handle
+
+
+ def disconnect(self):
+ result = super(CLI, self).disconnect(self)
+ result = main.TRUE
+ #self.execute(cmd="exit",timeout=120,prompt="(.*)")
+
+
+ def execute(self, **execparams):
+ '''
+ It facilitates the command line execution of a given command. It has arguments as :
+ cmd => represents command to be executed,
+ prompt => represents expect command prompt or output,
+ timeout => timeout for command execution,
+ more => to provide a key press if it is on.
+
+ It will return output of command exection.
+ '''
+
+ result = super(CLI, self).execute(self)
+ defaultPrompt = '.*[$>\#]'
+ args = utilities.parse_args(["CMD", "TIMEOUT", "PROMPT", "MORE"], **execparams)
+ expectPrompt = args["PROMPT"] if args["PROMPT"] else defaultPrompt
+ self.LASTRSP = ""
+ timeoutVar = args["TIMEOUT"] if args["TIMEOUT"] else 10
+ cmd = ''
+ if args["CMD"]:
+ cmd = args["CMD"]
+ else :
+ return 0
+ if args["MORE"] == None:
+ args["MORE"] = " "
+ self.handle.sendline(cmd)
+ self.lastCommand = cmd
+ index = self.handle.expect([expectPrompt, "--More--", 'Command not found.', pexpect.TIMEOUT,"^:$"], timeout = timeoutVar)
+ if index == 0:
+ self.LASTRSP = self.LASTRSP + self.handle.before + self.handle.after
+ main.log.info("Executed :"+str(cmd)+" \t\t Expected Prompt '"+ str(expectPrompt)+"' Found")
+ elif index == 1:
+ self.LASTRSP = self.LASTRSP + self.handle.before
+ self.handle.send(args["MORE"])
+ main.log.info("Found More screen to go , Sending a key to proceed")
+ indexMore = self.handle.expect(["--More--", expectPrompt], timeout = timeoutVar)
+ while indexMore == 0:
+ main.log.info("Found anoother More screen to go , Sending a key to proceed")
+ self.handle.send(args["MORE"])
+ indexMore = self.handle.expect(["--More--", expectPrompt], timeout = timeoutVar)
+ self.LASTRSP = self.LASTRSP + self.handle.before
+ elif index ==2:
+ main.log.error("Command not found")
+ self.LASTRSP = self.LASTRSP + self.handle.before
+ elif index ==3:
+ main.log.error("Expected Prompt not found , Time Out!!")
+ main.log.error( expectPrompt )
+ return "Expected Prompt not found , Time Out!!"
+
+ elif index == 4:
+ self.LASTRSP = self.LASTRSP + self.handle.before
+ #self.handle.send(args["MORE"])
+ self.handle.sendcontrol("D")
+ main.log.info("Found More screen to go , Sending a key to proceed")
+ indexMore = self.handle.expect(["^:$", expectPrompt], timeout = timeoutVar)
+ while indexMore == 0:
+ main.log.info("Found anoother More screen to go , Sending a key to proceed")
+ self.handle.sendcontrol("D")
+ indexMore = self.handle.expect(["^:$", expectPrompt], timeout = timeoutVar)
+ self.LASTRSP = self.LASTRSP + self.handle.before
+
+ main.last_response = self.remove_contol_chars(self.LASTRSP)
+ return self.LASTRSP
+
+ def remove_contol_chars(self,response):
+ #RE_XML_ILLEGAL = '([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])|([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])'%(unichr(0xd800),unichr(0xdbff),unichr(0xdc00),unichr(0xdfff),unichr(0xd800),unichr(0xdbff),unichr(0xdc00),unichr(0xdfff),unichr(0xd800),unichr(0xdbff),unichr(0xdc00),unichr(0xdfff))
+ #response = re.sub(RE_XML_ILLEGAL, "\n", response)
+ response = re.sub(r"[\x01-\x1F\x7F]", "", response)
+ #response = re.sub(r"\[\d+\;1H", "\n", response)
+ response = re.sub(r"\[\d+\;\d+H", "", response)
+ return response
+
+ def runAsSudoUser(self,handle,pwd,default):
+
+ i = handle.expect([".ssword:*",default, pexpect.EOF])
+ if i==0:
+ handle.sendline(pwd)
+ handle.sendline("\r")
+
+ if i==1:
+ handle.expect(default)
+
+ if i==2:
+ main.log.error("Unable to run as Sudo user")
+
+ return handle
+
+ def onfail(self):
+ if main.componentDictionary[self.name].has_key('onfail'):
+ commandList = main.componentDictionary[self.name]['onfail'].split(",")
+ for command in commandList :
+ response = self.execute(cmd=command,prompt="(.*)",timeout=120)
+
+ def secureCopy(self,user_name, ip_address,filepath, pwd,dst_path):
+
+ #scp openflow@192.168.56.101:/home/openflow/sample /home/paxterra/Desktop/
+
+ '''
+ Connection will establish to the remote host using ssh.
+ It will take user_name ,ip_address and password as arguments<br>
+ and will return the handle.
+ '''
+ ssh_newkey = 'Are you sure you want to continue connecting'
+ refused = "ssh: connect to host "+ip_address+" port 22: Connection refused"
+ self.handle =pexpect.spawn('scp '+user_name+'@'+ip_address+':'+filepath+' '+dst_path)
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF,pexpect.TIMEOUT,refused],120)
+
+ if i==0:
+ main.log.info("ssh key confirmation received, send yes")
+ self.handle.sendline('yes')
+ i=self.handle.expect([ssh_newkey,'password:',pexpect.EOF])
+ if i==1:
+ main.log.info("ssh connection asked for password, gave password")
+ self.handle.sendline(pwd)
+ #self.handle.expect(user_name)
+
+ elif i==2:
+ main.log.error("Connection timeout")
+ pass
+ elif i==3: #timeout
+ main.log.error("No route to the Host "+user_name+"@"+ip_address)
+ return main.FALSE
+ elif i==4:
+ main.log.error("ssh: connect to host "+ip_address+" port 22: Connection refused")
+ return main.FALSE
+
+ self.handle.sendline("\r")
+
+ return self.handle
+