From: Justin Pettit Date: Sat, 10 Apr 2010 08:09:08 +0000 (-0700) Subject: ovs-ofctl: Allow setting cookie as a decimal or hex value X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cce2125eea6e800bfe501916aac313880b751a7;p=openvswitch 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. --- diff --git a/lib/ofp-print.c b/lib/ofp-print.c index f6425318..937eb15d 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 da2ecd93..948df51d 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 0c977c79..360f881e 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")) {