Added files created for SDNIP CHO test
diff --git a/TestON/drivers/common/cli/dpclidriver.py b/TestON/drivers/common/cli/dpclidriver.py
new file mode 100644
index 0000000..1cdd281
--- /dev/null
+++ b/TestON/drivers/common/cli/dpclidriver.py
@@ -0,0 +1,149 @@
+'''
+Driver for blank dataplane VMs. Created for SDNIP test.
+'''
+
+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 DPCliDriver(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(DPCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ if self.handle:
+ return self.handle
+ else :
+ main.log.info("NO HANDLE")
+ return main.FALSE
+
+ def create_interfaces(self, net, number, start, destlogin, dest):
+ self.handle.sendline("")
+ self.handle.expect("\$")
+
+ self.handle.sendline("rm /tmp/local_ip.txt")
+ self.handle.expect("\$")
+ self.handle.sendline("touch /tmp/local_ip.txt")
+ self.handle.expect("\$")
+
+ main.log.info("Creating interfaces")
+ k = 0
+ intf = 0
+ while number != 0:
+ k= k + 1
+ if k == 256:
+ k = 1
+ start = start + 1
+ number = number - 1
+ intf = intf + 1
+ ip = net+"."+str(start)+"."+str(k)+".1"
+ self.handle.sendline("sudo ifconfig eth0:"+str(intf)+" "+ip+" netmask 255.255.255.0")
+
+ i = self.handle.expect(["\$","password",pexpect.TIMEOUT,pexpect.EOF], timeout = 120)
+ if i == 0:
+ self.handle.sendline("echo "+str(ip)+"\n >> /tmp/local_ip.txt")
+ self.handle.expect("\$")
+ elif i == 1:
+ main.log.info("Sending sudo password")
+ self.handle.sendline(self.pwd)
+ self.handle.expect("\$")
+ else:
+ main.log.error("INTERFACES NOT CREATED")
+ return main.FALSE
+ self.handle.sendline("scp /tmp/local_ip.txt "+str(destlogin)+"@"+str(destip)+":/tmp/ip_table"+str(net)+".txt")
+ try:
+ self.handle.expect("100%")
+ return main.TRUE
+ except:
+ self.log.warn("FAILURE SENDING IP TABLE TO DESTINATION MACHINE")
+ return main.FALSE
+
+ '''
+ def remove_interfaces(self, number, start):
+ self.handle.sendline("")
+ self.handle.expect("\$")
+
+ main.log.info("Deleting interfaces")
+ while number != 0:
+ number = number - 1
+ intf = intf + 1
+ self.handle.sendline("sudo ifconfig eth0:"+str(intf)+" down")
+
+ i = self.handle.expect(["\$","password",pexpect.TIMEOUT,pexpect.EOF], timeout = 120)
+ if i == 0:
+ main.log.info("Interfaces deleted")
+ return main.TRUE
+ elif i == 1:
+ main.log.info("Sending sudo password")
+ self.handle.sendline(self.pwd)
+ self.handle.expect("DONE")
+ main.log.info("Interfaces deleted")
+ return main.TRUE
+ else:
+ main.log.error("INTERFACES NOT DELETED")
+ return main.FALSE
+ '''
+
+ def pingall_interfaces(self, netsrc, netstrt, netdst):
+ self.handle.sendline("")
+ self.handle.expect("\$")
+
+ main.log.info("Pinging interfaces on the "+str(netdst)+" network from "+str(netsrc)+"."+str(netstrt)+".1.1")
+ self.handle.sendline("sudo fping -S "+str(netsrc)+"."+str(netstrt)+".1.1 -f /tmp/ip_table"+str(netdst)+".txt")
+ while 1:
+ i = self.handle.expect(["reachable","unreachable","\$","password",pexpect.TIMEOUT,"not installed"], timeout=45)
+ if i == 0:
+ result = main.TRUE
+ elif i == 1:
+ main.log.error("An interface was unreachable")
+ result = main.FALSE
+ return result
+ elif i == 2:
+ main.log.info("All interfaces reachable")
+ return result
+ elif i == 3:
+ self.handle.sendline(self.pwd)
+ elif i == 4:
+ main.log.error("Unable to fping")
+ result = main.FALSE
+ return result
+ elif i == 5:
+ main.log.info("fping not installed, installing fping")
+ self.handle.sendline("sudo apt-get install fping")
+ i = self.handle.expect(["password","\$",pexpect.TIMEOUT], timeout = 60)
+ if i == 0:
+ self.handle.sendline(self.pwd)
+ self.handle.expect("\$", timeout = 30)
+ main.log.info("fping installed")
+ self.handle.sendline("sudo fping -S "+str(netsrc)+"."+str(netstrt)+".1.1 -f /tmp/ip_table"+str(netdst)+".txt")
+ elif i == 1:
+ main.log.info("fping installed")
+ self.handle.sendline("sudo fping -S "+str(netsrc)+"."+str(netstrt)+".1.1 -f /tmp/ip_table"+str(netdst)+".txt")
+ elif i == 2:
+ main.log.error("Could not install fping")
+ result = main.FALSE
+ return result
+
+ def disconnect(self):
+ response = ''
+ try:
+ self.handle.sendline("exit")
+ self.handle.expect("closed")
+ except:
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
+
diff --git a/TestON/drivers/common/cli/quaggaclidriver.py b/TestON/drivers/common/cli/quaggaclidriver.py
new file mode 100644
index 0000000..744d284
--- /dev/null
+++ b/TestON/drivers/common/cli/quaggaclidriver.py
@@ -0,0 +1,213 @@
+#!/usr/bin/env python
+
+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 QuaggaCliDriver(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(QuaggaCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ if self.handle:
+ self.handle.expect("")
+ self.handle.expect("\$")
+ self.handle.sendline("telnet localhost 2605")
+ self.handle.expect("Password:", timeout = 5)
+ self.handle.sendline("hello")
+ self.handle.expect("bgpd",timeout = 5)
+ self.handle.sendline("enable")
+ self.handle.expect("bgpd#", timeout = 5)
+ return self.handle
+ else :
+ main.log.info("NO HANDLE")
+ return main.FALSE
+
+ def enter_config(self, asn):
+ try:
+ self.handle.sendline("")
+ self.handle.expect("bgpd#")
+ except:
+ main.log.warn("Probably not currently in enable mode!")
+ self.disconnect()
+ return main.FALSE
+ self.handle.sendline("configure terminal")
+ self.handle.expect("config", timeout = 5)
+ routerAS = "router bgp " + str(asn)
+ try:
+ self.handle.sendline(routerAS)
+ self.handle.expect("config-router", timeout = 5)
+ return main.TRUE
+ except:
+ return main.FALSE
+ def add_route(self, net, numRoutes, routeRate):
+ try:
+ self.handle.sendline("")
+ self.handle.expect("config-router")
+ except:
+ main.log.warn("Probably not in config-router mode!")
+ self.disconnect()
+ main.log.report("Adding Routes")
+ j=0
+ k=0
+ while numRoutes > 255:
+ numRoutes = numRoutes - 255
+ j = j + 1
+ k = numRoutes % 254
+ routes_added = 0
+ if numRoutes > 255:
+ numRoutes = 255
+ for m in range(1,j+1):
+ for n in range(1, numRoutes+1):
+ network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
+ routeCmd = "network " + network
+ try:
+ self.handle.sendline(routeCmd)
+ self.handle.expect("bgpd")
+ except:
+ main.log.warn("failed to add route")
+ self.disconnect()
+ waitTimer = 1.00/routeRate
+ time.sleep(waitTimer)
+ routes_added = routes_added + 1
+ for d in range(j+1,j+2):
+ for e in range(1,k+1):
+ network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
+ routeCmd = "network " + network
+ try:
+ self.handle.sendline(routeCmd)
+ self.handle.expect("bgpd")
+ except:
+ main.log.warn("failed to add route")
+ self.disconnect
+ waitTimer = 1.00/routeRate
+ time.sleep(waitTimer)
+ routes_added = routes_added + 1
+ if routes_added == numRoutes:
+ return main.TRUE
+ return main.FALSE
+ def del_route(self, net, numRoutes, routeRate):
+ try:
+ self.handle.sendline("")
+ self.handle.expect("config-router")
+ except:
+ main.log.warn("Probably not in config-router mode!")
+ self.disconnect()
+ main.log.report("Deleting Routes")
+ j=0
+ k=0
+ while numRoutes > 255:
+ numRoutes = numRoutes - 255
+ j = j + 1
+ k = numRoutes % 254
+ routes_deleted = 0
+ if numRoutes > 255:
+ numRoutes = 255
+ for m in range(1,j+1):
+ for n in range(1, numRoutes+1):
+ network = str(net) + "." + str(m) + "." + str(n) + ".0/24"
+ routeCmd = "no network " + network
+ try:
+ self.handle.sendline(routeCmd)
+ self.handle.expect("bgpd")
+ except:
+ main.log.warn("Failed to delete route")
+ self.disconnect()
+ waitTimer = 1.00/routeRate
+ time.sleep(waitTimer)
+ routes_deleted = routes_deleted + 1
+ for d in range(j+1,j+2):
+ for e in range(1,k+1):
+ network = str(net) + "." + str(d) + "." + str(e) + ".0/24"
+ routeCmd = "no network " + network
+ try:
+ self.handle.sendline(routeCmd)
+ self.handle.expect("bgpd")
+ except:
+ main.log.warn("Failed to delete route")
+ self.disconnect()
+ waitTimer = 1.00/routeRate
+ time.sleep(waitTimer)
+ routes_deleted = routes_deleted + 1
+ if routes_deleted == numRoutes:
+ return main.TRUE
+ return main.FALSE
+ def check_routes(self, brand, ip, user, pw):
+ def pronto(ip, user, passwd):
+ print "Connecting to Pronto switch"
+ child = pexpect.spawn("telnet " + ip)
+ i = child.expect(["login:", "CLI#",pexpect.TIMEOUT])
+ if i == 0:
+ print "Username and password required. Passing login info."
+ child.sendline(user)
+ child.expect("Password:")
+ child.sendline(passwd)
+ child.expect("CLI#")
+ print "Logged in, getting flowtable."
+ child.sendline("flowtable brief")
+ for t in range (9):
+ t2 = 9 - t
+ print "\r" + str(t2)
+ sys.stdout.write("\033[F")
+ time.sleep(1)
+ print "Scanning flowtable"
+ child.expect("Flow table show")
+ count = 0
+ while 1:
+ i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}','CLI#',pexpect.TIMEOUT])
+ if i == 0:
+ count = count + 1
+ elif i == 1:
+ print "Pronto flows: " + str(count) + "\nDone\n"
+ break
+ else:
+ break
+ def cisco(ip,user,passwd):
+ print "Establishing Cisco switch connection"
+ child = pexpect.spawn("ssh " + user + "@" + ip)
+ i = child.expect(["Password:", "CLI#",pexpect.TIMEOUT])
+ if i == 0:
+ print "Password required. Passing now."
+ child.sendline(passwd)
+ child.expect("#")
+ print "Logged in. Retrieving flow table then counting flows."
+ child.sendline("show openflow switch all flows all")
+ child.expect("Logical Openflow Switch")
+ print "Flow table retrieved. Counting flows"
+ count = 0
+ while 1:
+ i = child.expect(["nw_src=17","#",pexpect.TIMEOUT])
+ if i == 0:
+ count = count + 1
+ elif i == 1:
+ print "Cisco flows: " + str(count) + "\nDone\n"
+ break
+ else:
+ break
+ if brand == "pronto" or brand == "PRONTO":
+ pronto(ip,user,passwd)
+ #elif brand == "cisco" or brand == "CISCO":
+ # cisco(ip,user,passwd)
+ def disconnect(self):
+ '''
+ Called when Test is complete to disconnect the Quagga handle.
+ '''
+ response = ''
+ try:
+ self.handle.close()
+ except:
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response
diff --git a/TestON/drivers/common/cli/sdnipclidriver.py b/TestON/drivers/common/cli/sdnipclidriver.py
new file mode 100644
index 0000000..58dfb03
--- /dev/null
+++ b/TestON/drivers/common/cli/sdnipclidriver.py
@@ -0,0 +1,73 @@
+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 SDNIPCliDriver(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(SDNIPCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
+
+ if self.handle:
+ return self.handle
+ else :
+ main.log.info("NO HANDLE")
+ return main.FALSE
+
+ def check_routes(self, brand, ip, user, pw):
+ self.handle.sendline("")
+ self.handle.expect("\$")
+ main.log.info("Connecting to Pronto switch")
+ child = pexpect.spawn("telnet " + ip)
+ i = child.expect(["login:", "CLI#",pexpect.TIMEOUT])
+ if i == 0:
+ main.log.info("Username and password required. Passing login info.")
+ child.sendline(user)
+ child.expect("Password:")
+ child.sendline(pw)
+ child.expect("CLI#")
+ main.log.info("Logged in, getting flowtable.")
+ child.sendline("flowtable brief")
+ for t in range (9):
+ t2 = 9 - t
+ main.log.info("\r" + str(t2))
+ sys.stdout.write("\033[F")
+ time.sleep(1)
+ time.sleep(10)
+ main.log.info("Scanning flowtable")
+ child.expect("Flow table show")
+ count = 0
+ while 1:
+ i = child.expect(['17\d\.\d{1,3}\.\d{1,3}\.\d{1,3}','CLI#',pexpect.TIMEOUT])
+ if i == 0:
+ count = count + 1
+ elif i == 1:
+ a ="Pronto flows: " + str(count) + "\nDone\n"
+ main.log.info(a)
+ break
+ else:
+ break
+ return count
+ def disconnect(self):
+ '''
+ Called when Test is complete to disconnect the Quagga handle.
+ '''
+ response = ''
+ try:
+ self.handle.close()
+ except:
+ main.log.error("Connection failed to the host")
+ response = main.FALSE
+ return response