Skip to content

Commit

Permalink
[portsyncd]: Removing manual commands to bring up interfaces (sonic-n…
Browse files Browse the repository at this point in the history
…et#174)

- allow-hotplug stanza is added to interfaces file
- vlan_interfaces and lag_interfaces files are removed

Signed-off-by: Shuotian Cheng <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored Mar 15, 2017
1 parent b09c0e2 commit 6f06b59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 42 deletions.
22 changes: 7 additions & 15 deletions portsyncd/linksync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ using namespace swss;
#define VLAN_DRV_NAME "bridge"
#define TEAM_DRV_NAME "team"

#define DEFAULT_LAG_INTERFACES_FILE "/etc/network/interfaces.d/lag_interfaces"

const string INTFS_PREFIX = "Ethernet";
const string VLAN_PREFIX = "Vlan";
const string LAG_PREFIX = "PortChannel";
Expand All @@ -40,7 +38,7 @@ LinkSync::LinkSync(DBConnector *db) :
m_vlanTableConsumer(db, APP_VLAN_TABLE_NAME),
m_lagTableConsumer(db, APP_LAG_TABLE_NAME)
{
/* See the comments for g_portSet in linksync.h */
/* See the comments for g_portSet in portsyncd.cpp */
for (string port : g_portSet)
{
vector<FieldValueTuple> temp;
Expand Down Expand Up @@ -122,12 +120,9 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
/* Insert or update the ifindex to key map */
m_ifindexNameMap[ifindex] = key;

/* LAG (PortChannel) */
/* teamd instances are dealt in teamsyncd */
if (type && !strcmp(type, TEAM_DRV_NAME))
{
/* Bring up the LAG */
if (system(("/sbin/ifup --force -i " + string(DEFAULT_LAG_INTERFACES_FILE) + " " + key).c_str()))
;
return;
}

Expand Down Expand Up @@ -190,7 +185,9 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
return;
}

/* front panel interfaces: Check if the port is in the PORT_TABLE */
/* front panel interfaces: Check if the port is in the PORT_TABLE
* non-front panel interfaces such as eth0, lo which are not in the
* PORT_TABLE are ignored. */
vector<FieldValueTuple> temp;
if (m_portTableConsumer.get(key, temp))
{
Expand All @@ -200,17 +197,12 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
return;
}

/* Host interface is created */
if (!g_init && g_portSet.find(key) != g_portSet.end())
{
/* Bring up the front panel port as the first place*/
/* TODO: handle system retur code, if-block is just a warning suppressor */
if (system(("/sbin/ifup --force " + key).c_str()))
;
g_portSet.erase(key);
}
else
m_portTableProducer.set(key, fvVector);

return;
m_portTableProducer.set(key, fvVector);
}
}
31 changes: 4 additions & 27 deletions portsyncd/portsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@
#include "portsyncd/linksync.h"

#define DEFAULT_PORT_CONFIG_FILE "port_config.ini"
#define DEFAULT_VLAN_INTERFACES_FILE "/etc/network/interfaces.d/vlan_interfaces"

using namespace std;
using namespace swss;

/*
* This m_portSet contains all the front panel ports that the corresponding
* 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 ConfigDone and bring up VLAN interfaces
* when the vlan_interfaces file exists. g_init is used to limit the command
* to be run only once.
* is empty, we send out the signal ConfigDone. g_init is used to limit the
* command to be run only once.
*/
set<string> g_portSet;
map<string, set<string>> g_vlanMap;
bool g_init = false;

void usage()
{
cout << "Usage: portsyncd [-p port_config.ini] [-v vlan_interfaces]" << endl;
cout << "Usage: portsyncd [-p port_config.ini]" << endl;
cout << " -p port_config.ini: MANDATORY import port lane mapping" << endl;
cout << " default: port_config.ini" << endl;
cout << " -v vlan_interfaces: import VLAN interfaces configuration file" << endl;
cout << " default: /etc/network/interfaces.d/vlan_interfaces" << endl;
}

void handlePortConfigFile(ProducerStateTable &p, string file);
Expand All @@ -50,7 +46,6 @@ int main(int argc, char **argv)
Logger::linkToDbNative("portsyncd");
int opt;
string port_config_file = DEFAULT_PORT_CONFIG_FILE;
string vlan_interfaces_file = DEFAULT_VLAN_INTERFACES_FILE;

while ((opt = getopt(argc, argv, "p:v:h")) != -1 )
{
Expand All @@ -59,9 +54,6 @@ int main(int argc, char **argv)
case 'p':
port_config_file.assign(optarg);
break;
case 'v':
vlan_interfaces_file.assign(optarg);
break;
case 'h':
usage();
return 1;
Expand Down Expand Up @@ -117,8 +109,6 @@ int main(int argc, char **argv)
vector<FieldValueTuple> attrs = { finish_notice };
p.set("ConfigDone", attrs);

handleVlanIntfFile(vlan_interfaces_file);

g_init = true;
}
}
Expand Down Expand Up @@ -175,16 +165,3 @@ void handlePortConfigFile(ProducerStateTable &p, string file)

infile.close();
}

void handleVlanIntfFile(string file)
{
ifstream infile(file);
if (infile.good())
{
/* Bring up VLAN interfaces when vlan_interfaces_file exists */
string cmd = "/sbin/ifup --all --force --interfaces " + file;
int ret = system(cmd.c_str());
if (!ret)
cerr << "Execute command returns non-zero value! " << cmd << endl;
}
}

0 comments on commit 6f06b59

Please sign in to comment.