Commit 5f5460ab authored by Ondřej Zajíček's avatar Ondřej Zajíček

Netlab: Make MAC addresses stable

parent 3e5fca60
......@@ -96,6 +96,12 @@ function netlab_stop()
}
function if_mac()
{
echo "$1-$2" | sha1sum | sed -E 's/^(.)(..)(..)(..)(..)(..).*$/\1a:\2:\3:\4:\5:\6/'
}
function if_net()
{
IF=$1
......@@ -111,6 +117,7 @@ function if_dummy()
IF=$2
ip link add name $IF netns $NS type dummy
ip netns exec $NS ip link set $IF address $(if_mac $NS $IF)
if [[ $1 == */* ]]; then ip netns exec $NS ip link set $IF vrf ${1##*/} ; fi
ip netns exec $NS ip link set $IF up
......@@ -135,6 +142,8 @@ function if_veth()
IF2=$4
ip link add name $IF1 netns $NS1 type veth peer name $IF2 netns $NS2
ip netns exec $NS1 ip link set $IF1 address $(if_mac $NS1 $IF1)
ip netns exec $NS2 ip link set $IF2 address $(if_mac $NS2 $IF2)
if [[ $1 == */* ]]; then ip netns exec $NS1 ip link set $IF1 vrf ${1##*/} ; fi
if [[ $3 == */* ]]; then ip netns exec $NS2 ip link set $IF2 vrf ${3##*/} ; fi
......@@ -160,6 +169,8 @@ function if_link()
NET=$3
ip link add name $IF1 netns $NS1 type veth peer name $IF2 netns $NS2
ip netns exec $NS1 ip link set $IF1 address $(if_mac $NS1 $IF1)
ip netns exec $NS2 ip link set $IF2 address $(if_mac $NS2 $IF2)
if [[ $1 == */* ]]; then ip netns exec $NS1 ip link set $IF1 vrf ${1##*/} ; fi
......@@ -182,5 +193,6 @@ function vrf()
IF=$2
ip link add name $IF netns $NS type vrf table $3
# ip netns exec $NS ip link set $IF address $(if_mac $NS $IF)
ip netns exec $NS ip link set $IF up
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment