|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -usage_str=""" |
4 | | -Usage: ${0} <AMOUNT OF IPS> |
5 | | -
|
6 | | -<AMOUNT OF IPS> specifies the number of IP addresses assigned to each NAT; setting this argument >1 allows NAT IP pooling to be simulated |
| 3 | +usage_str="""Usage: ${0} [OPTIONAL ARGUMENTS] |
7 | 4 |
|
8 | 5 | Simulates a network setup containing two private networks connected via the public network. Each private network contains two peers using eduP2P |
9 | | -To allow traffic to flow between the public and private networks, the scripts setup_nat_mapping.sh should also be executed |
10 | | -To allow traffic to flow between peers in the same private network, the scripts setup_nat_filtering_hairpinning.sh should also be executed |
11 | 6 |
|
12 | | -This script must be run with root permissions""" |
| 7 | +By default, a single NAT with one IP address facilitates the communication between a private and public network. With the -2 flag, Double NAT is simulated by adding another level of private networks on top of the existing ones. With the -n flag, the amount of IPs on the NAT can be increased up to 9; if Double NAT is enabled, the additional NAT always has 1 IP address. |
13 | 8 |
|
14 | | -if [[ $1 = "-h" || $# -ne 1 ]]; then |
15 | | - echo $usage_str |
16 | | - exit 1 |
17 | | -fi |
| 9 | +To allow traffic to flow between the public and private networks, the script setup_nat_mapping.sh should also be executed. To allow traffic to flow between peers in the same private network, the script setup_nat_filtering_hairpinning.sh should also be executed |
18 | 10 |
|
19 | | -# Number of IPs per router to test NAT IP pooling |
20 | | -n_pooling_ips=$1 |
| 11 | +This script must be run with root permissions""" |
| 12 | + |
| 13 | +# Use functions and constants from util.sh |
| 14 | +. ../util.sh |
| 15 | + |
| 16 | +# Default arguments |
| 17 | +n_pooling_ips=1 |
| 18 | + |
| 19 | +# Validate optional arguments |
| 20 | +while getopts ":2n:h" opt; do |
| 21 | + case $opt in |
| 22 | + 2) |
| 23 | + double_nat=true |
| 24 | + ;; |
| 25 | + n) |
| 26 | + n_pooling_ips=$OPTARG |
| 27 | + |
| 28 | + # Make sure n_pooling_ips is an integer between 1 and 9 |
| 29 | + n_pooling_ips_regex="^[1-9]$" |
| 30 | + validate_str $n_pooling_ips $n_pooling_ips_regex |
| 31 | + ;; |
| 32 | + h) |
| 33 | + echo "$usage_str" |
| 34 | + exit 0 |
| 35 | + ;; |
| 36 | + *) |
| 37 | + exit_with_error "invalid option" |
| 38 | + ;; |
| 39 | + esac |
| 40 | +done |
21 | 41 |
|
22 | 42 | # Enable IP forwarding to allow for routing between namespaces |
23 | 43 | sysctl -w net.ipv4.ip_forward=1 &> /dev/null |
@@ -73,11 +93,31 @@ for ((i=1; i<=n_priv_nets; i++)); do |
73 | 93 | # Add router's public subnet to list created earlier |
74 | 94 | adm_ips+=($pub_subnet) |
75 | 95 |
|
76 | | - # Setup router |
77 | | - ip netns exec $router_name ./setup_router.sh $router_name $priv_name $priv_subnet $router_priv_ip $pub_prefix $n_pooling_ips $switch_ip |
| 96 | + if [[ -z $double_nat ]]; then |
| 97 | + # Setup router |
| 98 | + ip netns exec $router_name ./setup_router.sh $router_name $priv_name public $priv_subnet $router_priv_ip $pub_prefix $n_pooling_ips $switch_ip 0 |
| 99 | + |
| 100 | + # Setup private network |
| 101 | + ip netns exec $priv_name ./setup_private.sh $router_name $router_pub_ip $priv_subnet |
| 102 | + else |
| 103 | + # Create namespace for the additional private network |
| 104 | + double_name="double${i}" |
| 105 | + ./create_namespace.sh $double_name |
| 106 | + |
| 107 | + # Variables related to the additional private network and its router |
| 108 | + double_prefix="172.16.${i}" |
| 109 | + double_subnet="${priv_prefix}.0/24" |
| 110 | + double_ip="${double_prefix}.254" |
| 111 | + |
| 112 | + # Setup first router |
| 113 | + ip netns exec $router_name ./setup_router.sh $router_name $double_name public $double_subnet $double_ip $pub_prefix $n_pooling_ips $switch_ip 0 |
| 114 | + |
| 115 | + # Setup additional router |
| 116 | + ip netns exec $double_name ./setup_router.sh $double_name $priv_name $router_name $priv_subnet $router_priv_ip $double_prefix $n_pooling_ips $router_pub_ip 1 |
78 | 117 |
|
79 | | - # Setup private network |
80 | | - ip netns exec $priv_name ./setup_private.sh $router_name $router_pub_ip $priv_subnet |
| 118 | + # Setup private network |
| 119 | + ip netns exec $priv_name ./setup_private.sh $double_name $double_ip $priv_subnet |
| 120 | + fi |
81 | 121 |
|
82 | 122 | # Setup peers in each private network |
83 | 123 | for ((j=1; j<=n_peers; j++)); do |
|
0 commit comments