Skip to content

Commit

Permalink
Make this usable in 2022
Browse files Browse the repository at this point in the history
Remove old dependencies
  • Loading branch information
nleiva committed May 11, 2022
2 parents 616fccb + 5814af4 commit 571e1eb
Show file tree
Hide file tree
Showing 41 changed files with 11,487 additions and 12,391 deletions.
123 changes: 56 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ The end goal is to enable use-cases where multiple interactions with devices are
- [JSON (GPBKV): OpenConfig](#json-gpbkv-openconfig)
- [GPB (Protobuf)](#gpb-protobuf)
+ [Config and Validate](#config-and-validate)
+ [Service Layer API](#service-layer-api)
- [Add an IPv6 route](#add-an-ipv6-route)
- [SLA IOS XR config](#sla-ios-xr-config)
+ [Actions](#actions)
- [Ping](#ping)
- [Traceroute](#traceroute)
- [Log Generation](#log-generation)
- [Crypto Key Generation](#crypto-key-generation)
+ [Bypass the config file](#bypass-the-config-file)
* [XR gRPC Config](#xr-grpc-config)
+ [Port range](#port-range)
Expand All @@ -72,28 +64,48 @@ CLI examples to use the library are provided in the [example](example/) folder.

Retrieves the config from one target device described in [config.json](example/input/config.json), for the YANG paths specified in [yangpaths.json](example/input/yangpaths.json). If you want to see it using [OpenConfig models](https://github.com/openconfig/public/tree/master/release/models), you can issue `./getconfig -ypath "../input/yangocpaths.json"` instead.

- example/getconfig
- `example/getconfig`

```console
$ ./getconfig
example/getconfig$ go run main.go

Config from [2001:420:2cff:1204::5502:1]:57344
{
config from sandbox-iosxr-1.cisco.com:57777
{
"data": {
"Cisco-IOS-XR-ifmgr-cfg:interface-configurations": {
"interface-configuration": [
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "BVI511",
"config": {
"name": "BVI511",
"type": "iana-if-type:propVirtual"
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"openconfig-if-ip:ipv4": {
"addresses": {
"address": [
{
"ip": "10.200.188.33",
"config": {
"ip": "10.200.188.33",
"prefix-length": 24
}
}
]
}
}
}
]
}
},
{
"active": "act",
"interface-name": "Loopback60",
"interface-virtual": [
null
],
"Cisco-IOS-XR-ipv6-ma-cfg:ipv6-network": {
"addresses": {
"regular-addresses": {
"regular-address": [

...
2017/07/21 15:11:47 This process took 1.195469855s

2022/05/11 16:55:36 This process took 715.136564ms
```

### Show Commands
Expand Down Expand Up @@ -715,45 +727,10 @@ telemetry model-driven
!
```
### Service Layer API
#### Add an IPv6 route
Add a new route to the IPv6 routing table.
- example/setroute
```console
$ ./setroute -pfx "2001:db8:1413::/48" -nh "2001:db8:cafe::2"
2017/07/25 15:02:01 This process took 329.560647ms
```
Which results in:
```console
RP/0/RP0/CPU0:mrstn-5502-1.cisco.com#show route ipv6 unicast 2001:db8:1413::/48
Tue Jul 25 15:02:20.369 EDT

Routing entry for 2001:db8:1413::/48
Known via "application Service-layer", distance 2, metric 0
Installed Jul 25 15:01:54.011 for 00:00:27
Routing Descriptor Blocks
2001:db8:cafe::2, from ::
Route metric is 0
No advertising protos.
```
#### SLA IOS XR config
```
!! IOS XR Configuration version = 6.2.2
grpc
service-layer
!
```
### Actions
>*NOTE*: Support for actions has been deprecated on XR, most likely in favor of gNOI.
There are multiple actions than can be triggered via gRPC on IOS XR devices running 6.3.1 or later. Below the YANG models supported to the date and some examples using this library.
```console
Expand Down Expand Up @@ -1001,18 +978,30 @@ $ openssl req -new -x509 -nodes -subj '/C=US/CN=localhost' \
The Go generated code in [ems_grpc.pb.go](proto/ems/ems_grpc.pb.go) is the result of the following:
- proto/ems
- `proto/ems`
```console
$ protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
--go_opt=Mproto/ems/ems_grpc.proto=proto/ems \
--go-grpc_opt=Mproto/ems/ems_grpc.proto=proto/ems \
proto/ems/ems_grpc.proto
```
- The Go generated code in [bgp_nbr_bag.pb.go](proto/telemetry/bgp/bgp_nbr_bag.pb.go) is the result of the following:
```console
$ protoc --go_out=plugins=grpc:. ems_grpc.proto
$ protoc --go_out=. \
--go_opt=Mproto/telemetry/bgp/bgp_nbr_bag.proto=proto/telemetry/bgp \
proto/telemetry/bgp/bgp_nbr_bag.proto
```
The Go generated code in [bgp_nbr_bag.pb.go](proto/telemetry/bgp/bgp_nbr_bag.pb.go) is the result of the following:
- The Go generated code in [lldp_neighbor.pb.go](proto/telemetry/lldp/lldp_neighbor.pb.go) is the result of the following:
```console
protoc --go_out=. \
--go_opt=Mproto/telemetry/bgp/bgp_nbr_bag.proto=proto/telemetry/bgp \
proto/telemetry/bgp/bgp_nbr_bag.proto
$ protoc --go_out=. \
--go_opt=Mproto/telemetry/lldp/lldp_neighbor.proto=proto/telemetry/lldp \
proto/telemetry/lldp/lldp_neighbor.proto
```
## Running the Examples
Expand Down
60 changes: 30 additions & 30 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strconv"
"time"
"errors"
"context"

pb "github.com/nleiva/xrgrpc/proto/ems"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
Expand Down Expand Up @@ -258,35 +258,35 @@ func ShowCmdTextOutput(ctx context.Context, conn *grpc.ClientConn, cli string, i
}

// ActionJSON returns the output of an action commands as a JSON structured output.
func ActionJSON(ctx context.Context, conn *grpc.ClientConn, j string, id int64) (string, error) {
var s string
// 'c' is the gRPC stub.
c := pb.NewGRPCExecClient(conn)

// 'a' is the object we send to the router via the stub.
a := pb.ActionJSONArgs{ReqId: id, Yangpathjson: j}

// 'st' is the streamed result that comes back from the target.
st, err := c.ActionJSON(context.Background(), &a)
if err != nil {
return s, fmt.Errorf("gRPC ActionJSON failed: %w", err)
}

for {
// Loop through the responses in the stream until there is nothing left.
r, err := st.Recv()
if err == io.EOF {
return s, nil
}
if len(r.GetErrors()) != 0 {
si := strconv.FormatInt(id, 10)
return s, fmt.Errorf("error triggered by remote host for ReqId: %s; %s", si, r.GetErrors())
}
if len(r.GetYangjson()) > 0 {
s += r.GetYangjson()
}
}
}
// func ActionJSON(ctx context.Context, conn *grpc.ClientConn, j string, id int64) (string, error) {
// var s string
// // 'c' is the gRPC stub.
// c := pb.NewGRPCExecClient(conn)

// // 'a' is the object we send to the router via the stub.
// a := pb.ActionJSONArgs{ReqId: id, Yangpathjson: j}

// // 'st' is the streamed result that comes back from the target.
// st, err := c.ActionJSON(context.Background(), &a)
// if err != nil {
// return s, fmt.Errorf("gRPC ActionJSON failed: %w", err)
// }

// for {
// // Loop through the responses in the stream until there is nothing left.
// r, err := st.Recv()
// if err == io.EOF {
// return s, nil
// }
// if len(r.GetErrors()) != 0 {
// si := strconv.FormatInt(id, 10)
// return s, fmt.Errorf("error triggered by remote host for ReqId: %s; %s", si, r.GetErrors())
// }
// if len(r.GetYangjson()) > 0 {
// s += r.GetYangjson()
// }
// }
// }

// ShowCmdJSONOutput returns the output of a CLI show commands
// as a JSON structured output.
Expand Down
Loading

0 comments on commit 571e1eb

Please sign in to comment.