daemon: initial changes to breakout custom interface creation for networks that require it, without being emane specific
This commit is contained in:
parent
a870c15b43
commit
da9c0d0660
2 changed files with 52 additions and 20 deletions
|
@ -6,9 +6,10 @@ share the same MAC+PHY model.
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type
|
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Type
|
||||||
|
|
||||||
from core.emulator.data import LinkData, LinkOptions
|
from core.emulator.data import InterfaceData, LinkData, LinkOptions
|
||||||
from core.emulator.distributed import DistributedServer
|
from core.emulator.distributed import DistributedServer
|
||||||
from core.emulator.enumerations import (
|
from core.emulator.enumerations import (
|
||||||
|
EventTypes,
|
||||||
LinkTypes,
|
LinkTypes,
|
||||||
MessageFlags,
|
MessageFlags,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
|
@ -16,7 +17,7 @@ from core.emulator.enumerations import (
|
||||||
TransportType,
|
TransportType,
|
||||||
)
|
)
|
||||||
from core.errors import CoreError
|
from core.errors import CoreError
|
||||||
from core.nodes.base import CoreNetworkBase
|
from core.nodes.base import CoreNetworkBase, CoreNode
|
||||||
from core.nodes.interface import CoreInterface, TunTap
|
from core.nodes.interface import CoreInterface, TunTap
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -47,7 +48,7 @@ class EmaneNet(CoreNetworkBase):
|
||||||
apitype: NodeTypes = NodeTypes.EMANE
|
apitype: NodeTypes = NodeTypes.EMANE
|
||||||
linktype: LinkTypes = LinkTypes.WIRED
|
linktype: LinkTypes = LinkTypes.WIRED
|
||||||
type: str = "wlan"
|
type: str = "wlan"
|
||||||
is_emane: bool = True
|
has_custom_iface: bool = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -262,3 +263,32 @@ class EmaneNet(CoreNetworkBase):
|
||||||
if link:
|
if link:
|
||||||
links.append(link)
|
links.append(link)
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
def custom_iface(self, node: CoreNode, iface_data: InterfaceData) -> CoreInterface:
|
||||||
|
# TUN/TAP is not ready for addressing yet; the device may
|
||||||
|
# take some time to appear, and installing it into a
|
||||||
|
# namespace after it has been bound removes addressing;
|
||||||
|
# save addresses with the interface now
|
||||||
|
iface_id = node.newtuntap(iface_data.id, iface_data.name)
|
||||||
|
node.attachnet(iface_id, self)
|
||||||
|
iface = node.get_iface(iface_id)
|
||||||
|
iface.set_mac(iface_data.mac)
|
||||||
|
for ip in iface_data.get_ips():
|
||||||
|
iface.add_ip(ip)
|
||||||
|
# TODO: if added during runtime start EMANE
|
||||||
|
if self.session.state == EventTypes.RUNTIME_STATE:
|
||||||
|
logging.info("startup emane for node: %s", node.name)
|
||||||
|
# create specific xml if needed
|
||||||
|
config = self.session.emane.get_iface_config(
|
||||||
|
self.model.id, iface, self.model.name
|
||||||
|
)
|
||||||
|
if config:
|
||||||
|
self.model.build_xml_files(config, iface)
|
||||||
|
|
||||||
|
# start emane daemon
|
||||||
|
|
||||||
|
# install netif
|
||||||
|
|
||||||
|
# add nem to nemfile
|
||||||
|
|
||||||
|
return iface
|
||||||
|
|
|
@ -812,30 +812,29 @@ class CoreNode(CoreNodeBase):
|
||||||
:param iface_data: interface data for new interface
|
:param iface_data: interface data for new interface
|
||||||
:return: interface index
|
:return: interface index
|
||||||
"""
|
"""
|
||||||
ips = iface_data.get_ips()
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
# TODO: emane specific code
|
if net.has_custom_iface:
|
||||||
if net.is_emane is True:
|
return net.custom_iface(self, iface_data)
|
||||||
iface_id = self.newtuntap(iface_data.id, iface_data.name)
|
# if net.is_emane is True:
|
||||||
# TUN/TAP is not ready for addressing yet; the device may
|
# iface_id = self.newtuntap(iface_data.id, iface_data.name)
|
||||||
# take some time to appear, and installing it into a
|
# # TUN/TAP is not ready for addressing yet; the device may
|
||||||
# namespace after it has been bound removes addressing;
|
# # take some time to appear, and installing it into a
|
||||||
# save addresses with the interface now
|
# # namespace after it has been bound removes addressing;
|
||||||
self.attachnet(iface_id, net)
|
# # save addresses with the interface now
|
||||||
iface = self.get_iface(iface_id)
|
# self.attachnet(iface_id, net)
|
||||||
iface.set_mac(iface_data.mac)
|
# iface = self.get_iface(iface_id)
|
||||||
for ip in ips:
|
# iface.set_mac(iface_data.mac)
|
||||||
iface.add_ip(ip)
|
# for ip in ips:
|
||||||
|
# iface.add_ip(ip)
|
||||||
else:
|
else:
|
||||||
iface_id = self.newveth(iface_data.id, iface_data.name)
|
iface_id = self.newveth(iface_data.id, iface_data.name)
|
||||||
self.attachnet(iface_id, net)
|
self.attachnet(iface_id, net)
|
||||||
if iface_data.mac:
|
if iface_data.mac:
|
||||||
self.set_mac(iface_id, iface_data.mac)
|
self.set_mac(iface_id, iface_data.mac)
|
||||||
for ip in ips:
|
for ip in iface_data.get_ips():
|
||||||
self.add_ip(iface_id, ip)
|
self.add_ip(iface_id, ip)
|
||||||
self.ifup(iface_id)
|
self.ifup(iface_id)
|
||||||
iface = self.get_iface(iface_id)
|
return self.get_iface(iface_id)
|
||||||
return iface
|
|
||||||
|
|
||||||
def addfile(self, srcname: str, filename: str) -> None:
|
def addfile(self, srcname: str, filename: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -925,7 +924,7 @@ class CoreNetworkBase(NodeBase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
linktype: LinkTypes = LinkTypes.WIRED
|
linktype: LinkTypes = LinkTypes.WIRED
|
||||||
is_emane: bool = False
|
has_custom_iface: bool = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -990,6 +989,9 @@ class CoreNetworkBase(NodeBase):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def custom_iface(self, node: CoreNode, iface_data: InterfaceData) -> CoreInterface:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_linked_iface(self, net: "CoreNetworkBase") -> Optional[CoreInterface]:
|
def get_linked_iface(self, net: "CoreNetworkBase") -> Optional[CoreInterface]:
|
||||||
"""
|
"""
|
||||||
Return the interface that links this net with another net.
|
Return the interface that links this net with another net.
|
||||||
|
|
Loading…
Add table
Reference in a new issue