blob: 9b400cfcb771f2c9fd0641029c262512d2194c53 [file] [log] [blame]
Maros Ondrejicka11a03e92022-12-01 09:56:37 +01001package main
2
3import (
Filip Tehlarf3ee2b62023-01-09 12:07:09 +01004 "fmt"
Adrian Villin637edda2024-05-06 06:55:34 -04005 "io"
Filip Tehlarec5c40b2023-02-28 18:59:15 +01006 "os"
Maros Ondrejickaa2d52622023-02-24 11:26:39 +01007 "os/exec"
Filip Tehlarec5c40b2023-02-28 18:59:15 +01008 "os/signal"
Filip Tehlar543cd572023-06-27 10:01:37 +02009 "strconv"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010010 "strings"
Filip Tehlarec5c40b2023-02-28 18:59:15 +010011 "syscall"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010012 "time"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010013
Adrian Villin637edda2024-05-06 06:55:34 -040014 "github.com/sirupsen/logrus"
Filip Tehlar9abba112023-03-07 10:13:19 +010015 "github.com/edwarnicke/exechelper"
Adrian Villincee15aa2024-03-14 11:42:55 -040016 . "github.com/onsi/ginkgo/v2"
Filip Tehlar9abba112023-03-07 10:13:19 +010017
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010018 "go.fd.io/govpp"
19 "go.fd.io/govpp/api"
20 "go.fd.io/govpp/binapi/af_packet"
21 interfaces "go.fd.io/govpp/binapi/interface"
22 "go.fd.io/govpp/binapi/interface_types"
23 "go.fd.io/govpp/binapi/session"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010024 "go.fd.io/govpp/binapi/tapv2"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010025 "go.fd.io/govpp/binapi/vpe"
26 "go.fd.io/govpp/core"
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010027)
28
29const vppConfigTemplate = `unix {
30 nodaemon
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010031 log %[1]s%[4]s
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010032 full-coredump
33 cli-listen %[1]s%[2]s
34 runtime-dir %[1]s/var/run
35 gid vpp
36}
37
38api-trace {
39 on
40}
41
42api-segment {
43 gid vpp
44}
45
46socksvr {
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +010047 socket-name %[1]s%[3]s
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010048}
49
50statseg {
51 socket-name %[1]s/var/run/vpp/stats.sock
52}
53
54plugins {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010055 plugin default { disable }
56
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010057 plugin unittest_plugin.so { enable }
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010058 plugin quic_plugin.so { enable }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010059 plugin af_packet_plugin.so { enable }
60 plugin hs_apps_plugin.so { enable }
61 plugin http_plugin.so { enable }
Filip Tehlarcc1475c2023-11-29 12:59:05 +010062 plugin http_static_plugin.so { enable }
63 plugin prom_plugin.so { enable }
Filip Tehlar3336eef2023-11-29 07:40:18 +010064 plugin tlsopenssl_plugin.so { enable }
Adrian Villincee15aa2024-03-14 11:42:55 -040065 plugin ping_plugin.so { enable }
Matus Fabianc899ab42024-04-22 13:42:00 +020066 plugin nsim_plugin.so { enable }
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010067}
68
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010069logging {
70 default-log-level debug
71 default-syslog-log-level debug
72}
73
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010074`
75
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010076const (
77 defaultCliSocketFilePath = "/var/run/vpp/cli.sock"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010078 defaultApiSocketFilePath = "/var/run/vpp/api.sock"
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010079 defaultLogFilePath = "/var/log/vpp/vpp.log"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010080)
81
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010082type VppInstance struct {
Maros Ondrejicka300f70d2023-02-21 10:53:20 +010083 container *Container
Filip Tehlar608d0062023-04-28 10:29:47 +020084 additionalConfig []Stanza
Maros Ondrejicka300f70d2023-02-21 10:53:20 +010085 connection *core.Connection
86 apiChannel api.Channel
Filip Tehlar608d0062023-04-28 10:29:47 +020087 cpus []int
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010088}
89
Maros Ondrejickae7625d02023-02-28 16:55:01 +010090func (vpp *VppInstance) getSuite() *HstSuite {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010091 return vpp.container.suite
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010092}
93
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010094func (vpp *VppInstance) getCliSocket() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +010095 return fmt.Sprintf("%s%s", vpp.container.getContainerWorkDir(), defaultCliSocketFilePath)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010096}
97
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010098func (vpp *VppInstance) getRunDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +010099 return vpp.container.getContainerWorkDir() + "/var/run/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100100}
101
102func (vpp *VppInstance) getLogDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100103 return vpp.container.getContainerWorkDir() + "/var/log/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100104}
105
106func (vpp *VppInstance) getEtcDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100107 return vpp.container.getContainerWorkDir() + "/etc/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100108}
109
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100110func (vpp *VppInstance) start() error {
Adrian Villin637edda2024-05-06 06:55:34 -0400111 // Replace default logger in govpp with our own
112 govppLogger := logrus.New()
113 govppLogger.SetOutput(io.MultiWriter(vpp.getSuite().logger.Writer(), GinkgoWriter))
114 core.SetLogger(govppLogger)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100115 // Create folders
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100116 containerWorkDir := vpp.container.getContainerWorkDir()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100117
118 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getRunDir())
119 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getLogDir())
120 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getEtcDir())
121
122 // Create startup.conf inside the container
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100123 configContent := fmt.Sprintf(
Maros Ondrejicka300f70d2023-02-21 10:53:20 +0100124 vppConfigTemplate,
125 containerWorkDir,
126 defaultCliSocketFilePath,
127 defaultApiSocketFilePath,
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100128 defaultLogFilePath,
Maros Ondrejicka300f70d2023-02-21 10:53:20 +0100129 )
Filip Tehlar608d0062023-04-28 10:29:47 +0200130 configContent += vpp.generateCpuConfig()
131 for _, c := range vpp.additionalConfig {
132 configContent += c.toString()
133 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100134 startupFileName := vpp.getEtcDir() + "/startup.conf"
135 vpp.container.createFile(startupFileName, configContent)
136
Filip Tehlar1a661502023-03-08 11:55:50 +0100137 // create wrapper script for vppctl with proper CLI socket path
138 cliContent := "#!/usr/bin/bash\nvppctl -s " + vpp.getRunDir() + "/cli.sock"
139 vppcliFileName := "/usr/bin/vppcli"
140 vpp.container.createFile(vppcliFileName, cliContent)
141 vpp.container.exec("chmod 0755 " + vppcliFileName)
142
Adrian Villincee15aa2024-03-14 11:42:55 -0400143 vpp.getSuite().log("starting vpp")
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100144 if *isVppDebug {
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100145 sig := make(chan os.Signal, 1)
Adrian Villincee15aa2024-03-14 11:42:55 -0400146 signal.Notify(sig, syscall.SIGQUIT)
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100147 cont := make(chan bool, 1)
148 go func() {
Filip Tehlar9abba112023-03-07 10:13:19 +0100149 <-sig
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100150 cont <- true
151 }()
152
Filip Tehlara6b1a7d2023-09-02 08:39:25 +0200153 vpp.container.execServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"")
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100154 fmt.Println("run following command in different terminal:")
Filip Tehlara6b1a7d2023-09-02 08:39:25 +0200155 fmt.Println("docker exec -it " + vpp.container.name + " gdb -ex \"attach $(docker exec " + vpp.container.name + " pidof vpp)\"")
Adrian Villincee15aa2024-03-14 11:42:55 -0400156 fmt.Println("Afterwards press CTRL+\\ to continue")
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100157 <-cont
158 fmt.Println("continuing...")
159 } else {
160 // Start VPP
161 vpp.container.execServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"")
162 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100163
Adrian Villincee15aa2024-03-14 11:42:55 -0400164 vpp.getSuite().log("connecting to vpp")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100165 // Connect to VPP and store the connection
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100166 sockAddress := vpp.container.getHostWorkDir() + defaultApiSocketFilePath
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100167 conn, connEv, err := govpp.AsyncConnect(
168 sockAddress,
169 core.DefaultMaxReconnectAttempts,
170 core.DefaultReconnectInterval)
171 if err != nil {
172 fmt.Println("async connect error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100173 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100174 }
175 vpp.connection = conn
176
177 // ... wait for Connected event
178 e := <-connEv
179 if e.State != core.Connected {
180 fmt.Println("connecting to VPP failed: ", e.Error)
181 }
182
183 // ... check compatibility of used messages
184 ch, err := conn.NewAPIChannel()
185 if err != nil {
186 fmt.Println("creating channel failed: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100187 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100188 }
189 if err := ch.CheckCompatiblity(vpe.AllMessages()...); err != nil {
190 fmt.Println("compatibility error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100191 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100192 }
193 if err := ch.CheckCompatiblity(interfaces.AllMessages()...); err != nil {
194 fmt.Println("compatibility error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100195 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100196 }
197 vpp.apiChannel = ch
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100198
199 return nil
200}
201
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100202func (vpp *VppInstance) vppctl(command string, arguments ...any) string {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100203 vppCliCommand := fmt.Sprintf(command, arguments...)
204 containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s",
205 vpp.container.name, vpp.getCliSocket(), vppCliCommand)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100206 vpp.getSuite().log(containerExecCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100207 output, err := exechelper.CombinedOutput(containerExecCommand)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100208 vpp.getSuite().assertNil(err)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100209
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100210 return string(output)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100211}
212
Filip Tehlar543cd572023-06-27 10:01:37 +0200213func (vpp *VppInstance) GetSessionStat(stat string) int {
214 o := vpp.vppctl("show session stats")
215 vpp.getSuite().log(o)
216 for _, line := range strings.Split(o, "\n") {
217 if strings.Contains(line, stat) {
218 tokens := strings.Split(strings.TrimSpace(line), " ")
219 val, err := strconv.Atoi(tokens[0])
220 if err != nil {
Adrian Villincee15aa2024-03-14 11:42:55 -0400221 Fail("failed to parse stat value %s" + fmt.Sprint(err))
Filip Tehlar543cd572023-06-27 10:01:37 +0200222 return 0
223 }
224 return val
225 }
226 }
227 return 0
228}
229
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100230func (vpp *VppInstance) waitForApp(appName string, timeout int) {
Adrian Villincee15aa2024-03-14 11:42:55 -0400231 vpp.getSuite().log("waiting for app " + appName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100232 for i := 0; i < timeout; i++ {
233 o := vpp.vppctl("show app")
234 if strings.Contains(o, appName) {
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100235 return
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100236 }
237 time.Sleep(1 * time.Second)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100238 }
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100239 vpp.getSuite().assertNil(1, "Timeout while waiting for app '%s'", appName)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100240}
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100241
242func (vpp *VppInstance) createAfPacket(
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100243 veth *NetInterface,
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100244) (interface_types.InterfaceIndex, error) {
245 createReq := &af_packet.AfPacketCreateV2{
246 UseRandomHwAddr: true,
247 HostIfName: veth.Name(),
248 }
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100249 if veth.hwAddress != (MacAddress{}) {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100250 createReq.UseRandomHwAddr = false
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100251 createReq.HwAddr = veth.hwAddress
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100252 }
253 createReply := &af_packet.AfPacketCreateV2Reply{}
254
Adrian Villincee15aa2024-03-14 11:42:55 -0400255 vpp.getSuite().log("create af-packet interface " + veth.Name())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100256 if err := vpp.apiChannel.SendRequest(createReq).ReceiveReply(createReply); err != nil {
257 return 0, err
258 }
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100259 veth.index = createReply.SwIfIndex
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100260
261 // Set to up
262 upReq := &interfaces.SwInterfaceSetFlags{
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100263 SwIfIndex: veth.index,
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100264 Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
265 }
266 upReply := &interfaces.SwInterfaceSetFlagsReply{}
267
Adrian Villincee15aa2024-03-14 11:42:55 -0400268 vpp.getSuite().log("set af-packet interface " + veth.Name() + " up")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100269 if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil {
270 return 0, err
271 }
272
273 // Add address
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100274 if veth.addressWithPrefix() == (AddressWithPrefix{}) {
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100275 var err error
276 var ip4Address string
Filip Tehlar3a910ab2023-06-08 17:39:39 +0200277 if ip4Address, err = veth.ip4AddrAllocator.NewIp4InterfaceAddress(veth.peer.networkNumber); err == nil {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100278 veth.ip4Address = ip4Address
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100279 } else {
280 return 0, err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100281 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100282 }
283 addressReq := &interfaces.SwInterfaceAddDelAddress{
284 IsAdd: true,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100285 SwIfIndex: veth.index,
286 Prefix: veth.addressWithPrefix(),
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100287 }
288 addressReply := &interfaces.SwInterfaceAddDelAddressReply{}
289
Adrian Villincee15aa2024-03-14 11:42:55 -0400290 vpp.getSuite().log("af-packet interface " + veth.Name() + " add address " + veth.ip4Address)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100291 if err := vpp.apiChannel.SendRequest(addressReq).ReceiveReply(addressReply); err != nil {
292 return 0, err
293 }
294
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100295 return veth.index, nil
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100296}
297
298func (vpp *VppInstance) addAppNamespace(
299 secret uint64,
300 ifx interface_types.InterfaceIndex,
301 namespaceId string,
302) error {
303 req := &session.AppNamespaceAddDelV2{
304 Secret: secret,
305 SwIfIndex: ifx,
306 NamespaceID: namespaceId,
307 }
308 reply := &session.AppNamespaceAddDelV2Reply{}
309
Adrian Villincee15aa2024-03-14 11:42:55 -0400310 vpp.getSuite().log("add app namespace " + namespaceId)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100311 if err := vpp.apiChannel.SendRequest(req).ReceiveReply(reply); err != nil {
312 return err
313 }
314
315 sessionReq := &session.SessionEnableDisable{
316 IsEnable: true,
317 }
318 sessionReply := &session.SessionEnableDisableReply{}
319
Adrian Villincee15aa2024-03-14 11:42:55 -0400320 vpp.getSuite().log("enable app namespace " + namespaceId)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100321 if err := vpp.apiChannel.SendRequest(sessionReq).ReceiveReply(sessionReply); err != nil {
322 return err
323 }
324
325 return nil
326}
327
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100328func (vpp *VppInstance) createTap(
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100329 tap *NetInterface,
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100330 tapId ...uint32,
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100331) error {
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100332 var id uint32 = 1
333 if len(tapId) > 0 {
334 id = tapId[0]
335 }
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100336 createTapReq := &tapv2.TapCreateV2{
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100337 ID: id,
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100338 HostIfNameSet: true,
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100339 HostIfName: tap.Name(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100340 HostIP4PrefixSet: true,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100341 HostIP4Prefix: tap.ip4AddressWithPrefix(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100342 }
343 createTapReply := &tapv2.TapCreateV2Reply{}
344
Adrian Villincee15aa2024-03-14 11:42:55 -0400345 vpp.getSuite().log("create tap interface " + tap.Name())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100346 // Create tap interface
347 if err := vpp.apiChannel.SendRequest(createTapReq).ReceiveReply(createTapReply); err != nil {
348 return err
349 }
350
351 // Add address
352 addAddressReq := &interfaces.SwInterfaceAddDelAddress{
353 IsAdd: true,
354 SwIfIndex: createTapReply.SwIfIndex,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100355 Prefix: tap.peer.addressWithPrefix(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100356 }
357 addAddressReply := &interfaces.SwInterfaceAddDelAddressReply{}
358
Adrian Villincee15aa2024-03-14 11:42:55 -0400359 vpp.getSuite().log("tap interface " + tap.Name() + " add address " + tap.peer.ip4Address)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100360 if err := vpp.apiChannel.SendRequest(addAddressReq).ReceiveReply(addAddressReply); err != nil {
361 return err
362 }
363
364 // Set interface to up
365 upReq := &interfaces.SwInterfaceSetFlags{
366 SwIfIndex: createTapReply.SwIfIndex,
367 Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
368 }
369 upReply := &interfaces.SwInterfaceSetFlagsReply{}
370
Adrian Villincee15aa2024-03-14 11:42:55 -0400371 vpp.getSuite().log("set tap interface " + tap.Name() + " up")
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100372 if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil {
373 return err
374 }
375
376 return nil
377}
378
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100379func (vpp *VppInstance) saveLogs() {
380 logTarget := vpp.container.getLogDirPath() + "vppinstance-" + vpp.container.name + ".log"
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100381 logSource := vpp.container.getHostWorkDir() + defaultLogFilePath
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100382 cmd := exec.Command("cp", logSource, logTarget)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100383 vpp.getSuite().log(cmd.String())
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100384 cmd.Run()
385}
386
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100387func (vpp *VppInstance) disconnect() {
388 vpp.connection.Disconnect()
389 vpp.apiChannel.Close()
390}
Filip Tehlar608d0062023-04-28 10:29:47 +0200391
392func (vpp *VppInstance) generateCpuConfig() string {
393 var c Stanza
394 var s string
395 if len(vpp.cpus) < 1 {
396 return ""
397 }
398 c.newStanza("cpu").
399 append(fmt.Sprintf("main-core %d", vpp.cpus[0]))
400 workers := vpp.cpus[1:]
401
402 if len(workers) > 0 {
403 for i := 0; i < len(workers); i++ {
404 if i != 0 {
405 s = s + ", "
406 }
407 s = s + fmt.Sprintf("%d", workers[i])
408 }
409 c.append(fmt.Sprintf("corelist-workers %s", s))
410 }
411 return c.close().toString()
412}