daemon: refactored usages of hwaddr to mac and be consistent everywhere
This commit is contained in:
parent
a1734c3bc0
commit
f4671ab2b8
8 changed files with 40 additions and 40 deletions
|
@ -466,7 +466,7 @@ def iface_to_proto(iface: CoreInterface) -> core_pb2.Interface:
|
||||||
id=iface.node_id,
|
id=iface.node_id,
|
||||||
net_id=net_id,
|
net_id=net_id,
|
||||||
name=iface.name,
|
name=iface.name,
|
||||||
mac=iface.hwaddr,
|
mac=iface.mac,
|
||||||
mtu=iface.mtu,
|
mtu=iface.mtu,
|
||||||
flow_id=iface.flow_id,
|
flow_id=iface.flow_id,
|
||||||
ip4=ip4,
|
ip4=ip4,
|
||||||
|
|
|
@ -731,9 +731,9 @@ class CoreNode(CoreNodeBase):
|
||||||
flow_id = self.node_net_client.get_ifindex(veth.name)
|
flow_id = self.node_net_client.get_ifindex(veth.name)
|
||||||
veth.flow_id = int(flow_id)
|
veth.flow_id = int(flow_id)
|
||||||
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
|
||||||
hwaddr = self.node_net_client.get_mac(veth.name)
|
mac = self.node_net_client.get_mac(veth.name)
|
||||||
logging.debug("interface mac: %s - %s", veth.name, hwaddr)
|
logging.debug("interface mac: %s - %s", veth.name, mac)
|
||||||
veth.sethwaddr(hwaddr)
|
veth.set_mac(mac)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# add network interface to the node. If unsuccessful, destroy the
|
# add network interface to the node. If unsuccessful, destroy the
|
||||||
|
@ -775,20 +775,20 @@ class CoreNode(CoreNodeBase):
|
||||||
|
|
||||||
return iface_id
|
return iface_id
|
||||||
|
|
||||||
def sethwaddr(self, iface_id: int, addr: str) -> None:
|
def set_mac(self, iface_id: int, mac: str) -> None:
|
||||||
"""
|
"""
|
||||||
Set hardware address for an interface.
|
Set hardware address for an interface.
|
||||||
|
|
||||||
:param iface_id: id of interface to set hardware address for
|
:param iface_id: id of interface to set hardware address for
|
||||||
:param addr: hardware address to set
|
:param mac: mac address to set
|
||||||
:return: nothing
|
:return: nothing
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
addr = utils.validate_mac(addr)
|
mac = utils.validate_mac(mac)
|
||||||
iface = self.get_iface(iface_id)
|
iface = self.get_iface(iface_id)
|
||||||
iface.sethwaddr(addr)
|
iface.set_mac(mac)
|
||||||
if self.up:
|
if self.up:
|
||||||
self.node_net_client.device_mac(iface.name, addr)
|
self.node_net_client.device_mac(iface.name, mac)
|
||||||
|
|
||||||
def addaddr(self, iface_id: int, addr: str) -> None:
|
def addaddr(self, iface_id: int, addr: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -857,14 +857,14 @@ class CoreNode(CoreNodeBase):
|
||||||
# save addresses with the interface now
|
# save addresses with the interface now
|
||||||
self.attachnet(iface_id, net)
|
self.attachnet(iface_id, net)
|
||||||
iface = self.get_iface(iface_id)
|
iface = self.get_iface(iface_id)
|
||||||
iface.sethwaddr(iface_data.mac)
|
iface.set_mac(iface_data.mac)
|
||||||
for address in addresses:
|
for address in addresses:
|
||||||
iface.addaddr(address)
|
iface.addaddr(address)
|
||||||
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.sethwaddr(iface_id, iface_data.mac)
|
self.set_mac(iface_id, iface_data.mac)
|
||||||
for address in addresses:
|
for address in addresses:
|
||||||
self.addaddr(iface_id, address)
|
self.addaddr(iface_id, address)
|
||||||
self.ifup(iface_id)
|
self.ifup(iface_id)
|
||||||
|
@ -1094,7 +1094,7 @@ class CoreNetworkBase(NodeBase):
|
||||||
unidirectional = 1
|
unidirectional = 1
|
||||||
|
|
||||||
iface2 = InterfaceData(
|
iface2 = InterfaceData(
|
||||||
id=linked_node.get_iface_id(iface), name=iface.name, mac=iface.hwaddr
|
id=linked_node.get_iface_id(iface), name=iface.name, mac=iface.mac
|
||||||
)
|
)
|
||||||
for address in iface.addrlist:
|
for address in iface.addrlist:
|
||||||
ip, _sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
|
|
|
@ -53,7 +53,7 @@ class CoreInterface:
|
||||||
self.othernet: Optional[CoreNetworkBase] = None
|
self.othernet: Optional[CoreNetworkBase] = None
|
||||||
self._params: Dict[str, float] = {}
|
self._params: Dict[str, float] = {}
|
||||||
self.addrlist: List[str] = []
|
self.addrlist: List[str] = []
|
||||||
self.hwaddr: Optional[str] = None
|
self.mac: Optional[str] = None
|
||||||
# placeholder position hook
|
# placeholder position hook
|
||||||
self.poshook: Callable[[CoreInterface], None] = lambda x: None
|
self.poshook: Callable[[CoreInterface], None] = lambda x: None
|
||||||
# used with EMANE
|
# used with EMANE
|
||||||
|
@ -150,16 +150,16 @@ class CoreInterface:
|
||||||
"""
|
"""
|
||||||
self.addrlist.remove(addr)
|
self.addrlist.remove(addr)
|
||||||
|
|
||||||
def sethwaddr(self, addr: str) -> None:
|
def set_mac(self, mac: str) -> None:
|
||||||
"""
|
"""
|
||||||
Set hardware address.
|
Set mac address.
|
||||||
|
|
||||||
:param addr: hardware address to set to.
|
:param mac: mac address to set
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
if addr is not None:
|
if mac is not None:
|
||||||
addr = utils.validate_mac(addr)
|
mac = utils.validate_mac(mac)
|
||||||
self.hwaddr = addr
|
self.mac = mac
|
||||||
|
|
||||||
def getparam(self, key: str) -> float:
|
def getparam(self, key: str) -> float:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -895,7 +895,7 @@ class PtpNet(CoreNetwork):
|
||||||
unidirectional = 1
|
unidirectional = 1
|
||||||
|
|
||||||
iface1_data = InterfaceData(
|
iface1_data = InterfaceData(
|
||||||
id=iface1.node.get_iface_id(iface1), name=iface1.name, mac=iface1.hwaddr
|
id=iface1.node.get_iface_id(iface1), name=iface1.name, mac=iface1.mac
|
||||||
)
|
)
|
||||||
for address in iface1.addrlist:
|
for address in iface1.addrlist:
|
||||||
ip, _sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
|
@ -908,7 +908,7 @@ class PtpNet(CoreNetwork):
|
||||||
iface1.ip6_mask = mask
|
iface1.ip6_mask = mask
|
||||||
|
|
||||||
iface2_data = InterfaceData(
|
iface2_data = InterfaceData(
|
||||||
id=iface2.node.get_iface_id(iface2), name=iface2.name, mac=iface2.hwaddr
|
id=iface2.node.get_iface_id(iface2), name=iface2.name, mac=iface2.mac
|
||||||
)
|
)
|
||||||
for address in iface2.addrlist:
|
for address in iface2.addrlist:
|
||||||
ip, _sep, mask = address.partition("/")
|
ip, _sep, mask = address.partition("/")
|
||||||
|
|
|
@ -65,20 +65,20 @@ class PhysicalNode(CoreNodeBase):
|
||||||
"""
|
"""
|
||||||
return sh
|
return sh
|
||||||
|
|
||||||
def sethwaddr(self, iface_id: int, addr: str) -> None:
|
def set_mac(self, iface_id: int, mac: str) -> None:
|
||||||
"""
|
"""
|
||||||
Set hardware address for an interface.
|
Set mac address for an interface.
|
||||||
|
|
||||||
:param iface_id: index of interface to set hardware address for
|
:param iface_id: index of interface to set hardware address for
|
||||||
:param addr: hardware address to set
|
:param mac: mac address to set
|
||||||
:return: nothing
|
:return: nothing
|
||||||
:raises CoreCommandError: when a non-zero exit status occurs
|
:raises CoreCommandError: when a non-zero exit status occurs
|
||||||
"""
|
"""
|
||||||
addr = utils.validate_mac(addr)
|
mac = utils.validate_mac(mac)
|
||||||
iface = self.ifaces[iface_id]
|
iface = self.ifaces[iface_id]
|
||||||
iface.sethwaddr(addr)
|
iface.set_mac(mac)
|
||||||
if self.up:
|
if self.up:
|
||||||
self.net_client.device_mac(iface.name, addr)
|
self.net_client.device_mac(iface.name, mac)
|
||||||
|
|
||||||
def addaddr(self, iface_id: int, addr: str) -> None:
|
def addaddr(self, iface_id: int, addr: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -111,7 +111,7 @@ class PhysicalNode(CoreNodeBase):
|
||||||
self.net_client.delete_address(iface.name, addr)
|
self.net_client.delete_address(iface.name, addr)
|
||||||
|
|
||||||
def adopt_iface(
|
def adopt_iface(
|
||||||
self, iface: CoreInterface, iface_id: int, hwaddr: str, addrlist: List[str]
|
self, iface: CoreInterface, iface_id: int, mac: str, addrlist: List[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
When a link message is received linking this node to another part of
|
When a link message is received linking this node to another part of
|
||||||
|
@ -126,8 +126,8 @@ class PhysicalNode(CoreNodeBase):
|
||||||
self.net_client.device_down(iface.localname)
|
self.net_client.device_down(iface.localname)
|
||||||
self.net_client.device_name(iface.localname, iface.name)
|
self.net_client.device_name(iface.localname, iface.name)
|
||||||
iface.localname = iface.name
|
iface.localname = iface.name
|
||||||
if hwaddr:
|
if mac:
|
||||||
self.sethwaddr(iface_id, hwaddr)
|
self.set_mac(iface_id, mac)
|
||||||
for addr in addrlist:
|
for addr in addrlist:
|
||||||
self.addaddr(iface_id, addr)
|
self.addaddr(iface_id, addr)
|
||||||
if self.up:
|
if self.up:
|
||||||
|
|
|
@ -69,7 +69,7 @@ class XorpRtrmgr(CoreService):
|
||||||
"""
|
"""
|
||||||
helper for adding link-local address entries (required by OSPFv3)
|
helper for adding link-local address entries (required by OSPFv3)
|
||||||
"""
|
"""
|
||||||
cfg = "\t address %s {\n" % iface.hwaddr.tolinklocal()
|
cfg = "\t address %s {\n" % iface.mac.tolinklocal()
|
||||||
cfg += "\t\tprefix-length: 64\n"
|
cfg += "\t\tprefix-length: 64\n"
|
||||||
cfg += "\t }\n"
|
cfg += "\t }\n"
|
||||||
return cfg
|
return cfg
|
||||||
|
@ -305,7 +305,7 @@ class XorpRipng(XorpService):
|
||||||
for iface in node.get_ifaces(control=False):
|
for iface in node.get_ifaces(control=False):
|
||||||
cfg += "\tinterface %s {\n" % iface.name
|
cfg += "\tinterface %s {\n" % iface.name
|
||||||
cfg += "\t vif %s {\n" % iface.name
|
cfg += "\t vif %s {\n" % iface.name
|
||||||
cfg += "\t\taddress %s {\n" % iface.hwaddr.tolinklocal()
|
cfg += "\t\taddress %s {\n" % iface.mac.tolinklocal()
|
||||||
cfg += "\t\t disable: false\n"
|
cfg += "\t\t disable: false\n"
|
||||||
cfg += "\t\t}\n"
|
cfg += "\t\t}\n"
|
||||||
cfg += "\t }\n"
|
cfg += "\t }\n"
|
||||||
|
|
|
@ -18,7 +18,7 @@ if TYPE_CHECKING:
|
||||||
from core.emane.emanemanager import EmaneManager
|
from core.emane.emanemanager import EmaneManager
|
||||||
from core.emane.emanemodel import EmaneModel
|
from core.emane.emanemodel import EmaneModel
|
||||||
|
|
||||||
_hwaddr_prefix = "02:02"
|
_MAC_PREFIX = "02:02"
|
||||||
|
|
||||||
|
|
||||||
def is_external(config: Dict[str, str]) -> bool:
|
def is_external(config: Dict[str, str]) -> bool:
|
||||||
|
@ -230,9 +230,9 @@ def build_node_platform_xml(
|
||||||
platform_element.append(nem_element)
|
platform_element.append(nem_element)
|
||||||
|
|
||||||
node.setnemid(iface, nem_id)
|
node.setnemid(iface, nem_id)
|
||||||
macstr = _hwaddr_prefix + ":00:00:"
|
macstr = _MAC_PREFIX + ":00:00:"
|
||||||
macstr += f"{(nem_id >> 8) & 0xFF:02X}:{nem_id & 0xFF:02X}"
|
macstr += f"{(nem_id >> 8) & 0xFF:02X}:{nem_id & 0xFF:02X}"
|
||||||
iface.sethwaddr(macstr)
|
iface.set_mac(macstr)
|
||||||
|
|
||||||
# increment nem id
|
# increment nem id
|
||||||
nem_id += 1
|
nem_id += 1
|
||||||
|
|
|
@ -49,7 +49,7 @@ class TestNodes:
|
||||||
with pytest.raises(CoreError):
|
with pytest.raises(CoreError):
|
||||||
session.get_node(node.id, CoreNode)
|
session.get_node(node.id, CoreNode)
|
||||||
|
|
||||||
def test_node_sethwaddr(self, session: Session):
|
def test_node_set_mac(self, session: Session):
|
||||||
# given
|
# given
|
||||||
node = session.add_node(CoreNode)
|
node = session.add_node(CoreNode)
|
||||||
switch = session.add_node(SwitchNode)
|
switch = session.add_node(SwitchNode)
|
||||||
|
@ -58,12 +58,12 @@ class TestNodes:
|
||||||
mac = "aa:aa:aa:ff:ff:ff"
|
mac = "aa:aa:aa:ff:ff:ff"
|
||||||
|
|
||||||
# when
|
# when
|
||||||
node.sethwaddr(iface.node_id, mac)
|
node.set_mac(iface.node_id, mac)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert iface.hwaddr == mac
|
assert iface.mac == mac
|
||||||
|
|
||||||
def test_node_sethwaddr_exception(self, session: Session):
|
def test_node_set_mac_exception(self, session: Session):
|
||||||
# given
|
# given
|
||||||
node = session.add_node(CoreNode)
|
node = session.add_node(CoreNode)
|
||||||
switch = session.add_node(SwitchNode)
|
switch = session.add_node(SwitchNode)
|
||||||
|
@ -73,7 +73,7 @@ class TestNodes:
|
||||||
|
|
||||||
# when
|
# when
|
||||||
with pytest.raises(CoreError):
|
with pytest.raises(CoreError):
|
||||||
node.sethwaddr(iface.node_id, mac)
|
node.set_mac(iface.node_id, mac)
|
||||||
|
|
||||||
def test_node_addaddr(self, session: Session):
|
def test_node_addaddr(self, session: Session):
|
||||||
# given
|
# given
|
||||||
|
|
Loading…
Reference in a new issue