diff --git a/api/models/b_g_p_neigh_get_entry.go b/api/models/b_g_p_neigh_get_entry.go new file mode 100644 index 000000000..2f44ccc36 --- /dev/null +++ b/api/models/b_g_p_neigh_get_entry.go @@ -0,0 +1,59 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPNeighGetEntry b g p neigh get entry +// +// swagger:model BGPNeighGetEntry +type BGPNeighGetEntry struct { + + // BGP Neighbor IP address + IPAddress string `json:"ipAddress,omitempty"` + + // Remote AS number + RemoteAs int64 `json:"remoteAs,omitempty"` + + // Current state + State string `json:"state,omitempty"` + + // Current uptime + Updowntime string `json:"updowntime,omitempty"` +} + +// Validate validates this b g p neigh get entry +func (m *BGPNeighGetEntry) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this b g p neigh get entry based on context it is used +func (m *BGPNeighGetEntry) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *BGPNeighGetEntry) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPNeighGetEntry) UnmarshalBinary(b []byte) error { + var res BGPNeighGetEntry + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/restapi/configure_loxilb_rest_api.go b/api/restapi/configure_loxilb_rest_api.go index 32a650cc4..14810033d 100644 --- a/api/restapi/configure_loxilb_rest_api.go +++ b/api/restapi/configure_loxilb_rest_api.go @@ -153,6 +153,7 @@ func configureAPI(api *operations.LoxilbRestAPIAPI) http.Handler { api.GetMetricsHandler = operations.GetMetricsHandlerFunc(handler.ConfigGetPrometheusCounter) // BGP Peer + api.GetConfigBgpNeighAllHandler = operations.GetConfigBgpNeighAllHandlerFunc(handler.ConfigGetBGPNeigh) api.PostConfigBgpGlobalHandler = operations.PostConfigBgpGlobalHandlerFunc(handler.ConfigPostBGPGlobal) api.PostConfigBgpNeighHandler = operations.PostConfigBgpNeighHandlerFunc(handler.ConfigPostBGPNeigh) api.DeleteConfigBgpNeighIPAddressHandler = operations.DeleteConfigBgpNeighIPAddressHandlerFunc(handler.ConfigDeleteBGPNeigh) diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index e3fd0e31f..c8716d119 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -165,6 +165,73 @@ func init() { } } }, + "/config/bgp/neigh/all": { + "get": { + "description": "Get the all of BGP Neighbor", + "summary": "Get the all of BGP Neighbor", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "properties": { + "bgpNeiAttr": { + "type": "array", + "items": { + "$ref": "#/definitions/BGPNeighGetEntry" + } + } + } + } + }, + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. VLAN already exists OR dependency VRF/VNET not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/bgp/neigh/{ip_address}": { "delete": { "description": "Delete a BGP Neighbor", @@ -3271,6 +3338,27 @@ func init() { } } }, + "BGPNeighGetEntry": { + "type": "object", + "properties": { + "ipAddress": { + "description": "BGP Neighbor IP address", + "type": "string" + }, + "remoteAs": { + "description": "Remote AS number", + "type": "integer" + }, + "state": { + "description": "Current state", + "type": "string" + }, + "updowntime": { + "description": "Current uptime", + "type": "string" + } + } + }, "CIStatusEntry": { "type": "object", "properties": { @@ -4552,6 +4640,73 @@ func init() { } } }, + "/config/bgp/neigh/all": { + "get": { + "description": "Get the all of BGP Neighbor", + "summary": "Get the all of BGP Neighbor", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "properties": { + "bgpNeiAttr": { + "type": "array", + "items": { + "$ref": "#/definitions/BGPNeighGetEntry" + } + } + } + } + }, + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. VLAN already exists OR dependency VRF/VNET not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/bgp/neigh/{ip_address}": { "delete": { "description": "Delete a BGP Neighbor", @@ -7658,6 +7813,27 @@ func init() { } } }, + "BGPNeighGetEntry": { + "type": "object", + "properties": { + "ipAddress": { + "description": "BGP Neighbor IP address", + "type": "string" + }, + "remoteAs": { + "description": "Remote AS number", + "type": "integer" + }, + "state": { + "description": "Current state", + "type": "string" + }, + "updowntime": { + "description": "Current uptime", + "type": "string" + } + } + }, "CIStatusEntry": { "type": "object", "properties": { diff --git a/api/restapi/handler/gobgp.go b/api/restapi/handler/gobgp.go index 2e1be1f23..fe82d44ba 100644 --- a/api/restapi/handler/gobgp.go +++ b/api/restapi/handler/gobgp.go @@ -16,13 +16,36 @@ package handler import ( + "net" + "github.com/go-openapi/runtime/middleware" + "github.com/loxilb-io/loxilb/api/models" "github.com/loxilb-io/loxilb/api/restapi/operations" cmn "github.com/loxilb-io/loxilb/common" tk "github.com/loxilb-io/loxilib" - "net" ) +func ConfigGetBGPNeigh(params operations.GetConfigBgpNeighAllParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + res, err := ApiHooks.NetGoBGPNeighGet() + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + var result []*models.BGPNeighGetEntry + result = make([]*models.BGPNeighGetEntry, 0) + for _, nei := range res { + tmpNeigh := models.BGPNeighGetEntry{} + tmpNeigh.IPAddress = nei.Addr + tmpNeigh.RemoteAs = int64(nei.RemoteAS) + tmpNeigh.State = nei.State + tmpNeigh.Updowntime = nei.Uptime + + result = append(result, &tmpNeigh) + } + + return operations.NewGetConfigBgpNeighAllOK().WithPayload(&operations.GetConfigBgpNeighAllOKBody{BgpNeiAttr: result}) +} func ConfigPostBGPNeigh(params operations.PostConfigBgpNeighParams) middleware.Responder { tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpNeighMod cmn.GoBGPNeighMod diff --git a/api/restapi/operations/get_config_bgp_neigh_all.go b/api/restapi/operations/get_config_bgp_neigh_all.go new file mode 100644 index 000000000..f6def74b7 --- /dev/null +++ b/api/restapi/operations/get_config_bgp_neigh_all.go @@ -0,0 +1,166 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "context" + "net/http" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + + "github.com/loxilb-io/loxilb/api/models" +) + +// GetConfigBgpNeighAllHandlerFunc turns a function with the right signature into a get config bgp neigh all handler +type GetConfigBgpNeighAllHandlerFunc func(GetConfigBgpNeighAllParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetConfigBgpNeighAllHandlerFunc) Handle(params GetConfigBgpNeighAllParams) middleware.Responder { + return fn(params) +} + +// GetConfigBgpNeighAllHandler interface for that can handle valid get config bgp neigh all params +type GetConfigBgpNeighAllHandler interface { + Handle(GetConfigBgpNeighAllParams) middleware.Responder +} + +// NewGetConfigBgpNeighAll creates a new http.Handler for the get config bgp neigh all operation +func NewGetConfigBgpNeighAll(ctx *middleware.Context, handler GetConfigBgpNeighAllHandler) *GetConfigBgpNeighAll { + return &GetConfigBgpNeighAll{Context: ctx, Handler: handler} +} + +/* + GetConfigBgpNeighAll swagger:route GET /config/bgp/neigh/all getConfigBgpNeighAll + +# Get the all of BGP Neighbor + +Get the all of BGP Neighbor +*/ +type GetConfigBgpNeighAll struct { + Context *middleware.Context + Handler GetConfigBgpNeighAllHandler +} + +func (o *GetConfigBgpNeighAll) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetConfigBgpNeighAllParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} + +// GetConfigBgpNeighAllOKBody get config bgp neigh all o k body +// +// swagger:model GetConfigBgpNeighAllOKBody +type GetConfigBgpNeighAllOKBody struct { + + // bgp nei attr + BgpNeiAttr []*models.BGPNeighGetEntry `json:"bgpNeiAttr"` +} + +// Validate validates this get config bgp neigh all o k body +func (o *GetConfigBgpNeighAllOKBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateBgpNeiAttr(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *GetConfigBgpNeighAllOKBody) validateBgpNeiAttr(formats strfmt.Registry) error { + if swag.IsZero(o.BgpNeiAttr) { // not required + return nil + } + + for i := 0; i < len(o.BgpNeiAttr); i++ { + if swag.IsZero(o.BgpNeiAttr[i]) { // not required + continue + } + + if o.BgpNeiAttr[i] != nil { + if err := o.BgpNeiAttr[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("getConfigBgpNeighAllOK" + "." + "bgpNeiAttr" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("getConfigBgpNeighAllOK" + "." + "bgpNeiAttr" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this get config bgp neigh all o k body based on the context it is used +func (o *GetConfigBgpNeighAllOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := o.contextValidateBgpNeiAttr(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *GetConfigBgpNeighAllOKBody) contextValidateBgpNeiAttr(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(o.BgpNeiAttr); i++ { + + if o.BgpNeiAttr[i] != nil { + if err := o.BgpNeiAttr[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("getConfigBgpNeighAllOK" + "." + "bgpNeiAttr" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("getConfigBgpNeighAllOK" + "." + "bgpNeiAttr" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (o *GetConfigBgpNeighAllOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *GetConfigBgpNeighAllOKBody) UnmarshalBinary(b []byte) error { + var res GetConfigBgpNeighAllOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/api/restapi/operations/get_config_bgp_neigh_all_parameters.go b/api/restapi/operations/get_config_bgp_neigh_all_parameters.go new file mode 100644 index 000000000..fb7902813 --- /dev/null +++ b/api/restapi/operations/get_config_bgp_neigh_all_parameters.go @@ -0,0 +1,46 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" +) + +// NewGetConfigBgpNeighAllParams creates a new GetConfigBgpNeighAllParams object +// +// There are no default values defined in the spec. +func NewGetConfigBgpNeighAllParams() GetConfigBgpNeighAllParams { + + return GetConfigBgpNeighAllParams{} +} + +// GetConfigBgpNeighAllParams contains all the bound params for the get config bgp neigh all operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetConfigBgpNeighAll +type GetConfigBgpNeighAllParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetConfigBgpNeighAllParams() beforehand. +func (o *GetConfigBgpNeighAllParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/restapi/operations/get_config_bgp_neigh_all_responses.go b/api/restapi/operations/get_config_bgp_neigh_all_responses.go new file mode 100644 index 000000000..ccbbeda8b --- /dev/null +++ b/api/restapi/operations/get_config_bgp_neigh_all_responses.go @@ -0,0 +1,399 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// GetConfigBgpNeighAllOKCode is the HTTP code returned for type GetConfigBgpNeighAllOK +const GetConfigBgpNeighAllOKCode int = 200 + +/* +GetConfigBgpNeighAllOK OK + +swagger:response getConfigBgpNeighAllOK +*/ +type GetConfigBgpNeighAllOK struct { + + /* + In: Body + */ + Payload *GetConfigBgpNeighAllOKBody `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllOK creates GetConfigBgpNeighAllOK with default headers values +func NewGetConfigBgpNeighAllOK() *GetConfigBgpNeighAllOK { + + return &GetConfigBgpNeighAllOK{} +} + +// WithPayload adds the payload to the get config bgp neigh all o k response +func (o *GetConfigBgpNeighAllOK) WithPayload(payload *GetConfigBgpNeighAllOKBody) *GetConfigBgpNeighAllOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all o k response +func (o *GetConfigBgpNeighAllOK) SetPayload(payload *GetConfigBgpNeighAllOKBody) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllNoContentCode is the HTTP code returned for type GetConfigBgpNeighAllNoContent +const GetConfigBgpNeighAllNoContentCode int = 204 + +/* +GetConfigBgpNeighAllNoContent OK + +swagger:response getConfigBgpNeighAllNoContent +*/ +type GetConfigBgpNeighAllNoContent struct { +} + +// NewGetConfigBgpNeighAllNoContent creates GetConfigBgpNeighAllNoContent with default headers values +func NewGetConfigBgpNeighAllNoContent() *GetConfigBgpNeighAllNoContent { + + return &GetConfigBgpNeighAllNoContent{} +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// GetConfigBgpNeighAllBadRequestCode is the HTTP code returned for type GetConfigBgpNeighAllBadRequest +const GetConfigBgpNeighAllBadRequestCode int = 400 + +/* +GetConfigBgpNeighAllBadRequest Malformed arguments for API call + +swagger:response getConfigBgpNeighAllBadRequest +*/ +type GetConfigBgpNeighAllBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllBadRequest creates GetConfigBgpNeighAllBadRequest with default headers values +func NewGetConfigBgpNeighAllBadRequest() *GetConfigBgpNeighAllBadRequest { + + return &GetConfigBgpNeighAllBadRequest{} +} + +// WithPayload adds the payload to the get config bgp neigh all bad request response +func (o *GetConfigBgpNeighAllBadRequest) WithPayload(payload *models.Error) *GetConfigBgpNeighAllBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all bad request response +func (o *GetConfigBgpNeighAllBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllUnauthorizedCode is the HTTP code returned for type GetConfigBgpNeighAllUnauthorized +const GetConfigBgpNeighAllUnauthorizedCode int = 401 + +/* +GetConfigBgpNeighAllUnauthorized Invalid authentication credentials + +swagger:response getConfigBgpNeighAllUnauthorized +*/ +type GetConfigBgpNeighAllUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllUnauthorized creates GetConfigBgpNeighAllUnauthorized with default headers values +func NewGetConfigBgpNeighAllUnauthorized() *GetConfigBgpNeighAllUnauthorized { + + return &GetConfigBgpNeighAllUnauthorized{} +} + +// WithPayload adds the payload to the get config bgp neigh all unauthorized response +func (o *GetConfigBgpNeighAllUnauthorized) WithPayload(payload *models.Error) *GetConfigBgpNeighAllUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all unauthorized response +func (o *GetConfigBgpNeighAllUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllForbiddenCode is the HTTP code returned for type GetConfigBgpNeighAllForbidden +const GetConfigBgpNeighAllForbiddenCode int = 403 + +/* +GetConfigBgpNeighAllForbidden Capacity insufficient + +swagger:response getConfigBgpNeighAllForbidden +*/ +type GetConfigBgpNeighAllForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllForbidden creates GetConfigBgpNeighAllForbidden with default headers values +func NewGetConfigBgpNeighAllForbidden() *GetConfigBgpNeighAllForbidden { + + return &GetConfigBgpNeighAllForbidden{} +} + +// WithPayload adds the payload to the get config bgp neigh all forbidden response +func (o *GetConfigBgpNeighAllForbidden) WithPayload(payload *models.Error) *GetConfigBgpNeighAllForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all forbidden response +func (o *GetConfigBgpNeighAllForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllNotFoundCode is the HTTP code returned for type GetConfigBgpNeighAllNotFound +const GetConfigBgpNeighAllNotFoundCode int = 404 + +/* +GetConfigBgpNeighAllNotFound Resource not found + +swagger:response getConfigBgpNeighAllNotFound +*/ +type GetConfigBgpNeighAllNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllNotFound creates GetConfigBgpNeighAllNotFound with default headers values +func NewGetConfigBgpNeighAllNotFound() *GetConfigBgpNeighAllNotFound { + + return &GetConfigBgpNeighAllNotFound{} +} + +// WithPayload adds the payload to the get config bgp neigh all not found response +func (o *GetConfigBgpNeighAllNotFound) WithPayload(payload *models.Error) *GetConfigBgpNeighAllNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all not found response +func (o *GetConfigBgpNeighAllNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllConflictCode is the HTTP code returned for type GetConfigBgpNeighAllConflict +const GetConfigBgpNeighAllConflictCode int = 409 + +/* +GetConfigBgpNeighAllConflict Resource Conflict. VLAN already exists OR dependency VRF/VNET not found + +swagger:response getConfigBgpNeighAllConflict +*/ +type GetConfigBgpNeighAllConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllConflict creates GetConfigBgpNeighAllConflict with default headers values +func NewGetConfigBgpNeighAllConflict() *GetConfigBgpNeighAllConflict { + + return &GetConfigBgpNeighAllConflict{} +} + +// WithPayload adds the payload to the get config bgp neigh all conflict response +func (o *GetConfigBgpNeighAllConflict) WithPayload(payload *models.Error) *GetConfigBgpNeighAllConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all conflict response +func (o *GetConfigBgpNeighAllConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllInternalServerErrorCode is the HTTP code returned for type GetConfigBgpNeighAllInternalServerError +const GetConfigBgpNeighAllInternalServerErrorCode int = 500 + +/* +GetConfigBgpNeighAllInternalServerError Internal service error + +swagger:response getConfigBgpNeighAllInternalServerError +*/ +type GetConfigBgpNeighAllInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllInternalServerError creates GetConfigBgpNeighAllInternalServerError with default headers values +func NewGetConfigBgpNeighAllInternalServerError() *GetConfigBgpNeighAllInternalServerError { + + return &GetConfigBgpNeighAllInternalServerError{} +} + +// WithPayload adds the payload to the get config bgp neigh all internal server error response +func (o *GetConfigBgpNeighAllInternalServerError) WithPayload(payload *models.Error) *GetConfigBgpNeighAllInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all internal server error response +func (o *GetConfigBgpNeighAllInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetConfigBgpNeighAllServiceUnavailableCode is the HTTP code returned for type GetConfigBgpNeighAllServiceUnavailable +const GetConfigBgpNeighAllServiceUnavailableCode int = 503 + +/* +GetConfigBgpNeighAllServiceUnavailable Maintanence mode + +swagger:response getConfigBgpNeighAllServiceUnavailable +*/ +type GetConfigBgpNeighAllServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetConfigBgpNeighAllServiceUnavailable creates GetConfigBgpNeighAllServiceUnavailable with default headers values +func NewGetConfigBgpNeighAllServiceUnavailable() *GetConfigBgpNeighAllServiceUnavailable { + + return &GetConfigBgpNeighAllServiceUnavailable{} +} + +// WithPayload adds the payload to the get config bgp neigh all service unavailable response +func (o *GetConfigBgpNeighAllServiceUnavailable) WithPayload(payload *models.Error) *GetConfigBgpNeighAllServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get config bgp neigh all service unavailable response +func (o *GetConfigBgpNeighAllServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetConfigBgpNeighAllServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/api/restapi/operations/get_config_bgp_neigh_all_urlbuilder.go b/api/restapi/operations/get_config_bgp_neigh_all_urlbuilder.go new file mode 100644 index 000000000..09e4ebc63 --- /dev/null +++ b/api/restapi/operations/get_config_bgp_neigh_all_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// GetConfigBgpNeighAllURL generates an URL for the get config bgp neigh all operation +type GetConfigBgpNeighAllURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetConfigBgpNeighAllURL) WithBasePath(bp string) *GetConfigBgpNeighAllURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetConfigBgpNeighAllURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetConfigBgpNeighAllURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/neigh/all" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetConfigBgpNeighAllURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetConfigBgpNeighAllURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetConfigBgpNeighAllURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetConfigBgpNeighAllURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetConfigBgpNeighAllURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetConfigBgpNeighAllURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/api/restapi/operations/loxilb_rest_api_api.go b/api/restapi/operations/loxilb_rest_api_api.go index 8546eb18d..43dc1fa1d 100644 --- a/api/restapi/operations/loxilb_rest_api_api.go +++ b/api/restapi/operations/loxilb_rest_api_api.go @@ -93,6 +93,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler: DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandlerFunc(func(params DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigVlanVlanIDMemberIfNameTaggedTagged has not yet been implemented") }), + GetConfigBgpNeighAllHandler: GetConfigBgpNeighAllHandlerFunc(func(params GetConfigBgpNeighAllParams) middleware.Responder { + return middleware.NotImplemented("operation GetConfigBgpNeighAll has not yet been implemented") + }), GetConfigCistateAllHandler: GetConfigCistateAllHandlerFunc(func(params GetConfigCistateAllParams) middleware.Responder { return middleware.NotImplemented("operation GetConfigCistateAll has not yet been implemented") }), @@ -283,6 +286,8 @@ type LoxilbRestAPIAPI struct { DeleteConfigVlanVlanIDHandler DeleteConfigVlanVlanIDHandler // DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler sets the operation handler for the delete config vlan vlan ID member if name tagged tagged operation DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler + // GetConfigBgpNeighAllHandler sets the operation handler for the get config bgp neigh all operation + GetConfigBgpNeighAllHandler GetConfigBgpNeighAllHandler // GetConfigCistateAllHandler sets the operation handler for the get config cistate all operation GetConfigCistateAllHandler GetConfigCistateAllHandler // GetConfigConntrackAllHandler sets the operation handler for the get config conntrack all operation @@ -491,6 +496,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler == nil { unregistered = append(unregistered, "DeleteConfigVlanVlanIDMemberIfNameTaggedTaggedHandler") } + if o.GetConfigBgpNeighAllHandler == nil { + unregistered = append(unregistered, "GetConfigBgpNeighAllHandler") + } if o.GetConfigCistateAllHandler == nil { unregistered = append(unregistered, "GetConfigCistateAllHandler") } @@ -770,6 +778,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/config/bgp/neigh/all"] = NewGetConfigBgpNeighAll(o.context, o.GetConfigBgpNeighAllHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/config/cistate/all"] = NewGetConfigCistateAll(o.context, o.GetConfigCistateAllHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) diff --git a/api/swagger.yml b/api/swagger.yml index 8541303cb..0dfe7d8a0 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2100,6 +2100,50 @@ paths: #---------------------------------------------- # GoBGP #---------------------------------------------- + '/config/bgp/neigh/all': + get: + summary: Get the all of BGP Neighbor + description: Get the all of BGP Neighbor + responses: + '200': + description: OK + schema: + type: object + properties: + bgpNeiAttr: + type: array + items: + $ref: '#/definitions/BGPNeighGetEntry' + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '403': + description: Capacity insufficient + schema: + $ref: '#/definitions/Error' + '404': + description: Resource not found + schema: + $ref: '#/definitions/Error' + '409': + description: Resource Conflict. VLAN already exists OR dependency VRF/VNET not found + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintanence mode + schema: + $ref: '#/definitions/Error' '/config/bgp/neigh': post: summary: Adds a BGP Neighbor @@ -3108,6 +3152,24 @@ definitions: type: boolean description: Enable multi-hop peering (if needed) + + BGPNeighGetEntry: + type: object + properties: + ipAddress: + type: string + description: BGP Neighbor IP address + remoteAs: + type: integer + description: Remote AS number + state: + type: string + description: Current state + updowntime: + type: string + description: Current uptime + + BGPGlobalConfig: type: object properties: diff --git a/common/common.go b/common/common.go index 2c43bf81b..286864f38 100644 --- a/common/common.go +++ b/common/common.go @@ -612,6 +612,14 @@ type GoBGPNeighMod struct { MultiHop bool `json:"multiHop"` } +// GoBGPNeighGetMod - Info related to goBGP neigh +type GoBGPNeighGetMod struct { + Addr string `json:"neighIP"` + RemoteAS uint32 `json:"remoteAS"` + State string `json:"state"` + Uptime string `json:"uptime"` +} + // Equal - check if two session tunnel entries are equal func (ut *SessTun) Equal(ut1 *SessTun) bool { if ut.TeID == ut1.TeID && ut.Addr.Equal(ut1.Addr) { @@ -821,6 +829,7 @@ type NetHookInterface interface { NetEpHostGet() ([]EndPointMod, error) NetParamSet(param ParamMod) (int, error) NetParamGet(param *ParamMod) (int, error) + NetGoBGPNeighGet() ([]GoBGPNeighGetMod, error) NetGoBGPNeighAdd(nm *GoBGPNeighMod) (int, error) NetGoBGPNeighDel(nm *GoBGPNeighMod) (int, error) NetGoBGPGCAdd(gc *GoBGPGlobalConfig) (int, error) diff --git a/loxinet/apiclient.go b/loxinet/apiclient.go index 2f1e8c208..80ba65b07 100644 --- a/loxinet/apiclient.go +++ b/loxinet/apiclient.go @@ -587,6 +587,20 @@ func (na *NetAPIStruct) NetParamGet(param *cmn.ParamMod) (int, error) { return ret, err } +// NetGoBGPNeighGet - Get bgp neigh to gobgp +func (na *NetAPIStruct) NetGoBGPNeighGet() ([]cmn.GoBGPNeighGetMod, error) { + if mh.bgp != nil { + a, err := mh.bgp.BGPNeighGet("", false) + if err != nil { + return nil, err + } + return a, nil + } + tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") + return nil, errors.New("loxilb BGP mode is disabled") + +} + // NetGoBGPNeighAdd - Add bgp neigh to gobgp func (na *NetAPIStruct) NetGoBGPNeighAdd(param *cmn.GoBGPNeighMod) (int, error) { if mh.bgp != nil { diff --git a/loxinet/gobgpclient.go b/loxinet/gobgpclient.go index 33e54fe6e..bd00984f3 100644 --- a/loxinet/gobgpclient.go +++ b/loxinet/gobgpclient.go @@ -920,6 +920,53 @@ func (gbh *GoBgpH) resetBGPPolicy(toLow bool) error { return nil } +// BGPNeighGet - Routine to get BGP neigh from goBGP server +func (gbh *GoBgpH) BGPNeighGet(address string, enableAdv bool) ([]cmn.GoBGPNeighGetMod, error) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + defer cancel() + stream, err := gbh.client.ListPeer(ctx, &api.ListPeerRequest{ + Address: address, + EnableAdvertised: enableAdv, + }) + if err != nil { + return nil, err + } + + b := make([]cmn.GoBGPNeighGetMod, 0, 1024) + for { + r, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + return nil, err + } + tmpPeer := cmn.GoBGPNeighGetMod{} + tmpPeer.Addr = r.Peer.State.NeighborAddress + tmpPeer.RemoteAS = r.Peer.State.PeerAsn + tmpPeer.State = r.Peer.State.SessionState.String() + timeStr := "never" + maxtimelen := len("Up/Down") + if r.Peer.Timers.State.Uptime != nil { + t := r.Peer.Timers.State.Downtime.AsTime() + if r.Peer.State.SessionState == api.PeerState_ESTABLISHED { + t = r.Peer.Timers.State.Uptime.AsTime() + } + timeStr = FormatTimedelta(t) + } + if len(timeStr) > maxtimelen { + maxtimelen = len(timeStr) + } + + tmpPeer.Uptime = timeStr + b = append(b, tmpPeer) + } + if address != "" && len(b) == 0 { + return b, fmt.Errorf("not found neighbor %s", address) + } + + return b, err +} + // BGPNeighMod - Routine to add BGP neigh to goBGP server func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32, rPort uint32, mhop bool) (int, error) { var peer *api.Peer diff --git a/loxinet/utils.go b/loxinet/utils.go index 40cca7c36..f91e133f0 100644 --- a/loxinet/utils.go +++ b/loxinet/utils.go @@ -23,6 +23,7 @@ import ( "crypto/x509" "encoding/binary" "errors" + "fmt" "io/ioutil" "net" "net/http" @@ -307,3 +308,23 @@ func GratArpReqWithCtx(ctx context.Context, rCh chan<- int, AdvIP net.IP, ifName } } } + +func FormatTimedelta(t time.Time) string { + d := time.Now().Unix() - t.Unix() + u := uint64(d) + neg := d < 0 + if neg { + u = -u + } + secs := u % 60 + u /= 60 + mins := u % 60 + u /= 60 + hours := u % 24 + days := u / 24 + + if days == 0 { + return fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs) + } + return fmt.Sprintf("%dd ", days) + fmt.Sprintf("%02d:%02d:%02d", hours, mins, secs) +}