Permalink
Browse files

packets to any IP in the block allocated to a topology are now forwar…

…ded onto that topology

  -- previously, only IPs which were actually assigned to nodes would be forwarded
  -- now, IPs which are allocated to a topology but not assigned to any interface will still be forwarded onto the topology
  • Loading branch information...
dound committed Feb 9, 2010
1 parent 2afbe91 commit 69150c35c6deb1bf45bd4441917ea702f855ee58
Showing with 21 additions and 3 deletions.
  1. +17 −1 Topology.py
  2. +2 −2 TopologyResolver.py
  3. +2 −0 VNS.py
View
@@ -38,7 +38,8 @@ class Topology():
"""A topology to simulate."""
def __init__(self, tid, raw_socket, client_ip, user, start_stats=True):
"""Reads topology with the specified id from the database. A
- DoesNotExist exception (Topology or IPAssignment) is raised if this fails."""
+ DoesNotExist exception (Topology, IPAssignment, or IPBlockAllocation) is
+ raised if this fails."""
self.raw_socket = raw_socket
# stores jobs which need to be done for this topology
@@ -63,6 +64,10 @@ def __init__(self, tid, raw_socket, client_ip, user, start_stats=True):
self.id = tid
self.temporary = t.temporary
+ # determine what IP block is allocated to this topology
+ ipba = db.IPBlockAllocation.objects.get(topology=t)
+ self.ip_block = (struct.unpack('>I',inet_aton(ipba.start_addr))[0], ipba.mask)
+
# determine who may connect to nodes in this topology
if t.public:
# anyone may use it
@@ -186,6 +191,17 @@ def get_my_ip_addrs(self):
for intf in node.interfaces:
addrs.append(intf.ip)
return addrs
+
+ def get_my_ip_block(self):
+ """Returns a 2-tuple containing the subnet and associated mask which
+ contains all IPs assigned to this topology. The subnet is expressed as
+ a 4B NBO integer."""
+ return self.ip_block
+
+ def get_all_ip_addrs_in_my_ip_block(self):
+ """Returns a list of NBO byte-strings representing the IPs allocated to this topology."""
+ dst_block_start_ip, dst_block_mask = self.get_my_ip_block()
+ return [struct.pack('>I',dst_block_start_ip+i) for i in xrange(2**(32-dst_block_mask))]
def get_my_mac_addrs(self):
"""Returns a list of Ethernet addresses (as byte-strings) which belong
View
@@ -58,7 +58,7 @@ def register_topology(self, topo):
self.m2t[mac] = [topo]
logging.debug('%s: MAC registered: %s' % (topo, addrstr(mac)))
- for ip in topo.get_my_ip_addrs():
+ for ip in topo.get_all_ip_addrs_in_my_ip_block():
# get the source filtering tree associated with the destination
try:
st = self.i2t[ip]
@@ -95,7 +95,7 @@ def unregister_topology(self, topo):
except KeyError:
logging.error('%s: missing topo list for %s' % (topo, addrstr(mac)))
- for ip in topo.get_my_ip_addrs():
+ for ip in topo.get_all_ip_addrs_in_my_ip_block():
# get the source filtering tree associated with the destination
try:
st = self.i2t[ip]
View
2 VNS.py
@@ -265,6 +265,8 @@ def start_topology(self, tid, client_ip, user):
return (None, 'topology %d does not exist' % tid)
except db.IPAssignment.DoesNotExist:
return (None, 'topology %d is missing an IP assignment' % tid)
+ except db.IPBlockAllocation.DoesNotExist:
+ return (None, 'topology %d is not allocated any IPs' % tid)
except:
msg = 'topology instantiation unexpectedly failed'
log_exception(logging.ERROR, msg)

0 comments on commit 69150c3

Please sign in to comment.