summaryrefslogtreecommitdiff
path: root/datapath-windows/ovsext/Meter.h
diff options
context:
space:
mode:
authorldejing <ldejing@vmware.com>2022-08-18 19:11:00 +0800
committerAlin-Gabriel Serdean <aserdean@ovn.org>2022-09-20 02:48:44 +0300
commitb26015c33fe420399fff1c9f35d1e3204c441954 (patch)
tree7f5ea882a645a452a41da75e4834caf7bfe1fbd0 /datapath-windows/ovsext/Meter.h
parent7af5c33c1629b309cbcbe3b6c9c3bd6d3b4c0abf (diff)
downloadopenvswitch-b26015c33fe420399fff1c9f35d1e3204c441954.tar.gz
datapath-windows: support meter action initial version
This patch implemented meter action, currently, meter only support drop method and only support one band. The overall implementation is, when a packet comes in, it will first lookup meter according to the meter id, then get the band->rates and delta time since last access the same meter from the meter struct. Add the multiply result(band->rates * delta_time) to bucket, finally bucket minus the packet size, if the result larger than zero, allow the packet go through, otherwise deny the packet go through. Test case: 1. Setting the size meter size 3M, then the bandwidth was limit around 3M; ovs-ofctl -O OpenFlow13 add-meter br-test meter=2,kbps,\ band=type=drop,rate=3000 ovs-ofctl add-flow br-test "table=0,priority=1,ip \ actions=meter:2,normal" -O OpenFlow13 2. Setting the meter size 8M, then the bandwidth was limit around 8M; ovs-ofctl -O OpenFlow13 add-meter br-test meter=2,\ kbps,band=type=drop,rate=8000 ovs-ofctl add-flow br-test "table=0,priority=1,ip\ actions=meter:2,normal" -O OpenFlow13 Signed-off-by: ldejing <ldejing@vmware.com> Signed-off-by: Alin-Gabriel Serdean <aserdean@ovn.org>
Diffstat (limited to 'datapath-windows/ovsext/Meter.h')
-rw-r--r--datapath-windows/ovsext/Meter.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/datapath-windows/ovsext/Meter.h b/datapath-windows/ovsext/Meter.h
new file mode 100644
index 000000000..bc94489a5
--- /dev/null
+++ b/datapath-windows/ovsext/Meter.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2022 VMware, Inc.
+ *
+ * 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.
+ */
+
+#ifndef OVS_METER_H
+#define OVS_METER_H
+
+#include "precomp.h"
+#include "Switch.h"
+#include "User.h"
+#include "Datapath.h"
+#include "Event.h"
+#include "NetProto.h"
+#include "Netlink/Netlink.h"
+#include "Flow.h"
+
+#define OVS_MAX_BANDS 1
+#define OVS_MAX_METERS 32
+#define METER_HASH_BUCKET_MAX 1024
+
+typedef struct _DpMeterBand {
+ UINT32 type;
+ UINT32 rate;
+ UINT32 burst_size;
+ UINT64 bucket;
+ struct ovs_flow_stats stats;
+} DpMeterBand;
+
+typedef struct _DpMeter {
+ LIST_ENTRY link;
+ UINT32 id;
+ UINT16 kbps:1;
+ UINT16 keepStatus:1;
+ UINT16 nBands;
+ UINT32 maxDelta;
+ UINT64 used;
+ struct ovs_flow_stats stats;
+ DpMeterBand bands[OVS_MAX_BANDS];
+} DpMeter;
+
+NTSTATUS OvsInitMeter(POVS_SWITCH_CONTEXT context);
+NDIS_STATUS OvsNewMeterCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
+ UINT32 *replyLen);
+NDIS_STATUS OvsMeterFeatureProbe(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
+UINT32 *replyLen);
+
+NDIS_STATUS OvsMeterDestroy(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
+ UINT32 *replyLen);
+DpMeter* OvsMeterLookup(UINT32 meterId);
+BOOLEAN
+OvsMeterExecute(OvsForwardingContext *fwdCtx, UINT32 meterId);
+BOOLEAN
+buildOvsMeterReplyMsg(NL_BUFFER *nlBuf, DpMeter *dpMeter);
+
+
+#endif //OVS_METER_H