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/vpe"
27 _ "git.fd.io/govpp.git/core"
28 "git.fd.io/govpp.git/proxy"
32 binapiSocket = flag.String("binapi-socket", socketclient.DefaultSocketName, "Path to VPP binapi socket")
33 statsSocket = flag.String("stats-socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
34 proxyAddr = flag.String("addr", ":7878", "Address on which proxy serves RPC.")
38 for _, msg := range api.GetRegisteredMessages() {
46 switch cmd := flag.Arg(0); cmd {
52 log.Printf("invalid command: %q, (available commands: client, server)", cmd)
57 // connect to proxy server
58 client, err := proxy.Connect(*proxyAddr)
60 log.Fatalln("connecting to proxy failed:", err)
64 statsProvider, err := client.NewStatsClient()
69 var sysStats api.SystemStats
70 if err := statsProvider.GetSystemStats(&sysStats); err != nil {
71 log.Fatalln("getting stats failed:", err)
73 log.Printf("SystemStats: %+v", sysStats)
75 var ifaceStats api.InterfaceStats
76 if err := statsProvider.GetInterfaceStats(&ifaceStats); err != nil {
77 log.Fatalln("getting stats failed:", err)
79 log.Printf("InterfaceStats: %+v", ifaceStats)
82 binapiChannel, err := client.NewBinapiClient()
86 log.Println("checking compatibility")
87 var msgs []api.Message
88 msgs = append(msgs, interfaces.AllMessages()...)
89 msgs = append(msgs, vpe.AllMessages()...)
90 if err := binapiChannel.CheckCompatiblity(msgs...); err != nil {
94 req := &vpe.CliInband{Cmd: "show version"}
95 reply := new(vpe.CliInbandReply)
96 if err := binapiChannel.SendRequest(req).ReceiveReply(reply); err != nil {
97 log.Fatalln("binapi request failed:", err)
99 log.Printf("VPP version: %+v", reply.Reply)
103 p, err := proxy.NewServer()
108 statsAdapter := statsclient.NewStatsClient(*statsSocket)
109 binapiAdapter := socketclient.NewVppClient(*binapiSocket)
111 if err := p.ConnectStats(statsAdapter); err != nil {
112 log.Fatalln("connecting to stats failed:", err)
114 defer p.DisconnectStats()
116 if err := p.ConnectBinapi(binapiAdapter); err != nil {
117 log.Fatalln("connecting to binapi failed:", err)
119 defer p.DisconnectBinapi()
121 if err := p.ListenAndServe(*proxyAddr); err != nil {