Index: /trunk/README
===================================================================
--- /trunk/README	(revision 6437)
+++ /trunk/README	(revision 6440)
@@ -33,4 +33,4 @@
 
 Run script from commandline with verbose
-./bin/django runscript --verbosity=2 --traceback genesis_to_exodus
+$ ./bin/django runscript --verbosity=2 --traceback genesis_to_exodus
 
Index: /trunk/exodus/forms.py
===================================================================
--- /trunk/exodus/forms.py	(revision 6437)
+++ /trunk/exodus/forms.py	(revision 6440)
@@ -20,7 +20,7 @@
             else:
                 #XXX: Need to update ipconfigurations for depending interfaces
+                #XXX: Need to set netmask
                 masterip = free_master_ip(new_network) 
         return masterip        
-
 
 class InterfaceForm(forms.ModelForm):
@@ -60,11 +60,15 @@
                 # convert master to slave
                 #XXX: update mode
+                #XXX: update ssids
                 old_slave = link
                 old_master = old_slave.link
                 old_master.link = old_slave
                 old_slave.link = old_slave
+
+                #XXX: do ip address switch stuff
+                # 
+                # Save 
                 old_slave.save()
                 old_master.save()
-                #XXX: do ip address switch stuff
                 return link
 
@@ -76,5 +80,4 @@
                     %(link.type, type))
                 
- 
         return link
 
Index: /trunk/exodus/tests.py
===================================================================
--- /trunk/exodus/tests.py	(revision 6437)
+++ /trunk/exodus/tests.py	(revision 6440)
@@ -7,5 +7,5 @@
         self.client = Client()
         
-        #Set up the database
+        #Set up a inmemory database
         from exodus import settings
         self.olddbname = settings.DATABASE_NAME
@@ -23,46 +23,4 @@
         connection.creation.destroy_test_db(self.olddbname, 0)
 
-    def test_addlocation(self):
-        post_data = {'description': 'JohnLaan2', 'longitude': '34.55', \
-            'latitude' : '44.55', 'proceed': 'OK, proceed'}
-        response = self.client.post('/add/location/new/', post_data) 
-
-        self.failUnlessEqual(response.status_code, 302)
-        self.failUnlessEqual(response['Location'], \
-                'http://testserver/add/node/new/?location=2')
-
-        from exodus.models import Location
-    
-        l = Location.objects.get(description = 'JohnLaan2')
-        self.failUnless(str(l.longitude), '34.55')
-        self.failUnless(str(l.latitude), '44.55')
-
-    def test_addnode(self):
-        post_data = {'name' : 'Tabitha', 'location' : 1, \
-            'status' : 'up', 'network' : 1, 'proceed': 'OK, proceed'}
-        response = self.client.post('/add/node/new/', post_data) 
-
-        self.failUnlessEqual(response.status_code, 302)
-        self.failUnlessEqual(response['Location'], \
-                'http://testserver/view/node/Tabitha/')
-
-        from exodus.models import Node
-    
-        try:
-             n = Node.objects.get(name = 'Tabitha')
-        except Node.DoesNotExist: 
-            self.fail("Node wasn't added.")
-
-        node = n 
-        self.failUnlessEqual(n.location.id, 1)
-        self.failUnlessEqual(n.status, 'up')
-        self.failUnlessEqual(n.network.id, 1) 
-
-        c = {}
-
-        for i in n.as_list():
-           c[i[0]] = i[1] 
-
-        self.failUnless(c.has_key('masterip'))
 
 class wllogic(unittest.TestCase):
@@ -82,5 +40,5 @@
         connection.creation.destroy_test_db(self.olddbname, 0)
 
-    def test_new_SSID_name(self):
+    def test_new_ssid(self):
         class node(object):
             name = 'CeTIM'
@@ -160,25 +118,29 @@
     def test_free_master_ip(self):
         from wllogic import free_master_ip
-        from exodus.models import Node, Network
-
-        node = Node.objects.create(location_id = 1, \
-                masterip = '172.16.0.1', name = 'testnode')
+        from exodus.models import Network, Node
+        nodes = Node.objects.all()
+        ip_list = []
+        for i in nodes:
+            ip_list.append(i.masterip)
         network = Network.objects.get(pk=1)
         ip = free_master_ip(network) 
-        self.failIfEqual(ip, '172.16.0.1') 
-        self.failUnlessEqual(ip, '172.16.1.1')
-        
-    def test_free_publicap_ip(self):
-        from wllogic import free_publicap_ip
-        self.fail('test not implemented')
-
-    def test_free_interlink_ip(self):
-        from wllogic import free_interlink_ip
-        self.fail('Test not implemented')
-
-    def test_add_interlink_ip(self):
-        from wllogic import add_interlink_ip
-        self.fail('Test not implemented')
-
+        self.failIf(ip in ip_list)
+        self.failUnlessEqual(ip, '172.16.2.1')
+
+    def test_calc_subnet(self):
+        from wllogic import calc_subnet
+        self.failUnlessEqual(calc_subnet(1), 32)
+        self.failUnlessRaises(ValueError, calc_subnet, 0)
+        self.failUnlessRaises(ValueError, calc_subnet, 255)
+
+        l = []
+        for i in range(1,255):
+            l.append(calc_subnet(i))
+        k = []
+        for i in range(24,33):
+            k.append(l.count(i))
+        n = [128, 64, 32, 16, 8, 4, 1, 0, 1]
+        self.failUnlessEqual(k,n)
+        
 class Link(unittest.TestCase):
     def setUp(self):
@@ -201,16 +163,23 @@
        
         # test link to self
-        self.failUnless(link_has_compat_type(self.link00, self.link00))
+        self.failUnless(link_has_compat_type(self.link00.type, 
+				self.link00.type))
         # test eth
-        self.failUnless(link_has_compat_type(self.link00, self.link01))
+        self.failUnless(link_has_compat_type(self.link00.type, 
+				self.link01.type))
         # test 11a
-        self.failUnless(link_has_compat_type(self.link10, self.link11))
+        self.failUnless(link_has_compat_type(self.link10.type,
+				 self.link11.type))
         # test 11b
-        self.failUnless(link_has_compat_type(self.link20, self.link21))
+        self.failUnless(link_has_compat_type(self.link20.type, 
+				self.link21.type))
         # test 11g
-        self.failUnless(link_has_compat_type(self.link30, self.link31))
+        self.failUnless(link_has_compat_type(self.link30.type, 
+				self.link31.type))
         # test 11b vs 11g
-        self.failUnless(link_has_compat_type(self.link20, self.link30))
-        self.failUnless(link_has_compat_type(self.link30, self.link20))
+        self.failUnless(link_has_compat_type(self.link20.type, 
+				self.link30.type))
+        self.failUnless(link_has_compat_type(self.link30.type, 
+				self.link20.type))
 
         # test fail eth vs 11a
Index: /trunk/exodus/wllogic.py
===================================================================
--- /trunk/exodus/wllogic.py	(revision 6437)
+++ /trunk/exodus/wllogic.py	(revision 6440)
@@ -3,4 +3,5 @@
 from exodus.models import Node, Interface
 from exodus.settings import MASTERIP_NETMASK
+from math import ceil, log
 
 def new_ssid(node, nic, desc):
@@ -16,5 +17,5 @@
 #
 def parse_addr(s):
-	"""Remember when using an address has a section which is higher than
+	"""Remember when using an address which has a section which is higher than
 	255, such as 172.16.0.256, the ip address from show_addr turns out as
 	172.16.1.0
@@ -58,9 +59,7 @@
 #     requested subnet
 
-def free_master_ip(city_network, netmask = None):
-	if netmask == None:
-		netmask = MASTERIP_NETMASK
-
-	if netmask < 0 or netmask > 32 :
+def free_master_ip(city_network, netmask = MASTERIP_NETMASK):
+	"""Calculates the next free masterip."""
+	if netmask < 0 or netmask > 32:
 		raise ValueError, 'netmask out of bounds'	
 
@@ -129,8 +128,8 @@
 	return show_addr(i)
 
-def add_interlink_ip(masterLink):
+def add_interlink_ip(master_link):
 	taken = {}
 	
-	for interface in Interface.objects.filter(link=masterLink):
+	for interface in Interface.objects.filter(link=master_link):
 		#Grr, needs all interfaces which are master requires a bit of a hack
 		addr = parse_addr(interface.ip)
@@ -139,5 +138,5 @@
 	size = 32
 	numaddrs = 1 << (32 - size)
-	i = network(masterLink.ip, masterLink.netmask) + 1
+	i = network(master_link.ip, master_link.netmask) + 1
 	while taken.has_key(i):
 		i = i + 1
@@ -164,6 +163,16 @@
 
 def link_is_not_to_itself(link1, link2):
-	# check if a link is not going itself
-	if link1.node != link2.node:
-		return True
+	"""check if a link referenced itself."""
+	return link1.node != link2.node
 
+def calc_subnet(number_ifaces):
+	"""Returns the subnetmask.
+
+	We need the subnet with number_ifaces available in subnet. As such
+	we correct for the broadcast and network address.
+	"""
+	if number_ifaces > 254 or number_ifaces < 1:
+		raise ValueError, 'Number of ifaces is out of bounds' 
+	if number_ifaces == 1:
+		return 32	
+	return int(32) - int(ceil(log(number_ifaces+2,2)))
