Hi.

I have tried to use ofp_msg_from_jsondict() as follows.
However, codes are not simple at the same level as the original.
I think that it is necessary to implement setdefault() for each parameter 
because of keeping the convenience.
I am not confident in whether there is any merit to continue to rewrite the 
codes.

Are there any comments?



    --- a/ryu/app/ofctl_rest.py
    +++ b/ryu/app/ofctl_rest.py
    @@ -392,7 +392,7 @@ class StatsController(ControllerBase):
                 return Response(status=400)

             if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
    -            ofctl_v1_2.send_experimenter(dp, exp)
    +            ofctl_v1_2.send_experimenter(dp, req.body)
             elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
                 ofctl_v1_3.send_experimenter(dp, exp)
             else:

    --- a/ryu/lib/ofctl_v1_2.py
    +++ b/ryu/lib/ofctl_v1_2.py
    @@ -653,17 +655,11 @@ def mod_group_entry(dp, group, cmd):
         dp.send_msg(group_mod)


    -def send_experimenter(dp, exp):
    -    experimenter = exp.get('experimenter', 0)
    -    exp_type = exp.get('exp_type', 0)
    -    data_type = exp.get('data_type', 'ascii')
    -    if data_type != 'ascii' and data_type != 'base64':
    -        LOG.debug('Unknown data type: %s', data_type)
    -    data = exp.get('data', '')
    -    if data_type == 'base64':
    -        data = base64.b64decode(data)
    -
    -    expmsg = dp.ofproto_parser.OFPExperimenter(
    -        dp, experimenter, exp_type, data)
    -
    +def send_experimenter(dp, body):
    +    jsonstr = '{"OFPExperimenter": %s}' % body
    +    jsondict = eval(jsonstr)
    +    jsondict.setdefault('experimenter', 0)
    +    jsondict.setdefault('exp_type', 0)
    +    jsondict.setdefault('data', '')
    +    expmsg = ofproto_parser.ofp_msg_from_jsondict(dp, jsondict)
         dp.send_msg(expmsg)



On Wed, 08 Jan 2014 15:06:13 +0900
Yuichi Ito <[email protected]> wrote:

> thank you for your comment.
> I was just thinking that was like reinventing the wheel.
> I will try to replace them shortly.
> 
> 
> On Wed,  8 Jan 2014 14:49:39 +0900 (JST)
> YAMAMOTO Takashi <[email protected]> wrote:
> 
>> how about using ofp_msg_from_jsondict?
>> stringify stuff is intended to replace the most of ofctl.
>>
>> YAMAMOTO Takashi
>>
>>> this patch makes ofctl_rest enable use of OFPExperimenter message.
>>>
>>> usage)
>>>
>>>    URI:    /stats/experimenter/{dpid}
>>>    method: POST
>>>
>>> the message body is as follows:
>>>
>>>    experimenter  Experimenter ID. (default: 0)
>>>    exp_type      Experimenter defined type. (default:0)
>>>    data_type     Data encoding type. 'ascii' or 'base64'. (default: 'ascii')
>>>    data          Experimenter-defined arbitrary additional data. (default: 
>>> '')
>>>
>>> e.g.)
>>>
>>>    curl -X POST -d '{"experimenter": 8992,
>>>                      "exp_type": 10,
>>>                      "data": "\x00\x00\x00\x01"}' 
>>> http://localhost:8080/stats/experimenter/1
>>>
>>>    curl -X POST -d '{"experimenter": 8992,
>>>                      "exp_type": 10.
>>>                      "data_type": "base64",
>>>                      "data": "AAAAAQ=="}' 
>>> http://localhost:8080/stats/experimenter/1
>>>
>>> Signed-off-by: Yuichi Ito <[email protected]>
>>> ---
>>>   ryu/app/ofctl_rest.py |   30 ++++++++++++++++++++++++++++++
>>>   ryu/lib/ofctl_v1_2.py |   17 +++++++++++++++++
>>>   ryu/lib/ofctl_v1_3.py |   17 +++++++++++++++++
>>>   3 files changed, 64 insertions(+)
>>>
>>> diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
>>> index b9656b1..8ab53f9 100644
>>> --- a/ryu/app/ofctl_rest.py
>>> +++ b/ryu/app/ofctl_rest.py
>>> @@ -81,6 +81,10 @@ LOG = logging.getLogger('ryu.app.ofctl_rest')
>>>   #
>>>   # delete a meter entry
>>>   # POST /stats/meterentry/delete
>>> +#
>>> +#
>>> +# send a experimeter message
>>> +# POST /stats/experimenter/<dpid>
>>>
>>>
>>>   class StatsController(ControllerBase):
>>> @@ -269,6 +273,27 @@ class StatsController(ControllerBase):
>>>
>>>           return Response(status=200)
>>>
>>> +    def send_experimenter(self, req, dpid, **_kwargs):
>>> +        dp = self.dpset.get(int(dpid))
>>> +        if dp is None:
>>> +            return Response(status=404)
>>> +
>>> +        try:
>>> +            exp = eval(req.body)
>>> +        except SyntaxError:
>>> +            LOG.debug('invalid syntax %s', req.body)
>>> +            return Response(status=400)
>>> +
>>> +        if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>>> +            ofctl_v1_2.send_experimenter(dp, exp)
>>> +        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>>> +            ofctl_v1_3.send_experimenter(dp, exp)
>>> +        else:
>>> +            LOG.debug('Unsupported OF protocol')
>>> +            return Response(status=501)
>>> +
>>> +        return Response(status=200)
>>> +
>>>
>>>   class RestStatsApi(app_manager.RyuApp):
>>>       OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION,
>>> @@ -341,6 +366,11 @@ class RestStatsApi(app_manager.RyuApp):
>>>                          controller=StatsController, 
>>> action='mod_meter_entry',
>>>                          conditions=dict(method=['POST']))
>>>
>>> +        uri = path + '/experimenter/{dpid}'
>>> +        mapper.connect('stats', uri,
>>> +                       controller=StatsController, 
>>> action='send_experimenter',
>>> +                       conditions=dict(method=['POST']))
>>> +
>>>       def stats_reply_handler(self, ev):
>>>           msg = ev.msg
>>>           dp = msg.datapath
>>> diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
>>> index 6eb2981..660832a 100644
>>> --- a/ryu/lib/ofctl_v1_2.py
>>> +++ b/ryu/lib/ofctl_v1_2.py
>>> @@ -13,6 +13,7 @@
>>>   # See the License for the specific language governing permissions and
>>>   # limitations under the License.
>>>
>>> +import base64
>>>   import struct
>>>   import socket
>>>   import logging
>>> @@ -367,3 +368,19 @@ def mod_flow_entry(dp, flow, cmd):
>>>           flags, match, inst)
>>>
>>>       dp.send_msg(flow_mod)
>>> +
>>> +
>>> +def send_experimenter(dp, exp):
>>> +    experimenter = exp.get('experimenter', 0)
>>> +    exp_type = exp.get('exp_type', 0)
>>> +    data_type = exp.get('data_type', 'ascii')
>>> +    if data_type != 'ascii' and data_type != 'base64':
>>> +        LOG.debug('Unknown data type: %s', data_type)
>>> +    data = exp.get('data', '')
>>> +    if data_type == 'base64':
>>> +        data = base64.b64decode(data)
>>> +
>>> +    expmsg = dp.ofproto_parser.OFPExperimenter(
>>> +        dp, experimenter, exp_type, data)
>>> +
>>> +    dp.send_msg(expmsg)
>>> diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
>>> index 7d2c9fb..f983624 100644
>>> --- a/ryu/lib/ofctl_v1_3.py
>>> +++ b/ryu/lib/ofctl_v1_3.py
>>> @@ -13,6 +13,7 @@
>>>   # See the License for the specific language governing permissions and
>>>   # limitations under the License.
>>>
>>> +import base64
>>>   import struct
>>>   import socket
>>>   import logging
>>> @@ -640,3 +641,19 @@ def mod_meter_entry(dp, flow, cmd):
>>>           dp, cmd, flags, meter_id, bands)
>>>
>>>       dp.send_msg(meter_mod)
>>> +
>>> +
>>> +def send_experimenter(dp, exp):
>>> +    experimenter = exp.get('experimenter', 0)
>>> +    exp_type = exp.get('exp_type', 0)
>>> +    data_type = exp.get('data_type', 'ascii')
>>> +    if data_type != 'ascii' and data_type != 'base64':
>>> +        LOG.debug('Unknown data type: %s', data_type)
>>> +    data = exp.get('data', '')
>>> +    if data_type == 'base64':
>>> +        data = base64.b64decode(data)
>>> +
>>> +    expmsg = dp.ofproto_parser.OFPExperimenter(
>>> +        dp, experimenter, exp_type, data)
>>> +
>>> +    dp.send_msg(expmsg)
>>> -- 
>>> 1.7.10.4
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Rapidly troubleshoot problems before they affect your business. Most IT
>>> organizations don't have a clear picture of how application performance
>>> affects their revenue. With AppDynamics, you get 100% visibility into your
>>> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics 
>>> Pro!
>>> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> Ryu-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
> 
> 
> 


 

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to