History

Merge branch 'net-openvswitch-add-sample-multicasting'

Adrian Moreno says: ==================== net: openvswitch: Add sample multicasting. ** Background ** Currently, OVS supports several packet sampling mechanisms (sFlow, per-bridge IPFIX, per-flow IPFIX). These end up being translated into a userspace action that needs to be handled by ovs-vswitchd's handler threads only to be forwarded to some third party application that will somehow process the sample and provide observability on the datapath. A particularly interesting use-case is controller-driven per-flow IPFIX sampling where the OpenFlow controller can add metadata to samples (via two 32bit integers) and this metadata is then available to the sample-collecting system for correlation. ** Problem ** The fact that sampled traffic share netlink sockets and handler thread time with upcalls, apart from being a performance bottleneck in the sample extraction itself, can severely compromise the datapath, yielding this solution unfit for highly loaded production systems. Users are left with little options other than guessing what sampling rate will be OK for their traffic pattern and system load and dealing with the lost accuracy. Looking at available infrastructure, an obvious candidated would be to use psample. However, it's current state does not help with the use-case at stake because sampled packets do not contain user-defined metadata. ** Proposal ** This series is an attempt to fix this situation by extending the existing psample infrastructure to carry a variable length user-defined cookie. The main existing user of psample is tc's act_sample. It is also extended to forward the action's cookie to psample. Finally, a new OVS action (OVS_SAMPLE_ATTR_PSAMPLE) is created. It accepts a group and an optional cookie and uses psample to multicast the packet and the metadata. ====================

Jakub Kicinski committed 2 years ago

Commit 73d4d642 parents 064fbc4 30d772a13 files · +566 −16Browse files

Unified · Split

13 files
  1. Documentation/netlink/specs/ovs_flow.yaml +17 −0
  2. include/net/psample.h +4 −1
  3. include/uapi/linux/openvswitch.h +30 −1
  4. include/uapi/linux/psample.h +10 −1
  5. net/openvswitch/Kconfig +1 −0
  6. net/openvswitch/actions.c +64 −2
  7. net/openvswitch/datapath.h +3 −0
  8. net/openvswitch/flow_netlink.c +31 −1
  9. net/openvswitch/vport.c +1 −0
  10. net/psample/psample.c +15 −1
  11. net/sched/act_sample.c +12 −0
  12. tools/testing/selftests/net/openvswitch/openvswitch.sh +112 −3
  13. tools/testing/selftests/net/openvswitch/ovs-dpctl.py +266 −6
