Skip to content
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c9606fd
Add initial RIB management.
robshakir Jun 8, 2021
74a88d6
Add support for different network instances in the RIB.
robshakir Jun 9, 2021
fb91477
Add support for adding NHG and NH values.
robshakir Jun 9, 2021
b1b0104
validate entries against schema before allowing them.#
robshakir Jun 9, 2021
2bd0bc1
Update comments.
robshakir Jun 9, 2021
e73db09
Address review comments.
robshakir Jun 10, 2021
7514349
Merge branch 'rib1' into rib2
robshakir Jun 10, 2021
7a7caaa
Merge branch 'main' into rib2
robshakir Jun 10, 2021
c4d17e1
Merge branch 'main' into rib2
robshakir Jun 10, 2021
5803e14
Add support for a callback after each RIB operation.
robshakir Jun 11, 2021
1aef65f
Add an initial implementation of a resolved-RIB. (#22)
robshakir Jun 11, 2021
8208a66
Add gNMI cache for target to use.
robshakir Jun 11, 2021
d6a2a06
Improve commenting and avoid hostname repetition.
robshakir Jun 11, 2021
3d957e1
Merge branch 'main' into rib4
robshakir Jun 12, 2021
2eee535
Fix bad merge.
robshakir Jun 12, 2021
6996899
Fix commenting.
robshakir Jun 12, 2021
b5bc01b
start to integrate services for device.
robshakir Jun 12, 2021
fd1a4b8
Add test file.
robshakir Jun 12, 2021
12cc0a0
Move to latest version of ygot, server goroutines.
robshakir Jun 14, 2021
85ce82d
Deflake test by validating correct semantics.
robshakir Jun 14, 2021
f49693f
Merge branch 'rib4' into rib4.5
robshakir Jun 15, 2021
4b20ff9
Add support for entries in fluent, improve coverage.
robshakir Jun 15, 2021
b61e8b9
Add support for adding IPv4 Entries.
robshakir Jun 15, 2021
0540a61
Merge branch 'rib4.6' into rib5
robshakir Jun 15, 2021
ae26c50
Refactor RIB implementation.
robshakir Jun 15, 2021
a9afd5f
Add initial 'device' function which acts as a combined server.
robshakir Jun 15, 2021
bb0b789
Add main package.
robshakir Jun 15, 2021
245e4c0
Split into separate tests rather than using subtests.
robshakir Jun 15, 2021
aa061b0
Merge branch 'rib4' into rib4.5
robshakir Jun 15, 2021
85795df
Merge branch 'main' into rib4.5
robshakir Jun 15, 2021
8041fe3
Merge branch 'rib4.5' into rib4.6
robshakir Jun 15, 2021
ed26938
Remove stale comment.
robshakir Jun 15, 2021
b82d9a6
Merge branch 'rib4.5' into rib4.6
robshakir Jun 15, 2021
69ed249
Add test coverage, robustness, cleaner election handling.
robshakir Jun 16, 2021
3a3e934
Resolve race.
robshakir Jun 16, 2021
84f1e2e
🧹
robshakir Jun 16, 2021
b5d9589
Add lock to check whether the RIB is valid.
robshakir Jun 16, 2021
0e80281
Merge branch 'rib4.6' into rib5
robshakir Jun 16, 2021
4aa7fd1
Remove const package.
robshakir Jun 16, 2021
7e1a0ad
Plumb TLS through the client.
robshakir Jun 16, 2021
43d36b1
# TODO: Summary
robshakir Jun 16, 2021
e274145
Update CI to exclude files from race testing.
robshakir Jun 16, 2021
4b12cc7
Switch to race testing everything.
robshakir Jun 16, 2021
a4f0ea9
Add checking whether candidates can be resolved in gRIBI.
robshakir Jun 16, 2021
73c4c01
Make race tests run for all code.
robshakir Jun 16, 2021
bdcf19e
Merge branch 'main' into rib5
robshakir Jun 17, 2021
bd6d4fe
Merge branch 'rib5' into rib6
robshakir Jun 17, 2021
d2e6e88
Merge branch 'main' into rib5
robshakir Jun 17, 2021
b80637b
Merge branch 'rib5' into rib6
robshakir Jun 17, 2021
4f222c8
Remove duplicate default network instance name const.
robshakir Jun 17, 2021
c600905
Merge branch 'rib5' into rib6
robshakir Jun 17, 2021
9e78142
Resolve test failures following merge.
robshakir Jun 17, 2021
f554887
Fix stale references.
robshakir Jun 17, 2021
d8adc99
Merge branch 'rib5' into rib6
robshakir Jun 17, 2021
98ae8be
Address review comments.
robshakir Jun 18, 2021
0e70e5d
Clean up use of context.
robshakir Jun 18, 2021
b788c46
Fix tests.
robshakir Jun 18, 2021
cafce1f
Merge branch 'rib5' into rib6
robshakir Jun 18, 2021
6dbf870
gofmt.
robshakir Jun 18, 2021
820d242
Merge branch 'rib5' into rib6
robshakir Jun 18, 2021
2c5fc15
Merge branch 'main' into rib6
robshakir Jun 18, 2021
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
4 changes: 1 addition & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ jobs:

- name: Race Test
run: |
for i in `find . -type d -mindepth 1 -maxdepth 1 | egrep -v ".git|.github|fluent|doc"`; do
go test -race ./$i
done
go test -race ./...

- name: Coveralls
if: ${{ matrix.go == '1.14' }}
Expand Down
227 changes: 105 additions & 122 deletions aft/oc.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions aft/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ generator -path=gribi -output_file=oc.go \
-typedef_enum_with_defmod \
-enum_suffix_for_simple_union_enums \
-exclude_modules=openconfig-interfaces,ietf-interfaces \
-generate_simple_unions \
-generate_getters \
-generate_leaf_getters \
-generate_delete \
Expand Down
38 changes: 34 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package client
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
Expand All @@ -14,6 +15,7 @@ import (
log "github.com/golang/glog"
"go.uber.org/atomic"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"lukechampine.com/uint128"

spb "github.com/openconfig/gribi/v1/proto/service"
Expand Down Expand Up @@ -151,7 +153,11 @@ type DialOpt interface {
func (c *Client) Dial(ctx context.Context, addr string, opts ...DialOpt) error {
// TODO(robjs): translate any options within the dial options here, we may
// want to consider just accepting some gRPC dialoptions directly.
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithBlock())

conn, err := grpc.DialContext(ctx, addr,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
InsecureSkipVerify: true,
})), grpc.WithBlock())
if err != nil {
return fmt.Errorf("cannot dial remote system, %v", err)
}
Expand Down Expand Up @@ -529,7 +535,7 @@ func (c *Client) StartSending() {
defer c.qs.sendMu.Unlock()
for _, m := range c.qs.sendq {
log.V(2).Infof("sending %s to modify channel", m)
c.Q(m)
c.q(m)
}
c.qs.sendq = []*spb.ModifyRequest{}
}
Expand Down Expand Up @@ -598,6 +604,13 @@ func (c *Client) handleModifyResponse(m *spb.ModifyResponse) error {
}

