
# Giorgio Ciciani  18-11-2009

#VPN-GREoverIP butterfly topology
#  
#                  
#       GW4---|		    ---GW2
#        |      ----GW1----     |
#	 |     			|	
# 	GW5---|		    ---GW3	
#  
#
#

# internet net_id	160.80.85.0/24
# site1 net_id	192.168.1.0/24	
# site2 net_id	192.168.2.0/24	
# site3 net_id	192.168.3.0/24	
# site4 net_id	192.168.4.0/24
# site5 net_id	192.168.5.0/24
# virtal adapters net_id 10.0.8.0/24

vstart GW1 --eth0=internet --eth1=site1 -M 16
vstart GW2 --eth0=internet --eth1=site2 -M 16
vstart GW3 --eth0=internet --eth1=site3 -M 16
vstart GW4 --eth0=internet --eth1=site4 -M 16
vstart GW5 --eth0=internet --eth1=site5 -M 16
vstart PC11 --eth0=site1 -M 16
vstart PC12 --eth0=site2 -M 16
vstart PC13 --eth0=site3 -M 16
vstart PC14 --eth0=site4 -M 16
vstart PC15 --eth0=site5 -M 16

## configuration of ip addresses and IP routing
#GW1
ifconfig eth0 160.80.85.1/24
ifconfig eth1 192.168.1.1/24

#GW2
ifconfig eth0 160.80.85.2/24
ifconfig eth1 192.168.2.1/24

#GW3
ifconfig eth0 160.80.85.3/24
ifconfig eth1 192.168.3.1/24

#GW4
ifconfig eth0 160.80.85.4/24
ifconfig eth1 192.168.4.1/24

#GW5
ifconfig eth0 160.80.85.5/24
ifconfig eth1 192.168.5.1/24


#PC11
ifconfig eth0 192.168.1.2/24
route add default gw 192.168.1.1

#PC12
ifconfig eth0 192.168.2.2/24
route add default gw 192.168.2.1

#PC13
ifconfig eth0 192.168.3.2/24
route add default gw 192.168.3.1

#PC14
ifconfig eth0 192.168.4.2/24
route add default gw 192.168.4.1

#PC15
ifconfig eth0 192.168.5.2/24
route add default gw 192.168.5.1


## configuration of gre tunnels and routing table on GWx

#GW1
ip tunnel add to_gw2 mode gre remote 160.80.85.2 local 160.80.85.1 ttl 255
ip tunnel add to_gw3 mode gre remote 160.80.85.3 local 160.80.85.1 ttl 255
ip tunnel add to_gw4 mode gre remote 160.80.85.4 local 160.80.85.1 ttl 255
ip tunnel add to_gw5 mode gre remote 160.80.85.5 local 160.80.85.1 ttl 255
ifconfig to_gw2 10.8.0.12
ifconfig to_gw3 10.8.0.13
ifconfig to_gw4 10.8.0.14
ifconfig to_gw5 10.8.0.15

# add all IP routes for remote VPN subnets
route add -net 192.168.2.0/24 dev to_gw2
route add -net 192.168.3.0/24 dev to_gw3
route add -net 192.168.4.0/24 dev to_gw4
route add -net 192.168.5.0/24 dev to_gw5

# add all IP route for remote virtual adapters 
route add -host 10.8.0.21 dev to_gw2
route add -host 10.8.0.31 dev to_gw3
route add -host 10.8.0.41 dev to_gw4
route add -host 10.8.0.51 dev to_gw5

#GW2
ip tunnel add to_gw1 mode gre remote 160.80.85.1 local 160.80.85.2 ttl 255
ip tunnel add to_gw3 mode gre remote 160.80.85.3 local 160.80.85.2 ttl 255
ifconfig to_gw1 10.8.0.21
ifconfig to_gw3 10.8.0.23

# add all IP routes for remote VPN subnets
route add -net 192.168.1.0/24 dev to_gw1
route add -net 192.168.3.0/24 dev to_gw3
route add -net 192.168.4.0/24 dev to_gw1
route add -net 192.168.5.0/24 dev to_gw1

# add all IP route for remote virtual adapters 
route add -host 10.8.0.13 dev to_gw1
route add -host 10.8.0.32 dev to_gw3



#GW3
ip tunnel add to_gw1 mode gre remote 160.80.85.1 local 160.80.85.3 ttl 255
ip tunnel add to_gw2 mode gre remote 160.80.85.2 local 160.80.85.3 ttl 255
ifconfig to_gw1 10.8.0.31
ifconfig to_gw2 10.8.0.32

# add all IP routes for remote VPN subnets
route add -net 192.168.1.0/24 dev to_gw1
route add -net 192.168.2.0/24 dev to_gw2
route add -net 192.168.4.0/24 dev to_gw1
route add -net 192.168.5.0/24 dev to_gw1

# add all IP route for remote virtual adapters 
route add -host 10.8.0.23 dev to_gw2
route add -host 10.8.0.13 dev to_gw1

#GW4
ip tunnel add to_gw1 mode gre remote 160.80.85.1 local 160.80.85.4 ttl 255
ip tunnel add to_gw5 mode gre remote 160.80.85.5 local 160.80.85.4 ttl 255
ifconfig to_gw1 10.8.0.41
ifconfig to_gw5 10.8.0.45

# add all IP routes for remote VPN subnets
route add -net 192.168.1.0/24 dev to_gw1
route add -net 192.168.2.0/24 dev to_gw1
route add -net 192.168.3.0/24 dev to_gw1
route add -net 192.168.5.0/24 dev to_gw5

# add all IP route for remote virtual adapters
route add -host 10.8.0.14 dev to_gw1
route add -host 10.8.0.54 dev to_gw5

#GW5
ip tunnel add to_gw1 mode gre remote 160.80.85.1 local 160.80.85.5 ttl 255
ip tunnel add to_gw4 mode gre remote 160.80.85.4 local 160.80.85.5 ttl 255
ifconfig to_gw1 10.8.0.51
ifconfig to_gw4 10.8.0.54

# add all IP routes for remote VPN subnets
route add -net 192.168.1.0/24 dev to_gw1
route add -net 192.168.2.0/24 dev to_gw1
route add -net 192.168.3.0/24 dev to_gw1
route add -net 192.168.4.0/24 dev to_gw4

# add all IP route for remote virtual adapters
route add -host 10.8.0.15 dev to_gw1
route add -host 10.8.0.45 dev to_gw4

##GW1
cd /hosthome/greIPsec_butterfly
setkey -f ./ipsecgw1.conf

##GW2
cd /hosthome/greIPsec_butterfly
setkey -f ./ipsecgw2.conf

##GW3
cd /hosthome/greIPsec_butterfly
setkey -f ./ipsecgw3.conf

##GW4
cd /hosthome/greIPsec_butterfly
setkey -f ./ipsecgw4.conf

##GW5
cd /hosthome/greIPsec_butterfly
setkey -f ./ipsecgw5.conf

