Files
vppcfg/config/mac.py
Pim van Pelt bc0310e088 Study and respond to PyLint
Add a reasonably tolerant .pylintrc and fix most pylint errors and
warnings.

------------------------------------------------------------------
Your code has been rated at 9.78/10
2022-04-22 19:32:38 +00:00

52 lines
1.4 KiB
Python

#
# Copyright (c) 2022 Pim van Pelt
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import netaddr
def is_valid(mac):
"""Return True if the string given in `mac` is a valid (6-byte) MAC address,
as defined by netaddr.EUI"""
try:
_addr = netaddr.EUI(mac)
except:
return False
return True
def is_local(mac):
"""Return True if a MAC address is a valid locally administered one."""
try:
addr = netaddr.EUI(mac)
except:
return False
return bool(addr.words[0] & 0b10)
def is_multicast(mac):
"""Return True if a MAC address is a valid multicast one."""
try:
addr = netaddr.EUI(mac)
except:
return False
return bool(addr.words[0] & 0b01)
def is_unicast(mac):
"""Return True if a MAC address is a valid unicast one."""
try:
addr = netaddr.EUI(mac)
except:
return False
return not bool(addr.words[0] & 0b01)