Add scripts for vIPSEC VNF
[demo.git] / vnfs / vIPSEC / scripts / v_sink_init.sh
1 #!/bin/bash
2
3 # Convert Network CIDR to Netmask
4 cdr2mask () {
5         # Number of args to shift, 255..255, first non-255 byte, zeroes
6         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
7         [ $1 -gt 1 ] && shift $1 || shift
8         echo ${1-0}.${2-0}.${3-0}.${4-0}
9 }
10
11 # Set the IP address of the protected network interface of the vIPsec as a default gateway to the unprotected network
12 PROTECTED_NET_GW=$(cat /opt/config/protected_net_gw.txt)
13 PROTECTED_NET_A=$(cat /opt/config/protected_net_A.txt | cut -d'/' -f1)
14 BITS=$(cat /opt/config/protected_net_A.txt | cut -d"/" -f2)
15 NETMASK=$(cdr2mask $BITS) 
16
17 route add -net $PROTECTED_NET_A netmask $NETMASK gw $PROTECTED_NET_GW