Allow multiple ports on dpctl addif and delif commands, for convenience.
authorBen Pfaff <blp@nicira.com>
Tue, 19 Aug 2008 20:47:17 +0000 (13:47 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 26 Aug 2008 19:02:59 +0000 (12:02 -0700)
utilities/dpctl.8
utilities/dpctl.c

index c91166a549f7860b85a98056a25007c3ea137f85..2af2f270a15f37e64471d292b108ebebdfa9cf8c 100644 (file)
@@ -70,8 +70,8 @@ explicitly removed before the datapath can be deleted (see \fBdelif\fR
 command).
 
 .TP
 command).
 
 .TP
-\fBaddif nl:\fIdp_idx netdev\fR
-Adds \fInetdev\fR to the list of network devices datapath
+\fBaddif nl:\fIdp_idx netdev\fR...
+Adds each \fInetdev\fR to the list of network devices datapath
 \fIdp_idx\fR monitors, where \fIdp_idx\fR is the ID of an existing
 datapath, and \fInetdev\fR is the name of one of the host's
 network devices, e.g. \fBeth0\fR.  Once a network device has been added
 \fIdp_idx\fR monitors, where \fIdp_idx\fR is the ID of an existing
 datapath, and \fInetdev\fR is the name of one of the host's
 network devices, e.g. \fBeth0\fR.  Once a network device has been added
@@ -79,8 +79,8 @@ to a datapath, the datapath has complete ownership of the network device's
 traffic and the network device appears silent to the rest of the system.
 
 .TP
 traffic and the network device appears silent to the rest of the system.
 
 .TP
-\fBdelif nl:\fIdp_idx netdev\fR
-Removes \fInetdev\fR from the list of network devices datapath
+\fBdelif nl:\fIdp_idx netdev\fR...
+Removes each \fInetdev\fR from the list of network devices datapath
 \fIdp_idx\fR monitors.
 
 .TP
 \fIdp_idx\fR monitors.
 
 .TP
index 7c5020067dfa8d9352bf0ee813a4abc9791e3eef..bade78ab939c805f17f9fe9dc1d76eb7c09a2338 100644 (file)
@@ -187,8 +187,8 @@ usage(void)
            "\nFor local datapaths only:\n"
            "  adddp nl:DP_ID              add a new local datapath DP_ID\n"
            "  deldp nl:DP_ID              delete local datapath DP_ID\n"
            "\nFor local datapaths only:\n"
            "  adddp nl:DP_ID              add a new local datapath DP_ID\n"
            "  deldp nl:DP_ID              delete local datapath DP_ID\n"
-           "  addif nl:DP_ID IFACE        add IFACE as a port on DP_ID\n"
-           "  delif nl:DP_ID IFACE        delete IFACE as a port on DP_ID\n"
+           "  addif nl:DP_ID IFACE...     add each IFACE as a port on DP_ID\n"
+           "  delif nl:DP_ID IFACE...     delete each IFACE from DP_ID\n"
            "  monitor nl:DP_ID            print packets received\n"
 #endif
            "\nFor local datapaths and remote switches:\n"
            "  monitor nl:DP_ID            print packets received\n"
 #endif
            "\nFor local datapaths and remote switches:\n"
@@ -280,21 +280,43 @@ static void do_del_dp(int argc UNUSED, char *argv[])
     dpif_close(&dp);
 }
 
     dpif_close(&dp);
 }
 
-static void do_add_port(int argc UNUSED, char *argv[])
+static void add_del_ports(int argc UNUSED, char *argv[],
+                          int (*function)(struct dpif *, const char *netdev),
+                          const char *operation, const char *preposition)
 {
     struct dpif dp;
 {
     struct dpif dp;
-    if_up(argv[2]);
+    bool failure = false;
+    int i;
+
     open_nl_vconn(argv[1], false, &dp);
     open_nl_vconn(argv[1], false, &dp);
-    run(dpif_add_port(&dp, argv[2]), "add_port");
+    for (i = 2; i < argc; i++) {
+        int retval = function(&dp, argv[i]);
+        if (retval) {
+            error(retval, "failed to %s %s %s %s",
+                  operation, argv[i], preposition, argv[1]);
+            failure = true;
+        }
+    }
     dpif_close(&dp);
     dpif_close(&dp);
+    if (failure) {
+        exit(EXIT_FAILURE);
+    }
+}
+
+static int ifup_and_add_port(struct dpif *dpif, const char *netdev)
+{
+    if_up(netdev);
+    return dpif_add_port(dpif, netdev);
+}
+
+static void do_add_port(int argc UNUSED, char *argv[])
+{
+    add_del_ports(argc, argv, ifup_and_add_port, "add", "to");
 }
 
 static void do_del_port(int argc UNUSED, char *argv[])
 {
 }
 
 static void do_del_port(int argc UNUSED, char *argv[])
 {
-    struct dpif dp;
-    open_nl_vconn(argv[1], false, &dp);
-    run(dpif_del_port(&dp, argv[2]), "del_port");
-    dpif_close(&dp);
+    add_del_ports(argc, argv, dpif_del_port, "remove", "from");
 }
 
 static void do_monitor(int argc UNUSED, char *argv[])
 }
 
 static void do_monitor(int argc UNUSED, char *argv[])
@@ -1060,8 +1082,8 @@ static struct command all_commands[] = {
 #ifdef HAVE_NETLINK
     { "adddp", 1, 1, do_add_dp },
     { "deldp", 1, 1, do_del_dp },
 #ifdef HAVE_NETLINK
     { "adddp", 1, 1, do_add_dp },
     { "deldp", 1, 1, do_del_dp },
-    { "addif", 2, 2, do_add_port },
-    { "delif", 2, 2, do_del_port },
+    { "addif", 2, INT_MAX, do_add_port },
+    { "delif", 2, INT_MAX, do_del_port },
 #endif
 
     { "show", 1, 1, do_show },
 #endif
 
     { "show", 1, 1, do_show },