blob: c53e80de36e3bf8309147c509348015c02635c62 [file] [log] [blame]
Dean Troyerd4f69b22013-07-24 12:24:43 -05001#!/usr/bin/env bash
2
3# Tests for DevStack functions
4# address_in_net()
5
6TOP=$(cd $(dirname "$0")/.. && pwd)
7
8# Import common functions
9source $TOP/functions
10
Ian Wienandf56348b2015-04-17 12:58:56 +100011source $TOP/tests/unittest.sh
Dean Troyerd4f69b22013-07-24 12:24:43 -050012
13echo "Testing IP addr functions"
14
15if [[ $(cidr2netmask 4) == 240.0.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100016 passed "cidr2netmask(): /4...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050017else
Ian Wienandf56348b2015-04-17 12:58:56 +100018 failed "cidr2netmask(): /4...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050019fi
20if [[ $(cidr2netmask 8) == 255.0.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100021 passed "cidr2netmask(): /8...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050022else
Ian Wienandf56348b2015-04-17 12:58:56 +100023 failed "cidr2netmask(): /8...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050024fi
25if [[ $(cidr2netmask 12) == 255.240.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100026 passed "cidr2netmask(): /12...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050027else
Ian Wienandf56348b2015-04-17 12:58:56 +100028 failed "cidr2netmask(): /12...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050029fi
30if [[ $(cidr2netmask 16) == 255.255.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100031 passed "cidr2netmask(): /16...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050032else
Ian Wienandf56348b2015-04-17 12:58:56 +100033 failed "cidr2netmask(): /16...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050034fi
35if [[ $(cidr2netmask 20) == 255.255.240.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100036 passed "cidr2netmask(): /20...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050037else
Ian Wienandf56348b2015-04-17 12:58:56 +100038 failed "cidr2netmask(): /20...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050039fi
40if [[ $(cidr2netmask 24) == 255.255.255.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100041 passed "cidr2netmask(): /24...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050042else
Ian Wienandf56348b2015-04-17 12:58:56 +100043 failed "cidr2netmask(): /24...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050044fi
45if [[ $(cidr2netmask 28) == 255.255.255.240 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100046 passed "cidr2netmask(): /28...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050047else
Ian Wienandf56348b2015-04-17 12:58:56 +100048 failed "cidr2netmask(): /28...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050049fi
50if [[ $(cidr2netmask 30) == 255.255.255.252 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100051 passed "cidr2netmask(): /30...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050052else
Ian Wienandf56348b2015-04-17 12:58:56 +100053 failed "cidr2netmask(): /30...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050054fi
55if [[ $(cidr2netmask 32) == 255.255.255.255 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100056 passed "cidr2netmask(): /32...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050057else
Ian Wienandf56348b2015-04-17 12:58:56 +100058 failed "cidr2netmask(): /32...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050059fi
60
61if [[ $(maskip 169.254.169.254 240.0.0.0) == 160.0.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100062 passed "maskip(): /4...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050063else
Ian Wienandf56348b2015-04-17 12:58:56 +100064 failed "maskip(): /4...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050065fi
66if [[ $(maskip 169.254.169.254 255.0.0.0) == 169.0.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100067 passed "maskip(): /8...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050068else
Ian Wienandf56348b2015-04-17 12:58:56 +100069 failed "maskip(): /8...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050070fi
71if [[ $(maskip 169.254.169.254 255.240.0.0) == 169.240.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100072 passed "maskip(): /12...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050073else
Ian Wienandf56348b2015-04-17 12:58:56 +100074 failed "maskip(): /12...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050075fi
76if [[ $(maskip 169.254.169.254 255.255.0.0) == 169.254.0.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100077 passed "maskip(): /16...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050078else
Ian Wienandf56348b2015-04-17 12:58:56 +100079 failed "maskip(): /16...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050080fi
81if [[ $(maskip 169.254.169.254 255.255.240.0) == 169.254.160.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100082 passed "maskip(): /20...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050083else
Ian Wienandf56348b2015-04-17 12:58:56 +100084 failed "maskip(): /20...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050085fi
86if [[ $(maskip 169.254.169.254 255.255.255.0) == 169.254.169.0 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100087 passed "maskip(): /24...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050088else
Ian Wienandf56348b2015-04-17 12:58:56 +100089 failed "maskip(): /24...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050090fi
91if [[ $(maskip 169.254.169.254 255.255.255.240) == 169.254.169.240 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100092 passed "maskip(): /28...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050093else
Ian Wienandf56348b2015-04-17 12:58:56 +100094 failed "maskip(): /28...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -050095fi
96if [[ $(maskip 169.254.169.254 255.255.255.255) == 169.254.169.254 ]]; then
Ian Wienandf56348b2015-04-17 12:58:56 +100097 passed "maskip(): /32...OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -050098else
Ian Wienandf56348b2015-04-17 12:58:56 +100099 failed "maskip(): /32...failed"
Dean Troyerd4f69b22013-07-24 12:24:43 -0500100fi
101
102for 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 Wienandf56348b2015-04-17 12:58:56 +1000105 passed "OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -0500106 else
Ian Wienandf56348b2015-04-17 12:58:56 +1000107 failed "address_in_net() failed on /$mask"
Dean Troyerd4f69b22013-07-24 12:24:43 -0500108 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 Wienandf56348b2015-04-17 12:58:56 +1000112 passed "OK"
Dean Troyerd4f69b22013-07-24 12:24:43 -0500113 else
Ian Wienandf56348b2015-04-17 12:58:56 +1000114 failed "address_in_net() failed on /$mask"
Dean Troyerd4f69b22013-07-24 12:24:43 -0500115 fi
116done
Ian Wienandf56348b2015-04-17 12:58:56 +1000117
118report_results