summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/rest.go17
-rwxr-xr-xcli/gobgpcli25
-rw-r--r--server/peer.go2
-rw-r--r--server/server.go6
4 files changed, 49 insertions, 1 deletions
diff --git a/api/rest.go b/api/rest.go
index f2bdd42e..656b5583 100644
--- a/api/rest.go
+++ b/api/rest.go
@@ -38,10 +38,12 @@ const (
REQ_NEIGHBOR_SOFT_RESET_OUT
REQ_NEIGHBOR_ENABLE
REQ_NEIGHBOR_DISABLE
+ REQ_GLOBAL_RIB
)
const (
BASE_VERSION = "/v1"
+ GLOBAL = "/bgp/global"
NEIGHBOR = "/bgp/neighbor"
NEIGHBORS = "/bgp/neighbors"
@@ -110,6 +112,7 @@ func NewRestServer(port int, bgpServerCh chan *RestRequest) *RestServer {
// get local-rib of each neighbor.
// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/local-rib/<rf>
func (rs *RestServer) Serve() {
+ global := BASE_VERSION + GLOBAL
neighbor := BASE_VERSION + NEIGHBOR
neighbors := BASE_VERSION + NEIGHBORS
@@ -118,6 +121,7 @@ func (rs *RestServer) Serve() {
showObjectURL := "/{" + PARAM_SHOW_OBJECT + "}"
operationURL := "/{" + PARAM_OPERATION + "}"
routeFamilyURL := "/{" + PARAM_ROUTE_FAMILY + "}"
+ r.HandleFunc(global+showObjectURL+routeFamilyURL, rs.GlobalGET).Methods("GET")
r.HandleFunc(neighbors, rs.NeighborGET).Methods("GET")
r.HandleFunc(neighbor+perPeerURL, rs.NeighborGET).Methods("GET")
r.HandleFunc(neighbor+perPeerURL+showObjectURL+routeFamilyURL, rs.NeighborGET).Methods("GET")
@@ -213,6 +217,19 @@ func (rs *RestServer) NeighborGET(w http.ResponseWriter, r *http.Request) {
}
}
+func (rs *RestServer) GlobalGET(w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+ if showObject, ok := params[PARAM_SHOW_OBJECT]; ok {
+ switch showObject {
+ case "rib":
+ rs.neighbor(w, r, REQ_GLOBAL_RIB)
+ default:
+ NotFoundHandler(w, r)
+ }
+ }
+
+}
+
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}
diff --git a/cli/gobgpcli b/cli/gobgpcli
index 553d8121..b2130f2d 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -82,6 +82,31 @@ class Show(object):
return f[1]()
return 1
+ def do_global(self):
+ if len(self.args) != 1 and len(self.args) != 2:
+ return 1
+
+ url = self.base_url + "/global/rib"
+ if len(self.args) == 2:
+ url += "/" + self.args[1]
+ else:
+ url += "/ipv4"
+
+ try:
+ r = requests.get(url)
+ except:
+ print "Failed to connect to gobgpd. It runs?"
+ sys.exit(1)
+
+ f = "{:2s} {:18s} {:15s} {:10s} {:10s} {:s}"
+ print(f.format("", "Network", "Next Hop", "AS_PATH", "Age", "Attrs"))
+
+ for d in r.json()["Destinations"]:
+ d["Paths"][d["BestPathIdx"]]["Best"] = True
+ self.show_routes(f, d["Paths"], True, True)
+
+ return 0
+
def _neighbor(self, neighbor=None):
capdict = {1: "MULTIPROTOCOL",
2: "ROUTE_REFRESH",
diff --git a/server/peer.go b/server/peer.go
index 68e67254..4160ba6e 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -242,7 +242,7 @@ func (peer *Peer) sendMessages(msgs []*bgp.BGPMessage) {
func (peer *Peer) handleREST(restReq *api.RestRequest) {
result := &api.RestResponse{}
switch restReq.RequestType {
- case api.REQ_LOCAL_RIB:
+ case api.REQ_LOCAL_RIB, api.REQ_GLOBAL_RIB:
// just empty so we use ipv4 for any route family
j, _ := json.Marshal(table.NewIPv4Table(0))
if peer.fsm.adminState != ADMIN_STATE_DOWN {
diff --git a/server/server.go b/server/server.go
index 19d7eeba..27570d5a 100644
--- a/server/server.go
+++ b/server/server.go
@@ -269,6 +269,12 @@ func (server *BgpServer) handleRest(restReq *api.RestRequest) {
}
restReq.ResponseCh <- result
close(restReq.ResponseCh)
+ case api.REQ_GLOBAL_RIB:
+ msg := &serverMsg{
+ msgType: SRV_MSG_API,
+ msgData: restReq,
+ }
+ 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,