blob: 7ddec7e0ed43a6d613db6efa988ca44d0c5bc08c [file] [log] [blame]
Maros Ondrejicka11a03e92022-12-01 09:56:37 +01001package main
2
3import (
Filip Tehlarf3ee2b62023-01-09 12:07:09 +01004 "fmt"
Filip Tehlarec5c40b2023-02-28 18:59:15 +01005 "os"
Maros Ondrejickaa2d52622023-02-24 11:26:39 +01006 "os/exec"
Filip Tehlarec5c40b2023-02-28 18:59:15 +01007 "os/signal"
Filip Tehlar543cd572023-06-27 10:01:37 +02008 "strconv"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +01009 "strings"
Filip Tehlarec5c40b2023-02-28 18:59:15 +010010 "syscall"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010011 "time"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010012
Filip Tehlar9abba112023-03-07 10:13:19 +010013 "github.com/edwarnicke/exechelper"
Adrian Villincee15aa2024-03-14 11:42:55 -040014 . "github.com/onsi/ginkgo/v2"
Filip Tehlar9abba112023-03-07 10:13:19 +010015
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010016 "go.fd.io/govpp"
17 "go.fd.io/govpp/api"
18 "go.fd.io/govpp/binapi/af_packet"
19 interfaces "go.fd.io/govpp/binapi/interface"
20 "go.fd.io/govpp/binapi/interface_types"
21 "go.fd.io/govpp/binapi/session"
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010022 "go.fd.io/govpp/binapi/tapv2"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010023 "go.fd.io/govpp/binapi/vpe"
24 "go.fd.io/govpp/core"
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010025)
26
27const vppConfigTemplate = `unix {
28 nodaemon
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010029 log %[1]s%[4]s
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010030 full-coredump
31 cli-listen %[1]s%[2]s
32 runtime-dir %[1]s/var/run
33 gid vpp
34}
35
36api-trace {
37 on
38}
39
40api-segment {
41 gid vpp
42}
43
44socksvr {
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +010045 socket-name %[1]s%[3]s
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010046}
47
48statseg {
49 socket-name %[1]s/var/run/vpp/stats.sock
50}
51
52plugins {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010053 plugin default { disable }
54
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010055 plugin unittest_plugin.so { enable }
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010056 plugin quic_plugin.so { enable }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010057 plugin af_packet_plugin.so { enable }
58 plugin hs_apps_plugin.so { enable }
59 plugin http_plugin.so { enable }
Filip Tehlarcc1475c2023-11-29 12:59:05 +010060 plugin http_static_plugin.so { enable }
61 plugin prom_plugin.so { enable }
Filip Tehlar3336eef2023-11-29 07:40:18 +010062 plugin tlsopenssl_plugin.so { enable }
Adrian Villincee15aa2024-03-14 11:42:55 -040063 plugin ping_plugin.so { enable }
Matus Fabianc899ab42024-04-22 13:42:00 +020064 plugin nsim_plugin.so { enable }
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010065}
66
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010067logging {
68 default-log-level debug
69 default-syslog-log-level debug
70}
71
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010072`
73
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010074const (
75 defaultCliSocketFilePath = "/var/run/vpp/cli.sock"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010076 defaultApiSocketFilePath = "/var/run/vpp/api.sock"
Maros Ondrejickaa2d52622023-02-24 11:26:39 +010077 defaultLogFilePath = "/var/log/vpp/vpp.log"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010078)
79
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010080type VppInstance struct {
Maros Ondrejicka300f70d2023-02-21 10:53:20 +010081 container *Container
Filip Tehlar608d0062023-04-28 10:29:47 +020082 additionalConfig []Stanza
Maros Ondrejicka300f70d2023-02-21 10:53:20 +010083 connection *core.Connection
84 apiChannel api.Channel
Filip Tehlar608d0062023-04-28 10:29:47 +020085 cpus []int
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010086}
87
Maros Ondrejickae7625d02023-02-28 16:55:01 +010088func (vpp *VppInstance) getSuite() *HstSuite {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010089 return vpp.container.suite
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010090}
91
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010092func (vpp *VppInstance) getCliSocket() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +010093 return fmt.Sprintf("%s%s", vpp.container.getContainerWorkDir(), defaultCliSocketFilePath)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010094}
95
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010096func (vpp *VppInstance) getRunDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +010097 return vpp.container.getContainerWorkDir() + "/var/run/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010098}
99
100func (vpp *VppInstance) getLogDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100101 return vpp.container.getContainerWorkDir() + "/var/log/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100102}
103
104func (vpp *VppInstance) getEtcDir() string {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100105 return vpp.container.getContainerWorkDir() + "/etc/vpp"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100106}
107
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100108func (vpp *VppInstance) start() error {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100109 // Create folders
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100110 containerWorkDir := vpp.container.getContainerWorkDir()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100111
112 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getRunDir())
113 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getLogDir())
114 vpp.container.exec("mkdir --mode=0700 -p " + vpp.getEtcDir())
115
116 // Create startup.conf inside the container
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100117 configContent := fmt.Sprintf(
Maros Ondrejicka300f70d2023-02-21 10:53:20 +0100118 vppConfigTemplate,
119 containerWorkDir,
120 defaultCliSocketFilePath,
121 defaultApiSocketFilePath,
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100122 defaultLogFilePath,
Maros Ondrejicka300f70d2023-02-21 10:53:20 +0100123 )
Filip Tehlar608d0062023-04-28 10:29:47 +0200124 configContent += vpp.generateCpuConfig()
125 for _, c := range vpp.additionalConfig {
126 configContent += c.toString()
127 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100128 startupFileName := vpp.getEtcDir() + "/startup.conf"
129 vpp.container.createFile(startupFileName, configContent)
130
Filip Tehlar1a661502023-03-08 11:55:50 +0100131 // create wrapper script for vppctl with proper CLI socket path
132 cliContent := "#!/usr/bin/bash\nvppctl -s " + vpp.getRunDir() + "/cli.sock"
133 vppcliFileName := "/usr/bin/vppcli"
134 vpp.container.createFile(vppcliFileName, cliContent)
135 vpp.container.exec("chmod 0755 " + vppcliFileName)
136
Adrian Villincee15aa2024-03-14 11:42:55 -0400137 vpp.getSuite().log("starting vpp")
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100138 if *isVppDebug {
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100139 sig := make(chan os.Signal, 1)
Adrian Villincee15aa2024-03-14 11:42:55 -0400140 signal.Notify(sig, syscall.SIGQUIT)
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100141 cont := make(chan bool, 1)
142 go func() {
Filip Tehlar9abba112023-03-07 10:13:19 +0100143 <-sig
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100144 cont <- true
145 }()
146
Filip Tehlara6b1a7d2023-09-02 08:39:25 +0200147 vpp.container.execServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"")
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100148 fmt.Println("run following command in different terminal:")
Filip Tehlara6b1a7d2023-09-02 08:39:25 +0200149 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 -0400150 fmt.Println("Afterwards press CTRL+\\ to continue")
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100151 <-cont
152 fmt.Println("continuing...")
153 } else {
154 // Start VPP
155 vpp.container.execServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"")
156 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100157
Adrian Villincee15aa2024-03-14 11:42:55 -0400158 vpp.getSuite().log("connecting to vpp")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100159 // Connect to VPP and store the connection
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100160 sockAddress := vpp.container.getHostWorkDir() + defaultApiSocketFilePath
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100161 conn, connEv, err := govpp.AsyncConnect(
162 sockAddress,
163 core.DefaultMaxReconnectAttempts,
164 core.DefaultReconnectInterval)
165 if err != nil {
166 fmt.Println("async connect error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100167 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100168 }
169 vpp.connection = conn
170
171 // ... wait for Connected event
172 e := <-connEv
173 if e.State != core.Connected {
174 fmt.Println("connecting to VPP failed: ", e.Error)
175 }
176
177 // ... check compatibility of used messages
178 ch, err := conn.NewAPIChannel()
179 if err != nil {
180 fmt.Println("creating channel failed: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100181 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100182 }
183 if err := ch.CheckCompatiblity(vpe.AllMessages()...); err != nil {
184 fmt.Println("compatibility error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100185 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100186 }
187 if err := ch.CheckCompatiblity(interfaces.AllMessages()...); err != nil {
188 fmt.Println("compatibility error: ", err)
Filip Tehlar56e17cf2024-01-11 17:17:33 +0100189 return err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100190 }
191 vpp.apiChannel = ch
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100192
193 return nil
194}
195
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100196func (vpp *VppInstance) vppctl(command string, arguments ...any) string {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100197 vppCliCommand := fmt.Sprintf(command, arguments...)
198 containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s",
199 vpp.container.name, vpp.getCliSocket(), vppCliCommand)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100200 vpp.getSuite().log(containerExecCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100201 output, err := exechelper.CombinedOutput(containerExecCommand)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100202 vpp.getSuite().assertNil(err)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100203
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100204 return string(output)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100205}
206
Filip Tehlar543cd572023-06-27 10:01:37 +0200207func (vpp *VppInstance) GetSessionStat(stat string) int {
208 o := vpp.vppctl("show session stats")
209 vpp.getSuite().log(o)
210 for _, line := range strings.Split(o, "\n") {
211 if strings.Contains(line, stat) {
212 tokens := strings.Split(strings.TrimSpace(line), " ")
213 val, err := strconv.Atoi(tokens[0])
214 if err != nil {
Adrian Villincee15aa2024-03-14 11:42:55 -0400215 Fail("failed to parse stat value %s" + fmt.Sprint(err))
Filip Tehlar543cd572023-06-27 10:01:37 +0200216 return 0
217 }
218 return val
219 }
220 }
221 return 0
222}
223
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100224func (vpp *VppInstance) waitForApp(appName string, timeout int) {
Adrian Villincee15aa2024-03-14 11:42:55 -0400225 vpp.getSuite().log("waiting for app " + appName)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100226 for i := 0; i < timeout; i++ {
227 o := vpp.vppctl("show app")
228 if strings.Contains(o, appName) {
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100229 return
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100230 }
231 time.Sleep(1 * time.Second)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100232 }
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100233 vpp.getSuite().assertNil(1, "Timeout while waiting for app '%s'", appName)
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100234}
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100235
236func (vpp *VppInstance) createAfPacket(
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100237 veth *NetInterface,
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100238) (interface_types.InterfaceIndex, error) {
239 createReq := &af_packet.AfPacketCreateV2{
240 UseRandomHwAddr: true,
241 HostIfName: veth.Name(),
242 }
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100243 if veth.hwAddress != (MacAddress{}) {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100244 createReq.UseRandomHwAddr = false
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100245 createReq.HwAddr = veth.hwAddress
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100246 }
247 createReply := &af_packet.AfPacketCreateV2Reply{}
248
Adrian Villincee15aa2024-03-14 11:42:55 -0400249 vpp.getSuite().log("create af-packet interface " + veth.Name())
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100250 if err := vpp.apiChannel.SendRequest(createReq).ReceiveReply(createReply); err != nil {
251 return 0, err
252 }
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100253 veth.index = createReply.SwIfIndex
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100254
255 // Set to up
256 upReq := &interfaces.SwInterfaceSetFlags{
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100257 SwIfIndex: veth.index,
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100258 Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
259 }
260 upReply := &interfaces.SwInterfaceSetFlagsReply{}
261
Adrian Villincee15aa2024-03-14 11:42:55 -0400262 vpp.getSuite().log("set af-packet interface " + veth.Name() + " up")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100263 if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil {
264 return 0, err
265 }
266
267 // Add address
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100268 if veth.addressWithPrefix() == (AddressWithPrefix{}) {
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100269 var err error
270 var ip4Address string
Filip Tehlar3a910ab2023-06-08 17:39:39 +0200271 if ip4Address, err = veth.ip4AddrAllocator.NewIp4InterfaceAddress(veth.peer.networkNumber); err == nil {
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100272 veth.ip4Address = ip4Address
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100273 } else {
274 return 0, err
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100275 }
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100276 }
277 addressReq := &interfaces.SwInterfaceAddDelAddress{
278 IsAdd: true,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100279 SwIfIndex: veth.index,
280 Prefix: veth.addressWithPrefix(),
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100281 }
282 addressReply := &interfaces.SwInterfaceAddDelAddressReply{}
283
Adrian Villincee15aa2024-03-14 11:42:55 -0400284 vpp.getSuite().log("af-packet interface " + veth.Name() + " add address " + veth.ip4Address)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100285 if err := vpp.apiChannel.SendRequest(addressReq).ReceiveReply(addressReply); err != nil {
286 return 0, err
287 }
288
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100289 return veth.index, nil
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100290}
291
292func (vpp *VppInstance) addAppNamespace(
293 secret uint64,
294 ifx interface_types.InterfaceIndex,
295 namespaceId string,
296) error {
297 req := &session.AppNamespaceAddDelV2{
298 Secret: secret,
299 SwIfIndex: ifx,
300 NamespaceID: namespaceId,
301 }
302 reply := &session.AppNamespaceAddDelV2Reply{}
303
Adrian Villincee15aa2024-03-14 11:42:55 -0400304 vpp.getSuite().log("add app namespace " + namespaceId)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100305 if err := vpp.apiChannel.SendRequest(req).ReceiveReply(reply); err != nil {
306 return err
307 }
308
309 sessionReq := &session.SessionEnableDisable{
310 IsEnable: true,
311 }
312 sessionReply := &session.SessionEnableDisableReply{}
313
Adrian Villincee15aa2024-03-14 11:42:55 -0400314 vpp.getSuite().log("enable app namespace " + namespaceId)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100315 if err := vpp.apiChannel.SendRequest(sessionReq).ReceiveReply(sessionReply); err != nil {
316 return err
317 }
318
319 return nil
320}
321
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100322func (vpp *VppInstance) createTap(
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100323 tap *NetInterface,
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100324 tapId ...uint32,
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100325) error {
Maros Ondrejickac2f76f42023-02-27 13:22:45 +0100326 var id uint32 = 1
327 if len(tapId) > 0 {
328 id = tapId[0]
329 }
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100330 createTapReq := &tapv2.TapCreateV2{
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100331 ID: id,
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100332 HostIfNameSet: true,
Maros Ondrejicka40cba402023-02-23 13:19:15 +0100333 HostIfName: tap.Name(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100334 HostIP4PrefixSet: true,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100335 HostIP4Prefix: tap.ip4AddressWithPrefix(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100336 }
337 createTapReply := &tapv2.TapCreateV2Reply{}
338
Adrian Villincee15aa2024-03-14 11:42:55 -0400339 vpp.getSuite().log("create tap interface " + tap.Name())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100340 // Create tap interface
341 if err := vpp.apiChannel.SendRequest(createTapReq).ReceiveReply(createTapReply); err != nil {
342 return err
343 }
344
345 // Add address
346 addAddressReq := &interfaces.SwInterfaceAddDelAddress{
347 IsAdd: true,
348 SwIfIndex: createTapReply.SwIfIndex,
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100349 Prefix: tap.peer.addressWithPrefix(),
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100350 }
351 addAddressReply := &interfaces.SwInterfaceAddDelAddressReply{}
352
Adrian Villincee15aa2024-03-14 11:42:55 -0400353 vpp.getSuite().log("tap interface " + tap.Name() + " add address " + tap.peer.ip4Address)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100354 if err := vpp.apiChannel.SendRequest(addAddressReq).ReceiveReply(addAddressReply); err != nil {
355 return err
356 }
357
358 // Set interface to up
359 upReq := &interfaces.SwInterfaceSetFlags{
360 SwIfIndex: createTapReply.SwIfIndex,
361 Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP,
362 }
363 upReply := &interfaces.SwInterfaceSetFlagsReply{}
364
Adrian Villincee15aa2024-03-14 11:42:55 -0400365 vpp.getSuite().log("set tap interface " + tap.Name() + " up")
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100366 if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil {
367 return err
368 }
369
370 return nil
371}
372
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100373func (vpp *VppInstance) saveLogs() {
374 logTarget := vpp.container.getLogDirPath() + "vppinstance-" + vpp.container.name + ".log"
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100375 logSource := vpp.container.getHostWorkDir() + defaultLogFilePath
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100376 cmd := exec.Command("cp", logSource, logTarget)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100377 vpp.getSuite().log(cmd.String())
Maros Ondrejickaa2d52622023-02-24 11:26:39 +0100378 cmd.Run()
379}
380
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100381func (vpp *VppInstance) disconnect() {
382 vpp.connection.Disconnect()
383 vpp.apiChannel.Close()
384}
Filip Tehlar608d0062023-04-28 10:29:47 +0200385
386func (vpp *VppInstance) generateCpuConfig() string {
387 var c Stanza
388 var s string
389 if len(vpp.cpus) < 1 {
390 return ""
391 }
392 c.newStanza("cpu").
393 append(fmt.Sprintf("main-core %d", vpp.cpus[0]))
394 workers := vpp.cpus[1:]
395
396 if len(workers) > 0 {
397 for i := 0; i < len(workers); i++ {
398 if i != 0 {
399 s = s + ", "
400 }
401 s = s + fmt.Sprintf("%d", workers[i])
402 }
403 c.append(fmt.Sprintf("corelist-workers %s", s))
404 }
405 return c.close().toString()
406}