added metaclass to reduce emane model code, fixed broken emaneuniversal references

This commit is contained in:
Blake J. Harnden 2018-03-30 12:52:10 -07:00
parent fd32e1cf78
commit 405614bbd8
7 changed files with 59 additions and 47 deletions

View file

@ -14,17 +14,14 @@ class EmaneBypassModel(emanemodel.EmaneModel):
# mac definitions
mac_library = "bypassmaclayer"
config_mac = [
mac_config = [
("none", ConfigDataTypes.BOOL.value, "0", "True,False",
"There are no parameters for the bypass model."),
]
# phy definitions
phy_library = "bypassphylayer"
config_phy = []
phy_config = []
# defines overall config
config_matrix = config_mac + config_phy
# gui display tabs
config_groups = "Bypass Parameters:1-1"
# override gui display tabs
config_groups_override = "Bypass Parameters:1-1"

View file

@ -31,9 +31,9 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
shim_xml = "/usr/share/emane/manifest/commeffectshim.xml"
shim_defaults = {}
config_shim = emanemanifest.parse(shim_xml, shim_defaults)
config_matrix = config_shim
config_groups = "CommEffect SHIM Parameters:1-%d" % len(config_matrix)
config_groups_override = "CommEffect SHIM Parameters:1-%d" % len(config_shim)
config_matrix_override = config_shim
def build_xml_files(self, emane_manager, interface):
"""

View file

@ -1048,10 +1048,10 @@ class EmaneGlobalModel(EmaneModel):
("nem_id_start", ConfigDataTypes.INT32.value, "1", "", "starting NEM ID"),
]
config_matrix = _confmatrix_platform + _confmatrix_nem
config_groups = "Platform Attributes:1-%d|NEM Parameters:%d-%d" % \
(len(_confmatrix_platform), len(_confmatrix_platform) + 1,
len(config_matrix))
config_matrix_override = _confmatrix_platform + _confmatrix_nem
config_groups_override = "Platform Attributes:1-%d|NEM Parameters:%d-%d" % \
(len(_confmatrix_platform), len(_confmatrix_platform) + 1,
len(config_matrix_override))
def __init__(self, session, object_id=None):
EmaneModel.__init__(self, session, object_id)

View file

@ -9,12 +9,6 @@ from core.mobility import WirelessModel
from core.xml import xmlutils
def create_config_groups(config_mac, config_matrix):
mac_len = len(config_mac)
config_len = len(config_matrix)
return "MAC Parameters:1-%d|PHY Parameters:%d-%d" % (mac_len, mac_len + 1, config_len)
def value_to_params(doc, name, value):
"""
Helper to convert a parameter to a paramlist. Returns an XML paramlist, or None if the value does not expand to
@ -40,17 +34,56 @@ def value_to_params(doc, name, value):
return xmlutils.add_param_list_to_parent(doc, parent=None, name=name, values=values)
class EmaneModelMetaClass(type):
"""
Hack into making class level properties to streamline emane model creation, until the Configurable class is
removed or refactored.
"""
@property
def config_matrix(cls):
"""
Convenience method for creating the config matrix, allow for a custom override.
:param EmaneModel cls: emane class
:return: config matrix value
:rtype: list
"""
if cls.config_matrix_override:
return cls.config_matrix_override
else:
return cls.mac_config + cls.phy_config
@property
def config_groups(cls):
"""
Convenience method for creating the config groups, allow for a custom override.
:param EmaneModel cls: emane class
:return: config groups value
:rtype: str
"""
if cls.config_groups_override:
return cls.config_groups_override
else:
mac_len = len(cls.mac_config)
config_len = len(cls.config_matrix)
return "MAC Parameters:1-%d|PHY Parameters:%d-%d" % (mac_len, mac_len + 1, config_len)
class EmaneModel(WirelessModel):
"""
EMANE models inherit from this parent class, which takes care of
handling configuration messages based on the list of
configurable parameters. Helper functions also live here.
"""
__metaclass__ = EmaneModelMetaClass
# default mac configuration settings
mac_library = None
mac_xml = None
mac_defaults = {}
config_mac = []
mac_config = []
# default phy configuration settings, using the universal model
phy_library = None
@ -60,11 +93,11 @@ class EmaneModel(WirelessModel):
"propagationmodel": "2ray",
"noisemode": "none"
}
config_phy = emanemanifest.parse(phy_xml, phy_defaults)
phy_config = emanemanifest.parse(phy_xml, phy_defaults)
config_ignore = set()
config_matrix = config_mac + config_phy
config_groups = create_config_groups(config_mac, config_matrix)
config_groups_override = None
config_matrix_override = None
def __init__(self, session, object_id=None):
WirelessModel.__init__(self, session, object_id)
@ -134,7 +167,7 @@ class EmaneModel(WirelessModel):
:rtype: xml.dom.minidom.Document
"""
names = list(self.getnames())
mac_names = names[:len(self.config_mac)]
mac_names = names[:len(self.mac_config)]
mac_document = emane_manager.xmldoc("mac")
mac_element = mac_document.getElementsByTagName("mac").pop()
@ -163,7 +196,7 @@ class EmaneModel(WirelessModel):
:rtype: xml.dom.minidom.Document
"""
names = list(self.getnames())
phy_names = names[len(self.config_mac):]
phy_names = names[len(self.mac_config):]
phy_document = emane_manager.xmldoc("phy")
phy_element = phy_document.getElementsByTagName("phy").pop()

View file

@ -16,10 +16,4 @@ class EmaneIeee80211abgModel(emanemodel.EmaneModel):
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/ieee80211abg/ieee80211pcr.xml",
}
config_mac = emanemanifest.parse(mac_xml, mac_defaults)
# defines overall config
config_matrix = config_mac + emanemodel.EmaneModel.config_phy
# gui display tabs
config_groups = emanemodel.create_config_groups(config_mac, config_matrix)
mac_config = emanemanifest.parse(mac_xml, mac_defaults)

View file

@ -16,10 +16,4 @@ class EmaneRfPipeModel(emanemodel.EmaneModel):
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/rfpipe/rfpipepcr.xml",
}
config_mac = emanemanifest.parse(mac_xml, mac_defaults)
# defines overall config
config_matrix = config_mac + emanemodel.EmaneModel.config_phy
# gui display tabs
config_groups = emanemodel.create_config_groups(config_mac, config_matrix)
mac_config = emanemanifest.parse(mac_xml, mac_defaults)

View file

@ -22,20 +22,14 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
mac_defaults = {
"pcrcurveuri": "/usr/share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml",
}
config_mac = emanemanifest.parse(mac_xml, mac_defaults)
mac_config = emanemanifest.parse(mac_xml, mac_defaults)
# add custom schedule options and ignore it when writing emane xml
schedule_name = "schedule"
default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml")
config_mac.insert(0, (schedule_name, ConfigDataTypes.STRING.value, default_schedule, "", "TDMA schedule file"))
mac_config.insert(0, (schedule_name, ConfigDataTypes.STRING.value, default_schedule, "", "TDMA schedule file"))
config_ignore = {schedule_name}
# defines overall config
config_matrix = config_mac + emanemodel.EmaneModel.config_phy
# gui display tabs
config_groups = emanemodel.create_config_groups(config_mac, config_matrix)
def post_startup(self, emane_manager):
"""
Logic to execute after the emane manager is finished with startup.