Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 4 | "context" |
Filip Tehlar | f3ee2b6 | 2023-01-09 12:07:09 +0100 | [diff] [blame] | 5 | "fmt" |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 6 | "go.fd.io/govpp/binapi/ethernet_types" |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 7 | "io" |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 8 | "net" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 9 | "os" |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 10 | "os/exec" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 11 | "os/signal" |
Filip Tehlar | 543cd57 | 2023-06-27 10:01:37 +0200 | [diff] [blame] | 12 | "strconv" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 13 | "strings" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 14 | "syscall" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 15 | "time" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 16 | |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 17 | "github.com/edwarnicke/exechelper" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 18 | . "github.com/onsi/ginkgo/v2" |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 19 | "github.com/sirupsen/logrus" |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 20 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 21 | "go.fd.io/govpp" |
| 22 | "go.fd.io/govpp/api" |
| 23 | "go.fd.io/govpp/binapi/af_packet" |
| 24 | interfaces "go.fd.io/govpp/binapi/interface" |
| 25 | "go.fd.io/govpp/binapi/interface_types" |
| 26 | "go.fd.io/govpp/binapi/session" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 27 | "go.fd.io/govpp/binapi/tapv2" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 28 | "go.fd.io/govpp/core" |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 29 | ) |
| 30 | |
| 31 | const vppConfigTemplate = `unix { |
| 32 | nodaemon |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 33 | log %[1]s%[4]s |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 34 | full-coredump |
| 35 | cli-listen %[1]s%[2]s |
| 36 | runtime-dir %[1]s/var/run |
| 37 | gid vpp |
| 38 | } |
| 39 | |
| 40 | api-trace { |
| 41 | on |
| 42 | } |
| 43 | |
| 44 | api-segment { |
| 45 | gid vpp |
| 46 | } |
| 47 | |
| 48 | socksvr { |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 49 | socket-name %[1]s%[3]s |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | statseg { |
| 53 | socket-name %[1]s/var/run/vpp/stats.sock |
| 54 | } |
| 55 | |
| 56 | plugins { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 57 | plugin default { disable } |
| 58 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 59 | plugin unittest_plugin.so { enable } |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 60 | plugin quic_plugin.so { enable } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 61 | plugin af_packet_plugin.so { enable } |
| 62 | plugin hs_apps_plugin.so { enable } |
| 63 | plugin http_plugin.so { enable } |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 64 | plugin http_static_plugin.so { enable } |
| 65 | plugin prom_plugin.so { enable } |
Filip Tehlar | 3336eef | 2023-11-29 07:40:18 +0100 | [diff] [blame] | 66 | plugin tlsopenssl_plugin.so { enable } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 67 | plugin ping_plugin.so { enable } |
Matus Fabian | c899ab4 | 2024-04-22 13:42:00 +0200 | [diff] [blame] | 68 | plugin nsim_plugin.so { enable } |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 69 | plugin mactime_plugin.so { enable } |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 72 | logging { |
| 73 | default-log-level debug |
| 74 | default-syslog-log-level debug |
| 75 | } |
| 76 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 77 | ` |
| 78 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 79 | const ( |
| 80 | defaultCliSocketFilePath = "/var/run/vpp/cli.sock" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 81 | defaultApiSocketFilePath = "/var/run/vpp/api.sock" |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 82 | defaultLogFilePath = "/var/log/vpp/vpp.log" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 83 | ) |
| 84 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 85 | type VppInstance struct { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 86 | Container *Container |
| 87 | AdditionalConfig []Stanza |
| 88 | Connection *core.Connection |
| 89 | ApiStream api.Stream |
| 90 | Cpus []int |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 91 | CpuConfig VppCpuConfig |
| 92 | } |
| 93 | |
| 94 | type VppCpuConfig struct { |
| 95 | PinMainCpu bool |
| 96 | PinWorkersCorelist bool |
| 97 | SkipCores int |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 100 | func (vpp *VppInstance) getSuite() *HstSuite { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 101 | return vpp.Container.Suite |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 104 | func (vpp *VppInstance) getCliSocket() string { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 105 | return fmt.Sprintf("%s%s", vpp.Container.GetContainerWorkDir(), defaultCliSocketFilePath) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 108 | func (vpp *VppInstance) getRunDir() string { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 109 | return vpp.Container.GetContainerWorkDir() + "/var/run/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | func (vpp *VppInstance) getLogDir() string { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 113 | return vpp.Container.GetContainerWorkDir() + "/var/log/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | func (vpp *VppInstance) getEtcDir() string { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 117 | return vpp.Container.GetContainerWorkDir() + "/etc/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 120 | func (vpp *VppInstance) Start() error { |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 121 | maxReconnectAttempts := 3 |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 122 | // Replace default logger in govpp with our own |
| 123 | govppLogger := logrus.New() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 124 | govppLogger.SetOutput(io.MultiWriter(vpp.getSuite().Logger.Writer(), GinkgoWriter)) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 125 | core.SetLogger(govppLogger) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 126 | // Create folders |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 127 | containerWorkDir := vpp.Container.GetContainerWorkDir() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 128 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 129 | vpp.Container.Exec("mkdir --mode=0700 -p " + vpp.getRunDir()) |
| 130 | vpp.Container.Exec("mkdir --mode=0700 -p " + vpp.getLogDir()) |
| 131 | vpp.Container.Exec("mkdir --mode=0700 -p " + vpp.getEtcDir()) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 132 | |
| 133 | // Create startup.conf inside the container |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 134 | configContent := fmt.Sprintf( |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 135 | vppConfigTemplate, |
| 136 | containerWorkDir, |
| 137 | defaultCliSocketFilePath, |
| 138 | defaultApiSocketFilePath, |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 139 | defaultLogFilePath, |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 140 | ) |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 141 | configContent += vpp.generateVPPCpuConfig() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 142 | for _, c := range vpp.AdditionalConfig { |
| 143 | configContent += c.ToString() |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 144 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 145 | startupFileName := vpp.getEtcDir() + "/startup.conf" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 146 | vpp.Container.CreateFile(startupFileName, configContent) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 147 | |
Filip Tehlar | 1a66150 | 2023-03-08 11:55:50 +0100 | [diff] [blame] | 148 | // create wrapper script for vppctl with proper CLI socket path |
| 149 | cliContent := "#!/usr/bin/bash\nvppctl -s " + vpp.getRunDir() + "/cli.sock" |
| 150 | vppcliFileName := "/usr/bin/vppcli" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 151 | vpp.Container.CreateFile(vppcliFileName, cliContent) |
| 152 | vpp.Container.Exec("chmod 0755 " + vppcliFileName) |
Filip Tehlar | 1a66150 | 2023-03-08 11:55:50 +0100 | [diff] [blame] | 153 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 154 | vpp.getSuite().Log("starting vpp") |
| 155 | if *IsVppDebug { |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 156 | // default = 3; VPP will timeout while debugging if there are not enough attempts |
| 157 | maxReconnectAttempts = 5000 |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 158 | sig := make(chan os.Signal, 1) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 159 | signal.Notify(sig, syscall.SIGQUIT) |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 160 | cont := make(chan bool, 1) |
| 161 | go func() { |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 162 | <-sig |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 163 | cont <- true |
| 164 | }() |
| 165 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 166 | vpp.Container.ExecServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"") |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 167 | fmt.Println("run following command in different terminal:") |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 168 | fmt.Println("docker exec -it " + vpp.Container.Name + " gdb -ex \"attach $(docker exec " + vpp.Container.Name + " pidof vpp)\"") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 169 | fmt.Println("Afterwards press CTRL+\\ to continue") |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 170 | <-cont |
| 171 | fmt.Println("continuing...") |
| 172 | } else { |
| 173 | // Start VPP |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 174 | vpp.Container.ExecServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"") |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 175 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 176 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 177 | vpp.getSuite().Log("connecting to vpp") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 178 | // Connect to VPP and store the connection |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 179 | sockAddress := vpp.Container.GetHostWorkDir() + defaultApiSocketFilePath |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 180 | conn, connEv, err := govpp.AsyncConnect( |
| 181 | sockAddress, |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 182 | maxReconnectAttempts, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 183 | core.DefaultReconnectInterval) |
| 184 | if err != nil { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 185 | vpp.getSuite().Log("async connect error: " + fmt.Sprint(err)) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 186 | return err |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 187 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 188 | vpp.Connection = conn |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 189 | |
| 190 | // ... wait for Connected event |
| 191 | e := <-connEv |
| 192 | if e.State != core.Connected { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 193 | vpp.getSuite().Log("connecting to VPP failed: " + fmt.Sprint(e.Error)) |
Hadi Rayan Al-Sandid | 0eccf45 | 2024-06-24 10:48:54 +0200 | [diff] [blame] | 194 | return e.Error |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 197 | ch, err := conn.NewStream( |
| 198 | context.Background(), |
| 199 | core.WithRequestSize(50), |
| 200 | core.WithReplySize(50), |
Adrian Villin | 93974e2 | 2024-05-30 06:10:59 -0400 | [diff] [blame] | 201 | core.WithReplyTimeout(time.Second*5)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 202 | if err != nil { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 203 | vpp.getSuite().Log("creating stream failed: " + fmt.Sprint(err)) |
Filip Tehlar | 56e17cf | 2024-01-11 17:17:33 +0100 | [diff] [blame] | 204 | return err |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 205 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 206 | vpp.ApiStream = ch |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 207 | |
| 208 | return nil |
| 209 | } |
| 210 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 211 | func (vpp *VppInstance) Vppctl(command string, arguments ...any) string { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 212 | vppCliCommand := fmt.Sprintf(command, arguments...) |
| 213 | containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s", |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 214 | vpp.Container.Name, vpp.getCliSocket(), vppCliCommand) |
| 215 | vpp.getSuite().Log(containerExecCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 216 | output, err := exechelper.CombinedOutput(containerExecCommand) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 217 | vpp.getSuite().AssertNil(err) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 218 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 219 | return string(output) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Filip Tehlar | 543cd57 | 2023-06-27 10:01:37 +0200 | [diff] [blame] | 222 | func (vpp *VppInstance) GetSessionStat(stat string) int { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 223 | o := vpp.Vppctl("show session stats") |
| 224 | vpp.getSuite().Log(o) |
Filip Tehlar | 543cd57 | 2023-06-27 10:01:37 +0200 | [diff] [blame] | 225 | for _, line := range strings.Split(o, "\n") { |
| 226 | if strings.Contains(line, stat) { |
| 227 | tokens := strings.Split(strings.TrimSpace(line), " ") |
| 228 | val, err := strconv.Atoi(tokens[0]) |
| 229 | if err != nil { |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 230 | Fail("failed to parse stat value %s" + fmt.Sprint(err)) |
Filip Tehlar | 543cd57 | 2023-06-27 10:01:37 +0200 | [diff] [blame] | 231 | return 0 |
| 232 | } |
| 233 | return val |
| 234 | } |
| 235 | } |
| 236 | return 0 |
| 237 | } |
| 238 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 239 | func (vpp *VppInstance) WaitForApp(appName string, timeout int) { |
| 240 | vpp.getSuite().Log("waiting for app " + appName) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 241 | for i := 0; i < timeout; i++ { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 242 | o := vpp.Vppctl("show app") |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 243 | if strings.Contains(o, appName) { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 244 | return |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 245 | } |
| 246 | time.Sleep(1 * time.Second) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 247 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 248 | vpp.getSuite().AssertNil(1, "Timeout while waiting for app '%s'", appName) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 249 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 250 | |
| 251 | func (vpp *VppInstance) createAfPacket( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 252 | veth *NetInterface, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 253 | ) (interface_types.InterfaceIndex, error) { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 254 | createReq := &af_packet.AfPacketCreateV3{ |
| 255 | Mode: 1, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 256 | UseRandomHwAddr: true, |
| 257 | HostIfName: veth.Name(), |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 258 | Flags: af_packet.AfPacketFlags(11), |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 259 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 260 | if veth.HwAddress != (MacAddress{}) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 261 | createReq.UseRandomHwAddr = false |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 262 | createReq.HwAddr = veth.HwAddress |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 263 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 264 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 265 | vpp.getSuite().Log("create af-packet interface " + veth.Name()) |
| 266 | if err := vpp.ApiStream.SendMsg(createReq); err != nil { |
| 267 | vpp.getSuite().HstFail() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 268 | return 0, err |
| 269 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 270 | replymsg, err := vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 271 | if err != nil { |
| 272 | return 0, err |
| 273 | } |
| 274 | reply := replymsg.(*af_packet.AfPacketCreateV3Reply) |
| 275 | err = api.RetvalToVPPApiError(reply.Retval) |
| 276 | if err != nil { |
| 277 | return 0, err |
| 278 | } |
| 279 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 280 | veth.Index = reply.SwIfIndex |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 281 | |
| 282 | // Set to up |
| 283 | upReq := &interfaces.SwInterfaceSetFlags{ |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 284 | SwIfIndex: veth.Index, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 285 | Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, |
| 286 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 287 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 288 | vpp.getSuite().Log("set af-packet interface " + veth.Name() + " up") |
| 289 | if err := vpp.ApiStream.SendMsg(upReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 290 | return 0, err |
| 291 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 292 | replymsg, err = vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 293 | if err != nil { |
| 294 | return 0, err |
| 295 | } |
| 296 | reply2 := replymsg.(*interfaces.SwInterfaceSetFlagsReply) |
| 297 | if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 298 | return 0, err |
| 299 | } |
| 300 | |
| 301 | // Add address |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 302 | if veth.AddressWithPrefix() == (AddressWithPrefix{}) { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 303 | var err error |
| 304 | var ip4Address string |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 305 | if ip4Address, err = veth.Ip4AddrAllocator.NewIp4InterfaceAddress(veth.Peer.NetworkNumber); err == nil { |
| 306 | veth.Ip4Address = ip4Address |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 307 | } else { |
| 308 | return 0, err |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 309 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 310 | } |
| 311 | addressReq := &interfaces.SwInterfaceAddDelAddress{ |
| 312 | IsAdd: true, |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 313 | SwIfIndex: veth.Index, |
| 314 | Prefix: veth.AddressWithPrefix(), |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 315 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 316 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 317 | vpp.getSuite().Log("af-packet interface " + veth.Name() + " add address " + veth.Ip4Address) |
| 318 | if err := vpp.ApiStream.SendMsg(addressReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 319 | return 0, err |
| 320 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 321 | replymsg, err = vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 322 | if err != nil { |
| 323 | return 0, err |
| 324 | } |
| 325 | reply3 := replymsg.(*interfaces.SwInterfaceAddDelAddressReply) |
| 326 | err = api.RetvalToVPPApiError(reply3.Retval) |
| 327 | if err != nil { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 328 | return 0, err |
| 329 | } |
| 330 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 331 | return veth.Index, nil |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | func (vpp *VppInstance) addAppNamespace( |
| 335 | secret uint64, |
| 336 | ifx interface_types.InterfaceIndex, |
| 337 | namespaceId string, |
| 338 | ) error { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 339 | req := &session.AppNamespaceAddDelV4{ |
| 340 | IsAdd: true, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 341 | Secret: secret, |
| 342 | SwIfIndex: ifx, |
| 343 | NamespaceID: namespaceId, |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 344 | SockName: defaultApiSocketFilePath, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 345 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 346 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 347 | vpp.getSuite().Log("add app namespace " + namespaceId) |
| 348 | if err := vpp.ApiStream.SendMsg(req); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 349 | return err |
| 350 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 351 | replymsg, err := vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 352 | if err != nil { |
| 353 | return err |
| 354 | } |
| 355 | reply := replymsg.(*session.AppNamespaceAddDelV4Reply) |
| 356 | if err = api.RetvalToVPPApiError(reply.Retval); err != nil { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 357 | return err |
| 358 | } |
| 359 | |
| 360 | sessionReq := &session.SessionEnableDisable{ |
| 361 | IsEnable: true, |
| 362 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 363 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 364 | vpp.getSuite().Log("enable app namespace " + namespaceId) |
| 365 | if err := vpp.ApiStream.SendMsg(sessionReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 366 | return err |
| 367 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 368 | replymsg, err = vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 369 | if err != nil { |
| 370 | return err |
| 371 | } |
| 372 | reply2 := replymsg.(*session.SessionEnableDisableReply) |
| 373 | if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 374 | return err |
| 375 | } |
| 376 | |
| 377 | return nil |
| 378 | } |
| 379 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 380 | func (vpp *VppInstance) createTap( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 381 | tap *NetInterface, |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 382 | tapId ...uint32, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 383 | ) error { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 384 | var id uint32 = 1 |
| 385 | if len(tapId) > 0 { |
| 386 | id = tapId[0] |
| 387 | } |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 388 | createTapReq := &tapv2.TapCreateV3{ |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 389 | ID: id, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 390 | HostIfNameSet: true, |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 391 | HostIfName: tap.Name(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 392 | HostIP4PrefixSet: true, |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 393 | HostIP4Prefix: tap.Ip4AddressWithPrefix(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 394 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 395 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 396 | vpp.getSuite().Log("create tap interface " + tap.Name()) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 397 | // Create tap interface |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 398 | if err := vpp.ApiStream.SendMsg(createTapReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 399 | return err |
| 400 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 401 | replymsg, err := vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 402 | if err != nil { |
| 403 | return err |
| 404 | } |
| 405 | reply := replymsg.(*tapv2.TapCreateV3Reply) |
| 406 | if err = api.RetvalToVPPApiError(reply.Retval); err != nil { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 407 | return err |
| 408 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 409 | tap.Peer.Index = reply.SwIfIndex |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 410 | |
| 411 | // Get name and mac |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 412 | if err := vpp.ApiStream.SendMsg(&interfaces.SwInterfaceDump{ |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 413 | SwIfIndex: reply.SwIfIndex, |
| 414 | }); err != nil { |
| 415 | return err |
| 416 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 417 | replymsg, err = vpp.ApiStream.RecvMsg() |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 418 | if err != nil { |
| 419 | return err |
| 420 | } |
| 421 | ifDetails := replymsg.(*interfaces.SwInterfaceDetails) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 422 | tap.Peer.name = ifDetails.InterfaceName |
| 423 | tap.Peer.HwAddress = ifDetails.L2Address |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 424 | |
| 425 | // Add address |
| 426 | addAddressReq := &interfaces.SwInterfaceAddDelAddress{ |
| 427 | IsAdd: true, |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 428 | SwIfIndex: reply.SwIfIndex, |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 429 | Prefix: tap.Peer.AddressWithPrefix(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 430 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 431 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 432 | vpp.getSuite().Log("tap interface " + tap.Name() + " add address " + tap.Peer.Ip4Address) |
| 433 | if err := vpp.ApiStream.SendMsg(addAddressReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 434 | return err |
| 435 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 436 | replymsg, err = vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 437 | if err != nil { |
| 438 | return err |
| 439 | } |
| 440 | reply2 := replymsg.(*interfaces.SwInterfaceAddDelAddressReply) |
| 441 | if err = api.RetvalToVPPApiError(reply2.Retval); err != nil { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 442 | return err |
| 443 | } |
| 444 | |
| 445 | // Set interface to up |
| 446 | upReq := &interfaces.SwInterfaceSetFlags{ |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 447 | SwIfIndex: reply.SwIfIndex, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 448 | Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, |
| 449 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 450 | |
| 451 | vpp.getSuite().Log("set tap interface " + tap.Name() + " up") |
| 452 | if err := vpp.ApiStream.SendMsg(upReq); err != nil { |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 453 | return err |
| 454 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 455 | replymsg, err = vpp.ApiStream.RecvMsg() |
Adrian Villin | 46d6600 | 2024-05-15 04:33:41 -0400 | [diff] [blame] | 456 | if err != nil { |
| 457 | return err |
| 458 | } |
| 459 | reply3 := replymsg.(*interfaces.SwInterfaceSetFlagsReply) |
| 460 | if err = api.RetvalToVPPApiError(reply3.Retval); err != nil { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 461 | return err |
| 462 | } |
| 463 | |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 464 | // Get host mac |
| 465 | netIntf, err := net.InterfaceByName(tap.Name()) |
| 466 | if err == nil { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 467 | tap.HwAddress, _ = ethernet_types.ParseMacAddress(netIntf.HardwareAddr.String()) |
Matus Fabian | 82ad966 | 2024-06-04 19:00:00 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 470 | return nil |
| 471 | } |
| 472 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 473 | func (vpp *VppInstance) saveLogs() { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 474 | logTarget := vpp.Container.getLogDirPath() + "vppinstance-" + vpp.Container.Name + ".log" |
| 475 | logSource := vpp.Container.GetHostWorkDir() + defaultLogFilePath |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 476 | cmd := exec.Command("cp", logSource, logTarget) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 477 | vpp.getSuite().Log(cmd.String()) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 478 | cmd.Run() |
| 479 | } |
| 480 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 481 | func (vpp *VppInstance) Disconnect() { |
| 482 | vpp.Connection.Disconnect() |
| 483 | vpp.ApiStream.Close() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 484 | } |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 485 | |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 486 | func (vpp *VppInstance) setDefaultCpuConfig() { |
| 487 | vpp.CpuConfig.PinMainCpu = true |
| 488 | vpp.CpuConfig.PinWorkersCorelist = true |
| 489 | vpp.CpuConfig.SkipCores = 0 |
| 490 | } |
| 491 | |
| 492 | func (vpp *VppInstance) generateVPPCpuConfig() string { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 493 | var c Stanza |
| 494 | var s string |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 495 | startCpu := 0 |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 496 | if len(vpp.Cpus) < 1 { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 497 | return "" |
| 498 | } |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 499 | |
| 500 | c.NewStanza("cpu") |
| 501 | |
| 502 | // If skip-cores is valid, use as start value to assign main/workers CPUs |
| 503 | if vpp.CpuConfig.SkipCores != 0 { |
| 504 | c.Append(fmt.Sprintf("skip-cores %d", vpp.CpuConfig.SkipCores)) |
| 505 | vpp.getSuite().Log(fmt.Sprintf("skip-cores %d", vpp.CpuConfig.SkipCores)) |
| 506 | } |
| 507 | |
| 508 | if len(vpp.Cpus) > vpp.CpuConfig.SkipCores { |
| 509 | startCpu = vpp.CpuConfig.SkipCores |
| 510 | } |
| 511 | |
| 512 | if vpp.CpuConfig.PinMainCpu { |
| 513 | c.Append(fmt.Sprintf("main-core %d", vpp.Cpus[startCpu])) |
| 514 | vpp.getSuite().Log(fmt.Sprintf("main-core %d", vpp.Cpus[startCpu])) |
| 515 | } |
| 516 | |
| 517 | workers := vpp.Cpus[startCpu+1:] |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 518 | |
| 519 | if len(workers) > 0 { |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 520 | if vpp.CpuConfig.PinWorkersCorelist { |
| 521 | for i := 0; i < len(workers); i++ { |
| 522 | if i != 0 { |
| 523 | s = s + ", " |
| 524 | } |
| 525 | s = s + fmt.Sprintf("%d", workers[i]) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 526 | } |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 527 | c.Append(fmt.Sprintf("corelist-workers %s", s)) |
| 528 | vpp.getSuite().Log("corelist-workers " + s) |
| 529 | } else { |
| 530 | s = fmt.Sprintf("%d", len(workers)) |
| 531 | c.Append(fmt.Sprintf("workers %s", s)) |
| 532 | vpp.getSuite().Log("workers " + s) |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 533 | } |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 534 | } |
Hadi Rayan Al-Sandid | e0e8513 | 2024-06-24 10:28:58 +0200 | [diff] [blame^] | 535 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 536 | return c.Close().ToString() |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 537 | } |