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.
26 "git.fd.io/govpp.git/api"
27 "git.fd.io/govpp.git/examples/binapi/interfaces"
28 "git.fd.io/govpp.git/examples/binapi/vpe"
32 fmt.Println("Starting VPP service client...")
35 conn, err := govpp.Connect("")
37 log.Fatalln("failed to connect:", err)
39 defer conn.Disconnect()
41 // create an API channel
42 ch, err := conn.NewAPIChannel()
44 log.Fatalln("failed to create channel:", err)
52 // showVersion shows an example of simple request with services.
53 func showVersion(ch api.Channel) {
54 c := vpe.NewService(ch)
56 version, err := c.ShowVersion(context.Background(), &vpe.ShowVersion{})
58 log.Fatalln("ShowVersion failed:", err)
61 fmt.Printf("Version: %v\n", version.Version)
64 // interfaceDump shows an example of multi request with services.
65 func interfaceDump(ch api.Channel) {
66 c := interfaces.NewService(ch)
68 ifaces, err := c.DumpSwInterface(context.Background(), &interfaces.SwInterfaceDump{})
70 log.Fatalln("DumpSwInterface failed:", err)
73 fmt.Printf("Listing %d interfaces:\n", len(ifaces))
74 for _, d := range ifaces {
75 fmt.Printf("- interface: %s\n", bytes.Trim(d.InterfaceName, "\x00"))