|
10 | 10 | using namespace std; |
11 | 11 | using namespace swss; |
12 | 12 |
|
| 13 | +/* Port default admin status is down */ |
| 14 | +#define DEFAULT_ADMIN_STATUS_STR "down" |
| 15 | +#define DEFAULT_MTU_STR "9100" |
| 16 | + |
13 | 17 | PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) : |
14 | 18 | Orch(cfgDb, tableNames), |
15 | 19 | m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME), |
@@ -91,23 +95,44 @@ void PortMgr::doTask(Consumer &consumer) |
91 | 95 | continue; |
92 | 96 | } |
93 | 97 |
|
| 98 | + string admin_status, mtu; |
| 99 | + |
| 100 | + bool configured = (m_portList.find(alias) != m_portList.end()); |
| 101 | + |
| 102 | + /* If this is the first time we set port settings |
| 103 | + * assign default admin status and mtu |
| 104 | + */ |
| 105 | + if (!configured) |
| 106 | + { |
| 107 | + admin_status = DEFAULT_ADMIN_STATUS_STR; |
| 108 | + mtu = DEFAULT_MTU_STR; |
| 109 | + |
| 110 | + m_portList.insert(alias); |
| 111 | + } |
| 112 | + |
94 | 113 | for (auto i : kfvFieldsValues(t)) |
95 | 114 | { |
96 | 115 | if (fvField(i) == "mtu") |
97 | 116 | { |
98 | | - auto mtu = fvValue(i); |
99 | | - setPortMtu(alias, mtu); |
100 | | - SWSS_LOG_NOTICE("Configure %s MTU to %s", |
101 | | - alias.c_str(), mtu.c_str()); |
| 117 | + mtu = fvValue(i); |
102 | 118 | } |
103 | 119 | else if (fvField(i) == "admin_status") |
104 | 120 | { |
105 | | - auto status = fvValue(i); |
106 | | - setPortAdminStatus(alias, status == "up"); |
107 | | - SWSS_LOG_NOTICE("Configure %s %s", |
108 | | - alias.c_str(), status.c_str()); |
| 121 | + admin_status = fvValue(i); |
109 | 122 | } |
110 | 123 | } |
| 124 | + |
| 125 | + if (!mtu.empty()) |
| 126 | + { |
| 127 | + setPortMtu(alias, mtu); |
| 128 | + SWSS_LOG_NOTICE("Configure %s MTU to %s", alias.c_str(), mtu.c_str()); |
| 129 | + } |
| 130 | + |
| 131 | + if (!admin_status.empty()) |
| 132 | + { |
| 133 | + setPortAdminStatus(alias, admin_status == "up"); |
| 134 | + SWSS_LOG_NOTICE("Configure %s admin status to %s", alias.c_str(), admin_status.c_str()); |
| 135 | + } |
111 | 136 | } |
112 | 137 |
|
113 | 138 | it = consumer.m_toSync.erase(it); |
|
0 commit comments