[ovs-dev] vswitchd: implement bond/hash unixctl

Ian Campbell Ian.Campbell at citrix.com
Thu Sep 17 12:37:25 UTC 2009


Our test case automation has a requirement to know which hash value a
given MAC address hashes to, in order to validate that balancing is
happening as expect etc.. Rather than attempt to reimplement the hash
algorithm used by vswitchd in python instead expose an appctl which
returns this information.

diff -r 44438fc53b52 vswitchd/bridge.c
--- a/vswitchd/bridge.c	Thu Sep 17 11:43:40 2009 +0100
+++ b/vswitchd/bridge.c	Thu Sep 17 13:33:23 2009 +0100
@@ -2751,6 +2751,25 @@
 }
 
 static void
+bond_unixctl_hash(struct unixctl_conn *conn, const char *args)
+{
+	uint8_t mac[ETH_ADDR_LEN];
+	uint8_t hash;
+	char *hash_cstr;
+
+	if (sscanf(args, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
+	    == ETH_ADDR_SCAN_COUNT) {
+		hash = bond_hash(mac);
+
+		hash_cstr = xasprintf("%u", hash);
+		unixctl_command_reply(conn, 200, hash_cstr);
+		free(hash_cstr);
+	} else {
+		unixctl_command_reply(conn, 501, "invalid mac");
+	}
+}
+
+static void
 bond_init(void)
 {
     unixctl_command_register("bond/list", bond_unixctl_list);
@@ -2760,6 +2779,7 @@
                              bond_unixctl_set_active_slave);
     unixctl_command_register("bond/enable-slave", bond_unixctl_enable_slave);
     unixctl_command_register("bond/disable-slave", bond_unixctl_disable_slave);
+    unixctl_command_register("bond/hash", bond_unixctl_hash);
 }
 
 /* Port functions. */
diff -r 44438fc53b52 vswitchd/ovs-vswitchd.8.in
--- a/vswitchd/ovs-vswitchd.8.in	Thu Sep 17 11:43:40 2009 +0100
+++ b/vswitchd/ovs-vswitchd.8.in	Thu Sep 17 13:33:23 2009 +0100
@@ -136,6 +136,8 @@
 .IP
 This setting is not permanent: it persists only until the carrier
 status of \fIslave\fR changes.
+.IP "\fBbond/hash\fR \fImac\fR"
+Returns the hash value which would be used for \fImac\fR.
 .
 .so lib/vlog-unixctl.man
 .SH "SEE ALSO"






More information about the dev mailing list