Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
Filip Tehlar | f3ee2b6 | 2023-01-09 12:07:09 +0100 | [diff] [blame] | 4 | "fmt" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 5 | "os" |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 6 | "os/exec" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 7 | "os/signal" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 8 | "strings" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 9 | "syscall" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 10 | "time" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 11 | |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 12 | "github.com/edwarnicke/exechelper" |
| 13 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 14 | "go.fd.io/govpp" |
| 15 | "go.fd.io/govpp/api" |
| 16 | "go.fd.io/govpp/binapi/af_packet" |
| 17 | interfaces "go.fd.io/govpp/binapi/interface" |
| 18 | "go.fd.io/govpp/binapi/interface_types" |
| 19 | "go.fd.io/govpp/binapi/session" |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 20 | "go.fd.io/govpp/binapi/tapv2" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 21 | "go.fd.io/govpp/binapi/vpe" |
| 22 | "go.fd.io/govpp/core" |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | const vppConfigTemplate = `unix { |
| 26 | nodaemon |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 27 | log %[1]s%[4]s |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 28 | full-coredump |
| 29 | cli-listen %[1]s%[2]s |
| 30 | runtime-dir %[1]s/var/run |
| 31 | gid vpp |
| 32 | } |
| 33 | |
| 34 | api-trace { |
| 35 | on |
| 36 | } |
| 37 | |
| 38 | api-segment { |
| 39 | gid vpp |
| 40 | } |
| 41 | |
| 42 | socksvr { |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 43 | socket-name %[1]s%[3]s |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | statseg { |
| 47 | socket-name %[1]s/var/run/vpp/stats.sock |
| 48 | } |
| 49 | |
| 50 | plugins { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 51 | plugin default { disable } |
| 52 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 53 | plugin unittest_plugin.so { enable } |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 54 | plugin quic_plugin.so { enable } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 55 | plugin af_packet_plugin.so { enable } |
| 56 | plugin hs_apps_plugin.so { enable } |
| 57 | plugin http_plugin.so { enable } |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 60 | logging { |
| 61 | default-log-level debug |
| 62 | default-syslog-log-level debug |
| 63 | } |
| 64 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 65 | ` |
| 66 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 67 | const ( |
| 68 | defaultCliSocketFilePath = "/var/run/vpp/cli.sock" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 69 | defaultApiSocketFilePath = "/var/run/vpp/api.sock" |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 70 | defaultLogFilePath = "/var/log/vpp/vpp.log" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 71 | ) |
| 72 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 73 | type VppInstance struct { |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 74 | container *Container |
| 75 | additionalConfig Stanza |
| 76 | connection *core.Connection |
| 77 | apiChannel api.Channel |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 80 | func (vpp *VppInstance) getSuite() *HstSuite { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 81 | return vpp.container.suite |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 84 | func (vpp *VppInstance) getCliSocket() string { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 85 | return fmt.Sprintf("%s%s", vpp.container.getContainerWorkDir(), defaultCliSocketFilePath) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 88 | func (vpp *VppInstance) getRunDir() string { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 89 | return vpp.container.getContainerWorkDir() + "/var/run/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | func (vpp *VppInstance) getLogDir() string { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 93 | return vpp.container.getContainerWorkDir() + "/var/log/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func (vpp *VppInstance) getEtcDir() string { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 97 | return vpp.container.getContainerWorkDir() + "/etc/vpp" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 100 | func (vpp *VppInstance) start() error { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 101 | // Create folders |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 102 | containerWorkDir := vpp.container.getContainerWorkDir() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 103 | |
| 104 | vpp.container.exec("mkdir --mode=0700 -p " + vpp.getRunDir()) |
| 105 | vpp.container.exec("mkdir --mode=0700 -p " + vpp.getLogDir()) |
| 106 | vpp.container.exec("mkdir --mode=0700 -p " + vpp.getEtcDir()) |
| 107 | |
| 108 | // Create startup.conf inside the container |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 109 | configContent := fmt.Sprintf( |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 110 | vppConfigTemplate, |
| 111 | containerWorkDir, |
| 112 | defaultCliSocketFilePath, |
| 113 | defaultApiSocketFilePath, |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 114 | defaultLogFilePath, |
Maros Ondrejicka | 300f70d | 2023-02-21 10:53:20 +0100 | [diff] [blame] | 115 | ) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 116 | configContent += vpp.additionalConfig.toString() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 117 | startupFileName := vpp.getEtcDir() + "/startup.conf" |
| 118 | vpp.container.createFile(startupFileName, configContent) |
| 119 | |
Filip Tehlar | 1a66150 | 2023-03-08 11:55:50 +0100 | [diff] [blame] | 120 | // create wrapper script for vppctl with proper CLI socket path |
| 121 | cliContent := "#!/usr/bin/bash\nvppctl -s " + vpp.getRunDir() + "/cli.sock" |
| 122 | vppcliFileName := "/usr/bin/vppcli" |
| 123 | vpp.container.createFile(vppcliFileName, cliContent) |
| 124 | vpp.container.exec("chmod 0755 " + vppcliFileName) |
| 125 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 126 | if *isVppDebug { |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 127 | sig := make(chan os.Signal, 1) |
| 128 | signal.Notify(sig, syscall.SIGINT) |
| 129 | cont := make(chan bool, 1) |
| 130 | go func() { |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 131 | <-sig |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 132 | cont <- true |
| 133 | }() |
| 134 | |
| 135 | // Start VPP in GDB and wait for user to attach it |
| 136 | vpp.container.execServer("su -c \"gdb -ex run --args vpp -c " + startupFileName + " &> /proc/1/fd/1\"") |
| 137 | fmt.Println("run following command in different terminal:") |
| 138 | fmt.Println("docker exec -it " + vpp.container.name + " gdb -ex \"attach $(docker exec " + vpp.container.name + " pidof gdb)\"") |
| 139 | fmt.Println("Afterwards press CTRL+C to continue") |
| 140 | <-cont |
| 141 | fmt.Println("continuing...") |
| 142 | } else { |
| 143 | // Start VPP |
| 144 | vpp.container.execServer("su -c \"vpp -c " + startupFileName + " &> /proc/1/fd/1\"") |
| 145 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 146 | |
| 147 | // Connect to VPP and store the connection |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 148 | sockAddress := vpp.container.getHostWorkDir() + defaultApiSocketFilePath |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 149 | conn, connEv, err := govpp.AsyncConnect( |
| 150 | sockAddress, |
| 151 | core.DefaultMaxReconnectAttempts, |
| 152 | core.DefaultReconnectInterval) |
| 153 | if err != nil { |
| 154 | fmt.Println("async connect error: ", err) |
| 155 | } |
| 156 | vpp.connection = conn |
| 157 | |
| 158 | // ... wait for Connected event |
| 159 | e := <-connEv |
| 160 | if e.State != core.Connected { |
| 161 | fmt.Println("connecting to VPP failed: ", e.Error) |
| 162 | } |
| 163 | |
| 164 | // ... check compatibility of used messages |
| 165 | ch, err := conn.NewAPIChannel() |
| 166 | if err != nil { |
| 167 | fmt.Println("creating channel failed: ", err) |
| 168 | } |
| 169 | if err := ch.CheckCompatiblity(vpe.AllMessages()...); err != nil { |
| 170 | fmt.Println("compatibility error: ", err) |
| 171 | } |
| 172 | if err := ch.CheckCompatiblity(interfaces.AllMessages()...); err != nil { |
| 173 | fmt.Println("compatibility error: ", err) |
| 174 | } |
| 175 | vpp.apiChannel = ch |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 176 | |
| 177 | return nil |
| 178 | } |
| 179 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 180 | func (vpp *VppInstance) vppctl(command string, arguments ...any) string { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 181 | vppCliCommand := fmt.Sprintf(command, arguments...) |
| 182 | containerExecCommand := fmt.Sprintf("docker exec --detach=false %[1]s vppctl -s %[2]s %[3]s", |
| 183 | vpp.container.name, vpp.getCliSocket(), vppCliCommand) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 184 | vpp.getSuite().log(containerExecCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 185 | output, err := exechelper.CombinedOutput(containerExecCommand) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 186 | vpp.getSuite().assertNil(err) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 187 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 188 | return string(output) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 191 | func (vpp *VppInstance) waitForApp(appName string, timeout int) { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 192 | for i := 0; i < timeout; i++ { |
| 193 | o := vpp.vppctl("show app") |
| 194 | if strings.Contains(o, appName) { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 195 | return |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 196 | } |
| 197 | time.Sleep(1 * time.Second) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 198 | } |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 199 | vpp.getSuite().assertNil(1, "Timeout while waiting for app '%s'", appName) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 200 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 201 | |
| 202 | func (vpp *VppInstance) createAfPacket( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 203 | veth *NetInterface, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 204 | ) (interface_types.InterfaceIndex, error) { |
| 205 | createReq := &af_packet.AfPacketCreateV2{ |
| 206 | UseRandomHwAddr: true, |
| 207 | HostIfName: veth.Name(), |
| 208 | } |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 209 | if veth.hwAddress != (MacAddress{}) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 210 | createReq.UseRandomHwAddr = false |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 211 | createReq.HwAddr = veth.hwAddress |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 212 | } |
| 213 | createReply := &af_packet.AfPacketCreateV2Reply{} |
| 214 | |
| 215 | if err := vpp.apiChannel.SendRequest(createReq).ReceiveReply(createReply); err != nil { |
| 216 | return 0, err |
| 217 | } |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 218 | veth.index = createReply.SwIfIndex |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 219 | |
| 220 | // Set to up |
| 221 | upReq := &interfaces.SwInterfaceSetFlags{ |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 222 | SwIfIndex: veth.index, |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 223 | Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, |
| 224 | } |
| 225 | upReply := &interfaces.SwInterfaceSetFlagsReply{} |
| 226 | |
| 227 | if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil { |
| 228 | return 0, err |
| 229 | } |
| 230 | |
| 231 | // Add address |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 232 | if veth.addressWithPrefix() == (AddressWithPrefix{}) { |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 233 | var err error |
| 234 | var ip4Address string |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 235 | if ip4Address, err = veth.addresser.newIp4Address(veth.peer.networkNumber); err == nil { |
| 236 | veth.ip4Address = ip4Address |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 237 | } else { |
| 238 | return 0, err |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 239 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 240 | } |
| 241 | addressReq := &interfaces.SwInterfaceAddDelAddress{ |
| 242 | IsAdd: true, |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 243 | SwIfIndex: veth.index, |
| 244 | Prefix: veth.addressWithPrefix(), |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 245 | } |
| 246 | addressReply := &interfaces.SwInterfaceAddDelAddressReply{} |
| 247 | |
| 248 | if err := vpp.apiChannel.SendRequest(addressReq).ReceiveReply(addressReply); err != nil { |
| 249 | return 0, err |
| 250 | } |
| 251 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 252 | return veth.index, nil |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | func (vpp *VppInstance) addAppNamespace( |
| 256 | secret uint64, |
| 257 | ifx interface_types.InterfaceIndex, |
| 258 | namespaceId string, |
| 259 | ) error { |
| 260 | req := &session.AppNamespaceAddDelV2{ |
| 261 | Secret: secret, |
| 262 | SwIfIndex: ifx, |
| 263 | NamespaceID: namespaceId, |
| 264 | } |
| 265 | reply := &session.AppNamespaceAddDelV2Reply{} |
| 266 | |
| 267 | if err := vpp.apiChannel.SendRequest(req).ReceiveReply(reply); err != nil { |
| 268 | return err |
| 269 | } |
| 270 | |
| 271 | sessionReq := &session.SessionEnableDisable{ |
| 272 | IsEnable: true, |
| 273 | } |
| 274 | sessionReply := &session.SessionEnableDisableReply{} |
| 275 | |
| 276 | if err := vpp.apiChannel.SendRequest(sessionReq).ReceiveReply(sessionReply); err != nil { |
| 277 | return err |
| 278 | } |
| 279 | |
| 280 | return nil |
| 281 | } |
| 282 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 283 | func (vpp *VppInstance) createTap( |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 284 | tap *NetInterface, |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 285 | tapId ...uint32, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 286 | ) error { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 287 | var id uint32 = 1 |
| 288 | if len(tapId) > 0 { |
| 289 | id = tapId[0] |
| 290 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 291 | createTapReq := &tapv2.TapCreateV2{ |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 292 | ID: id, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 293 | HostIfNameSet: true, |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 294 | HostIfName: tap.Name(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 295 | HostIP4PrefixSet: true, |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 296 | HostIP4Prefix: tap.ip4AddressWithPrefix(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 297 | } |
| 298 | createTapReply := &tapv2.TapCreateV2Reply{} |
| 299 | |
| 300 | // Create tap interface |
| 301 | if err := vpp.apiChannel.SendRequest(createTapReq).ReceiveReply(createTapReply); err != nil { |
| 302 | return err |
| 303 | } |
| 304 | |
| 305 | // Add address |
| 306 | addAddressReq := &interfaces.SwInterfaceAddDelAddress{ |
| 307 | IsAdd: true, |
| 308 | SwIfIndex: createTapReply.SwIfIndex, |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 309 | Prefix: tap.peer.addressWithPrefix(), |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 310 | } |
| 311 | addAddressReply := &interfaces.SwInterfaceAddDelAddressReply{} |
| 312 | |
| 313 | if err := vpp.apiChannel.SendRequest(addAddressReq).ReceiveReply(addAddressReply); err != nil { |
| 314 | return err |
| 315 | } |
| 316 | |
| 317 | // Set interface to up |
| 318 | upReq := &interfaces.SwInterfaceSetFlags{ |
| 319 | SwIfIndex: createTapReply.SwIfIndex, |
| 320 | Flags: interface_types.IF_STATUS_API_FLAG_ADMIN_UP, |
| 321 | } |
| 322 | upReply := &interfaces.SwInterfaceSetFlagsReply{} |
| 323 | |
| 324 | if err := vpp.apiChannel.SendRequest(upReq).ReceiveReply(upReply); err != nil { |
| 325 | return err |
| 326 | } |
| 327 | |
| 328 | return nil |
| 329 | } |
| 330 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 331 | func (vpp *VppInstance) saveLogs() { |
| 332 | logTarget := vpp.container.getLogDirPath() + "vppinstance-" + vpp.container.name + ".log" |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 333 | logSource := vpp.container.getHostWorkDir() + defaultLogFilePath |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 334 | cmd := exec.Command("cp", logSource, logTarget) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 335 | vpp.getSuite().T().Helper() |
| 336 | vpp.getSuite().log(cmd.String()) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 337 | cmd.Run() |
| 338 | } |
| 339 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 340 | func (vpp *VppInstance) disconnect() { |
| 341 | vpp.connection.Disconnect() |
| 342 | vpp.apiChannel.Close() |
| 343 | } |