This commit is contained in:
Rod A Santiago 2016-10-19 16:21:10 -07:00
commit 3f6040a0f3

View file

@ -522,13 +522,14 @@ class CoreBroker(ConfigurableManager):
Returning False indicates this message should be handled locally. Returning False indicates this message should be handled locally.
''' '''
servers = set() servers = set()
handle_locally = False
# Do not forward messages when in definition state # Do not forward messages when in definition state
# (for e.g. configuring services) # (for e.g. configuring services)
if self.session.getstate() == coreapi.CORE_EVENT_DEFINITION_STATE: if self.session.getstate() == coreapi.CORE_EVENT_DEFINITION_STATE:
return False return False
# Decide whether message should be handled locally or forwarded, or both # Decide whether message should be handled locally or forwarded, or both
if msg.msgtype == coreapi.CORE_API_NODE_MSG: if msg.msgtype == coreapi.CORE_API_NODE_MSG:
servers = self.handlenodemsg(msg) handle_locally, servers = self.handlenodemsg(msg)
elif msg.msgtype == coreapi.CORE_API_EVENT_MSG: elif msg.msgtype == coreapi.CORE_API_EVENT_MSG:
# broadcast events everywhere # broadcast events everywhere
servers = self.getservers() servers = self.getservers()
@ -547,7 +548,7 @@ class CoreBroker(ConfigurableManager):
if msg.msgtype == coreapi.CORE_API_LINK_MSG: if msg.msgtype == coreapi.CORE_API_LINK_MSG:
# prepare a server list from two node numbers in link message # prepare a server list from two node numbers in link message
servers, msg = self.handlelinkmsg(msg) handle_locally, servers, msg = self.handlelinkmsg(msg)
elif len(servers) == 0: elif len(servers) == 0:
# check for servers based on node numbers in all messages but link # check for servers based on node numbers in all messages but link
nn = msg.nodenumbers() nn = msg.nodenumbers()
@ -562,7 +563,7 @@ class CoreBroker(ConfigurableManager):
handler(msg) handler(msg)
# Perform any message forwarding # Perform any message forwarding
handle_locally = self.forwardmsg(msg, servers) handle_locally |= self.forwardmsg(msg, servers)
return not handle_locally return not handle_locally
def setupserver(self, servername): def setupserver(self, servername):
@ -629,6 +630,7 @@ class CoreBroker(ConfigurableManager):
nodes to servers. nodes to servers.
''' '''
servers = set() servers = set()
handle_locally = False
serverfiletxt = None serverfiletxt = None
# snoop Node Message for emulation server TLV and record mapping # snoop Node Message for emulation server TLV and record mapping
n = msg.tlvdata[coreapi.CORE_TLV_NODE_NUMBER] n = msg.tlvdata[coreapi.CORE_TLV_NODE_NUMBER]
@ -639,21 +641,22 @@ class CoreBroker(ConfigurableManager):
nodecls = coreapi.node_class(nodetype) nodecls = coreapi.node_class(nodetype)
except KeyError: except KeyError:
self.session.warn("broker invalid node type %s" % nodetype) self.session.warn("broker invalid node type %s" % nodetype)
return servers return handle_locally, servers
if nodecls is None: if nodecls is None:
self.session.warn("broker unimplemented node type %s" % nodetype) self.session.warn("broker unimplemented node type %s" % nodetype)
return servers return handle_locally, servers
if issubclass(nodecls, PyCoreNet) and \ if issubclass(nodecls, PyCoreNet) and \
nodetype != coreapi.CORE_NODE_WLAN: nodetype != coreapi.CORE_NODE_WLAN:
# network node replicated on all servers; could be optimized # network node replicated on all servers; could be optimized
# don't replicate WLANs, because ebtables rules won't work # don't replicate WLANs, because ebtables rules won't work
servers = self.getservers() servers = self.getservers()
handle_locally = True
self.addnet(n) self.addnet(n)
for server in servers: for server in servers:
self.addnodemap(server, n) self.addnodemap(server, n)
# do not record server name for networks since network # do not record server name for networks since network
# nodes are replicated across all server # nodes are replicated across all server
return servers return handle_locally, servers
elif issubclass(nodecls, PyCoreNode): elif issubclass(nodecls, PyCoreNode):
name = msg.gettlv(coreapi.CORE_TLV_NODE_NAME) name = msg.gettlv(coreapi.CORE_TLV_NODE_NAME)
if name: if name:
@ -674,7 +677,7 @@ class CoreBroker(ConfigurableManager):
# hook to update coordinates of physical nodes # hook to update coordinates of physical nodes
if n in self.phys: if n in self.phys:
self.session.mobility.physnodeupdateposition(msg) self.session.mobility.physnodeupdateposition(msg)
return servers return handle_locally, servers
def handlelinkmsg(self, msg): def handlelinkmsg(self, msg):
''' Determine and return the servers to which this link message should ''' Determine and return the servers to which this link message should
@ -731,10 +734,11 @@ class CoreBroker(ConfigurableManager):
self.addtunnel(host, nn[0], nn[1], localn) self.addtunnel(host, nn[0], nn[1], localn)
elif msg.flags & coreapi.CORE_API_DEL_FLAG: elif msg.flags & coreapi.CORE_API_DEL_FLAG:
self.deltunnel(nn[0], nn[1]) self.deltunnel(nn[0], nn[1])
handle_locally = False
else: else:
servers = servers1.union(servers2) servers = servers1.union(servers2)
return servers, msg return handle_locally, servers, msg
def addlinkendpoints(self, msg, servers1, servers2): def addlinkendpoints(self, msg, servers1, servers2):
''' For a link message that is not handled locally, inform the remote ''' For a link message that is not handled locally, inform the remote