Skip to content

Commit 7bf63a0

Browse files
shine4chenpavel-shirshov
authored andcommitted
[teammgrd]during warm-reboot teamd need to recover system-id from saved lacp-pdu (sonic-net#1003)
* during warm-reboot teamd need to use same system-id before warm-reboot Signed-off-by: shine.chen <[email protected]> * refine per review comment Signed-off-by: shine.chen <[email protected]>
1 parent 8b4cfb6 commit 7bf63a0

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

cfgmgr/teammgr.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "portmgr.h"
88

99
#include <algorithm>
10+
#include <iostream>
11+
#include <fstream>
1012
#include <sstream>
1113
#include <thread>
1214

@@ -396,8 +398,35 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal
396398
string res;
397399

398400
stringstream conf;
401+
402+
const string dump_path = "/var/warmboot/teamd/";
403+
MacAddress mac_boot = m_mac;
404+
405+
// set portchannel mac same with mac before warmStart, when warmStart and there
406+
// is a file written by teamd.
407+
ifstream aliasfile(dump_path + alias);
408+
if (WarmStart::isWarmStart() && aliasfile.is_open())
409+
{
410+
const int partner_system_id_offset = 40;
411+
string line;
412+
413+
while (getline(aliasfile, line))
414+
{
415+
ifstream memberfile(dump_path + line, ios::binary);
416+
uint8_t mac_temp[ETHER_ADDR_LEN];
417+
418+
if (!memberfile.is_open())
419+
continue;
420+
421+
memberfile.seekg(partner_system_id_offset, std::ios::beg);
422+
memberfile.read(reinterpret_cast<char*>(mac_temp), ETHER_ADDR_LEN);
423+
mac_boot = MacAddress(mac_temp);
424+
break;
425+
}
426+
}
427+
399428
conf << "'{\"device\":\"" << alias << "\","
400-
<< "\"hwaddr\":\"" << m_mac.to_string() << "\","
429+
<< "\"hwaddr\":\"" << mac_boot.to_string() << "\","
401430
<< "\"runner\":{"
402431
<< "\"active\":true,"
403432
<< "\"name\":\"lacp\"";
@@ -418,7 +447,6 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal
418447
alias.c_str(), conf.str().c_str());
419448

420449
string warmstart_flag = WarmStart::isWarmStart() ? " -w -o " : " -r ";
421-
const string dump_path = "/var/warmboot/teamd/";
422450

423451
cmd << TEAMD_CMD
424452
<< warmstart_flag

0 commit comments

Comments
 (0)