diff mbox series

[ovs-dev,v12,1/5] tests: Define new ADD_VETH_NS macro.

Message ID 20230329055118.57547-2-nmiki@yahoo-corp.jp
State Accepted
Commit 0db74e0eb41b1cd105d7ef2d27d55af47cc7cf87
Headers show
Series userspace: Add SRv6 tunnel support. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Nobuhiro MIKI March 29, 2023, 5:51 a.m. UTC
The new ADD_VETH_NS macro creates two netns and connects them
with a veth pair. We can use it for testing in a generic purpose.

e.g.
ADD_VETH_NS([ns1], [p1], [1.1.1.1/24], [ns2], [p2], [1.1.1.2/24])

Signed-off-by: Nobuhiro MIKI <nmiki@yahoo-corp.jp>
---
 tests/system-common-macros.at | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at
index 8b9f5c75254f..0077a8609c02 100644
--- a/tests/system-common-macros.at
+++ b/tests/system-common-macros.at
@@ -126,6 +126,22 @@  m4_define([ADD_VETH_BOND],
     ]
 )
 
+# ADD_VETH_NS([ns1], [port1], [ip_addr1], [ns2], [port2], [ip_addr2])
+#
+# Add a pair of veth ports in 'ns1' and 'ns2'. The port names are 'port1'
+# and 'port2' respectively, and the IP addresses 'ip_addr1' and 'ip_addr2'
+# are assigned to each port.
+m4_define([ADD_VETH_NS],
+    [ AT_CHECK([ip link add $2 type veth peer name $5]),
+      AT_CHECK([ip link set $2 netns $1])
+      AT_CHECK([ip link set $5 netns $4])
+      NS_CHECK_EXEC([$1], [ip link set $2 up])
+      NS_CHECK_EXEC([$4], [ip link set $5 up])
+      NS_CHECK_EXEC([$1], [ip addr add $3 dev $2])
+      NS_CHECK_EXEC([$4], [ip addr add $6 dev $5])
+    ]
+)
+
 # ADD_VLAN([port], [namespace], [vlan-id], [ip-addr])
 #
 # Add a VLAN device named 'port' within 'namespace'. It will be configured