diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 02:52:18 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 02:52:18 -0800 |
commit | 93dcc43b1dd184a6e917862e4ee9a31d79411b26 (patch) | |
tree | 77d46962d5c9a5e8ac9ff944c3d3a1b49368aeb8 /server | |
parent | 1f80266d6ef342a2ed89c76936afd1e16cf3001d (diff) |
rest: support local-rib URL
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/peer.go | 11 | ||||
-rw-r--r-- | server/server.go | 18 |
2 files changed, 28 insertions, 1 deletions
diff --git a/server/peer.go b/server/peer.go index 5c26fc18..a0ec5064 100644 --- a/server/peer.go +++ b/server/peer.go @@ -18,6 +18,7 @@ package server import ( "encoding/json" log "github.com/Sirupsen/logrus" + "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet" "github.com/osrg/gobgp/table" @@ -103,6 +104,14 @@ func (peer *Peer) path2update(pathList []table.Path) []*bgp.BGPMessage { return msgs } +func (peer *Peer) handleREST(restReq *api.RestRequest) { + result := &api.RestResponseDefault{} + j, _ := json.Marshal(peer.rib.Tables[bgp.RF_IPv4_UC]) + result.Data = j + restReq.ResponseCh <- result + close(restReq.ResponseCh) +} + func (peer *Peer) handlePeermessage(m *message) { sendpath := func(pList []table.Path, wList []table.Destination) { @@ -123,6 +132,8 @@ func (peer *Peer) handlePeermessage(m *message) { case PEER_MSG_DOWN: pList, wList, _ := peer.rib.DeletePathsforPeer(m.data.(*table.PeerInfo)) sendpath(pList, wList) + case PEER_MSG_REST: + peer.handleREST(m.data.(*api.RestRequest)) } } diff --git a/server/server.go b/server/server.go index 126bd6a9..2852598b 100644 --- a/server/server.go +++ b/server/server.go @@ -32,6 +32,7 @@ const ( PEER_MSG_NEW PEER_MSG_PATH PEER_MSG_DOWN + PEER_MSG_REST //hacky, fix later ) type message struct { @@ -150,7 +151,6 @@ func (server *BgpServer) broadcast(msg *message) { } func (server *BgpServer) handleRest(restReq *api.RestRequest) { - defer close(restReq.ResponseCh) switch restReq.RequestType { case api.REQ_NEIGHBOR: // get neighbor state @@ -166,5 +166,21 @@ func (server *BgpServer) handleRest(restReq *api.RestRequest) { result.ResponseErr = fmt.Errorf("Neighbor that has %v does not exist.", remoteAddr) } restReq.ResponseCh <- result + close(restReq.ResponseCh) + case api.REQ_LOCAL_RIB: + remoteAddr := restReq.RemoteAddr + result := &api.RestResponseNeighbor{} + peer, found := server.peerMap[remoteAddr] + if found { + msg := message{ + event: PEER_MSG_REST, + data: restReq, + } + peer.SendMessage(&msg) + } else { + result.ResponseErr = fmt.Errorf("Neighbor that has %v does not exist.", remoteAddr) + restReq.ResponseCh <- result + close(restReq.ResponseCh) + } } } |