From b26015c33fe420399fff1c9f35d1e3204c441954 Mon Sep 17 00:00:00 2001 From: ldejing Date: Thu, 18 Aug 2022 19:11:00 +0800 Subject: 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 Signed-off-by: Alin-Gabriel Serdean --- datapath-windows/ovsext/Actions.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'datapath-windows/ovsext/Actions.c') diff --git a/datapath-windows/ovsext/Actions.c b/datapath-windows/ovsext/Actions.c index 884fce4e3..2f44086b4 100644 --- a/datapath-windows/ovsext/Actions.c +++ b/datapath-windows/ovsext/Actions.c @@ -23,6 +23,7 @@ #include "Flow.h" #include "Gre.h" #include "Jhash.h" +#include "Meter.h" #include "Mpls.h" #include "NetProto.h" #include "Offload.h" @@ -2503,6 +2504,15 @@ OvsDoExecuteActions(POVS_SWITCH_CONTEXT switchContext, } break; } + case OVS_ACTION_ATTR_METER: { + if (OvsMeterExecute(&ovsFwdCtx, NlAttrGetU32(a))) { + OVS_LOG_INFO("Drop packet"); + dropReason = L"Ovs-meter exceed max rate"; + goto dropit; + } + + break; + } case OVS_ACTION_ATTR_SAMPLE: { if (ovsFwdCtx.destPortsSizeOut > 0 || ovsFwdCtx.tunnelTxNic != NULL -- cgit v1.2.1