Index: fedd/federation/emulab_access.py
===================================================================
--- fedd/federation/emulab_access.py	(revision b7f6cccc78b4592ea8ef904b2b23964002a5e222)
+++ fedd/federation/emulab_access.py	(revision 617592b008e12b7ccdf4592cac90f3280f0f46e9)
@@ -917,8 +917,12 @@
 
 	    rv = None
+	    print info
 	    for i in info:
-		if i.get('portal', "") == key:
+		if key == i.get('portal', "") or \
+			key in [e.get('element', "") \
+			for e in i.get('member', [])]:
 		    rv = i.copy()
 		    break
+
 	    else:
 		return rv
@@ -1049,32 +1053,78 @@
 
 
-    def generate_ns2(self, topo, expfn, softdir, master):
-	def dragon_commands(e):
-	    s = ""
-	    if isinstance(e, topdl.Computer):
-		for i in e.interface:
-		    vlan = i.get_attribute('dragon_vlan')
-		    if vlan:
-			type = i.get_attribute('dragon_type')
-			ip = i.get_attribute('ip4_address')
-			if type == 'link':
-			    s = ("tb-allow-external $%s dragonportal " + \
-				    "ip %s vlan %s\n") % \
-				    (topdl.to_tcl_name(e.name[0]), ip, vlan)
-			elif type == 'lan':
-			    s = ("tb-allow-external $%s dragonportal " + \
-				    "ip %s vlan %s usurp %s\n") % \
-				    (topdl.to_tcl_name(e.name[0]), ip, vlan,
-					i.substrate[0])
-			else:
-			    raise service_error(service_error_internal,
-				    "Unknown DRAGON type %s" % type)
-	    return s
-
-	def not_dragon(e):
-	    return all([not i.get_attribute('dragon_vlan') \
-		    for i in e.interface])
+    def generate_ns2(self, topo, expfn, softdir, master, connInfo):
+	class dragon_commands:
+	    """
+	    Functor to spit out approrpiate dragon commands for nodes listed in
+	    the connectivity description.  The constructor makes a dict mapping
+	    dragon nodes to their parameters and the __call__ checks each
+	    element in turn for membership.
+	    """
+	    def __init__(self, map):
+		self.node_info = map
+
+	    def __call__(self, e):
+		s = ""
+		if isinstance(e, topdl.Computer):
+		    if self.node_info.has_key(e.name[0]):
+			i = self.node_info[e.name[0]]
+			for ifname, vlan, type in i:
+			    print "Checking %s" % e.name[0]
+			    for i in e.interface:
+				print "interface s %s %s" % (i.name, ifname)
+				if i.name == ifname:
+				    addr = i.get_attribute('ip4_address')
+				    subs = i.substrate[0]
+				    break
+			    else:
+				raise service_error(service_error.internal,
+					"No interface %s on element %s" % \
+						(ifname, e.name[0]))
+			    if type =='link':
+				s = ("tb-allow-external $%s dragonportal " + \
+					"ip %s vlan %s\n") % \
+					(e.name[0], addr, vlan)
+			    elif type =='lan':
+				s = ("tb-allow-external $%s dragonportal " + \
+					"ip %s vlan %s usurp %s\n") % \
+					(e.name[0], addr, vlan, subs)
+			    else:
+				raise service_error(service_error_internal,
+					"Unknown DRAGON type %s" % type)
+		return s
+
+	class not_dragon:
+	    def __init__(self, map):
+		self.nodes = set(map.keys())
+
+	    def __call__(self, e):
+		return e.name[0] not in self.nodes
 
 	t = topo.clone()
+
+	dragon_map = { }
+	for i in [ i for i in connInfo if i['type'] == 'transit']:
+	    for a in i.get('fedAttr', []):
+		if a['attribute'] == 'vlan_id':
+		    vlan = a['value']
+		    break
+	    else:
+		raise service_error(service_error.internal, 
+			"No vlan tag")
+	    members = i.get('member', [])
+	    if len(members) > 1: type = 'lan'
+	    else: type = 'link'
+
+	    try:
+		for m in members:
+		    if dragon_map.has_key(m['element']):
+			dragon_map[m['element']].append(( m['interface'], 
+			    vlan, type))
+		    else:
+			dragon_map[m['element']] = [( m['interface'], 
+			    vlan, type),]
+	    except KeyError:
+		raise service_error(service_error.req,
+			"Missing connectivity info")
 
 	# The startcmds for master and slave testbeds
@@ -1109,8 +1159,8 @@
 			e.set_attribute('startup', node_cmd)
 
+		dinf = [i[0] for i in dragon_map.get(e.name[0], []) ]
 		# Remove portal interfaces that do not connect to DRAGON
 		e.interface = [i for i in e.interface \
-			if not i.get_attribute('portal') or \
-			    i.get_attribute('dragon_vlan')]
+			if not i.get_attribute('portal') or i.name in dinf ]
 
 	t.substrates = [ s.clone() for s in t.substrates ]
@@ -1125,6 +1175,6 @@
 
 	if self.attrs.has_key('dragon'):
-	    add_filter = not_dragon
-	    filters.append(dragon_commands)
+	    add_filter = not_dragon(dragon_map)
+	    filters.append(dragon_commands(dragon_map))
 	else:
 	    add_filter = None
@@ -1312,5 +1362,5 @@
 		    services)
 	    self.generate_ns2(topo, expfile, 
-		    "/proj/%s/software/%s/" % (proj, ename), master)
+		    "/proj/%s/software/%s/" % (proj, ename), master, connInfo)
 
 	    starter = self.start_segment(keyfile=self.ssh_privkey_file, 
