initial sweeping changes to call all usages of various interface related variables and functions (netif, interface, if, ifc, etc) to use a consistent name iface

This commit is contained in:
Blake Harnden 2020-06-16 09:30:16 -07:00
parent 0462c1b084
commit 0725199d6d
93 changed files with 1955 additions and 2156 deletions

View file

@ -63,7 +63,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
return [ConfigGroup("CommEffect SHIM Parameters", 1, len(cls.configurations()))]
def build_xml_files(
self, config: Dict[str, str], interface: CoreInterface = None
self, config: Dict[str, str], iface: CoreInterface = None
) -> None:
"""
Build the necessary nem and commeffect XMLs in the given path.
@ -72,17 +72,17 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
nXXemane_commeffectnem.xml, nXXemane_commeffectshim.xml are used.
:param config: emane model configuration for the node and interface
:param interface: interface for the emane node
:param iface: interface for the emane node
:return: nothing
"""
# retrieve xml names
nem_name = emanexml.nem_file_name(self, interface)
shim_name = emanexml.shim_file_name(self, interface)
nem_name = emanexml.nem_file_name(self, iface)
shim_name = emanexml.shim_file_name(self, iface)
# create and write nem document
nem_element = etree.Element("nem", name=f"{self.name} NEM", type="unstructured")
transport_type = TransportType.VIRTUAL
if interface and interface.transport_type == TransportType.RAW:
if iface and iface.transport_type == TransportType.RAW:
transport_type = TransportType.RAW
transport_file = emanexml.transport_file_name(self.id, transport_type)
etree.SubElement(nem_element, "transport", definition=transport_file)
@ -115,7 +115,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
emanexml.create_file(shim_element, "shim", shim_file)
def linkconfig(
self, netif: CoreInterface, options: LinkOptions, netif2: CoreInterface = None
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None
) -> None:
"""
Generate CommEffect events when a Link Message is received having
@ -126,7 +126,7 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
logging.warning("%s: EMANE event service unavailable", self.name)
return
if netif is None or netif2 is None:
if iface is None or iface2 is None:
logging.warning("%s: missing NEM information", self.name)
return
@ -134,8 +134,8 @@ class EmaneCommEffectModel(emanemodel.EmaneModel):
# TODO: may want to split out seconds portion of delay and jitter
event = CommEffectEvent()
emane_node = self.session.get_node(self.id, EmaneNet)
nemid = emane_node.getnemid(netif)
nemid2 = emane_node.getnemid(netif2)
nemid = emane_node.getnemid(iface)
nemid2 = emane_node.getnemid(iface2)
logging.info("sending comm effect event")
event.append(
nemid,

View file

@ -111,41 +111,39 @@ class EmaneManager(ModelManager):
self.event_device: Optional[str] = None
self.emane_check()
def getifcconfig(
self, node_id: int, interface: CoreInterface, model_name: str
def get_iface_config(
self, node_id: int, iface: CoreInterface, model_name: str
) -> Dict[str, str]:
"""
Retrieve interface configuration or node configuration if not provided.
:param node_id: node id
:param interface: node interface
:param iface: node interface
:param model_name: model to get configuration for
:return: node/interface model configuration
"""
# use the network-wide config values or interface(NEM)-specific values?
if interface is None:
if iface is None:
return self.get_configs(node_id=node_id, config_type=model_name)
else:
# don"t use default values when interface config is the same as net
# note here that using ifc.node.id as key allows for only one type
# note here that using iface.node.id 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"
# Adamson change: first check for iface config keyed by "node:iface.name"
# (so that nodes w/ multiple interfaces of same conftype can have
# different configs for each separate interface)
key = 1000 * interface.node.id
if interface.netindex is not None:
key += interface.netindex
key = 1000 * iface.node.id
if iface.node_id is not None:
key += iface.node_id
# try retrieve interface specific configuration, avoid getting defaults
config = self.get_configs(node_id=key, config_type=model_name)
# otherwise retrieve the interfaces node configuration, avoid using defaults
if not config:
config = self.get_configs(
node_id=interface.node.id, config_type=model_name
)
config = self.get_configs(node_id=iface.node.id, config_type=model_name)
# get non interface config, when none found
if not config:
@ -265,8 +263,8 @@ class EmaneManager(ModelManager):
# assumes self._objslock already held
nodes = set()
for emane_net in self._emane_nets.values():
for netif in emane_net.netifs():
nodes.add(netif.node)
for iface in emane_net.get_ifaces():
nodes.add(iface.node)
return nodes
def setup(self) -> int:
@ -352,13 +350,13 @@ class EmaneManager(ModelManager):
if self.numnems() > 0:
self.startdaemons()
self.installnetifs()
self.install_ifaces()
for node_id in self._emane_nets:
emane_node = self._emane_nets[node_id]
for netif in emane_node.netifs():
for iface in emane_node.get_ifaces():
nems.append(
(netif.node.name, netif.name, emane_node.getnemid(netif))
(iface.node.name, iface.name, emane_node.getnemid(iface))
)
if nems:
@ -392,8 +390,8 @@ class EmaneManager(ModelManager):
emane_node.name,
)
emane_node.model.post_startup()
for netif in emane_node.netifs():
netif.setposition()
for iface in emane_node.get_ifaces():
iface.setposition()
def reset(self) -> None:
"""
@ -420,7 +418,7 @@ class EmaneManager(ModelManager):
logging.info("stopping EMANE daemons")
if self.links_enabled():
self.link_monitor.stop()
self.deinstallnetifs()
self.deinstall_ifaces()
self.stopdaemons()
self.stopeventmonitor()
@ -474,31 +472,31 @@ class EmaneManager(ModelManager):
EMANE network and NEM interface.
"""
emane_node = None
netif = None
iface = None
for node_id in self._emane_nets:
emane_node = self._emane_nets[node_id]
netif = emane_node.getnemnetif(nemid)
if netif is not None:
iface = emane_node.get_nem_iface(nemid)
if iface is not None:
break
else:
emane_node = None
return emane_node, netif
return emane_node, iface
def get_nem_link(
self, nem1: int, nem2: int, flags: MessageFlags = MessageFlags.NONE
) -> Optional[LinkData]:
emane1, netif = self.nemlookup(nem1)
if not emane1 or not netif:
emane1, iface = self.nemlookup(nem1)
if not emane1 or not iface:
logging.error("invalid nem: %s", nem1)
return None
node1 = netif.node
emane2, netif = self.nemlookup(nem2)
if not emane2 or not netif:
node1 = iface.node
emane2, iface = self.nemlookup(nem2)
if not emane2 or not iface:
logging.error("invalid nem: %s", nem2)
return None
node2 = netif.node
node2 = iface.node
color = self.session.get_link_color(emane1.id)
return LinkData(
message_type=flags,
@ -516,7 +514,7 @@ class EmaneManager(ModelManager):
count = 0
for node_id in self._emane_nets:
emane_node = self._emane_nets[node_id]
count += len(emane_node.netifs())
count += len(emane_node.ifaces)
return count
def buildplatformxml(self, ctrlnet: CtrlNet) -> None:
@ -607,19 +605,19 @@ class EmaneManager(ModelManager):
n = node.id
# control network not yet started here
self.session.add_remove_control_interface(
self.session.add_remove_control_iface(
node, 0, remove=False, conf_required=False
)
if otanetidx > 0:
logging.info("adding ota device ctrl%d", otanetidx)
self.session.add_remove_control_interface(
self.session.add_remove_control_iface(
node, otanetidx, remove=False, conf_required=False
)
if eventservicenetidx >= 0:
logging.info("adding event service device ctrl%d", eventservicenetidx)
self.session.add_remove_control_interface(
self.session.add_remove_control_iface(
node, eventservicenetidx, remove=False, conf_required=False
)
@ -676,23 +674,23 @@ class EmaneManager(ModelManager):
except CoreCommandError:
logging.exception("error shutting down emane daemons")
def installnetifs(self) -> None:
def install_ifaces(self) -> None:
"""
Install TUN/TAP virtual interfaces into their proper namespaces
now that the EMANE daemons are running.
"""
for key in sorted(self._emane_nets.keys()):
emane_node = self._emane_nets[key]
logging.info("emane install netifs for node: %d", key)
emane_node.installnetifs()
node = self._emane_nets[key]
logging.info("emane install interface for node(%s): %d", node.name, key)
node.install_ifaces()
def deinstallnetifs(self) -> None:
def deinstall_ifaces(self) -> None:
"""
Uninstall TUN/TAP virtual interfaces.
"""
for key in sorted(self._emane_nets.keys()):
emane_node = self._emane_nets[key]
emane_node.deinstallnetifs()
emane_node.deinstall_ifaces()
def doeventmonitor(self) -> bool:
"""
@ -808,12 +806,12 @@ class EmaneManager(ModelManager):
Returns True if successfully parsed and a Node Message was sent.
"""
# convert nemid to node number
_emanenode, netif = self.nemlookup(nemid)
if netif is None:
_emanenode, iface = self.nemlookup(nemid)
if iface is None:
logging.info("location event for unknown NEM %s", nemid)
return False
n = netif.node.id
n = iface.node.id
# convert from lat/long/alt to x,y,z coordinates
x, y, z = self.session.location.getxyz(lat, lon, alt)
x = int(x)

View file

@ -97,28 +97,28 @@ class EmaneModel(WirelessModel):
]
def build_xml_files(
self, config: Dict[str, str], interface: CoreInterface = None
self, config: Dict[str, str], iface: CoreInterface = None
) -> None:
"""
Builds xml files for this emane model. Creates a nem.xml file that points to
both mac.xml and phy.xml definitions.
:param config: emane model configuration for the node and interface
:param interface: interface for the emane node
:param iface: interface for the emane node
:return: nothing
"""
nem_name = emanexml.nem_file_name(self, interface)
mac_name = emanexml.mac_file_name(self, interface)
phy_name = emanexml.phy_file_name(self, interface)
nem_name = emanexml.nem_file_name(self, iface)
mac_name = emanexml.mac_file_name(self, iface)
phy_name = emanexml.phy_file_name(self, iface)
# remote server for file
server = None
if interface is not None:
server = interface.node.server
if iface is not None:
server = iface.node.server
# check if this is external
transport_type = TransportType.VIRTUAL
if interface and interface.transport_type == TransportType.RAW:
if iface and iface.transport_type == TransportType.RAW:
transport_type = TransportType.RAW
transport_name = emanexml.transport_file_name(self.id, transport_type)
@ -144,31 +144,31 @@ class EmaneModel(WirelessModel):
"""
logging.debug("emane model(%s) has no post setup tasks", self.name)
def update(self, moved: List[CoreNode], moved_netifs: List[CoreInterface]) -> None:
def update(self, moved: List[CoreNode], moved_ifaces: List[CoreInterface]) -> None:
"""
Invoked from MobilityModel when nodes are moved; this causes
emane location events to be generated for the nodes in the moved
list, making EmaneModels compatible with Ns2ScriptedMobility.
:param moved: moved nodes
:param moved_netifs: interfaces that were moved
:param moved_ifaces: interfaces that were moved
:return: nothing
"""
try:
wlan = self.session.get_node(self.id, EmaneNet)
wlan.setnempositions(moved_netifs)
wlan.setnempositions(moved_ifaces)
except CoreError:
logging.exception("error during update")
def linkconfig(
self, netif: CoreInterface, options: LinkOptions, netif2: CoreInterface = None
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None
) -> None:
"""
Invoked when a Link Message is received. Default is unimplemented.
:param netif: interface one
:param iface: interface one
:param options: options for configuring link
:param netif2: interface two
:param iface2: interface two
:return: nothing
"""
logging.warning("emane model(%s) does not support link config", self.name)

