@@ -94,12 +94,22 @@ def parseArgs():
94
94
op .add_option ( '--enable_profile' , '-p' , action = "store_true" ,
95
95
dest = "enable_profile" ,
96
96
help = 'enable yappi multithreaded profiler' )
97
+ backends = ['pox' , 'ryu' ]
98
+ op .add_option ( '--backend' , '-b' , type = 'choice' ,
99
+ choices = backends ,
100
+ default = 'pox' ,
101
+ help = '|' .join (backends ) )
97
102
98
103
op .set_defaults (frontend_only = False ,mode = 'reactive0' ,enable_profile = False )
99
104
options , args = op .parse_args ()
100
105
101
106
return (op , options , args , kwargs_to_pass )
102
107
108
+ def which (file ):
109
+ for path in os .environ ["PATH" ].split (":" ):
110
+ if os .path .exists (path + "/" + file ):
111
+ return path + "/" + file
112
+ return None
103
113
104
114
def main ():
105
115
global of_client , enable_profile
@@ -174,29 +184,35 @@ def log_writer(queue, log_level):
174
184
handler = util .QueueStreamHandler (logging_queue )
175
185
logger .addHandler (handler )
176
186
logger .setLevel (log_level )
177
-
187
+
178
188
runtime = Runtime (Backend (),main ,path_main ,kwargs ,options .mode ,options .verbosity )
179
189
if not options .frontend_only :
180
- try :
181
- output = subprocess .check_output ('echo $PYTHONPATH' ,shell = True ).strip ()
182
- except :
183
- print 'Error: Unable to obtain PYTHONPATH'
190
+ if options .backend == 'pox' :
191
+ backend_client = 'of_client.pox_client'
192
+ backend_path = None
193
+ for p in sys .path :
194
+ if re .match ('.*pox/?$' ,p ):
195
+ backend_path = os .path .abspath (p )
196
+ break
197
+ if backend_path is None :
198
+ print 'Error: {} not found in PYTHONPATH' .format (backend )
199
+ sys .exit (1 )
200
+ backend_exec = os .path .join (backend_path ,'pox.py' )
201
+ elif options .backend == 'ryu' :
202
+ backend_client = 'of_client.ryu_shim'
203
+ backend_exec = which ('ryu-manager' )
204
+ if not backend_exec :
205
+ print "Error: Could not find 'ryu-manager' in path. Is ryu installed?"
206
+ else :
207
+ print "Error: Invalid backend '{}' specified" .format (options .backend )
184
208
sys .exit (1 )
185
- poxpath = None
186
- for p in output .split (':' ):
187
- if re .match ('.*pox/?$' ,p ):
188
- poxpath = os .path .abspath (p )
189
- break
190
- if poxpath is None :
191
- print 'Error: pox not found in PYTHONPATH'
192
- sys .exit (1 )
193
- pox_exec = os .path .join (poxpath ,'pox.py' )
209
+
194
210
python = sys .executable
195
- # TODO(josh): pipe pox_client stdout to subprocess.PIPE or
211
+ # TODO(josh): pipe backend stdout to subprocess.PIPE or
196
212
# other log file descriptor if necessary
197
- of_client = subprocess .Popen ([python ,
198
- pox_exec ,
199
- 'of_client.pox_client' ],
213
+ of_client = subprocess .Popen ([python ,
214
+ backend_exec ,
215
+ backend_client ],
200
216
stdout = sys .stdout ,
201
217
stderr = subprocess .STDOUT )
202
218
0 commit comments