Skip to content

Commit

Permalink
Added 'send annoucement' event to eggpd_peer
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHabets committed Aug 6, 2011
1 parent d4e4c39 commit 8bc17ed
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Links
-----
http://www.ietf.org/rfc/rfc4271.txt
http://en.wikipedia.org/wiki/Border_Gateway_Protocol


Cut-and-paste stuff
-------------------
lc([eggpd_peer]),ReloadAll().

After startup, set up a peer:
{ok,P}=eggpd_peer_sup:add_peer("192.168.42.4").

Announce two nets:
gen_fsm:send_event(P, {send_announce,
[{as_path, {as_sequence, [1,2,3]}},
{next_hop, 16#01010101},
{origin, igp}
],
[{0,32},
{1,32}]}).


f(S). {ok,{_, S}} = eggpd_rib:get_rib(), dict:fetch(ipv4, S).

TODO
----
* should each peer get its own sup, and kill its sup (thereby killing
its own state)?
9 changes: 6 additions & 3 deletions src/eggpd_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@ do_send_open(Sock, Peer) ->


%%--------------------------------------------------------------------
%% Function: do_announce_route(Sock, Pathattr, Nets) -> ignored
%%
%% Function: do_announce_route(Sock, Path, Nets) -> ignored
%% Path: List of ASs
%% Nets
%% Description:
%%--------------------------------------------------------------------
do_announce_route(_Sock, _Path, []) ->
void;

%% TODO: this function only works for /32s, or possibly /8, /16 and /24 too
do_announce_route(Sock, Path, [OneRoute|Routes]) ->
%% Info
{Net,Plen} = OneRoute,
Expand Down Expand Up @@ -397,7 +399,7 @@ array_to_binary(Size, [H|T]) ->
%% Convert pathattr structures to binary.
%%--------------------------------------------------------------------
pathattr_factory(Attrs) ->
erlang:list_to_binary(fun pathattr_factory_entry/1, Attrs).
list_to_binary(lists:map(fun pathattr_factory_entry/1, Attrs)).

pathattr_factory_entry({origin, V}) ->
Origin = case V of
Expand Down Expand Up @@ -538,6 +540,7 @@ state_connected(LSock, Sock, Parent, Peer) ->
?MODULE:state_connected(LSock, Sock, Parent, Peer);

{Parent, {announce, Path, Route}} ->
io:format("con(~p): announce ~p ~p~n", [self(), Path, Route]),
do_announce_route(Sock, Path, Route),
?MODULE:state_connected(LSock, Sock, Parent, Peer);

Expand Down
6 changes: 6 additions & 0 deletions src/eggpd_peer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ established(keepalive, Data) ->
eggpd_connection:send_keepalive(Data#peer_state.connection),
{next_state, established, Data};

established({send_announce, Path, Routes}, Data) ->
eggpd_connection:announce_route(Data#peer_state.connection,
Path,
Routes),
{next_state, established, Data};

established({update,
Update={withdraw, Withdraw,
pathattr, _Pathattr,
Expand Down

0 comments on commit 8bc17ed

Please sign in to comment.