Cleaned two more driver
diff --git a/TestON/drivers/common/cli/quaggaclidriver.py b/TestON/drivers/common/cli/quaggaclidriver.py
index 8314941..28f95af 100644
--- a/TestON/drivers/common/cli/quaggaclidriver.py
+++ b/TestON/drivers/common/cli/quaggaclidriver.py
@@ -2,93 +2,111 @@
import time
import pexpect
-import struct, fcntl, os, sys, signal
+import struct
+import fcntl
+import os
+import sys
+import signal
import sys
import re
import json
-sys.path.append("../")
+sys.path.append( "../" )
from drivers.common.clidriver import CLI
-class QuaggaCliDriver(CLI):
- def __init__(self):
- super(CLI, self).__init__()
+class QuaggaCliDriver( CLI ):
+
+ def __init__( self ):
+ super( CLI, self ).__init__()
# TODO: simplify this method
- def connect(self, **connectargs):
+ def connect( self, **connectargs ):
for key in connectargs:
- vars(self)[key] = connectargs[key]
+ 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="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))
+ 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="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:
- #self.handle.expect("",timeout=10)
- #self.handle.expect("\$",timeout=10)
- self.handle.sendline("telnet localhost 2605")
- #self.handle.expect("Password:", timeout=5)
- self.handle.expect("Password:")
- self.handle.sendline("hello")
- #self.handle.expect("bgpd", timeout=5)
- self.handle.expect("bgpd")
- self.handle.sendline("enable")
- #self.handle.expect("bgpd#", timeout=5)
- self.handle.expect("bgpd#")
+ # self.handle.expect( "",timeout=10 )
+ # self.handle.expect( "\$",timeout=10 )
+ self.handle.sendline( "telnet localhost 2605" )
+ # self.handle.expect( "Password:", timeout=5 )
+ self.handle.expect( "Password:" )
+ self.handle.sendline( "hello" )
+ # self.handle.expect( "bgpd", timeout=5 )
+ self.handle.expect( "bgpd" )
+ self.handle.sendline( "enable" )
+ # self.handle.expect( "bgpd#", timeout=5 )
+ self.handle.expect( "bgpd#" )
return self.handle
- else :
- main.log.info("NO HANDLE")
+ else:
+ main.log.info( "NO HANDLE" )
return main.FALSE
- def loginQuagga(self, ip_address):
- self.name = self.options['name']
- self.handle = super(QuaggaCliDriver, self).connect(
+ def loginQuagga( self, ip_address ):
+ 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))
+ 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("\$")
- self.handle.sendline("telnet localhost 2605")
- #self.handle.expect("Password:", timeout=5)
- self.handle.expect("Password:")
- self.handle.sendline("hello")
- #self.handle.expect("bgpd", timeout=5)
- self.handle.expect("bgpd")
- self.handle.sendline("enable")
- #self.handle.expect("bgpd#", timeout=5)
- self.handle.expect("bgpd#")
- main.log.info("I in quagga on host " + str(ip_address))
+ # self.handle.expect( "" )
+ # self.handle.expect( "\$" )
+ self.handle.sendline( "telnet localhost 2605" )
+ # self.handle.expect( "Password:", timeout=5 )
+ self.handle.expect( "Password:" )
+ self.handle.sendline( "hello" )
+ # self.handle.expect( "bgpd", timeout=5 )
+ self.handle.expect( "bgpd" )
+ self.handle.sendline( "enable" )
+ # self.handle.expect( "bgpd#", timeout=5 )
+ self.handle.expect( "bgpd#" )
+ main.log.info( "I in quagga on host " + str( ip_address ) )
return self.handle
else:
- main.log.info("NO HANDLE")
+ main.log.info( "NO HANDLE" )
return main.FALSE
- def enter_config(self, asn):
- main.log.info("I am in enter_config method!")
+ def enter_config( self, asn ):
+ main.log.info( "I am in enter_config method!" )
try:
- self.handle.sendline("")
- self.handle.expect("bgpd#")
+ self.handle.sendline( "" )
+ self.handle.expect( "bgpd#" )
except:
- main.log.warn("Probably not currently in enable mode!")
+ 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)
+ 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)
+ self.handle.sendline( routerAS )
+ self.handle.expect( "config-router", timeout=5 )
return main.TRUE
except:
return main.FALSE
- def generate_prefixes(self, net, numRoutes):
- main.log.info("I am in generate_prefixes method!")
+ def generate_prefixes( self, net, numRoutes ):
+ main.log.info( "I am in generate_prefixes method!" )
# each IP prefix will be composed by "net" + "." + m + "." + n + "." + x
# the length of each IP prefix is 24
@@ -97,248 +115,298 @@
m = numRoutes / 256
n = numRoutes % 256
- for i in range(0, m):
- for j in range(0, 256):
- network = str(net) + "." + str(i) + "." + str(j) + ".0/24"
- routes.append(network)
+ for i in range( 0, m ):
+ for j in range( 0, 256 ):
+ network = str(
+ net ) + "." + str(
+ i ) + "." + str(
+ j ) + ".0/24"
+ routes.append( network )
routes_gen = routes_gen + 1
- for j in range(0, n):
- network = str(net) + "." + str(m) + "." + str(j) + ".0/24"
- routes.append(network)
+ for j in range( 0, n ):
+ network = str( net ) + "." + str( m ) + "." + str( j ) + ".0/24"
+ routes.append( network )
routes_gen = routes_gen + 1
if routes_gen == numRoutes:
- main.log.info("Successfully generated " + str(numRoutes)
- + " prefixes!")
+ main.log.info( "Successfully generated " + str( numRoutes )
+ + " prefixes!" )
return routes
return main.FALSE
- # This method generates a multiple to single point intent(MultiPointToSinglePointIntent) for a given route
- def generate_expected_singleRouteIntent(self, prefix, nextHop, nextHopMac, sdnip_data):
+ # This method generates a multiple to single point intent(
+ # MultiPointToSinglePointIntent ) for a given route
+ def generate_expected_singleRouteIntent( self, prefix, nextHop, nextHopMac, sdnip_data ):
ingress = []
egress = ""
- for peer in sdnip_data['bgpPeers']:
- if peer['ipAddress'] == nextHop:
- egress = "of:" + str(peer['attachmentDpid']).replace(":", "") + ":" + str(peer['attachmentPort'])
+ for peer in sdnip_data[ 'bgpPeers' ]:
+ 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 + "}"
- treatment = "[ETH_DST{mac=" + str(nextHopMac) + "}]"
+ treatment = "[ETH_DST{mac=" + str( nextHopMac ) + "}]"
- intent = egress + "/" + str(sorted(ingress)) + "/" + selector + "/" + treatment
+ intent = egress + "/" + \
+ str( sorted( ingress ) ) + "/" + selector + "/" + treatment
return intent
- def generate_expected_onePeerRouteIntents(self, prefixes, nextHop, nextHopMac, sdnip_json_file_path):
+ 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)
+ sdnip_data = json.loads( sdnip_json_file )
for prefix in prefixes:
- intents.append(self.generate_expected_singleRouteIntent(prefix, nextHop, nextHopMac, sdnip_data))
- return sorted(intents)
+ intents.append(
+ self.generate_expected_singleRouteIntent(
+ prefix,
+ nextHop,
+ nextHopMac,
+ sdnip_data ) )
+ return sorted( intents )
# TODO
# This method generates all expected route intents for all BGP peers
- def generate_expected_routeIntents(self):
+ def generate_expected_routeIntents( self ):
intents = []
return intents
# This method extracts all actual routes from ONOS CLI
- def extract_actual_routes(self, get_routes_result):
- routes_json_obj = json.loads(get_routes_result)
+ def extract_actual_routes( self, get_routes_result ):
+ routes_json_obj = json.loads( get_routes_result )
allRoutes_actual = []
for route in routes_json_obj:
- if route['prefix'] == '172.16.10.0/24':
+ if route[ 'prefix' ] == '172.16.10.0/24':
continue
- allRoutes_actual.append(route['prefix'] + "/" + route['nextHop'])
+ allRoutes_actual.append(
+ route[ 'prefix' ] + "/" + route[ 'nextHop' ] )
- return sorted(allRoutes_actual)
+ return sorted( allRoutes_actual )
# This method extracts all actual route intents from ONOS CLI
- def extract_actual_routeIntents(self, get_intents_result):
+ def extract_actual_routeIntents( self, get_intents_result ):
intents = []
# TODO: delete the line below when change to Mininet demo script
- # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
- intents_json_obj = json.loads(get_intents_result)
+ # get_intents_result=open( "../tests/SdnIpTest/intents.json" ).read()
+ intents_json_obj = json.loads( get_intents_result )
for intent in intents_json_obj:
- if intent['appId'] != "org.onosproject.sdnip" :
+ if intent[ 'appId' ] != "org.onosproject.sdnip":
continue
- if intent['type'] == "MultiPointToSinglePointIntent" and intent['state'] == 'INSTALLED':
- 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']))
+ for attachmentPoint in intent[ 'ingress' ]:
+ ingress.append(
+ str( attachmentPoint[ 'device' ] ) + ":" + str( attachmentPoint[ 'port' ] ) )
- selector = intent['selector'].replace("[" , "").replace("]" , "").replace(" ", "")
- if str(selector).startswith("IPV4"):
- str1, str2 = str(selector).split(",")
+ 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)
+ intent = egress + "/" + \
+ str( sorted( ingress ) ) + "/" + \
+ selector + "/" + intent[ 'treatment' ]
+ intents.append( intent )
+ return sorted( intents )
# This method extracts all actual BGP intents from ONOS CLI
- def extract_actual_bgpIntents(self, get_intents_result):
+ def extract_actual_bgpIntents( self, get_intents_result ):
intents = []
# TODO: delete the line below when change to Mininet demo script
- # get_intents_result=open("../tests/SdnIpTest/intents.json").read()
- intents_json_obj = json.loads(get_intents_result)
+ # get_intents_result=open( "../tests/SdnIpTest/intents.json" ).read()
+ intents_json_obj = json.loads( get_intents_result )
for intent in intents_json_obj:
- if intent['appId'] != "org.onosproject.sdnip":
+ if intent[ 'appId' ] != "org.onosproject.sdnip":
continue
- if intent['type'] == "PointToPointIntent" and "protocol=6" in str(intent['selector']):
- ingress = str(intent['ingress']['device']) + ":" + str(intent['ingress']['port'])
- egress = str(intent['egress']['device']) + ":" + str(intent['egress']['port'])
- selector = str(intent['selector']).replace(" ", "").replace("[", "").replace("]", "").split(",")
- intent = ingress + "/" + egress + "/" + str(sorted(selector))
- intents.append(intent)
+ if intent[ 'type' ] == "PointToPointIntent" and "protocol=6" in str( intent[ 'selector' ] ):
+ ingress = str( intent[ 'ingress' ][ 'device' ] ) + ":" + str(
+ intent[ 'ingress' ][ 'port' ] )
+ egress = str( intent[ 'egress' ][ 'device' ] ) + ":" + str(
+ intent[ 'egress' ][ 'port' ] )
+ selector = str(
+ intent[ 'selector' ] ).replace( " ", "" ).replace( "[", "" ).replace( "]", "" ).split( "," )
+ intent = ingress + "/" + egress + \
+ "/" + str( sorted( selector ) )
+ intents.append( intent )
- return sorted(intents)
+ return sorted( intents )
- # This method generates a single point to single point intent(PointToPointIntent) for BGP path
- def generate_expected_bgpIntents(self, sdnip_json_file_path):
+ # This method generates a single point to single point intent(
+ # PointToPointIntent ) for BGP path
+ def generate_expected_bgpIntents( self, sdnip_json_file_path ):
from operator import eq
- sdnip_json_file = open(sdnip_json_file_path).read()
- sdnip_data = json.loads(sdnip_json_file)
+ sdnip_json_file = open( sdnip_json_file_path ).read()
+ sdnip_data = json.loads( sdnip_json_file )
intents = []
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'])
+ 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 = ""
- 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']
+ 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' ]
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 = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
- intent = bgpSpeakerAttachmentPoint + "/" + bgpPeerAttachmentPoint + "/" + str(sorted(selector))
- intents.append(intent)
+ # 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 = 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 = 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 = 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 = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
- intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + 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 = selector_str.replace( " ", "" ).replace(
+ "[", "" ).replace( "]", "" ).split( "," )
+ intent = bgpPeerAttachmentPoint + "/" + \
+ bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
+ intents.append( intent )
- selector_str = "IPV4_SRC{ip=" + peer['ipAddress'] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
- selector = selector_str.replace(" ", "").replace("[", "").replace("]", "").split(",")
- intent = bgpPeerAttachmentPoint + "/" + bgpSpeakerAttachmentPoint + "/" + str(sorted(selector))
- intents.append(intent)
+ selector_str = "IPV4_SRC{ip=" + peer[ 'ipAddress' ] + "/32}," + "IPV4_DST{ip=" + bgpSpeakerIpAddress + "/32}," + \
+ "IP_PROTO{protocol=6}, ETH_TYPE{ethType=800}, TCP_SRC{tcpPort=179}"
+ selector = selector_str.replace( " ", "" ).replace(
+ "[", "" ).replace( "]", "" ).split( "," )
+ intent = bgpPeerAttachmentPoint + "/" + \
+ bgpSpeakerAttachmentPoint + "/" + str( sorted( selector ) )
+ intents.append( intent )
- return sorted(intents)
+ return sorted( intents )
- def add_routes(self, routes, routeRate):
- main.log.info("I am in add_routes method!")
+ 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", timeout=5)
+ 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!")
+ main.log.warn( "Probably not in config-router mode!" )
self.disconnect()
- main.log.info("Start to add routes")
+ main.log.info( "Start to add routes" )
- for i in range(0, len(routes)):
- routeCmd = "network " + routes[i]
+ for i in range( 0, len( routes ) ):
+ routeCmd = "network " + routes[ i ]
try:
- self.handle.sendline(routeCmd)
- self.handle.expect("bgpd", timeout=5)
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd", timeout=5 )
except:
- main.log.warn("Failed to add route")
+ 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 adding routes")
+ time.sleep( waitTimer )
+ if routes_added == len( routes ):
+ 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!")
+ 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)
+ 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!")
+ main.log.warn( "Probably not in config-router mode!" )
self.disconnect()
- main.log.info("Start to delete routes")
+ main.log.info( "Start to delete routes" )
- for i in range(0, len(routes)):
- routeCmd = "no network " + routes[i]
+ for i in range( 0, len( routes ) ):
+ routeCmd = "no network " + routes[ i ]
try:
- self.handle.sendline(routeCmd)
- self.handle.expect("bgpd", timeout=5)
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd", timeout=5 )
except:
- main.log.warn("Failed to add route")
+ 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")
+ 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("Start the ping test on host:" + str(ip_address))
+ def ping_test( self, ip_address, ping_test_file, ping_test_result_file ):
+ main.log.info( "Start the ping test on host:" + str( ip_address ) )
- self.name = self.options['name']
- self.handle = super(QuaggaCliDriver, self).connect(
+ 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))
+ 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))
- main.log.info(ping_test_file + " > " + ping_test_result_file + " &")
- self.handle.sendline(ping_test_file + " > " + ping_test_result_file + " &")
- self.handle.expect("\$", timeout=60)
+ # self.handle.expect( "" )
+ # self.handle.expect( "\$" )
+ main.log.info( "I in host " + str( ip_address ) )
+ main.log.info(
+ ping_test_file +
+ " > " +
+ ping_test_result_file +
+ " &" )
+ 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")
+ 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):
+ def add_route( self, net, numRoutes, routeRate ):
try:
- self.handle.sendline("")
- self.handle.expect("config-router")
+ self.handle.sendline( "" )
+ self.handle.expect( "config-router" )
except:
- main.log.warn("Probably not in config-router mode!")
+ main.log.warn( "Probably not in config-router mode!" )
self.disconnect()
- main.log.info("Adding Routes")
+ main.log.info( "Adding Routes" )
j = 0
k = 0
while numRoutes > 255:
@@ -348,44 +416,47 @@
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"
+ 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")
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd" )
except:
- main.log.warn("failed to add route")
+ main.log.warn( "failed to add route" )
self.disconnect()
waitTimer = 1.00 / routeRate
- time.sleep(waitTimer)
+ 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"
+ 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")
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd" )
except:
- main.log.warn("failed to add route")
+ main.log.warn( "failed to add route" )
self.disconnect
waitTimer = 1.00 / routeRate
- time.sleep(waitTimer)
+ 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):
+ def del_route( self, net, numRoutes, routeRate ):
try:
- self.handle.sendline("")
- self.handle.expect("config-router")
+ self.handle.sendline( "" )
+ self.handle.expect( "config-router" )
except:
- main.log.warn("Probably not in config-router mode!")
+ main.log.warn( "Probably not in config-router mode!" )
self.disconnect()
- main.log.info("Deleting Routes")
+ main.log.info( "Deleting Routes" )
j = 0
k = 0
while numRoutes > 255:
@@ -395,100 +466,106 @@
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"
+ 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")
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd" )
except:
- main.log.warn("Failed to delete route")
+ main.log.warn( "Failed to delete route" )
self.disconnect()
waitTimer = 1.00 / routeRate
- time.sleep(waitTimer)
+ 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"
+ 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")
+ self.handle.sendline( routeCmd )
+ self.handle.expect( "bgpd" )
except:
- main.log.warn("Failed to delete route")
+ main.log.warn( "Failed to delete route" )
self.disconnect()
waitTimer = 1.00 / routeRate
- time.sleep(waitTimer)
+ 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):
+ 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])
+ 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#")
+ 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):
+ 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 "\r" + str( t2 )
+ sys.stdout.write( "\033[F" )
+ time.sleep( 1 )
print "Scanning flowtable"
- child.expect("Flow table show")
+ 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])
+ while True:
+ 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"
+ print "Pronto flows: " + str( count ) + "\nDone\n"
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)
- child.expect("#")
+ 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")
+ 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])
+ while True:
+ i = child.expect( [ "nw_src=17", "#", pexpect.TIMEOUT ] )
if i == 0:
count = count + 1
elif i == 1:
- print "Cisco flows: " + str(count) + "\nDone\n"
+ print "Cisco flows: " + str( count ) + "\nDone\n"
break
else:
break
if brand == "pronto" or brand == "PRONTO":
- pronto(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.
- '''
+ # 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")
+ main.log.error( "Connection failed to the host" )
response = main.FALSE
return response
+
diff --git a/TestON/drivers/common/cli/remotesysdriver.py b/TestON/drivers/common/cli/remotesysdriver.py
index 374e502..a536e02 100644
--- a/TestON/drivers/common/cli/remotesysdriver.py
+++ b/TestON/drivers/common/cli/remotesysdriver.py
@@ -1,13 +1,13 @@
#!/usr/bin/env python
-'''
-Created on 26-Oct-2012
+"""
+Created on 26-Oct-2012
-@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
+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.
+ ( 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
@@ -15,41 +15,52 @@
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/>.
+ along with TestON. If not, see <http://www.gnu.org/licenses/>.
-'''
+"""
import time
import pexpect
-import struct, fcntl, os, sys, signal
+import struct
+import fcntl
+import os
import sys
-sys.path.append("../")
+import signal
+import sys
+sys.path.append( "../" )
from drivers.common.clidriver import CLI
-class RemoteSysDriver(CLI):
+
+class RemoteSysDriver( CLI ):
# The common functions for emulator included in emulatordriver
- def __init__(self):
- super(CLI, self).__init__()
-
- def connect(self,**connectargs):
+
+ 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']
+ vars( self )[ key ] = connectargs[ key ]
- self.handle = super(RemoteSysDriver,self).connect(user_name = self.user_name, ip_address = self.ip_address,port = self.port, pwd = self.pwd)
- '''
+ 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= "\n",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= "\n",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= "\n",prompt= "$",timeout= 10)
- #self.execute(cmd = "help",prompt = ">",timeout = 10)
-
- #self.execute(cmd = "~.",prompt= ".*",timeout= 10)
- return main.TRUE
- '''
+ self.execute( cmd= "\n",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= "\n",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= "\n",prompt= "$",timeout= 10 )
+ #self.execute( cmd="help",prompt=">",timeout=10 )
+ #self.execute( cmd="~.",prompt= ".*",timeout= 10 )
+ return main.TRUE
+ """