Skip to content

Commit

Permalink
openvswitch: Add meter infrastructure
Browse files Browse the repository at this point in the history
OVS kernel datapath so far does not support Openflow meter action.
This is the first stab at adding kernel datapath meter support.
This implementation supports only drop band type.

Signed-off-by: Andy Zhou <azhou@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
azhou-nicira authored and davem330 committed Nov 13, 2017
1 parent 9602c01 commit 96fbc13
Show file tree
Hide file tree
Showing 5 changed files with 674 additions and 2 deletions.
1 change: 1 addition & 0 deletions net/openvswitch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ openvswitch-y := \
flow.o \
flow_netlink.o \
flow_table.o \
meter.o \
vport.o \
vport-internal_dev.o \
vport-netdev.o
Expand Down
14 changes: 12 additions & 2 deletions net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "flow.h"
#include "flow_table.h"
#include "flow_netlink.h"
#include "meter.h"
#include "vport-internal_dev.h"
#include "vport-netdev.h"

Expand Down Expand Up @@ -174,6 +175,7 @@ static void destroy_dp_rcu(struct rcu_head *rcu)
ovs_flow_tbl_destroy(&dp->table);
free_percpu(dp->stats_percpu);
kfree(dp->ports);
ovs_meters_exit(dp);
kfree(dp);
}

Expand Down Expand Up @@ -1572,6 +1574,10 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++)
INIT_HLIST_HEAD(&dp->ports[i]);

err = ovs_meters_init(dp);
if (err)
goto err_destroy_ports_array;

/* Set up our datapath device. */
parms.name = nla_data(a[OVS_DP_ATTR_NAME]);
parms.type = OVS_VPORT_TYPE_INTERNAL;
Expand Down Expand Up @@ -1600,7 +1606,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
ovs_dp_reset_user_features(skb, info);
}

goto err_destroy_ports_array;
goto err_destroy_meters;
}

err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
Expand All @@ -1615,8 +1621,10 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
ovs_notify(&dp_datapath_genl_family, reply, info);
return 0;

err_destroy_ports_array:
err_destroy_meters:
ovs_unlock();
ovs_meters_exit(dp);
err_destroy_ports_array:
kfree(dp->ports);
err_destroy_percpu:
free_percpu(dp->stats_percpu);
Expand Down Expand Up @@ -2265,6 +2273,7 @@ static struct genl_family * const dp_genl_families[] = {
&dp_vport_genl_family,
&dp_flow_genl_family,
&dp_packet_genl_family,
&dp_meter_genl_family,
};

static void dp_unregister_genl(int n_families)
Expand Down Expand Up @@ -2445,3 +2454,4 @@ MODULE_ALIAS_GENL_FAMILY(OVS_DATAPATH_FAMILY);
MODULE_ALIAS_GENL_FAMILY(OVS_VPORT_FAMILY);
MODULE_ALIAS_GENL_FAMILY(OVS_FLOW_FAMILY);
MODULE_ALIAS_GENL_FAMILY(OVS_PACKET_FAMILY);
MODULE_ALIAS_GENL_FAMILY(OVS_METER_FAMILY);
3 changes: 3 additions & 0 deletions net/openvswitch/datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ struct datapath {
u32 user_features;

u32 max_headroom;

/* Switch meters. */
struct hlist_head *meters;
};

/**
Expand Down
Loading

0 comments on commit 96fbc13

Please sign in to comment.