Thread: [Ryu-devel] Passing config file to Ryu app
Brought to you by:
nz_gizmoguy
From: A S. <asy...@gm...> - 2015-02-12 23:05:34
|
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 |
From: Yusuke I. <iwa...@gm...> - 2015-02-13 08:36:41
|
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 > Ryu...@li... > https://lists.sourceforge.net/lists/listinfo/ryu-devel > |
From: A S. <asy...@gm...> - 2015-02-13 15:34:37
|
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 <iwa...@gm...> 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 > > Ryu...@li... > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > |
From: A S. <asy...@gm...> - 2015-02-17 00:13:19
|
Any feedback? Thanks, Ali On Fri, Feb 13, 2015 at 10:34 AM, A Sydney <asy...@gm...> 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 <iwa...@gm...> > 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 >> > Ryu...@li... >> > https://lists.sourceforge.net/lists/listinfo/ryu-devel >> > >> > > |
From: Yusuke I. <iwa...@gm...> - 2015-02-17 00:44:08
|
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 <asy...@gm... <mailto:asy...@gm...>> 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 <iwa...@gm... <mailto:iwa...@gm...>> 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 > > Ryu...@li... <mailto:Ryu...@li...> > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > > > |
From: A S. <asy...@gm...> - 2015-02-19 23:36:40
|
That will do :) Thanks a bunch! -Ali On Mon, Feb 16, 2015 at 7:43 PM, Yusuke Iwase <iwa...@gm...> wrote: > 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 <asy...@gm... > <mailto:asy...@gm...>> 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 < > iwa...@gm... <mailto:iwa...@gm...>> 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 > > > Ryu...@li... <mailto: > Ryu...@li...> > > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > > > > > > > > |