-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved common methods/ds to a different file
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
- Loading branch information
Showing
5 changed files
with
98 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "portsyncd/linksync.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
/* | ||
* This g_portSet contains all the front panel ports that the corresponding | ||
* host interfaces needed to be created. When this LinkSync class is | ||
* initialized, we check the database to see if some of the ports' host | ||
* interfaces are already created and remove them from this set. We will | ||
* remove the rest of the ports in the set when receiving the first netlink | ||
* message indicating that the host interfaces are created. After the set | ||
* is empty, we send out the signal PortInitDone. g_init is used to limit the | ||
* command to be run only once. | ||
*/ | ||
set<string> g_portSet; | ||
bool g_init; | ||
|
||
static void notifyPortConfigDone(ProducerStateTable &p) | ||
{ | ||
/* Notify that all ports added */ | ||
FieldValueTuple finish_notice("count", to_string(g_portSet.size())); | ||
vector<FieldValueTuple> attrs = { finish_notice }; | ||
p.set("PortConfigDone", attrs); | ||
} | ||
|
||
void handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, bool warm) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
SWSS_LOG_NOTICE("Getting port configuration from ConfigDB..."); | ||
|
||
Table table(&cfgDb, CFG_PORT_TABLE_NAME); | ||
std::vector<FieldValueTuple> ovalues; | ||
std::vector<string> keys; | ||
table.getKeys(keys); | ||
|
||
if (keys.empty()) | ||
{ | ||
SWSS_LOG_NOTICE("ConfigDB does not have port information, " | ||
"however ports can be added later on, continuing..."); | ||
} | ||
|
||
for ( auto &k : keys ) | ||
{ | ||
table.get(k, ovalues); | ||
vector<FieldValueTuple> attrs; | ||
for ( auto &v : ovalues ) | ||
{ | ||
FieldValueTuple attr(v.first, v.second); | ||
attrs.push_back(attr); | ||
} | ||
if (!warm) | ||
{ | ||
p.set(k, attrs); | ||
} | ||
g_portSet.insert(k); | ||
} | ||
if (!warm) | ||
{ | ||
notifyPortConfigDone(p); | ||
} | ||
|
||
} | ||
|
||
void handlePortConfig(ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map) | ||
{ | ||
auto it = port_cfg_map.begin(); | ||
while (it != port_cfg_map.end()) | ||
{ | ||
KeyOpFieldsValuesTuple entry = it->second; | ||
string key = kfvKey(entry); | ||
string op = kfvOp(entry); | ||
auto values = kfvFieldsValues(entry); | ||
|
||
/* only push down port config when port is not in hostif create pending state */ | ||
if (g_portSet.find(key) == g_portSet.end()) | ||
{ | ||
/* No support for port delete yet */ | ||
if (op == SET_COMMAND) | ||
{ | ||
p.set(key, values); | ||
} | ||
|
||
it = port_cfg_map.erase(it); | ||
} | ||
else | ||
{ | ||
it++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters