Index: starbed_plugin/topdltok.py
===================================================================
--- starbed_plugin/topdltok.py	(revision adf8517cd63b0a2d2fc06028d8c36e1c6842dce7)
+++ starbed_plugin/topdltok.py	(revision adf8517cd63b0a2d2fc06028d8c36e1c6842dce7)
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+import federation.topdl as topdl
+
+# convert dotted quad netmask to CIDR / notation (i.e., 255.255.255.0 -> 24)
+# thanks faber
+def netmask_to_slash(nm):
+    m = long(0)
+    for i, b in enumerate([ int(x) for x in nm.split(".") ]):
+        m += (b & 0xff) << 8 * (3 - i)
+    count = 0
+    while m & 0x80000000:
+        m <<= 1
+        count += 1
+    return count
+#Get ip addresses gateway by zeroing the host bits
+#thanks to me :)
+def get_network(ip,prefix):
+        counter=32;
+        result = ""
+        for x in reversed(ip.split(".")):
+                if counter > prefix:
+                        b = 0xff;
+                        b <<= (counter-prefix)
+                        result = "%d." % (int(x) & b) + result
+                else:
+                        result = x + "." +  result
+                counter -= 8;
+        return result.rstrip('.')
+ 
+class klanguage:
+
+	def __init__ (self,rmanager,smanager,pmanager,fncp,user,project,tftpdman="localhost",wolagent="localhost:5959",encd="localhost",sparenodemin=0,sparenoderatio=100):
+		self.rmanager = rmanager
+		self.smanager = smanager
+		self.pmanager = pmanager
+		self.fncp = fncp
+		self.tftpdman = tftpdman
+		self.wolagent = wolagent
+		self.user = user
+		self.project = project
+		self.encd = encd
+		self.sparenodemin = sparenodemin
+		self.sparenoderatio = sparenoderatio
+		self.gut = ""
+	def to_file(self,name):
+		f = open(name, 'w+')
+		f.write(self.gut)
+	def k_from_topologyxml(self,name):
+		# load the topology
+		topo = topdl.topology_from_xml(filename=name, top='experiment')
+		self.k_from_topology(topo)
+	def k_from_topology(self,topo):
+		nodedef = ""
+		landef = ""
+		nodeinst = ""
+		laninst = ""
+		connection = ""
+		daemon = "/etc/quagga/daemons"
+		zebra = "/etc/quagga/zebra.conf"
+		ospfd = "/etc/quagga/ospfd.conf"
+		for elt in topo.elements:
+    			if isinstance(elt, topdl.Computer):
+    				name = str(elt.name)
+				nodedef = nodedef + 'nodeclass %sclass {\nmethod "thru"\npartition 1\nostype "FreeBSD"\n' % name
+				scenario = ""
+				interfaces = ""
+				networks = ""
+				for (counter,iface) in enumerate(elt.interface):
+					nodedef = nodedef + "netif media FastEthernet\n"
+					ip = str(iface.get_attribute('ip4_address'))
+        				mask = str(iface.get_attribute('ip4_netmask'))
+					ifname = str(iface.name)
+					substrate = str(iface.substrate[0])
+					scenario = scenario + ("callw \"/sbin/ifconfig\" self.netif[%d].rname \"%s\" \"netmask\" \"%s\"\n" %(counter,ip,mask) )
+					interfaces += "callw \"/bin/echo\" \"interface\" self.netif[%d].rname >> \"%s\"\n" %(counter,zebra)
+					connection = connection + "attach %s.netif[%d] %s[0]\n" %(name,counter,substrate)
+					prefix = netmask_to_slash(mask);
+					gateway = "%s/%d" % (get_network(ip,int(prefix)),prefix )
+					networks += "callw \"/bin/echo\" \" network %s area 0.0.0.2\" >> \"%s\"\n" % (gateway,ospfd) 
+				if scenario != "":
+					scenario += "callw \"/bin/echo\" \"zebra=yes\" > \"%s\"\n" % (daemon)
+					scenario += "callw \"/bin/echo\" \"bgpd=no\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"ospfd=yes\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"ospf6d=no\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"ripd=no\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"ripngd=no\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"isisd=no\" >> \"%s\"\n" %(daemon)
+					scenario += "callw \"/bin/echo\" \"hostname %s\" > \"%s\"\n" % (name,zebra)
+					scenario += interfaces
+					scenario += "callw \"/bin/echo\" \"hostname %s\" > \"%s\"\n" % (name,ospfd)
+					scenario += "callw \"/bin/echo\" \"router ospf\" >> \"%s\"\n" % (ospfd)
+					scenario += networks
+					scenario += "callw \"/bin/chown\" \"quagga.quaggavty\" \"/etc/quagga/*.conf\"\n"
+					scenario += "callw \"/bin/chown\" \"640\" \"/etc/quagga/*.conf\"\n"
+					scenario += "callw \"/etc/init.d/quagga\" \"restart\"\n" 
+					scenario = "scenario { \n netiffit \"/usr/bin/ifscan\"\n%s\n}\n" % (scenario)
+					nodedef = nodedef + scenario 
+				nodedef = nodedef + "}\n"
+				nodeinst = nodeinst + "nodeset %s class %sclass num 1\n" % (name,name)
+
+		#This should be replaced to specificlly define each LAN when required!
+		lanclass = "ethernet"
+		landef = "netclass %s {\nmedia FastEthernet\n}\n" % lanclass
+		for sub in topo.substrates:
+			sname = str(sub.name)
+			laninst = laninst + "netset %s class %s num 1\n" % (sname,lanclass)
+			laninst += "%s[0].ipaddrrange = \"192.168.33.0/24\"\n" % (sname)
+		self.gut = 'rmanager ipaddr "%s" port "%s"\n' % (self.rmanager.split(':')[0], self.rmanager.split(':')[1]);
+		self.gut += 'smanager ipaddr "%s" port "%s"\n' % (self.smanager.split(':')[0],self.smanager.split(':')[1] )
+		self.gut += 'pmanager ipaddr "%s" port "%s"\n' % (self.pmanager.split(':')[0],self.pmanager.split(':')[1] )
+		self.gut += 'fncp ipaddr "%s"\n' % (self.fncp)
+		self.gut += 'tftpdman ipaddr "%s"\n' % (self.tftpdman)
+
+		self.gut += 'wolagent ipaddr "%s" port "%s" ipaddrrange "%s"\n' % (self.wolagent.split(':')[0],self.wolagent.split(':')[1],self.wolagent.split(':')[2])
+
+		self.gut += 'user "%s" "%s@starbed.org"\n' % (self.user,self.user)
+		self.gut += 'project "%s"\n' % (self.project)
+		self.gut += 'encd ipaddr "%s"\n' % (self.encd)
+		self.gut += "sparenodemin %d\n" % (self.sparenodemin)
+		self.gut += "sparenoderatio %d\n" % (self.sparenoderatio)
+
+		self.gut += nodedef
+		self.gut += landef
+		self.gut += nodeinst
+		self.gut += laninst
+		self.gut += connection
+		self.gut += "scenario { \n sleep 10000 \n }\n"
