Bring manpages and usage messages up-to-date.
[openvswitch] / utilities / dpctl.c
index 9bc50ca0c54b395f4175473cee385f439096e1d0..2d09e98e0aa1d04c702b03fac47a621cde84f0e9 100644 (file)
@@ -171,12 +171,15 @@ usage(void)
            "  dump-ports SWITCH           print port statistics\n"
            "  dump-flows SWITCH           print all flow entries\n"
            "  dump-flows SWITCH FLOW      print matching FLOWs\n"
+           "  dump-aggregate SWITCH       print aggregate flow statistics\n"
+           "  dump-aggregate SWITCH FLOW  print aggregate stats for FLOWs\n"
            "  add-flows SWITCH FILE       add flows from FILE\n"
            "  del-flows SWITCH FLOW       delete matching FLOWs\n"
            "where each SWITCH is an active OpenFlow connection method.\n",
            program_name, program_name);
     vconn_usage(true, false);
     printf("\nOptions:\n"
+           "  -v, --verbose=MODULE:FACILITY:LEVEL  configure logging levels\n"
            "  -v, --verbose               set maximum verbosity level\n"
            "  -h, --help                  display this help message\n"
            "  -V, --version               display version information\n");
@@ -344,6 +347,17 @@ alloc_openflow_buffer(size_t openflow_len, uint8_t type,
        return oh;
 }
 
+static void *
+alloc_stats_request(size_t body_len, uint16_t type, struct buffer **bufferp)
+{
+    struct ofp_stats_request *rq;
+    rq = alloc_openflow_buffer((offsetof(struct ofp_stats_request, body)
+                                + body_len), OFPT_STATS_REQUEST, bufferp);
+    rq->type = htons(type);
+    rq->flags = htons(0);
+    return rq->body;
+}
+
 static void
 send_openflow_buffer(struct vconn *vconn, struct buffer *buffer)
 {
@@ -378,30 +392,76 @@ transact_openflow(struct vconn *vconn, struct buffer *request)
 }
 
 static void
-dump_transaction(const char *vconn_name, uint8_t request_type)
+dump_transaction(const char *vconn_name, struct buffer *request)
 {
     struct vconn *vconn;
-    struct buffer *request, *reply;
+    struct buffer *reply;
 
     run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
-    alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
     reply = transact_openflow(vconn, request);
     ofp_print(stdout, reply->data, reply->size, 1);
     vconn_close(vconn);
 }
 
+static void
+dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
+{
+    struct buffer *request;
+    alloc_openflow_buffer(sizeof(struct ofp_header), request_type, &request);
+    dump_transaction(vconn_name, request);
+}
+
+static void
+dump_stats_transaction(const char *vconn_name, struct buffer *request)
+{
+    uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
+    struct vconn *vconn;
+    bool done = false;
+
+    run(vconn_open_block(vconn_name, &vconn), "connecting to %s", vconn_name);
+    send_openflow_buffer(vconn, request);
+    while (!done) {
+        uint32_t recv_xid;
+        struct buffer *reply;
+
+        run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
+        recv_xid = ((struct ofp_header *) reply->data)->xid;
+        if (send_xid == recv_xid) {
+            struct ofp_stats_reply *osr;
+
+            ofp_print(stdout, reply->data, reply->size, 1);
+
+            osr = buffer_at(reply, 0, sizeof *osr);
+            done = !osr || !(ntohs(osr->flags) & OFPSF_REPLY_MORE);
+        } else {
+            VLOG_DBG("received reply with xid %08"PRIx32" "
+                     "!= expected %08"PRIx32, recv_xid, send_xid);
+        }
+        buffer_delete(reply);
+    }
+    vconn_close(vconn);
+}
+
+static void
+dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
+{
+    struct buffer *request;
+    alloc_stats_request(0, stats_type, &request);
+    dump_stats_transaction(vconn_name, request);
+}
+
 static void
 do_show(int argc UNUSED, char *argv[])
 {
-    dump_transaction(argv[1], OFPT_FEATURES_REQUEST);
-    dump_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
+    dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
+    dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
 }
 
 
 static void
 do_dump_tables(int argc, char *argv[])
 {
-    dump_transaction(argv[1], OFPT_TABLE_STATS_REQUEST);
+    dump_trivial_stats_transaction(argv[1], OFPST_TABLE);
 }
 
 
