Skip to content

Commit

Permalink
[docker-teamd]: Explicitly set LAG hwaddr (#664)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
marian-pritsak authored and lguohan committed Jun 6, 2017
1 parent b968cf7 commit 820e7aa
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dockers/docker-teamd/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dockers/docker-teamd/teamd.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"device": "{{ pc }}",
"hwaddr": "{{ hwaddr }}",
"runner": {
"name": "lacp",
"active": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"device": "PortChannel01",
"hwaddr": "e4:1d:2d:a5:f3:ad",
"runner": {
"name": "lacp",
"active": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"device": "PortChannel02",
"hwaddr": "e4:1d:2d:a5:f3:ad",
"runner": {
"name": "lacp",
"active": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"device": "PortChannel03",
"hwaddr": "e4:1d:2d:a5:f3:ad",
"runner": {
"name": "lacp",
"active": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"device": "PortChannel04",
"hwaddr": "e4:1d:2d:a5:f3:ad",
"runner": {
"name": "lacp",
"active": true,
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 820e7aa

Please sign in to comment.