Package TestON :: Package drivers :: Package common :: Package cli :: Package emulator :: Module poxclidriver
[hide private]
[frames] | no frames]

Source Code for Module TestON.drivers.common.cli.emulator.poxclidriver

  1  #!/usr/bin/env python 
  2  ''' 
  3  Created on 26-Oct-2012 
  4          
  5  @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com) 
  6   
  7  pox driver provides the basic functions of POX controller 
  8  ''' 
  9  import pexpect 
 10  import struct, fcntl, os, sys, signal 
 11  import sys 
 12  from drivers.common.cli.emulatordriver import Emulator 
 13   
14 -class PoxCliDriver(Emulator):
15 ''' 16 PoxCliDriver driver provides the basic functions of POX controller 17 '''
18 - def __init__(self):
19 super(Emulator, self).__init__() 20 self.handle = self 21 self.wrapped = sys.modules[__name__]
22
23 - def connect(self, **connectargs):
24 #,user_name, ip_address, pwd,options): 25 ''' 26 this subroutine is to launch pox controller . It must have arguments as : 27 user_name = host name , 28 ip_address = ip address of the host , 29 pwd = password of host , 30 options = it is a topology hash which will consists the component's details for the test run 31 32 *** host is here a virtual mahine or system where pox framework hierarchy exists 33 ''' 34 35 for key in connectargs: 36 vars(self)[key] = connectargs[key] 37 38 self.name = self.options['name'] 39 40 poxLibPath = 'default' 41 copy = super(PoxCliDriver, self).secureCopy(self.user_name, self.ip_address,'/home/openflow/pox/pox/core.py', self.pwd,path+'/lib/pox/') 42 self.handle = super(PoxCliDriver, self).connect(user_name = self.user_name, ip_address = self.ip_address,port = None, pwd = self.pwd) 43 44 if self.handle: 45 self.handle.expect("openflow") 46 command = self.getcmd(self.options) 47 #print command 48 main.log.info("Entering into POX hierarchy") 49 if self.options['pox_lib_location'] != 'default': 50 self.execute(cmd="cd "+self.options['pox_lib_location'],prompt="/pox\$",timeout=120) 51 else: 52 self.execute(cmd="cd ~/TestON/lib/pox/",prompt="/pox\$",timeout=120) 53 ### launching pox with components 54 main.log.info("launching POX controller with given components") 55 self.execute(cmd=command,prompt="DEBUG:",timeout=120) 56 return main.TRUE 57 else : 58 main.log.error("Connection failed to the host "+self.user_name+"@"+self.ip_address) 59 main.log.error("Failed to connect to the POX controller") 60 return main.FALSE
61 62
63 - def disconnect(self,handle):
64 if self.handle: 65 self.execute(cmd="exit()",prompt="/pox\$",timeout=120) 66 else : 67 main.log.error("Connection failed to the host")
68 69
70 - def get_version(self):
71 file_input = path+'/lib/pox/core.py' 72 version = super(PoxCliDriver, self).get_version() 73 pattern = '\s*self\.version(.*)' 74 import re 75 for line in open(file_input,'r').readlines(): 76 result = re.match(pattern, line) 77 if result: 78 version = result.group(0) 79 version = re.sub("\s*self\.version\s*=\s*|\(|\)",'',version) 80 version = re.sub(",",'.',version) 81 version = "POX "+version 82 83 84 return version
85 86
87 - def getcmd(self,options):
88 command = "./pox.py " 89 for item in options.keys(): 90 if isinstance(options[item],dict): 91 command = command + item 92 for items in options[item].keys(): 93 if options[item][items] == "None": 94 command = command + " --" + items + " " 95 else : 96 command = command + " --" + items + "=" + options[item][items] + " " 97 else: 98 if item == 'pox_lib_location': 99 poxLibPath = options[item] 100 elif item == 'type' or item == 'name': 101 pass 102 else : 103 command = command + item 104 105 106 return command
107 108 109 if __name__ != "__main__": 110 import sys 111 112 sys.modules[__name__] = PoxCliDriver() 113