removed broker from session, updated most places using broker to use alternative logic to compensate where needed
This commit is contained in:
parent
6570f22ccf
commit
b2d2705849
19 changed files with 151 additions and 471 deletions
|
@ -19,13 +19,9 @@ from core.emulator.enumerations import (
|
|||
EventTypes,
|
||||
LinkTypes,
|
||||
MessageFlags,
|
||||
MessageTypes,
|
||||
NodeTlvs,
|
||||
RegisterTlvs,
|
||||
)
|
||||
from core.errors import CoreError
|
||||
from core.nodes.base import CoreNodeBase
|
||||
from core.nodes.ipaddress import IpAddress
|
||||
|
||||
|
||||
class MobilityManager(ModelManager):
|
||||
|
@ -48,11 +44,6 @@ class MobilityManager(ModelManager):
|
|||
self.models[BasicRangeModel.name] = BasicRangeModel
|
||||
self.models[Ns2ScriptedMobility.name] = Ns2ScriptedMobility
|
||||
|
||||
# dummy node objects for tracking position of nodes on other servers
|
||||
self.phys = {}
|
||||
self.physnets = {}
|
||||
self.session.broker.handlers.add(self.physnodehandlelink)
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Clear out all current configurations.
|
||||
|
@ -93,9 +84,6 @@ class MobilityManager(ModelManager):
|
|||
model_class = self.models[model_name]
|
||||
self.set_model(node, model_class, config)
|
||||
|
||||
if self.session.master:
|
||||
self.installphysnodes(node)
|
||||
|
||||
if node.mobility:
|
||||
self.session.event_loop.add_event(0.0, node.mobility.startup)
|
||||
|
||||
|
@ -209,87 +197,6 @@ class MobilityManager(ModelManager):
|
|||
if node.model:
|
||||
node.model.update(moved, moved_netifs)
|
||||
|
||||
def addphys(self, netnum, node):
|
||||
"""
|
||||
Keep track of PhysicalNodes and which network they belong to.
|
||||
|
||||
:param int netnum: network number
|
||||
:param core.coreobj.PyCoreNode node: node to add physical network to
|
||||
:return: nothing
|
||||
"""
|
||||
node_id = node.id
|
||||
self.phys[node_id] = node
|
||||
if netnum not in self.physnets:
|
||||
self.physnets[netnum] = [node_id]
|
||||
else:
|
||||
self.physnets[netnum].append(node_id)
|
||||
|
||||
# TODO: remove need for handling old style message
|
||||
|
||||
def physnodehandlelink(self, message):
|
||||
"""
|
||||
Broker handler. Snoop Link add messages to get
|
||||
node numbers of PhyiscalNodes and their nets.
|
||||
Physical nodes exist only on other servers, but a shadow object is
|
||||
created here for tracking node position.
|
||||
|
||||
:param message: link message to handle
|
||||
:return: nothing
|
||||
"""
|
||||
if (
|
||||
message.message_type == MessageTypes.LINK.value
|
||||
and message.flags & MessageFlags.ADD.value
|
||||
):
|
||||
nn = message.node_numbers()
|
||||
# first node is always link layer node in Link add message
|
||||
if nn[0] not in self.session.broker.network_nodes:
|
||||
return
|
||||
if nn[1] in self.session.broker.physical_nodes:
|
||||
# record the fact that this PhysicalNode is linked to a net
|
||||
dummy = CoreNodeBase(
|
||||
session=self.session, _id=nn[1], name="n%d" % nn[1], start=False
|
||||
)
|
||||
self.addphys(nn[0], dummy)
|
||||
|
||||
# TODO: remove need to handling old style messages
|
||||
def physnodeupdateposition(self, message):
|
||||
"""
|
||||
Snoop node messages belonging to physical nodes. The dummy object
|
||||
in self.phys[] records the node position.
|
||||
|
||||
:param message: message to handle
|
||||
:return: nothing
|
||||
"""
|
||||
nodenum = message.node_numbers()[0]
|
||||
try:
|
||||
dummy = self.phys[nodenum]
|
||||
nodexpos = message.get_tlv(NodeTlvs.X_POSITION.value)
|
||||
nodeypos = message.get_tlv(NodeTlvs.Y_POSITION.value)
|
||||
dummy.setposition(nodexpos, nodeypos, None)
|
||||
except KeyError:
|
||||
logging.exception("error retrieving physical node: %s", nodenum)
|
||||
|
||||
def installphysnodes(self, net):
|
||||
"""
|
||||
After installing a mobility model on a net, include any physical
|
||||
nodes that we have recorded. Use the GreTap tunnel to the physical node
|
||||
as the node's interface.
|
||||
|
||||
:param net: network to install
|
||||
:return: nothing
|
||||
"""
|
||||
node_ids = self.physnets.get(net.id, [])
|
||||
for node_id in node_ids:
|
||||
node = self.phys[node_id]
|
||||
# TODO: fix this bad logic, relating to depending on a break to get a valid server
|
||||
for server in self.session.broker.getserversbynode(node_id):
|
||||
break
|
||||
netif = self.session.broker.gettunnel(net.id, IpAddress.to_int(server.host))
|
||||
node.addnetif(netif, 0)
|
||||
netif.node = node
|
||||
x, y, z = netif.node.position.get()
|
||||
netif.poshook(netif, x, y, z)
|
||||
|
||||
|
||||
class WirelessModel(ConfigurableOptions):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue