15
15
#include " subscriberstatetable.h"
16
16
#include " exec.h"
17
17
18
- #define DEFAULT_PORT_CONFIG_FILE " port_config.ini"
19
-
20
18
using namespace std ;
21
19
using namespace swss ;
22
20
@@ -36,19 +34,20 @@ bool g_init = false;
36
34
void usage ()
37
35
{
38
36
cout << " Usage: portsyncd [-p port_config.ini]" << endl;
39
- cout << " -p port_config.ini: MANDATORY import port lane mapping" << endl;
40
- cout << " default: port_config.ini " << endl;
37
+ cout << " -p port_config.ini: import port lane mapping" << endl;
38
+ cout << " use configDB data if not specified " << endl;
41
39
}
42
40
43
41
void handlePortConfigFile (ProducerStateTable &p, string file);
42
+ void handlePortConfigFromConfigDB (ProducerStateTable &p, DBConnector &cfgDb);
44
43
void handleVlanIntfFile (string file);
45
44
void handlePortConfig (ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map);
46
45
47
46
int main (int argc, char **argv)
48
47
{
49
48
Logger::linkToDbNative (" portsyncd" );
50
49
int opt;
51
- string port_config_file = DEFAULT_PORT_CONFIG_FILE ;
50
+ string port_config_file;
52
51
map<string, KeyOpFieldsValuesTuple> port_cfg_map;
53
52
54
53
while ((opt = getopt (argc, argv, " p:v:h" )) != -1 )
@@ -85,7 +84,12 @@ int main(int argc, char **argv)
85
84
netlink.registerGroup (RTNLGRP_LINK);
86
85
cout << " Listen to link messages..." << endl;
87
86
88
- handlePortConfigFile (p, port_config_file);
87
+ if (!port_config_file.empty ())
88
+ {
89
+ handlePortConfigFile (p, port_config_file);
90
+ } else {
91
+ handlePortConfigFromConfigDB (p, cfgDb);
92
+ }
89
93
90
94
s.addSelectable (&netlink);
91
95
s.addSelectable (&portCfg);
@@ -153,6 +157,37 @@ int main(int argc, char **argv)
153
157
return 1 ;
154
158
}
155
159
160
+ static void notifyPortConfigDone (ProducerStateTable &p)
161
+ {
162
+ /* Notify that all ports added */
163
+ FieldValueTuple finish_notice (" count" , to_string (g_portSet.size ()));
164
+ vector<FieldValueTuple> attrs = { finish_notice };
165
+ p.set (" PortConfigDone" , attrs);
166
+ }
167
+
168
+ void handlePortConfigFromConfigDB (ProducerStateTable &p, DBConnector &cfgDb)
169
+ {
170
+ cout << " Get port configuration from ConfigDB..." << endl;
171
+
172
+ Table table (&cfgDb, CFG_PORT_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR);
173
+ std::vector<FieldValueTuple> ovalues;
174
+ std::vector<string> keys;
175
+ table.getKeys (keys);
176
+ for ( auto &k : keys )
177
+ {
178
+ table.get (k, ovalues);
179
+ vector<FieldValueTuple> attrs;
180
+ for ( auto &v : ovalues )
181
+ {
182
+ FieldValueTuple attr (v.first , v.second );
183
+ attrs.push_back (attr);
184
+ }
185
+ p.set (k, attrs);
186
+ g_portSet.insert (k);
187
+ }
188
+ notifyPortConfigDone (p);
189
+ }
190
+
156
191
void handlePortConfigFile (ProducerStateTable &p, string file)
157
192
{
158
193
cout << " Read port configuration file..." << endl;
@@ -225,11 +260,7 @@ void handlePortConfigFile(ProducerStateTable &p, string file)
225
260
}
226
261
227
262
infile.close ();
228
-
229
- /* Notify that all ports added */
230
- FieldValueTuple finish_notice (" count" , to_string (g_portSet.size ()));
231
- vector<FieldValueTuple> attrs = { finish_notice };
232
- p.set (" PortConfigDone" , attrs);
263
+ notifyPortConfigDone (p);
233
264
}
234
265
235
266
void handlePortConfig (ProducerStateTable &p, map<string, KeyOpFieldsValuesTuple> &port_cfg_map)
0 commit comments