Skip to content

Commit

Permalink
Fix tools vxlan create cmd (#1625)
Browse files Browse the repository at this point in the history
* init the fix

tests pending

* remove mtu default value to make sure mtu is derived from the parent iface

* added tests for tools vxlan create

* get link netnsid

* add debug statement

* added iproute2

* added rn

* final attempt to get nsid

* propagate env vars to sudo clab command
  • Loading branch information
hellt authored Oct 9, 2023
1 parent 85206be commit 4ee5ba0
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/vxlan-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
test-suite:
- "01*.robot"
- "02*.robot"
- "03*.robot"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
3 changes: 1 addition & 2 deletions cmd/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ func init() {
"parent (source) interface name for VxLAN")
vxlanCreateCmd.Flags().StringVarP(&cntLink, "link", "l", "",
"link to which 'attach' vxlan tunnel with tc redirect")
vxlanCreateCmd.Flags().IntVarP(&vxlanMTU, "mtu", "m", 1554, "VxLAN MTU")
vxlanCreateCmd.Flags().IntVarP(&vxlanMTU, "mtu", "m", 0, "VxLAN MTU")
vxlanCreateCmd.Flags().IntVarP(&vxlanUDPPort, "port", "p", 14789, "VxLAN Destination UDP Port")

_ = vxlanCreateCmd.MarkFlagRequired("remote")
_ = vxlanCreateCmd.MarkFlagRequired("id")
_ = vxlanCreateCmd.MarkFlagRequired("link")

vxlanDeleteCmd.Flags().StringVarP(&delPrefix, "prefix", "p", "vx-",
Expand Down
6 changes: 6 additions & 0 deletions docs/rn/0.46.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ Couple that with containerlab' ability to use env variables in the topology file
curl -sL srlinux.dev/clab-srl | \
SRL_VERSION=23.3.3 SRL_TYPE=ixrd2l clab dep -c -t -
```

## Patches

### 0.46.1

* fixed `tools vxlan create` #1625.
11 changes: 10 additions & 1 deletion links/link_vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ func (lr *LinkVxlanRaw) Resolve(params *ResolveParams) (Link, error) {
func (lr *LinkVxlanRaw) resolveStitchedVEthComponent(params *ResolveParams) (*LinkVEth, Endpoint, error) {
var err error

// hostIface is the name of the host interface that will be created
hostIface := fmt.Sprintf("ve-%s_%s", lr.Endpoint.Node, lr.Endpoint.Iface)

// when tools vxlan create command is used, the hostIface is provided
// by the user, otherwise it is generated
if params.VxlanIfaceNameOverwrite != "" {
hostIface = params.VxlanIfaceNameOverwrite
}

lhr := &LinkHostRaw{
LinkCommonParams: lr.LinkCommonParams,
HostInterface: fmt.Sprintf("ve-%s_%s", lr.Endpoint.Node, lr.Endpoint.Iface),
HostInterface: hostIface,
Endpoint: &EndpointRaw{
Node: lr.Endpoint.Node,
Iface: lr.Endpoint.Iface,
Expand Down
10 changes: 5 additions & 5 deletions tests/01-smoke/12-tools-veth.robot
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ${runtime-cli-exec-cmd} sudo docker exec
Deploy ${lab-name} lab
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
Log ${output}
Should Be Equal As Integers ${rc} 0
# save output to be used in next steps
Expand All @@ -45,7 +45,7 @@ Verify links in node n1 pre-deploy
Deploy veth between bridge and n1
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n1:eth1 -b bridge:${bridge-name}:${bridge-n1-iface}
... sudo -E ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n1:eth1 -b bridge:${bridge-name}:${bridge-n1-iface}
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand All @@ -65,7 +65,7 @@ Verify bridge link
Deploy veth between n1 and n2
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n1:eth2 -b clab-${lab-name}-n2:eth2
... sudo -E ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n1:eth2 -b clab-${lab-name}-n2:eth2
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand All @@ -86,7 +86,7 @@ Verify links in node n2 post-deploy
Deploy veth between n2 and host
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n2:eth3 -b host:${host-n1-iface}
... sudo -E ${CLAB_BIN} --runtime ${runtime} tools veth create -d -a clab-${lab-name}-n2:eth3 -b host:${host-n1-iface}
Log ${output}
Should Be Equal As Integers ${rc} 0

Expand All @@ -110,5 +110,5 @@ Setup
Run sudo ip l add dev ${bridge-name} type bridge

Teardown
Run sudo ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Run sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Run sudo ip l del dev ${bridge-name}
6 changes: 3 additions & 3 deletions tests/01-smoke/13-stdin-lab.robot
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ ${lab-url} https://gist.githubusercontent.com/hellt/9baa28d7e3cb8290ade1e1b
*** Test Cases ***
Deploy remote lab
${rc} ${output} = Run And Return Rc And Output
... sudo curl -s ${lab-url} | sudo ${CLAB_BIN} --runtime ${runtime} deploy -c -t -
... sudo curl -s ${lab-url} | sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -c -t -
Log ${output}
Should Be Equal As Integers ${rc} 0

Ensure inspect works
${rc} ${output} = Run And Return Rc And Output
... sudo ${CLAB_BIN} --runtime ${runtime} inspect --all
... sudo -E ${CLAB_BIN} --runtime ${runtime} inspect --all
Log ${output}
Should Be Equal As Integers ${rc} 0


*** Keywords ***
Teardown
# destroy all labs
Run sudo ${CLAB_BIN} --runtime ${runtime} destroy -c -a
Run sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -c -a
150 changes: 150 additions & 0 deletions tests/08-vxlan/03-tools-veth-vxlan.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
*** Settings ***
Library OperatingSystem
Library String
Library Process
Resource ../common.robot

Suite Setup Run Keyword Setup
Suite Teardown Run Keyword Cleanup


*** Variables ***
${lab-file} 03-vxlan-tools.clab.yml
${lab-name} vxlan-tools
${runtime} docker
${bridge-name} clabtestbr
${l1_name} some_very_long_node_name_l1
${l2_name} l2
${l1_host_link} some_very_long_node_name_l1_eth1
${l2_host_link} l2_eth1
${vxlan-br} clab-vxlan-br
${vxlan-br-ip} 172.20.25.1/24

# runtime command to execute tasks in a container
# defaults to docker exec. Will be rewritten to containerd `ctr` if needed in "Define runtime exec" test
${runtime-cli-exec-cmd} sudo docker exec


*** Test Cases ***
Deploy ${lab-name} lab
Log ${CURDIR}
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} deploy -t ${CURDIR}/${lab-file}
Log ${output}
Should Be Equal As Integers ${rc} 0
# save output to be used in next steps
Set Suite Variable ${deploy-output} ${output}

Define runtime exec command
IF "${runtime}" == "podman"
Set Suite Variable ${runtime-cli-exec-cmd} sudo podman exec
END

Get netns id for host interface of some_very_long_node_name_l1
${output} = Run
... ip netns list-id
Log ${output}

${rc} ${output} = Run And Return Rc And Output
... ip netns list-id | awk '/clab-${lab-name}-${l1_name}/ {print $2}'

Set Suite Variable ${l1_host_link_netnsid} ${output}

Check host interface for some_very_long_node_name_l1 node
${rc} ${output} = Run And Return Rc And Output
... sudo ip -j link | jq -r '.[] | select(.ifalias == "${l1_host_link}") | .ifname' | xargs ip -d l show

Should Contain ${output} mtu 9500

Should Contain Any
... ${output}
... link-netns clab-vxlan-tools-some_very_long_node_name_l1
... link-netnsid ${l1_host_link_netnsid}

Check host interface for l2 node
${rc} ${output} = Run And Return Rc And Output
... sudo ip -d l show l2_eth1

Should Contain ${output} mtu 9500

Should Contain ${output} link-netns clab-vxlan-tools-l2

Deploy vxlab link between l1 and l3 with tools cmd
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} tools vxlan create --remote 172.20.25.23 --link ${l1_host_link} --id 101 --port 14788
Log ${output}
Should Be Equal As Integers ${rc} 0

Verify vxlan links betweem l1 and l3
${rc} ${output} = Run And Return Rc And Output
... sudo ip -j link | jq -r '.[] | select(.ifalias == "vx-${l1_host_link}") | .ifname' | xargs ip -d l show
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} mtu 9050 qdisc noqueue state UNKNOWN
Should Contain ${output} vxlan id 101 remote 172.20.25.23 dev clab-vxlan-br srcport 0 0 dstport 14788

Check VxLAN connectivity l1-l3
# CI env var is set to true in Github Actions
# and this test won't run there, since it fails for unknown reason
IF '%{CI=false}'=='false'
Wait Until Keyword Succeeds 60 2s Check VxLAN connectivity l1->l3
END

Deploy vxlab link between l2 and l4 with tools cmd
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} tools vxlan create --remote 172.20.25.24 --link ${l2_host_link} --id 102
Log ${output}
Should Be Equal As Integers ${rc} 0

Verify vxlan links betweem l2 and l4
${rc} ${output} = Run And Return Rc And Output
... sudo ip -d link show vx-${l2_host_link}
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} mtu 9050 qdisc noqueue state UNKNOWN
Should Contain ${output} vxlan id 102 remote 172.20.25.24 dev clab-vxlan-br srcport 0 0 dstport 14789

Check VxLAN connectivity l2-l4
# CI env var is set to true in Github Actions
# and this test won't run there, since it fails for unknown reason
IF '%{CI=false}'=='false'
Wait Until Keyword Succeeds 60 2s Check VxLAN connectivity l2->l4
END


*** Keywords ***
Setup
# skipping this test suite for podman for now
Skip If '${runtime}' == 'podman'
# setup vxlan underlay bridge
# we have to setup an underlay management bridge with big enought mtu to support vxlan and srl requirements for link mtu
# we set mtu 9100 (and not the default 9500) because srl can't set vxlan mtu > 9412 and < 1500
${rc} ${output} = Run And Return Rc And Output
... sudo ip link add ${vxlan-br} type bridge || true
${rc} ${output} = Run And Return Rc And Output
... sudo ip link set dev ${vxlan-br} up && sudo ip link set dev ${vxlan-br} mtu 9100 && sudo ip addr add ${vxlan-br-ip} dev ${vxlan-br} || true
Log ${output}
Should Be Equal As Integers ${rc} 0

Cleanup
${rc} ${output} = Run And Return Rc And Output
... sudo -E ${CLAB_BIN} --runtime ${runtime} destroy -t ${CURDIR}/${lab-file} --cleanup
Log ${output}

${rc} ${output} = Run And Return Rc And Output
... sudo ip l del ${vxlan-br}
Log ${output}

Check VxLAN connectivity l1->l3
${rc} ${output} = Run And Return Rc And Output
... sudo -E docker exec -it clab-${lab-name}-${l1_name} ping 192.168.13.2 -c 1
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} 0% packet loss

Check VxLAN connectivity l2->l4
${rc} ${output} = Run And Return Rc And Output
... sudo -E docker exec -it clab-${lab-name}-${l2_name} ping 192.168.24.2 -c 1
Log ${output}
Should Be Equal As Integers ${rc} 0
Should Contain ${output} 0% packet loss
59 changes: 59 additions & 0 deletions tests/08-vxlan/03-vxlan-tools.clab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: vxlan-tools

mgmt:
network: clab-vxlan
bridge: clab-vxlan-br
ipv4-subnet: 172.20.25.0/24

topology:
nodes:
# this node doesn't participate in the vxlan datapath
# we just put it here to test that long named nodes
# are treated correctly with ip aliases added to link name.
some_very_long_node_name_l1:
kind: linux
image: alpine:3
exec:
- apk add iproute2
- ip addr add dev eth1 192.168.13.1/30
mgmt-ipv4: 172.20.25.21

l2:
kind: linux
image: alpine:3
exec:
- apk add iproute2
- ip addr add dev eth1 192.168.24.1/30
mgmt-ipv4: 172.20.25.22

l3:
kind: linux
image: alpine:3
exec:
- >
ash -c '
apk add iproute2 &&
ip link add name vxlan0 type vxlan id 101 remote 172.20.25.21 dstport 14788 &&
ip l set dev vxlan0 up &&
ip addr add dev vxlan0 192.168.13.2/30'
mgmt-ipv4: 172.20.25.23

l4:
kind: linux
image: alpine:3
exec:
- >
ash -c '
apk add iproute2 &&
ip link add name vxlan0 type vxlan id 102 remote 172.20.25.22 dstport 14789 &&
ip l set dev vxlan0 up &&
ip addr add dev vxlan0 192.168.24.2/30'
mgmt-ipv4: 172.20.25.24

links:
- endpoints:
[
"some_very_long_node_name_l1:eth1",
"host:some_very_long_node_name_l1_eth1",
]
- endpoints: ["l2:eth1", "host:l2_eth1"]

0 comments on commit 4ee5ba0

Please sign in to comment.