From 8cce2125eea6e800bfe501916aac313880b751a7 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Sat, 10 Apr 2010 01:09:08 -0700 Subject: [PATCH] ovs-ofctl: Allow setting cookie as a decimal or hex value Clean-up a few items related to flow cookies: - Allow setting the flow cookie as a hex or decimal string - Consistently print the cookie in hex - Document the ability to set the flow cookie in ovs-ofctl. --- lib/ofp-print.c | 6 +++--- utilities/ovs-ofctl.8.in | 10 ++++++++++ utilities/ovs-ofctl.c | 16 +++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index f6425318c..937eb15d8 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -743,7 +743,7 @@ ofp_print_flow_mod(struct ds *string, const void *oh, size_t len, default: ds_put_format(string, " cmd:%d ", ntohs(ofm->command)); } - ds_put_format(string, "cookie:%"PRIx64" idle:%d hard:%d pri:%d " + ds_put_format(string, "cookie:0x%"PRIx64" idle:%d hard:%d pri:%d " "buf:%#x flags:%"PRIx16" ", ntohll(ofm->cookie), ntohs(ofm->idle_timeout), ntohs(ofm->hard_timeout), ofm->match.wildcards ? ntohs(ofm->priority) : (uint16_t)-1, @@ -778,7 +778,7 @@ ofp_print_flow_removed(struct ds *string, const void *oh, break; } ds_put_format(string, - " cookie%"PRIx64" pri%"PRIu16" secs%"PRIu32" nsecs%"PRIu32 + " cookie0x%"PRIx64" pri%"PRIu16" secs%"PRIu32" nsecs%"PRIu32 " idle%"PRIu16" pkts%"PRIu64" bytes%"PRIu64"\n", ntohll(ofr->cookie), ofr->match.wildcards ? ntohs(ofr->priority) : (uint16_t)-1, @@ -1000,7 +1000,7 @@ ofp_flow_stats_reply(struct ds *string, const void *body_, size_t len, break; } - ds_put_format(string, " cookie=%"PRIu64", ", ntohll(fs->cookie)); + ds_put_format(string, " cookie=0x%"PRIx64", ", ntohll(fs->cookie)); ds_put_format(string, "duration_sec=%"PRIu32"s, ", ntohl(fs->duration_sec)); ds_put_format(string, "duration_nsec=%"PRIu32"ns, ", diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index da2ecd933..948df51d7 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -407,6 +407,16 @@ only known to be implemented by Open vSwitch. not yet expose to the user.) . .PP +The \fBadd\-flow\fR, \fBadd\-flows\fR, and \fBmod\-flows\fR commands +support an additional optional field: +. +.IP \fBcookie=\fIvalue\fR +. +A cookie is an opaque identifier that can be associated with the flow. +\fIvalue\fR can be any 64-bit number and need not be unique among +flows. +. +.PP The \fBadd-flow\fR, \fBadd-flows\fR, and \fBdel-flows\fR commands support an additional optional field: . diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 0c977c790..360f881ed 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -405,6 +405,20 @@ str_to_u32(const char *str) return value; } +static uint64_t +str_to_u64(const char *str) +{ + char *tail; + uint64_t value; + + errno = 0; + value = strtoull(str, &tail, 0); + if (errno == EINVAL || errno == ERANGE || *tail) { + ovs_fatal(0, "invalid numeric format %s", str); + } + return value; +} + static void str_to_mac(const char *str, uint8_t mac[6]) { @@ -810,7 +824,7 @@ str_to_flow(char *string, struct ofp_match *match, struct ofpbuf *actions, } else if (hard_timeout && !strcmp(name, "hard_timeout")) { *hard_timeout = atoi(value); } else if (cookie && !strcmp(name, "cookie")) { - *cookie = atoi(value); + *cookie = str_to_u64(value); } else if (parse_field(name, &f)) { void *data = (char *) match + f->offset; if (!strcmp(value, "*") || !strcmp(value, "ANY")) { -- 2.43.0