Skip to content

Commit

Permalink
Add partial adj detection to breeze
Browse files Browse the repository at this point in the history
Summary: We can now ask a node to display all partial adj of an area, in its perspective

Reviewed By: xiangxu1121

Differential Revision: D52643484

fbshipit-source-id: 11a1895164fdac1b6836fe38c0fbbb579ce9a09e
  • Loading branch information
Michael Liu authored and facebook-github-bot committed Jan 11, 2024
1 parent 61ede65 commit 908ac61
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions openr/py/openr/cli/clis/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self):
self.decision.add_command(DecisionRibPolicyCli().show, name="rib-policy")
self.decision.add_command(ReceivedRoutesCli().show)
self.decision.add_command(DecisionValidateCli().validate)
self.decision.add_command(DecisionPartialAdjCli().show, name="partial-adj")

@click.group(cls=deduceCommandGroup)
@click.pass_context
Expand Down Expand Up @@ -83,6 +84,16 @@ def routes(cli_opts, nodes, prefixes, labels, hostnames, json): # noqa: B902
)


class DecisionPartialAdjCli:
@click.command()
@click.option("--area", "-a", help="Show partial adj for the given area")
@click.pass_obj
def show(cli_opts, area): # noqa: B902
"""dump the partial adjacencies of an area"""

decision.DecisionShowPartialAdjCmd(cli_opts).run(area)


class DecisionAdjCli:
@click.command()
@click.option(
Expand Down
35 changes: 35 additions & 0 deletions openr/py/openr/cli/commands/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ async def _run(
)


class DecisionShowPartialAdjCmd(OpenrCtrlCmd):
# pyre-fixme[14]: `_run` overrides method defined in `OpenrCtrlCmd` inconsistently.
async def _run(
self,
client: OpenrCtrlCppClient.Async,
area: str,
*args,
**kwargs,
) -> None:
adj_dbs = await client.getDecisionAdjacenciesFiltered(
ctrl_types.AdjacenciesFilter(selectAreas={area})
)
# convert list<adjDb> from server to a two level map: {area: {node: adjDb}}
adjs_map_all_areas = utils.adj_dbs_to_area_dict(
adj_dbs, nodes={"all"}, bidir=False
)

print("\n== Area:", area, "==\n")
adj_set = set()
for _, adj_dbs in adjs_map_all_areas.items():
for node_name, adj_db in adj_dbs.items():
for adj in adj_db["adjacencies"]:
adj_set.add((node_name, adj["otherNodeName"]))
print("Total adj (uni-directional):", len(adj_set))

missing = []
for node, adj in adj_set:
r = (adj, node)
if r not in adj_set:
missing.append(r)
print("Total partial adj:", len(missing))
for missing_adj in sorted(missing):
print(f"{missing_adj[0]} -X-> {missing_adj[1]}")


class DecisionAdjCmd(OpenrCtrlCmd):
# pyre-fixme[14]: `_run` overrides method defined in `OpenrCtrlCmd` inconsistently.
async def _run(
Expand Down

0 comments on commit 908ac61

Please sign in to comment.