// TODO(robjs): add handling of received operations.
for _, r := range m.Result {
res, err := c.clearPendingOp(r)
c.qs.resultq = append(c.qs.resultq, res)
if err != nil {
return fmt.Errorf("cannot remove pending operation %d, %v", r.Id, err)
}
}

return nil
}
Expand All @@ -623,8 +636,8 @@ func (c *Client) isConverged() bool {
func (c *Client) addPendingOp(op *spb.AFTOperation) error {
c.qs.pendMu.Lock()
defer c.qs.pendMu.Unlock()
if c.qs.pendq.Ops[op.Id] != nil {
return fmt.Errorf("could not enqueue operation %d, duplicate pending ID", op.Id)
if v := c.qs.pendq.Ops[op.Id]; v != nil {
return fmt.Errorf("could not enqueue operation %d, duplicate pending ID (pending: %v)", op.Id, v)
}
c.qs.pendq.Ops[op.Id] = &PendingOp{
Timestamp: unixTS(),
Expand All @@ -633,6 +646,23 @@ func (c *Client) addPendingOp(op *spb.AFTOperation) error {
return nil
}

// clearPendingOp removes the operation with the ID in the specified result from the
// pending queue and returns the result.
func (c *Client) clearPendingOp(op *spb.AFTResult) (*OpResult, error) {
c.qs.pendMu.Lock()
defer c.qs.pendMu.Unlock()
v := c.qs.pendq.Ops[op.Id]
if v == nil {
return nil, fmt.Errorf("could not dequeue operation %d, unknown operation", op.Id)
}
delete(c.qs.pendq.Ops, op.Id)
n := unixTS()
return &OpResult{
Timestamp: n,
Latency: n - v.Timestamp,
}, nil
}

// updatePendingElection adds the election ID specified by id to the pending transaction
// queue on the client. There can only be a single pending election, and hence the
// election ID is updated in place.
Expand Down
35 changes: 35 additions & 0 deletions cmd/rtr/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"context"
"flag"

log "github.com/golang/glog"
"github.com/openconfig/gribigo/device"
)

var (
certFile = flag.String("cert", "", "cert is the path to the server TLS certificate file")
keyFile = flag.String("key", "", "key is the path to the server TLS key file")
)

func main() {
flag.Parse()

if *certFile == "" || *keyFile == "" {
log.Exitf("must specify a TLS certificate and key file")
}

ctx := context.Background()
creds, err := device.TLSCredsFromFile(*certFile, *keyFile)
if err != nil {
log.Exitf("cannot initialise TLS, got: %v", err)
}
d, cancel, err := device.New(context.Background(), creds)
defer cancel()
if err != nil {
log.Exitf("cannot start device, %v", err)
}
log.Infof("listening on:\n\tgRIBI: %s\n\tgNMI: %s", d.GRIBIAddr(), d.GNMIAddr())
<-ctx.Done()
}
18 changes: 18 additions & 0 deletions compliance/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ package compliance

import (
"context"
"fmt"
"testing"

"github.com/openconfig/gribigo/chk"
"github.com/openconfig/gribigo/client"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/gribigo/server"
"google.golang.org/grpc/codes"
)

Expand Down Expand Up @@ -87,3 +89,19 @@ func ModifyConnectionSinglePrimaryPreserve(addr string, t testing.TB) {
t.Fatalf("did not get expected error type, got: %v, want: %v", ce, want)
}
}

// AddIPv4EntrySuccess adds a simple IPv4 Entry which references a next-hop-group to the gRIBI target.
func AddIPv4EntrySuccess(addr string, t testing.TB) {
c := fluent.NewClient()
c.Connection().WithTarget(addr).WithRedundancyMode(fluent.ElectedPrimaryClient).WithInitialElectionID(0, 1).WithPersistence()
c.Start(context.Background(), t)
c.Modify().AddEntry(t, fluent.IPv4Entry().WithPrefix("1.1.1.1/32").WithNetworkInstance(server.DefaultNIName).WithNextHopGroup(42))
c.StartSending(context.Background(), t)
err := c.Await(context.Background(), t)
if err != nil {
t.Fatalf("got unexpected error from server, got: %v, want: nil", err)
}
// TODO(robjs): add verification of the received gRIBI results.
// TODO(robjs): add gNMI subscription using generated telemetry library.
fmt.Printf("%v\n", c.Results(t))
}
19 changes: 14 additions & 5 deletions compliance/compliance_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package compliance

import (
"context"
"strings"
"testing"

"github.com/openconfig/gribigo/device"
"github.com/openconfig/gribigo/negtest"
"github.com/openconfig/gribigo/testcommon"
)
Expand Down Expand Up @@ -32,12 +34,19 @@ func TestModifyConnectionParameters(t *testing.T) {

for _, tt := range tests {
t.Run(tt.in.ShortName, func(t *testing.T) {
startServer, addr := testcommon.Server()
go startServer()
creds, err := device.TLSCredsFromFile(testcommon.TLSCreds())
if err != nil {
t.Fatalf("cannot load credentials, got err: %v", err)
}
d, cancel, err := device.New(context.Background(), creds)
defer cancel()
if err != nil {
t.Fatalf("cannot start server, %v", err)
}

if tt.wantFatalMsg != "" {
if got := negtest.ExpectFatal(t, func(t testing.TB) {
tt.in.Fn(addr, t)
tt.in.Fn(d.GRIBIAddr(), t)
}); !strings.Contains(got, tt.wantFatalMsg) {
t.Fatalf("did not get expected fatal error, got: %s, want: %s", got, tt.wantFatalMsg)
}
Expand All @@ -46,14 +55,14 @@ func TestModifyConnectionParameters(t *testing.T) {

if tt.wantErrorMsg != "" {
if got := negtest.ExpectError(t, func(t testing.TB) {
tt.in.Fn(addr, t)
tt.in.Fn(d.GRIBIAddr(), t)
}); !strings.Contains(got, tt.wantErrorMsg) {
t.Fatalf("did not get expected error, got: %s, want: %s", got, tt.wantErrorMsg)
}
}

// Any unexpected error will be caught by being called directly on t from the fluent library.
tt.in.Fn(addr, t)
tt.in.Fn(d.GRIBIAddr(), t)
})
}
}
16 changes: 16 additions & 0 deletions constants/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// package constants defines constants that are shared amongst multiple gRIBIgo packages.
package constants

// OpType indicates the type of operation that was performed in contexts where it
// is not available, such as callbacks to user-provided functions.
type OpType int64

const (
_ OpType = iota
// ADD indicates that the operation called was an Add.
ADD
// DELETE indicates that the operation called was a Delete.
DELETE
// MODIFY indicates that the operation called was a Modify.
MODIFY
)
4 changes: 4 additions & 0 deletions demo/ipv4/ipv4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package ipv4 is a very simple (test) demo package that shows
// an IPv4 entry being sent to the gRIBI server using the fluent
// API and client packages defined in this package.
package ipv4
26 changes: 26 additions & 0 deletions demo/ipv4/ipv4_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ipv4

import (
"flag"
"testing"
"time"

"github.com/openconfig/gribigo/compliance"
)

var (
addr = flag.String("addr", "", "address of the gRIBI target")
run = flag.Bool("run", false, "whether to run the tests, this stops this file causing failures in CI")
)

func TestDemo(t *testing.T) {
flag.Parse()
if !*run {
return
}
if *addr == "" {
t.Fatalf("must specify an address")
}
compliance.AddIPv4EntrySuccess(*addr, t)
time.Sleep(2 * time.Second)
}
Loading