updated network.py to leverage super()
This commit is contained in:
parent
68be311c7a
commit
b185c3c679
2 changed files with 16 additions and 24 deletions
|
@ -139,7 +139,7 @@ class NodeBase:
|
||||||
if sort:
|
if sort:
|
||||||
return [self._netif[x] for x in sorted(self._netif)]
|
return [self._netif[x] for x in sorted(self._netif)]
|
||||||
else:
|
else:
|
||||||
return self._netif.values()
|
return list(self._netif.values())
|
||||||
|
|
||||||
def numnetif(self):
|
def numnetif(self):
|
||||||
"""
|
"""
|
||||||
|
@ -158,11 +158,9 @@ class NodeBase:
|
||||||
:return: interface index if found, -1 otherwise
|
:return: interface index if found, -1 otherwise
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for ifindex in self._netif:
|
for ifindex in self._netif:
|
||||||
if self._netif[ifindex] is netif:
|
if self._netif[ifindex] is netif:
|
||||||
return ifindex
|
return ifindex
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
def newifindex(self):
|
def newifindex(self):
|
||||||
|
|
|
@ -257,7 +257,7 @@ class CoreNetwork(CoreNetworkBase):
|
||||||
will run on, default is None for localhost
|
will run on, default is None for localhost
|
||||||
:param policy: network policy
|
:param policy: network policy
|
||||||
"""
|
"""
|
||||||
CoreNetworkBase.__init__(self, session, _id, name, start, server)
|
super().__init__(session, _id, name, start, server)
|
||||||
if name is None:
|
if name is None:
|
||||||
name = str(self.id)
|
name = str(self.id)
|
||||||
if policy is not None:
|
if policy is not None:
|
||||||
|
@ -346,8 +346,7 @@ class CoreNetwork(CoreNetworkBase):
|
||||||
"""
|
"""
|
||||||
if self.up:
|
if self.up:
|
||||||
netif.net_client.create_interface(self.brname, netif.localname)
|
netif.net_client.create_interface(self.brname, netif.localname)
|
||||||
|
super().attach(netif)
|
||||||
CoreNetworkBase.attach(self, netif)
|
|
||||||
|
|
||||||
def detach(self, netif):
|
def detach(self, netif):
|
||||||
"""
|
"""
|
||||||
|
@ -358,8 +357,7 @@ class CoreNetwork(CoreNetworkBase):
|
||||||
"""
|
"""
|
||||||
if self.up:
|
if self.up:
|
||||||
netif.net_client.delete_interface(self.brname, netif.localname)
|
netif.net_client.delete_interface(self.brname, netif.localname)
|
||||||
|
super().detach(netif)
|
||||||
CoreNetworkBase.detach(self, netif)
|
|
||||||
|
|
||||||
def linked(self, netif1, netif2):
|
def linked(self, netif1, netif2):
|
||||||
"""
|
"""
|
||||||
|
@ -652,7 +650,7 @@ class GreTapBridge(CoreNetwork):
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
CoreNetwork.startup(self)
|
super().startup()
|
||||||
if self.gretap:
|
if self.gretap:
|
||||||
self.attach(self.gretap)
|
self.attach(self.gretap)
|
||||||
|
|
||||||
|
@ -666,7 +664,7 @@ class GreTapBridge(CoreNetwork):
|
||||||
self.detach(self.gretap)
|
self.detach(self.gretap)
|
||||||
self.gretap.shutdown()
|
self.gretap.shutdown()
|
||||||
self.gretap = None
|
self.gretap = None
|
||||||
CoreNetwork.shutdown(self)
|
super().shutdown()
|
||||||
|
|
||||||
def addrconfig(self, addrlist):
|
def addrconfig(self, addrlist):
|
||||||
"""
|
"""
|
||||||
|
@ -753,7 +751,7 @@ class CtrlNet(CoreNetwork):
|
||||||
self.assign_address = assign_address
|
self.assign_address = assign_address
|
||||||
self.updown_script = updown_script
|
self.updown_script = updown_script
|
||||||
self.serverintf = serverintf
|
self.serverintf = serverintf
|
||||||
CoreNetwork.__init__(self, session, _id, name, start, server)
|
super().__init__(session, _id, name, start, server)
|
||||||
|
|
||||||
def add_addresses(self, address):
|
def add_addresses(self, address):
|
||||||
"""
|
"""
|
||||||
|
@ -784,8 +782,7 @@ class CtrlNet(CoreNetwork):
|
||||||
if self.net_client.existing_bridges(self.id):
|
if self.net_client.existing_bridges(self.id):
|
||||||
raise CoreError(f"old bridges exist for node: {self.id}")
|
raise CoreError(f"old bridges exist for node: {self.id}")
|
||||||
|
|
||||||
CoreNetwork.startup(self)
|
super().startup()
|
||||||
|
|
||||||
logging.info("added control network bridge: %s %s", self.brname, self.prefix)
|
logging.info("added control network bridge: %s %s", self.brname, self.prefix)
|
||||||
|
|
||||||
if self.hostid and self.assign_address:
|
if self.hostid and self.assign_address:
|
||||||
|
@ -833,7 +830,7 @@ class CtrlNet(CoreNetwork):
|
||||||
except CoreCommandError:
|
except CoreCommandError:
|
||||||
logging.exception("error issuing shutdown script shutdown")
|
logging.exception("error issuing shutdown script shutdown")
|
||||||
|
|
||||||
CoreNetwork.shutdown(self)
|
super().shutdown()
|
||||||
|
|
||||||
def all_link_data(self, flags):
|
def all_link_data(self, flags):
|
||||||
"""
|
"""
|
||||||
|
@ -864,8 +861,7 @@ class PtpNet(CoreNetwork):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Point-to-point links support at most 2 network interfaces"
|
"Point-to-point links support at most 2 network interfaces"
|
||||||
)
|
)
|
||||||
|
super().attach(netif)
|
||||||
CoreNetwork.attach(self, netif)
|
|
||||||
|
|
||||||
def data(self, message_type, lat=None, lon=None, alt=None):
|
def data(self, message_type, lat=None, lon=None, alt=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1017,7 +1013,7 @@ class HubNode(CoreNetwork):
|
||||||
will run on, default is None for localhost
|
will run on, default is None for localhost
|
||||||
:raises CoreCommandError: when there is a command exception
|
:raises CoreCommandError: when there is a command exception
|
||||||
"""
|
"""
|
||||||
CoreNetwork.__init__(self, session, _id, name, start, server)
|
super().__init__(session, _id, name, start, server)
|
||||||
|
|
||||||
# TODO: move to startup method
|
# TODO: move to startup method
|
||||||
if start:
|
if start:
|
||||||
|
@ -1048,7 +1044,7 @@ class WlanNode(CoreNetwork):
|
||||||
will run on, default is None for localhost
|
will run on, default is None for localhost
|
||||||
:param policy: wlan policy
|
:param policy: wlan policy
|
||||||
"""
|
"""
|
||||||
CoreNetwork.__init__(self, session, _id, name, start, server, policy)
|
super().__init__(session, _id, name, start, server, policy)
|
||||||
# wireless model such as basic range
|
# wireless model such as basic range
|
||||||
self.model = None
|
self.model = None
|
||||||
# mobility model such as scripted
|
# mobility model such as scripted
|
||||||
|
@ -1065,7 +1061,7 @@ class WlanNode(CoreNetwork):
|
||||||
:param core.nodes.interface.Veth netif: network interface
|
:param core.nodes.interface.Veth netif: network interface
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
CoreNetwork.attach(self, netif)
|
super().attach(netif)
|
||||||
if self.model:
|
if self.model:
|
||||||
netif.poshook = self.model.position_callback
|
netif.poshook = self.model.position_callback
|
||||||
if netif.node is None:
|
if netif.node is None:
|
||||||
|
@ -1097,12 +1093,12 @@ class WlanNode(CoreNetwork):
|
||||||
|
|
||||||
def update_mobility(self, config):
|
def update_mobility(self, config):
|
||||||
if not self.mobility:
|
if not self.mobility:
|
||||||
raise ValueError("no mobility set to update for node(%s)", self.id)
|
raise ValueError(f"no mobility set to update for node({self.id})")
|
||||||
self.mobility.update_config(config)
|
self.mobility.update_config(config)
|
||||||
|
|
||||||
def updatemodel(self, config):
|
def updatemodel(self, config):
|
||||||
if not self.model:
|
if not self.model:
|
||||||
raise ValueError("no model set to update for node(%s)", self.id)
|
raise ValueError(f"no model set to update for node({self.id})")
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"node(%s) updating model(%s): %s", self.id, self.model.name, config
|
"node(%s) updating model(%s): %s", self.id, self.model.name, config
|
||||||
)
|
)
|
||||||
|
@ -1120,11 +1116,9 @@ class WlanNode(CoreNetwork):
|
||||||
:return: list of link data
|
:return: list of link data
|
||||||
:rtype: list[core.emulator.data.LinkData]
|
:rtype: list[core.emulator.data.LinkData]
|
||||||
"""
|
"""
|
||||||
all_links = CoreNetwork.all_link_data(self, flags)
|
all_links = super().all_link_data(flags)
|
||||||
|
|
||||||
if self.model:
|
if self.model:
|
||||||
all_links.extend(self.model.all_link_data(flags))
|
all_links.extend(self.model.all_link_data(flags))
|
||||||
|
|
||||||
return all_links
|
return all_links
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue