updates to account for config messages in core handlers that dont contain all configuration options
This commit is contained in:
parent
7abf4bca16
commit
4b9cf996d1
8 changed files with 85 additions and 90 deletions
|
@ -2,21 +2,19 @@
|
|||
Converts CORE data objects into legacy API messages.
|
||||
"""
|
||||
|
||||
from core import logger
|
||||
from core.api import coreapi
|
||||
from core.enumerations import ConfigTlvs
|
||||
from core.enumerations import NodeTlvs
|
||||
from core.misc import structutils
|
||||
|
||||
|
||||
def convert_node(node_data):
|
||||
"""
|
||||
Callback to handle an node broadcast out from a session.
|
||||
Convenience method for converting NodeData to a packed TLV message.
|
||||
|
||||
:param core.data.NodeData node_data: node data to handle
|
||||
:param core.data.NodeData node_data: node data to convert
|
||||
:return: packed node message
|
||||
"""
|
||||
logger.debug("converting node data to message: %s", node_data)
|
||||
|
||||
tlv_data = structutils.pack_values(coreapi.CoreNodeTlv, [
|
||||
(NodeTlvs.NUMBER, node_data.id),
|
||||
(NodeTlvs.TYPE, node_data.node_type),
|
||||
|
@ -39,5 +37,29 @@ def convert_node(node_data):
|
|||
(NodeTlvs.ICON, node_data.icon),
|
||||
(NodeTlvs.OPAQUE, node_data.opaque)
|
||||
])
|
||||
|
||||
return coreapi.CoreNodeMessage.pack(node_data.message_type, tlv_data)
|
||||
|
||||
|
||||
def convert_config(config_data):
|
||||
"""
|
||||
Convenience method for converting ConfigData to a packed TLV message.
|
||||
|
||||
:param core.data.ConfigData config_data: config data to convert
|
||||
:return: packed message
|
||||
"""
|
||||
tlv_data = structutils.pack_values(coreapi.CoreConfigTlv, [
|
||||
(ConfigTlvs.NODE, config_data.node),
|
||||
(ConfigTlvs.OBJECT, config_data.object),
|
||||
(ConfigTlvs.TYPE, config_data.type),
|
||||
(ConfigTlvs.DATA_TYPES, config_data.data_types),
|
||||
(ConfigTlvs.VALUES, config_data.data_values),
|
||||
(ConfigTlvs.CAPTIONS, config_data.captions),
|
||||
(ConfigTlvs.BITMAP, config_data.bitmap),
|
||||
(ConfigTlvs.POSSIBLE_VALUES, config_data.possible_values),
|
||||
(ConfigTlvs.GROUPS, config_data.groups),
|
||||
(ConfigTlvs.SESSION, config_data.session),
|
||||
(ConfigTlvs.INTERFACE_NUMBER, config_data.interface_number),
|
||||
(ConfigTlvs.NETWORK_ID, config_data.network_id),
|
||||
(ConfigTlvs.OPAQUE, config_data.opaque),
|
||||
])
|
||||
return coreapi.CoreConfMessage.pack(config_data.message_type, tlv_data)
|
||||
|
|
|
@ -14,13 +14,16 @@ from itertools import repeat
|
|||
|
||||
from core import logger
|
||||
from core.api import coreapi
|
||||
from core.api import dataconversion
|
||||
from core.conf import ConfigShim
|
||||
from core.data import ConfigData
|
||||
from core.data import EventData
|
||||
from core.emulator.emudata import InterfaceData
|
||||
from core.emulator.emudata import LinkOptions
|
||||
from core.emulator.emudata import NodeOptions
|
||||
from core.enumerations import ConfigTlvs, ConfigFlags, ConfigDataTypes
|
||||
from core.enumerations import ConfigDataTypes
|
||||
from core.enumerations import ConfigFlags
|
||||
from core.enumerations import ConfigTlvs
|
||||
from core.enumerations import EventTlvs
|
||||
from core.enumerations import EventTypes
|
||||
from core.enumerations import ExceptionTlvs
|
||||
|
@ -37,7 +40,8 @@ from core.enumerations import SessionTlvs
|
|||
from core.misc import nodeutils
|
||||
from core.misc import structutils
|
||||
from core.misc import utils
|
||||
from core.mobility import BasicRangeModel, Ns2ScriptedMobility
|
||||
from core.mobility import BasicRangeModel
|
||||
from core.mobility import Ns2ScriptedMobility
|
||||
from core.service import ServiceManager
|
||||
|
||||
|
||||
|
@ -265,24 +269,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
|
|||
:return: nothing
|
||||
"""
|
||||
logger.debug("handling broadcast config: %s", config_data)
|
||||
|
||||
tlv_data = structutils.pack_values(coreapi.CoreConfigTlv, [
|
||||
(ConfigTlvs.NODE, config_data.node),
|
||||
(ConfigTlvs.OBJECT, config_data.object),
|
||||
(ConfigTlvs.TYPE, config_data.type),
|
||||
(ConfigTlvs.DATA_TYPES, config_data.data_types),
|
||||
(ConfigTlvs.VALUES, config_data.data_values),
|
||||
(ConfigTlvs.CAPTIONS, config_data.captions),
|
||||
(ConfigTlvs.BITMAP, config_data.bitmap),
|
||||
(ConfigTlvs.POSSIBLE_VALUES, config_data.possible_values),
|
||||
(ConfigTlvs.GROUPS, config_data.groups),
|
||||
(ConfigTlvs.SESSION, config_data.session),
|
||||
(ConfigTlvs.INTERFACE_NUMBER, config_data.interface_number),
|
||||
(ConfigTlvs.NETWORK_ID, config_data.network_id),
|
||||
(ConfigTlvs.OPAQUE, config_data.opaque),
|
||||
])
|
||||
message = coreapi.CoreConfMessage.pack(config_data.message_type, tlv_data)
|
||||
|
||||
message = dataconversion.convert_config(config_data)
|
||||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
|
@ -319,31 +306,7 @@ class CoreHandler(SocketServer.BaseRequestHandler):
|
|||
:return: nothing
|
||||
"""
|
||||
logger.debug("handling broadcast node: %s", node_data)
|
||||
|
||||
tlv_data = structutils.pack_values(coreapi.CoreNodeTlv, [
|
||||
(NodeTlvs.NUMBER, node_data.id),
|
||||
(NodeTlvs.TYPE, node_data.node_type),
|
||||
(NodeTlvs.NAME, node_data.name),
|
||||
(NodeTlvs.IP_ADDRESS, node_data.ip_address),
|
||||
(NodeTlvs.MAC_ADDRESS, node_data.mac_address),
|
||||
(NodeTlvs.IP6_ADDRESS, node_data.ip6_address),
|
||||
(NodeTlvs.MODEL, node_data.model),
|
||||
(NodeTlvs.EMULATION_ID, node_data.emulation_id),
|
||||
(NodeTlvs.EMULATION_SERVER, node_data.emulation_server),
|
||||
(NodeTlvs.SESSION, node_data.session),
|
||||
(NodeTlvs.X_POSITION, node_data.x_position),
|
||||
(NodeTlvs.Y_POSITION, node_data.y_position),
|
||||
(NodeTlvs.CANVAS, node_data.canvas),
|
||||
(NodeTlvs.NETWORK_ID, node_data.network_id),
|
||||
(NodeTlvs.SERVICES, node_data.services),
|
||||
(NodeTlvs.LATITUDE, node_data.latitude),
|
||||
(NodeTlvs.LONGITUDE, node_data.longitude),
|
||||
(NodeTlvs.ALTITUDE, node_data.altitude),
|
||||
(NodeTlvs.ICON, node_data.icon),
|
||||
(NodeTlvs.OPAQUE, node_data.opaque)
|
||||
])
|
||||
message = coreapi.CoreNodeMessage.pack(node_data.message_type, tlv_data)
|
||||
|
||||
message = dataconversion.convert_node(node_data)
|
||||
try:
|
||||
self.sendall(message)
|
||||
except IOError:
|
||||
|
@ -1247,7 +1210,11 @@ class CoreHandler(SocketServer.BaseRequestHandler):
|
|||
if values_str:
|
||||
config = ConfigShim.str_to_dict(values_str)
|
||||
else:
|
||||
config = model_class.default_values()
|
||||
config = self.session.mobility.get_configs(node_id, object_name)
|
||||
|
||||
for name, value in model_class.default_values().iteritems():
|
||||
if name not in config:
|
||||
config[name] = value
|
||||
|
||||
self.session.mobility.set_configs(config, node_id, object_name)
|
||||
|
||||
|
@ -1339,7 +1306,11 @@ class CoreHandler(SocketServer.BaseRequestHandler):
|
|||
if values_str:
|
||||
config = ConfigShim.str_to_dict(values_str)
|
||||
else:
|
||||
config = model_class.default_values()
|
||||
config = self.session.emane.get_configs(node_id, object_name)
|
||||
|
||||
for name, value in model_class.default_values().iteritems():
|
||||
if name not in config:
|
||||
config[name] = value
|
||||
|
||||
self.session.emane.set_configs(config, node_id, object_name)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from core import CoreCommandError
|
|||
from core import constants
|
||||
from core import logger
|
||||
from core.api import coreapi
|
||||
from core.api import dataconversion
|
||||
from core.conf import ConfigShim
|
||||
from core.conf import Configuration
|
||||
from core.conf import NewConfigurableManager
|
||||
|
@ -20,11 +21,12 @@ from core.emane.emanemodel import EmaneModel
|
|||
from core.emane.ieee80211abg import EmaneIeee80211abgModel
|
||||
from core.emane.rfpipe import EmaneRfPipeModel
|
||||
from core.emane.tdma import EmaneTdmaModel
|
||||
from core.enumerations import ConfigDataTypes, NodeTypes
|
||||
from core.enumerations import ConfigDataTypes
|
||||
from core.enumerations import ConfigFlags
|
||||
from core.enumerations import ConfigTlvs
|
||||
from core.enumerations import MessageFlags
|
||||
from core.enumerations import MessageTypes
|
||||
from core.enumerations import NodeTypes
|
||||
from core.enumerations import RegisterTlvs
|
||||
from core.misc import nodeutils
|
||||
from core.misc import utils
|
||||
|
@ -459,9 +461,9 @@ class EmaneManager(NewConfigurableManager):
|
|||
typeflags = ConfigFlags.UPDATE.value
|
||||
self.set_config("platform_id_start", str(platformid))
|
||||
self.set_config("nem_id_start", str(nemid))
|
||||
msg = ConfigShim.config_data(0, None, typeflags, self.emane_config, self.get_configs())
|
||||
# TODO: this needs to be converted into a sendable TLV message
|
||||
server.sock.send(msg)
|
||||
config_data = ConfigShim.config_data(0, None, typeflags, self.emane_config, self.get_configs())
|
||||
message = dataconversion.convert_config(config_data)
|
||||
server.sock.send(message)
|
||||
# increment nemid for next server by number of interfaces
|
||||
with self._ifccountslock:
|
||||
if server in self._ifccounts:
|
||||
|
|
|
@ -77,7 +77,7 @@ class EmaneNode(EmaneNet):
|
|||
# when buildnemxml() is called, not during init()
|
||||
self.model = model(session=self.session, object_id=self.objid)
|
||||
elif model.config_type == RegisterTlvs.MOBILITY.value:
|
||||
self.mobility = model(session=self.session, object_id=self.objid, values=config)
|
||||
self.mobility = model(session=self.session, object_id=self.objid, config=config)
|
||||
|
||||
def setnemid(self, netif, nemid):
|
||||
"""
|
||||
|
|
|
@ -108,7 +108,7 @@ class MobilityManager(NewConfigurableManager):
|
|||
logger.info("setting mobility model(%s) to node: %s", model_name, model_config)
|
||||
node.setmodel(clazz, model_config)
|
||||
except KeyError:
|
||||
logger.error("skipping mobility configuration for unknown model: %s", model_name)
|
||||
logger.exception("skipping mobility configuration for unknown model: %s", model_name)
|
||||
continue
|
||||
|
||||
if self.session.master:
|
||||
|
@ -328,13 +328,13 @@ class WirelessModel(ConfigurableOptions):
|
|||
bitmap = None
|
||||
position_callback = None
|
||||
|
||||
def __init__(self, session, object_id, values=None):
|
||||
def __init__(self, session, object_id, config=None):
|
||||
"""
|
||||
Create a WirelessModel instance.
|
||||
|
||||
:param core.session.Session session: core session we are tied to
|
||||
:param int object_id: object id
|
||||
:param values: values
|
||||
:param dict config: values
|
||||
"""
|
||||
self.session = session
|
||||
self.object_id = object_id
|
||||
|
@ -395,13 +395,13 @@ class BasicRangeModel(WirelessModel):
|
|||
def config_groups(cls):
|
||||
return "Basic Range Parameters:1-%d" % len(cls.configurations())
|
||||
|
||||
def __init__(self, session, object_id, values=None):
|
||||
def __init__(self, session, object_id, config=None):
|
||||
"""
|
||||
Create a BasicRangeModel instance.
|
||||
|
||||
:param core.session.Session session: related core session
|
||||
:param int object_id: object id
|
||||
:param dict values: values
|
||||
:param dict config: values
|
||||
"""
|
||||
super(BasicRangeModel, self).__init__(session=session, object_id=object_id)
|
||||
self.session = session
|
||||
|
@ -410,9 +410,9 @@ class BasicRangeModel(WirelessModel):
|
|||
self._netifslock = threading.Lock()
|
||||
|
||||
# TODO: can this be handled in a better spot
|
||||
if not values:
|
||||
values = self.default_values()
|
||||
self.session.mobility.set_configs(values, node_id=object_id, config_type=self.name)
|
||||
if not config:
|
||||
config = self.default_values()
|
||||
self.session.mobility.set_configs(config, node_id=object_id, config_type=self.name)
|
||||
|
||||
self.range = None
|
||||
self.bw = None
|
||||
|
@ -420,7 +420,7 @@ class BasicRangeModel(WirelessModel):
|
|||
self.loss = None
|
||||
self.jitter = None
|
||||
|
||||
self.values_from_config(values)
|
||||
self.values_from_config(config)
|
||||
|
||||
def values_from_config(self, config):
|
||||
"""
|
||||
|
@ -430,7 +430,7 @@ class BasicRangeModel(WirelessModel):
|
|||
:return: nothing
|
||||
"""
|
||||
self.range = float(config["range"])
|
||||
logger.info("Basic range model configured for WLAN %d using range %d", self.wlan.objid, self.range)
|
||||
logger.info("basic range model configured for WLAN %d using range %d", self.wlan.objid, self.range)
|
||||
self.bw = int(config["bandwidth"])
|
||||
if self.bw == 0.0:
|
||||
self.bw = None
|
||||
|
@ -680,16 +680,16 @@ class WayPointMobility(WirelessModel):
|
|||
STATE_RUNNING = 1
|
||||
STATE_PAUSED = 2
|
||||
|
||||
def __init__(self, session, object_id, values=None):
|
||||
def __init__(self, session, object_id, config=None):
|
||||
"""
|
||||
Create a WayPointMobility instance.
|
||||
|
||||
:param core.session.Session session: CORE session instance
|
||||
:param int object_id: object id
|
||||
:param values: values for this model
|
||||
:param config: values for this model
|
||||
:return:
|
||||
"""
|
||||
super(WayPointMobility, self).__init__(session=session, object_id=object_id, values=values)
|
||||
super(WayPointMobility, self).__init__(session=session, object_id=object_id, config=config)
|
||||
|
||||
self.state = self.STATE_STOPPED
|
||||
self.queue = []
|
||||
|
@ -1002,30 +1002,30 @@ class Ns2ScriptedMobility(WayPointMobility):
|
|||
def config_groups(cls):
|
||||
return "ns-2 Mobility Script Parameters:1-%d" % len(cls.configurations())
|
||||
|
||||
def __init__(self, session, object_id, values=None):
|
||||
def __init__(self, session, object_id, config=None):
|
||||
"""
|
||||
Creates a Ns2ScriptedMobility instance.
|
||||
|
||||
:param core.session.Session session: CORE session instance
|
||||
:param int object_id: object id
|
||||
:param values: values
|
||||
:param config: values
|
||||
"""
|
||||
super(Ns2ScriptedMobility, self).__init__(session=session, object_id=object_id, values=values)
|
||||
super(Ns2ScriptedMobility, self).__init__(session=session, object_id=object_id, config=config)
|
||||
self._netifs = {}
|
||||
self._netifslock = threading.Lock()
|
||||
|
||||
if not values:
|
||||
values = self.default_values()
|
||||
self.session.mobility.set_configs(values, node_id=object_id, config_type=self.name)
|
||||
if not config:
|
||||
config = self.default_values()
|
||||
self.session.mobility.set_configs(config, node_id=object_id, config_type=self.name)
|
||||
|
||||
self.file = values["file"]
|
||||
self.refresh_ms = int(values["refresh_ms"])
|
||||
self.loop = values["loop"].lower() == "on"
|
||||
self.autostart = values["autostart"]
|
||||
self.parsemap(values["map"])
|
||||
self.script_start = values["script_start"]
|
||||
self.script_pause = values["script_pause"]
|
||||
self.script_stop = values["script_stop"]
|
||||
self.file = config["file"]
|
||||
self.refresh_ms = int(config["refresh_ms"])
|
||||
self.loop = config["loop"].lower() == "on"
|
||||
self.autostart = config["autostart"]
|
||||
self.parsemap(config["map"])
|
||||
self.script_start = config["script_start"]
|
||||
self.script_pause = config["script_pause"]
|
||||
self.script_stop = config["script_stop"]
|
||||
logger.info("ns-2 scripted mobility configured for WLAN %d using file: %s", object_id, self.file)
|
||||
self.readscriptfile()
|
||||
self.copywaypoints()
|
||||
|
|
|
@ -387,7 +387,7 @@ class WlanNode(LxBrNet):
|
|||
"""
|
||||
logger.info("adding model: %s", model.name)
|
||||
if model.config_type == RegisterTlvs.WIRELESS.value:
|
||||
self.model = model(session=self.session, object_id=self.objid, values=config)
|
||||
self.model = model(session=self.session, object_id=self.objid, config=config)
|
||||
if self.model.position_callback:
|
||||
for netif in self.netifs():
|
||||
netif.poshook = self.model.position_callback
|
||||
|
@ -396,7 +396,7 @@ class WlanNode(LxBrNet):
|
|||
netif.poshook(netif, x, y, z)
|
||||
self.model.setlinkparams()
|
||||
elif model.config_type == RegisterTlvs.MOBILITY.value:
|
||||
self.mobility = model(session=self.session, object_id=self.objid, values=config)
|
||||
self.mobility = model(session=self.session, object_id=self.objid, config=config)
|
||||
|
||||
def updatemodel(self, model_name, config):
|
||||
"""
|
||||
|
|
|
@ -600,7 +600,7 @@ class OvsWlanNode(OvsNet):
|
|||
logger.info("adding model %s", model.name)
|
||||
|
||||
if model.type == RegisterTlvs.WIRELESS.value:
|
||||
self.model = model(session=self.session, object_id=self.objid, values=config)
|
||||
self.model = model(session=self.session, object_id=self.objid, config=config)
|
||||
if self.model.position_callback:
|
||||
for interface in self.netifs():
|
||||
interface.poshook = self.model.position_callback
|
||||
|
@ -609,7 +609,7 @@ class OvsWlanNode(OvsNet):
|
|||
interface.poshook(interface, x, y, z)
|
||||
self.model.setlinkparams()
|
||||
elif model.type == RegisterTlvs.MOBILITY.value:
|
||||
self.mobility = model(session=self.session, object_id=self.objid, values=config)
|
||||
self.mobility = model(session=self.session, object_id=self.objid, config=config)
|
||||
|
||||
def updatemodel(self, model_name, values):
|
||||
"""
|
||||
|
|
|
@ -488,7 +488,7 @@ class Ns3Session(Session):
|
|||
Start a tracing thread using the ASCII output from the ns3
|
||||
mobility helper.
|
||||
"""
|
||||
net.mobility = WayPointMobility(session=self, object_id=net.objid, values=None)
|
||||
net.mobility = WayPointMobility(session=self, object_id=net.objid, config=None)
|
||||
net.mobility.setendtime()
|
||||
net.mobility.refresh_ms = 300
|
||||
net.mobility.empty_queue_stop = False
|
||||
|
|
Loading…
Reference in a new issue