From 820e7aafd031db7458a92f6cbdabb0ae06a4b891 Mon Sep 17 00:00:00 2001 From: Marian Pritsak Date: Wed, 7 Jun 2017 02:13:38 +0300 Subject: [PATCH] [docker-teamd]: Explicitly set LAG hwaddr (#664) * [docker-teamd]: Explicitly set LAG hwaddr Team device is initially created without any members and has a random HW address, which is later changed to port's address. This configuration sets team device's address explicitly to base MAC to avoid reassignment. Signed-off-by: marian-pritsak * Update teamd config tests with hwaddr Signed-off-by: marian-pritsak * Align HW addr byte for Centec and Mellanox Signed-off-by: marian-pritsak * Change HW addr to unicast in config tests Signed-off-by: marian-pritsak --- dockers/docker-teamd/start.sh | 12 +++++++++++- dockers/docker-teamd/teamd.j2 | 1 + .../tests/sample_output/PortChannel01.conf | 1 + .../tests/sample_output/PortChannel02.conf | 1 + .../tests/sample_output/PortChannel03.conf | 1 + .../tests/sample_output/PortChannel04.conf | 1 + src/sonic-config-engine/tests/test_j2files.py | 2 +- 7 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dockers/docker-teamd/start.sh b/dockers/docker-teamd/start.sh index 77a3ff43be..0f6a8c9f9c 100755 --- a/dockers/docker-teamd/start.sh +++ b/dockers/docker-teamd/start.sh @@ -5,8 +5,18 @@ TEAMD_CONF_PATH=/etc/teamd rm -rf $TEAMD_CONF_PATH mkdir -p $TEAMD_CONF_PATH +SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) +MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') + +# Align last byte +if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then + last_byte=$(python -c "print '$MAC_ADDRESS'[-2:]") + aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix + MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC +fi + for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | join(' ')"`; do - sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf + sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf done mkdir -p /var/sonic diff --git a/dockers/docker-teamd/teamd.j2 b/dockers/docker-teamd/teamd.j2 index e2ef239c82..08a3415f51 100644 --- a/dockers/docker-teamd/teamd.j2 +++ b/dockers/docker-teamd/teamd.j2 @@ -1,5 +1,6 @@ { "device": "{{ pc }}", + "hwaddr": "{{ hwaddr }}", "runner": { "name": "lacp", "active": true, diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel01.conf b/src/sonic-config-engine/tests/sample_output/PortChannel01.conf index 95369ce06a..d69c0d6697 100644 --- a/src/sonic-config-engine/tests/sample_output/PortChannel01.conf +++ b/src/sonic-config-engine/tests/sample_output/PortChannel01.conf @@ -1,5 +1,6 @@ { "device": "PortChannel01", + "hwaddr": "e4:1d:2d:a5:f3:ad", "runner": { "name": "lacp", "active": true, diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel02.conf b/src/sonic-config-engine/tests/sample_output/PortChannel02.conf index 960ca2d0db..e9b2ff4f1a 100644 --- a/src/sonic-config-engine/tests/sample_output/PortChannel02.conf +++ b/src/sonic-config-engine/tests/sample_output/PortChannel02.conf @@ -1,5 +1,6 @@ { "device": "PortChannel02", + "hwaddr": "e4:1d:2d:a5:f3:ad", "runner": { "name": "lacp", "active": true, diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel03.conf b/src/sonic-config-engine/tests/sample_output/PortChannel03.conf index d26ad7795e..a73617abad 100644 --- a/src/sonic-config-engine/tests/sample_output/PortChannel03.conf +++ b/src/sonic-config-engine/tests/sample_output/PortChannel03.conf @@ -1,5 +1,6 @@ { "device": "PortChannel03", + "hwaddr": "e4:1d:2d:a5:f3:ad", "runner": { "name": "lacp", "active": true, diff --git a/src/sonic-config-engine/tests/sample_output/PortChannel04.conf b/src/sonic-config-engine/tests/sample_output/PortChannel04.conf index 76c97b3f7c..073b8057d4 100644 --- a/src/sonic-config-engine/tests/sample_output/PortChannel04.conf +++ b/src/sonic-config-engine/tests/sample_output/PortChannel04.conf @@ -1,5 +1,6 @@ { "device": "PortChannel04", + "hwaddr": "e4:1d:2d:a5:f3:ad", "runner": { "name": "lacp", "active": true, diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index 6ea49efc75..2a8c7a3568 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -37,7 +37,7 @@ class TestJ2Files(TestCase): def test_render_teamd(self, pc): teamd_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-teamd', 'teamd.j2') sample_output_file = os.path.join(self.test_dir, 'sample_output',pc + '.conf') - argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\"}\' -t ' + teamd_file + ' > ' + self.output_file + argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\",\"hwaddr\":\"e4:1d:2d:a5:f3:ad\"}\' -t ' + teamd_file + ' > ' + self.output_file self.run_script(argument) assert filecmp.cmp(sample_output_file, self.output_file)