1+ #include < getopt.h>
12#include < iostream>
23#include < inttypes.h>
34#include " logger.h"
78#include " warmRestartHelper.h"
89#include " fpmsyncd/fpmlink.h"
910#include " fpmsyncd/routesync.h"
11+ #include " netlink.h"
1012
1113
1214using namespace std ;
@@ -44,12 +46,54 @@ static bool eoiuFlagsSet(Table &bgpStateTable)
4446 return true ;
4547}
4648
49+ static void usage ()
50+ {
51+ cout << " Usage: fpmsyncd [ -l ( fpm | net) ]" << endl;
52+ cout << " fpm = FpmLink (default)" << endl;
53+ cout << " net = NetLink" << endl;
54+ }
55+
4756int main (int argc, char **argv)
4857{
58+ bool useFpmLink = true ;
59+ int opt;
60+ while ((opt = getopt (argc, argv, " l:h" )) != -1 )
61+ {
62+ switch (opt)
63+ {
64+ case ' l' :
65+ {
66+ string linkmode (optarg);
67+ if (linkmode == " net" )
68+ {
69+ useFpmLink = false ;
70+ }
71+ else if (linkmode == " fpm" )
72+ {
73+ useFpmLink = true ;
74+ }
75+ else
76+ {
77+ usage ();
78+ return EXIT_FAILURE;
79+ }
80+ break ;
81+ }
82+
83+ case ' h' :
84+ usage ();
85+ return 1 ;
86+
87+ default : /* '?' */
88+ usage ();
89+ return EXIT_FAILURE;
90+ }
91+ }
92+
4993 swss::Logger::linkToDbNative (" fpmsyncd" );
5094 DBConnector db (" APPL_DB" , 0 );
5195 RedisPipeline pipeline (&db);
52- RouteSync sync (&pipeline);
96+ RouteSync sync (&pipeline, useFpmLink );
5397
5498 DBConnector stateDb (" STATE_DB" , 0 );
5599 Table bgpStateTable (&stateDb, STATE_BGP_TABLE_NAME);
@@ -61,7 +105,6 @@ int main(int argc, char **argv)
61105 {
62106 try
63107 {
64- FpmLink fpm (&sync);
65108 Select s;
66109 SelectableTimer warmStartTimer (timespec{0 , 0 });
67110 // Before eoiu flags detected, check them periodically. It also stop upon detection of reconciliation done.
@@ -75,11 +118,30 @@ int main(int argc, char **argv)
75118 */
76119 pipeline.flush ();
77120
78- cout << " Waiting for fpm-client connection..." << endl;
79- fpm.accept ();
80- cout << " Connected!" << endl;
121+ shared_ptr<Selectable> link;
122+ if (useFpmLink)
123+ {
124+ shared_ptr<FpmLink> fpm = make_shared<FpmLink>(&sync);
125+
126+ cout << " Waiting for fpm-client connection..." << endl;
127+ fpm->accept ();
128+ cout << " Connected!" << endl;
81129
82- s.addSelectable (&fpm);
130+ link = fpm;
131+ }
132+ else
133+ {
134+ shared_ptr<NetLink> netlink = make_shared<NetLink>();
135+
136+ netlink->registerGroup (RTNLGRP_IPV4_ROUTE);
137+ netlink->registerGroup (RTNLGRP_IPV6_ROUTE);
138+ netlink->registerGroup (RTNLGRP_MPLS_ROUTE);
139+ cout << " NetLink listening for route messages..." << endl;
140+ netlink->dumpRequest (RTM_GETROUTE);
141+
142+ link = netlink;
143+ }
144+ s.addSelectable (link.get ());
83145
84146 /* If warm-restart feature is enabled, execute 'restoration' logic */
85147 bool warmStartEnabled = sync.m_warmStartHelper .checkAndStart ();
0 commit comments