Documentation/netlink/specs/ovs_flow.yaml+17−0
@@ -727,6 +727,12 @@ attribute-sets: · 726 unmodified lines
727 name: dec-ttl727 name: dec-ttl
728 type: nest728 type: nest
729 nested-attributes: dec-ttl-attrs729 nested-attributes: dec-ttl-attrs
730 -
731 name: psample
732 type: nest
733 nested-attributes: psample-attrs
734 doc: |
735 Sends a packet sample to psample for external observation.
730 -736 -
731 name: tunnel-key-attrs737 name: tunnel-key-attrs
732 enum-name: ovs-tunnel-key-attr738 enum-name: ovs-tunnel-key-attr
@@ -938,6 +944,17 @@ attribute-sets: · 205 unmodified lines
938 -944 -
939 name: gbp945 name: gbp
940 type: u32946 type: u32
947 -
948 name: psample-attrs
949 enum-name: ovs-psample-attr
950 name-prefix: ovs-psample-attr-
951 attributes:
952 -
953 name: group
954 type: u32
955 -
956 name: cookie
957 type: binary
941 958
942operations:959operations:
943 name-prefix: ovs-flow-cmd-960 name-prefix: ovs-flow-cmd-
include/net/psample.h+4−1
@@ -24,7 +24,10 @@ struct psample_metadata { · 23 unmodified lines
24 u8 out_tc_valid:1,24 u8 out_tc_valid:1,
25 out_tc_occ_valid:1,25 out_tc_occ_valid:1,
26 latency_valid:1,26 latency_valid:1,
27 unused:5;27 rate_as_probability:1,
28 unused:4;
29 const u8 *user_cookie;
30 u32 user_cookie_len;
28};31};
29 32
30struct psample_group *psample_group_get(struct net *net, u32 group_num);33struct psample_group *psample_group_get(struct net *net, u32 group_num);
include/uapi/linux/openvswitch.h+30−1
@@ -649,7 +649,8 @@ enum ovs_flow_attr { · 648 unmodified lines
649 * Actions are passed as nested attributes.649 * Actions are passed as nested attributes.
650 *650 *
651 * Executes the specified actions with the given probability on a per-packet651 * Executes the specified actions with the given probability on a per-packet
652 * basis.652 * basis. Nested actions will be able to access the probability value of the
653 * parent @OVS_ACTION_ATTR_SAMPLE.
653 */654 */
654enum ovs_sample_attr {655enum ovs_sample_attr {
655 OVS_SAMPLE_ATTR_UNSPEC,656 OVS_SAMPLE_ATTR_UNSPEC,
@@ -914,6 +915,31 @@ struct check_pkt_len_arg { · 258 unmodified lines
914};915};
915#endif916#endif
916 917
918#define OVS_PSAMPLE_COOKIE_MAX_SIZE 16
919/**
920 * enum ovs_psample_attr - Attributes for %OVS_ACTION_ATTR_PSAMPLE
921 * action.
922 *
923 * @OVS_PSAMPLE_ATTR_GROUP: 32-bit number to identify the source of the
924 * sample.
925 * @OVS_PSAMPLE_ATTR_COOKIE: An optional variable-length binary cookie that
926 * contains user-defined metadata. The maximum length is
927 * OVS_PSAMPLE_COOKIE_MAX_SIZE bytes.
928 *
929 * Sends the packet to the psample multicast group with the specified group and
930 * cookie. It is possible to combine this action with the
931 * %OVS_ACTION_ATTR_TRUNC action to limit the size of the sample.
932 */
933enum ovs_psample_attr {
934 OVS_PSAMPLE_ATTR_GROUP = 1, /* u32 number. */
935 OVS_PSAMPLE_ATTR_COOKIE, /* Optional, user specified cookie. */
936
937 /* private: */
938 __OVS_PSAMPLE_ATTR_MAX
939};
940
941#define OVS_PSAMPLE_ATTR_MAX (__OVS_PSAMPLE_ATTR_MAX - 1)
942
917/**943/**
918 * enum ovs_action_attr - Action types.944 * enum ovs_action_attr - Action types.
919 *945 *
@@ -966,6 +992,8 @@ struct check_pkt_len_arg { · 46 unmodified lines
966 * of l3 tunnel flag in the tun_flags field of OVS_ACTION_ATTR_ADD_MPLS992 * of l3 tunnel flag in the tun_flags field of OVS_ACTION_ATTR_ADD_MPLS
967 * argument.993 * argument.
968 * @OVS_ACTION_ATTR_DROP: Explicit drop action.994 * @OVS_ACTION_ATTR_DROP: Explicit drop action.
995 * @OVS_ACTION_ATTR_PSAMPLE: Send a sample of the packet to external observers
996 * via psample.
969 *997 *
970 * Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all998 * Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all
971 * fields within a header are modifiable, e.g. the IPv4 protocol and fragment999 * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -1004,6 +1032,7 @@ enum ovs_action_attr { · 32 unmodified lines
1004 OVS_ACTION_ATTR_ADD_MPLS, /* struct ovs_action_add_mpls. */1032 OVS_ACTION_ATTR_ADD_MPLS, /* struct ovs_action_add_mpls. */
1005 OVS_ACTION_ATTR_DEC_TTL, /* Nested OVS_DEC_TTL_ATTR_*. */1033 OVS_ACTION_ATTR_DEC_TTL, /* Nested OVS_DEC_TTL_ATTR_*. */
1006 OVS_ACTION_ATTR_DROP, /* u32 error code. */1034 OVS_ACTION_ATTR_DROP, /* u32 error code. */
1035 OVS_ACTION_ATTR_PSAMPLE, /* Nested OVS_PSAMPLE_ATTR_*. */
1007 1036
1008 __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted1037 __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted
1009 * from userspace. */1038 * from userspace. */
include/uapi/linux/psample.h+10−1
@@ -8,7 +8,11 @@ enum { · 7 unmodified lines
8 PSAMPLE_ATTR_ORIGSIZE,8 PSAMPLE_ATTR_ORIGSIZE,
9 PSAMPLE_ATTR_SAMPLE_GROUP,9 PSAMPLE_ATTR_SAMPLE_GROUP,
10 PSAMPLE_ATTR_GROUP_SEQ,10 PSAMPLE_ATTR_GROUP_SEQ,
11 PSAMPLE_ATTR_SAMPLE_RATE,11 PSAMPLE_ATTR_SAMPLE_RATE, /* u32, ratio between observed and
12 * sampled packets or scaled probability
13 * if PSAMPLE_ATTR_SAMPLE_PROBABILITY
14 * is set.
15 */
12 PSAMPLE_ATTR_DATA,16 PSAMPLE_ATTR_DATA,
13 PSAMPLE_ATTR_GROUP_REFCOUNT,17 PSAMPLE_ATTR_GROUP_REFCOUNT,
14 PSAMPLE_ATTR_TUNNEL,18 PSAMPLE_ATTR_TUNNEL,
@@ -19,6 +23,11 @@ enum { · 4 unmodified lines
19 PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */23 PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */
20 PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */24 PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */
21 PSAMPLE_ATTR_PROTO, /* u16 */25 PSAMPLE_ATTR_PROTO, /* u16 */
26 PSAMPLE_ATTR_USER_COOKIE, /* binary, user provided data */
27 PSAMPLE_ATTR_SAMPLE_PROBABILITY,/* no argument, interpret rate in
28 * PSAMPLE_ATTR_SAMPLE_RATE as a
29 * probability scaled 0 - U32_MAX.
30 */
22 31
23 __PSAMPLE_ATTR_MAX32 __PSAMPLE_ATTR_MAX
24};33};
net/openvswitch/Kconfig+1−0
@@ -10,6 +10,7 @@ config OPENVSWITCH · 9 unmodified lines
10 (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \10 (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \
11 (!NF_NAT || NF_NAT) && \11 (!NF_NAT || NF_NAT) && \
12 (!NETFILTER_CONNCOUNT || NETFILTER_CONNCOUNT)))12 (!NETFILTER_CONNCOUNT || NETFILTER_CONNCOUNT)))
13 depends on PSAMPLE || !PSAMPLE
13 select LIBCRC32C14 select LIBCRC32C
14 select MPLS15 select MPLS
15 select NET_MPLS_GSO16 select NET_MPLS_GSO
net/openvswitch/actions.c+64−2
@@ -24,6 +24,11 @@ · 23 unmodified lines
24#include <net/checksum.h>24#include <net/checksum.h>
25#include <net/dsfield.h>25#include <net/dsfield.h>
26#include <net/mpls.h>26#include <net/mpls.h>
27
28#if IS_ENABLED(CONFIG_PSAMPLE)
29#include <net/psample.h>
30#endif
31
27#include <net/sctp/checksum.h>32#include <net/sctp/checksum.h>
28 33
29#include "datapath.h"34#include "datapath.h"
@@ -1043,12 +1048,15 @@ static int sample(struct datapath *dp, struct sk_buff *skb, · 1013 unmodified lines
1043 struct nlattr *sample_arg;1048 struct nlattr *sample_arg;
1044 int rem = nla_len(attr);1049 int rem = nla_len(attr);
1045 const struct sample_arg *arg;1050 const struct sample_arg *arg;
1051 u32 init_probability;
1046 bool clone_flow_key;1052 bool clone_flow_key;
1053 int err;
1047 1054
1048 /* The first action is always 'OVS_SAMPLE_ATTR_ARG'. */1055 /* The first action is always 'OVS_SAMPLE_ATTR_ARG'. */
1049 sample_arg = nla_data(attr);1056 sample_arg = nla_data(attr);
1050 arg = nla_data(sample_arg);1057 arg = nla_data(sample_arg);
1051 actions = nla_next(sample_arg, &rem);1058 actions = nla_next(sample_arg, &rem);
1059 init_probability = OVS_CB(skb)->probability;
1052 1060
1053 if ((arg->probability != U32_MAX) &&1061 if ((arg->probability != U32_MAX) &&
1054 (!arg->probability || get_random_u32() > arg->probability)) {1062 (!arg->probability || get_random_u32() > arg->probability)) {
@@ -1057,9 +1065,16 @@ static int sample(struct datapath *dp, struct sk_buff *skb, · 2 unmodified lines
1057 return 0;1065 return 0;
1058 }1066 }
1059 1067
1068 OVS_CB(skb)->probability = arg->probability;
1069
1060 clone_flow_key = !arg->exec;1070 clone_flow_key = !arg->exec;
1061 return clone_execute(dp, skb, key, 0, actions, rem, last,1071 err = clone_execute(dp, skb, key, 0, actions, rem, last,
1062 clone_flow_key);1072 clone_flow_key);
1073
1074 if (!last)
1075 OVS_CB(skb)->probability = init_probability;
1076
1077 return err;
1063}1078}
1064 1079
1065/* When 'last' is true, clone() should always consume the 'skb'.1080/* When 'last' is true, clone() should always consume the 'skb'.
@@ -1299,6 +1314,44 @@ static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key) · 233 unmodified lines
1299 return 0;1314 return 0;
1300}1315}
1301 1316
1317#if IS_ENABLED(CONFIG_PSAMPLE)
1318static void execute_psample(struct datapath *dp, struct sk_buff *skb,
1319 const struct nlattr *attr)
1320{
1321 struct psample_group psample_group = {};
1322 struct psample_metadata md = {};
1323 const struct nlattr *a;
1324 u32 rate;
1325 int rem;
1326
1327 nla_for_each_attr(a, nla_data(attr), nla_len(attr), rem) {
1328 switch (nla_type(a)) {
1329 case OVS_PSAMPLE_ATTR_GROUP:
1330 psample_group.group_num = nla_get_u32(a);
1331 break;
1332
1333 case OVS_PSAMPLE_ATTR_COOKIE:
1334 md.user_cookie = nla_data(a);
1335 md.user_cookie_len = nla_len(a);
1336 break;
1337 }
1338 }
1339
1340 psample_group.net = ovs_dp_get_net(dp);
1341 md.in_ifindex = OVS_CB(skb)->input_vport->dev->ifindex;
1342 md.trunc_size = skb->len - OVS_CB(skb)->cutlen;
1343 md.rate_as_probability = 1;
1344
1345 rate = OVS_CB(skb)->probability ? OVS_CB(skb)->probability : U32_MAX;
1346
1347 psample_sample_packet(&psample_group, skb, rate, &md);
1348}
1349#else
1350static void execute_psample(struct datapath *dp, struct sk_buff *skb,
1351 const struct nlattr *attr)
1352{}
1353#endif
1354
1302/* Execute a list of actions against 'skb'. */1355/* Execute a list of actions against 'skb'. */
1303static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,1356static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1304 struct sw_flow_key *key,1357 struct sw_flow_key *key,
@@ -1502,6 +1555,15 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, · 197 unmodified lines
1502 ovs_kfree_skb_reason(skb, reason);1555 ovs_kfree_skb_reason(skb, reason);
1503 return 0;1556 return 0;
1504 }1557 }
1558
1559 case OVS_ACTION_ATTR_PSAMPLE:
1560 execute_psample(dp, skb, a);
1561 OVS_CB(skb)->cutlen = 0;
1562 if (nla_is_last(a, rem)) {
1563 consume_skb(skb);
1564 return 0;
1565 }
1566 break;
1505 }1567 }
1506 1568
1507 if (unlikely(err)) {1569 if (unlikely(err)) {
net/openvswitch/datapath.h+3−0
@@ -115,12 +115,15 @@ struct datapath { · 114 unmodified lines
115 * fragmented.115 * fragmented.
116 * @acts_origlen: The netlink size of the flow actions applied to this skb.116 * @acts_origlen: The netlink size of the flow actions applied to this skb.
117 * @cutlen: The number of bytes from the packet end to be removed.117 * @cutlen: The number of bytes from the packet end to be removed.
118 * @probability: The sampling probability that was applied to this skb; 0 means
119 * no sampling has occurred; U32_MAX means 100% probability.
118 */120 */
119struct ovs_skb_cb {121struct ovs_skb_cb {
120 struct vport *input_vport;122 struct vport *input_vport;
121 u16 mru;123 u16 mru;
122 u16 acts_origlen;124 u16 acts_origlen;
123 u32 cutlen;125 u32 cutlen;
126 u32 probability;
124};127};
125#define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)128#define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
126 129
net/openvswitch/flow_netlink.c+31−1
@@ -64,6 +64,7 @@ static bool actions_may_change_flow(const struct nlattr *actions) · 63 unmodified lines
64 case OVS_ACTION_ATTR_TRUNC:64 case OVS_ACTION_ATTR_TRUNC:
65 case OVS_ACTION_ATTR_USERSPACE:65 case OVS_ACTION_ATTR_USERSPACE:
66 case OVS_ACTION_ATTR_DROP:66 case OVS_ACTION_ATTR_DROP:
67 case OVS_ACTION_ATTR_PSAMPLE:
67 break;68 break;
68 69
69 case OVS_ACTION_ATTR_CT:70 case OVS_ACTION_ATTR_CT:
@@ -2409,7 +2410,7 @@ static void ovs_nla_free_nested_actions(const struct nlattr *actions, int len) · 2339 unmodified lines
2409 /* Whenever new actions are added, the need to update this2410 /* Whenever new actions are added, the need to update this
2410 * function should be considered.2411 * function should be considered.
2411 */2412 */
2412 BUILD_BUG_ON(OVS_ACTION_ATTR_MAX != 24);2413 BUILD_BUG_ON(OVS_ACTION_ATTR_MAX != 25);
2413 2414
2414 if (!actions)2415 if (!actions)
2415 return;2416 return;
@@ -3157,6 +3158,28 @@ static int validate_and_copy_check_pkt_len(struct net *net, · 741 unmodified lines
3157 return 0;3158 return 0;
3158}3159}
3159 3160
3161static int validate_psample(const struct nlattr *attr)
3162{
3163 static const struct nla_policy policy[OVS_PSAMPLE_ATTR_MAX + 1] = {
3164 [OVS_PSAMPLE_ATTR_GROUP] = { .type = NLA_U32 },
3165 [OVS_PSAMPLE_ATTR_COOKIE] = {
3166 .type = NLA_BINARY,
3167 .len = OVS_PSAMPLE_COOKIE_MAX_SIZE,
3168 },
3169 };
3170 struct nlattr *a[OVS_PSAMPLE_ATTR_MAX + 1];
3171 int err;
3172
3173 if (!IS_ENABLED(CONFIG_PSAMPLE))
3174 return -EOPNOTSUPP;
3175
3176 err = nla_parse_nested(a, OVS_PSAMPLE_ATTR_MAX, attr, policy, NULL);
3177 if (err)
3178 return err;
3179
3180 return a[OVS_PSAMPLE_ATTR_GROUP] ? 0 : -EINVAL;
3181}
3182
3160static int copy_action(const struct nlattr *from,3183static int copy_action(const struct nlattr *from,
3161 struct sw_flow_actions **sfa, bool log)3184 struct sw_flow_actions **sfa, bool log)
3162{3185{
@@ -3212,6 +3235,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, · 49 unmodified lines
3212 [OVS_ACTION_ATTR_ADD_MPLS] = sizeof(struct ovs_action_add_mpls),3235 [OVS_ACTION_ATTR_ADD_MPLS] = sizeof(struct ovs_action_add_mpls),
3213 [OVS_ACTION_ATTR_DEC_TTL] = (u32)-1,3236 [OVS_ACTION_ATTR_DEC_TTL] = (u32)-1,
3214 [OVS_ACTION_ATTR_DROP] = sizeof(u32),3237 [OVS_ACTION_ATTR_DROP] = sizeof(u32),
3238 [OVS_ACTION_ATTR_PSAMPLE] = (u32)-1,
3215 };3239 };
3216 const struct ovs_action_push_vlan *vlan;3240 const struct ovs_action_push_vlan *vlan;
3217 int type = nla_type(a);3241 int type = nla_type(a);
@@ -3490,6 +3514,12 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, · 272 unmodified lines
3490 return -EINVAL;3514 return -EINVAL;
3491 break;3515 break;
3492 3516
3517 case OVS_ACTION_ATTR_PSAMPLE:
3518 err = validate_psample(a);
3519 if (err)
3520 return err;
3521 break;
3522
3493 default:3523 default:
3494 OVS_NLERR(log, "Unknown Action type %d", type);3524 OVS_NLERR(log, "Unknown Action type %d", type);
3495 return -EINVAL;3525 return -EINVAL;
net/openvswitch/vport.c+1−0
@@ -500,6 +500,7 @@ int ovs_vport_receive(struct vport *vport, struct sk_buff *skb, · 499 unmodified lines
500 OVS_CB(skb)->input_vport = vport;500 OVS_CB(skb)->input_vport = vport;
501 OVS_CB(skb)->mru = 0;501 OVS_CB(skb)->mru = 0;
502 OVS_CB(skb)->cutlen = 0;502 OVS_CB(skb)->cutlen = 0;
503 OVS_CB(skb)->probability = 0;
503 if (unlikely(dev_net(skb->dev) != ovs_dp_get_net(vport->dp))) {504 if (unlikely(dev_net(skb->dev) != ovs_dp_get_net(vport->dp))) {
504 u32 mark;505 u32 mark;
505 506
net/psample/psample.c+15−1
@@ -376,6 +376,10 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, · 375 unmodified lines
376 void *data;376 void *data;
377 int ret;377 int ret;
378 378
379 if (!genl_has_listeners(&psample_nl_family, group->net,
380 PSAMPLE_NL_MCGRP_SAMPLE))
381 return;
382
379 meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) +383 meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) +
380 (out_ifindex ? nla_total_size(sizeof(u16)) : 0) +384 (out_ifindex ? nla_total_size(sizeof(u16)) : 0) +
381 (md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) +385 (md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) +
@@ -386,7 +390,9 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, · 4 unmodified lines
386 nla_total_size(sizeof(u32)) + /* group_num */390 nla_total_size(sizeof(u32)) + /* group_num */
387 nla_total_size(sizeof(u32)) + /* seq */391 nla_total_size(sizeof(u32)) + /* seq */
388 nla_total_size_64bit(sizeof(u64)) + /* timestamp */392 nla_total_size_64bit(sizeof(u64)) + /* timestamp */
389 nla_total_size(sizeof(u16)); /* protocol */393 nla_total_size(sizeof(u16)) + /* protocol */
394 (md->user_cookie_len ?
395 nla_total_size(md->user_cookie_len) : 0); /* user cookie */
390 396
391#ifdef CONFIG_INET397#ifdef CONFIG_INET
392 tun_info = skb_tunnel_info(skb);398 tun_info = skb_tunnel_info(skb);
@@ -486,6 +492,14 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, · 93 unmodified lines
486 }492 }
487#endif493#endif
488 494
495 if (md->user_cookie && md->user_cookie_len &&
496 nla_put(nl_skb, PSAMPLE_ATTR_USER_COOKIE, md->user_cookie_len,
497 md->user_cookie))
498 goto error;
499
500 if (md->rate_as_probability)
501 nla_put_flag(skb, PSAMPLE_ATTR_SAMPLE_PROBABILITY);
502
489 genlmsg_end(nl_skb, data);503 genlmsg_end(nl_skb, data);
490 genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,504 genlmsg_multicast_netns(&psample_nl_family, group->net, nl_skb, 0,
491 PSAMPLE_NL_MCGRP_SAMPLE, GFP_ATOMIC);505 PSAMPLE_NL_MCGRP_SAMPLE, GFP_ATOMIC);
net/sched/act_sample.c+12−0
@@ -167,7 +167,9 @@ TC_INDIRECT_SCOPE int tcf_sample_act(struct sk_buff *skb, · 166 unmodified lines
167{167{
168 struct tcf_sample *s = to_sample(a);168 struct tcf_sample *s = to_sample(a);
169 struct psample_group *psample_group;169 struct psample_group *psample_group;
170 u8 cookie_data[TC_COOKIE_MAX_SIZE];
170 struct psample_metadata md = {};171 struct psample_metadata md = {};
172 struct tc_cookie *user_cookie;
171 int retval;173 int retval;
172 174
173 tcf_lastuse_update(&s->tcf_tm);175 tcf_lastuse_update(&s->tcf_tm);
@@ -189,6 +191,16 @@ TC_INDIRECT_SCOPE int tcf_sample_act(struct sk_buff *skb, · 15 unmodified lines
189 if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))191 if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev))
190 skb_push(skb, skb->mac_len);192 skb_push(skb, skb->mac_len);
191 193
194 rcu_read_lock();
195 user_cookie = rcu_dereference(a->user_cookie);
196 if (user_cookie) {
197 memcpy(cookie_data, user_cookie->data,
198 user_cookie->len);
199 md.user_cookie = cookie_data;
200 md.user_cookie_len = user_cookie->len;
201 }
202 rcu_read_unlock();
203
192 md.trunc_size = s->truncate ? s->trunc_size : skb->len;204 md.trunc_size = s->truncate ? s->trunc_size : skb->len;
193 psample_sample_packet(psample_group, skb, s->rate, &md);205 psample_sample_packet(psample_group, skb, s->rate, &md);
194 206
tools/testing/selftests/net/openvswitch/openvswitch.sh+112−3
@@ -20,7 +20,8 @@ tests=" · 19 unmodified lines
20 nat_related_v4 ip4-nat-related: ICMP related matches work with SNAT20 nat_related_v4 ip4-nat-related: ICMP related matches work with SNAT
21 netlink_checks ovsnl: validate netlink attrs and settings21 netlink_checks ovsnl: validate netlink attrs and settings
22 upcall_interfaces ovs: test the upcall interfaces22 upcall_interfaces ovs: test the upcall interfaces
23 drop_reason drop: test drop reasons are emitted"23 drop_reason drop: test drop reasons are emitted
24 psample psample: Sampling packets with psample"
24 25
25info() {26info() {
26 [ "${ovs_dir}" != "" ] &&27 [ "${ovs_dir}" != "" ] &&
@@ -105,12 +106,21 @@ ovs_netns_spawn_daemon() { · 78 unmodified lines
105 shift106 shift
106 netns=$1107 netns=$1
107 shift108 shift
108 info "spawning cmd: $*"109 if [ "$netns" == "_default" ]; then
109 ip netns exec $netns $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &110 $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &
111 else
112 ip netns exec $netns $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &
113 fi
110 pid=$!114 pid=$!
111 ovs_sbx "$sbx" on_exit "kill -TERM $pid 2>/dev/null"115 ovs_sbx "$sbx" on_exit "kill -TERM $pid 2>/dev/null"
112}116}
113 117
118ovs_spawn_daemon() {
119 sbx=$1
120 shift
121 ovs_netns_spawn_daemon $sbx "_default" $*
122}
123
114ovs_add_netns_and_veths () {124ovs_add_netns_and_veths () {
115 info "Adding netns attached: sbx:$1 dp:$2 {$3, $4, $5}"125 info "Adding netns attached: sbx:$1 dp:$2 {$3, $4, $5}"
116 ovs_sbx "$1" ip netns add "$3" || return 1126 ovs_sbx "$1" ip netns add "$3" || return 1
@@ -173,6 +183,19 @@ ovs_drop_reason_count() · 56 unmodified lines
173 return `echo "$perf_output" | grep "$pattern" | wc -l`183 return `echo "$perf_output" | grep "$pattern" | wc -l`
174}184}
175 185
186ovs_test_flow_fails () {
187 ERR_MSG="Flow actions may not be safe on all matching packets"
188
189 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
190 ovs_add_flow $@ &> /dev/null $@ && return 1
191 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
192
193 if [ "$PRE_TEST" == "$POST_TEST" ]; then
194 return 1
195 fi
196 return 0
197}
198
176usage() {199usage() {
177 echo200 echo
178 echo "$0 [OPTIONS] [TEST]..."201 echo "$0 [OPTIONS] [TEST]..."
@@ -187,6 +210,92 @@ usage() { · 8 unmodified lines
187 exit 1210 exit 1
188}211}
189 212
213
214# psample test
215# - use psample to observe packets
216test_psample() {
217 sbx_add "test_psample" || return $?
218
219 # Add a datapath with per-vport dispatching.
220 ovs_add_dp "test_psample" psample -V 2:1 || return 1
221
222 info "create namespaces"
223 ovs_add_netns_and_veths "test_psample" "psample" \
224 client c0 c1 172.31.110.10/24 -u || return 1
225 ovs_add_netns_and_veths "test_psample" "psample" \
226 server s0 s1 172.31.110.20/24 -u || return 1
227
228 # Check if psample actions can be configured.
229 ovs_add_flow "test_psample" psample \
230 'in_port(1),eth(),eth_type(0x0806),arp()' 'psample(group=1)' &> /dev/null
231 if [ $? == 1 ]; then
232 info "no support for psample - skipping"
233 ovs_exit_sig
234 return $ksft_skip
235 fi
236
237 ovs_del_flows "test_psample" psample
238
239 # Test action verification.
240 OLDIFS=$IFS
241 IFS='*'
242 min_key='in_port(1),eth(),eth_type(0x0800),ipv4()'
243 for testcase in \
244 "cookie to large"*"psample(group=1,cookie=1615141312111009080706050403020100)" \
245 "no group with cookie"*"psample(cookie=abcd)" \
246 "no group"*"psample()";
247 do
248 set -- $testcase;
249 ovs_test_flow_fails "test_psample" psample $min_key $2
250 if [ $? == 1 ]; then
251 info "failed - $1"
252 return 1
253 fi
254 done
255 IFS=$OLDIFS
256
257 ovs_del_flows "test_psample" psample
258 # Allow ARP
259 ovs_add_flow "test_psample" psample \
260 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
261 ovs_add_flow "test_psample" psample \
262 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
263
264 # Sample first 14 bytes of all traffic.
265 ovs_add_flow "test_psample" psample \
266 "in_port(1),eth(),eth_type(0x0800),ipv4()" \
267 "trunc(14),psample(group=1,cookie=c0ffee),2"
268
269 # Sample all traffic. In this case, use a sample() action with both
270 # psample and an upcall emulating simultaneous local sampling and
271 # sFlow / IPFIX.
272 nlpid=$(grep -E "listening on upcall packet handler" \
273 $ovs_dir/s0.out | cut -d ":" -f 2 | tr -d ' ')
274
275 ovs_add_flow "test_psample" psample \
276 "in_port(2),eth(),eth_type(0x0800),ipv4()" \
277 "sample(sample=100%,actions(psample(group=2,cookie=eeff0c),userspace(pid=${nlpid},userdata=eeff0c))),1"
278
279 # Record psample data.
280 ovs_spawn_daemon "test_psample" python3 $ovs_base/ovs-dpctl.py psample-events
281
282 # Send a single ping.
283 sleep 1
284 ovs_sbx "test_psample" ip netns exec client ping -I c1 172.31.110.20 -c 1 || return 1
285 sleep 1
286
287 # We should have received one userspace action upcall and 2 psample packets.
288 grep -E "userspace action command" $ovs_dir/s0.out >/dev/null 2>&1 || return 1
289
290 # client -> server samples should only contain the first 14 bytes of the packet.
291 grep -E "rate:4294967295,group:1,cookie:c0ffee data:[0-9a-f]{28}$" \
292 $ovs_dir/stdout >/dev/null 2>&1 || return 1
293 grep -E "rate:4294967295,group:2,cookie:eeff0c" \
294 $ovs_dir/stdout >/dev/null 2>&1 || return 1
295
296 return 0
297}
298
190# drop_reason test299# drop_reason test
191# - drop packets and verify the right drop reason is reported300# - drop packets and verify the right drop reason is reported
192test_drop_reason() {301test_drop_reason() {
tools/testing/selftests/net/openvswitch/ovs-dpctl.py+266−6
@@ -8,6 +8,7 @@ import argparse · 7 unmodified lines
8import errno8import errno
9import ipaddress9import ipaddress
10import logging10import logging
11import math
11import multiprocessing12import multiprocessing
12import re13import re
13import socket14import socket
@@ -27,8 +28,10 @@ try: · 13 unmodified lines
27 from pyroute2.netlink import genlmsg28 from pyroute2.netlink import genlmsg
28 from pyroute2.netlink import nla29 from pyroute2.netlink import nla
29 from pyroute2.netlink import nlmsg_atoms30 from pyroute2.netlink import nlmsg_atoms
31 from pyroute2.netlink.event import EventSocket
30 from pyroute2.netlink.exceptions import NetlinkError32 from pyroute2.netlink.exceptions import NetlinkError
31 from pyroute2.netlink.generic import GenericNetlinkSocket33 from pyroute2.netlink.generic import GenericNetlinkSocket
34 from pyroute2.netlink.nlsocket import Marshal
32 import pyroute235 import pyroute2
33 import pyroute2.iproute36 import pyroute2.iproute
34 37
@@ -60,6 +63,7 @@ OVS_FLOW_CMD_DEL = 2 · 25 unmodified lines
60OVS_FLOW_CMD_GET = 363OVS_FLOW_CMD_GET = 3
61OVS_FLOW_CMD_SET = 464OVS_FLOW_CMD_SET = 4
62 65
66UINT32_MAX = 0xFFFFFFFF
63 67
64def macstr(mac):68def macstr(mac):
65 outstr = ":".join(["%02X" % i for i in mac])69 outstr = ":".join(["%02X" % i for i in mac])
@@ -281,6 +285,75 @@ def parse_extract_field( · 215 unmodified lines
281 return str_skipped, data285 return str_skipped, data
282 286
283 287
288def parse_attrs(actstr, attr_desc):
289 """Parses the given action string and returns a list of netlink
290 attributes based on a list of attribute descriptions.
291
292 Each element in the attribute description list is a tuple such as:
293 (name, attr_name, parse_func)
294 where:
295 name: is the string representing the attribute
296 attr_name: is the name of the attribute as defined in the uAPI.
297 parse_func: is a callable accepting a string and returning either
298 a single object (the parsed attribute value) or a tuple of
299 two values (the parsed attribute value and the remaining string)
300
301 Returns a list of attributes and the remaining string.
302 """
303 def parse_attr(actstr, key, func):
304 actstr = actstr[len(key) :]
305
306 if not func:
307 return None, actstr
308
309 delim = actstr[0]
310 actstr = actstr[1:]
311
312 if delim == "=":
313 pos = strcspn(actstr, ",)")
314 ret = func(actstr[:pos])
315 else:
316 ret = func(actstr)
317
318 if isinstance(ret, tuple):
319 (datum, actstr) = ret
320 else:
321 datum = ret
322 actstr = actstr[strcspn(actstr, ",)"):]
323
324 if delim == "(":
325 if not actstr or actstr[0] != ")":
326 raise ValueError("Action contains unbalanced parentheses")
327
328 actstr = actstr[1:]
329
330 actstr = actstr[strspn(actstr, ", ") :]
331
332 return datum, actstr
333
334 attrs = []
335 attr_desc = list(attr_desc)
336 while actstr and actstr[0] != ")" and attr_desc:
337 found = False
338 for i, (key, attr, func) in enumerate(attr_desc):
339 if actstr.startswith(key):
340 datum, actstr = parse_attr(actstr, key, func)
341 attrs.append([attr, datum])
342 found = True
343 del attr_desc[i]
344
345 if not found:
346 raise ValueError("Unknown attribute: '%s'" % actstr)
347
348 actstr = actstr[strspn(actstr, ", ") :]
349
350 if actstr[0] != ")":
351 raise ValueError("Action string contains extra garbage or has "
352 "unbalanced parenthesis: '%s'" % actstr)
353
354 return attrs, actstr[1:]
355
356
284class ovs_dp_msg(genlmsg):357class ovs_dp_msg(genlmsg):
285 # include the OVS version358 # include the OVS version
286 # We need a custom header rather than just being able to rely on359 # We need a custom header rather than just being able to rely on
@@ -299,7 +372,7 @@ class ovsactions(nla): · 12 unmodified lines
299 ("OVS_ACTION_ATTR_SET", "ovskey"),372 ("OVS_ACTION_ATTR_SET", "ovskey"),
300 ("OVS_ACTION_ATTR_PUSH_VLAN", "none"),373 ("OVS_ACTION_ATTR_PUSH_VLAN", "none"),
301 ("OVS_ACTION_ATTR_POP_VLAN", "flag"),374 ("OVS_ACTION_ATTR_POP_VLAN", "flag"),
302 ("OVS_ACTION_ATTR_SAMPLE", "none"),375 ("OVS_ACTION_ATTR_SAMPLE", "sample"),
303 ("OVS_ACTION_ATTR_RECIRC", "uint32"),376 ("OVS_ACTION_ATTR_RECIRC", "uint32"),
304 ("OVS_ACTION_ATTR_HASH", "none"),377 ("OVS_ACTION_ATTR_HASH", "none"),
305 ("OVS_ACTION_ATTR_PUSH_MPLS", "none"),378 ("OVS_ACTION_ATTR_PUSH_MPLS", "none"),
@@ -318,8 +391,85 @@ class ovsactions(nla): · 12 unmodified lines
318 ("OVS_ACTION_ATTR_ADD_MPLS", "none"),391 ("OVS_ACTION_ATTR_ADD_MPLS", "none"),
319 ("OVS_ACTION_ATTR_DEC_TTL", "none"),392 ("OVS_ACTION_ATTR_DEC_TTL", "none"),
320 ("OVS_ACTION_ATTR_DROP", "uint32"),393 ("OVS_ACTION_ATTR_DROP", "uint32"),
394 ("OVS_ACTION_ATTR_PSAMPLE", "psample"),
321 )395 )
322 396
397 class psample(nla):
398 nla_flags = NLA_F_NESTED
399
400 nla_map = (
401 ("OVS_PSAMPLE_ATTR_UNSPEC", "none"),
402 ("OVS_PSAMPLE_ATTR_GROUP", "uint32"),
403 ("OVS_PSAMPLE_ATTR_COOKIE", "array(uint8)"),
404 )
405
406 def dpstr(self, more=False):
407 args = "group=%d" % self.get_attr("OVS_PSAMPLE_ATTR_GROUP")
408
409 cookie = self.get_attr("OVS_PSAMPLE_ATTR_COOKIE")
410 if cookie:
411 args += ",cookie(%s)" % \
412 "".join(format(x, "02x") for x in cookie)
413
414 return "psample(%s)" % args
415
416 def parse(self, actstr):
417 desc = (
418 ("group", "OVS_PSAMPLE_ATTR_GROUP", int),
419 ("cookie", "OVS_PSAMPLE_ATTR_COOKIE",
420 lambda x: list(bytearray.fromhex(x)))
421 )
422
423 attrs, actstr = parse_attrs(actstr, desc)
424
425 for attr in attrs:
426 self["attrs"].append(attr)
427
428 return actstr
429
430 class sample(nla):
431 nla_flags = NLA_F_NESTED
432
433 nla_map = (
434 ("OVS_SAMPLE_ATTR_UNSPEC", "none"),
435 ("OVS_SAMPLE_ATTR_PROBABILITY", "uint32"),
436 ("OVS_SAMPLE_ATTR_ACTIONS", "ovsactions"),
437 )
438
439 def dpstr(self, more=False):
440 args = []
441
442 args.append("sample={:.2f}%".format(
443 100 * self.get_attr("OVS_SAMPLE_ATTR_PROBABILITY") /
444 UINT32_MAX))
445
446 actions = self.get_attr("OVS_SAMPLE_ATTR_ACTIONS")
447 if actions:
448 args.append("actions(%s)" % actions.dpstr(more))
449
450 return "sample(%s)" % ",".join(args)
451
452 def parse(self, actstr):
453 def parse_nested_actions(actstr):
454 subacts = ovsactions()
455 parsed_len = subacts.parse(actstr)
456 return subacts, actstr[parsed_len :]
457
458 def percent_to_rate(percent):
459 percent = float(percent.strip('%'))
460 return int(math.floor(UINT32_MAX * (percent / 100.0) + .5))
461
462 desc = (
463 ("sample", "OVS_SAMPLE_ATTR_PROBABILITY", percent_to_rate),
464 ("actions", "OVS_SAMPLE_ATTR_ACTIONS", parse_nested_actions),
465 )
466 attrs, actstr = parse_attrs(actstr, desc)
467
468 for attr in attrs:
469 self["attrs"].append(attr)
470
471 return actstr
472
323 class ctact(nla):473 class ctact(nla):
324 nla_flags = NLA_F_NESTED474 nla_flags = NLA_F_NESTED
325 475
@@ -441,13 +591,27 @@ class ovsactions(nla): · 115 unmodified lines
441 print_str += "userdata="591 print_str += "userdata="
442 for f in self.get_attr("OVS_USERSPACE_ATTR_USERDATA"):592 for f in self.get_attr("OVS_USERSPACE_ATTR_USERDATA"):
443 print_str += "%x." % f593 print_str += "%x." % f
444 if self.get_attr("OVS_USERSPACE_ATTR_TUN_PORT") is not None:594 if self.get_attr("OVS_USERSPACE_ATTR_EGRESS_TUN_PORT") is not None:
445 print_str += "egress_tun_port=%d" % self.get_attr(595 print_str += "egress_tun_port=%d" % self.get_attr(
446 "OVS_USERSPACE_ATTR_TUN_PORT"596 "OVS_USERSPACE_ATTR_EGRESS_TUN_PORT"
447 )597 )
448 print_str += ")"598 print_str += ")"
449 return print_str599 return print_str
450 600
601 def parse(self, actstr):
602 attrs_desc = (
603 ("pid", "OVS_USERSPACE_ATTR_PID", int),
604 ("userdata", "OVS_USERSPACE_ATTR_USERDATA",
605 lambda x: list(bytearray.fromhex(x))),
606 ("egress_tun_port", "OVS_USERSPACE_ATTR_EGRESS_TUN_PORT", int)
607 )
608
609 attrs, actstr = parse_attrs(actstr, attrs_desc)
610 for attr in attrs:
611 self["attrs"].append(attr)
612
613 return actstr
614
451 def dpstr(self, more=False):615 def dpstr(self, more=False):
452 print_str = ""616 print_str = ""
453 617
@@ -683,6 +847,37 @@ class ovsactions(nla): · 229 unmodified lines
683 self["attrs"].append(["OVS_ACTION_ATTR_CT", ctact])847 self["attrs"].append(["OVS_ACTION_ATTR_CT", ctact])
684 parsed = True848 parsed = True
685 849
850 elif parse_starts_block(actstr, "sample(", False):
851 sampleact = self.sample()
852 actstr = sampleact.parse(actstr[len("sample(") : ])
853 self["attrs"].append(["OVS_ACTION_ATTR_SAMPLE", sampleact])
854 parsed = True
855
856 elif parse_starts_block(actstr, "psample(", False):
857 psampleact = self.psample()
858 actstr = psampleact.parse(actstr[len("psample(") : ])
859 self["attrs"].append(["OVS_ACTION_ATTR_PSAMPLE", psampleact])
860 parsed = True
861
862 elif parse_starts_block(actstr, "userspace(", False):
863 uact = self.userspace()
864 actstr = uact.parse(actstr[len("userspace(") : ])
865 self["attrs"].append(["OVS_ACTION_ATTR_USERSPACE", uact])
866 parsed = True
867
868 elif parse_starts_block(actstr, "trunc(", False):
869 parencount += 1
870 actstr, val = parse_extract_field(
871 actstr,
872 "trunc(",
873 r"([0-9]+)",
874 int,
875 False,
876 None,
877 )
878 self["attrs"].append(["OVS_ACTION_ATTR_TRUNC", val])
879 parsed = True
880
686 actstr = actstr[strspn(actstr, ", ") :]881 actstr = actstr[strspn(actstr, ", ") :]
687 while parencount > 0:882 while parencount > 0:
688 parencount -= 1883 parencount -= 1
@@ -2267,10 +2462,70 @@ class OvsFlow(GenericNetlinkSocket): · 1578 unmodified lines
2267 print("MISS upcall[%d/%s]: %s" % (seq, pktpres, keystr), flush=True)2462 print("MISS upcall[%d/%s]: %s" % (seq, pktpres, keystr), flush=True)
2268 2463
2269 def execute(self, packetmsg):2464 def execute(self, packetmsg):
2270 print("userspace execute command")2465 print("userspace execute command", flush=True)
2271 2466
2272 def action(self, packetmsg):2467 def action(self, packetmsg):
2273 print("userspace action command")2468 print("userspace action command", flush=True)
2469
2470
2471class psample_sample(genlmsg):
2472 nla_map = (
2473 ("PSAMPLE_ATTR_IIFINDEX", "none"),
2474 ("PSAMPLE_ATTR_OIFINDEX", "none"),
2475 ("PSAMPLE_ATTR_ORIGSIZE", "none"),
2476 ("PSAMPLE_ATTR_SAMPLE_GROUP", "uint32"),
2477 ("PSAMPLE_ATTR_GROUP_SEQ", "none"),
2478 ("PSAMPLE_ATTR_SAMPLE_RATE", "uint32"),
2479 ("PSAMPLE_ATTR_DATA", "array(uint8)"),
2480 ("PSAMPLE_ATTR_GROUP_REFCOUNT", "none"),
2481 ("PSAMPLE_ATTR_TUNNEL", "none"),
2482 ("PSAMPLE_ATTR_PAD", "none"),
2483 ("PSAMPLE_ATTR_OUT_TC", "none"),
2484 ("PSAMPLE_ATTR_OUT_TC_OCC", "none"),
2485 ("PSAMPLE_ATTR_LATENCY", "none"),
2486 ("PSAMPLE_ATTR_TIMESTAMP", "none"),
2487 ("PSAMPLE_ATTR_PROTO", "none"),
2488 ("PSAMPLE_ATTR_USER_COOKIE", "array(uint8)"),
2489 )
2490
2491 def dpstr(self):
2492 fields = []
2493 data = ""
2494 for (attr, value) in self["attrs"]:
2495 if attr == "PSAMPLE_ATTR_SAMPLE_GROUP":
2496 fields.append("group:%d" % value)
2497 if attr == "PSAMPLE_ATTR_SAMPLE_RATE":
2498 fields.append("rate:%d" % value)
2499 if attr == "PSAMPLE_ATTR_USER_COOKIE":
2500 value = "".join(format(x, "02x") for x in value)
2501 fields.append("cookie:%s" % value)
2502 if attr == "PSAMPLE_ATTR_DATA" and len(value) > 0:
2503 data = "data:%s" % "".join(format(x, "02x") for x in value)
2504
2505 return ("%s %s" % (",".join(fields), data)).strip()
2506
2507
2508class psample_msg(Marshal):
2509 PSAMPLE_CMD_SAMPLE = 0
2510 PSAMPLE_CMD_GET_GROUP = 1
2511 PSAMPLE_CMD_NEW_GROUP = 2
2512 PSAMPLE_CMD_DEL_GROUP = 3
2513 PSAMPLE_CMD_SET_FILTER = 4
2514 msg_map = {PSAMPLE_CMD_SAMPLE: psample_sample}
2515
2516
2517class PsampleEvent(EventSocket):
2518 genl_family = "psample"
2519 mcast_groups = ["packets"]
2520 marshal_class = psample_msg
2521
2522 def read_samples(self):
2523 while True:
2524 try:
2525 for msg in self.get():
2526 print(msg.dpstr(), flush=True)
2527 except NetlinkError as ne:
2528 raise ne
2274 2529
2275 2530
2276def print_ovsdp_full(dp_lookup_rep, ifindex, ndb=NDB(), vpl=OvsVport()):2531def print_ovsdp_full(dp_lookup_rep, ifindex, ndb=NDB(), vpl=OvsVport()):
@@ -2337,7 +2592,7 @@ def main(argv): · 60 unmodified lines
2337 help="Increment 'verbose' output counter.",2592 help="Increment 'verbose' output counter.",
2338 default=0,2593 default=0,
2339 )2594 )
2340 subparsers = parser.add_subparsers()2595 subparsers = parser.add_subparsers(dest="subcommand")
2341 2596
2342 showdpcmd = subparsers.add_parser("show")2597 showdpcmd = subparsers.add_parser("show")
2343 showdpcmd.add_argument(2598 showdpcmd.add_argument(
@@ -2412,6 +2667,8 @@ def main(argv): · 68 unmodified lines
2412 delfscmd = subparsers.add_parser("del-flows")2667 delfscmd = subparsers.add_parser("del-flows")
2413 delfscmd.add_argument("flsbr", help="Datapath name")2668 delfscmd.add_argument("flsbr", help="Datapath name")
2414 2669
2670 subparsers.add_parser("psample-events")
2671
2415 args = parser.parse_args()2672 args = parser.parse_args()
2416 2673
2417 if args.verbose > 0:2674 if args.verbose > 0:
@@ -2426,6 +2683,9 @@ def main(argv): · 8 unmodified lines
2426 2683
2427 sys.setrecursionlimit(100000)2684 sys.setrecursionlimit(100000)
2428 2685
2686 if args.subcommand == "psample-events":
2687 PsampleEvent().read_samples()
2688
2429 if hasattr(args, "showdp"):2689 if hasattr(args, "showdp"):
2430 found = False2690 found = False
2431 for iface in ndb.interfaces:2691 for iface in ndb.interfaces:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t