[ovs-dev] [PATCH] ofctl: Adding support for table ID in add-flow, add-flows, mod-flows and del-flows.
Hao Zheng
hzheng at nicira.com
Fri Jul 30 06:29:50 UTC 2010
Now for add-flow, add-flows, mod-flows and del-flows commands of ovs-ofctl command, user can specify on which table these commands modify flows. The is accomplished by adding "table=table_id" to your flow description. Note: currently Open vSwitch only supports up to 32 tables, so a valid table_id should be in the range of 0 to 31. If "table=table_id" is not specified as part of the flow description, then these commands behave like before.
---
utilities/ovs-ofctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index ac8fdb7..6ed82a2 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -830,6 +830,9 @@ str_to_flow(char *string, struct ofp_match *match, struct ofpbuf *actions,
if (table_idx && !strcmp(name, "table")) {
*table_idx = atoi(value);
+ if (*table_idx < 0 || *table_idx > 31) {
+ ovs_fatal(0, "table %s is invalid, must be between 0 and 31", value);
+ }
} else if (out_port && !strcmp(name, "out_port")) {
*out_port = atoi(value);
} else if (priority && !strcmp(name, "priority")) {
@@ -916,6 +919,21 @@ do_dump_aggregate(int argc, char *argv[])
}
static void
+enable_flow_mod_table_id_ext(struct vconn *vconn, uint8_t enable)
+{
+ struct nxt_flow_mod_table_id *flow_mod_table_id;
+ struct ofpbuf *buffer;
+
+ flow_mod_table_id = make_openflow(sizeof *flow_mod_table_id, OFPT_VENDOR, &buffer);
+
+ flow_mod_table_id->vendor = htonl(NX_VENDOR_ID);
+ flow_mod_table_id->subtype = htonl(NXT_FLOW_MOD_TABLE_ID);
+ flow_mod_table_id->set = enable;
+
+ send_openflow_buffer(vconn, buffer);
+}
+
+static void
do_add_flow(int argc OVS_UNUSED, char *argv[])
{
struct vconn *vconn;
@@ -924,12 +942,13 @@ do_add_flow(int argc OVS_UNUSED, char *argv[])
uint16_t priority, idle_timeout, hard_timeout;
uint64_t cookie;
struct ofp_match match;
+ uint8_t table_idx;
/* Parse and send. str_to_flow() will expand and reallocate the data in
* 'buffer', so we can't keep pointers to across the str_to_flow() call. */
make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
str_to_flow(argv[2], &match, buffer,
- NULL, NULL, &priority, &idle_timeout, &hard_timeout,
+ &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
&cookie);
ofm = buffer->data;
ofm->match = match;
@@ -941,6 +960,12 @@ do_add_flow(int argc OVS_UNUSED, char *argv[])
ofm->priority = htons(priority);
open_vconn(argv[1], &vconn);
+ if (table_idx != 0xff) {
+ enable_flow_mod_table_id_ext(vconn, 1);
+ ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
+ } else {
+ enable_flow_mod_table_id_ext(vconn, 0);
+ }
send_openflow_buffer(vconn, buffer);
vconn_close(vconn);
}
@@ -951,6 +976,7 @@ do_add_flows(int argc OVS_UNUSED, char *argv[])
struct vconn *vconn;
FILE *file;
char line[1024];
+ uint8_t table_idx;
file = fopen(argv[2], "r");
if (file == NULL) {
@@ -983,7 +1009,7 @@ do_add_flows(int argc OVS_UNUSED, char *argv[])
* call. */
make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
str_to_flow(line, &match, buffer,
- NULL, NULL, &priority, &idle_timeout, &hard_timeout,
+ &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
&cookie);
ofm = buffer->data;
ofm->match = match;
@@ -994,6 +1020,12 @@ do_add_flows(int argc OVS_UNUSED, char *argv[])
ofm->buffer_id = htonl(UINT32_MAX);
ofm->priority = htons(priority);
+ if (table_idx != 0xff) {
+ enable_flow_mod_table_id_ext(vconn, 1);
+ ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
+ } else {
+ enable_flow_mod_table_id_ext(vconn, 0);
+ }
send_openflow_buffer(vconn, buffer);
}
vconn_close(vconn);
@@ -1009,12 +1041,13 @@ do_mod_flows(int argc OVS_UNUSED, char *argv[])
struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
struct ofp_match match;
+ uint8_t table_idx;
/* Parse and send. str_to_flow() will expand and reallocate the data in
* 'buffer', so we can't keep pointers to across the str_to_flow() call. */
make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
str_to_flow(argv[2], &match, buffer,
- NULL, NULL, &priority, &idle_timeout, &hard_timeout,
+ &table_idx, NULL, &priority, &idle_timeout, &hard_timeout,
&cookie);
ofm = buffer->data;
ofm->match = match;
@@ -1030,6 +1063,12 @@ do_mod_flows(int argc OVS_UNUSED, char *argv[])
ofm->priority = htons(priority);
open_vconn(argv[1], &vconn);
+ if (table_idx != 0xff) {
+ enable_flow_mod_table_id_ext(vconn, 1);
+ ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
+ } else {
+ enable_flow_mod_table_id_ext(vconn, 0);
+ }
send_openflow_buffer(vconn, buffer);
vconn_close(vconn);
}
@@ -1041,6 +1080,7 @@ static void do_del_flows(int argc, char *argv[])
uint16_t out_port;
struct ofpbuf *buffer;
struct ofp_flow_mod *ofm;
+ uint8_t table_idx;
/* Parse and send. */
ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer);
@@ -1058,6 +1098,12 @@ static void do_del_flows(int argc, char *argv[])
ofm->priority = htons(priority);
open_vconn(argv[1], &vconn);
+ if (table_idx != 0xff) {
+ enable_flow_mod_table_id_ext(vconn, 1);
+ ofm->command = htons(ntohs(ofm->command) | (table_idx << 8));
+ } else {
+ enable_flow_mod_table_id_ext(vconn, 0);
+ }
send_openflow_buffer(vconn, buffer);
vconn_close(vconn);
}
--
1.7.1
More information about the dev
mailing list