Skip to content

Commit bfb929e

Browse files
committed
Add initial bits for bgp client
Signed-off-by: Serguei Bezverkhi <[email protected]>
1 parent 4e12bed commit bfb929e

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ all: jalapeno-gateway
1313

1414
jalapeno-gateway:
1515
mkdir -p bin
16-
CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -ldflags '-extldflags "-static"' -o ./bin/jalapeno-gateway ./cmd/gateway.go
16+
CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -ldflags '-extldflags "-static"' -o ./bin/jalapeno-gateway ./cmd/jalapeno-gateway.go
1717

1818
container: jalapeno-gateway
1919
docker build -t $(REGISTRY_NAME)/jalapeno-gateway-debug:$(IMAGE_VERSION) -f ./build/Dockerfile.gateway .

cmd/gateway.go renamed to cmd/jalapeno-gateway.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/signal"
99
"strconv"
1010

11+
"github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient"
1112
"github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient"
1213
"github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient/mock"
1314
"github.com/cisco-ie/jalapeno-go-gateway/pkg/gateway"
@@ -42,6 +43,12 @@ func main() {
4243
glog.Warningf("env variable \"GATEWAY_PORT\" containes an invalid value %d, using default Gateway port instead: %s\n", srvPort, defaultGatewayPort)
4344
srvPort, _ = strconv.Atoi(defaultGatewayPort)
4445
}
46+
// Instantiate BGP client
47+
// TODO, the address:port of gobgp should be provided as a parameter.
48+
bgp, err := bgpclient.NewBGPClient("gobgpd.default:50051")
49+
if err != nil {
50+
glog.Warningf("failed to instantiate bgp client with error: %+v", err)
51+
}
4552
// Get interface to the database
4653
// TODO, since it is not clear which database will be used, for now use mock DB
4754
db := mock.NewMockDB()
@@ -53,7 +60,7 @@ func main() {
5360
glog.Errorf("failed to setup listener with with error: %+v", err)
5461
os.Exit(1)
5562
}
56-
gSrv := gateway.NewGateway(conn, dbc)
63+
gSrv := gateway.NewGateway(conn, dbc, bgp)
5764
gSrv.Start()
5865

5966
// For now just get stuck on stop channel, later add signal processing

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
module gateway
1+
module github.com/cisco-ie/jalapeno-go-gateway/jalapeno-gateway
22

33
go 1.13
44

55
require (
6+
github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient v0.0.0-00010101000000-000000000000
67
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient v0.0.0-00010101000000-000000000000
78
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient/mock v0.0.0-00010101000000-000000000000
89
github.com/cisco-ie/jalapeno-go-gateway/pkg/gateway v0.0.0-00010101000000-000000000000
910
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
1011
github.com/google/go-cmp v0.4.0 // indirect
12+
github.com/osrg/gobgp v2.0.0+incompatible // indirect
1113
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect
1214
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 // indirect
1315
golang.org/x/text v0.3.2 // indirect
@@ -16,6 +18,7 @@ require (
1618

1719
replace (
1820
github.com/cisco-ie/jalapeno-go-gateway/pkg/apis => ./pkg/apis
21+
github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient => ./pkg/bgpclient
1922
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient => ./pkg/dbclient
2023
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient/mock => ./pkg/dbclient/mock
2124
github.com/cisco-ie/jalapeno-go-gateway/pkg/gateway => ./pkg/gateway

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
1414
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
1515
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
1616
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
17+
github.com/osrg/gobgp v2.0.0+incompatible h1:91ARQbE1AtO0U4TIxHPJ7wYVZIqduyBwS1+FjlHlmrY=
18+
github.com/osrg/gobgp v2.0.0+incompatible/go.mod h1:vGVJPLW6JFDD7WA1vJsjB8OKmbbC2TKwHtr90CZS/u4=
1719
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
1820
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1921
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=

pkg/bgpclient/bgpclient.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package bgpclient
2+
3+
import (
4+
"context"
5+
6+
api "github.com/osrg/gobgp/api"
7+
"google.golang.org/grpc"
8+
)
9+
10+
// BGPClient defines the interface for communication with gobgpd process
11+
type BGPClient interface {
12+
}
13+
14+
type bgpclient struct {
15+
conn *grpc.ClientConn
16+
bgp api.GobgpApiClient
17+
}
18+
19+
// NewBGPClient creates a new instance of BGP client, addr variable carries
20+
// the address of gobgp process, it could in ip:port or dns-name:port formats.
21+
func NewBGPClient(addr string) (BGPClient, error) {
22+
conn, err := grpc.DialContext(context.TODO(), addr, grpc.WithInsecure())
23+
if err != nil {
24+
return nil, err
25+
}
26+
client := api.NewGobgpApiClient(conn)
27+
// Testing connection to gobgp by requesting its global config
28+
if _, err := client.GetBgp(context.TODO(), &api.GetBgpRequest{}); err != nil {
29+
return nil, err
30+
}
31+
return &bgpclient{
32+
conn: conn,
33+
bgp: client,
34+
}, nil
35+
}
36+
37+
func (b *bgpclient) Stop() {
38+
b.conn.Close()
39+
}

pkg/bgpclient/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/cisco-ie/jalapeno-go-gateway/pkg/bgplient
2+
3+
go 1.13

pkg/gateway/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
pbapi "github.com/cisco-ie/jalapeno-go-gateway/pkg/apis"
9+
"github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient"
910
"github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient"
1011
"github.com/golang/glog"
1112
"google.golang.org/grpc"
@@ -27,6 +28,7 @@ type gateway struct {
2728
gSrv *grpc.Server
2829
conn net.Listener
2930
dbc dbclient.DBClient
31+
bgp bgpclient.BGPClient
3032
}
3133

3234
func (g *gateway) Start() {
@@ -61,11 +63,12 @@ func (g *gateway) QoE(ctx context.Context, reqQoes *pbapi.RequestQoE) (*pbapi.Re
6163
}
6264

6365
// NewGateway return an instance of Gateway interface
64-
func NewGateway(conn net.Listener, dbc dbclient.DBClient) Gateway {
66+
func NewGateway(conn net.Listener, dbc dbclient.DBClient, bgp bgpclient.BGPClient) Gateway {
6567
gSrv := gateway{
6668
conn: conn,
6769
gSrv: grpc.NewServer([]grpc.ServerOption{}...),
6870
dbc: dbc,
71+
bgp: bgp,
6972
}
7073
pbapi.RegisterGatewayServiceServer(gSrv.gSrv, &gSrv)
7174

0 commit comments

Comments
 (0)