Hi Douglas,

Hmmm... how about swapping the order of arguments?

e.g)
if __name__ == "__main__":
    manager.main(args=['ryu.app.ofctl_rest'] + sys.argv)


FYI, I guess Dr.Bernstein did "hack"(used "ryu.cmd.manager" directly) in order 
to
add original CLI option like "--netfile" and "--widest_paths".
On the other hand, you can add your original CLI option as following.

$ git diff
diff --git a/ryu/flags.py b/ryu/flags.py
index 69eb3d2..ebf16c8 100644
--- a/ryu/flags.py
+++ b/ryu/flags.py
@@ -112,3 +112,10 @@ CONF.register_cli_opts([
         help='Initial Router ID used by Zebra protocol service '
              '(default: %s)' % DEFAULT_ZSERV_ROUTER_ID),
 ], group='zapi')
+
+CONF.register_cli_opts([
+    cfg.StrOpt(
+        'netfile', default=None, help='network json file'),
+    cfg.BoolOpt(
+        'widest_paths', default=False, help='Use widest path.'),
+])


Please note you need to re-install Ryu after the above modifications.

$ python setup.py install


Then, with this modification, you can run "l2DestForwardStaticRyu.py" as the
standard Ryu application via "ryu-manager":

$ ryu-manager --help
...(snip)...
  --netfile NETFILE     network json file
...(snip)...
  --widest_paths        Use widest path.
...(snip)...

$ ryu-manager l2DestForwardStaticRyu.py ryu.app.ofctl_rest 
--netfile=ExNetwithLoops1A.json --widest_paths


Thanks,
Iwase


