1 // Copyright (c) 2017 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.
15 // service-client is an example VPP management application that exercises the
16 // govpp API using generated service client.
28 "git.fd.io/govpp.git/adapter/socketclient"
29 "git.fd.io/govpp.git/api"
30 interfaces "git.fd.io/govpp.git/binapi/interface"
31 "git.fd.io/govpp.git/binapi/vpe"
35 sockAddr = flag.String("sock", socketclient.DefaultSocketName, "Path to VPP binary API socket file")
41 fmt.Println("Starting RPC service example")
44 conn, err := govpp.Connect(*sockAddr)
46 log.Fatalln("ERROR: connecting to VPP failed:", err)
48 defer conn.Disconnect()
54 // showVersion shows an example of simple request with services.
55 func showVersion(conn api.Connection) {
56 c := vpe.NewServiceClient(conn)
58 version, err := c.ShowVersion(context.Background(), &vpe.ShowVersion{})
60 log.Fatalln("ERROR: ShowVersion failed:", err)
63 fmt.Printf("Version: %v\n", version.Version)
66 // interfaceDump shows an example of multi request with services.
67 func interfaceDump(conn api.Connection) {
68 c := interfaces.NewServiceClient(conn)
70 stream, err := c.SwInterfaceDump(context.Background(), &interfaces.SwInterfaceDump{})
72 log.Fatalln("ERROR: DumpSwInterface failed:", err)
75 fmt.Println("Dumping interfaces")
77 iface, err := stream.Recv()
82 log.Fatalln("ERROR: DumpSwInterface failed:", err)
84 fmt.Printf("- interface: %s\n", strings.Trim(iface.InterfaceName, "\x00"))