diff --git a/dockers/docker-teamd/start.sh b/dockers/docker-teamd/start.sh index 77a3ff43be85..0f6a8c9f9ceb 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 e2ef239c8266..08a3415f5188 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 95369ce06a2e..d69c0d6697b2 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 960ca2d0db65..e9b2ff4f1ad9 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 d26ad7795e54..a73617abade0 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 76c97b3f7c03..073b8057d461 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 6ea49efc75f2..2a8c7a35688f 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -37,7 +37,7 @@ def test_teamd(self): 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)