IP allocation simulation - Pad IPv4 addresses in LCP2 algorithm.
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Jul 2011 02:09:39 +0000 (12:09 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 29 Jul 2011 04:32:07 +0000 (14:32 +1000)
This makes IPv4 addresses comparable with IPv6 but reduces the overall
effectiveness of the algorithm.  The alternative would be to treat
these addresses separately while trying to keep all the IPs in overall
balance...  which is basically the problem that LCP2 solves.  :-)

Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/takeover/ctdb_takeover.py

index 42feeb5b713bf06f8962c66a466829baf87886a6..c8c0ed6e337bcbbeefcbf8361a62dbdbdf6f1a80 100755 (executable)
@@ -143,7 +143,13 @@ def ip_to_list_of_ints(ip):
     try:
         l = socket.inet_pton(socket.AF_INET6, ip)
     except:
-        l = socket.inet_pton(socket.AF_INET, ip)
+        # Pad with leading 0s.  This makes IPv4 addresses comparable
+        # with IPv6 but reduces the overall effectiveness of the
+        # algorithm.  The alternative would be to treat these
+        # addresses separately while trying to keep all the IPs in
+        # overall balance.
+        l = "".join(itertools.repeat("\0", 12)) + \
+            socket.inet_pton(socket.AF_INET, ip)
 
     return map(lambda x: struct.unpack('B', x)[0], l)