aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simple-client/simple_client.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-07-17 10:36:28 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-07-17 11:43:41 +0200
commitd1f24d37bd447b64e402298bb8eb2479681facf9 (patch)
treea3fc21ba730a91d8a402c7a5bf9c614e3677c4fc /examples/simple-client/simple_client.go
parent1548c7e12531e3d055567d761c580a1c7ff0ac40 (diff)
Improve binapi generator
- simplified Size/Marshal/Unmarshal methods - replace struc in unions with custom marshal/unmarshal - fix imports in generated files - fix mock adapter - generate rpc service using low-level stream API (dumps generate control ping or stream msg..) - move examples/binapi to binapi and generate all API for latest release - add binapigen.Plugin for developing custom generator plugins - optionally generate HTTP handlers (REST API) for RPC services - add govpp program for browsing VPP API Change-Id: I092e9ed2b0c17972b3476463c3d4b14dd76ed42b Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'examples/simple-client/simple_client.go')
-rw-r--r--examples/simple-client/simple_client.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/examples/simple-client/simple_client.go b/examples/simple-client/simple_client.go
index 7aeaa0b..e3ba83d 100644
--- a/examples/simple-client/simple_client.go
+++ b/examples/simple-client/simple_client.go
@@ -18,6 +18,7 @@ package main
import (
"context"
+ "encoding/json"
"flag"
"fmt"
"log"
@@ -26,13 +27,13 @@ import (
"git.fd.io/govpp.git"
"git.fd.io/govpp.git/adapter/socketclient"
"git.fd.io/govpp.git/api"
+ interfaces "git.fd.io/govpp.git/binapi/interface"
+ "git.fd.io/govpp.git/binapi/interface_types"
+ "git.fd.io/govpp.git/binapi/ip"
+ "git.fd.io/govpp.git/binapi/ip_types"
+ "git.fd.io/govpp.git/binapi/mactime"
+ "git.fd.io/govpp.git/binapi/vpe"
"git.fd.io/govpp.git/core"
- "git.fd.io/govpp.git/examples/binapi/interface_types"
- "git.fd.io/govpp.git/examples/binapi/interfaces"
- "git.fd.io/govpp.git/examples/binapi/ip"
- "git.fd.io/govpp.git/examples/binapi/ip_types"
- "git.fd.io/govpp.git/examples/binapi/mactime"
- "git.fd.io/govpp.git/examples/binapi/vpe"
)
var (
@@ -156,6 +157,7 @@ func interfaceDump(ch api.Channel) {
}
n++
fmt.Printf(" - interface #%d: %+v\n", n, msg)
+ marshal(msg)
}
fmt.Println("OK")
@@ -177,6 +179,7 @@ func addIPAddress(ch api.Channel, index interface_types.InterfaceIndex) {
Len: 32,
},
}
+ marshal(req)
reply := &interfaces.SwInterfaceAddDelAddressReply{}
if err := ch.SendRequest(req).ReceiveReply(reply); err != nil {
@@ -208,6 +211,7 @@ func ipAddressDump(ch api.Channel, index interface_types.InterfaceIndex) {
break
}
fmt.Printf(" - ip address: %+v\n", msg)
+ marshal(msg)
}
fmt.Println("OK")
@@ -242,7 +246,9 @@ func interfaceNotifications(ch api.Channel, index interface_types.InterfaceIndex
// receive notifications
go func() {
for notif := range notifChan {
- fmt.Printf("incoming event: %+v\n", notif.(*interfaces.SwInterfaceEvent))
+ e := notif.(*interfaces.SwInterfaceEvent)
+ fmt.Printf("incoming event: %+v\n", e)
+ marshal(e)
}
}()
@@ -326,3 +332,12 @@ Loop:
fmt.Println("OK")
fmt.Println()
}
+
+func marshal(v interface{}) {
+ fmt.Printf("GO: %#v\n", v)
+ b, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ panic(err)
+ }
+ fmt.Printf("JSON: %s\n", b)
+}