Hi Sandesh,

On 2015年03月22日 13:08, Sandesh Shrestha wrote:
> Dear All,
> 
> I need to pass arguments to ryu app. How can I do that and how to get that in 
> the app.

How about adding CLI options for your App as follow?


$ git diff
diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py
index b9cbad0..1014c9f 100644
--- a/ryu/app/simple_switch_13.py
+++ b/ryu/app/simple_switch_13.py
@@ -20,6 +20,13 @@ from ryu.controller.handler import set_ev_cls
 from ryu.ofproto import ofproto_v1_3
 from ryu.lib.packet import packet
 from ryu.lib.packet import ethernet
+from ryu import cfg
+
+CONF = cfg.CONF
+CONF.register_cli_opts([
+    cfg.StrOpt('test-param-str', default='default-str',
+               help='test-param-for-register-cli-opts')
+])
 
 
 class SimpleSwitch13(app_manager.RyuApp):
@@ -29,6 +36,9 @@ class SimpleSwitch13(app_manager.RyuApp):
         super(SimpleSwitch13, self).__init__(*args, **kwargs)
         self.mac_to_port = {}
 
+        # Get param
+        print 'test-param-str = %s' % self.CONF.test_param_str
+
     @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
     def switch_features_handler(self, ev):
         datapath = ev.msg.datapath
diff --git a/ryu/cmd/manager.py b/ryu/cmd/manager.py
index 66d59b3..6dca80c 100755
--- a/ryu/cmd/manager.py
+++ b/ryu/cmd/manager.py
@@ -41,6 +41,8 @@ from ryu.app import wsgi
 from ryu.base.app_manager import AppManager
 from ryu.controller import controller
 from ryu.topology import switches
+# import your app
+from ryu.app import simple_switch_13
 
 
 CONF = cfg.CONF
$ 
$ 
$ sudo python setup.py install
$ 
$ sudo ryu-manager ryu.app.simple_switch_13 --test-param-str abc123
loading app ryu.app.simple_switch_13
loading app ryu.controller.ofp_handler
instantiating app ryu.app.simple_switch_13 of SimpleSwitch13
test-param-str = abc123
instantiating app ryu.controller.ofp_handler of OFPHandler
 ...
$ 


OR,
You can use Ryu config file (etc/ryu/ryu.conf).
This way is easy to use, but you need to modify the config file before running 
ryu-manager.


Thanks

> 
> 
> Thanks,
> Sandesh Shrestha
> 
> 
> ------------------------------------------------------------------------------
> 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]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
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]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to