Skip to content

Commit d36d872

Browse files
Nanda Kishore Salemfacebook-github-bot
authored andcommitted
CLI interface to see only dry run routes
Summary: A way to see only routes in dry run mode. At fib level we can only see non-dry run routes, by having ability to see uninstallabe/dryrun routes alone, we can quickly compare with bgp route table and expected behavior. This command routes will not intermix bgp and openr during dry run verification so easy to compare. Let me know what you guys think. Reviewed By: jstrizich Differential Revision: D15701821 fbshipit-source-id: 96e0326a88fb2355cf14b85df9850c6dc4f27294
1 parent 790d866 commit d36d872

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

openr/ctrl-server/OpenrCtrlHandler.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,25 @@ OpenrCtrlHandler::semifuture_getRouteDb() {
432432
return p.getSemiFuture();
433433
}
434434

435+
folly::SemiFuture<std::unique_ptr<thrift::RouteDatabase>>
436+
OpenrCtrlHandler::semifuture_getRouteDbUnInstallable() {
437+
folly::Promise<std::unique_ptr<thrift::RouteDatabase>> p;
438+
439+
thrift::FibRequest request;
440+
request.cmd = thrift::FibCommand::ROUTE_DB_UNINSTALLABLE_GET;
441+
442+
auto reply = requestReplyThrift<thrift::RouteDatabase>(
443+
thrift::OpenrModuleType::FIB, std::move(request));
444+
if (reply.hasError()) {
445+
p.setException(thrift::OpenrError(reply.error().errString));
446+
} else {
447+
p.setValue(
448+
std::make_unique<thrift::RouteDatabase>(std::move(reply.value())));
449+
}
450+
451+
return p.getSemiFuture();
452+
}
453+
435454
folly::SemiFuture<std::unique_ptr<thrift::RouteDatabase>>
436455
OpenrCtrlHandler::semifuture_getRouteDbComputed(
437456
std::unique_ptr<std::string> nodeName) {

openr/ctrl-server/OpenrCtrlHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class OpenrCtrlHandler final : public thrift::OpenrCtrlCppSvIf,
9595
folly::SemiFuture<std::unique_ptr<thrift::RouteDatabase>>
9696
semifuture_getRouteDbComputed(std::unique_ptr<std::string> nodeName) override;
9797

98+
folly::SemiFuture<std::unique_ptr<thrift::RouteDatabase>>
99+
semifuture_getRouteDbUnInstallable() override;
100+
98101
//
99102
// Performance stats APIs
100103
//

openr/fib/Fib.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ Fib::processRequestMsg(fbzmq::Message&& request) {
219219
// send the thrift::PerfDatabase
220220
return fbzmq::Message::fromThriftObj(dumpPerfDb(), serializer_);
221221
break;
222+
case thrift::FibCommand::ROUTE_DB_UNINSTALLABLE_GET:
223+
VLOG(2) << "Fib: Do not install RouteDb requested";
224+
// send the thrift::RouteDatabase
225+
return fbzmq::Message::fromThriftObj(doNotInstallRouteDb_, serializer_);
226+
break;
222227
default:
223228
LOG(ERROR) << "Unknown command received";
224229
return folly::makeUnexpected(fbzmq::Error());
@@ -227,6 +232,8 @@ Fib::processRequestMsg(fbzmq::Message&& request) {
227232

228233
void
229234
Fib::processRouteDb(thrift::RouteDatabase&& newRouteDb) {
235+
thrift::RouteDatabase doNotInstallRouteDb;
236+
230237
VLOG(2) << "Processing new routes from Decision. "
231238
<< newRouteDb.unicastRoutes.size() << " unicast routes and "
232239
<< newRouteDb.mplsRoutes.size() << " mpls routes";
@@ -242,6 +249,8 @@ Fib::processRouteDb(thrift::RouteDatabase&& newRouteDb) {
242249
auto rIter = newRouteDb.unicastRoutes.begin();
243250
while (rIter != newRouteDb.unicastRoutes.end()) {
244251
if (rIter->doNotInstall) {
252+
doNotInstallRouteDb.unicastRoutes.emplace_back(
253+
*std::make_move_iterator(rIter));
245254
rIter = newRouteDb.unicastRoutes.erase(rIter);
246255
} else {
247256
++rIter;
@@ -252,6 +261,7 @@ Fib::processRouteDb(thrift::RouteDatabase&& newRouteDb) {
252261
auto const routeDelta = findDeltaRoutes(newRouteDb, routeDb_);
253262
// update new routeDb_
254263
routeDb_ = std::move(newRouteDb);
264+
doNotInstallRouteDb_ = std::move(doNotInstallRouteDb);
255265
// Add some counters
256266
tData_.addStatValue("fib.process_route_db", 1, fbzmq::COUNT);
257267
// Send request to agent

openr/fib/Fib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class Fib final : public OpenrEventLoop {
139139
// received route-db if provided.
140140
folly::Optional<thrift::PerfEvents> maybePerfEvents_;
141141
thrift::RouteDatabase routeDb_;
142+
// Route DB containing only dry run or not installed routes
143+
thrift::RouteDatabase doNotInstallRouteDb_;
142144
std::deque<thrift::PerfEvents> perfDb_;
143145

144146
// Flag to indicate the result of previous route programming attempt.

openr/if/Fib.thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct PerfDatabase {
3737
enum FibCommand {
3838
ROUTE_DB_GET = 1,
3939
PERF_DB_GET = 2,
40+
ROUTE_DB_UNINSTALLABLE_GET = 3,
4041
}
4142

4243
struct FibRequest {

openr/if/OpenrCtrl.thrift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ service OpenrCtrl extends fb303.FacebookService {
113113
Fib.RouteDatabase getRouteDbComputed(1: string nodeName)
114114
throws (1: OpenrError error)
115115

116+
/**
117+
* Get route database of the current node which are not installable.
118+
*/
119+
Fib.RouteDatabase getRouteDbUnInstallable()
120+
throws (1: OpenrError error)
121+
116122
//
117123
// Performance stats APIs
118124
//

openr/py/openr/cli/clis/fib.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class FibCli(object):
2222
def __init__(self):
2323
self.fib.add_command(FibRoutesComputedCli().routes, name="routes-computed")
2424
self.fib.add_command(FibRoutesInstalledCli().routes, name="routes-installed")
25+
self.fib.add_command(
26+
FibRoutesUnInstallableCli().routes, name="routes-uninstallable"
27+
)
2528

2629
# NOTE: keeping alias `list` and `routes`
2730
# for backward compatibility. Deprecated.
@@ -109,6 +112,30 @@ def routes(cli_opts, prefixes, labels, json): # noqa: B902
109112
fib.FibRoutesComputedCmd(cli_opts).run(prefixes, labels, json)
110113

111114

115+
class FibRoutesUnInstallableCli(object):
116+
@click.command()
117+
@click.option(
118+
"--prefixes",
119+
"-p",
120+
default="",
121+
multiple=True,
122+
help="Get route for specific IPs or Prefixes.",
123+
)
124+
@click.option(
125+
"--labels",
126+
"-l",
127+
type=click.INT,
128+
multiple=True,
129+
help="Get route for specific labels.",
130+
)
131+
@click.option("--json/--no-json", default=False, help="Dump in JSON format")
132+
@click.pass_obj
133+
def routes(cli_opts, prefixes, labels, json): # noqa: B902
134+
""" Request un installable routing table of the current host """
135+
136+
fib.FibRoutesUnInstallableCmd(cli_opts).run(prefixes, labels, json)
137+
138+
112139
class FibAddRoutesCli(object):
113140
@click.command()
114141
@click.argument("prefixes") # Comma separated list of prefixes

openr/py/openr/cli/commands/fib.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ def _run(
5252
utils.print_route_db(route_db, prefixes, labels)
5353

5454

55+
class FibRoutesUnInstallableCmd(OpenrCtrlCmd):
56+
def _run(
57+
self, client: OpenrCtrl.Client, prefixes: Any, labels: Any, json: bool
58+
) -> None:
59+
route_db = client.getRouteDbUnInstallable()
60+
if json:
61+
route_db_dict = {route_db.thisNodeName: utils.route_db_to_dict(route_db)}
62+
utils.print_routes_json(route_db_dict, prefixes, labels)
63+
else:
64+
utils.print_route_db(route_db, prefixes, labels)
65+
66+
5567
class FibCountersCmd(FibAgentCmd):
5668
def run(self, json_opt):
5769
try:

0 commit comments

Comments
 (0)