added metaclass to reduce emane model code, fixed broken emaneuniversal references
This commit is contained in:
parent
fd32e1cf78
commit
405614bbd8
7 changed files with 59 additions and 47 deletions
|
@ -14,17 +14,14 @@ class EmaneBypassModel(emanemodel.EmaneModel):
|
||||||
|
|
||||||
# mac definitions
|
# mac definitions
|
||||||
mac_library = "bypassmaclayer"
|
mac_library = "bypassmaclayer"
|
||||||
config_mac = [
|
mac_config = [
|
||||||
("none", ConfigDataTypes.BOOL.value, "0", "True,False",
|
("none", ConfigDataTypes.BOOL.value, "0", "True,False",
|
||||||
"There are no parameters for the bypass model."),
|
"There are no parameters for the bypass model."),
|
||||||
]
|
]
|
||||||
|
|
||||||
# phy definitions
|
# phy definitions
|
||||||
phy_library = "bypassphylayer"
|
phy_library = "bypassphylayer"
|
||||||
config_phy = []
|
phy_config = []
|
||||||
|
|
||||||
# defines overall config
|
# override gui display tabs
|
||||||
config_matrix = config_mac + config_phy
|
config_groups_override = "Bypass Parameters:1-1"
|
||||||
|
|
||||||
# gui display tabs
|
|
||||||
config_groups = "Bypass Parameters:1-1"
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
|
||||||
shim_xml = "/usr/share/emane/manifest/commeffectshim.xml"
|
shim_xml = "/usr/share/emane/manifest/commeffectshim.xml"
|
||||||
shim_defaults = {}
|
shim_defaults = {}
|
||||||
config_shim = emanemanifest.parse(shim_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):
|
def build_xml_files(self, emane_manager, interface):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1048,10 +1048,10 @@ class EmaneGlobalModel(EmaneModel):
|
||||||
("nem_id_start", ConfigDataTypes.INT32.value, "1", "", "starting NEM ID"),
|
("nem_id_start", ConfigDataTypes.INT32.value, "1", "", "starting NEM ID"),
|
||||||
]
|
]
|
||||||
|
|
||||||
config_matrix = _confmatrix_platform + _confmatrix_nem
|
config_matrix_override = _confmatrix_platform + _confmatrix_nem
|
||||||
config_groups = "Platform Attributes:1-%d|NEM Parameters:%d-%d" % \
|
config_groups_override = "Platform Attributes:1-%d|NEM Parameters:%d-%d" % \
|
||||||
(len(_confmatrix_platform), len(_confmatrix_platform) + 1,
|
(len(_confmatrix_platform), len(_confmatrix_platform) + 1,
|
||||||
len(config_matrix))
|
len(config_matrix_override))
|
||||||
|
|
||||||
def __init__(self, session, object_id=None):
|
def __init__(self, session, object_id=None):
|
||||||
EmaneModel.__init__(self, session, object_id)
|
EmaneModel.__init__(self, session, object_id)
|
||||||
|
|
|
@ -9,12 +9,6 @@ from core.mobility import WirelessModel
|
||||||
from core.xml import xmlutils
|
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):
|
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
|
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)
|
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):
|
class EmaneModel(WirelessModel):
|
||||||
"""
|
"""
|
||||||
EMANE models inherit from this parent class, which takes care of
|
EMANE models inherit from this parent class, which takes care of
|
||||||
handling configuration messages based on the list of
|
handling configuration messages based on the list of
|
||||||
configurable parameters. Helper functions also live here.
|
configurable parameters. Helper functions also live here.
|
||||||
"""
|
"""
|
||||||
|
__metaclass__ = EmaneModelMetaClass
|
||||||
|
|
||||||
# default mac configuration settings
|
# default mac configuration settings
|
||||||
mac_library = None
|
mac_library = None
|
||||||
mac_xml = None
|
mac_xml = None
|
||||||
mac_defaults = {}
|
mac_defaults = {}
|
||||||
config_mac = []
|
mac_config = []
|
||||||
|
|
||||||
# default phy configuration settings, using the universal model
|
# default phy configuration settings, using the universal model
|
||||||
phy_library = None
|
phy_library = None
|
||||||
|
@ -60,11 +93,11 @@ class EmaneModel(WirelessModel):
|
||||||
"propagationmodel": "2ray",
|
"propagationmodel": "2ray",
|
||||||
"noisemode": "none"
|
"noisemode": "none"
|
||||||
}
|
}
|
||||||
config_phy = emanemanifest.parse(phy_xml, phy_defaults)
|
phy_config = emanemanifest.parse(phy_xml, phy_defaults)
|
||||||
|
|
||||||
config_ignore = set()
|
config_ignore = set()
|
||||||
config_matrix = config_mac + config_phy
|
config_groups_override = None
|
||||||
config_groups = create_config_groups(config_mac, config_matrix)
|
config_matrix_override = None
|
||||||
|
|
||||||
def __init__(self, session, object_id=None):
|
def __init__(self, session, object_id=None):
|
||||||
WirelessModel.__init__(self, session, object_id)
|
WirelessModel.__init__(self, session, object_id)
|
||||||
|
@ -134,7 +167,7 @@ class EmaneModel(WirelessModel):
|
||||||
:rtype: xml.dom.minidom.Document
|
:rtype: xml.dom.minidom.Document
|
||||||
"""
|
"""
|
||||||
names = list(self.getnames())
|
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_document = emane_manager.xmldoc("mac")
|
||||||
mac_element = mac_document.getElementsByTagName("mac").pop()
|
mac_element = mac_document.getElementsByTagName("mac").pop()
|
||||||
|
@ -163,7 +196,7 @@ class EmaneModel(WirelessModel):
|
||||||
:rtype: xml.dom.minidom.Document
|
:rtype: xml.dom.minidom.Document
|
||||||
"""
|
"""
|
||||||
names = list(self.getnames())
|
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_document = emane_manager.xmldoc("phy")
|
||||||
phy_element = phy_document.getElementsByTagName("phy").pop()
|
phy_element = phy_document.getElementsByTagName("phy").pop()
|
||||||
|
|
|
@ -16,10 +16,4 @@ class EmaneIeee80211abgModel(emanemodel.EmaneModel):
|
||||||
mac_defaults = {
|
mac_defaults = {
|
||||||
"pcrcurveuri": "/usr/share/emane/xml/models/mac/ieee80211abg/ieee80211pcr.xml",
|
"pcrcurveuri": "/usr/share/emane/xml/models/mac/ieee80211abg/ieee80211pcr.xml",
|
||||||
}
|
}
|
||||||
config_mac = emanemanifest.parse(mac_xml, mac_defaults)
|
mac_config = 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)
|
|
||||||
|
|
|
@ -16,10 +16,4 @@ class EmaneRfPipeModel(emanemodel.EmaneModel):
|
||||||
mac_defaults = {
|
mac_defaults = {
|
||||||
"pcrcurveuri": "/usr/share/emane/xml/models/mac/rfpipe/rfpipepcr.xml",
|
"pcrcurveuri": "/usr/share/emane/xml/models/mac/rfpipe/rfpipepcr.xml",
|
||||||
}
|
}
|
||||||
config_mac = emanemanifest.parse(mac_xml, mac_defaults)
|
mac_config = 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)
|
|
||||||
|
|
|
@ -22,20 +22,14 @@ class EmaneTdmaModel(emanemodel.EmaneModel):
|
||||||
mac_defaults = {
|
mac_defaults = {
|
||||||
"pcrcurveuri": "/usr/share/emane/xml/models/mac/tdmaeventscheduler/tdmabasemodelpcr.xml",
|
"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
|
# add custom schedule options and ignore it when writing emane xml
|
||||||
schedule_name = "schedule"
|
schedule_name = "schedule"
|
||||||
default_schedule = os.path.join(constants.CORE_DATA_DIR, "examples", "tdma", "schedule.xml")
|
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}
|
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):
|
def post_startup(self, emane_manager):
|
||||||
"""
|
"""
|
||||||
Logic to execute after the emane manager is finished with startup.
|
Logic to execute after the emane manager is finished with startup.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue