Skip to content

Commit

Permalink
ofp-print: Support printing of (draft) OpenFlow 1.5 group messages wi…
Browse files Browse the repository at this point in the history
…th bucket actions

ONF-JIRA: EXT-350
Signed-off-by: Simon Horman <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
shorman-netronome authored and blp committed Nov 11, 2014
1 parent 1c4c05a commit 76c4120
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 13 deletions.
50 changes: 39 additions & 11 deletions lib/ofp-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,14 +2110,14 @@ ofp_header_to_string__(const struct ofp_header *oh, enum ofpraw raw,
}

static void
ofp_print_bucket_id(struct ds *s, uint32_t bucket_id,
ofp_print_bucket_id(struct ds *s, const char *label, uint32_t bucket_id,
enum ofp_version ofp_version)
{
if (ofp_version < OFP15_VERSION) {
return;
}

ds_put_cstr(s, "bucket_id:");
ds_put_cstr(s, label);

switch (bucket_id) {
case OFPG15_BUCKET_FIRST:
Expand All @@ -2139,22 +2139,29 @@ ofp_print_bucket_id(struct ds *s, uint32_t bucket_id,

static void
ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,
struct list *p_buckets, enum ofp_version ofp_version)
struct list *p_buckets, enum ofp_version ofp_version,
bool suppress_type)
{
static const char *type_str[] = { "all", "select", "indirect",
"ff", "unknown" };
struct ofputil_bucket *bucket;

ds_put_format(s, "group_id=%"PRIu32",type=%s",
group_id, type_str[type > 4 ? 4 : type]);
ds_put_format(s, "group_id=%"PRIu32, group_id);

if (!suppress_type) {
static const char *type_str[] = { "all", "select", "indirect",
"ff", "unknown" };
ds_put_format(s, ",type=%s", type_str[type > 4 ? 4 : type]);
}

if (!p_buckets) {
return;
}

ds_put_char(s, ',');

LIST_FOR_EACH (bucket, list_node, p_buckets) {
ds_put_cstr(s, ",bucket=");
ds_put_cstr(s, "bucket=");

ofp_print_bucket_id(s, bucket->bucket_id, ofp_version);
ofp_print_bucket_id(s, "bucket_id:", bucket->bucket_id, ofp_version);
if (bucket->weight != 1) {
ds_put_format(s, "weight:%"PRIu16",", bucket->weight);
}
Expand All @@ -2167,7 +2174,10 @@ ofp_print_group(struct ds *s, uint32_t group_id, uint8_t type,

ds_put_cstr(s, "actions=");
ofpacts_format(bucket->ofpacts, bucket->ofpacts_len, s);
ds_put_char(s, ',');
}

ds_chomp(s, ',');
}

static void
Expand Down Expand Up @@ -2199,7 +2209,8 @@ ofp_print_group_desc(struct ds *s, const struct ofp_header *oh)

ds_put_char(s, '\n');
ds_put_char(s, ' ');
ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, oh->version);
ofp_print_group(s, gd.group_id, gd.type, &gd.buckets, oh->version,
false);
ofputil_bucket_list_destroy(&gd.buckets);
}
}
Expand Down Expand Up @@ -2308,6 +2319,7 @@ ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
{
struct ofputil_group_mod gm;
int error;
bool bucket_command = false;

error = ofputil_decode_group_mod(oh, &gm);
if (error) {
Expand All @@ -2331,12 +2343,28 @@ ofp_print_group_mod(struct ds *s, const struct ofp_header *oh)
ds_put_cstr(s, "DEL");
break;

case OFPGC15_INSERT_BUCKET:
ds_put_cstr(s, "INSERT_BUCKET");
bucket_command = true;
break;

case OFPGC15_REMOVE_BUCKET:
ds_put_cstr(s, "REMOVE_BUCKET");
bucket_command = true;
break;

default:
ds_put_format(s, "cmd:%"PRIu16"", gm.command);
}
ds_put_char(s, ' ');

ofp_print_group(s, gm.group_id, gm.type, &gm.buckets, oh->version);
if (bucket_command) {
ofp_print_bucket_id(s, "command_bucket_id:",
gm.command_bucket_id, oh->version);
}

ofp_print_group(s, gm.group_id, gm.type, &gm.buckets, oh->version,
bucket_command);
ofputil_bucket_list_destroy(&gm.buckets);
}

