Flow mod behavior: Add a new flag to flow mods and flow conflict
detection handler for table maintanance Add a CHECK_OVERLAP flag to flow mods which requires the switch to do the (potentially more costly) check that there doesn't already exist a conflicting flow with the same priority. If there is one, the mod fails and an error code is returned. Flow expiry: Record OFPFF_SEND_FLOW_EXP flag in user data path
This commit is contained in:
1 parent
c42075a48f
commit
a47208dc76
21 files changed
+412
-111
No files matched your search
@@ -153,6 +153,27 @@ chain_modify(struct sw_chain *chain, const struct sw_flow_key *key,
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Checks whether the chain has an entry with the same priority which conflicts
|
||||
* with 'key'. If 'strict' set, wildcards should also match. If 'strict' is not
|
||||
* set, comparison is done 'module wildcards'.
|
||||
*
|
||||
* Returns 'true' if such an entry exists, 'false' otherwise. */
|
||||
int
|
||||
chain_has_conflict(struct sw_chain *chain, const struct sw_flow_key *key,
|
||||
uint16_t priority, int strict)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < chain->n_tables; i++) {
|
||||
struct sw_table *t = chain->tables[i];
|
||||
if (t->has_conflict(t, key, priority, strict)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Deletes from 'chain' any and all flows that match 'key'. If 'out_port'
|
||||
* is not OFPP_NONE, then matching entries must have that port as an
|
||||
* argument for an output action. If 'strict" is set, then wildcards and
|
||||
|
||||
@@ -29,6 +29,8 @@ struct sw_flow *chain_lookup(struct sw_chain *, const struct sw_flow_key *,
|
||||
int chain_insert(struct sw_chain *, struct sw_flow *, int);
|
||||
int chain_modify(struct sw_chain *, const struct sw_flow_key *,
|
||||
uint16_t, int, const struct ofp_action_header *, size_t, int);
|
||||
int chain_has_conflict(struct sw_chain *, const struct sw_flow_key *,
|
||||
uint16_t, int);
|
||||
int chain_delete(struct sw_chain *, const struct sw_flow_key *, uint16_t,
|
||||
uint16_t, int, int);
|
||||
int chain_timeout(struct sw_chain *);
|
||||
|
||||
+2
-22
@@ -54,18 +54,10 @@ static char hw_desc[DESC_STR_LEN] = "Reference Data plane Kernel Extension for L
|
||||
static char sw_desc[DESC_STR_LEN] = VERSION BUILDNR;
|
||||
static char serial_num[SERIAL_NUM_LEN] = "None";
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
|
||||
module_param_string(mfr_desc, mfr_desc, sizeof mfr_desc, 0444);
|
||||
module_param_string(hw_desc, hw_desc, sizeof hw_desc, 0444);
|
||||
module_param_string(sw_desc, sw_desc, sizeof sw_desc, 0444);
|
||||
module_param_string(serial_num, serial_num, sizeof serial_num, 0444);
|
||||
#else
|
||||
MODULE_PARM(mfr_desc, "s");
|
||||
MODULE_PARM(hw_desc, "s");
|
||||
MODULE_PARM(sw_desc, "s");
|
||||
MODULE_PARM(serial_num, "s");
|
||||
#endif
|
||||
|
||||
|
||||
int (*dp_ioctl_hook)(struct net_device *dev, struct ifreq *rq, int cmd);
|
||||
EXPORT_SYMBOL(dp_ioctl_hook);
|
||||
@@ -544,29 +536,17 @@ do_port_input(struct net_bridge_port *p, struct sk_buff *skb)
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
/* Called with rcu_read_lock. */
|
||||
static struct sk_buff *dp_frame_hook(struct net_bridge_port *p,
|
||||
struct sk_buff *skb)
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
do_port_input(p, skb);
|
||||
return NULL;
|
||||
}
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
|
||||
#else
|
||||
static int dp_frame_hook(struct net_bridge_port *p, struct sk_buff **pskb)
|
||||
{
|
||||
do_port_input(p, *pskb);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
/* NB: This has only been tested on 2.4.35 */
|
||||
static void dp_frame_hook(struct sk_buff *skb)
|
||||
{
|
||||
struct net_bridge_port *p = skb->dev->br_port;
|
||||
if (p) {
|
||||
rcu_read_lock();
|
||||
do_port_input(p, skb);
|
||||
rcu_read_unlock();
|
||||
} else
|
||||
kfree_skb(skb);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Forwarding output path.
|
||||
|
||||
+54
-12
@@ -202,13 +202,14 @@ recv_echo_reply(struct sw_chain *chain, const struct sender *sender,
|
||||
}
|
||||
|
||||
static int
|
||||
add_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
add_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
const struct ofp_flow_mod *ofm)
|
||||
{
|
||||
int error = -ENOMEM;
|
||||
uint16_t v_code;
|
||||
struct sw_flow *flow;
|
||||
size_t actions_len = ntohs(ofm->header.length) - sizeof *ofm;
|
||||
int overlap;
|
||||
|
||||
/* Allocate memory. */
|
||||
flow = flow_alloc(actions_len, GFP_ATOMIC);
|
||||
@@ -224,8 +225,21 @@ add_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
goto error_free_flow;
|
||||
}
|
||||
|
||||
/* Fill out flow. */
|
||||
flow->priority = flow->key.wildcards ? ntohs(ofm->priority) : -1;
|
||||
if (ntohs(ofm->flags) & OFPFF_CHECK_OVERLAP) {
|
||||
/* check whether there is any conflict */
|
||||
overlap = chain_has_conflict(chain, &flow->key, flow->priority,
|
||||
false);
|
||||
if (overlap){
|
||||
dp_send_error_msg(chain->dp, sender,
|
||||
OFPET_FLOW_MOD_FAILED,
|
||||
OFPFMFC_OVERLAP,
|
||||
ofm, ntohs(ofm->header.length));
|
||||
goto error_free_flow;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fill out flow. */
|
||||
flow->idle_timeout = ntohs(ofm->idle_timeout);
|
||||
flow->hard_timeout = ntohs(ofm->hard_timeout);
|
||||
flow->send_flow_exp = (ntohs(ofm->flags) & OFPFF_SEND_FLOW_EXP) ? 1 : 0;
|
||||
@@ -240,6 +254,7 @@ add_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
goto error_free_flow;
|
||||
} else if (error)
|
||||
goto error_free_flow;
|
||||
|
||||
error = 0;
|
||||
if (ntohl(ofm->buffer_id) != (uint32_t) -1) {
|
||||
struct sk_buff *skb = retrieve_skb(ntohl(ofm->buffer_id));
|
||||
@@ -269,27 +284,52 @@ mod_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
{
|
||||
int error = -ENOMEM;
|
||||
uint16_t v_code;
|
||||
size_t actions_len;
|
||||
struct sw_flow_key key;
|
||||
uint16_t priority;
|
||||
size_t actions_len = ntohs(ofm->header.length) - sizeof *ofm;
|
||||
struct sw_flow *flow;
|
||||
int strict;
|
||||
|
||||
flow_extract_match(&key, &ofm->match);
|
||||
/* Allocate memory. */
|
||||
flow = flow_alloc(actions_len,GFP_ATOMIC);
|
||||
if (flow == NULL)
|
||||
goto error;
|
||||
|
||||
actions_len = ntohs(ofm->header.length) - sizeof *ofm;
|
||||
flow_extract_match(&flow->key, &ofm->match);
|
||||
|
||||
v_code = validate_actions(chain->dp, &key, ofm->actions, actions_len);
|
||||
v_code = validate_actions(chain->dp, &flow->key, ofm->actions, actions_len);
|
||||
if (v_code != ACT_VALIDATION_OK) {
|
||||
dp_send_error_msg(chain->dp, sender, OFPET_BAD_ACTION, v_code,
|
||||
ofm, ntohs(ofm->header.length));
|
||||
goto error;
|
||||
goto error_free_flow;
|
||||
}
|
||||
|
||||
priority = key.wildcards ? ntohs(ofm->priority) : -1;
|
||||
flow->priority = flow->key.wildcards ? ntohs(ofm->priority) : -1;
|
||||
strict = (ofm->command == htons(OFPFC_MODIFY_STRICT)) ? 1 : 0;
|
||||
chain_modify(chain, &key, priority, strict, ofm->actions, actions_len,
|
||||
(ntohs(ofm->flags) & OFPFF_EMERG) ? 1 : 0);
|
||||
|
||||
/* First try to modify existing flows if any */
|
||||
/* if there is no matching flow, add it */
|
||||
if (!chain_modify(chain, &flow->key, flow->priority, strict,
|
||||
ofm->actions, actions_len,
|
||||
(ntohs(ofm->flags) & OFPFF_EMERG) ? 1 : 0)) {
|
||||
/* Fill out flow. */
|
||||
flow->idle_timeout = ntohs(ofm->idle_timeout);
|
||||
flow->hard_timeout = ntohs(ofm->hard_timeout);
|
||||
flow->send_flow_exp = (ntohs(ofm->flags) & OFPFF_SEND_FLOW_EXP)
|
||||
? 1 : 0;
|
||||
flow_setup_actions(flow, ofm->actions, actions_len);
|
||||
error = chain_insert(chain, flow,
|
||||
(ntohs(ofm->flags) & OFPFF_EMERG) ? 1 : 0);
|
||||
if (error == -ENOBUFS) {
|
||||
dp_send_error_msg(chain->dp, sender,
|
||||
OFPET_FLOW_MOD_FAILED,
|
||||
OFPFMFC_ALL_TABLES_FULL,
|
||||
ofm, ntohs(ofm->header.length));
|
||||
goto error_free_flow;
|
||||
} else if (error) {
|
||||
goto error_free_flow;
|
||||
}
|
||||
}
|
||||
|
||||
error = 0;
|
||||
if (ntohl(ofm->buffer_id) != (uint32_t) -1) {
|
||||
struct sk_buff *skb = retrieve_skb(ntohl(ofm->buffer_id));
|
||||
if (skb) {
|
||||
@@ -303,6 +343,8 @@ mod_flow(struct sw_chain *chain, const struct sender *sender,
|
||||
}
|
||||
return error;
|
||||
|
||||
error_free_flow:
|
||||
flow_free(flow);
|
||||
error:
|
||||
if (ntohl(ofm->buffer_id) != (uint32_t) -1)
|
||||
discard_skb(ntohl(ofm->buffer_id));
|
||||
|
||||
@@ -75,9 +75,11 @@ protection_callback(struct sw_flow *flow, void *private_)
|
||||
memset(&match, 0, sizeof(match));
|
||||
flow_fill_match(&match, &flow->key);
|
||||
flow_extract_match(&tgtflow->key, &match);
|
||||
/* Fill out flow. */
|
||||
tgtflow->priority = flow->priority;
|
||||
tgtflow->idle_timeout = 0;
|
||||
tgtflow->hard_timeout = 0;
|
||||
tgtflow->send_flow_exp = flow->send_flow_exp;
|
||||
flow_setup_actions(tgtflow, actions->actions, actions->actions_len);
|
||||
|
||||
error = chain_insert(private->chain, tgtflow, 0);
|
||||
|
||||
@@ -101,6 +101,34 @@ static int table_hash_modify(struct sw_table *swt,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int table_hash_has_conflict(struct sw_table *swt,
|
||||
const struct sw_flow_key *key,
|
||||
uint16_t priority, int strict)
|
||||
{
|
||||
struct sw_table_hash *th = (struct sw_table_hash *)swt;
|
||||
|
||||
if (key->wildcards == 0) {
|
||||
struct sw_flow **bucket = find_bucket(swt, key);
|
||||
struct sw_flow *flow = *bucket;
|
||||
if (flow && flow_matches_desc(&flow->key, key,strict)
|
||||
&& (flow->priority == priority)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i <= th->bucket_mask; i++) {
|
||||
struct sw_flow **bucket = &th->buckets[i];
|
||||
struct sw_flow *flow = *bucket;
|
||||
if (flow && flow_matches_desc(&flow->key, key, strict)
|
||||
&& (flow->priority == priority)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Caller must update n_flows. */
|
||||
static int do_delete(struct datapath *dp, struct sw_flow **bucket,
|
||||
struct sw_flow *flow, enum nx_flow_end_reason reason)
|
||||
@@ -252,6 +280,7 @@ struct sw_table *table_hash_create(unsigned int polynomial,
|
||||
swt = &th->swt;
|
||||
swt->lookup = table_hash_lookup;
|
||||
swt->insert = table_hash_insert;
|
||||
swt->has_conflict = table_hash_has_conflict;
|
||||
swt->delete = table_hash_delete;
|
||||
swt->timeout = table_hash_timeout;
|
||||
swt->destroy = table_hash_destroy;
|
||||
@@ -305,6 +334,15 @@ static int table_hash2_modify(struct sw_table *swt,
|
||||
actions, actions_len));
|
||||
}
|
||||
|
||||
static int table_hash2_has_conflict(struct sw_table *swt,
|
||||
const struct sw_flow_key *key,
|
||||
uint16_t priority, int strict)
|
||||
{
|
||||
struct sw_table_hash2 *t2 = (struct sw_table_hash2 *) swt;
|
||||
return (table_hash_has_conflict(t2->subtable[0], key, priority, strict) ||
|
||||
table_hash_has_conflict(t2->subtable[1], key, priority, strict));
|
||||
}
|
||||
|
||||
static int table_hash2_delete(struct datapath *dp, struct sw_table *swt,
|
||||
const struct sw_flow_key *key,
|
||||
uint16_t out_port,
|
||||
@@ -393,6 +431,7 @@ struct sw_table *table_hash2_create(unsigned int poly0, unsigned int buckets0,
|
||||
swt->lookup = table_hash2_lookup;
|
||||
swt->insert = table_hash2_insert;
|
||||
swt->modify = table_hash2_modify;
|
||||
swt->has_conflict = table_hash2_has_conflict;
|
||||
swt->delete = table_hash2_delete;
|
||||
swt->timeout = table_hash2_timeout;
|
||||
swt->destroy = table_hash2_destroy;
|
||||
|
||||
@@ -90,6 +90,21 @@ static int table_linear_modify(struct sw_table *swt,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int table_linear_has_conflict(struct sw_table *swt,
|
||||
const struct sw_flow_key *key, uint16_t priority, int strict)
|
||||
{
|
||||
struct sw_table_linear *tl = (struct sw_table_linear *) swt;
|
||||
struct sw_flow *flow;
|
||||
|
||||
list_for_each_entry (flow, &tl->flows, node) {
|
||||
if (flow_matches_desc(&flow->key, key, strict)
|
||||
&& (flow->priority == priority)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int do_delete(struct datapath *dp, struct sw_table *swt,
|
||||
struct sw_flow *flow, enum nx_flow_end_reason reason)
|
||||
{
|
||||
@@ -201,6 +216,7 @@ struct sw_table *table_linear_create(unsigned int max_flows)
|
||||
swt->lookup = table_linear_lookup;
|
||||
swt->insert = table_linear_insert;
|
||||
swt->modify = table_linear_modify;
|
||||
swt->has_conflict = table_linear_has_conflict;
|
||||
swt->delete = table_linear_delete;
|
||||
swt->timeout = table_linear_timeout;
|
||||
swt->destroy = table_linear_destroy;
|
||||
|
||||
@@ -64,6 +64,12 @@ struct sw_table {
|
||||
uint16_t priority, int strict,
|
||||
const struct ofp_action_header *actions, size_t actions_len);
|
||||
|
||||
/* Checks whether 'table' has an equal priotiry entry of thethat conflicts
|
||||
* with 'key'. If 'strict' is set, wildcards must match.
|
||||
* Returns the number of flows that were modified. */
|
||||
int (*has_conflict)(struct sw_table *table, const struct sw_flow_key *key,
|
||||
uint16_t priority, int strict);
|
||||
|
||||
/* Deletes from 'table' any and all flows that match 'key' from
|
||||
* 'table'. If 'out_port' is not OFPP_NONE, then matching entries
|
||||
* must have that port as an argument for an output action. If
|
||||
|
||||
Reference in new issue
Block a user