h2_destroy()
{
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/28
}
rp1_set_addr()
{
ip address add dev $rp1 192.0.2.17/28
ip route add 192.0.2.32/28 nexthop via 192.0.2.18
ip route add 192.0.2.48/28 nexthop via 192.0.2.18
}
rp1_unset_addr()
{
ip route del 192.0.2.48/28 nexthop via 192.0.2.18
ip route del 192.0.2.32/28 nexthop via 192.0.2.18
ip address del dev $rp1 192.0.2.17/28
}
switch_create()
{
ip link add name br1 type bridge vlan_filtering 0 mcast_snooping 0 # Make sure the bridge uses the MAC address of the local port and not # that of the VxLAN's device.
ip link set dev br1 address $(mac_get $swp1)
ip link set dev br1 up
ip link set dev $rp1 up
rp1_set_addr
ip link add name vx1 type vxlan id 1000 \
local 192.0.2.17 dstport "$VXPORT" \
nolearning noudpcsum tos inherit ttl 100
ip link set dev vx1 up
ip link set dev vx1 master br1
ip link set dev $swp1 master br1
ip link set dev $swp1 up
ip link set dev $swp2 master br1
ip link set dev $swp2 up
bridge fdb append dev vx1 00:00:00:00:00:00 dst 192.0.2.34 self
bridge fdb append dev vx1 00:00:00:00:00:00 dst 192.0.2.50 self
}
switch_destroy()
{
rp1_unset_addr
ip link set dev $rp1 down
bridge fdb del dev vx1 00:00:00:00:00:00 dst 192.0.2.50 self
bridge fdb del dev vx1 00:00:00:00:00:00 dst 192.0.2.34 self
ip link set dev vx1 nomaster
ip link set dev vx1 down
ip link del dev vx1
ip link set dev $swp2 down
ip link set dev $swp2 nomaster
ip link set dev $swp1 down
ip link set dev $swp1 nomaster
vrp2_destroy()
{
tc qdisc del dev v1 clsact
__simple_if_fini v3 192.0.2.49/28
__simple_if_fini v1 192.0.2.33/28
simple_if_fini $rp2 192.0.2.18/28
}
ns_init_common()
{
local in_if=$1; shift
local in_addr=$1; shift
local other_in_addr=$1; shift
local nh_addr=$1; shift
local host_addr=$1; shift
ip link set dev $in_if up
ip address add dev $in_if $in_addr/28
tc qdisc add dev $in_if clsact
ip link add name br2 type bridge vlan_filtering 0
ip link set dev br2 up
ip link add name w1 type veth peer name w2
ip link set dev w1 master br2
ip link set dev w1 up
ip link add name vx2 type vxlan id 1000 local $in_addr dstport "$VXPORT"
ip link set dev vx2 up
bridge fdb append dev vx2 00:00:00:00:00:00 dst 192.0.2.17 self
bridge fdb append dev vx2 00:00:00:00:00:00 dst $other_in_addr self
ip link set dev vx2 master br2
tc qdisc add dev vx2 clsact
simple_if_init w2 $host_addr/28
ip route add 192.0.2.16/28 nexthop via $nh_addr
ip route add $other_in_addr/32 nexthop via $nh_addr
} export -f ns_init_common
ns1_create()
{
ip netns add ns1
ip link set dev v2 netns ns1
in_ns ns1 \
ns_init_common v2 192.0.2.34 192.0.2.50 192.0.2.33 192.0.2.3
}
ns1_destroy()
{
ip netns exec ns1 ip link set dev v2 netns 1
ip netns del ns1
}
ns2_create()
{
ip netns add ns2
ip link set dev v4 netns ns2
in_ns ns2 \
ns_init_common v4 192.0.2.50 192.0.2.34 192.0.2.49 192.0.2.4
}
ns2_destroy()
{
ip netns exec ns2 ip link set dev v4 netns 1
ip netns del ns2
}
ns2_destroy
ns1_destroy
vrp2_destroy
ip link del dev v3
ip link del dev v1
switch_destroy
h2_destroy
h1_destroy
forwarding_restore
vrf_cleanup
}
# For the first round of tests, vx1 is the first device to get attached to the # bridge, and that at the point that the local IP is already configured. Try the # other scenario of attaching the device to an already-offloaded bridge, and # only then attach the local IP.
reapply_config()
{ echo"Reapplying configuration"
bridge fdb del dev vx1 00:00:00:00:00:00 dst 192.0.2.50 self
bridge fdb del dev vx1 00:00:00:00:00:00 dst 192.0.2.34 self
rp1_unset_addr
ip link set dev vx1 nomaster
sleep 5
ip link set dev vx1 master br1
bridge fdb append dev vx1 00:00:00:00:00:00 dst 192.0.2.34 self
bridge fdb append dev vx1 00:00:00:00:00:00 dst 192.0.2.50 self
sleep 1
rp1_set_addr
sleep 5
}
__flood_counter_add_del()
{
local add_del=$1; shift
local dev=$1; shift
local ns=$1; shift
# Putting the ICMP capture both to HW and to SW will end up # double-counting the packets that are trapped to slow path, such as for # the unicast test. Adding either skip_hw or skip_sw fixes this problem, # but with skip_hw, the flooded packets are not counted at all, because # those are dropped due to MAC address mismatch; and skip_sw is a no-go # for veth-based topologies. # # So try to install with skip_sw and fall back to skip_sw if that fails.
# Add an entry with arbitrary destination IP. Verify that packets are # not duplicated (this can happen if hardware floods the packets, and # then traps them due to misconfiguration, so software data path repeats # flooding and resends packets).
bridge fdb append dev vx1 00:00:00:00:00:00 dst 198.51.100.1 self
__test_flood de:ad:be:ef:13:37 192.0.2.100 "flood, unresolved FDB entry"
bridge fdb del dev vx1 00:00:00:00:00:00 dst 198.51.100.1 self
}
vxlan_fdb_add_del()
{
local add_del=$1; shift
local mac=$1; shift
local dev=$1; shift
local dst=$1; shift
__test_unicast()
{
local mac=$1; shift
local dst=$1; shift
local hit_idx=$1; shift
local what=$1; shift
RET=0
local -a expects=(0 0 0)
expects[$hit_idx]=10
vxlan_flood_test $mac $dst "${expects[@]}"
log_test "VXLAN: $what"
}
test_unicast()
{
local -a targets=("$h2_mac $h2" "$r1_mac vx1 192.0.2.34" "$r2_mac vx1 192.0.2.50")
local target
for target in "${targets[@]}"; do
vxlan_fdb_add_del add $target done
__test_unicast $h2_mac 192.0.2.2 0 "local MAC unicast"
__test_unicast $r1_mac 192.0.2.3 1 "remote MAC 1 unicast"
__test_unicast $r2_mac 192.0.2.4 2 "remote MAC 2 unicast"
for target in "${targets[@]}"; do
vxlan_fdb_add_del del $target done
}
vxlan_ping_test()
{
local ping_dev=$1; shift
local ping_dip=$1; shift
local ping_args=$1; shift
local capture_dev=$1; shift
local capture_dir=$1; shift
local capture_pref=$1; shift
local expect=$1; shift
local t0=$(tc_rule_stats_get $capture_dev $capture_pref $capture_dir)
ping_do $ping_dev $ping_dip "$ping_args"
local t1=$(tc_rule_stats_get $capture_dev $capture_pref $capture_dir)
local delta=$((t1 - t0))
# Tolerate a couple stray extra packets.
((expect <= delta && delta <= expect + 5))
check_err $? "$capture_dev: Expected to capture $expect packets, got $delta."
}
test_ttl()
{
RET=0
tc filter add dev v1 egress pref 77 prot ip \
flower ip_ttl 99 action pass
vxlan_ping_test $h1 192.0.2.3 "" v1 egress 77 10
tc filter del dev v1 egress pref 77 prot ip
log_test "VXLAN: envelope TTL"
}
test_tos()
{
RET=0
tc filter add dev v1 egress pref 77 prot ip \
flower ip_tos 0x14 action pass
vxlan_ping_test $h1 192.0.2.3 "-Q 0x14" v1 egress 77 10
vxlan_ping_test $h1 192.0.2.3 "-Q 0x18" v1 egress 77 0
tc filter del dev v1 egress pref 77 prot ip
log_test "VXLAN: envelope TOS inheritance"
}
__test_ecn_encap()
{
local q=$1; shift
local tos=$1; shift
RET=0
tc filter add dev v1 egress pref 77 prot ip \
flower ip_tos $tos ip_proto udp dst_port $VXPORT action pass
sleep 1
vxlan_ping_test $h1 192.0.2.3 "-Q $q" v1 egress 77 10
tc filter del dev v1 egress pref 77 prot ip
log_test "VXLAN: ECN encap: $q->$tos"
}
test_ecn_encap()
{ # In accordance with INET_ECN_encapsulate()
__test_ecn_encap 0x00 0x00
__test_ecn_encap 0x01 0x01
__test_ecn_encap 0x02 0x02
__test_ecn_encap 0x03 0x02
}
vxlan_encapped_ping_do()
{
local count=$1; shift
local dev=$1; shift
local next_hop_mac=$1; shift
local dest_ip=$1; shift
local dest_mac=$1; shift
local inner_tos=$1; shift
local outer_tos=$1; shift
$MZ $dev -c $count -d 100msec -q \
-b $next_hop_mac -B $dest_ip \
-t udp tos=$outer_tos,sp=23456,dp=$VXPORT,p=$(:
)"08:"$( : VXLAN flags
)"00:00:00:"$( : VXLAN reserved
)"00:03:e8:"$( : VXLAN VNI
)"00:"$( : VXLAN reserved
)"$dest_mac:"$( : ETH daddr
)"$(mac_get w2):"$( : ETH saddr
)"08:00:"$( : ETH type
)"45:"$( : IP version + IHL
)"$inner_tos:"$( : IP TOS
)"00:54:"$( : IP total length
)"99:83:"$( : IP identification
)"40:00:"$( : IP flags + frag off
)"40:"$( : IP TTL
)"01:"$( : IP proto
)"00:00:"$( : IP header csum
)"c0:00:02:03:"$( : IP saddr: 192.0.2.3
)"c0:00:02:01:"$( : IP daddr: 192.0.2.1
)"08:"$( : ICMP type
)"00:"$( : ICMP code
)"8b:f2:"$( : ICMP csum
)"1f:6a:"$( : ICMP request identifier
)"00:01:"$( : ICMP request sequence number
)"4f:ff:c5:5b:00:00:00:00:"$( : ICMP payload
)"6d:74:0b:00:00:00:00:00:"$( :
)"10:11:12:13:14:15:16:17:"$( :
)"18:19:1a:1b:1c:1d:1e:1f:"$( :
)"20:21:22:23:24:25:26:27:"$( :
)"28:29:2a:2b:2c:2d:2e:2f:"$( :
)"30:31:32:33:34:35:36:37"
} export -f vxlan_encapped_ping_do
vxlan_encapped_ping_test()
{
local ping_dev=$1; shift
local nh_dev=$1; shift
local ping_dip=$1; shift
local inner_tos=$1; shift
local outer_tos=$1; shift
local stat_get=$1; shift
local expect=$1; shift
test_learning()
{
local mac=de:ad:be:ef:13:37
local dst=192.0.2.100
# Enable learning on the VxLAN device and set ageing time to 30 seconds
ip link set dev br1 type bridge ageing_time 3000
ip link set dev vx1 type vxlan ageing 30
ip link set dev vx1 type vxlan learning
reapply_config
# Check that flooding works
RET=0
vxlan_flood_test $mac $dst 10 10 10
log_test "VXLAN: flood before learning"
# Send a packet with source mac set to $mac from host w2 and check that # a corresponding entry is created in VxLAN device vx1
RET=0
log_test "VXLAN: learning toggling on bridge port"
# Restore previous settings
ip link set dev vx1 type vxlan nolearning
ip link set dev vx1 type vxlan ageing 300
ip link set dev br1 type bridge ageing_time 30000
reapply_config
}
test_all()
{ echo"Running tests with UDP port $VXPORT"
tests_run
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.