aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-10-23 11:40:18 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-10-30 10:00:00 +0000
commit0f46871b4cc45f2c3bd5bdb0aa0f7615795a2c6d (patch)
tree3d3de8febc3e2becfbbbd648538fc5dd1748374f /examples
parentcb540dc166c12180adba024d5b8fd463d2582928 (diff)
Fix encoding for float64 and generate conversion for Timestamp
- fixes encoding/decoding of float64 - uses little endian (contrary to all other types) - generates helper methods for vpe_types.Timestamp type - adds usage code to simple-client and binapi-types examples Change-Id: I2e83eee0629eb67964049406c50c7ee0a692ccaf Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/binapi-types/binapi_types.go43
-rw-r--r--examples/simple-client/simple_client.go17
2 files changed, 43 insertions, 17 deletions
diff --git a/examples/binapi-types/binapi_types.go b/examples/binapi-types/binapi_types.go
index 849ad1b..2dbaa3e 100644
--- a/examples/binapi-types/binapi_types.go
+++ b/examples/binapi-types/binapi_types.go
@@ -18,36 +18,42 @@ package main
import (
"fmt"
"log"
+ "time"
"git.fd.io/govpp.git/binapi/ethernet_types"
"git.fd.io/govpp.git/binapi/ip"
"git.fd.io/govpp.git/binapi/ip_types"
+ "git.fd.io/govpp.git/binapi/vpe_types"
"git.fd.io/govpp.git/codec"
)
func init() {
- log.SetFlags(0)
}
func main() {
- addressUnionExample()
- ipAddressExample()
+ log.SetFlags(0)
+
+ usageUnion()
+ usageAddress()
- // convert IP from string form into Address type containing union
- convertIP("10.10.1.1")
- convertIP("ff80::1")
+ // convert IP address in string form into ip_types.Address
+ convertIPAddress("10.10.1.1")
+ convertIPAddress("ff80::1")
- // convert IP from string form into Prefix type
+ // convert IP address / CIDR in string form into ip_types.Prefix
convertIPPrefix("20.10.1.1/24")
convertIPPrefix("21.10.1.1")
convertIPPrefix("ff90::1/64")
convertIPPrefix("ff91::1")
- // convert MAC address from string into MacAddress
+ // convert MAC address in string form into ethernet_types.MacAddress
convertToMacAddress("00:10:ab:4f:00:01")
+
+ // convert time.Time into vpe_types.Timestamp
+ convertToTimestamp(time.Now())
}
-func addressUnionExample() {
+func usageUnion() {
var union ip_types.AddressUnion
// initialize union using constructors
@@ -63,21 +69,17 @@ func addressUnionExample() {
union.SetIP6(ip6)
}
-func ipAddressExample() {
+func usageAddress() {
// parse string into IP address
- addrIP4, err := ip_types.ParseAddress("192.168.1.10")
+ addr, err := ip_types.ParseAddress("192.168.1.10")
if err != nil {
panic(err)
}
- /*addrIP6, err := ip_types.ParseAddress("ff:2::2")
- if err != nil {
- panic(err)
- }*/
var msg = ip.IPPuntRedirect{
IsAdd: true,
Punt: ip.PuntRedirect{
- Nh: addrIP4,
+ Nh: addr,
},
}
@@ -103,7 +105,7 @@ func ipAddressExample() {
}
}
-func convertIP(ip string) {
+func convertIPAddress(ip string) {
addr, err := ip_types.ParseAddress(ip)
if err != nil {
log.Printf("error converting IP to Address: %v", err)
@@ -135,3 +137,10 @@ func convertToMacAddress(mac string) {
fmt.Printf("MacAddress converted back to string %#v to: %s\n", parsedMac, parsedMac)
}
+
+func convertToTimestamp(t time.Time) {
+ timestamp := vpe_types.NewTimestamp(t)
+ fmt.Printf("converted time %v to: %#v\n", t, timestamp)
+
+ fmt.Printf("Timestamp converted back to string %#v to: %s\n", timestamp, timestamp)
+}
diff --git a/examples/simple-client/simple_client.go b/examples/simple-client/simple_client.go
index 0898c0a..10a0ea6 100644
--- a/examples/simple-client/simple_client.go
+++ b/examples/simple-client/simple_client.go
@@ -84,6 +84,7 @@ func main() {
// use request/reply (channel API)
getVppVersion(ch)
+ getSystemTime(ch)
idx := createLoopback(ch)
interfaceDump(ch)
addIPAddress(ch, idx)
@@ -107,6 +108,22 @@ func getVppVersion(ch api.Channel) {
fmt.Println()
}
+func getSystemTime(ch api.Channel) {
+ fmt.Println("Retrieving system time..")
+
+ req := &vpe.ShowVpeSystemTime{}
+ reply := &vpe.ShowVpeSystemTimeReply{}
+
+ if err := ch.SendRequest(req).ReceiveReply(reply); err != nil {
+ logError(err, "retrieving system time")
+ return
+ }
+
+ fmt.Printf("system time: %v\n", reply.VpeSystemTime)
+ fmt.Println("OK")
+ fmt.Println()
+}
+
func createLoopback(ch api.Channel) interface_types.InterfaceIndex {
fmt.Println("Creating loopback interface..")