Skip to content

Commit

Permalink
Merge pull request #32 from karimra/housekeeping
Browse files Browse the repository at this point in the history
various housekeeping changes
  • Loading branch information
karimra authored Aug 24, 2023
2 parents c37ecf5 + 737666e commit 89126a7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
48 changes: 32 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

SRL gRPC Tunnel is an [SR Linux](https://learn.srlinux.dev/) [NDK](https://learn.srlinux.dev/ndk/intro/) application that adds support for [Openconfig gRPC tunnel](https://github.com/openconfig/grpctunnel) to SR Linux.

It acts as a gRPC tunnel client to allow access to locally configured targets (gNMI server, gNMI server, SSH server...)
It acts as a gRPC tunnel client to allow access to locally configured targets (gNMI server, gNOI server, SSH server...)

It connects to a gRPC tunnel server such as [gNMIc](https://gnmic.kmrd.dev/user_guide/tunnel_server/).
It connects to a gRPC tunnel server such as [gNMIc](https://gnmic.openconfig.net/user_guide/tunnel_server/).

## Features

* gRPC tunnel client handling gNMI, SSH and custom targets
* gRPC tunnel client handles gNMI, SSH and custom targets

* Both secure and insecure connections are supported

Expand Down Expand Up @@ -42,11 +42,10 @@ Copy the RPM file to your SR Linux instance and run (from bash)
sudo rpm -i srl-grpc-tunnel_0.0.1_Linux_x86_64.rpm
```

Start an `sr_cli` session and reload the application manager
Reload the application manager

```bash
--{ + running }--[ ]--
A:srl1# tools system app-management application app_mgr reload
sr_cli tools system app-management application app_mgr reload
```

Check that the `grpc-tunnel` application is running
Expand All @@ -65,7 +64,7 @@ A:srl1#

## Configuration

``` bash
``` shell
--{ + running }--[ system grpc-tunnel ]--
A:srl1#
Local commands:
Expand All @@ -76,7 +75,7 @@ Local commands:

### Destinations (gRPC Tunnel servers)

```bash
```shell
--{ + running }--[ system grpc-tunnel ]--
A:srl1# destination d1
usage: destination <name>
Expand Down Expand Up @@ -104,7 +103,7 @@ Setting a tls-profile on the client side is not implemented yet, by default the

To configure a gRPC tunnel destination `d1` run the below commands:

```bash
```shell
enter candidate
# create destination d1
/ system grpc-tunnel destination d1
Expand All @@ -130,7 +129,7 @@ A:srl1#

#### gNMI

```bash
```shell
gnmic -a clab-grpc-tunnel-srl1 -u admin -p admin --skip-verify set \
--update /system/grpc-tunnel/destination[name=d1]/address:::json_ietf:::172.20.20.2 \
--update /system/grpc-tunnel/destination[name=d1]/port:::json_ietf:::57401 \
Expand All @@ -148,7 +147,7 @@ A max of 16 tunnels can be created, To each one, 16 destinations can be linked.

To configure a gRPC tunnel `t1` run the below commands:

```bash
```shell
enter candidate
# create tunnel d1
/ system grpc-tunnel tunnel t1
Expand All @@ -159,7 +158,7 @@ commit now

#### gNMI

```bash
```shell
gnmic -a clab-grpc-tunnel-srl1 -u admin -p admin --skip-verify set \
--update /system/grpc-tunnel/tunnel[name=t1]:::json_ietf:::'{"destination":{"name":"d1"}}'
```
Expand All @@ -180,10 +179,27 @@ Local commands:
type target type
```

Add a target called tg1, type `grpc-server` with ID `node-name`
The `id` and `type` are the unique identifiers used to register the target with the gRPC tunnel server.
The `local-address` is used to customize the local handler behavior by changing the dialed address when a request is received through the tunnel.

The target `id` values are:

* `node-name`: The configure node host-name under `system name host-name`
* `user-agent`: A custom string in the format `<node-name>:nokia-srl:<chassis>:<sw-version>`
* `mac-address`: The node chassis mac address
* `custom <string>`: A user defined string, or a Go template that uses the systemInfo struct as input.

The target `type` values are:

* `grpc-server`: This sets the target type to `GNMI_GNOI` when registering the target with the gRPC tunnel server. In this case, the `local-address` defaults to `unix:///opt/srlinux/var/run/sr_gnmi_server`.
* `ssh-server`: This sets the target type to `SSH` when registering the target with the gRPC tunnel server. In this case, the `local-address` defaults to `localhost:22`.
* `custom`: Sets a custom string or Go template as the target `type`. In this case setting the `local-address` is mandatory.

E.g: Add a target called tg1, type `grpc-server` with ID `node-name`

#### CLI

```bash
```shell
enter candidate
# add target with type `grpc-server`
/ system grpc-tunnel tunnel t1 target tg1 type grpc-server
Expand All @@ -194,7 +210,7 @@ commit now

#### gNMI

```bash
```shell
gnmic -a clab-grpc-tunnel-srl1 -u admin -p admin --skip-verify set \
--update /system/grpc-tunnel/tunnel[name=t1]/target[name=tg1]/type/grpc-server:::json_ietf:::'[null]' \
--update /system/grpc-tunnel/tunnel[name=t1]/target[name=tg1]/id/node-name:::json_ietf:::'[null]'
Expand All @@ -204,7 +220,7 @@ gnmic -a clab-grpc-tunnel-srl1 -u admin -p admin --skip-verify set \

#### CLI

```bash
```shell
enter candidate
# enable tunnel t1
/ system grpc-tunnel tunnel t1 admin-state enable
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#

A containerlab with 2 SRLs, 2 gNMIcs, a Prometheus server and a Consul server.
A containerlab topology with 2 SRLs, 2 gNMIcs, a Prometheus server and a Consul server.

The `run.sh` script will download the NDK app RPM, deploy the lab, install the app and configure it.

Expand Down
4 changes: 2 additions & 2 deletions example/config_grpc_tunnel_vars.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Destination1: 172.20.20.3
Destination2: 172.20.20.4
Destination1: 172.20.20.4
Destination2: 172.20.20.5
Empty file modified example/run.sh
100644 → 100755
Empty file.
Empty file modified example/stop.sh
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (a *app) startTunnel(ctx context.Context, tn string, tunnelConfig *tunnelCf
return nil
}

//
func (a *app) stopTunnel(ctx context.Context, tn string) {
tuns, ok := a.tunnelClients[tn]
if !ok {
Expand Down Expand Up @@ -145,7 +144,6 @@ func (a *app) tunnelHandlerFunc(tn, dn string) func(t tunnel.Target, i io.ReadWr
}
}

//
func (a *app) stopAll(ctx context.Context) {
for tn := range a.tunnelClients {
a.stopTunnel(ctx, tn)
Expand All @@ -170,7 +168,6 @@ func (a *app) startAll(ctx context.Context) {
}
}

//
func (a *app) startTunnelDestination(ctx context.Context, tn, dn string, tunnelConfig *tunnelCfg, dest *destination, destState *destinationState) {
netIns := dest.Destination.NetworkInstance.Value
if netIns == "" {
Expand Down Expand Up @@ -377,6 +374,13 @@ func (a *app) stopTunnelHandlerDestination(ctx context.Context,
}

func (a *app) newTargetDetails(tg *target) (tunnelTargetDetails, error) {
for {
if a.config.sysInfo.Name == "" {
time.Sleep(time.Second / 2)
continue
}
break
}
var ttd tunnelTargetDetails
// ID
switch {
Expand Down

0 comments on commit 89126a7

Please sign in to comment.