add Test Case1 && delete route driver && integrate ping test
diff --git a/TestON/drivers/common/cli/quaggaclidriver.py b/TestON/drivers/common/cli/quaggaclidriver.py
index 0f84bc0..779472d 100644
--- a/TestON/drivers/common/cli/quaggaclidriver.py
+++ b/TestON/drivers/common/cli/quaggaclidriver.py
@@ -14,25 +14,25 @@
def __init__(self):
super(CLI, self).__init__()
- #TODO: simplify this method
+ # TODO: simplify this method
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)
+ # self.handle = super(QuaggaCliDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
self.handle = super(QuaggaCliDriver, self).connect(user_name=self.user_name, ip_address="1.1.1.1", port=self.port, pwd=self.pwd)
main.log.info("connect parameters:" + str(self.user_name) + ";" + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
- if self.handle:
+ if self.handle:
self.handle.expect("")
self.handle.expect("\$")
self.handle.sendline("telnet localhost 2605")
- self.handle.expect("Password:", timeout = 5)
+ self.handle.expect("Password:", timeout=5)
self.handle.sendline("hello")
- self.handle.expect("bgpd",timeout = 5)
+ self.handle.expect("bgpd", timeout=5)
self.handle.sendline("enable")
- self.handle.expect("bgpd#", timeout = 5)
+ self.handle.expect("bgpd#", timeout=5)
return self.handle
else :
main.log.info("NO HANDLE")
@@ -72,11 +72,11 @@
self.disconnect()
return main.FALSE
self.handle.sendline("configure terminal")
- self.handle.expect("config", timeout = 5)
+ self.handle.expect("config", timeout=5)
routerAS = "router bgp " + str(asn)
try:
self.handle.sendline(routerAS)
- self.handle.expect("config-router", timeout = 5)
+ self.handle.expect("config-router", timeout=5)
return main.TRUE
except:
return main.FALSE
@@ -117,9 +117,9 @@
if peer['ipAddress'] == nextHop:
egress = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
else:
- ingress.append("of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort']) )
+ ingress.append("of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort']))
- selector = "[ETH_TYPE{ethType=800}, IPV4_DST{ip=" + prefix + "}]"
+ selector = "ETH_TYPE{ethType=800},IPV4_DST{ip=" + prefix + "}"
treatment = "[ETH_DST{mac=" + str(nextHopMac) + "}]"
intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + treatment
@@ -127,7 +127,7 @@
def generate_expected_onePeerRouteIntents(self, prefixes, nextHop, nextHopMac, sdnip_json_file_path):
intents = []
- sdnip_json_file=open(sdnip_json_file_path).read()
+ sdnip_json_file = open(sdnip_json_file_path).read()
sdnip_data = json.loads(sdnip_json_file)
@@ -163,12 +163,18 @@
for intent in intents_json_obj:
if intent['appId'] != "org.onlab.onos.sdnip" :
continue
- if intent['type'] == "MultiPointToSinglePointIntent":
- egress = str(intent['egress']['device'])+ ":" + str(intent['egress']['port'])
+ if intent['type'] == "MultiPointToSinglePointIntent" and intent['state'] == 'INSTALLED':
+ egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
ingress = []
for attachmentPoint in intent['ingress']:
ingress.append(str(attachmentPoint['device']) + ":" + str(attachmentPoint['port']))
- intent = egress + "/" + str(sorted(ingress)) + "/" + intent['selector'] + "/" + intent['treatment']
+
+ selector = intent['selector'].replace("[" , "").replace("]" , "").replace(" ", "")
+ if str(selector).startswith("IPV4"):
+ str1, str2 = str(selector).split(",")
+ selector = str2 + "," + str1
+
+ intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + intent['treatment']
intents.append(intent)
return sorted(intents)
@@ -195,37 +201,37 @@
def generate_expected_bgpIntents(self, sdnip_json_file_path):
from operator import eq
- sdnip_json_file=open(sdnip_json_file_path).read()
+ sdnip_json_file = open(sdnip_json_file_path).read()
sdnip_data = json.loads(sdnip_json_file)
intents = []
- bgpPeerAttachmentPoint=""
+ bgpPeerAttachmentPoint = ""
bgpSpeakerAttachmentPoint = "of:" + str(sdnip_data['bgpSpeakers'][0]['attachmentDpid']).replace(":", "") + ":" + str(sdnip_data['bgpSpeakers'][0]['attachmentPort'])
for peer in sdnip_data['bgpPeers']:
bgpPeerAttachmentPoint = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
# find out the BGP speaker IP address for this BGP peer
- bgpSpeakerIpAddress=""
+ bgpSpeakerIpAddress = ""
for interfaceAddress in sdnip_data['bgpSpeakers'][0]['interfaceAddresses']:
- #if eq(interfaceAddress['interfaceDpid'],sdnip_data['bgpSpeakers'][0]['attachmentDpid']) and eq(interfaceAddress['interfacePort'], sdnip_data['bgpSpeakers'][0]['attachmentPort']):
- if eq(interfaceAddress['interfaceDpid'],peer['attachmentDpid']) and eq(interfaceAddress['interfacePort'], peer['attachmentPort']):
- bgpSpeakerIpAddress = interfaceAddress['ipAddress']
+ # if eq(interfaceAddress['interfaceDpid'],sdnip_data['bgpSpeakers'][0]['attachmentDpid']) and eq(interfaceAddress['interfacePort'], sdnip_data['bgpSpeakers'][0]['attachmentPort']):
+ if eq(interfaceAddress['interfaceDpid'], peer['attachmentDpid']) and eq(interfaceAddress['interfacePort'], peer['attachmentPort']):
+ bgpSpeakerIpAddress = interfaceAddress['ipAddress']
break
else:
continue
# from bgpSpeakerAttachmentPoint to bgpPeerAttachmentPoint direction
- selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress']+ "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
+ selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress'] + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
intents.append(intent)
- selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress']+ "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
+ selector_str = "IPV4_SRC{ip=" + bgpSpeakerIpAddress + "/32}," + "IPV4_DST{ip=" + peer['ipAddress'] + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
intents.append(intent)
# from bgpPeerAttachmentPoint to bgpSpeakerAttachmentPoint direction
- selector_str = "IPV4_SRC{ip=" + peer['ipAddress'] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
+ selector_str = "IPV4_SRC{ip=" + peer['ipAddress'] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_DST{tcpPort=179}"
selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
intents.append(intent)
@@ -236,14 +242,14 @@
intents.append(intent)
return sorted(intents)
-
+
def add_routes(self, routes, routeRate):
main.log.info("I am in add_routes method!")
-
+
routes_added = 0
try:
self.handle.sendline("")
- #self.handle.expect("config-router")
+ # self.handle.expect("config-router")
self.handle.expect("config-router", timeout=5)
except:
main.log.warn("Probably not in config-router mode!")
@@ -264,7 +270,60 @@
main.log.info("Finished adding routes")
return main.TRUE
return main.FALSE
-
+
+ def delete_routes(self, routes, routeRate):
+ main.log.info("I am in delete_routes method!")
+
+ routes_added = 0
+ try:
+ self.handle.sendline("")
+ # self.handle.expect("config-router")
+ self.handle.expect("config-router", timeout=5)
+ except:
+ main.log.warn("Probably not in config-router mode!")
+ self.disconnect()
+ main.log.info("Start to delete routes")
+
+ for i in range(0, len(routes)):
+ routeCmd = "no network " + routes[i]
+ try:
+ self.handle.sendline(routeCmd)
+ self.handle.expect("bgpd", timeout=5)
+ except:
+ main.log.warn("Failed to add route")
+ self.disconnect()
+ waitTimer = 1.00 / routeRate
+ time.sleep(waitTimer)
+ if routes_added == len(routes):
+ main.log.info("Finished deleting routes")
+ return main.TRUE
+ return main.FALSE
+
+ def ping_test(self, ip_address, ping_test_file, ping_test_result_file):
+ main.log.info("I am in ping_test method!")
+
+
+ self.name = self.options['name']
+ self.handle = super(QuaggaCliDriver, self).connect(
+ user_name=self.user_name, ip_address=ip_address,
+ port=self.port, pwd=self.pwd)
+ main.log.info("connect parameters:" + str(self.user_name) + ";"
+ + str(self.ip_address) + ";" + str(self.port) + ";" + str(self.pwd))
+
+ if self.handle:
+ self.handle.expect("")
+ self.handle.expect("\$")
+ main.log.info("I in host " + str(ip_address))
+ self.handle.sendline(ping_test_file + ">" + ping_test_result_file + "&")
+ self.handle.expect("\$", timeout=60)
+ handle = self.handle.before
+
+ return handle
+ else:
+ main.log.info("NO HANDLE")
+ return main.FALSE
+
+
# Please use the generate_routes plus add_routes instead of this one
def add_route(self, net, numRoutes, routeRate):
try:
@@ -274,8 +333,8 @@
main.log.warn("Probably not in config-router mode!")
self.disconnect()
main.log.info("Adding Routes")
- j=0
- k=0
+ j = 0
+ k = 0
while numRoutes > 255:
numRoutes = numRoutes - 255
j = j + 1
@@ -283,8 +342,8 @@
routes_added = 0
if numRoutes > 255:
numRoutes = 255
- for m in range(1,j+1):
- for n in range(1, numRoutes+1):
+ 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:
@@ -292,12 +351,12 @@
self.handle.expect("bgpd")
except:
main.log.warn("failed to add route")
- self.disconnect()
- waitTimer = 1.00/routeRate
+ 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):
+ 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:
@@ -306,7 +365,7 @@
except:
main.log.warn("failed to add route")
self.disconnect
- waitTimer = 1.00/routeRate
+ waitTimer = 1.00 / routeRate
time.sleep(waitTimer)
routes_added = routes_added + 1
if routes_added == numRoutes:
@@ -321,8 +380,8 @@
main.log.warn("Probably not in config-router mode!")
self.disconnect()
main.log.info("Deleting Routes")
- j=0
- k=0
+ j = 0
+ k = 0
while numRoutes > 255:
numRoutes = numRoutes - 255
j = j + 1
@@ -330,8 +389,8 @@
routes_deleted = 0
if numRoutes > 255:
numRoutes = 255
- for m in range(1,j+1):
- for n in range(1, numRoutes+1):
+ 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:
@@ -340,11 +399,11 @@
except:
main.log.warn("Failed to delete route")
self.disconnect()
- waitTimer = 1.00/routeRate
+ 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):
+ 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:
@@ -353,17 +412,18 @@
except:
main.log.warn("Failed to delete route")
self.disconnect()
- waitTimer = 1.00/routeRate
+ 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])
+ i = child.expect(["login:", "CLI#", pexpect.TIMEOUT])
if i == 0:
print "Username and password required. Passing login info."
child.sendline(user)
@@ -381,7 +441,7 @@
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])
+ 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:
@@ -389,10 +449,10 @@
break
else:
break
- def cisco(ip,user,passwd):
+ def cisco(ip, user, passwd):
print "Establishing Cisco switch connection"
- child = pexpect.spawn("ssh " + user + "@" + ip)
- i = child.expect(["Password:", "CLI#",pexpect.TIMEOUT])
+ child = pexpect.spawn("ssh " + user + "@" + ip)
+ i = child.expect(["Password:", "CLI#", pexpect.TIMEOUT])
if i == 0:
print "Password required. Passing now."
child.sendline(passwd)
@@ -403,7 +463,7 @@
print "Flow table retrieved. Counting flows"
count = 0
while 1:
- i = child.expect(["nw_src=17","#",pexpect.TIMEOUT])
+ i = child.expect(["nw_src=17", "#", pexpect.TIMEOUT])
if i == 0:
count = count + 1
elif i == 1:
@@ -412,9 +472,9 @@
else:
break
if brand == "pronto" or brand == "PRONTO":
- pronto(ip,user,passwd)
- #elif brand == "cisco" or brand == "CISCO":
- # cisco(ip,user,passwd)
+ 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.