diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-15 05:24:58 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-15 05:24:58 +0000 |
commit | 3f6876df0b16043412972e7fd92377226bc9c89d (patch) | |
tree | d8b1e2a41a0dca1720929807cc8161568e7c3565 /server/server.go | |
parent | a1114dc7bb6dcb165c6494799be94b5d10fe5b17 (diff) |
api: add a method to convert internal structs to protobuf structs
- add ToApiStruct() for convertion of internal structs to protobuf structs
to avoid ugly convertion by json.Marshal() && json.Unmarshal()
- move grpc server code under /server instead of /api
- update proto file to include more detailed path information
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/server/server.go b/server/server.go index 8212a1a0..c83c48df 100644 --- a/server/server.go +++ b/server/server.go @@ -18,7 +18,6 @@ package server import ( "fmt" log "github.com/Sirupsen/logrus" - "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/policy" "net" @@ -60,7 +59,7 @@ type BgpServer struct { globalTypeCh chan config.Global addedPeerCh chan config.Neighbor deletedPeerCh chan config.Neighbor - GrpcReqCh chan *api.GrpcRequest + GrpcReqCh chan *GrpcRequest listenPort int peerMap map[string]peerMapInfo globalRib *Peer @@ -73,7 +72,7 @@ func NewBgpServer(port int) *BgpServer { b.globalTypeCh = make(chan config.Global) b.addedPeerCh = make(chan config.Neighbor) b.deletedPeerCh = make(chan config.Neighbor) - b.GrpcReqCh = make(chan *api.GrpcRequest, 1) + b.GrpcReqCh = make(chan *GrpcRequest, 1) b.policyUpdateCh = make(chan config.RoutingPolicy) b.listenPort = port return &b @@ -293,53 +292,49 @@ func (p peers) Less(i, j int) bool { return strings.Less(0, 1) } -func (server *BgpServer) handleGrpc(grpcReq *api.GrpcRequest) { +func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { switch grpcReq.RequestType { - case api.REQ_NEIGHBORS: + case REQ_NEIGHBORS: peerList := peers{} for _, info := range server.peerMap { peerList = append(peerList, info.peer) } sort.Sort(peerList) for _, peer := range peerList { - data, err := peer.ToGrpc() - result := &api.GrpcResponse{ - ResponseErr: err, - Data: data, + result := &GrpcResponse{ + Data: peer.ToApiStruct(), } grpcReq.ResponseCh <- result } close(grpcReq.ResponseCh) - case api.REQ_NEIGHBOR: + case REQ_NEIGHBOR: remoteAddr := grpcReq.RemoteAddr - var result *api.GrpcResponse + var result *GrpcResponse info, found := server.peerMap[remoteAddr] if found { - data, err := info.peer.ToGrpc() - result = &api.GrpcResponse{ - ResponseErr: err, - Data: data, + result = &GrpcResponse{ + Data: info.peer.ToApiStruct(), } } else { - result = &api.GrpcResponse{ + result = &GrpcResponse{ ResponseErr: fmt.Errorf("Neighbor that has %v does not exist.", remoteAddr), } } grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) - case api.REQ_GLOBAL_RIB, api.REQ_GLOBAL_ADD, api.REQ_GLOBAL_DELETE: + case REQ_GLOBAL_RIB, REQ_GLOBAL_ADD, REQ_GLOBAL_DELETE: msg := &serverMsg{ msgType: SRV_MSG_API, msgData: grpcReq, } server.globalRib.serverMsgCh <- msg - case api.REQ_LOCAL_RIB, api.REQ_NEIGHBOR_SHUTDOWN, api.REQ_NEIGHBOR_RESET, - api.REQ_NEIGHBOR_SOFT_RESET, api.REQ_NEIGHBOR_SOFT_RESET_IN, api.REQ_NEIGHBOR_SOFT_RESET_OUT, - api.REQ_ADJ_RIB_IN, api.REQ_ADJ_RIB_OUT, - api.REQ_NEIGHBOR_ENABLE, api.REQ_NEIGHBOR_DISABLE: + case REQ_LOCAL_RIB, REQ_NEIGHBOR_SHUTDOWN, REQ_NEIGHBOR_RESET, + REQ_NEIGHBOR_SOFT_RESET, REQ_NEIGHBOR_SOFT_RESET_IN, REQ_NEIGHBOR_SOFT_RESET_OUT, + REQ_ADJ_RIB_IN, REQ_ADJ_RIB_OUT, + REQ_NEIGHBOR_ENABLE, REQ_NEIGHBOR_DISABLE: remoteAddr := grpcReq.RemoteAddr - result := &api.GrpcResponse{} + result := &GrpcResponse{} info, found := server.peerMap[remoteAddr] if found { msg := &serverMsg{ |