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   
  8      TestON is free software: you can redistribute it and/or modify 
  9      it under the terms of the GNU General Public License as published by 
 10      the Free Software Foundation, either version 2 of the License, or 
 11      ( at your option ) any later version. 
 12   
 13      TestON is distributed in the hope that it will be useful, 
 14      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16      GNU General Public License for more details. 
 17   
 18      You should have received a copy of the GNU General Public License 
 19      along with TestON.  If not, see <http://www.gnu.org/licenses/>. 
 20   
 21   
 22  pox driver provides the basic functions of POX controller 
 23  """ 
 24  import pexpect 
 25  import struct 
 26  import fcntl 
 27  import os 
 28  import signal 
 29  import sys 
 30  from drivers.common.cli.emulatordriver import Emulator 
 31   
 32   
33 -class PoxCliDriver( Emulator ):
34 35 """ 36 PoxCliDriver driver provides the basic functions of POX controller 37 """
38 - def __init__( self ):
39 super( Emulator, self ).__init__() 40 self.handle = self 41 self.wrapped = sys.modules[ __name__ ]
42
43 - def connect( self, **connectargs ):
44 #,user_name, ip_address, pwd,options ): 45 """ 46 this subroutine is to launch pox controller . It must have arguments as : 47 user_name = host name , 48 ip_address = ip address of the host , 49 pwd = password of host , 50 options = it is a topology hash which will consists the component's details for the test run 51 52 *** host is here a virtual mahine or system where pox framework hierarchy exists 53 """ 54 for key in connectargs: 55 vars( self )[ key ] = connectargs[ key ] 56 57 self.name = self.options[ 'name' ] 58 59 poxLibPath = 'default' 60 copy = super( 61 PoxCliDriver, 62 self ).secureCopy( 63 self.user_name, 64 self.ip_address, 65 '/home/openflow/pox/pox/core.py', 66 self.pwd, 67 path + 68 '/lib/pox/' ) 69 self.handle = super( 70 PoxCliDriver, 71 self ).connect( 72 user_name=self.user_name, 73 ip_address=self.ip_address, 74 port=None, 75 pwd=self.pwd ) 76 77 if self.handle: 78 self.handle.expect( "openflow" ) 79 command = self.getcmd( self.options ) 80 # print command 81 main.log.info( "Entering into POX hierarchy" ) 82 if self.options[ 'pox_lib_location' ] != 'default': 83 self.execute( 84 cmd="cd " + 85 self.options[ 'pox_lib_location' ], 86 prompt="/pox\$", 87 timeout=120 ) 88 else: 89 self.execute( 90 cmd="cd ~/TestON/lib/pox/", 91 prompt="/pox\$", 92 timeout=120 ) 93 # launching pox with components 94 main.log.info( "launching POX controller with given components" ) 95 self.execute( cmd=command, prompt="DEBUG:", timeout=120 ) 96 return main.TRUE 97 else: 98 main.log.error( 99 "Connection failed to the host " + 100 self.user_name + 101 "@" + 102 self.ip_address ) 103 main.log.error( "Failed to connect to the POX controller" ) 104 return main.FALSE
105
106 - def disconnect( self, handle ):
107 if self.handle: 108 self.execute( cmd="exit()", prompt="/pox\$", timeout=120 ) 109 else: 110 main.log.error( "Connection failed to the host" )
111
112 - def get_version( self ):
113 file_input = path + '/lib/pox/core.py' 114 version = super( PoxCliDriver, self ).get_version() 115 pattern = '\s*self\.version(.*)' 116 import re 117 for line in open( file_input, 'r' ).readlines(): 118 result = re.match( pattern, line ) 119 if result: 120 version = result.group( 0 ) 121 version = re.sub( 122 "\s*self\.version\s*=\s*|\(|\)", 123 '', 124 version ) 125 version = re.sub( ",", '.', version ) 126 version = "POX " + version 127 128 return version
129
130 - def getcmd( self, options ):
131 command = "./pox.py " 132 for item in options.keys(): 133 if isinstance( options[ item ], dict ): 134 command = command + item 135 for items in options[ item ].keys(): 136 if options[ item ][ items ] == "None": 137 command = command + " --" + items + " " 138 else: 139 command = command + " --" + items + \ 140 "=" + options[ item ][ items ] + " " 141 else: 142 if item == 'pox_lib_location': 143 poxLibPath = options[ item ] 144 elif item == 'type' or item == 'name': 145 pass 146 else: 147 command = command + item 148 149 return command
150 151 152 if __name__ != "__main__": 153 import sys 154 155 sys.modules[ __name__ ] = PoxCliDriver() 156