Bring manpages and usage messages up-to-date.
[sliver-openvswitch.git] / utilities / dpctl.c
index ac77018..2d09e98 100644 (file)
@@ -171,11 +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");
@@ -261,7 +265,7 @@ static void do_del_port(int argc UNUSED, char *argv[])
 static void do_monitor(int argc UNUSED, char *argv[])
 {
     struct dpif dp;
-    open_nl_vconn(argv[1], false, &dp);
+    open_nl_vconn(argv[1], true, &dp);
     for (;;) {
         struct buffer *b;
         run(dpif_recv_openflow(&dp, &b, true), "dpif_recv_openflow");
@@ -343,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)
 {
@@ -377,29 +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_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);
 }
 
 
@@ -440,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);
     }
@@ -485,11 +553,14 @@ str_to_flow(char *string, struct ofp_match *match, struct ofp_action *action,
     if (table_idx) {
         *table_idx = 0xff;
     }
+    if (priority) {
+        *priority = OFP_DEFAULT_PRIORITY;
+    }
     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;
@@ -528,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;
@@ -556,18 +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, *reply;
-    struct ofp_flow_stats_request *fsr;
+    struct ofp_flow_stats_request *req;
+    struct buffer *request;
 
-    run(vconn_open_block(argv[1], &vconn), "connecting to %s", argv[1]);
-    fsr = alloc_openflow_buffer(sizeof *fsr, OFPT_FLOW_STATS_REQUEST, &request);
-    str_to_flow(argc > 2 ? argv[2] : "", &fsr->match, NULL, &fsr->table_id, NULL);
-    fsr->type = OFPFS_INDIV;
-    fsr->pad = 0;
-    reply = transact_openflow(vconn, request);
-    ofp_print(stdout, reply->data, reply->size, 1);
-    vconn_close(vconn);
+    req = alloc_stats_request(sizeof *req, OFPST_FLOW, &request);
+    str_to_flow(argc > 2 ? argv[2] : "", &req->match, NULL, &req->table_id, 
+            NULL);
+    memset(req->pad, 0, sizeof req->pad);
+
+    dump_stats_transaction(argv[1], request);
+}
+
+static void do_dump_aggregate(int argc, char *argv[])
+{
+    struct ofp_aggregate_stats_request *req;
+    struct buffer *request;
+
+    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);
+
+    dump_stats_transaction(argv[1], request);
 }
 
 static void do_add_flows(int argc, char *argv[])
@@ -586,7 +667,7 @@ static void do_add_flows(int argc, char *argv[])
     while (fgets(line, sizeof line, file)) {
         struct buffer *buffer;
         struct ofp_flow_mod *ofm;
-        uint16_t priority=0;
+        uint16_t priority;
         size_t size;
 
         char *comment;
@@ -605,12 +686,12 @@ static void do_add_flows(int argc, char *argv[])
         /* Parse and send. */
         size = sizeof *ofm + sizeof ofm->actions[0];
         ofm = alloc_openflow_buffer(size, OFPT_FLOW_MOD, &buffer);
+        str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
         ofm->command = htons(OFPFC_ADD);
         ofm->max_idle = htons(50);
         ofm->buffer_id = htonl(UINT32_MAX);
-        ofm->group_id = htonl(0);
-        str_to_flow(line, &ofm->match, &ofm->actions[0], NULL, &priority);
         ofm->priority = htons(priority);
+        ofm->reserved = htonl(0);
 
         send_openflow_buffer(vconn, buffer);
     }
@@ -618,10 +699,36 @@ static void do_add_flows(int argc, char *argv[])
     fclose(file);
 }
 
+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;
+    struct ofp_flow_mod *ofm;
+    size_t size;
+
+
+    /* 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->priority = htons(priority);
+    ofm->reserved = htonl(0);
+
+    send_openflow_buffer(vconn, buffer);
+
+    vconn_close(vconn);
+}
+
 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)
@@ -644,6 +751,9 @@ 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 },
+    { NULL, 0, 0, NULL },
 };