ovs-ofctl: Allow setting cookie as a decimal or hex value
authorJustin Pettit <jpettit@nicira.com>
Sat, 10 Apr 2010 08:09:08 +0000 (01:09 -0700)
committerJustin Pettit <jpettit@nicira.com>
Mon, 12 Apr 2010 09:46:12 +0000 (02:46 -0700)
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
utilities/ovs-ofctl.8.in
utilities/ovs-ofctl.c

index f642531..937eb15 100644 (file)
@@ -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, ", 
index da2ecd9..948df51 100644 (file)
@@ -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:
 .
index 0c977c7..360f881 100644 (file)
@@ -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")) {