Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Initial gateway code #2

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
01d0067
Initial proposal of new api for go based gateway
sbezverk Jan 23, 2020
f46a3fe
Add generated code
sbezverk Jan 23, 2020
484dd7f
Addressing comment
sbezverk Jan 23, 2020
167b088
regenerating proto for grpc plugin
sbezverk Jan 23, 2020
faf32e8
Define errors code for consistent error handling
sbezverk Jan 24, 2020
8883ea6
Add new vpn label service
sbezverk Jan 27, 2020
5ccf250
Switch to use oneof
sbezverk Jan 27, 2020
5299d4e
Fix typos
sbezverk Jan 27, 2020
24f118a
simplify route distinguisher type
sbezverk Jan 28, 2020
ef7704e
Update api
sbezverk Feb 1, 2020
3a1d6cc
update rt name
sbezverk Feb 1, 2020
0e4f13f
change name
sbezverk Feb 1, 2020
3119838
Add vpn prefix to vpn request
sbezverk Feb 4, 2020
304e952
initial gateway files
sbezverk Jan 23, 2020
2685956
Add grpc testing
sbezverk Jan 24, 2020
3a9abed
Add timeout for request processing
sbezverk Jan 24, 2020
4f65466
Start mock db client
sbezverk Jan 26, 2020
41b6214
Rearrange DB mock and db client code
sbezverk Jan 26, 2020
515d072
Mkae sure all go routine can be terminated on a timeout
sbezverk Jan 26, 2020
9152de9
new api
sbezverk Jan 27, 2020
e10739f
fix import name
sbezverk Jan 27, 2020
cac979b
Adjust to new api
sbezverk Jan 28, 2020
799f4a1
Add script to build code and container
sbezverk Jan 28, 2020
384715c
Add initial bits for bgp client
sbezverk Jan 28, 2020
5c3a20c
gateway client
sbezverk Feb 1, 2020
6cb403a
More client code
sbezverk Feb 1, 2020
c3cab7e
working on vpn rpc
sbezverk Feb 2, 2020
c030186
working on label api
sbezverk Feb 4, 2020
fc93ac7
refactor bgp client
sbezverk Feb 6, 2020
f54205d
fix panic
sbezverk Feb 6, 2020
c35870f
add marshal/unmarshal functions for greater flexibility
sbezverk Feb 6, 2020
2e88d69
refactor interface with bgp
sbezverk Feb 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add initial bits for bgp client
Signed-off-by: Serguei Bezverkhi <[email protected]>
sbezverk committed Feb 4, 2020

Verified

This commit was signed with the committer’s verified signature.
steventux Steve Laing
commit 384715c70faaecf07ed348de673f741123d10ff3
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ all: jalapeno-gateway

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

container: jalapeno-gateway
docker build -t $(REGISTRY_NAME)/jalapeno-gateway-debug:$(IMAGE_VERSION) -f ./build/Dockerfile.gateway .
9 changes: 8 additions & 1 deletion cmd/gateway.go → cmd/jalapeno-gateway.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
"os/signal"
"strconv"

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

// For now just get stuck on stop channel, later add signal processing
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module gateway
module github.com/cisco-ie/jalapeno-go-gateway/jalapeno-gateway

go 1.13

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

replace (
github.com/cisco-ie/jalapeno-go-gateway/pkg/apis => ./pkg/apis
github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient => ./pkg/bgpclient
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient => ./pkg/dbclient
github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient/mock => ./pkg/dbclient/mock
github.com/cisco-ie/jalapeno-go-gateway/pkg/gateway => ./pkg/gateway
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/osrg/gobgp v2.0.0+incompatible h1:91ARQbE1AtO0U4TIxHPJ7wYVZIqduyBwS1+FjlHlmrY=
github.com/osrg/gobgp v2.0.0+incompatible/go.mod h1:vGVJPLW6JFDD7WA1vJsjB8OKmbbC2TKwHtr90CZS/u4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
39 changes: 39 additions & 0 deletions pkg/bgpclient/bgpclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package bgpclient

import (
"context"

api "github.com/osrg/gobgp/api"
"google.golang.org/grpc"
)

// BGPClient defines the interface for communication with gobgpd process
type BGPClient interface {
}

type bgpclient struct {
conn *grpc.ClientConn
bgp api.GobgpApiClient
}

// NewBGPClient creates a new instance of BGP client, addr variable carries
// the address of gobgp process, it could in ip:port or dns-name:port formats.
func NewBGPClient(addr string) (BGPClient, error) {
conn, err := grpc.DialContext(context.TODO(), addr, grpc.WithInsecure())
if err != nil {
return nil, err
}
client := api.NewGobgpApiClient(conn)
// Testing connection to gobgp by requesting its global config
if _, err := client.GetBgp(context.TODO(), &api.GetBgpRequest{}); err != nil {
return nil, err
}
return &bgpclient{
conn: conn,
bgp: client,
}, nil
}

func (b *bgpclient) Stop() {
b.conn.Close()
}
3 changes: 3 additions & 0 deletions pkg/bgpclient/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/cisco-ie/jalapeno-go-gateway/pkg/bgplient

go 1.13
5 changes: 4 additions & 1 deletion pkg/gateway/server.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"time"

pbapi "github.com/cisco-ie/jalapeno-go-gateway/pkg/apis"
"github.com/cisco-ie/jalapeno-go-gateway/pkg/bgpclient"
"github.com/cisco-ie/jalapeno-go-gateway/pkg/dbclient"
"github.com/golang/glog"
"google.golang.org/grpc"
@@ -27,6 +28,7 @@ type gateway struct {
gSrv *grpc.Server
conn net.Listener
dbc dbclient.DBClient
bgp bgpclient.BGPClient
}

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

// NewGateway return an instance of Gateway interface
func NewGateway(conn net.Listener, dbc dbclient.DBClient) Gateway {
func NewGateway(conn net.Listener, dbc dbclient.DBClient, bgp bgpclient.BGPClient) Gateway {
gSrv := gateway{
conn: conn,
gSrv: grpc.NewServer([]grpc.ServerOption{}...),
dbc: dbc,
bgp: bgp,
}
pbapi.RegisterGatewayServiceServer(gSrv.gSrv, &gSrv)