On 2017年06月13日 22:04, Douglas Harewood-Gill wrote:
> Hi Iwase and thank you for getting back to me. The author of this program, Dr 
> Bernstein added this line "from ryu.cmd import manager" which as far as I 
> understand directly starts Ryu from within side L2DestForwardStaticRyu.py. 
> Should be around line 29 I think. He had to do this he told me because he 
> could not start the program in the conventional way because he needed to 
> import the "ExNetwithLoops!A.json file" for the topology with static mac and 
> IP addresses. Apparently he could not do this just using the standard Ryu 
> format of starting the Ryu Manager with the Controller file and then with 
> REST.
> 
> I tried your suggestion by removing "manager.main(args=sys.argv)"
> 
> from   " if __name__ == "__main__": "
> 
> and using the following:-
> 
> "manager.main(args=sys.argv + ['ryu.app.ofctl_rest'])" and I got the 
> following error message in the terminal.
> 
> "l2DestForwardStaticRyuNS: error: unrecognized arguments: ryu.app.ofctl_rest"
> 
> Any advice would be welcome. I am obviously going to see what I can find here 
> and will let you know if I find anything relevant.
> 
> Cheers
> 
> Douglas
> 
> 
> 
> 
> On 13 June 2017 at 02:17, Iwase Yusuke <iwase.yusu...@gmail.com 
> <mailto:iwase.yusu...@gmail.com>> wrote:
> 
>     Hi Douglas,
> 
>     I checked "L2DestForwardStaticRyu.py", and it seems to be "hacked" to run
>     app without "ryu-manager".
>     To start the built-in Ryu application with "L2DestForwardStaticRyu.py",
>     how about the following?
>     The following appends to "ofctl_rest" app to the argument of "manager".
> 
>     e.g.) around line 91:
> 
>      if __name__ == "__main__":
>     -    manager.main(args=sys.argv)
>     +    manager.main(args=sys.argv + ['ryu.app.ofctl_rest'])
> 
> 
>     Thanks,
>     Iwase
> 
> 
>     On 2017年06月09日 21:00, Douglas Harewood-Gill wrote:
>     > Hi Iwase. Thank you for contacting me and apologies for my delay in 
> responding. I have tried what you have suggested but the problem I have is 
> that the L2DestForwardStaticRyu.py program is designed to run on its own. It 
> imports the the ryu.cmd import manager and uses the Ryu controller but you 
> start it by typing "|python l2DestForwardStaticRyu.py 
> --netfile=ExNetwithLoops1A.json" |where  it imports =ExNetWithLoops1A.Json.
>     > When this program is started, it automatically loads Ryu and implements 
> the code within this program. I am not sure how to start the this and 
> ryu.app.ofctl_rest at the same time. I have tried starting them separately in 
> different terminals but that did not work.
>     >
>     > Thank you also for the information you have sent. I have looked at it 
> before but I do not know how to implement this with my custom code. I have 
> been looking for examples but they seem to be few and far between. Any advice 
> as always would be greatly appreciated.
>     >
>     > Thanks again.
>     >
>     > Douglas
>     >
>     > On 8 June 2017 at 01:27, Iwase Yusuke <iwase.yusu...@gmail.com 
> <mailto:iwase.yusu...@gmail.com> <mailto:iwase.yusu...@gmail.com 
> <mailto:iwase.yusu...@gmail.com>>> wrote:
>     >
>     >     Hi Douglas,
>     >
>     >     Excuse me for cutting in.
>     >
>     >     Just for getting flow statistics, how about running your app and 
> ofctl_rest
>     >     together as Fujimoto said.
>     >     e.g.)
>     >      $ ryu-manager your_app.py ryu.app.ofctl_rest
>     >
>     >
>     >     If you want to implement your own REST APIs on your app, Ryu-Book 
> is the
>     >     most helpful as far as I know.
>     >     (You might already be aware of this though...)
>     >       http://osrg.github.io/ryu-book/en/html/rest_api.html 
> <http://osrg.github.io/ryu-book/en/html/rest_api.html> 
> <http://osrg.github.io/ryu-book/en/html/rest_api.html 
> <http://osrg.github.io/ryu-book/en/html/rest_api.html>>
>     >
>     >
>     >     FYI, here is an sample implementation on simple_switch_13.py for 
> getting
>     >     flow statistics.
>     >     The usage of "WSGI" framework is described on Ryu-Book.
>     >
>     >
>     >     $ git diff
>     >     diff --git a/ryu/app/simple_switch_13.py 
> b/ryu/app/simple_switch_13.py
>     >     index 3e7c598..f33e474 100644
>     >     --- a/ryu/app/simple_switch_13.py
>     >     +++ b/ryu/app/simple_switch_13.py
>     >     @@ -13,6 +13,8 @@
>     >      # See the License for the specific language governing permissions 
> and
>     >      # limitations under the License.
>     >
>     >     +import json
>     >     +
>     >      from ryu.base import app_manager
>     >      from ryu.controller import ofp_event
>     >      from ryu.controller.handler import CONFIG_DISPATCHER, 
> MAIN_DISPATCHER
>     >     @@ -21,14 +23,26 @@ from ryu.ofproto import ofproto_v1_3
>     >      from ryu.lib.packet import packet
>     >      from ryu.lib.packet import ethernet
>     >      from ryu.lib.packet import ether_types
>     >     +from ryu.app.ofctl import api as ofctl_api
>     >     +from ryu.app.wsgi import ControllerBase
>     >     +from ryu.app.wsgi import Response
>     >     +from ryu.app.wsgi import route
>     >     +from ryu.app.wsgi import WSGIApplication
>     >     +
>     >     +
>     >     +_URI_PREFIX = '/simpleswitch/stats/{dpid}'
>     >
>     >
>     >      class SimpleSwitch13(app_manager.RyuApp):
>     >          OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
>     >     +    _CONTEXTS = {'wsgi': WSGIApplication}
>     >
>     >          def __init__(self, *args, **kwargs):
>     >              super(SimpleSwitch13, self).__init__(*args, **kwargs)
>     >              self.mac_to_port = {}
>     >     +        wsgi = kwargs['wsgi']
>     >     +        wsgi.register(SimpleSwitchController,
>     >     +                      {SimpleSwitch13.__name__: self})
>     >
>     >          @set_ev_cls(ofp_event.EventOFPSwitchFeatures, 
> CONFIG_DISPATCHER)
>     >          def switch_features_handler(self, ev):
>     >     @@ -117,3 +131,32 @@ class SimpleSwitch13(app_manager.RyuApp):
>     >              out = parser.OFPPacketOut(datapath=datapath, 
> buffer_id=msg.buffer_id,
>     >                                        in_port=in_port, 
> actions=actions, data=data)
>     >              datapath.send_msg(out)
>     >     +
>     >     +    def get_flow_stats(self, dpid):
>     >     +        datapath = ofctl_api.get_datapath(self, dpid)
>     >     +        if datapath is None:
>     >     +            return None
>     >     +
>     >     +        parser = datapath.ofproto_parser
>     >     +        req = parser.OFPFlowStatsRequest(datapath)
>     >     +
>     >     +        rep = ofctl_api.send_msg(
>     >     +            app=self, msg=req,
>     >     +            reply_cls=parser.OFPFlowStatsReply, reply_multi=True)
>     >     +        return [r.to_jsondict() for r in rep]
>     >     +
>     >     +
>     >     +class SimpleSwitchController(ControllerBase):
>     >     +
>     >     +    def __init__(self, req, link, data, **config):
>     >     +        super(SimpleSwitchController, self).__init__(req, link, 
> data, **config)
>     >     +        self.simple_switch_app = data[SimpleSwitch13.__name__]
>     >     +
>     >     +    @route('simpleswitch', _URI_PREFIX, methods=['GET'])
>     >     +    def list_mac_table(self, req, **kwargs):
>     >     +        dpid = int(str(kwargs['dpid']))
>     >     +        ret = self.simple_switch_app.get_flow_stats(dpid)
>     >     +        if ret is None:
>     >     +            return Response(status=404)
>     >     +
>     >     +        return Response(content_type='application/json', 
> body=json.dumps(ret))
>     >
>     >
>     >     $ ryu-manager ryu/app/simple_switch_13.py
>     >     Registered VCS backend: git
>     >     Registered VCS backend: hg
>     >     Registered VCS backend: svn
>     >     Registered VCS backend: bzr
>     >     loading app ryu/app/simple_switch_13.py
>     >     loading app ryu.controller.ofp_handler
>     >     loading app ryu.app.ofctl.service
>     >     loading app ryu.controller.ofp_handler
>     >     creating context wsgi
>     >     instantiating app ryu.app.ofctl.service of OfctlService
>     >     instantiating app ryu/app/simple_switch_13.py of SimpleSwitch13
>     >     instantiating app ryu.controller.ofp_handler of OFPHandler
>     >     (10332) wsgi starting up on http://0.0.0.0:8080
>     >     ...
>     >
>     >
>     >     $ curl -X GET http://localhost:8080/simpleswitch/stats/1 
> <http://localhost:8080/simpleswitch/stats/1> 
> <http://localhost:8080/simpleswitch/stats/1 
> <http://localhost:8080/simpleswitch/stats/1>> | python -m json.tool
>     >     [
>     >         {
>     >             "OFPFlowStatsReply": {
>     >                 "body": [
>     >                     {
>     >                         "OFPFlowStats": {
>     >                             "byte_count": 140,
>     >                             "cookie": 0,
>     >                             "duration_nsec": 771000000,
>     >                             "duration_sec": 1,
>     >                             "flags": 0,
>     >                             "hard_timeout": 0,
>     >                             "idle_timeout": 0,
>     >                             "instructions": [
>     >                                 {
>     >                                     "OFPInstructionActions": {
>     >                                         "actions": [
>     >                                             {
>     >                                                 "OFPActionOutput": {
>     >                                                     "len": 16,
>     >                                                     "max_len": 65535,
>     >                                                     "port": 4294967293,
>     >                                                     "type": 0
>     >                                                 }
>     >                                             }
>     >                                         ],
>     >                                         "len": 24,
>     >                                         "type": 4
>     >                                     }
>     >                                 }
>     >                             ],
>     >                             "length": 80,
>     >                             "match": {
>     >                                 "OFPMatch": {
>     >                                     "length": 4,
>     >                                     "oxm_fields": [],
>     >                                     "type": 1
>     >                                 }
>     >                             },
>     >                             "packet_count": 2,
>     >                             "priority": 0,
>     >                             "table_id": 0
>     >                         }
>     >                     }
>     >                 ],
>     >                 "flags": 0,
>     >                 "type": 1
>     >             }
>     >         }
>     >     ]
>     >
>     >
>     >     Thanks,
>     >     Iwase
>     >
>     >
>     >     On 2017年06月07日 20:21, Douglas Harewood-Gill wrote:
>     >     > Hi there. That is fantastic. Sounds exactly like what I am 
> looking for so thank you.
>     >     >
>     >     > One last question for the minute. I know you provided a link but 
> how do you implement this with custom Ryu controller code?
>     >     >
>     >     > My apologies if I am asking something really obvious.
>     >     >
>     >     > Cheers
>     >     >
>     >     > Douglas
>     >     >
>     >     > On 7 June 2017 at 01:15, Fujimoto Satoshi 
> <satoshi.fujimo...@gmail.com <mailto:satoshi.fujimo...@gmail.com> 
> <mailto:satoshi.fujimo...@gmail.com <mailto:satoshi.fujimo...@gmail.com>> 
> <mailto:satoshi.fujimo...@gmail.com <mailto:satoshi.fujimo...@gmail.com> 
> <mailto:satoshi.fujimo...@gmail.com <mailto:satoshi.fujimo...@gmail.com>>>> 
> wrote:
>     >     >
>     >     >     Hi, Douglas
>     >     >
>     >     >     Ryu has ofctl_rest.py, which is a sample application and 
> provides REST API to get flow statistics.
>     >     >             
> http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html> 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html>> 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html> 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html 
> <http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html>>>
>     >     >
>     >     >     I think it is better to use ofctl_rest.py than to implement 
> your own REST API in your app.
>     >     >
>     >     >     Thanks,
>     >     >     Fujimoto
>     >     >
>     >     >
>     >     >     On 2017年06月06日 21:18, Douglas Harewood-Gill wrote:
>     >     >>
>     >     >>     Greetings  I am a PhD student new to both Python and Ryu and 
> I was wondering if anyone could give me some advice.
>     >     >>
>     >     >>
>     >     >>     I am using the Ryu controller program 
> (L2DestForwardStaticRyu.py) provided by Dr Grey Bernstein 
> (https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu> 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu>>
>  <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu> 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu 
> <https://www.grotto-networking.com/SDNfun.html#programming-switches-with-ryu>>>)
>  for shortest path computation for a full Mesh network in Mininet but the 
> example provided does not include REST which I require to be able to collect 
> flow statistics such as the flows in each router, bandwidth, latency, etc.
>     >     >>
>     >     >>
>     >     >>     Unfortunately I have been looking and with the exception of 
> (https://osrg.github.io/ryu-book/en/html/rest_api.html 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html> 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html>> 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html> 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html 
> <https://osrg.github.io/ryu-book/en/html/rest_api.html>>>) which seems overly 
> specific, I am unable to find a good example that would allow me to work out 
> how to integrate REST into the above Ryu control program.
>     >     >>
>     >     >>     So if anyone can point me in the right direction or can 
> provide some examples, I would be most grateful.
>     >     >>
>     >     >>
>     >     >>     Thank you for your time.
>     >     >>
>     >     >>
>     >     >>     Best Regards
>     >     >>
>     >     >>
>     >     >>     Douglas
>     >     >>
>     >     >>
>     >     >>
>     >     >>     --
>     >     >>     *Douglas Harewood-Gill MSc MIET*
>     >     >>     CDT Student in Communications (PhD), University of Bristol
>     >     >>     Post-Graduate Student (Taught and Research)
>     >     >>     e-mail: douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>>>
>     >     >>
>     >     >>     *
>     >     >>     CDT Communications*
>     >     >>
>     >     >>     University of Bristol, Merchant Venturers' Building, 
> Woodland Road, Clifton, Bristol. BS8 1UB
>     >     >>
>     >     >>     http://www.bristol.ac.uk/
>     >     >>
>     >     >>
>     >     >>
>     >     >>
>     >     >>     
> ------------------------------------------------------------------------------
>     >     >>     Check out the vibrant tech community on one of the world's 
> most
>     >     >>     engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>     >     >>
>     >     >>
>     >     >>     _______________________________________________
>     >     >>     Ryu-devel mailing list
>     >     >>     Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net> 
> <mailto:Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net>> 
> <mailto:Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net> 
> <mailto:Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net>>>
>     >     >>     https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel> 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>> 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel> 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>>
>     >     >
>     >     >
>     >     >
>     >     >
>     >     > --
>     >     > *Douglas Harewood-Gill MSc MIET*
>     >     > CDT Student in Communications (PhD), University of Bristol
>     >     > Post-Graduate Student (Taught and Research)
>     >     > e-mail: douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>>>
>     >     >
>     >     > *
>     >     > CDT Communications*
>     >     >
>     >     > University of Bristol, Merchant Venturers' Building, Woodland 
> Road, Clifton, Bristol. BS8 1UB
>     >     >
>     >     > http://www.bristol.ac.uk/
>     >     >
>     >     >
>     >     >
>     >     >
>     >     > 
> ------------------------------------------------------------------------------
>     >     > Check out the vibrant tech community on one of the world's most
>     >     > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>     >     >
>     >     >
>     >     >
>     >     > _______________________________________________
>     >     > Ryu-devel mailing list
>     >     > Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net> 
> <mailto:Ryu-devel@lists.sourceforge.net 
> <mailto:Ryu-devel@lists.sourceforge.net>>
>     >     > https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel> 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>>
>     >     >
>     >
>     >
>     >
>     >
>     > --
>     > *Douglas Harewood-Gill MSc MIET*
>     > CDT Student in Communications (PhD), University of Bristol
>     > Post-Graduate Student (Taught and Research)
>     > e-mail: douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk> 
> <mailto:douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>>
>     >
>     > *
>     > CDT Communications*
>     >
>     > University of Bristol, Merchant Venturers' Building, Woodland Road, 
> Clifton, Bristol. BS8 1UB
>     >
>     > http://www.bristol.ac.uk/
>     >
>     >
>     >
>     >
>     > 
> ------------------------------------------------------------------------------
>     > Check out the vibrant tech community on one of the world's most
>     > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>     >
>     >
>     >
>     > _______________________________________________
>     > Ryu-devel mailing list
>     > Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net>
>     > https://lists.sourceforge.net/lists/listinfo/ryu-devel 
> <https://lists.sourceforge.net/lists/listinfo/ryu-devel>
>     >
> 
> 
> 
> 
> -- 
> *Douglas Harewood-Gill MSc MIET*
> CDT Student in Communications (PhD), University of Bristol
> Post-Graduate Student (Taught and Research)
> e-mail: douglas.harewood-g...@bristol.ac.uk 
> <mailto:douglas.harewood-g...@bristol.ac.uk>
> 
> *
> CDT Communications*
> 
> University of Bristol, Merchant Venturers' Building, Woodland Road, Clifton, 
> Bristol. BS8 1UB
> 
> http://www.bristol.ac.uk/
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> 
> 
> 
> _______________________________________________
> Ryu-devel mailing list
> Ryu-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to