ovs-dev.py: rename ROOT to RUNDIR
[cascardo/ovs.git] / utilities / ovs-ofctl.c
index 566a6b4..0c315c1 100644 (file)
@@ -130,6 +130,8 @@ main(int argc, char *argv[])
     fatal_ignore_sigpipe();
     ctx.argc = argc - optind;
     ctx.argv = argv + optind;
+
+    daemon_become_new_user(false);
     ovs_cmdl_run_command(&ctx, get_all_commands());
     return 0;
 }
@@ -731,8 +733,72 @@ ofctl_dump_table_features(struct ovs_cmdl_context *ctx)
 
     open_vconn(ctx->argv[1], &vconn);
     request = ofputil_encode_table_features_request(vconn_get_version(vconn));
-    if (request) {
-        dump_stats_transaction(vconn, request);
+
+    /* The following is similar to dump_trivial_stats_transaction(), but it
+     * maintains the previous 'ofputil_table_features' from one stats reply
+     * message to the next, which allows duplication to be eliminated in the
+     * output across messages.  Otherwise the output is much larger and harder
+     * to read, because only 17 or so ofputil_table_features elements fit in a
+     * single 64 kB OpenFlow message and therefore you get a ton of repetition
+     * (every 17th element is printed in full instead of abbreviated). */
+
+    const struct ofp_header *request_oh = request->data;
+    ovs_be32 send_xid = request_oh->xid;
+    bool done = false;
+
+    struct ofputil_table_features prev;
+    int n = 0;
+
+    send_openflow_buffer(vconn, request);
+    while (!done) {
+        ovs_be32 recv_xid;
+        struct ofpbuf *reply;
+
+        run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
+        recv_xid = ((struct ofp_header *) reply->data)->xid;
+        if (send_xid == recv_xid) {
+            enum ofptype type;
+            enum ofperr error;
+            error = ofptype_decode(&type, reply->data);
+            if (error) {
+                ovs_fatal(0, "decode error: %s", ofperr_get_name(error));
+            } else if (type == OFPTYPE_ERROR) {
+                ofp_print(stdout, reply->data, reply->size, verbosity + 1);
+                done = true;
+            } else if (type == OFPTYPE_TABLE_FEATURES_STATS_REPLY) {
+                done = !ofpmp_more(reply->data);
+                for (;;) {
+                    struct ofputil_table_features tf;
+                    int retval;
+
+                    retval = ofputil_decode_table_features(reply, &tf, true);
+                    if (retval) {
+                        if (retval != EOF) {
+                            ovs_fatal(0, "decode error: %s",
+                                      ofperr_get_name(retval));
+                        }
+                        break;
+                    }
+
+                    struct ds s = DS_EMPTY_INITIALIZER;
+                    ofp_print_table_features(&s, &tf, n ? &prev : NULL,
+                                             NULL, NULL);
+                    puts(ds_cstr(&s));
+                    ds_destroy(&s);
+
+                    prev = tf;
+                    n++;
+                }
+            } else {
+                ovs_fatal(0, "received bad reply: %s",
+                          ofp_to_string(reply->data, reply->size,
+                                        verbosity + 1));
+            }
+        } else {
+            VLOG_DBG("received reply with xid %08"PRIx32" "
+                     "!= expected %08"PRIx32, recv_xid, send_xid);
+        }
+        ofpbuf_delete(reply);
     }
 
     vconn_close(vconn);
@@ -1547,7 +1613,7 @@ monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests)
     int error;
 
     daemon_save_fd(STDERR_FILENO);
-    daemonize_start();
+    daemonize_start(false);
     error = unixctl_server_create(unixctl_path, &server);
     if (error) {
         ovs_fatal(error, "failed to create unixctl server");
@@ -1835,7 +1901,7 @@ ofctl_mod_port(struct ovs_cmdl_context *ctx)
     fetch_ofputil_phy_port(ctx->argv[1], ctx->argv[2], &pp);
 
     pm.port_no = pp.port_no;
-    memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN);
+    pm.hw_addr = pp.hw_addr;
     pm.config = 0;
     pm.mask = 0;
     pm.advertise = 0;
@@ -2521,10 +2587,11 @@ fte_insert(struct classifier *cls, const struct match *match,
     struct fte *old, *fte;
 
     fte = xzalloc(sizeof *fte);
-    cls_rule_init(&fte->rule, match, priority, CLS_MIN_VERSION);
+    cls_rule_init(&fte->rule, match, priority);
     fte->versions[index] = version;
 
-    old = fte_from_cls_rule(classifier_replace(cls, &fte->rule, NULL, 0));
+    old = fte_from_cls_rule(classifier_replace(cls, &fte->rule,
+                                               CLS_MIN_VERSION, NULL, 0));
     if (old) {
         fte->versions[!index] = old->versions[!index];
         old->versions[!index] = NULL;