Skip to content

Commit

Permalink
lib: Keep track of usable protocols while parsing.
Browse files Browse the repository at this point in the history
Keep track of usable protocols while parsing actions and matches,
rather than checking for them afterwards.  This fixes silently discarded
meter and goto table instructions when not explicitly specifying the
protocol to use.

Signed-off-by: Jarno Rajahalme <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Jarno Rajahalme authored and blp committed Aug 28, 2013
1 parent 89454bf commit db0b6c2
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 315 deletions.
11 changes: 5 additions & 6 deletions lib/learning-switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct lswitch {
* to set up the flow table. */
const struct ofputil_flow_mod *default_flows;
size_t n_default_flows;
enum ofputil_protocol usable_protocols;
};

/* The log messages here could actually be useful in debugging, so keep the
Expand Down Expand Up @@ -161,6 +162,7 @@ lswitch_create(struct rconn *rconn, const struct lswitch_config *cfg)

sw->default_flows = cfg->default_flows;
sw->n_default_flows = cfg->n_default_flows;
sw->usable_protocols = cfg->usable_protocols;

sw->queued = rconn_packet_counter_create();

Expand All @@ -176,7 +178,6 @@ lswitch_handshake(struct lswitch *sw)

protocol = ofputil_protocol_from_ofp_version(rconn_get_version(sw->rconn));
if (sw->default_flows) {
enum ofputil_protocol usable_protocols;
struct ofpbuf *msg = NULL;
int error = 0;
size_t i;
Expand All @@ -188,10 +189,8 @@ lswitch_handshake(struct lswitch *sw)
* This could be improved by actually negotiating a mutually acceptable
* flow format with the switch, but that would require an asynchronous
* state machine. This version ought to work fine in practice. */
usable_protocols = ofputil_flow_mod_usable_protocols(
sw->default_flows, sw->n_default_flows);
if (!(protocol & usable_protocols)) {
enum ofputil_protocol want = rightmost_1bit(usable_protocols);
if (!(protocol & sw->usable_protocols)) {
enum ofputil_protocol want = rightmost_1bit(sw->usable_protocols);
while (!error) {
msg = ofputil_encode_set_protocol(protocol, want, &protocol);
if (!msg) {
Expand All @@ -200,7 +199,7 @@ lswitch_handshake(struct lswitch *sw)
error = rconn_send(sw->rconn, msg, NULL);
}
}
if (protocol & usable_protocols) {
if (protocol & sw->usable_protocols) {
for (i = 0; !error && i < sw->n_default_flows; i++) {
msg = ofputil_encode_flow_mod(&sw->default_flows[i], protocol);
error = rconn_send(sw->rconn, msg, NULL);
Expand Down
2 changes: 2 additions & 0 deletions lib/learning-switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "ofp-util.h"

struct ofpbuf;
struct rconn;
Expand Down Expand Up @@ -50,6 +51,7 @@ struct lswitch_config {
* to set up the flow table. */
const struct ofputil_flow_mod *default_flows;
size_t n_default_flows;
enum ofputil_protocol usable_protocols;

/* The OpenFlow queue to use by default. Use UINT32_MAX to avoid
* specifying a particular queue. */
Expand Down
Loading

0 comments on commit db0b6c2

Please sign in to comment.