Skip to content

Commit

Permalink
[teammgrd]during warm-reboot teamd need to recover system-id from sav…
Browse files Browse the repository at this point in the history
…ed lacp-pdu (#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]>
  • Loading branch information
shine4chen authored and pavel-shirshov committed Dec 1, 2019
1 parent 8b4cfb6 commit 7bf63a0
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "portmgr.h"

#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <thread>

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

stringstream conf;

const string dump_path = "/var/warmboot/teamd/";
MacAddress mac_boot = m_mac;

// set portchannel mac same with mac before warmStart, when warmStart and there
// is a file written by teamd.
ifstream aliasfile(dump_path + alias);
if (WarmStart::isWarmStart() && aliasfile.is_open())
{
const int partner_system_id_offset = 40;
string line;

while (getline(aliasfile, line))
{
ifstream memberfile(dump_path + line, ios::binary);
uint8_t mac_temp[ETHER_ADDR_LEN];

if (!memberfile.is_open())
continue;

memberfile.seekg(partner_system_id_offset, std::ios::beg);
memberfile.read(reinterpret_cast<char*>(mac_temp), ETHER_ADDR_LEN);
mac_boot = MacAddress(mac_temp);
break;
}
}

conf << "'{\"device\":\"" << alias << "\","
<< "\"hwaddr\":\"" << m_mac.to_string() << "\","
<< "\"hwaddr\":\"" << mac_boot.to_string() << "\","
<< "\"runner\":{"
<< "\"active\":true,"
<< "\"name\":\"lacp\"";
Expand All @@ -418,7 +447,6 @@ task_process_status TeamMgr::addLag(const string &alias, int min_links, bool fal
alias.c_str(), conf.str().c_str());

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

cmd << TEAMD_CMD
<< warmstart_flag
Expand Down

0 comments on commit 7bf63a0

Please sign in to comment.