1 #include "datapath_t.h"
2 #include <linux/skbuff.h>
5 #include <linux/if_ether.h>
7 #include <linux/rcupdate.h>
11 static struct sk_buff *
12 gen_sk_buff(struct datapath *dp, uint32_t packet_size)
20 for (in_port = 0; in_port < OFPP_MAX; in_port++) {
21 if (dp->ports[in_port] != NULL)
25 if (in_port == OFPP_MAX) {
26 printk("benchmark: no in_port to send packets as\n");
30 skb = alloc_skb(packet_size, GFP_ATOMIC);
32 printk("benchmark: cannot allocate skb for benchmark\n");
36 skb_put(skb, packet_size);
37 skb_set_mac_header(skb, 0);
39 memcpy(eh->h_dest, "\x12\x34\x56\x78\x9a\xbc", ETH_ALEN);
40 memcpy(eh->h_source, "\xab\xcd\xef\x12\x34\x56", ETH_ALEN);
41 eh->h_proto = htons(ETH_P_IP);
42 skb_set_network_header(skb, sizeof(*eh));
45 ih->version = IPVERSION;
47 ih->tot_len = htons(packet_size - sizeof(*eh));
48 ih->id = htons(12345);
51 ih->protocol = IPPROTO_UDP;
52 ih->check = 0; /* want this to be right?! */
53 ih->saddr = 0x12345678;
54 ih->daddr = 0x1234abcd;
55 skb_set_transport_header(skb, sizeof(*eh) + sizeof(*ih));
57 uh->source = htons(1234);
58 uh->dest = htons(5678);
59 uh->len = htons(packet_size - sizeof(*eh) - sizeof(*ih));
61 if (dp_set_origin(dp, in_port, skb)) {
62 printk("benchmark: could not set origin\n");
71 dp_genl_benchmark_nl(struct sk_buff *skb, struct genl_info *info)
74 uint32_t num_packets = 0;
78 if (!info->attrs[DP_GENL_A_DP_IDX] || !info->attrs[DP_GENL_A_NPACKETS]
79 || !info->attrs[DP_GENL_A_PSIZE])
82 num_packets = nla_get_u32((info->attrs[DP_GENL_A_NPACKETS]));
85 dp = dp_get(nla_get_u32((info->attrs[DP_GENL_A_DP_IDX])));
90 goto benchmark_unlock;
92 skb2 = gen_sk_buff(dp, nla_get_u32((info->attrs[DP_GENL_A_PSIZE])));
95 goto benchmark_unlock;
98 for (i = 0; i < num_packets; i++) {
99 struct sk_buff *copy = skb_get(skb2);
101 printk("benchmark: skb_get failed\n");
105 if ((err = dp_output_control(dp, copy, -1,
108 printk("benchmark: output control ret %d on iter %d\n", err, i);