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 "git.fd.io/govpp.git/examples/binapi/interfaces"
31 "git.fd.io/govpp.git/examples/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()
51 ch, err := conn.NewAPIChannel()
53 log.Fatalln("ERROR: creating channel failed:", err)
61 // showVersion shows an example of simple request with services.
62 func showVersion(ch api.Channel) {
63 c := vpe.NewServiceClient(ch)
65 version, err := c.ShowVersion(context.Background(), &vpe.ShowVersion{})
67 log.Fatalln("ERROR: ShowVersion failed:", err)
70 fmt.Printf("Version: %v\n", version.Version)
73 // interfaceDump shows an example of multi request with services.
74 func interfaceDump(ch api.Channel) {
75 c := interfaces.NewServiceClient(ch)
77 stream, err := c.DumpSwInterface(context.Background(), &interfaces.SwInterfaceDump{})
79 log.Fatalln("ERROR: DumpSwInterface failed:", err)
82 fmt.Println("Dumping interfaces")
84 iface, err := stream.Recv()
89 log.Fatalln("ERROR: DumpSwInterface failed:", err)
91 fmt.Printf("- interface: %s\n", strings.Trim(iface.InterfaceName, "\x00"))