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