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:
parent
0462c1b084
commit
0725199d6d
93 changed files with 1955 additions and 2156 deletions
|
@ -203,7 +203,7 @@ class Session:
|
|||
common_networks = node1.commonnets(node1)
|
||||
if not common_networks:
|
||||
raise CoreError("no common network found for wireless link/unlink")
|
||||
for common_network, interface1, interface2 in common_networks:
|
||||
for common_network, iface1, iface2 in common_networks:
|
||||
if not isinstance(common_network, (WlanNode, EmaneNet)):
|
||||
logging.info(
|
||||
"skipping common network that is not wireless/emane: %s",
|
||||
|
@ -211,16 +211,16 @@ class Session:
|
|||
)
|
||||
continue
|
||||
if connect:
|
||||
common_network.link(interface1, interface2)
|
||||
common_network.link(iface1, iface2)
|
||||
else:
|
||||
common_network.unlink(interface1, interface2)
|
||||
common_network.unlink(iface1, iface2)
|
||||
|
||||
def add_link(
|
||||
self,
|
||||
node1_id: int,
|
||||
node2_id: int,
|
||||
interface1_data: InterfaceData = None,
|
||||
interface2_data: InterfaceData = None,
|
||||
iface1_data: InterfaceData = None,
|
||||
iface2_data: InterfaceData = None,
|
||||
options: LinkOptions = None,
|
||||
) -> Tuple[CoreInterface, CoreInterface]:
|
||||
"""
|
||||
|
@ -228,9 +228,9 @@ class Session:
|
|||
|
||||
:param node1_id: node one id
|
||||
:param node2_id: node two id
|
||||
:param interface1_data: node one interface
|
||||
:param iface1_data: node one interface
|
||||
data, defaults to none
|
||||
:param interface2_data: node two interface
|
||||
:param iface2_data: node two interface
|
||||
data, defaults to none
|
||||
:param options: data for creating link,
|
||||
defaults to no options
|
||||
|
@ -240,8 +240,8 @@ class Session:
|
|||
options = LinkOptions()
|
||||
node1 = self.get_node(node1_id, NodeBase)
|
||||
node2 = self.get_node(node2_id, NodeBase)
|
||||
interface1 = None
|
||||
interface2 = None
|
||||
iface1 = None
|
||||
iface2 = None
|
||||
|
||||
# wireless link
|
||||
if options.type == LinkTypes.WIRELESS:
|
||||
|
@ -258,22 +258,22 @@ class Session:
|
|||
logging.info("linking ptp: %s - %s", node1.name, node2.name)
|
||||
start = self.state.should_start()
|
||||
ptp = self.create_node(PtpNet, start)
|
||||
interface1 = node1.newnetif(ptp, interface1_data)
|
||||
interface2 = node2.newnetif(ptp, interface2_data)
|
||||
ptp.linkconfig(interface1, options)
|
||||
iface1 = node1.new_iface(ptp, iface1_data)
|
||||
iface2 = node2.new_iface(ptp, iface2_data)
|
||||
ptp.linkconfig(iface1, options)
|
||||
if not options.unidirectional:
|
||||
ptp.linkconfig(interface2, options)
|
||||
ptp.linkconfig(iface2, options)
|
||||
# link node to net
|
||||
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
|
||||
interface1 = node1.newnetif(node2, interface1_data)
|
||||
iface1 = node1.new_iface(node2, iface1_data)
|
||||
if not isinstance(node2, (EmaneNet, WlanNode)):
|
||||
node2.linkconfig(interface1, options)
|
||||
node2.linkconfig(iface1, options)
|
||||
# link net to node
|
||||
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
|
||||
interface2 = node2.newnetif(node1, interface2_data)
|
||||
iface2 = node2.new_iface(node1, iface2_data)
|
||||
wireless_net = isinstance(node1, (EmaneNet, WlanNode))
|
||||
if not options.unidirectional and not wireless_net:
|
||||
node1.linkconfig(interface2, options)
|
||||
node1.linkconfig(iface2, options)
|
||||
# network to network
|
||||
elif isinstance(node1, CoreNetworkBase) and isinstance(
|
||||
node2, CoreNetworkBase
|
||||
|
@ -281,12 +281,12 @@ class Session:
|
|||
logging.info(
|
||||
"linking network to network: %s - %s", node1.name, node2.name
|
||||
)
|
||||
interface1 = node1.linknet(node2)
|
||||
node1.linkconfig(interface1, options)
|
||||
iface1 = node1.linknet(node2)
|
||||
node1.linkconfig(iface1, options)
|
||||
if not options.unidirectional:
|
||||
interface1.swapparams("_params_up")
|
||||
node2.linkconfig(interface1, options)
|
||||
interface1.swapparams("_params_up")
|
||||
iface1.swapparams("_params_up")
|
||||
node2.linkconfig(iface1, options)
|
||||
iface1.swapparams("_params_up")
|
||||
else:
|
||||
raise CoreError(
|
||||
f"cannot link node1({type(node1)}) node2({type(node2)})"
|
||||
|
@ -296,19 +296,19 @@ class Session:
|
|||
key = options.key
|
||||
if isinstance(node1, TunnelNode):
|
||||
logging.info("setting tunnel key for: %s", node1.name)
|
||||
node1.setkey(key, interface1_data)
|
||||
node1.setkey(key, iface1_data)
|
||||
if isinstance(node2, TunnelNode):
|
||||
logging.info("setting tunnel key for: %s", node2.name)
|
||||
node2.setkey(key, interface2_data)
|
||||
node2.setkey(key, iface2_data)
|
||||
self.sdt.add_link(node1_id, node2_id)
|
||||
return interface1, interface2
|
||||
return iface1, iface2
|
||||
|
||||
def delete_link(
|
||||
self,
|
||||
node1_id: int,
|
||||
node2_id: int,
|
||||
interface1_id: int = None,
|
||||
interface2_id: int = None,
|
||||
iface1_id: int = None,
|
||||
iface2_id: int = None,
|
||||
link_type: LinkTypes = LinkTypes.WIRED,
|
||||
) -> None:
|
||||
"""
|
||||
|
@ -316,8 +316,8 @@ class Session:
|
|||
|
||||
:param node1_id: node one id
|
||||
:param node2_id: node two id
|
||||
:param interface1_id: interface id for node one
|
||||
:param interface2_id: interface id for node two
|
||||
:param iface1_id: interface id for node one
|
||||
:param iface2_id: interface id for node two
|
||||
:param link_type: link type to delete
|
||||
:return: nothing
|
||||
:raises core.CoreError: when no common network is found for link being deleted
|
||||
|
@ -328,9 +328,9 @@ class Session:
|
|||
"deleting link(%s) node(%s):interface(%s) node(%s):interface(%s)",
|
||||
link_type.name,
|
||||
node1.name,
|
||||
interface1_id,
|
||||
iface1_id,
|
||||
node2.name,
|
||||
interface2_id,
|
||||
iface2_id,
|
||||
)
|
||||
|
||||
# wireless link
|
||||
|
@ -345,37 +345,29 @@ class Session:
|
|||
# wired link
|
||||
else:
|
||||
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
|
||||
interface1 = node1.netif(interface1_id)
|
||||
interface2 = node2.netif(interface2_id)
|
||||
if not interface1:
|
||||
raise CoreError(
|
||||
f"node({node1.name}) missing interface({interface1_id})"
|
||||
)
|
||||
if not interface2:
|
||||
raise CoreError(
|
||||
f"node({node2.name}) missing interface({interface2_id})"
|
||||
)
|
||||
if interface1.net != interface2.net:
|
||||
iface1 = node1.get_iface(iface1_id)
|
||||
iface2 = node2.get_iface(iface2_id)
|
||||
if iface1.net != iface2.net:
|
||||
raise CoreError(
|
||||
f"node1({node1.name}) node2({node2.name}) "
|
||||
"not connected to same net"
|
||||
)
|
||||
ptp = interface1.net
|
||||
node1.delnetif(interface1_id)
|
||||
node2.delnetif(interface2_id)
|
||||
ptp = iface1.net
|
||||
node1.delete_iface(iface1_id)
|
||||
node2.delete_iface(iface2_id)
|
||||
self.delete_node(ptp.id)
|
||||
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
|
||||
node1.delnetif(interface1_id)
|
||||
node1.delete_iface(iface1_id)
|
||||
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
|
||||
node2.delnetif(interface2_id)
|
||||
node2.delete_iface(iface2_id)
|
||||
self.sdt.delete_link(node1_id, node2_id)
|
||||
|
||||
def update_link(
|
||||
self,
|
||||
node1_id: int,
|
||||
node2_id: int,
|
||||
interface1_id: int = None,
|
||||
interface2_id: int = None,
|
||||
iface1_id: int = None,
|
||||
iface2_id: int = None,
|
||||
options: LinkOptions = None,
|
||||
) -> None:
|
||||
"""
|
||||
|
@ -383,8 +375,8 @@ class Session:
|
|||
|
||||
:param node1_id: node one id
|
||||
:param node2_id: node two id
|
||||
:param interface1_id: interface id for node one
|
||||
:param interface2_id: interface id for node two
|
||||
:param iface1_id: interface id for node one
|
||||
:param iface2_id: interface id for node two
|
||||
:param options: data to update link with
|
||||
:return: nothing
|
||||
:raises core.CoreError: when updating a wireless type link, when there is a
|
||||
|
@ -398,9 +390,9 @@ class Session:
|
|||
"update link(%s) node(%s):interface(%s) node(%s):interface(%s)",
|
||||
options.type.name,
|
||||
node1.name,
|
||||
interface1_id,
|
||||
iface1_id,
|
||||
node2.name,
|
||||
interface2_id,
|
||||
iface2_id,
|
||||
)
|
||||
|
||||
# wireless link
|
||||
|
@ -408,54 +400,54 @@ class Session:
|
|||
raise CoreError("cannot update wireless link")
|
||||
else:
|
||||
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
|
||||
interface1 = node1.netif(interface1_id)
|
||||
interface2 = node2.netif(interface2_id)
|
||||
if not interface1:
|
||||
iface1 = node1.ifaces.get(iface1_id)
|
||||
iface2 = node2.ifaces.get(iface2_id)
|
||||
if not iface1:
|
||||
raise CoreError(
|
||||
f"node({node1.name}) missing interface({interface1_id})"
|
||||
f"node({node1.name}) missing interface({iface1_id})"
|
||||
)
|
||||
if not interface2:
|
||||
if not iface2:
|
||||
raise CoreError(
|
||||
f"node({node2.name}) missing interface({interface2_id})"
|
||||
f"node({node2.name}) missing interface({iface2_id})"
|
||||
)
|
||||
if interface1.net != interface2.net:
|
||||
if iface1.net != iface2.net:
|
||||
raise CoreError(
|
||||
f"node1({node1.name}) node2({node2.name}) "
|
||||
"not connected to same net"
|
||||
)
|
||||
ptp = interface1.net
|
||||
ptp.linkconfig(interface1, options, interface2)
|
||||
ptp = iface1.net
|
||||
ptp.linkconfig(iface1, options, iface2)
|
||||
if not options.unidirectional:
|
||||
ptp.linkconfig(interface2, options, interface1)
|
||||
ptp.linkconfig(iface2, options, iface1)
|
||||
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
|
||||
interface = node1.netif(interface1_id)
|
||||
node2.linkconfig(interface, options)
|
||||
iface = node1.get_iface(iface1_id)
|
||||
node2.linkconfig(iface, options)
|
||||
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
|
||||
interface = node2.netif(interface2_id)
|
||||
node1.linkconfig(interface, options)
|
||||
iface = node2.get_iface(iface2_id)
|
||||
node1.linkconfig(iface, options)
|
||||
elif isinstance(node1, CoreNetworkBase) and isinstance(
|
||||
node2, CoreNetworkBase
|
||||
):
|
||||
interface = node1.getlinknetif(node2)
|
||||
iface = node1.get_linked_iface(node2)
|
||||
upstream = False
|
||||
if not interface:
|
||||
if not iface:
|
||||
upstream = True
|
||||
interface = node2.getlinknetif(node1)
|
||||
if not interface:
|
||||
iface = node2.get_linked_iface(node1)
|
||||
if not iface:
|
||||
raise CoreError("modify unknown link between nets")
|
||||
if upstream:
|
||||
interface.swapparams("_params_up")
|
||||
node1.linkconfig(interface, options)
|
||||
interface.swapparams("_params_up")
|
||||
iface.swapparams("_params_up")
|
||||
node1.linkconfig(iface, options)
|
||||
iface.swapparams("_params_up")
|
||||
else:
|
||||
node1.linkconfig(interface, options)
|
||||
node1.linkconfig(iface, options)
|
||||
if not options.unidirectional:
|
||||
if upstream:
|
||||
node2.linkconfig(interface, options)
|
||||
node2.linkconfig(iface, options)
|
||||
else:
|
||||
interface.swapparams("_params_up")
|
||||
node2.linkconfig(interface, options)
|
||||
interface.swapparams("_params_up")
|
||||
iface.swapparams("_params_up")
|
||||
node2.linkconfig(iface, options)
|
||||
iface.swapparams("_params_up")
|
||||
else:
|
||||
raise CoreError(
|
||||
f"cannot update link node1({type(node1)}) node2({type(node2)})"
|
||||
|
@ -553,7 +545,7 @@ class Session:
|
|||
is_boot_node = isinstance(node, CoreNodeBase) and not isinstance(node, Rj45Node)
|
||||
if self.state == EventTypes.RUNTIME_STATE and is_boot_node:
|
||||
self.write_nodes()
|
||||
self.add_remove_control_interface(node=node, remove=False)
|
||||
self.add_remove_control_iface(node=node, remove=False)
|
||||
self.services.boot_services(node)
|
||||
|
||||
self.sdt.add_node(node)
|
||||
|
@ -1268,7 +1260,7 @@ class Session:
|
|||
self.emane.shutdown()
|
||||
|
||||
# update control interface hosts
|
||||
self.update_control_interface_hosts(remove=True)
|
||||
self.update_control_iface_hosts(remove=True)
|
||||
|
||||
# remove all four possible control networks
|
||||
self.add_remove_control_net(0, remove=True)
|
||||
|
@ -1314,7 +1306,7 @@ class Session:
|
|||
:return: nothing
|
||||
"""
|
||||
logging.info("booting node(%s): %s", node.name, [x.name for x in node.services])
|
||||
self.add_remove_control_interface(node=node, remove=False)
|
||||
self.add_remove_control_iface(node=node, remove=False)
|
||||
self.services.boot_services(node)
|
||||
node.start_config_services()
|
||||
|
||||
|
@ -1338,7 +1330,7 @@ class Session:
|
|||
total = time.monotonic() - start
|
||||
logging.debug("boot run time: %s", total)
|
||||
if not exceptions:
|
||||
self.update_control_interface_hosts()
|
||||
self.update_control_iface_hosts()
|
||||
return exceptions
|
||||
|
||||
def get_control_net_prefixes(self) -> List[str]:
|
||||
|
@ -1356,7 +1348,7 @@ class Session:
|
|||
p0 = p
|
||||
return [p0, p1, p2, p3]
|
||||
|
||||
def get_control_net_server_interfaces(self) -> List[str]:
|
||||
def get_control_net_server_ifaces(self) -> List[str]:
|
||||
"""
|
||||
Retrieve control net server interfaces.
|
||||
|
||||
|
@ -1424,7 +1416,7 @@ class Session:
|
|||
else:
|
||||
prefix_spec = CtrlNet.DEFAULT_PREFIX_LIST[net_index]
|
||||
logging.debug("prefix spec: %s", prefix_spec)
|
||||
server_interface = self.get_control_net_server_interfaces()[net_index]
|
||||
server_iface = self.get_control_net_server_ifaces()[net_index]
|
||||
|
||||
# return any existing controlnet bridge
|
||||
try:
|
||||
|
@ -1465,7 +1457,7 @@ class Session:
|
|||
_id,
|
||||
prefix,
|
||||
updown_script,
|
||||
server_interface,
|
||||
server_iface,
|
||||
)
|
||||
control_net = self.create_node(
|
||||
CtrlNet,
|
||||
|
@ -1473,11 +1465,11 @@ class Session:
|
|||
prefix,
|
||||
_id=_id,
|
||||
updown_script=updown_script,
|
||||
serverintf=server_interface,
|
||||
serverintf=server_iface,
|
||||
)
|
||||
return control_net
|
||||
|
||||
def add_remove_control_interface(
|
||||
def add_remove_control_iface(
|
||||
self,
|
||||
node: CoreNode,
|
||||
net_index: int = 0,
|
||||
|
@ -1503,27 +1495,27 @@ class Session:
|
|||
if not node:
|
||||
return
|
||||
# ctrl# already exists
|
||||
if node.netif(control_net.CTRLIF_IDX_BASE + net_index):
|
||||
if node.ifaces.get(control_net.CTRLIF_IDX_BASE + net_index):
|
||||
return
|
||||
try:
|
||||
ip4 = control_net.prefix[node.id]
|
||||
ip4_mask = control_net.prefix.prefixlen
|
||||
interface_data = InterfaceData(
|
||||
iface_data = InterfaceData(
|
||||
id=control_net.CTRLIF_IDX_BASE + net_index,
|
||||
name=f"ctrl{net_index}",
|
||||
mac=utils.random_mac(),
|
||||
ip4=ip4,
|
||||
ip4_mask=ip4_mask,
|
||||
)
|
||||
interface = node.newnetif(control_net, interface_data)
|
||||
interface.control = True
|
||||
iface = node.new_iface(control_net, iface_data)
|
||||
iface.control = True
|
||||
except ValueError:
|
||||
msg = f"Control interface not added to node {node.id}. "
|
||||
msg += f"Invalid control network prefix ({control_net.prefix}). "
|
||||
msg += "A longer prefix length may be required for this many nodes."
|
||||
logging.exception(msg)
|
||||
|
||||
def update_control_interface_hosts(
|
||||
def update_control_iface_hosts(
|
||||
self, net_index: int = 0, remove: bool = False
|
||||
) -> None:
|
||||
"""
|
||||
|
@ -1549,9 +1541,9 @@ class Session:
|
|||
return
|
||||
|
||||
entries = []
|
||||
for interface in control_net.netifs():
|
||||
name = interface.node.name
|
||||
for address in interface.addrlist:
|
||||
for iface in control_net.get_ifaces():
|
||||
name = iface.node.name
|
||||
for address in iface.addrlist:
|
||||
address = address.split("/")[0]
|
||||
entries.append(f"{address} {name}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue