Skip to content

Commit

Permalink
netdev-dummy: Set flow mark for offloaded flows.
Browse files Browse the repository at this point in the history
Match packets received on dummy interfaces with offloaded flows and
set up corresponding marks in dp-packet.

Acked-by: Flavio Leitner <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
Signed-off-by: Ian Stokes <[email protected]>
  • Loading branch information
igsilya authored and istokes committed Mar 13, 2019
1 parent b4f86fc commit 4960f9a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions lib/netdev-dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct netdev_rxq_dummy {
static unixctl_cb_func netdev_dummy_set_admin_state;
static int netdev_dummy_construct(struct netdev *);
static void netdev_dummy_queue_packet(struct netdev_dummy *,
struct dp_packet *, int);
struct dp_packet *, struct flow *, int);

static void dummy_packet_stream_close(struct dummy_packet_stream *);

Expand Down Expand Up @@ -283,7 +283,7 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
dp_packet_pull(&s->rxbuf, 2);
netdev_dummy_queue_packet(dev,
dp_packet_clone(&s->rxbuf), 0);
dp_packet_clone(&s->rxbuf), NULL, 0);
dp_packet_clear(&s->rxbuf);
}
} else if (retval != -EAGAIN) {
Expand Down Expand Up @@ -1151,7 +1151,7 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
struct dp_packet *reply = dp_packet_new(0);
compose_arp(reply, ARP_OP_REPLY, dev->hwaddr, flow.dl_src,
false, flow.nw_dst, flow.nw_src);
netdev_dummy_queue_packet(dev, reply, 0);
netdev_dummy_queue_packet(dev, reply, NULL, 0);
}
}

Expand Down Expand Up @@ -1562,14 +1562,14 @@ eth_from_packet(const char *s)
}

static struct dp_packet *
eth_from_flow(const char *s, size_t packet_size, char **errorp)
eth_from_flow_str(const char *s, size_t packet_size,
struct flow *flow, char **errorp)
{
*errorp = NULL;

enum odp_key_fitness fitness;
struct dp_packet *packet;
struct ofpbuf odp_key;
struct flow flow;
int error;

/* Convert string to datapath key.
Expand All @@ -1586,23 +1586,23 @@ eth_from_flow(const char *s, size_t packet_size, char **errorp)
}

/* Convert odp_key to flow. */
fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow, errorp);
fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, flow, errorp);
if (fitness == ODP_FIT_ERROR) {
ofpbuf_uninit(&odp_key);
return NULL;
}

packet = dp_packet_new(0);
if (packet_size) {
flow_compose(packet, &flow, NULL, 0);
flow_compose(packet, flow, NULL, 0);
if (dp_packet_size(packet) < packet_size) {
packet_expand(packet, &flow, packet_size);
packet_expand(packet, flow, packet_size);
} else if (dp_packet_size(packet) > packet_size){
dp_packet_delete(packet);
packet = NULL;
}
} else {
flow_compose(packet, &flow, NULL, 64);
flow_compose(packet, flow, NULL, 64);
}

ofpbuf_uninit(&odp_key);
Expand All @@ -1622,14 +1622,28 @@ netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct dp_packet *packe

static void
netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet,
int queue_id)
struct flow *flow, int queue_id)
OVS_REQUIRES(dummy->mutex)
{
struct netdev_rxq_dummy *rx, *prev;
struct offloaded_flow *data;
struct flow packet_flow;

if (dummy->rxq_pcap) {
ovs_pcap_write(dummy->rxq_pcap, packet);
}

if (!flow) {
flow = &packet_flow;
flow_extract(packet, flow);
}
HMAP_FOR_EACH (data, node, &dummy->offloaded_flows) {
if (flow_equal_except(flow, &data->match.flow, &data->match.wc)) {
dp_packet_set_flow_mark(packet, data->mark);
break;
}
}

prev = NULL;
LIST_FOR_EACH (rx, node, &dummy->rxes) {
if (rx->up.queue_id == queue_id &&
Expand Down Expand Up @@ -1675,6 +1689,7 @@ netdev_dummy_receive(struct unixctl_conn *conn,

for (i = k; i < argc; i++) {
struct dp_packet *packet;
struct flow flow;

/* Try to parse 'argv[i]' as packet in hex. */
packet = eth_from_packet(argv[i]);
Expand All @@ -1695,15 +1710,17 @@ netdev_dummy_receive(struct unixctl_conn *conn,
}
/* Try parse 'argv[i]' as odp flow. */
char *error_s;
packet = eth_from_flow(flow_str, packet_size, &error_s);
packet = eth_from_flow_str(flow_str, packet_size, &flow, &error_s);
if (!packet) {
unixctl_command_reply_error(conn, error_s);
free(error_s);
goto exit;
}
} else {
flow_extract(packet, &flow);
}

netdev_dummy_queue_packet(dummy_dev, packet, rx_qid);
netdev_dummy_queue_packet(dummy_dev, packet, &flow, rx_qid);
}

unixctl_command_reply(conn, NULL);
Expand Down

0 comments on commit 4960f9a

Please sign in to comment.