import (
"context"
+ "encoding/json"
"flag"
"fmt"
"log"
"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 (
fmt.Println("Dumping interfaces")
n := 0
- reqCtx := ch.SendMultiRequest(&interfaces.SwInterfaceDump{})
+ reqCtx := ch.SendMultiRequest(&interfaces.SwInterfaceDump{
+ SwIfIndex: ^interface_types.InterfaceIndex(0),
+ })
for {
msg := &interfaces.SwInterfaceDetails{}
stop, err := reqCtx.ReceiveReply(msg)
}
n++
fmt.Printf(" - interface #%d: %+v\n", n, msg)
+ marshal(msg)
}
fmt.Println("OK")
Len: 32,
},
}
+ marshal(req)
reply := &interfaces.SwInterfaceAddDelAddressReply{}
if err := ch.SendRequest(req).ReceiveReply(reply); err != nil {
break
}
fmt.Printf(" - ip address: %+v\n", msg)
+ marshal(msg)
}
fmt.Println("OK")
// 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)
}
}()
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)
+}