summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2014-12-22 02:56:17 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-22 02:56:17 -0800
commitd2bbac0697bfdbf6395172163cd0d171bb196246 (patch)
tree388c8debe0b0f77e84dd0f07f1bfb2a718d14e82 /server
parent275f20e96e674e3a0b654292f81240744c61665a (diff)
Add rest API support
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/server.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go
index 54644560..bca36afa 100644
--- a/server/server.go
+++ b/server/server.go
@@ -17,6 +17,7 @@ package server
import (
"fmt"
+ "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"net"
"os"
@@ -43,6 +44,7 @@ type BgpServer struct {
globalTypeCh chan config.GlobalType
addedPeerCh chan config.NeighborType
deletedPeerCh chan config.NeighborType
+ RestReqCh chan *api.RestRequest
listenPort int
peerMap map[string]*Peer
}
@@ -52,6 +54,7 @@ func NewBgpServer(port int) *BgpServer {
b.globalTypeCh = make(chan config.GlobalType)
b.addedPeerCh = make(chan config.NeighborType)
b.deletedPeerCh = make(chan config.NeighborType)
+ b.RestReqCh = make(chan *api.RestRequest, 1)
b.listenPort = port
return &b
}
@@ -114,6 +117,9 @@ func (server *BgpServer) Serve() {
} else {
fmt.Println("can't found neighbor", addr)
}
+ case restReq := <-server.RestReqCh:
+ server.handleRest(restReq)
+
case msg := <-broadcastCh:
server.broadcast(msg)
}
@@ -143,3 +149,23 @@ 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
+
+ remoteAddr := restReq.RemoteAddr
+ result := &api.RestResponseNeighbor{}
+ peer, found := server.peerMap[remoteAddr]
+ if found {
+ c := peer.peerConfig
+ result.NeighborState = c.BgpNeighborCommonState.State
+ result.RemoteAddr = c.NeighborAddress.String()
+ result.RemoteAs = c.PeerAs
+ } else {
+ result.ResponseErr = fmt.Errorf("Neighbor that has %v does not exist.", remoteAddr)
+ }
+ restReq.ResponseCh <- result
+ }
+}