View file

@ -212,10 +212,10 @@ class EmaneLinkMonitor:
addresses = []
nodes = self.emane_manager.getnodes()
for node in nodes:
for netif in node.netifs():
if isinstance(netif.net, CtrlNet):
for iface in node.get_ifaces():
if isinstance(iface.net, CtrlNet):
ip4 = None
for x in netif.addrlist:
for x in iface.addrlist:
address, prefix = x.split("/")
if netaddr.valid_ipv4(address):
ip4 = address

View file

@ -64,14 +64,14 @@ class EmaneNet(CoreNetworkBase):
self.mobility: Optional[WayPointMobility] = None
def linkconfig(
self, netif: CoreInterface, options: LinkOptions, netif2: CoreInterface = None
self, iface: CoreInterface, options: LinkOptions, iface2: CoreInterface = None
) -> None:
"""
The CommEffect model supports link configuration.
"""
if not self.model:
return
self.model.linkconfig(netif, options, netif2)
self.model.linkconfig(iface, options, iface2)
def config(self, conf: str) -> None:
self.conf = conf
@ -82,10 +82,10 @@ class EmaneNet(CoreNetworkBase):
def shutdown(self) -> None:
pass
def link(self, netif1: CoreInterface, netif2: CoreInterface) -> None:
def link(self, iface1: CoreInterface, iface2: CoreInterface) -> None:
pass
def unlink(self, netif1: CoreInterface, netif2: CoreInterface) -> None:
def unlink(self, iface1: CoreInterface, iface2: CoreInterface) -> None:
pass
def linknet(self, net: "CoreNetworkBase") -> CoreInterface:
@ -113,39 +113,33 @@ class EmaneNet(CoreNetworkBase):
self.mobility = model(session=self.session, _id=self.id)
self.mobility.update_config(config)
def setnemid(self, netif: CoreInterface, nemid: int) -> None:
def setnemid(self, iface: CoreInterface, nemid: int) -> None:
"""
Record an interface to numerical ID mapping. The Emane controller
object manages and assigns these IDs for all NEMs.
"""
self.nemidmap[netif] = nemid
self.nemidmap[iface] = nemid
def getnemid(self, netif: CoreInterface) -> Optional[int]:
def getnemid(self, iface: CoreInterface) -> Optional[int]:
"""
Given an interface, return its numerical ID.
"""
if netif not in self.nemidmap:
if iface not in self.nemidmap:
return None
else:
return self.nemidmap[netif]
return self.nemidmap[iface]
def getnemnetif(self, nemid: int) -> Optional[CoreInterface]:
def get_nem_iface(self, nemid: int) -> Optional[CoreInterface]:
"""
Given a numerical NEM ID, return its interface. This returns the
first interface that matches the given NEM ID.
"""
for netif in self.nemidmap:
if self.nemidmap[netif] == nemid:
return netif
for iface in self.nemidmap:
if self.nemidmap[iface] == nemid:
return iface
return None
def netifs(self, sort: bool = True) -> List[CoreInterface]:
"""
Retrieve list of linked interfaces sorted by node number.
"""
return sorted(self._netif.values(), key=lambda ifc: ifc.node.id)
def installnetifs(self) -> None:
def install_ifaces(self) -> None:
"""
Install TAP devices into their namespaces. This is done after
EMANE daemons have been started, because that is their only chance
@ -159,48 +153,48 @@ class EmaneNet(CoreNetworkBase):
warntxt += "Python bindings failed to load"
logging.error(warntxt)
for netif in self.netifs():
for iface in self.get_ifaces():
external = self.session.emane.get_config(
"external", self.id, self.model.name
)
if external == "0":
netif.setaddrs()
iface.setaddrs()
if not self.session.emane.genlocationevents():
netif.poshook = None
iface.poshook = None
continue
# at this point we register location handlers for generating
# EMANE location events
netif.poshook = self.setnemposition
netif.setposition()
iface.poshook = self.setnemposition
iface.setposition()
def deinstallnetifs(self) -> None:
def deinstall_ifaces(self) -> None:
"""
Uninstall TAP devices. This invokes their shutdown method for
any required cleanup; the device may be actually removed when
emanetransportd terminates.
"""
for netif in self.netifs():
if netif.transport_type == TransportType.VIRTUAL:
netif.shutdown()
netif.poshook = None
for iface in self.get_ifaces():
if iface.transport_type == TransportType.VIRTUAL:
iface.shutdown()
iface.poshook = None
def _nem_position(
self, netif: CoreInterface
self, iface: CoreInterface
) -> Optional[Tuple[int, float, float, float]]:
"""
Creates nem position for emane event for a given interface.
:param netif: interface to get nem emane position for
:param iface: interface to get nem emane position for
:return: nem position tuple, None otherwise
"""
nemid = self.getnemid(netif)
ifname = netif.localname
nemid = self.getnemid(iface)
ifname = iface.localname
if nemid is None:
logging.info("nemid for %s is unknown", ifname)
return
node = netif.node
node = iface.node
x, y, z = node.getposition()
lat, lon, alt = self.session.location.getgeo(x, y, z)
if node.position.alt is not None:
@ -210,30 +204,30 @@ class EmaneNet(CoreNetworkBase):
alt = int(round(alt))
return nemid, lon, lat, alt
def setnemposition(self, netif: CoreInterface) -> None:
def setnemposition(self, iface: CoreInterface) -> None:
"""
Publish a NEM location change event using the EMANE event service.
:param netif: interface to set nem position for
:param iface: interface to set nem position for
"""
if self.session.emane.service is None:
logging.info("position service not available")
return
position = self._nem_position(netif)
position = self._nem_position(iface)
if position:
nemid, lon, lat, alt = position
event = LocationEvent()
event.append(nemid, latitude=lat, longitude=lon, altitude=alt)
self.session.emane.service.publish(0, event)
def setnempositions(self, moved_netifs: List[CoreInterface]) -> None:
def setnempositions(self, moved_ifaces: List[CoreInterface]) -> None:
"""
Several NEMs have moved, from e.g. a WaypointMobilityModel
calculation. Generate an EMANE Location Event having several
entries for each netif that has moved.
entries for each interface that has moved.
"""
if len(moved_netifs) == 0:
if len(moved_ifaces) == 0:
return
if self.session.emane.service is None:
@ -241,8 +235,8 @@ class EmaneNet(CoreNetworkBase):
return
event = LocationEvent()
for netif in moved_netifs:
position = self._nem_position(netif)
for iface in moved_ifaces:
position = self._nem_position(iface)
if position:
nemid, lon, lat, alt = position
event.append(nemid, latitude=lat, longitude=lon, altitude=alt)