Expand Down
60 changes: 58 additions & 2 deletions tests/ofp-print.at
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ AT_CHECK([ovs-ofctl ofp-print "\
])
AT_CLEANUP

AT_SETUP([OFPST_GROUP_DESC reply])
AT_SETUP([OFPST_GROUP_DESC reply - OF1.1])
AT_KEYWORDS([ofp-print OFPT_STATS_REQUEST])
AT_CHECK([ovs-ofctl ofp-print "\
02 13 00 78 00 00 00 02 00 07 00 00 00 00 00 00 \
Expand All @@ -1976,6 +1976,26 @@ OFPST_GROUP_DESC reply (OF1.1) (xid=0x2):
])
AT_CLEANUP

AT_SETUP([OFPST_GROUP_DESC reply - OF1.5])
AT_KEYWORDS([ofp-print OFPT_STATS_REPLY])
AT_CHECK([ovs-ofctl ofp-print "\
06 13 00 98 00 00 00 02 00 07 00 00 00 00 00 00 \
00 88 01 00 00 00 20 00 00 78 00 00 00 00 00 00 \
00 28 00 10 00 00 00 00 00 00 00 10 00 00 00 01 \
00 00 00 00 00 00 00 00 00 00 00 08 00 64 00 00 \
00 01 00 08 00 00 00 01 \
00 28 00 10 00 00 00 01 00 00 00 10 00 00 00 02 \
00 00 00 00 00 00 00 00 00 00 00 08 00 c8 00 00 \
00 01 00 08 00 00 00 02 \
00 28 00 10 00 00 00 02 00 00 00 10 00 00 00 03 \
00 00 00 00 00 00 00 00 00 00 00 08 00 c8 00 00 \
00 01 00 08 00 00 00 03 \
"], [0], [dnl
OFPST_GROUP_DESC reply (OF1.5) (xid=0x2):
group_id=8192,type=select,bucket=bucket_id:0,weight:100,watch_port:1,actions=output:1,bucket=bucket_id:1,weight:200,watch_port:2,actions=output:2,bucket=bucket_id:2,weight:200,watch_port:3,actions=output:3
])
AT_CLEANUP

AT_SETUP([OFPST_GROUP_FEATURES request])
AT_KEYWORDS([ofp-print OFPT_STATS_REQUEST])
AT_CHECK([ovs-ofctl ofp-print "\
Expand Down Expand Up @@ -2759,7 +2779,7 @@ NXT_FLOW_MOD (xid=0x2): ADD NXM_NX_TUN_ID(00000000000001c8), NXM_NX_REG0(0000007
])
AT_CLEANUP

AT_SETUP([OFPT_GROUP_MOD])
AT_SETUP([OFPT_GROUP_MOD - OF1.1])
AT_KEYWORDS([ofp-print])
AT_CHECK([ovs-ofctl ofp-print "\
02 0f 00 70 11 22 33 44 00 00 01 00 87 65 43 21 \
Expand All @@ -2775,6 +2795,42 @@ OFPT_GROUP_MOD (OF1.1) (xid=0x11223344):
])
AT_CLEANUP

AT_SETUP([OFPT_GROUP_MOD add - OF1.5])
AT_KEYWORDS([ofp-print])
AT_CHECK([ovs-ofctl ofp-print "\
06 0f 00 90 11 22 33 44 00 00 01 00 87 65 43 21 \
00 78 00 00 ff ff ff ff 00 28 00 10 00 00 00 00 \
00 00 00 10 00 00 00 01 00 00 00 00 00 00 00 00 \
00 00 00 08 00 64 00 00 00 01 00 08 00 00 00 01 \
00 28 00 10 00 00 00 01 00 00 00 10 00 00 00 02 \
00 00 00 00 00 00 00 00 00 00 00 08 00 c8 00 00 \
00 01 00 08 00 00 00 02 00 28 00 10 00 00 00 02 \
00 00 00 10 00 00 00 03 00 00 00 00 00 00 00 00 \
00 00 00 08 00 c8 00 00 00 01 00 08 00 00 00 03 \
"], [0], [dnl
OFPT_GROUP_MOD (OF1.5) (xid=0x11223344):
ADD group_id=2271560481,type=select,bucket=bucket_id:0,weight:100,watch_port:1,actions=output:1,bucket=bucket_id:1,weight:200,watch_port:2,actions=output:2,bucket=bucket_id:2,weight:200,watch_port:3,actions=output:3
])
AT_CLEANUP

AT_SETUP([OFPT_GROUP_MOD insert bucket - OF1.5])
AT_KEYWORDS([ofp-print])
AT_CHECK([ovs-ofctl ofp-print "\
06 0f 00 90 11 22 33 44 00 03 01 00 87 65 43 21 \
00 78 00 00 ff ff ff fd 00 28 00 10 00 00 00 00 \
00 00 00 10 00 00 00 01 00 00 00 00 00 00 00 00 \
00 00 00 08 00 64 00 00 00 01 00 08 00 00 00 01 \
00 28 00 10 00 00 00 01 00 00 00 10 00 00 00 02 \
00 00 00 00 00 00 00 00 00 00 00 08 00 c8 00 00 \
00 01 00 08 00 00 00 02 00 28 00 10 00 00 00 02 \
00 00 00 10 00 00 00 03 00 00 00 00 00 00 00 00 \
00 00 00 08 00 c8 00 00 00 01 00 08 00 00 00 03 \
"], [0], [dnl
OFPT_GROUP_MOD (OF1.5) (xid=0x11223344):
INSERT_BUCKET command_bucket_id:first,group_id=2271560481,bucket=bucket_id:0,weight:100,watch_port:1,actions=output:1,bucket=bucket_id:1,weight:200,watch_port:2,actions=output:2,bucket=bucket_id:2,weight:200,watch_port:3,actions=output:3
])
AT_CLEANUP

AT_SETUP([NXT_FLOW_REMOVED])
AT_KEYWORDS([ofp-print])
AT_CHECK([ovs-ofctl ofp-print "\
Expand Down

0 comments on commit 76c4120

Please sign in to comment.