@@ -442,10 +502,16 @@ str_to_action(const char *str, struct ofp_action *action)
 {
     uint16_t port;
 
-    if (!strcasecmp(str, "flood")) {
+    if (!strcasecmp(str, "normal")) {
+        port = OFPP_NORMAL;
+    } else if (!strcasecmp(str, "flood")) {
         port = OFPP_FLOOD;
+    } else if (!strcasecmp(str, "all")) {
+        port = OFPP_ALL;
     } else if (!strcasecmp(str, "controller")) {
         port = OFPP_CONTROLLER;
+    } else if (!strcasecmp(str, "local")) {
+        port = OFPP_LOCAL;
     } else {
         port = str_to_int(str);
     }
@@ -492,9 +558,9 @@ str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
     }
     memset(match, 0, sizeof *match);
     wildcards = OFPFW_ALL;
-    for (name = strtok(string, "="), value = strtok(NULL, " \t\n");
+    for (name = strtok(string, "="), value = strtok(NULL, ", \t\r\n");
          name && value;
-         name = strtok(NULL, "="), value = strtok(NULL, " \t\n"))
+         name = strtok(NULL, "="), value = strtok(NULL, ", \t\r\n"))
     {
         const struct field *f;
         void *data;
@@ -533,7 +599,7 @@ str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
 
     found:
         data = (char *) match + f->offset;
-        if (!strcmp(value, "*")) {
+        if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
             wildcards |= f->wildcard;
         } else {
             wildcards &= ~f->wildcard;
@@ -561,46 +627,28 @@ str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
 
 static void do_dump_flows(int argc, char *argv[])
 {
-    struct vconn *vconn;
-    struct buffer *request;
     struct ofp_flow_stats_request *req;
-    uint32_t send_xid;
-    bool done = false;
+    struct buffer *request;
 
-    run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
-    req = alloc_openflow_buffer(sizeof *req, OFPT_FLOW_STATS_REQUEST,
-                                &request);
+    req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
     str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id, 
             NULL);
-    req->type = OFPFS_INDIV;
-    req->pad = 0;
+    memset(req->pad, 0, sizeof req->pad);
 
-    send_xid = ((struct ofp_header *) request->data)->xid;
-    send_openflow_buffer(vconn, request);
-    while (!done) {
-        uint32_t recv_xid;
-        struct buffer *reply;
+    dump_stats_transaction(argv[1], request);
+}
 
-        run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
-        recv_xid = ((struct ofp_header *) reply->data)->xid;
-        if (send_xid == recv_xid) {
-            struct ofp_flow_stats_reply *rpy;
+static void do_dump_aggregate(int argc, char *argv[])
+{
+    struct ofp_aggregate_stats_request *req;
+    struct buffer *request;
 
-            ofp_print(stdout, reply->data, reply->size, 1);
+    req = alloc_stats_request(sizeof *req, OFPST_AGGREGATE, &request);
+    str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id,
+                NULL);
+    memset(req->pad, 0, sizeof req->pad);
 
-            rpy = buffer_at(reply, 0, sizeof *rpy);
-            done = (!rpy
-                    || rpy->header.version != OFP_VERSION
-                    || rpy->header.type != OFPT_FLOW_STATS_REPLY
-                    || (ntohs(rpy->header.length)
-                        < sizeof rpy->header + sizeof *rpy->flows));
-        } else {
-            VLOG_DBG("received reply with xid %08"PRIx32" "
-                     "!= expected %08"PRIx32, recv_xid, send_xid);
-        }
-        buffer_delete(reply);
-    }
-    vconn_close(vconn);
+    dump_stats_transaction(argv[1], request);
 }
 
 static void do_add_flows(int argc, char *argv[])
@@ -642,7 +690,6 @@ static void do_add_flows(int argc, char *argv[])
         ofm->command = htons(OFPFC_ADD);
         ofm->max_idle = htons(50);
         ofm->buffer_id = htonl(UINT32_MAX);
-        ofm->group_id = htonl(0);
         ofm->priority = htons(priority);
         ofm->reserved = htonl(0);
 
@@ -655,6 +702,7 @@ static void do_add_flows(int argc, char *argv[])
 static void do_del_flows(int argc, char *argv[])
 {
     struct vconn *vconn;
+    uint16_t priority;
 
     run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
     struct buffer *buffer;
@@ -665,13 +713,12 @@ static void do_del_flows(int argc, char *argv[])
     /* Parse and send. */
     size = sizeof *ofm;
     ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
+    str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, &priority);
     ofm->command = htons(OFPFC_DELETE);
     ofm->max_idle = htons(0);
     ofm->buffer_id = htonl(UINT32_MAX);
-    ofm->group_id = htonl(0);
-    ofm->priority = htons(0);
+    ofm->priority = htons(priority);
     ofm->reserved = htonl(0);
-    str_to_flow(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, NULL);
 
     send_openflow_buffer(vconn, buffer);
 
@@ -681,7 +728,7 @@ static void do_del_flows(int argc, char *argv[])
 static void
 do_dump_ports(int argc, char *argv[])
 {
-    dump_transaction(argv[1], OFPT_PORT_STATS_REQUEST);
+    dump_trivial_stats_transaction(argv[1], OFPST_PORT);
 }
 
 static void do_help(int argc UNUSED, char *argv[] UNUSED)
@@ -704,6 +751,7 @@ static struct command all_commands[] = {
     { "monitor", 1, 1, do_monitor },
     { "dump-tables", 1, 1, do_dump_tables },
     { "dump-flows", 1, 2, do_dump_flows },
+    { "dump-aggregate", 1, 2, do_dump_aggregate },
     { "add-flows", 2, 2, do_add_flows },
     { "del-flows", 1, 2, do_del_flows },
     { "dump-ports", 1, 1, do_dump_ports },