Skip to content

Commit 820e7aa

Browse files
marian-pritsaklguohan
authored andcommitted
[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 <[email protected]> * Update teamd config tests with hwaddr Signed-off-by: marian-pritsak <[email protected]> * Align HW addr byte for Centec and Mellanox Signed-off-by: marian-pritsak <[email protected]> * Change HW addr to unicast in config tests Signed-off-by: marian-pritsak <[email protected]>
1 parent b968cf7 commit 820e7aa

File tree

7 files changed

+17
-2
lines changed

7 files changed

+17
-2
lines changed

dockers/docker-teamd/start.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ TEAMD_CONF_PATH=/etc/teamd
55
rm -rf $TEAMD_CONF_PATH
66
mkdir -p $TEAMD_CONF_PATH
77

8+
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
9+
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
10+
11+
# Align last byte
12+
if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then
13+
last_byte=$(python -c "print '$MAC_ADDRESS'[-2:]")
14+
aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix
15+
MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC
16+
fi
17+
818
for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | join(' ')"`; do
9-
sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf
19+
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
1020
done
1121

1222
mkdir -p /var/sonic

dockers/docker-teamd/teamd.j2

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"device": "{{ pc }}",
3+
"hwaddr": "{{ hwaddr }}",
34
"runner": {
45
"name": "lacp",
56
"active": true,

src/sonic-config-engine/tests/sample_output/PortChannel01.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"device": "PortChannel01",
3+
"hwaddr": "e4:1d:2d:a5:f3:ad",
34
"runner": {
45
"name": "lacp",
56
"active": true,

src/sonic-config-engine/tests/sample_output/PortChannel02.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"device": "PortChannel02",
3+
"hwaddr": "e4:1d:2d:a5:f3:ad",
34
"runner": {
45
"name": "lacp",
56
"active": true,

src/sonic-config-engine/tests/sample_output/PortChannel03.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"device": "PortChannel03",
3+
"hwaddr": "e4:1d:2d:a5:f3:ad",
34
"runner": {
45
"name": "lacp",
56
"active": true,

src/sonic-config-engine/tests/sample_output/PortChannel04.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"device": "PortChannel04",
3+
"hwaddr": "e4:1d:2d:a5:f3:ad",
34
"runner": {
45
"name": "lacp",
56
"active": true,

src/sonic-config-engine/tests/test_j2files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_teamd(self):
3737
def test_render_teamd(self, pc):
3838
teamd_file = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-teamd', 'teamd.j2')
3939
sample_output_file = os.path.join(self.test_dir, 'sample_output',pc + '.conf')
40-
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -a \'{\"pc\":\"' + pc + '\"}\' -t ' + teamd_file + ' > ' + self.output_file
40+
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
4141
self.run_script(argument)
4242
assert filecmp.cmp(sample_output_file, self.output_file)
4343

0 commit comments

Comments
 (0)