MCPcopy Create free account
hub / github.com/FDio/vpp / MACAddress

Class MACAddress

src/vpp-api/python/vpp_papi/macaddress.py:31–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31class MACAddress:
32 def __init__(self, mac):
33 """MAC Address as a text-string (aa:bb:cc:dd:ee:ff) or 6 bytes"""
34 # Of course Python 2 doesn't distinguish str from bytes
35 if type(mac) is bytes and len(mac) == 6:
36 self.mac_binary = mac
37 self.mac_string = mac_ntop(mac)
38 else:
39 self.mac_binary = mac_pton(mac)
40 self.mac_string = mac
41
42 @property
43 def packed(self):
44 return self.mac_binary
45
46 def __len__(self):
47 return 6
48
49 def __str__(self):
50 return self.mac_string
51
52 def __repr__(self):
53 return "%s(%s)" % (self.__class__.__name__, self.mac_string)
54
55 def __eq__(self, other):
56 if not isinstance(other, MACAddress):
57 try:
58 # if it looks like a mac address, we'll take it.
59 # (allows for equality with scapy hw-addresses)
60 return self.mac_binary == MACAddress(other).mac_binary
61 except Exception:
62 return NotImplemented
63 return self.mac_binary == other.mac_binary
64
65 def __ne__(self, other):
66 return not self == other
67
68 def __hash__(self):
69 return hash(self.mac_binary)

Callers 13

test_ip4_irb_2Method · 0.90
create_rulesMethod · 0.90
create_streamMethod · 0.90
find_l2_fib_entryFunction · 0.90
__init__Method · 0.90
test_bond_trafficMethod · 0.90
test_eqMethod · 0.90
test_lispMethod · 0.90
find_gbp_endpointFunction · 0.90
__init__Method · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 10

test_ip4_irb_2Method · 0.72
create_rulesMethod · 0.72
create_streamMethod · 0.72
test_bond_trafficMethod · 0.72
test_eqMethod · 0.72
test_lispMethod · 0.72
find_gbp_endpointFunction · 0.72
__init__Method · 0.72
setUpMethod · 0.72