Skip to content

Commit

Permalink
Advertise ipv6 link local address (sonic-net#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhatv authored Feb 5, 2021
1 parent a6e322a commit e6cce21
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 16 additions & 0 deletions scripts/neighbor_advertiser
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import argparse
import json
import os
import requests
import subprocess
import sys
import time
import traceback
Expand Down Expand Up @@ -233,6 +234,21 @@ def get_vlan_addresses(vlan_interface):
ipv4_addr, ipv4_prefix = get_vlan_addr_prefix(vlan_interface, 4)
ipv6_addr, ipv6_prefix = get_vlan_addr_prefix(vlan_interface, 6)

if len(ipv6_addr):
try:
out = subprocess.check_output(['ip', '-6', 'addr', 'show', vlan_interface])
out = out.decode('UTF-8')
for line in out.splitlines():
keys = line.split()
if keys[0] == 'inet6':
ip = IPNetwork(keys[1])
if str(ip.ip).startswith("fe80") and str(ip.ip) not in ipv6_addr:
# Link local ipv6 address
ipv6_addr.append(str(ip.ip))
ipv6_prefix.append('128')
except Exception:
log.log_error('failed to get %s addresses from o.s.' % vlan_interface)

metadata = config_db.get_table('DEVICE_METADATA')
mac_addr = metadata['localhost']['mac']
if not mac_addr:
Expand Down
17 changes: 15 additions & 2 deletions tests/neighbor_advertiser_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import pytest
import subprocess
from swsscommon.swsscommon import ConfigDBConnector

test_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -19,6 +20,16 @@ def set_up(self):
neighbor_advertiser.connect_app_db()

def test_neighbor_advertiser_slice(self, set_up):
cmd = "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0"
subprocess.check_output(cmd.split())
cmd = "sudo ip link add Vlan1000 type dummy"
subprocess.check_output(cmd.split())
cmd = "sudo ip -6 address add dev Vlan1000 scope link fe80::1e34:daff:fe1e:2800/64"
subprocess.check_output(cmd.split())
cmd = "sudo ip link add Vlan2000 type dummy"
subprocess.check_output(cmd.split())
cmd = "sudo ip -6 address add dev Vlan2000 scope link fe80::1e43:dfaf:fe2e:1800/64"
subprocess.check_output(cmd.split())
output = neighbor_advertiser.construct_neighbor_advertiser_slice()
expected_output = dict(
{
Expand All @@ -29,7 +40,8 @@ def test_neighbor_advertiser_slice(self, set_up):
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.1', 'ipPrefixLen': '32'}
],
'ipv6AddrMappings': [
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'}
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1000::1', 'ipPrefixLen': '128'},
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e34:daff:fe1e:2800', 'ipPrefixLen': '128'}
],
'vxlanId': '1000',
'vlanId': '1000',
Expand All @@ -40,7 +52,8 @@ def test_neighbor_advertiser_slice(self, set_up):
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': '192.168.0.10', 'ipPrefixLen': '21'}
],
'ipv6AddrMappings': [
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'}
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fc02:1011::1', 'ipPrefixLen': '64'},
{'macAddr': '1d:34:db:16:a6:00', 'ipAddr': 'fe80::1e43:dfaf:fe2e:1800', 'ipPrefixLen': '128'}
],
'vxlanId': '2000',
'vlanId': '2000',
Expand Down

0 comments on commit e6cce21

Please sign in to comment.