Skip to content

Commit 52a62f8

Browse files
Nick Richardsondavem330
Nick Richardson
authored andcommitted
pktgen: Parse internet mix (imix) input
Adds "imix_weights" command for specifying internet mix distribution. The command is in this format: "imix_weights size_1,weight_1 size_2,weight_2 ... size_n,weight_n" where the probability that packet size_i is picked is: weight_i / (weight_1 + weight_2 + .. + weight_n) The user may provide up to 100 imix entries (size_i,weight_i) in this command. The user specified imix entries will be displayed in the "Params" section of the interface output. Values for clone_skb > 0 is not supported in IMIX mode. Summary of changes: Add flag for enabling internet mix mode. Add command (imix_weights) for internet mix input. Return -ENOTSUPP when clone_skb > 0 in IMIX mode. Display imix_weights in Params. Create data structures to store imix entries and distribution. Signed-off-by: Nick Richardson <richardsonnick@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6c4110d commit 52a62f8

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

net/core/pktgen.c

+96
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
#define IP_NAME_SZ 32
176176
#define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
177177
#define MPLS_STACK_BOTTOM htonl(0x00000100)
178+
/* Max number of internet mix entries that can be specified in imix_weights. */
179+
#define MAX_IMIX_ENTRIES 20
178180

179181
#define func_enter() pr_debug("entering %s\n", __func__);
180182

@@ -242,6 +244,12 @@ static char *pkt_flag_names[] = {
242244
#define VLAN_TAG_SIZE(x) ((x)->vlan_id == 0xffff ? 0 : 4)
243245
#define SVLAN_TAG_SIZE(x) ((x)->svlan_id == 0xffff ? 0 : 4)
244246

247+
struct imix_pkt {
248+
u64 size;
249+
u64 weight;
250+
u64 count_so_far;
251+
};
252+
245253
struct flow_state {
246254
__be32 cur_daddr;
247255
int count;
@@ -343,6 +351,10 @@ struct pktgen_dev {
343351
__u8 traffic_class; /* ditto for the (former) Traffic Class in IPv6
344352
(see RFC 3260, sec. 4) */
345353

354+
/* IMIX */
355+
unsigned int n_imix_entries;
356+
struct imix_pkt imix_entries[MAX_IMIX_ENTRIES];
357+
346358
/* MPLS */
347359
unsigned int nr_labels; /* Depth of stack, 0 = no MPLS */
348360
__be32 labels[MAX_MPLS_LABELS];
@@ -552,6 +564,16 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
552564
(unsigned long long)pkt_dev->count, pkt_dev->min_pkt_size,
553565
pkt_dev->max_pkt_size);
554566

567+
if (pkt_dev->n_imix_entries > 0) {
568+
seq_puts(seq, " imix_weights: ");
569+
for (i = 0; i < pkt_dev->n_imix_entries; i++) {
570+
seq_printf(seq, "%llu,%llu ",
571+
pkt_dev->imix_entries[i].size,
572+
pkt_dev->imix_entries[i].weight);
573+
}
574+
seq_puts(seq, "\n");
575+
}
576+
555577
seq_printf(seq,
556578
" frags: %d delay: %llu clone_skb: %d ifname: %s\n",
557579
pkt_dev->nfrags, (unsigned long long) pkt_dev->delay,
@@ -792,6 +814,62 @@ static int strn_len(const char __user * user_buffer, unsigned int maxlen)
792814
return i;
793815
}
794816

817+
/* Parses imix entries from user buffer.
818+
* The user buffer should consist of imix entries separated by spaces
819+
* where each entry consists of size and weight delimited by commas.
820+
* "size1,weight_1 size2,weight_2 ... size_n,weight_n" for example.
821+
*/
822+
static ssize_t get_imix_entries(const char __user *buffer,
823+
struct pktgen_dev *pkt_dev)
824+
{
825+
const int max_digits = 10;
826+
int i = 0;
827+
long len;
828+
char c;
829+
830+
pkt_dev->n_imix_entries = 0;
831+
832+
do {
833+
unsigned long weight;
834+
unsigned long size;
835+
836+
len = num_arg(&buffer[i], max_digits, &size);
837+
if (len < 0)
838+
return len;
839+
i += len;
840+
if (get_user(c, &buffer[i]))
841+
return -EFAULT;
842+
/* Check for comma between size_i and weight_i */
843+
if (c != ',')
844+
return -EINVAL;
845+
i++;
846+
847+
if (size < 14 + 20 + 8)
848+
size = 14 + 20 + 8;
849+
850+
len = num_arg(&buffer[i], max_digits, &weight);
851+
if (len < 0)
852+
return len;
853+
if (weight <= 0)
854+
return -EINVAL;
855+
856+
pkt_dev->imix_entries[pkt_dev->n_imix_entries].size = size;
857+
pkt_dev->imix_entries[pkt_dev->n_imix_entries].weight = weight;
858+
859+
i += len;
860+
if (get_user(c, &buffer[i]))
861+
return -EFAULT;
862+
863+
i++;
864+
pkt_dev->n_imix_entries++;
865+
866+
if (pkt_dev->n_imix_entries > MAX_IMIX_ENTRIES)
867+
return -E2BIG;
868+
} while (c == ' ');
869+
870+
return i;
871+
}
872+
795873
static ssize_t get_labels(const char __user *buffer, struct pktgen_dev *pkt_dev)
796874
{
797875
unsigned int n = 0;
@@ -960,6 +1038,18 @@ static ssize_t pktgen_if_write(struct file *file,
9601038
return count;
9611039
}
9621040

1041+
if (!strcmp(name, "imix_weights")) {
1042+
if (pkt_dev->clone_skb > 0)
1043+
return -EINVAL;
1044+
1045+
len = get_imix_entries(&user_buffer[i], pkt_dev);
1046+
if (len < 0)
1047+
return len;
1048+
1049+
i += len;
1050+
return count;
1051+
}
1052+
9631053
if (!strcmp(name, "debug")) {
9641054
len = num_arg(&user_buffer[i], 10, &value);
9651055
if (len < 0)
@@ -1082,10 +1172,16 @@ static ssize_t pktgen_if_write(struct file *file,
10821172
len = num_arg(&user_buffer[i], 10, &value);
10831173
if (len < 0)
10841174
return len;
1175+
/* clone_skb is not supported for netif_receive xmit_mode and
1176+
* IMIX mode.
1177+
*/
10851178
if ((value > 0) &&
10861179
((pkt_dev->xmit_mode == M_NETIF_RECEIVE) ||
10871180
!(pkt_dev->odev->priv_flags & IFF_TX_SKB_SHARING)))
10881181
return -ENOTSUPP;
1182+
if (value > 0 && pkt_dev->n_imix_entries > 0)
1183+
return -EINVAL;
1184+
10891185
i += len;
10901186
pkt_dev->clone_skb = value;
10911187

0 commit comments

Comments
 (0)