refactored configuration managers and options into a single class, now the models that can be configured will deal with and handle configurations for nodes themselves

This commit is contained in:
Blake J. Harnden 2018-06-11 12:26:12 -07:00
parent 1b843e2868
commit 52230bc026
22 changed files with 284 additions and 422 deletions

View file

@ -70,9 +70,6 @@ class EmaneModel(WirelessModel):
config_len = len(cls.configurations())
return "MAC Parameters:1-%d|PHY Parameters:%d-%d" % (mac_len, mac_len + 1, config_len)
def __init__(self, session, object_id=None):
super(EmaneModel, self).__init__(session, object_id)
def build_xml_files(self, emane_manager, interface):
"""
Builds xml files for emane. Includes a nem.xml file that points to both mac.xml and phy.xml definitions.
@ -82,7 +79,7 @@ class EmaneModel(WirelessModel):
:return: nothing
"""
# retrieve configuration values
config = emane_manager.getifcconfig(self.object_id, self.name, self.default_values(), interface)
config = self.getifcconfig(self.object_id, interface)
if not config:
return
@ -270,11 +267,10 @@ class EmaneModel(WirelessModel):
:rtype: str
"""
name = "n%s" % self.object_id
emane_manager = self.session.emane
if interface:
node_id = interface.node.objid
if emane_manager.getifcconfig(node_id, self.name, {}, interface):
if self.getifcconfig(node_id, interface):
name = interface.localname.replace(".", "_")
return "%s%s" % (name, self.name)
@ -353,3 +349,43 @@ class EmaneModel(WirelessModel):
:return: nothing
"""
logger.warn("emane model(%s) does not support link configuration", self.name)
def getifcconfig(self, node_id, ifc):
"""
Retrieve interface configuration or node configuration if not provided.
:param int node_id: node id
:param ifc: node interface
:return:
"""
# use the network-wide config values or interface(NEM)-specific values?
if ifc is None:
return self.get_configs(node_id)
else:
# don"t use default values when interface config is the same as net
# note here that using ifc.node.objid as key allows for only one type
# of each model per node;
# TODO: use both node and interface as key
# Adamson change: first check for iface config keyed by "node:ifc.name"
# (so that nodes w/ multiple interfaces of same conftype can have
# different configs for each separate interface)
key = 1000 * ifc.node.objid
if ifc.netindex is not None:
key += ifc.netindex
# try retrieve interface specific configuration, avoid getting defaults
config = {}
if key in self.configuration_maps:
config = self.get_configs(key)
# otherwise retrieve the interfaces node configuration, avoid using defaults
if not config and ifc.node.objid in self.configuration_maps:
config = self.get_configs(ifc.node.objid)
if not config and ifc.transport_type == "raw":
# with EMANE 0.9.2+, we need an extra NEM XML from
# model.buildnemxmlfiles(), so defaults are returned here
config = self.get_configs(node_id)
return config