ofctl_rest: improve readability of the result of MeterFeatures

although 'band_types' of MeterFeatures were bitmaps of supported band types, it was expressed numerically.
this patch makes 'band_types' human-readable.

e.g.)

  curl http://localhost:8080/stats/meterfeatures/8796750050962
  {
    "8796750050962": [
      {
        "max_meter": 16777216,
        "max_color": 0,
        "max_band": 255,
        "band_types": ["DROP", "DSCP_REMARK"]
      }
    ]
  }

Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yuichi Ito 2014-01-08 14:29:36 +09:00 committed by FUJITA Tomonori
parent 8b2097b352
commit aa074b23d9

View File

@ -550,6 +550,11 @@ def get_meter_stats(dp, waiters):
def get_meter_features(dp, waiters):
ofp = dp.ofproto
type_convert = {ofp.OFPMBT_DROP: 'DROP',
ofp.OFPMBT_DSCP_REMARK: 'DSCP_REMARK'}
stats = dp.ofproto_parser.OFPMeterFeaturesStatsRequest(dp, 0)
msgs = []
send_stats_request(dp, stats, waiters, msgs)
@ -557,8 +562,12 @@ def get_meter_features(dp, waiters):
features = []
for msg in msgs:
for feature in msg.body:
band_types = []
for k, v in type_convert.items():
if (1 << k) & feature.band_types:
band_types.append(v)
f = {'max_meter': feature.max_meter,
'band_types': feature.band_types,
'band_types': band_types,
'max_band': feature.max_band,
'max_color': feature.max_color}
features.append(f)