vswitchd: New unixctl command "fdb/show" to print the MAC learing table.
authorBen Pfaff <blp@nicira.com>
Wed, 15 Jul 2009 18:05:37 +0000 (11:05 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 16 Jul 2009 16:17:06 +0000 (09:17 -0700)
To implement "brctl showmacs" for bridge compatibility, brcompatd needs to
be able to extract the MAC learning table from ovs-vswitchd.  This provides
a way, and it may be directly useful to switch administrators also.

vswitchd/bridge.c

index 5d8a5b0..b0b2a8f 100644 (file)
@@ -206,6 +206,8 @@ static uint64_t bridge_pick_datapath_id(struct bridge *,
                                         const char *devname);
 static uint64_t dpid_from_hash(const void *, size_t nbytes);
 
+static void bridge_unixctl_fdb_show(struct unixctl_conn *, const char *args);
+
 static void bond_init(void);
 static void bond_run(struct bridge *);
 static void bond_wait(struct bridge *);
@@ -280,6 +282,8 @@ bridge_init(void)
 
     bond_init();
 
+    unixctl_command_register("fdb/show", bridge_unixctl_fdb_show);
+
     for (i = 0; i < DP_MAX; i++) {
         struct dpif dpif;
         char devname[16];
@@ -788,6 +792,32 @@ bridge_flush(struct bridge *br)
     }
 }
 \f
+/* Bridge unixctl user interface functions. */
+static void
+bridge_unixctl_fdb_show(struct unixctl_conn *conn, const char *args)
+{
+    struct ds ds = DS_EMPTY_INITIALIZER;
+    const struct bridge *br;
+
+    br = bridge_lookup(args);
+    if (!br) {
+        unixctl_command_reply(conn, 501, "no such bridge");
+        return;
+    }
+
+    ds_put_cstr(&ds, " port  VLAN  MAC                Age\n");
+    if (br->ml) {
+        const struct mac_entry *e;
+        LIST_FOR_EACH (e, struct mac_entry, lru_node, &br->ml->lrus) {
+            ds_put_format(&ds, "%5d  %4d  "ETH_ADDR_FMT"  %3d\n",
+                          e->port, e->vlan, ETH_ADDR_ARGS(e->mac),
+                          mac_entry_age(e));
+        }
+    }
+    unixctl_command_reply(conn, 200, ds_cstr(&ds));
+    ds_destroy(&ds);
+}
+\f
 /* Bridge reconfiguration functions. */
 
 static struct bridge *