Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 84f0aab

Browse files
committed
Add ryu backend integration
Signed-off-by: James Guthrie <[email protected]>
1 parent ed1b96f commit 84f0aab

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

of_client/ryu_shim.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
from ryu.lib.packet import packet, ethernet, lldp
3333
from ryu.lib.packet import ethernet
3434
from ryu.lib.packet import ipv4
35-
from ryu.netide.comm import *
36-
35+
from pyretic.backend.comm import *
3736

3837
def inport_value_hack(outport):
3938
if outport > 1:
@@ -111,8 +110,12 @@ def found_terminator(self):
111110
with self.of_client.channel_lock:
112111
msg = deserialize(self.received_data)
113112

113+
# Set up time for starting rule installs.
114+
if msg[0] == 'reset_install_time':
115+
pass
116+
# Ignore this for now - pyretic-specific thing
114117
# USE DESERIALIZED MSG
115-
if msg[0] == 'inject_discovery_packet':
118+
elif msg[0] == 'inject_discovery_packet':
116119
switch = msg[1]
117120
port = msg[2]
118121
self.of_client.inject_discovery_packet(switch,port)
@@ -188,7 +191,7 @@ def __init__(self, *args, **kwargs):
188191
}
189192

190193
self.channel_lock = threading.Lock()
191-
self.backend_channel = BackendChannel('127.0.0.1', RYU_BACKEND_PORT, self)
194+
self.backend_channel = BackendChannel('127.0.0.1', BACKEND_PORT, self)
192195
self.al = asyncore_loop()
193196
self.al.start()
194197

@@ -698,4 +701,4 @@ def _packet_in_handler(self, ev):
698701

699702
received = self.packet_from_network(switch=datapath.id, inport=msg.in_port, raw=msg.data)
700703
self.send_to_pyretic(['packet',received])
701-
704+

pyretic.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,22 @@ def parseArgs():
9494
op.add_option( '--enable_profile', '-p', action="store_true",
9595
dest="enable_profile",
9696
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) )
97102

98103
op.set_defaults(frontend_only=False,mode='reactive0',enable_profile=False)
99104
options, args = op.parse_args()
100105

101106
return (op, options, args, kwargs_to_pass)
102107

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
103113

104114
def main():
105115
global of_client, enable_profile
@@ -174,29 +184,35 @@ def log_writer(queue, log_level):
174184
handler = util.QueueStreamHandler(logging_queue)
175185
logger.addHandler(handler)
176186
logger.setLevel(log_level)
177-
187+
178188
runtime = Runtime(Backend(),main,path_main,kwargs,options.mode,options.verbosity)
179189
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)
184208
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+
194210
python=sys.executable
195-
# TODO(josh): pipe pox_client stdout to subprocess.PIPE or
211+
# TODO(josh): pipe backend stdout to subprocess.PIPE or
196212
# 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 ],
200216
stdout=sys.stdout,
201217
stderr=subprocess.STDOUT)
202218

0 commit comments

Comments
 (0)