Hi,
How about this?
(I use oslo.config lib)
$ git diff
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index b9cbad0..cd89c7f 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -21,6 +21,10 @@ from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
+import sys
+import json
+from oslo.config import cfg
+
class SimpleSwitch13(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
@@ -47,6 +51,24 @@ class SimpleSwitch13(app_manager.RyuApp):
ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions)
+
+ CONF = cfg.CONF
+ CONF.register_opts([
+ cfg.IntOpt('test-param_int', default=0),
+ cfg.StrOpt('test-param_str', default='default'),
+ cfg.StrOpt('test-param_jsn', default='None')])
+ CONF(sys.argv[1:])
+
+ print 'test_param_int = %d' % CONF.test_param_int
+ print 'test_param_str = %s' % CONF.test_param_str
+ print 'test_param_jsn = %s' % CONF.test_param_jsn
+
+ json_data = json.loads(CONF.test_param_jsn)
+ print 'json_data = %s' % json_data
+
+ dumped_data = json.dumps(json_data)
+ print 'dumped_data = %s' % dumped_data
+
def add_flow(self, datapath, priority, match, actions, buffer_id=None):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# JSON data with one line.
$ cat test_file.cfg
[DEFAULT]
test_parm_int=12345
test_param_str=test
test_param_jsn={ "switches" : [ { "dpid" : "b6-ad-fb-ca-08-45", "ports" : [ {
"port-number" : 1, "vlans" : [101, 102, 103] }, { "port-number" : 2, "vlans" :
[105] } ] } ] }
# You can change config file with '--config-file' option.
$ sudo ryu-manager --config-file test_file.cfg ryu.app.simple_switch_13
[sudo] password for ryu:
loading app ryu.app.simple_switch_13
loading app ryu.controller.ofp_handler
instantiating app ryu.app.simple_switch_13 of SimpleSwitch13
instantiating app ryu.controller.ofp_handler of OFPHandler
test_param_int = 0
test_param_str = test
test_param_jsn = { "switches" : [ { "dpid" : "b6-ad-fb-ca-08-45", "ports" : [ {
"port-number" : 1, "vlans" : [101, 102, 103] }, { "port-number" : 2, "vlans" :
[105] } ] } ] }
json_data = {u'switches': [{u'ports': [{u'vlans': [101, 102, 103],
u'port-number': 1}, {u'vlans': [105], u'port-number': 2}], u'dpid':
u'b6-ad-fb-ca-08-45'}]}
dumped_data = {"switches": [{"ports": [{"vlans": [101, 102, 103],
"port-number": 1}, {"vlans": [105], "port-number": 2}], "dpid":
"b6-ad-fb-ca-08-45"}]}
Thanks
On 2015年02月17日 09:13, A Sydney wrote:
> Any feedback?
>
> Thanks,
> Ali
>
> On Fri, Feb 13, 2015 at 10:34 AM, A Sydney <[email protected]
> <mailto:[email protected]>> wrote:
>
> Thanks for the quick reply :)
>
> Perhaps I should expound a bit...
>
> Below is an example of such a config file I'd like to pass to my ryu
> application: for each dpid, I'd like to track the associated VLANs allocated
> on each port (Please use the codepad link below if the format below is messed
> up). As shown, this config file can change quite a bit and hence reinstalling
> ryu after every change may not be ideal. Perhaps the "--config-file
> <fileLocation>" parameter can help? If yes, how would I use it?
>
> {
> "switches" : [
> {
> "dpid" : "b6-ad-fb-ca-08-45",
> "ports" : [
> {
> "port-number" : 1,
> "vlans" :
> [101, 102, 103]
> },
> {
> "port-number" : 2,
> "vlans" :
> [105]
> }
> ]
> }
>
> ]
> }
>
> REF(same as above):
> http://codepad.org/ZvMY9ySy
>
> Thanks,
> Ali
>
> On Fri, Feb 13, 2015 at 3:36 AM, Yusuke Iwase <[email protected]
> <mailto:[email protected]>> wrote:
>
> Hi,
>
> Ryu uses oslo.config library.
> You can use default Ryu configuration file (etc/ryu/ryu.conf) as
> follow.
>
> # Set params
> $ vi etc/ryu/ryu.conf
> ...
> test_param1=12345
> test_param2='test'
> ...
>
> # Get params in your App
> $ vi yourapp.py
> ...
> :
> from ryu import cfg
> :
> class SimpleSwitch13(app_manager.RyuApp):
> def __init__(self, *args, **kwargs):
> super(SimpleSwitch13, self).__init__(*args, **kwargs)
> :
> CONF = cfg.CONF
> CONF.register_opts([
> cfg.IntOpt('test-param1', default=0),
> cfg.StrOpt('test-param2', default='default')])
> print 'test_param1 = %d' % CONF.test_param1
> print 'test_param2 = %s' % CONF.test_param2
> ...
>
> # Reinstall ryu
> $ sudo python setup.py install
>
> # Run
> $ ryu-manager ryu.app.simple_switch_13
> loading app ryu.app.simple_switch_13
> loading app ryu.controller.ofp_handler
> instantiating app ryu.app.simple_switch_13 of SimpleSwitch13
> instantiating app ryu.controller.ofp_handler of OFPHandler
> test_param1 = 12345
> test_param2 = test
>
> Thanks
>
> On 2015年02月13日 08:05, A Sydney wrote:
> > Hi Ryu folks,
> > I'd like to pass a configuration file to an OF
> 1.3 app (perhaps containing information of dpids and corresponding ports).
> The documentation says I could use "--config-file" to pass a file to an
> application, but how do I go about creating the file and extracting the
> contents from the application? Can I use json/xml? Perhaps someone can
> share an example of a config file?
> >
> > Thanks,
> > Ali
> >
> >
> >
> ------------------------------------------------------------------------------
> > Dive into the World of Parallel Programming. The Go Parallel
> Website,
> > sponsored by Intel and developed in partnership with Slashdot
> Media, is your
> > hub for all things parallel software development, from weekly
> thought
> > leadership blogs to news, videos, case studies, tutorials and more.
> Take a
> > look and join the conversation now.
> http://goparallel.sourceforge.net/
> >
> >
> >
> > _______________________________________________
> > Ryu-devel mailing list
> > [email protected]
> <mailto:[email protected]>
> > https://lists.sourceforge.net/lists/listinfo/ryu-devel
> >
>
>
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel