Hi,

Can I have one more question?

When I was testing your patches, I got the following error messages.

$ # delete all matching flow entries
$ # POST /stats/flowentry/delete
$ curl -X POST -d '{
>     "dpid": 1,
>     "priority":"11111",
>     "match":{
>         "in_port":1
>     }
>  }' http://localhost:8080/stats/flowentry/delete
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/eventlet/wsgi.py", line 396, in 
handle_one_response
    result = self.application(self.environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/ryu/app/wsgi.py", line 197, in 
__call__
    return super(wsgify_hack, self).__call__(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/usr/lib/python2.7/dist-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ryu/app/wsgi.py", line 259, in 
__call__
    return controller(req)
  File "/usr/local/lib/python2.7/dist-packages/ryu/app/wsgi.py", line 121, in 
__call__
    return getattr(self, action)(req, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ryu/app/ofctl_rest.py", line 
500, in mod_flow_entry
    if not dpid.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'

The dpid can be specified as int-type (or string).
It can be said for the other mod_*_entry() methods.
(http://ryu.readthedocs.org/en/latest/app/ofctl_rest.html#delete-all-matching-flow-entries)


BTW...
How about using hasattr() method to check if ofctl_v1_* supports 
meter/group/experimenter features?

e.g.)
    def get_meter_stats(self, req, dpid, **_kwargs):
        ...
        ...
        _ofctl = supported_ofctl.get(_ofp_version, None)
        if _ofctl is not None and hasattr(_ofctl, 'get_meter_stats'):
                meters = _ofctl.get_meter_stats(dp, self.waiters)
        else:
            LOG.debug('Unsupported OF protocol')
            return Response(status=501)

Surely, OF version expressly shows the supported features, I think...

Thanks

On 2015年03月31日 18:14, Yi Tseng wrote:
> Hi
> 
> I am sorry that I forgot to add this file to the patch, attachd file is the 
> other patch for ofp_feature_support module.
> 
> 
> Yi
> 
> 2015-03-31 16:37 GMT+08:00 Yusuke Iwase <[email protected] 
> <mailto:[email protected]>>:
> 
>     Hi,
> 
>     I am sorry to have confused you,
>     ofp_feature_support module is not found in your new patch.
> 
>     Thanks
> 
>     On 2015年03月31日 17:17, Yi Tseng wrote:
>     > Hi
>     >
>     > Attached file is my new patch, Thanks.
>     >
>     >
>     > Yi
>     >
>     > 2015-03-31 15:57 GMT+08:00 Yusuke Iwase <[email protected] 
> <mailto:[email protected]> <mailto:[email protected] 
> <mailto:[email protected]>>>:
>     >
>     >     Hi,
>     >
>     >     Thank you for your patch.
>     >     I've tested your patch, but a conflict has occurred when applying 
> your patch.
>     >     Please update your master branch.
>     >
>     >     I've fixed some syntax as following while ago.
>     >     
> (https://github.com/osrg/ryu/commit/e9d7050a914391f502380ff5d0a511e2ef8a3871)
>     >
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >
>     >     Thanks
>     >
>     >     On 2015年03月31日 16:30, Yi Tseng wrote:
>     >     > Avoid invalid dpid
>     >     > Simplify the condition that decide which ofctl version to use
>     >     > Remove unnecessary brackets
>     >     >
>     >     > Signed-off-by: Takeshi <[email protected] 
> <mailto:[email protected]> <mailto:[email protected] 
> <mailto:[email protected]>> <mailto:[email protected] 
> <mailto:[email protected]> <mailto:[email protected] 
> <mailto:[email protected]>>>>
>     >     > ---
>     >     >  ryu/app/ofctl_rest.py          | 373 
> +++++++++++++++++++++++++++++------------
>     >     >  ryu/lib/ofp_feature_support.py |  26 +++
>     >     >  2 files changed, 295 insertions(+), 104 deletions(-)
>     >     >  create mode 100644 ryu/lib/ofp_feature_support.py
>     >     >
>     >     > diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
>     >     > index c398d94..e0b1d81 100644
>     >     > --- a/ryu/app/ofctl_rest.py
>     >     > +++ b/ryu/app/ofctl_rest.py
>     >     > @@ -30,11 +30,21 @@ from ryu.ofproto import ofproto_v1_3
>     >     >  from ryu.lib import ofctl_v1_0
>     >     >  from ryu.lib import ofctl_v1_2
>     >     >  from ryu.lib import ofctl_v1_3
>     >     > +from ryu.lib.ofp_feature_support import support_meter
>     >     > +from ryu.lib.ofp_feature_support import support_group
>     >     > +from ryu.lib.ofp_feature_support import support_experimenter
>     >     >  from ryu.app.wsgi import ControllerBase, WSGIApplication
>     >     >
>     >     >
>     >     >  LOG = logging.getLogger('ryu.app.ofctl_rest')
>     >     >
>     >     > +# supported ofctl versions in this restful app
>     >     > +supported_ofctl = {
>     >     > +    ofproto_v1_0.OFP_VERSION: ofctl_v1_0,
>     >     > +    ofproto_v1_2.OFP_VERSION: ofctl_v1_2,
>     >     > +    ofproto_v1_3.OFP_VERSION: ofctl_v1_3,
>     >     > +}
>     >     > +
>     >     >  # REST API
>     >     >  #
>     >     >
>     >     > @@ -143,70 +153,92 @@ class StatsController(ControllerBase):
>     >     >          return (Response(content_type='application/json', 
> body=body))
>     >     >
>     >     >      def get_desc_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            desc = _ofctl.get_desc_stats(dp, self.waiters)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            desc = ofctl_v1_0.get_desc_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            desc = ofctl_v1_2.get_desc_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            desc = ofctl_v1_3.get_desc_stats(dp, self.waiters)
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(desc)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_flow_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     >          if req.body == '':
>     >     >              flow = {}
>     >     > +
>     >     >          else:
>     >     > +
>     >     >              try:
>     >     >                  flow = ast.literal_eval(req.body)
>     >     > +
>     >     >              except SyntaxError:
>     >     >                  LOG.debug('invalid syntax %s', req.body)
>     >     >                  return Response(status=400)
>     >     >
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            flows = ofctl_v1_0.get_flow_stats(dp, self.waiters, 
> flow)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            flows = ofctl_v1_2.get_flow_stats(dp, self.waiters, 
> flow)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            flows = ofctl_v1_3.get_flow_stats(dp, self.waiters, 
> flow)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            flows = _ofctl.get_flow_stats(dp, self.waiters, flow)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(flows)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_aggregate_flow_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     >          if req.body == '':
>     >     >              flow = {}
>     >     > +
>     >     >          else:
>     >     >              try:
>     >     >                  flow = ast.literal_eval(req.body)
>     >     > +
>     >     >              except SyntaxError:
>     >     >                  LOG.debug('invalid syntax %s', req.body)
>     >     >                  return Response(status=400)
>     >     >
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            flows = ofctl_v1_0.get_aggregate_flow_stats(dp, 
> self.waiters, flow)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            flows = ofctl_v1_2.get_aggregate_flow_stats(dp, 
> self.waiters, flow)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            flows = ofctl_v1_3.get_aggregate_flow_stats(dp, 
> self.waiters, flow)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            flows = _ofctl.get_aggregate_flow_stats(dp, 
> self.waiters, flow)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -215,34 +247,46 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_port_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            ports = ofctl_v1_0.get_port_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            ports = ofctl_v1_2.get_port_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ports = ofctl_v1_3.get_port_stats(dp, self.waiters)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            ports = _ofctl.get_port_stats(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(ports)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_queue_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            queues = ofctl_v1_0.get_queue_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            queues = ofctl_v1_2.get_queue_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            queues = ofctl_v1_3.get_queue_stats(dp, self.waiters)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            queues = _ofctl.get_queue_stats(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -251,71 +295,110 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_meter_features(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            meters = ofctl_v1_3.get_meter_features(dp, 
> self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION 
> or \
>     >     > -                dp.ofproto.OFP_VERSION == 
> ofproto_v1_2.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_meter(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            meters = _ofctl.get_meter_features(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(meters)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_meter_config(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            meters = ofctl_v1_3.get_meter_config(dp, 
> self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION 
> or \
>     >     > -                dp.ofproto.OFP_VERSION == 
> ofproto_v1_2.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_meter(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            meters = _ofctl.get_meter_config(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(meters)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_meter_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            meters = ofctl_v1_3.get_meter_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION 
> or \
>     >     > -                dp.ofproto.OFP_VERSION == 
> ofproto_v1_2.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_meter(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            meters = _ofctl.get_meter_stats(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     >          body = json.dumps(meters)
>     >     > -        return (Response(content_type='application/json', 
> body=body))
>     >     > +        return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_group_features(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            groups = ofctl_v1_2.get_group_features(dp, 
> self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            groups = ofctl_v1_3.get_group_features(dp, 
> self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_group(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            groups = _ofctl.get_group_features(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -324,17 +407,26 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_group_desc(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            groups = ofctl_v1_2.get_group_desc(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            groups = ofctl_v1_3.get_group_desc(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_group(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            groups = _ofctl.get_group_desc(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -343,17 +435,26 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_group_stats(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            groups = ofctl_v1_2.get_group_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            groups = ofctl_v1_3.get_group_stats(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_group(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            groups = _ofctl.get_group_stats(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -362,16 +463,22 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def get_port_desc(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            groups = ofctl_v1_0.get_port_desc(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            groups = ofctl_v1_2.get_port_desc(dp, self.waiters)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            groups = ofctl_v1_3.get_port_desc(dp, self.waiters)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            groups = _ofctl.get_port_desc(dp, self.waiters)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -380,14 +487,22 @@ class StatsController(ControllerBase):
>     >     >          return Response(content_type='application/json', 
> body=body)
>     >     >
>     >     >      def mod_flow_entry(self, req, cmd, **_kwargs):
>     >     > +
>     >     >          try:
>     >     >              flow = ast.literal_eval(req.body)
>     >     > +
>     >     >          except SyntaxError:
>     >     >              LOG.debug('invalid syntax %s', req.body)
>     >     >              return Response(status=400)
>     >     >
>     >     >          dpid = flow.get('dpid')
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > @@ -404,12 +519,10 @@ class StatsController(ControllerBase):
>     >     >          else:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            ofctl_v1_0.mod_flow_entry(dp, flow, cmd)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            ofctl_v1_2.mod_flow_entry(dp, flow, cmd)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ofctl_v1_3.mod_flow_entry(dp, flow, cmd)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.mod_flow_entry(dp, flow, cmd)
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -417,18 +530,24 @@ class StatsController(ControllerBase):
>     >     >          return Response(status=200)
>     >     >
>     >     >      def delete_flow_entry(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     >          flow = {'table_id': dp.ofproto.OFPTT_ALL}
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            ofctl_v1_0.delete_flow_entry(dp)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            ofctl_v1_2.mod_flow_entry(dp, flow, 
> dp.ofproto.OFPFC_DELETE)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ofctl_v1_3.mod_flow_entry(dp, flow, 
> dp.ofproto.OFPFC_DELETE)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.mod_flow_entry(dp, flow, 
> dp.ofproto.OFPFC_DELETE)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -436,14 +555,22 @@ class StatsController(ControllerBase):
>     >     >          return Response(status=200)
>     >     >
>     >     >      def mod_meter_entry(self, req, cmd, **_kwargs):
>     >     > +
>     >     >          try:
>     >     >              flow = ast.literal_eval(req.body)
>     >     > +
>     >     >          except SyntaxError:
>     >     >              LOG.debug('invalid syntax %s', req.body)
>     >     >              return Response(status=400)
>     >     >
>     >     >          dpid = flow.get('dpid')
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > @@ -456,12 +583,16 @@ class StatsController(ControllerBase):
>     >     >          else:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ofctl_v1_3.mod_meter_entry(dp, flow, cmd)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION 
> or \
>     >     > -                dp.ofproto.OFP_VERSION == 
> ofproto_v1_2.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_meter(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.mod_meter_entry(dp, flow, cmd)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -469,21 +600,25 @@ class StatsController(ControllerBase):
>     >     >          return Response(status=200)
>     >     >
>     >     >      def mod_group_entry(self, req, cmd, **_kwargs):
>     >     > +
>     >     >          try:
>     >     >              group = ast.literal_eval(req.body)
>     >     > +
>     >     >          except SyntaxError:
>     >     >              LOG.debug('invalid syntax %s', req.body)
>     >     >              return Response(status=400)
>     >     >
>     >     >          dpid = group.get('dpid')
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            LOG.debug('Request not supported in this OF protocol 
> version')
>     >     > -            return Response(status=501)
>     >     > -
>     >     >          if cmd == 'add':
>     >     >              cmd = dp.ofproto.OFPGC_ADD
>     >     >          elif cmd == 'modify':
>     >     > @@ -493,10 +628,16 @@ class StatsController(ControllerBase):
>     >     >          else:
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            ofctl_v1_2.mod_group_entry(dp, group, cmd)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ofctl_v1_3.mod_group_entry(dp, group, cmd)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_group(_ofp_version):
>     >     > +            LOG.debug('Request not supported in this OF protocol 
> version')
>     >     > +            return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.mod_group_entry(dp, group, cmd)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > @@ -504,64 +645,88 @@ class StatsController(ControllerBase):
>     >     >          return Response(status=200)
>     >     >
>     >     >      def mod_port_behavior(self, req, cmd, **_kwargs):
>     >     > +
>     >     >          try:
>     >     >              port_config = ast.literal_eval(req.body)
>     >     > +
>     >     >          except SyntaxError:
>     >     >              LOG.debug('invalid syntax %s', req.body)
>     >     >              return Response(status=400)
>     >     >
>     >     >          dpid = port_config.get('dpid')
>     >     >
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     > +        port_no = port_config.get('port_no', 0)
>     >     > +        if not port_no.isdigit():
>     >     > +            LOG.debug('invalid port_no')
>     >     > +            return Response(status=400)
>     >     > +
>     >     >          port_no = int(port_config.get('port_no', 0))
>     >     >          port_info = self.dpset.port_state[int(dpid)].get(port_no)
>     >     >
>     >     >          if 'hw_addr' not in port_config:
>     >     >              if port_info is not None:
>     >     >                  port_config['hw_addr'] = port_info.hw_addr
>     >     > +
>     >     >              else:
>     >     >                  return Response(status=404)
>     >     >
>     >     >          if 'advertise' not in port_config:
>     >     >              if port_info is not None:
>     >     >                  port_config['advertise'] = port_info.advertised
>     >     > +
>     >     >              else:
>     >     >                  return Response(status=404)
>     >     >
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     >          if cmd != 'modify':
>     >     >              return Response(status=404)
>     >     >
>     >     > -        if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > -            ofctl_v1_0.mod_port_behavior(dp, port_config)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
>     >     > -            ofctl_v1_2.mod_port_behavior(dp, port_config)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
>     >     > -            ofctl_v1_3.mod_port_behavior(dp, port_config)
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.mod_port_behavior(dp, port_config)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     >
>     >     > +        return Response(status=200)
>     >     > +
>     >     >      def send_experimenter(self, req, dpid, **_kwargs):
>     >     > +
>     >     > +        if not dpid.isdigit():
>     >     > +            LOG.debug('invalid dpid %s', dpid)
>     >     > +            return Response(status=400)
>     >     >          dp = self.dpset.get(int(dpid))
>     >     > +
>     >     >          if dp is None:
>     >     >              return Response(status=404)
>     >     >
>     >     >          try:
>     >     >              exp = ast.literal_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)
>     >     > -        elif dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
>     >     > +        _ofp_version = dp.ofproto.OFP_VERSION
>     >     > +
>     >     > +        if not support_experimenter(_ofp_version):
>     >     >              LOG.debug('Request not supported in this OF protocol 
> version')
>     >     >              return Response(status=501)
>     >     > +
>     >     > +        elif _ofp_version in supported_ofctl:
>     >     > +            _ofctl = supported_ofctl[_ofp_version]
>     >     > +            _ofctl.send_experimenter(dp, exp)
>     >     > +
>     >     >          else:
>     >     >              LOG.debug('Unsupported OF protocol')
>     >     >              return Response(status=501)
>     >     > diff --git a/ryu/lib/ofp_feature_support.py 
> b/ryu/lib/ofp_feature_support.py
>     >     > new file mode 100644
>     >     > index 0000000..5200069
>     >     > --- /dev/null
>     >     > +++ b/ryu/lib/ofp_feature_support.py
>     >     > @@ -0,0 +1,26 @@
>     >     > +# Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
>     >     > +#
>     >     > +# Licensed under the Apache License, Version 2.0 (the "License");
>     >     > +# you may not use this file except in compliance with the 
> License.
>     >     > +# You may obtain a copy of the License at
>     >     > +#
>     >     > +#    http://www.apache.org/licenses/LICENSE-2.0
>     >     > +#
>     >     > +# Unless required by applicable law or agreed to in writing, 
> software
>     >     > +# distributed under the License is distributed on an "AS IS" 
> BASIS,
>     >     > +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>     >     > +# implied.
>     >     > +# See the License for the specific language governing 
> permissions and
>     >     > +# limitations under the License.
>     >     > +
>     >     > +
>     >     > +def support_meter(version):
>     >     > +    return version > 0x03
>     >     > +
>     >     > +
>     >     > +def support_group(version):
>     >     > +    return version > 0x01
>     >     > +
>     >     > +
>     >     > +def support_experimenter(version):
>     >     > +    return version > 0x01
>     >     > --
>     >     > 1.9.5 (Apple Git-50.3)
>     >     >
>     >     >
>     >     >
>     >     >
>     >     > 
> ------------------------------------------------------------------------------
>     >     > 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]> 
> <mailto:[email protected] 
> <mailto:[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