Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lowest_free_mac_gap_at_start(self):
first_job = data_setup.create_job(num_guestrecipes=1)
data_setup.mark_job_running(first_job)
self.assertEquals(first_job.recipesets[0].recipes[0].guests[0].resource.mac_address,
netaddr.EUI('52:54:00:00:00:00'))
second_job = data_setup.create_job(num_guestrecipes=1)
data_setup.mark_job_running(second_job)
self.assertEquals(second_job.recipesets[0].recipes[0].guests[0].resource.mac_address,
netaddr.EUI('52:54:00:00:00:01'))
self.assertEquals(RecipeResource._lowest_free_mac(),
netaddr.EUI('52:54:00:00:00:02'))
first_job.cancel()
first_job.update_status()
self.assertEquals(RecipeResource._lowest_free_mac(),
netaddr.EUI('52:54:00:00:00:00'))
if match is not None:
for new_match, old_match in old_matches.items():
if new_match in match:
match[old_match] = match[new_match]
del match[new_match]
return match
flowdump = os.path.join(self.tmpdir, 'flowdump-%s.log' % dpid)
match = to_old_match(match)
match_set = None
exact_mask_match_set = None
if match:
# Different OFAs handle matches with an exact mask, different.
# Most (including OVS) drop the redundant exact mask. But others
# include an exact mask. So we must handle both.
mac_exact = str(netaddr.EUI(2**48-1)).replace('-', ':').lower()
match_set = frozenset(match.items())
exact_mask_match = {}
for field, value in match.items():
if isinstance(value, str) and not '/' in value:
value_mac = None
value_ip = None
try:
value_mac = netaddr.EUI(value)
value_ip = ipaddress.ip_address(value)
except (ValueError, netaddr.core.AddrFormatError):
pass
if value_mac:
value = '/'.join((value, mac_exact))
elif value_ip:
ip_exact = str(ipaddress.ip_address(2**value_ip.max_prefixlen-1))
value = '/'.join((value, ip_exact))
def test_mac_address_numerical_operations():
mac = EUI('00-1B-77-49-54-FD')
assert int(mac) == 117965411581
assert hex(mac) == '0x1b774954fd'
assert mac.bits() == '00000000-00011011-01110111-01001001-01010100-11111101'
assert mac.bin == '0b1101101110111010010010101010011111101'
def setup_entry_for_arp_reply(self, br, action, local_vid, mac_address,
ip_address):
'''Set the ARP respond entry.
When the l2 population mechanism driver and OVS supports to edit ARP
fields, a table (ARP_RESPONDER) to resolve ARP locally is added to the
tunnel bridge.
'''
if not self.arp_responder_enabled:
return
mac = netaddr.EUI(mac_address, dialect=netaddr.mac_unix)
ip = netaddr.IPAddress(ip_address)
if action == 'add':
actions = constants.ARP_RESPONDER_ACTIONS % {'mac': mac, 'ip': ip}
br.add_flow(table=constants.ARP_RESPONDER,
priority=1,
proto='arp',
dl_vlan=local_vid,
nw_dst='%s' % ip,
actions=actions)
elif action == 'remove':
br.delete_flows(table=constants.ARP_RESPONDER,
proto='arp',
dl_vlan=local_vid,
nw_dst='%s' % ip)
else:
def _build_ipv4v6_mac_ip_list(self, mac, ip_address, mac_ipv4_pairs,
mac_ipv6_pairs):
mac = str(netaddr.EUI(mac, dialect=mac_iptables))
if netaddr.IPNetwork(ip_address).version == 4:
mac_ipv4_pairs.append((mac, ip_address))
else:
mac_ipv6_pairs.append((mac, ip_address))
lla = str(netutils.get_ipv6_addr_by_EUI64(
constants.IPv6_LLA_PREFIX, mac))
if (mac, lla) not in mac_ipv6_pairs:
# only add once so we don't generate duplicate rules
mac_ipv6_pairs.append((mac, lla))
ip_address):
'''Set the ARP respond entry.
When the l2 population mechanism driver and OVS supports to edit ARP
fields, a table (ARP_RESPONDER) to resolve ARP locally is added to the
tunnel bridge.
'''
if not self.arp_responder_enabled:
return
ip = netaddr.IPAddress(ip_address)
if ip.version == 6:
return
ip = str(ip)
mac = str(netaddr.EUI(mac_address, dialect=_mac_mydialect))
if action == 'add':
br.install_arp_responder(local_vid, ip, mac)
elif action == 'remove':
br.delete_arp_responder(local_vid, ip)
else:
LOG.warning('Action %s not supported', action)
def mac_address_list(self, router_id, count):
"""Returns a generator of random 48-bit MAC addresses"""
# 00:11:22:xx:xx:xx
virtual_lan_card_oui = "001122"
oui = int(virtual_lan_card_oui, 16) << 24
# 00:11:22:xx:xx:xx
oui += (router_id +1) << 16
# 00:11:22:yy:xx:xx where yy is router_id
return [netaddr.EUI(oui+ei, version=48, dialect=netaddr.mac_unix)
#TODO: see if better way to repeat the function
for ei in range(1,count)]
def to_python(self, value):
if value is None:
return value
if isinstance(value, EUI):
value.dialect = default_dialect(value)
return value
try:
return EUI(value, version=48, dialect=default_dialect())
except (TypeError, ValueError, AddrFormatError):
raise ValidationError(
"This value must be a valid MAC address.")
def to_python(self, value):
if value is None:
return value
if isinstance(value, EUI):
value.dialect = default_dialect(value)
return value
try:
return EUI(value, version=48, dialect=default_dialect())
except (TypeError, ValueError, AddrFormatError):
raise ValidationError(
"This value must be a valid MAC address.")
ip_address):
'''Set the ARP respond entry.
When the l2 population mechanism driver and OVS supports to edit ARP
fields, a table (ARP_RESPONDER) to resolve ARP locally is added to the
tunnel bridge.
'''
if not self.arp_responder_enabled:
return
ip = netaddr.IPAddress(ip_address)
if ip.version == 6:
return
ip = str(ip)
mac = str(netaddr.EUI(mac_address, dialect=_mac_mydialect))
if action == 'add':
br.install_arp_responder(local_vid, ip, mac)
elif action == 'remove':
br.delete_arp_responder(local_vid, ip)
else:
LOG.warning(_LW('Action %s not supported'), action)