This will be used by meter statistics messages

Signed-off-by: Simon Horman <[email protected]>
---
 ryu/ofproto/ofproto_v1_4.py        |  6 +++++
 ryu/ofproto/ofproto_v1_4_parser.py | 54 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/ryu/ofproto/ofproto_v1_4.py b/ryu/ofproto/ofproto_v1_4.py
index 70f7b45..acdf627 100644
--- a/ryu/ofproto/ofproto_v1_4.py
+++ b/ryu/ofproto/ofproto_v1_4.py
@@ -653,6 +653,12 @@ OFPMF_PKTPS = 1 << 1  # Rate value in packet/sec.
 OFPMF_BURST = 1 << 2  # Do burst size.
 OFPMF_STATS = 1 << 3  # Collect statistics.
 
+# struct ofp_meter_band_header
+OFP_METER_BAND_HEADER_PACK_STR = '!HHII'
+OFP_METER_BAND_HEADER_SIZE = 12
+assert (calcsize(OFP_METER_BAND_HEADER_PACK_STR) ==
+        OFP_METER_BAND_HEADER_SIZE)
+
 # struct ofp_meter_mod
 OFP_METER_MOD_PACK_STR = '!HHI'
 OFP_METER_MOD_SIZE = 16
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py 
b/ryu/ofproto/ofproto_v1_4_parser.py
index 0578c6e..4b35a30 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -2127,6 +2127,60 @@ class OFPGroupFeaturesStatsReply(OFPMultipartReply):
         super(OFPGroupFeaturesStatsReply, self).__init__(datapath, **kwargs)
 
 
+class OFPMeterBand(StringifyMixin):
+    def __init__(self, type_, len_):
+        super(OFPMeterBand, self).__init__()
+        self.type = type_
+        self.len = len_
+
+
+class OFPMeterBandHeader(OFPMeterBand):
+    _METER_BAND = {}
+
+    @staticmethod
+    def register_meter_band_type(type_, len_):
+        def _register_meter_band_type(cls):
+            OFPMeterBandHeader._METER_BAND[type_] = cls
+            cls.cls_meter_band_type = type_
+            cls.cls_meter_band_len = len_
+            return cls
+        return _register_meter_band_type
+
+    def __init__(self):
+        cls = self.__class__
+        super(OFPMeterBandHeader, self).__init__(cls.cls_meter_band_type,
+                                                 cls.cls_meter_band_len)
+
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, _rate, _burst_size = struct.unpack_from(
+            ofproto.OFP_METER_BAND_HEADER_PACK_STR, buf, offset)
+        cls_ = cls._METER_BAND[type_]
+        assert cls_.cls_meter_band_len == len_
+        return cls_.parser(buf, offset)
+
+
[email protected]_meter_band_type(
+    ofproto.OFPMBT_DROP, ofproto.OFP_METER_BAND_DROP_SIZE)
+class OFPMeterBandDrop(OFPMeterBandHeader):
+    def __init__(self, rate, burst_size, type_=None, len_=None):
+        super(OFPMeterBandDrop, self).__init__()
+        self.rate = rate
+        self.burst_size = burst_size
+
+    def serialize(self, buf, offset):
+        msg_pack_into(ofproto.OFP_METER_BAND_DROP_PACK_STR, buf, offset,
+                      self.type, self.len, self.rate, self.burst_size)
+
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, rate, burst_size = struct.unpack_from(
+            ofproto.OFP_METER_BAND_DROP_PACK_STR, buf, offset)
+        assert cls.cls_meter_band_type == type_
+        assert cls.cls_meter_band_len == len_
+        return cls(rate, burst_size)
+
+
 class OFPExperimenterMultipart(ofproto_parser.namedtuple(
                                'OFPExperimenterMultipart',
                                ('experimenter', 'exp_type', 'data'))):
-- 
1.8.5.2


------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to