12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- package vpp1908
15
+ package vpp2101
16
16
17
17
import (
18
- "bytes"
19
18
"context"
20
19
"fmt"
21
20
"strings"
22
21
22
+ "git.fd.io/govpp.git/api"
23
23
"github.com/pkg/errors"
24
24
25
25
"go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls"
26
- "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp1908 /memclnt"
27
- "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp1908 /vpe"
26
+ "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101 /memclnt"
27
+ "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101 /vpe"
28
28
)
29
29
30
30
// Ping sends VPP control ping.
@@ -77,7 +77,7 @@ func (h *VpeHandler) GetModules(ctx context.Context) ([]vppcalls.APIModule, erro
77
77
var modules []vppcalls.APIModule
78
78
for _ , v := range versions .APIVersions {
79
79
modules = append (modules , vppcalls.APIModule {
80
- Name : strings .TrimSuffix (cleanString (v .Name ), ".api" ),
80
+ Name : strings .TrimSuffix (strings . TrimRight (v .Name , " \x00 " ), ".api" ),
81
81
Major : v .Major ,
82
82
Minor : v .Minor ,
83
83
Patch : v .Patch ,
@@ -87,6 +87,11 @@ func (h *VpeHandler) GetModules(ctx context.Context) ([]vppcalls.APIModule, erro
87
87
}
88
88
89
89
func (h * VpeHandler ) GetPlugins (ctx context.Context ) ([]vppcalls.PluginInfo , error ) {
90
+ const (
91
+ pluginPathPrefix = "Plugin path is:"
92
+ pluginNameSuffix = "_plugin.so"
93
+ )
94
+
90
95
out , err := h .RunCli (ctx , "show plugins" )
91
96
if err != nil {
92
97
return nil , err
@@ -96,9 +101,7 @@ func (h *VpeHandler) GetPlugins(ctx context.Context) ([]vppcalls.PluginInfo, err
96
101
if len (lines ) == 0 {
97
102
return nil , fmt .Errorf ("empty output for 'show plugins'" )
98
103
}
99
-
100
104
pluginPathLine := strings .TrimSpace (lines [0 ])
101
- const pluginPathPrefix = "Plugin path is:"
102
105
if ! strings .HasPrefix (pluginPathLine , pluginPathPrefix ) {
103
106
return nil , fmt .Errorf ("unexpected output for 'show plugins'" )
104
107
}
@@ -121,7 +124,7 @@ func (h *VpeHandler) GetPlugins(ctx context.Context) ([]vppcalls.PluginInfo, err
121
124
continue
122
125
}
123
126
plugin := vppcalls.PluginInfo {
124
- Name : strings .TrimSuffix (fields [1 ], "_plugin.so" ),
127
+ Name : strings .TrimSuffix (fields [1 ], pluginNameSuffix ),
125
128
Path : fields [1 ],
126
129
Version : fields [2 ],
127
130
Description : strings .Join (fields [3 :], " " ),
@@ -140,9 +143,9 @@ func (h *VpeHandler) GetThreads(ctx context.Context) ([]vppcalls.ThreadInfo, err
140
143
threads := make ([]vppcalls.ThreadInfo , len (resp .ThreadData ))
141
144
for i , thread := range resp .ThreadData {
142
145
threads [i ] = vppcalls.ThreadInfo {
143
- Name : string ( thread .Name ) ,
146
+ Name : thread .Name ,
144
147
ID : thread .ID ,
145
- Type : string ( thread .Type ) ,
148
+ Type : thread .Type ,
146
149
PID : thread .PID ,
147
150
Core : thread .Core ,
148
151
CPUID : thread .CPUID ,
@@ -154,15 +157,13 @@ func (h *VpeHandler) GetThreads(ctx context.Context) ([]vppcalls.ThreadInfo, err
154
157
155
158
// RunCli sends CLI command to VPP and returns response.
156
159
func (h * VpeHandler ) RunCli (ctx context.Context , cmd string ) (string , error ) {
157
- resp , err := h .vpe .CliInband (ctx , & vpe.CliInband {
160
+ reply , err := h .vpe .CliInband (ctx , & vpe.CliInband {
158
161
Cmd : cmd ,
159
162
})
160
163
if err != nil {
161
164
return "" , errors .Wrapf (err , "VPP CLI command '%s' failed" , cmd )
165
+ } else if err = api .RetvalToVPPApiError (reply .Retval ); err != nil {
166
+ return "" , err
162
167
}
163
- return resp .Reply , nil
164
- }
165
-
166
- func cleanString (b []byte ) string {
167
- return string (bytes .SplitN (b , []byte {0x00 }, 2 )[0 ])
168
+ return reply .Reply , nil
168
169
}
0 commit comments