daemon: Use a set to store the broker node map.
This commit is contained in:
parent
6494605298
commit
8479ccd2c5
2 changed files with 37 additions and 43 deletions
|
@ -399,28 +399,25 @@ class CoreBroker(ConfigurableManager):
|
||||||
def addnodemap(self, server, nodenum):
|
def addnodemap(self, server, nodenum):
|
||||||
''' Record a node number to emulation server mapping.
|
''' Record a node number to emulation server mapping.
|
||||||
'''
|
'''
|
||||||
self.nodemap_lock.acquire()
|
with self.nodemap_lock:
|
||||||
if nodenum in self.nodemap:
|
if nodenum in self.nodemap:
|
||||||
if server in self.nodemap[nodenum]:
|
if server in self.nodemap[nodenum]:
|
||||||
self.nodemap_lock.release()
|
|
||||||
return
|
return
|
||||||
self.nodemap[nodenum].append(server)
|
self.nodemap[nodenum].add(server)
|
||||||
else:
|
else:
|
||||||
self.nodemap[nodenum] = [server,]
|
self.nodemap[nodenum] = {server}
|
||||||
if server in self.nodecounts:
|
if server in self.nodecounts:
|
||||||
self.nodecounts[server] += 1
|
self.nodecounts[server] += 1
|
||||||
else:
|
else:
|
||||||
self.nodecounts[server] = 1
|
self.nodecounts[server] = 1
|
||||||
self.nodemap_lock.release()
|
|
||||||
|
|
||||||
def delnodemap(self, sock, nodenum):
|
def delnodemap(self, sock, nodenum):
|
||||||
''' Remove a node number to emulation server mapping.
|
''' Remove a node number to emulation server mapping.
|
||||||
Return the number of nodes left on this server.
|
Return the number of nodes left on this server.
|
||||||
'''
|
'''
|
||||||
self.nodemap_lock.acquire()
|
|
||||||
count = None
|
count = None
|
||||||
|
with self.nodemap_lock:
|
||||||
if nodenum not in self.nodemap:
|
if nodenum not in self.nodemap:
|
||||||
self.nodemap_lock.release()
|
|
||||||
return count
|
return count
|
||||||
found = False
|
found = False
|
||||||
for server in self.nodemap[nodenum]:
|
for server in self.nodemap[nodenum]:
|
||||||
|
@ -435,7 +432,6 @@ class CoreBroker(ConfigurableManager):
|
||||||
if server in self.nodecounts:
|
if server in self.nodecounts:
|
||||||
count -= 1
|
count -= 1
|
||||||
self.nodecounts[server] = count
|
self.nodecounts[server] = count
|
||||||
self.nodemap_lock.release()
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
def incrbootcount(self):
|
def incrbootcount(self):
|
||||||
|
@ -450,15 +446,12 @@ class CoreBroker(ConfigurableManager):
|
||||||
return self.bootcount
|
return self.bootcount
|
||||||
|
|
||||||
def getserversbynode(self, nodenum):
|
def getserversbynode(self, nodenum):
|
||||||
''' Retrieve a list of emulation servers given a node number.
|
''' Retrieve a set of emulation servers given a node number.
|
||||||
'''
|
'''
|
||||||
self.nodemap_lock.acquire()
|
with self.nodemap_lock:
|
||||||
if nodenum not in self.nodemap:
|
if nodenum not in self.nodemap:
|
||||||
self.nodemap_lock.release()
|
return set()
|
||||||
return []
|
return self.nodemap[nodenum]
|
||||||
r = self.nodemap[nodenum]
|
|
||||||
self.nodemap_lock.release()
|
|
||||||
return r
|
|
||||||
|
|
||||||
def addnet(self, nodenum):
|
def addnet(self, nodenum):
|
||||||
''' Add a node number to the list of link-layer nodes.
|
''' Add a node number to the list of link-layer nodes.
|
||||||
|
|
|
@ -237,8 +237,9 @@ class MobilityManager(ConfigurableManager):
|
||||||
return
|
return
|
||||||
for nodenum in nodenums:
|
for nodenum in nodenums:
|
||||||
node = self.phys[nodenum]
|
node = self.phys[nodenum]
|
||||||
servers = self.session.broker.getserversbynode(nodenum)
|
for server in self.session.broker.getserversbynode(nodenum):
|
||||||
(host, port, sock) = self.session.broker.getserver(servers[0])
|
break
|
||||||
|
(host, port, sock) = self.session.broker.getserver(server)
|
||||||
netif = self.session.broker.gettunnel(net.objid, IPAddr.toint(host))
|
netif = self.session.broker.gettunnel(net.objid, IPAddr.toint(host))
|
||||||
node.addnetif(netif, 0)
|
node.addnetif(netif, 0)
|
||||||
netif.node = node
|
netif.node = node
|
||||||
|
|
Loading…
Reference in a new issue