diff options
Diffstat (limited to '6/bgp.pl')
-rw-r--r-- | 6/bgp.pl | 25 |
1 files changed, 12 insertions, 13 deletions
@@ -13,8 +13,6 @@ router_link/3, attached_network/2]). -:- discontiguous bgp:to_dict/2. - %host(H) :- router_link(H, _, _). %host(H) :- router_link(_, H, _). % host(H). @@ -22,13 +20,6 @@ router(R) :- host(R), hosts:host_config(R, _). routers(Routers) :- setof(router(R), router(R), Routers). -to_dict(router(R), Dict) :- - bgp:neighbors(R, Neighbors), - maplist(bgp:to_dict(), Neighbors, NeighborDicts), - Dict = _{ - host: R, - neighbors: NeighborDicts}. - neighbor(H, R) :- router(H), router(R), router_link(H, _, R), @@ -38,7 +29,7 @@ warning(Msg) :- host(H), host(R), router_link(H, _, R), \+ router_link(R, _, H), - format(string(Msg), "Missing router_link from ~w to ~w", [R, H]). + format(string(Msg), "Missing router_link from '~w' to '~w'", [R, H]). neighbors(H, Cs) :- findall(neighbor(H, Name), neighbor(H, Name), Cs). @@ -75,8 +66,16 @@ router_path(X, Y) :- router_path(X, Y, []). router_path(X, Y, _) :- router_link(X, _, Y). router_path(X, Y, V) :- \+ member(X, V), router_link(X, _, Z), router_path(Z, Y, [X|V]). -to_yaml(neighbor(H, Remote), Dict) :- Dict = yaml(router(H), remote(Remote)). -to_json(neighbor(H, Remote), Dict) :- Dict = json(router(H), remote(Remote)). +%to_yaml(neighbor(H, Remote), Dict) :- Dict = yaml(router(H), remote(Remote)). +%to_json(neighbor(H, Remote), Dict) :- Dict = json(router(H), remote(Remote)). + +to_dict(router(R), Dict) :- + neighbors(R, Neighbors), + maplist(to_dict(), Neighbors, NeighborDicts), + Dict = _{ + host: R, + neighbors: NeighborDicts}. + to_dict(neighbor(_, Remote), Dict) :- host_config(Remote, RC), Dict = neighbor{ neighbor:_{ @@ -91,7 +90,7 @@ routers_entry(router(R), Dict) :- dict_create(Dict, _, Data). bird_config(Dict) :- - bgp:routers(Routers), + routers(Routers), maplist(to_dict(), Routers, RouterDicts), % maplist(routers_entry(), Routers, RouterDicts), Dict = _{routers:RouterDicts}. |