From 44e9d4f5fc16653bd04259a7793199877d331f7b Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Sat, 26 Apr 2008 14:27:32 -0700 Subject: [PATCH] Clean-up related to supporting priorities...mostly suggestions from Ben. --- include/openflow.h | 3 +++ switch/table-linear.c | 6 ++---- utilities/dpctl.c | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/openflow.h b/include/openflow.h index 836c03a4..5c1a6e2d 100644 --- a/include/openflow.h +++ b/include/openflow.h @@ -329,6 +329,9 @@ struct ofp_match { /* Value used in "max_idle" to indicate that the entry is permanent */ #define OFP_FLOW_PERMANENT 0 +/* By default, choose a priority in the middle */ +#define OFP_DEFAULT_PRIORITY 0x8000 + /* Flow setup and teardown (controller -> datapath). */ struct ofp_flow_mod { struct ofp_header header; diff --git a/switch/table-linear.c b/switch/table-linear.c index 6da93a23..dc1f7e70 100644 --- a/switch/table-linear.c +++ b/switch/table-linear.c @@ -87,10 +87,8 @@ static int table_linear_insert(struct sw_table *swt, struct sw_flow *flow) tl->n_flows++; /* Insert the entry immediately in front of where we're pointing. */ - if (f) - list_push_back(&f->node, &flow->node); - else - list_push_back(&tl->flows, &flow->node); + list_push_back(&f->node, &flow->node); + return 1; } diff --git a/utilities/dpctl.c b/utilities/dpctl.c index c3fe8cd6..4b3e03af 100644 --- a/utilities/dpctl.c +++ b/utilities/dpctl.c @@ -487,6 +487,9 @@ str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action, if (table_idx) { *table_idx = 0xff; } + if (priority) { + *priority = OFP_DEFAULT_PRIORITY; + } memset(match, 0, sizeof *match); wildcards = OFPFW_ALL; for (name = strtok(string, "="), value = strtok(NULL, " \t\n"); @@ -589,7 +592,7 @@ static void do_add_flows(int argc, char *argv[]) while (fgets(line, sizeof line, file)) { struct buffer *buffer; struct ofp_flow_mod *ofm; - uint16_t priority=0; + uint16_t priority; size_t size; char *comment; @@ -608,12 +611,13 @@ static void do_add_flows(int argc, char *argv[]) /* Parse and send. */ size = sizeof *ofm + sizeof ofm->actions[0]; ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer); + str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority); ofm->command = htons(OFPFC_ADD); ofm->max_idle = htons(50); ofm->buffer_id = htonl(UINT32_MAX); ofm->group_id = htonl(0); - str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority); ofm->priority = htons(priority); + ofm->reserved = htonl(0); send_openflow_buffer(vconn, buffer); } @@ -635,10 +639,11 @@ static void do_del_flows(int argc, char *argv[]) size = sizeof *ofm; ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer); ofm->command = htons(OFPFC_DELETE); - ofm->max_idle = 0; + ofm->max_idle = htons(0); ofm->buffer_id = htonl(UINT32_MAX); - ofm->group_id = 0; - ofm->priority = 0; + ofm->group_id = htonl(0); + ofm->priority = htons(0); + ofm->reserved = htonl(0); str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, NULL); send_openflow_buffer(vconn, buffer); -- 2.30.2