Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
2 | |||||
3 | # Tests for DevStack functions | ||||
4 | # address_in_net() | ||||
5 | |||||
6 | TOP=$(cd $(dirname "$0")/.. && pwd) | ||||
7 | |||||
8 | # Import common functions | ||||
9 | source $TOP/functions | ||||
10 | |||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 11 | source $TOP/tests/unittest.sh |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 12 | |
13 | echo "Testing IP addr functions" | ||||
14 | |||||
15 | if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 16 | passed "cidr2netmask(): /4...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 17 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 18 | failed "cidr2netmask(): /4...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 19 | fi |
20 | if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 21 | passed "cidr2netmask(): /8...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 22 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 23 | failed "cidr2netmask(): /8...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 24 | fi |
25 | if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 26 | passed "cidr2netmask(): /12...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 27 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 28 | failed "cidr2netmask(): /12...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 29 | fi |
30 | if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 31 | passed "cidr2netmask(): /16...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 32 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 33 | failed "cidr2netmask(): /16...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 34 | fi |
35 | if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 36 | passed "cidr2netmask(): /20...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 37 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 38 | failed "cidr2netmask(): /20...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 39 | fi |
40 | if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 41 | passed "cidr2netmask(): /24...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 42 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 43 | failed "cidr2netmask(): /24...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 44 | fi |
45 | if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 46 | passed "cidr2netmask(): /28...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 47 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 48 | failed "cidr2netmask(): /28...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 49 | fi |
50 | if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 51 | passed "cidr2netmask(): /30...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 52 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 53 | failed "cidr2netmask(): /30...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 54 | fi |
55 | if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 56 | passed "cidr2netmask(): /32...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 57 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 58 | failed "cidr2netmask(): /32...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 59 | fi |
60 | |||||
61 | if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 62 | passed "maskip(): /4...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 63 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 64 | failed "maskip(): /4...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 65 | fi |
66 | if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 67 | passed "maskip(): /8...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 68 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 69 | failed "maskip(): /8...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 70 | fi |
71 | if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 72 | passed "maskip(): /12...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 73 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 74 | failed "maskip(): /12...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 75 | fi |
76 | if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 77 | passed "maskip(): /16...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 78 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 79 | failed "maskip(): /16...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 80 | fi |
81 | if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 82 | passed "maskip(): /20...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 83 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 84 | failed "maskip(): /20...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 85 | fi |
86 | if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 87 | passed "maskip(): /24...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 88 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 89 | failed "maskip(): /24...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 90 | fi |
91 | if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 92 | passed "maskip(): /28...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 93 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 94 | failed "maskip(): /28...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 95 | fi |
96 | if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 97 | passed "maskip(): /32...OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 98 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 99 | failed "maskip(): /32...failed" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 100 | fi |
101 | |||||
102 | for mask in 8 12 16 20 24 26 28; do | ||||
103 | echo -n "address_in_net(): in /$mask..." | ||||
104 | if address_in_net 10.10.10.1 10.10.10.0/$mask; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 105 | passed "OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 106 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 107 | failed "address_in_net() failed on /$mask" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 108 | fi |
109 | |||||
110 | echo -n "address_in_net(): not in /$mask..." | ||||
111 | if ! address_in_net 10.10.10.1 11.11.11.0/$mask; then | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 112 | passed "OK" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 113 | else |
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 114 | failed "address_in_net() failed on /$mask" |
Dean Troyer | d4f69b2 | 2013-07-24 12:24:43 -0500 | [diff] [blame] | 115 | fi |
116 | done | ||||
Ian Wienand | f56348b | 2015-04-17 12:58:56 +1000 | [diff] [blame] | 117 | |
118 | report_results |