summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/rest.go30
-rwxr-xr-xcli/gobgpcli11
-rw-r--r--server/peer_test.go18
3 files changed, 43 insertions, 16 deletions
diff --git a/api/rest.go b/api/rest.go
index d6b9d5a4..f2bdd42e 100644
--- a/api/rest.go
+++ b/api/rest.go
@@ -19,6 +19,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/fukata/golang-stats-api-handler"
"github.com/gorilla/mux"
+ "github.com/osrg/gobgp/packet"
"net/http"
"strconv"
)
@@ -47,6 +48,7 @@ const (
PARAM_REMOTE_PEER_ADDR = "remotePeerAddr"
PARAM_SHOW_OBJECT = "showObject"
PARAM_OPERATION = "operation"
+ PARAM_ROUTE_FAMILY = "routeFamily"
STATS = "/stats"
)
@@ -59,13 +61,15 @@ const REST_PORT = 8080
type RestRequest struct {
RequestType int
RemoteAddr string
+ RouteFamily bgp.RouteFamily
ResponseCh chan *RestResponse
Err error
}
-func NewRestRequest(reqType int, remoteAddr string) *RestRequest {
+func NewRestRequest(reqType int, remoteAddr string, rf bgp.RouteFamily) *RestRequest {
r := &RestRequest{
RequestType: reqType,
+ RouteFamily: rf,
RemoteAddr: remoteAddr,
ResponseCh: make(chan *RestResponse),
}
@@ -100,11 +104,11 @@ func NewRestServer(port int, bgpServerCh chan *RestRequest) *RestServer {
// get state of neighbor.
// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>
// get adj-rib-in of each neighbor.
-// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/adj-rib-in
+// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/adj-rib-in/<rf>
// get adj-rib-out of each neighbor.
-// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/adj-rib-out
+// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/adj-rib-out/<rf>
// get local-rib of each neighbor.
-// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/local-rib
+// -- curl -i -X GET http://<ownIP>:8080/v1/bgp/neighbor/<remote address of target neighbor>/local-rib/<rf>
func (rs *RestServer) Serve() {
neighbor := BASE_VERSION + NEIGHBOR
neighbors := BASE_VERSION + NEIGHBORS
@@ -113,10 +117,12 @@ func (rs *RestServer) Serve() {
perPeerURL := "/{" + PARAM_REMOTE_PEER_ADDR + "}"
showObjectURL := "/{" + PARAM_SHOW_OBJECT + "}"
operationURL := "/{" + PARAM_OPERATION + "}"
+ routeFamilyURL := "/{" + PARAM_ROUTE_FAMILY + "}"
r.HandleFunc(neighbors, rs.NeighborGET).Methods("GET")
r.HandleFunc(neighbor+perPeerURL, rs.NeighborGET).Methods("GET")
- r.HandleFunc(neighbor+perPeerURL+showObjectURL, rs.NeighborGET).Methods("GET")
+ r.HandleFunc(neighbor+perPeerURL+showObjectURL+routeFamilyURL, rs.NeighborGET).Methods("GET")
r.HandleFunc(neighbor+perPeerURL+operationURL, rs.NeighborPOST).Methods("POST")
+ r.HandleFunc(neighbor+perPeerURL+operationURL+routeFamilyURL, rs.NeighborPOST).Methods("POST")
// stats
r.HandleFunc(STATS, stats_api.Handler).Methods("GET")
@@ -133,9 +139,21 @@ func (rs *RestServer) neighbor(w http.ResponseWriter, r *http.Request, reqType i
params := mux.Vars(r)
remoteAddr, _ := params[PARAM_REMOTE_PEER_ADDR]
log.Debugf("Look up neighbor with the remote address : %v", remoteAddr)
+ var rf bgp.RouteFamily
+ routeFamily, ok := params[PARAM_ROUTE_FAMILY]
+ if ok {
+ switch routeFamily {
+ case "ipv4":
+ rf = bgp.RF_IPv4_UC
+ case "ipv6":
+ rf = bgp.RF_IPv6_UC
+ default:
+ NotFoundHandler(w, r)
+ }
+ }
//Send channel of request parameter.
- req := NewRestRequest(reqType, remoteAddr)
+ req := NewRestRequest(reqType, remoteAddr, rf)
rs.bgpServerCh <- req
//Wait response
diff --git a/cli/gobgpcli b/cli/gobgpcli
index cdf5b56e..c4ca602f 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -258,7 +258,7 @@ class Show(object):
return attrs
def do_neighbor(self):
- if len(self.args) != 2 and len(self.args) != 3:
+ if len(self.args) != 2 and len(self.args) != 3 and len(self.args) != 4:
return 1
if len(self.args) == 2:
return self._neighbor(neighbor=self.args[1])
@@ -274,6 +274,15 @@ class Show(object):
try:
r = requests.get(self.base_url + "/neighbor/" + self.args[1] + "/" + self.args[2])
+ url = self.base_url + "/neighbor/" + self.args[1] + "/" + self.args[2]
+ if len(self.args) == 3:
+ if self.args[2].find(':') == -1:
+ url += "/ipv4"
+ else:
+ url += "/ipv6"
+ else:
+ url += "/" + self.args[3]
+ r = requests.get(url)
except:
print "Failed to connect to gobgpd. It runs?"
sys.exit(1)
diff --git a/server/peer_test.go b/server/peer_test.go
index 7c78427c..a637a18d 100644
--- a/server/peer_test.go
+++ b/server/peer_test.go
@@ -123,7 +123,7 @@ func TestPeerAdminShutdownWhileEstablished(t *testing.T) {
peer.acceptedConnCh <- m
waitUntil(assert, bgp.BGP_FSM_ESTABLISHED, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -166,7 +166,7 @@ func TestPeerAdminShutdownWhileIdle(t *testing.T) {
waitUntil(assert, bgp.BGP_FSM_IDLE, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -201,7 +201,7 @@ func TestPeerAdminShutdownWhileActive(t *testing.T) {
waitUntil(assert, bgp.BGP_FSM_ACTIVE, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -238,7 +238,7 @@ func TestPeerAdminShutdownWhileOpensent(t *testing.T) {
peer.acceptedConnCh <- m
waitUntil(assert, bgp.BGP_FSM_OPENSENT, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -283,7 +283,7 @@ func TestPeerAdminShutdownWhileOpenconfirm(t *testing.T) {
peer.acceptedConnCh <- m
waitUntil(assert, bgp.BGP_FSM_OPENCONFIRM, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -334,7 +334,7 @@ func TestPeerAdminEnable(t *testing.T) {
waitUntil(assert, bgp.BGP_FSM_ESTABLISHED, peer, 1000)
// shutdown peer at first
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -350,7 +350,7 @@ func TestPeerAdminEnable(t *testing.T) {
assert.Equal(ADMIN_STATE_DOWN, peer.fsm.adminState)
// enable peer
- restReq = api.NewRestRequest(api.REQ_NEIGHBOR_ENABLE, "0.0.0.0")
+ restReq = api.NewRestRequest(api.REQ_NEIGHBOR_ENABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg = &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -397,7 +397,7 @@ func TestPeerAdminShutdownReject(t *testing.T) {
peer.acceptedConnCh <- m
waitUntil(assert, bgp.BGP_FSM_OPENSENT, peer, 1000)
- restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0")
+ restReq := api.NewRestRequest(api.REQ_NEIGHBOR_DISABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg := &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,
@@ -411,7 +411,7 @@ func TestPeerAdminShutdownReject(t *testing.T) {
json.Unmarshal(result.Data, &res)
assert.Equal("previous request is still remaining", res["result"])
- restReq = api.NewRestRequest(api.REQ_NEIGHBOR_ENABLE, "0.0.0.0")
+ restReq = api.NewRestRequest(api.REQ_NEIGHBOR_ENABLE, "0.0.0.0", bgp.RF_IPv4_UC)
msg = &serverMsg{
msgType: SRV_MSG_API,
msgData: restReq,