daemon: refactored usages of hwaddr to mac and be consistent everywhere

This commit is contained in:
Blake Harnden 2020-06-16 23:25:26 -07:00
parent a1734c3bc0
commit f4671ab2b8
8 changed files with 40 additions and 40 deletions

View file

@ -466,7 +466,7 @@ def iface_to_proto(iface: CoreInterface) -> core_pb2.Interface:
id=iface.node_id,
net_id=net_id,
name=iface.name,
mac=iface.hwaddr,
mac=iface.mac,
mtu=iface.mtu,
flow_id=iface.flow_id,
ip4=ip4,

View file

@ -731,9 +731,9 @@ class CoreNode(CoreNodeBase):
flow_id = self.node_net_client.get_ifindex(veth.name)
veth.flow_id = int(flow_id)
logging.debug("interface flow index: %s - %s", veth.name, veth.flow_id)
hwaddr = self.node_net_client.get_mac(veth.name)
logging.debug("interface mac: %s - %s", veth.name, hwaddr)
veth.sethwaddr(hwaddr)
mac = self.node_net_client.get_mac(veth.name)
logging.debug("interface mac: %s - %s", veth.name, mac)
veth.set_mac(mac)
try:
# add network interface to the node. If unsuccessful, destroy the
@ -775,20 +775,20 @@ class CoreNode(CoreNodeBase):
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.
: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
: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.sethwaddr(addr)
iface.set_mac(mac)
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:
"""
@ -857,14 +857,14 @@ class CoreNode(CoreNodeBase):
# save addresses with the interface now
self.attachnet(iface_id, net)
iface = self.get_iface(iface_id)
iface.sethwaddr(iface_data.mac)
iface.set_mac(iface_data.mac)
for address in addresses:
iface.addaddr(address)
else:
iface_id = self.newveth(iface_data.id, iface_data.name)
self.attachnet(iface_id, net)
if iface_data.mac:
self.sethwaddr(iface_id, iface_data.mac)
self.set_mac(iface_id, iface_data.mac)
for address in addresses:
self.addaddr(iface_id, address)
self.ifup(iface_id)
@ -1094,7 +1094,7 @@ class CoreNetworkBase(NodeBase):
unidirectional = 1
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:
ip, _sep, mask = address.partition("/")

View file

@ -53,7 +53,7 @@ class CoreInterface:
self.othernet: Optional[CoreNetworkBase] = None
self._params: Dict[str, float] = {}
self.addrlist: List[str] = []
self.hwaddr: Optional[str] = None
self.mac: Optional[str] = None
# placeholder position hook
self.poshook: Callable[[CoreInterface], None] = lambda x: None
# used with EMANE
@ -150,16 +150,16 @@ class CoreInterface:
"""
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
"""
if addr is not None:
addr = utils.validate_mac(addr)
self.hwaddr = addr
if mac is not None:
mac = utils.validate_mac(mac)
self.mac = mac
def getparam(self, key: str) -> float:
"""

View file

@ -895,7 +895,7 @@ class PtpNet(CoreNetwork):
unidirectional = 1
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:
ip, _sep, mask = address.partition("/")
@ -908,7 +908,7 @@ class PtpNet(CoreNetwork):
iface1.ip6_mask = mask
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:
ip, _sep, mask = address.partition("/")

View file

@ -65,20 +65,20 @@ class PhysicalNode(CoreNodeBase):
"""
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 addr: hardware address to set
:param mac: mac address to set
:return: nothing
: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.sethwaddr(addr)
iface.set_mac(mac)
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:
"""
@ -111,7 +111,7 @@ class PhysicalNode(CoreNodeBase):
self.net_client.delete_address(iface.name, addr)
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:
"""
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_name(iface.localname, iface.name)
iface.localname = iface.name
if hwaddr:
self.sethwaddr(iface_id, hwaddr)
if mac:
self.set_mac(iface_id, mac)
for addr in addrlist:
self.addaddr(iface_id, addr)
if self.up:

View file

@ -69,7 +69,7 @@ class XorpRtrmgr(CoreService):
"""
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 }\n"
return cfg
@ -305,7 +305,7 @@ class XorpRipng(XorpService):
for iface in node.get_ifaces(control=False):
cfg += "\tinterface %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}\n"
cfg += "\t }\n"

View file

@ -18,7 +18,7 @@ if TYPE_CHECKING:
from core.emane.emanemanager import EmaneManager
from core.emane.emanemodel import EmaneModel
_hwaddr_prefix = "02:02"
_MAC_PREFIX = "02:02"
def is_external(config: Dict[str, str]) -> bool:
@ -230,9 +230,9 @@ def build_node_platform_xml(
platform_element.append(nem_element)
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}"
iface.sethwaddr(macstr)
iface.set_mac(macstr)
# increment nem id
nem_id += 1

View file

@ -49,7 +49,7 @@ class TestNodes:
with pytest.raises(CoreError):
session.get_node(node.id, CoreNode)
def test_node_sethwaddr(self, session: Session):
def test_node_set_mac(self, session: Session):
# given
node = session.add_node(CoreNode)
switch = session.add_node(SwitchNode)
@ -58,12 +58,12 @@ class TestNodes:
mac = "aa:aa:aa:ff:ff:ff"
# when
node.sethwaddr(iface.node_id, mac)
node.set_mac(iface.node_id, mac)
# 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
node = session.add_node(CoreNode)
switch = session.add_node(SwitchNode)
@ -73,7 +73,7 @@ class TestNodes:
# when
with pytest.raises(CoreError):
node.sethwaddr(iface.node_id, mac)
node.set_mac(iface.node_id, mac)
def test_node_addaddr(self, session: Session):
# given