1 // Copyright (c) 2019 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
22 "git.fd.io/govpp.git/adapter/socketclient"
23 "git.fd.io/govpp.git/adapter/statsclient"
24 "git.fd.io/govpp.git/api"
25 interfaces "git.fd.io/govpp.git/binapi/interface"
26 "git.fd.io/govpp.git/binapi/vlib"
27 "git.fd.io/govpp.git/binapi/vpe"
28 _ "git.fd.io/govpp.git/core"
29 "git.fd.io/govpp.git/proxy"
33 binapiSocket = flag.String("binapi-socket", socketclient.DefaultSocketName, "Path to VPP binapi socket")
34 statsSocket = flag.String("stats-socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
35 proxyAddr = flag.String("addr", ":7878", "Address on which proxy serves RPC.")
39 for _, msgList := range api.GetRegisteredMessages() {
40 for _, msg := range msgList {
49 switch cmd := flag.Arg(0); cmd {
55 log.Printf("invalid command: %q, (available commands: client, server)", cmd)
60 // connect to proxy server
61 client, err := proxy.Connect(*proxyAddr)
63 log.Fatalln("connecting to proxy failed:", err)
67 statsProvider, err := client.NewStatsClient()
72 var sysStats api.SystemStats
73 if err := statsProvider.GetSystemStats(&sysStats); err != nil {
74 log.Fatalln("getting stats failed:", err)
76 log.Printf("SystemStats: %+v", sysStats)
78 var ifaceStats api.InterfaceStats
79 if err := statsProvider.GetInterfaceStats(&ifaceStats); err != nil {
80 log.Fatalln("getting stats failed:", err)
82 log.Printf("InterfaceStats: %+v", ifaceStats)
85 binapiChannel, err := client.NewBinapiClient()
89 log.Println("checking compatibility")
90 var msgs []api.Message
91 msgs = append(msgs, interfaces.AllMessages()...)
92 msgs = append(msgs, vpe.AllMessages()...)
93 if err := binapiChannel.CheckCompatiblity(msgs...); err != nil {
97 req := &vlib.CliInband{Cmd: "show version"}
98 reply := new(vlib.CliInbandReply)
99 if err := binapiChannel.SendRequest(req).ReceiveReply(reply); err != nil {
100 log.Fatalln("binapi request failed:", err)
102 log.Printf("VPP version: %+v", reply.Reply)
106 p, err := proxy.NewServer()
111 statsAdapter := statsclient.NewStatsClient(*statsSocket)
112 binapiAdapter := socketclient.NewVppClient(*binapiSocket)
114 if err := p.ConnectStats(statsAdapter); err != nil {
115 log.Fatalln("connecting to stats failed:", err)
117 defer p.DisconnectStats()
119 if err := p.ConnectBinapi(binapiAdapter); err != nil {
120 log.Fatalln("connecting to binapi failed:", err)
122 defer p.DisconnectBinapi()
124 if err := p.ListenAndServe(*proxyAddr); err != nil {