Last active
December 11, 2020 22:29
-
-
Save ahmetozer/d01538327a98ed70cf04e48e89fe8c31 to your computer and use it in GitHub Desktop.
Mesh Topology Demo on Linux in Namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Mesh Topology with Namespace | |
# Graph | |
NAMESPACE_COUNT=3 | |
### | |
# ! I recommend to run this script in temporary container. | |
# docker run -it --rm --privileged ahmetozer/cna | |
# in container curl https://gist.githubusercontent.com/ahmetozer/d01538327a98ed70cf04e48e89fe8c31/raw/mesh-topology-example.sh -o mesh-topology-example.sh ; chmod +x mesh-topology-example.sh | |
### | |
# IANA TEST NET 3 - 203.0.113.0/24 - https://tools.ietf.org/html/rfc5737 | |
IP_BLOCK="203.0.113" | |
if [ "$1" == "print" ]; then | |
RUN_COMMAND='echo' | |
else | |
RUN_COMMAND='command' | |
fi | |
# Create namespaces | |
echo -e "\n\tCreateting namespaces" | |
for ((i = 1; i <= $NAMESPACE_COUNT; i++)); do | |
$RUN_COMMAND ip netns add node-$i | |
$RUN_COMMAND ip netns add node-$i-end | |
$RUN_COMMAND ip netns exec node-$i ifconfig lo up | |
done | |
set -e | |
for ((i = 1; i <= $NAMESPACE_COUNT; i++)); do | |
echo -e "\n\tFor node-$i" | |
$RUN_COMMAND ip netns exec node-$i brctl addbr br0 | |
$RUN_COMMAND ip netns exec node-$i brctl stp br0 on | |
# ! IPv6 Disabled due to endless ndp packet loop on nodes | |
$RUN_COMMAND ip netns exec node-$i sysctl -w net.ipv6.icmp.echo_ignore_all=1 | |
$RUN_COMMAND ip netns exec node-$i sysctl -w net.ipv6.icmp.echo_ignore_all=1 | |
$RUN_COMMAND ip netns exec node-$i sysctl -w net.ipv6.conf.all.disable_ipv6=1 | |
$RUN_COMMAND ip netns exec node-$i sysctl -w net.ipv6.conf.default.disable_ipv6=1 | |
for ((n = (($i + 1)); n <= $NAMESPACE_COUNT; n++)); do | |
$RUN_COMMAND ip link add vertex$i-$n netns node-$i type veth peer name vertex$n-$i netns node-$n | |
$RUN_COMMAND ip netns exec node-$i ifconfig vertex$i-$n up | |
$RUN_COMMAND ip netns exec node-$n ifconfig vertex$n-$i up | |
done | |
for ((n = 1; n < $i; n++)); do | |
$RUN_COMMAND ip netns exec node-$i brctl addif br0 vertex$i-$n | |
done | |
for ((n = (($i + 1)); n <= $NAMESPACE_COUNT; n++)); do | |
$RUN_COMMAND ip netns exec node-$i brctl addif br0 vertex$i-$n | |
done | |
$RUN_COMMAND ip netns exec node-$i ifconfig br0 $IP_BLOCK.$i up | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment