Skip to content

Commit

Permalink
datapath: Add meter infrastructure
Browse files Browse the repository at this point in the history
Upstream commit:
    commit 96fbc13d7e770b542d2d1fcf700d0baadc6e8063
    Author: Andy Zhou <[email protected]>
    Date:   Fri Nov 10 12:09:42 2017 -0800

    openvswitch: Add meter infrastructure

    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 <[email protected]>
    Signed-off-by: David S. Miller <[email protected]>

Added a compat layer fixup for nla_parse.
Added another compat fixup for ktime_get_ns.

Cc: Andy Zhou <[email protected]>
Signed-off-by: Greg Rose <[email protected]>
Acked-by: Pravin B Shelar <[email protected]>
  • Loading branch information
azhou-nicira authored and pshelar committed Feb 13, 2018
1 parent 8011eea commit 1cb5703
Show file tree
Hide file tree
Showing 7 changed files with 699 additions and 4 deletions.
3 changes: 3 additions & 0 deletions acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
OVS_GREP_IFELSE([$KSRC/include/net/net_namespace.h],
[EXPORT_SYMBOL_GPL(peernet2id_alloc)],
[OVS_DEFINE([HAVE_PEERNET2ID_ALLOC])])
OVS_GREP_IFELSE([$KSRC/include/linux/timekeeping.h],
[ktime_get_ns],
[OVS_DEFINE([HAVE_KTIME_GET_NS])])
if cmp -s datapath/linux/kcompat.h.new \
datapath/linux/kcompat.h >/dev/null 2>&1; then
Expand Down
6 changes: 4 additions & 2 deletions datapath/Modules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ openvswitch_sources = \
vport.c \
vport-internal_dev.c \
vport-netdev.c \
nsh.c
nsh.c \
meter.c

vport_geneve_sources = vport-geneve.c
vport_vxlan_sources = vport-vxlan.c
Expand All @@ -45,7 +46,8 @@ openvswitch_headers = \
flow_table.h \
vport.h \
vport-internal_dev.h \
vport-netdev.h
vport-netdev.h \
meter.h

dist_sources = $(foreach module,$(dist_modules),$($(module)_sources))
dist_headers = $(foreach module,$(dist_modules),$($(module)_headers))
Expand Down
14 changes: 12 additions & 2 deletions datapath/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "flow.h"
#include "flow_table.h"
#include "flow_netlink.h"
#include "meter.h"
#include "gso.h"
#include "vport-internal_dev.h"
#include "vport-netdev.h"
Expand Down Expand Up @@ -178,6 +179,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 @@ -1602,6 +1604,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 @@ -1630,7 +1636,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 @@ -1645,8 +1651,10 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
ovs_notify(&dp_datapath_genl_family, &ovs_dp_datapath_multicast_group, 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 @@ -2296,6 +2304,7 @@ static struct genl_family *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 @@ -2492,3 +2501,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 datapath/datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ struct datapath {
u32 user_features;

u32 max_headroom;

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

/**
Expand Down
9 changes: 9 additions & 0 deletions datapath/linux/compat/include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ static inline int rpl_nla_parse_nested(struct nlattr *tb[], int maxtype,
return nla_parse_nested(tb, maxtype, nla, policy);
}
#define nla_parse_nested rpl_nla_parse_nested

static inline int rpl_nla_parse(struct nlattr **tb, int maxtype,
const struct nlattr *head, int len,
const struct nla_policy *policy,
struct netlink_ext_ack *extack)
{
return nla_parse(tb, maxtype, head, len, policy);
}
#define nla_parse rpl_nla_parse
#endif

#endif /* net/netlink.h */
Loading

0 comments on commit 1cb5703

Please sign in to comment.