1
2 """
3 Created on 26-Mar-2013
4
5 author:: Anil Kumar ( anilkumar.s@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 FlowVisorDriver is the basic driver which will handle the Mininet functions
23 """
24 import re
25 import sys
26 from drivers.common.cli.emulatordriver import Emulator
27
28
30
31 """
32 FlowVisorDriver is the basic driver which will handle the Mininet functions
33 """
35 super( Emulator, self ).__init__()
36 self.handle = self
37 self.wrapped = sys.modules[ __name__ ]
38
39 - def connect( self, **connectargs ):
40
41
42
43 for key in connectargs:
44 vars( self )[ key ] = connectargs[ key ]
45
46 self.name = self.options[ 'name' ]
47 self.handle = super(
48 FlowVisorDriver,
49 self ).connect(
50 user_name=self.user_name,
51 ip_address=self.ip_address,
52 port=None,
53 pwd=self.pwd )
54
55 self.ssh_handle = self.handle
56
57
58 if self.handle:
59 self.execute( cmd='\r', prompt='\$', timeout=10 )
60 self.options[ 'path' ] = '/home/openflow/flowvisor/scripts/'
61
62 self.execute(
63 cmd='cd ' +
64 self.options[ 'path' ],
65 prompt='\$',
66 timeout=10 )
67 main.log.info( "Starting FlowVisor " )
68
69 response = self.execute(
70 cmd='./flowvisor.sh &',
71 prompt='---\sSetting\slogging\slevel\sto\sNOTE',
72 timeout=10 )
73
74 pattern = '\d+'
75
76 process_id_search = re.search( "\[\d+\]\s+(\d+)", str( response ) )
77 self.fvprocess_id = "None"
78 if process_id_search:
79 self.fvprocess_id = process_id_search.group( 1 )
80
81 utilities.assert_matches(
82 expect=pattern,
83 actual=response,
84 onpass="FlowVisor Started Successfully : Proceess Id :" +
85 self.fvprocess_id,
86 onfail="Failed to start FlowVisor" )
87 main.log.info( response )
88
89
90
91
92 return main.TRUE
93 else:
94 main.log.error(
95 "Connection failed to the host " +
96 self.user_name +
97 "@" +
98 self.ip_address )
99 main.log.error( "Failed to connect to the FlowVisor" )
100 return main.FALSE
101
103 if id == "all":
104 flow_space = self.listFlowSpace()
105 flow_ids = re.findall( "\,id=\[(\d+)\]", flow_space )
106 for id in flow_ids:
107 self.removeFlowSpace( id )
108 else:
109 self.execute( cmd="clear", prompt="\$", timeout=10 )
110 self.execute(
111 cmd="./fvctl.sh removeFlowSpace " +
112 id,
113 prompt="passwd:",
114 timeout=10 )
115 self.execute( cmd="\n", prompt="\$", timeout=10 )
116 main.log.info( "Removed flowSpace which is having id :" + id )
117
118 return main.TRUE
119
121 temp_string = None
122 for key in flowspace_args:
123 if temp_string:
124 temp_string = temp_string + ',' + \
125 key + '=' + flowspace_args[ key ]
126 else:
127 temp_string = ''
128 temp_string = temp_string + key + '=' + flowspace_args[ key ]
129
130 src_search = re.search( 'dl_src', temp_string )
131 if src_search:
132 flowspace = "any 100 dl_type=0x806,nw_proto=6," + \
133 temp_string + " Slice:SSH=4"
134 else:
135 flowspace = "any 100 dl_type=0x800,nw_proto=6," + \
136 temp_string + " Slice:SSH=4"
137
138 """
139 try :
140 if self.dl_src and self.nw_dst:
141 flowspace = "any 100 dl_type=0x806,dl_src="+self.dl_src+",nw_dst="+self.nw_dst+" Slice:"+self.Slice+"=4"
142 except Exception:
143 try :
144 if self.nw_src and self.tp_dst:
145 flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_dst="+self.tp_dst+" Slice:"+self.Slice+"=4"
146 except Exception:
147 try :
148 if self.nw_src and self.tp_src:
149 flowspace = "any 100 dl_type=0x800,nw_proto=6,nw_src="+self.nw_src+",tp_src="+self.tp_dst+" Slice:"+self.Slice+"=4"
150 except Exception:
151 main.log.error( "Please specify flowspace properly" )
152 """
153
154 self.execute(
155 cmd="./fvctl.sh addFlowSpace " +
156 flowspace,
157 prompt="passwd:",
158 timeout=10 )
159 self.execute( cmd="\n", prompt="\$", timeout=10 )
160 sucess_match = re.search( "success\:\s+(\d+)", main.last_response )
161 if sucess_match:
162 main.log.info(
163 "Added flow Space and id is " +
164 sucess_match.group( 1 ) )
165 return main.TRUE
166 else:
167 return main.FALSE
168
170 self.execute( cmd="clear", prompt="\$", timeout=10 )
171 self.execute(
172 cmd="./fvctl.sh listFlowSpace ",
173 prompt="passwd:",
174 timeout=10 )
175 self.execute( cmd="\n", prompt="\$", timeout=10 )
176 flow_space = main.last_response
177 flow_space = self.remove_contol_chars( flow_space )
178 flow_space = re.sub(
179 "rule\s(\d+)\:",
180 "\nrule " +
181 r'\1' +
182 ":",
183 flow_space )
184 main.log.info( flow_space )
185
186 return flow_space
187
189
190
191
192 devices_list = ''
193 last_response = re.findall(
194 "(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))",
195 main.last_response )
196
197 for resp in last_response:
198 devices_match = re.search(
199 "(Device\s\d+\:\s((\d|[a-z])(\d|[a-z])\:)+(\d|[a-z])(\d|[a-z]))",
200 str( resp ) )
201 if devices_match:
202 devices_list = devices_list + devices_match.group( 0 ) + "\n"
203 devices_list = "Device 0: 00:00:00:00:00:00:00:02 \n Device 1: 00:00:00:00:00:00:00:03"
204 main.log.info( "List of Devices \n" + devices_list )
205
206 return main.TRUE
207
209
210 response = ''
211 main.log.info( "Stopping the FlowVisor" )
212 if self.handle:
213 self.handle.sendline( "kill -9 " + str( self.fvprocess_id ) )
214 else:
215 main.log.error( "Connection failed to the host" )
216 response = main.FALSE
217 return response
218