2 * Copyright (c) 2015 IBM Corporation. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.spi;
11 import java.math.BigInteger;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
16 public class NeutronSubnetIPAllocationPoolTest {
18 public void convertTest() {
19 Assert.assertEquals("Convert Test 1: null Argument failed",
20 0, NeutronSubnetIPAllocationPool.convert(null));
22 Assert.assertEquals("Convert Test 2: convert of 32.20.10.0 failed",
23 538184192, NeutronSubnetIPAllocationPool.convert("32.20.10.0"));
25 Assert.assertEquals("Convert Test 3: convert of 192.168.2.140 failed",
26 3232236172L, NeutronSubnetIPAllocationPool.convert("192.168.2.140"));
30 public void convertV6Test() {
31 boolean result = BigInteger.ZERO.equals(NeutronSubnetIPAllocationPool.convertV6(null));
32 Assert.assertTrue("Convert V6 Test 1: null Argument failed", result);
34 result = new BigInteger("42550872755692912415807417417958686721").
35 equals(NeutronSubnetIPAllocationPool.convertV6("2003:0:0:0:0:0:0:1"));
36 Assert.assertTrue("Convert V6 Test 2: 2003:0:0:0:0:0:0:1 Argument failed", result);
41 public void longToIPTest() {
42 Assert.assertEquals("longToIP Test 1: convert of 538184192L failed",
43 "32.20.10.0", NeutronSubnetIPAllocationPool.longToIP(538184192L));
45 Assert.assertEquals("longToIP Test 2: convert of 3232236172L failed",
46 "192.168.2.140", NeutronSubnetIPAllocationPool.longToIP(3232236172L));
50 public void bigIntegerToIPTest() {
51 BigInteger start = new BigInteger("42550872755692912415807417417958686721");
52 Assert.assertEquals("longToIP Test 1: convert of 42550872755692912415807417417958686721 failed",
53 "2003:0:0:0:0:0:0:1", NeutronSubnetIPAllocationPool.bigIntegerToIP(start));
56 public void containsTest() {
57 NeutronSubnetIPAllocationPool apUT = new NeutronSubnetIPAllocationPool();
58 apUT.setPoolStart("10.18.0.2");
59 apUT.setPoolEnd("10.18.0.4");
61 Assert.assertFalse("Contains Test 1: address one below pool start failed",
62 apUT.contains("10.18.0.1"));
64 Assert.assertTrue("Contains Test 2: address == pool start failed",
65 apUT.contains("10.18.0.2"));
67 Assert.assertTrue("Contains Test 3: adress in pool failed",
68 apUT.contains("10.18.0.3"));
70 Assert.assertTrue("Contains Test 4: address == pool end failed",
71 apUT.contains("10.18.0.4"));
73 Assert.assertFalse("Contains Test 5: one above pool end failed",
74 apUT.contains("10.18.0.5"));
78 public void containsV6Test() {
79 NeutronSubnetIPAllocationPool apUT = new NeutronSubnetIPAllocationPool();
80 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
81 apUT.setPoolEnd("2015:0:0:0:0:0:0:4");
83 Assert.assertFalse("Contains V6 Test 1: address one below pool start failed",
84 apUT.containsV6("2015:0:0:0:0:0:0:1"));
86 Assert.assertTrue("Contains V6 Test 2: address == pool start failed",
87 apUT.containsV6("2015:0:0:0:0:0:0:2"));
89 Assert.assertTrue("Contains V6 Test 3: adress in pool failed",
90 apUT.containsV6("2015:0:0:0:0:0:0:3"));
92 Assert.assertTrue("Contains V6 Test 4: address == pool end failed",
93 apUT.containsV6("2015:0:0:0:0:0:0:4"));
95 Assert.assertFalse("Contains V6 Test 5: one above pool end failed",
96 apUT.containsV6("2015:0:0:0:0:0:0:5"));
100 public void splitPoolTest() {
101 NeutronSubnetIPAllocationPool apUT = new NeutronSubnetIPAllocationPool();
102 apUT.setPoolStart("10.18.0.2");
103 apUT.setPoolEnd("10.18.0.6");
104 List<NeutronSubnetIPAllocationPool> result = apUT.splitPool("10.18.0.2");
105 Assert.assertEquals("splitPool Test 1.1: address == pool start (result size) failed",
107 Assert.assertEquals("splitPool Test 1.2: address == pool start (pool start) failed",
108 "10.18.0.3", result.get(0).getPoolStart());
109 Assert.assertEquals("splitPool Test 1.3: address == pool start (pool end) failed",
110 "10.18.0.6", result.get(0).getPoolEnd());
112 apUT = new NeutronSubnetIPAllocationPool();
113 apUT.setPoolStart("10.18.0.2");
114 apUT.setPoolEnd("10.18.0.6");
115 result = apUT.splitPool("10.18.0.3");
116 Assert.assertEquals("splitPool Test 2.1: address one above pool start (result size) failed",
118 Assert.assertEquals("splitPool Test 2.2: address one above pool start (pool 1 start) failed",
119 "10.18.0.2", result.get(0).getPoolStart());
120 Assert.assertEquals("splitPool Test 2.3: address one above pool start (pool 1 end) failed",
121 "10.18.0.2", result.get(0).getPoolEnd());
122 Assert.assertEquals("splitPool Test 2.4: address one above pool start (pool 2 start) failed",
123 "10.18.0.4", result.get(1).getPoolStart());
124 Assert.assertEquals("splitPool Test 2.5: address one above pool start (pool 2 end) failed",
125 "10.18.0.6", result.get(1).getPoolEnd());
127 apUT = new NeutronSubnetIPAllocationPool();
128 apUT.setPoolStart("10.18.0.2");
129 apUT.setPoolEnd("10.18.0.6");
130 result = apUT.splitPool("10.18.0.4");
131 Assert.assertEquals("splitPool Test 3.1: address one above pool start (result size) failed",
133 Assert.assertEquals("splitPool Test 3.2: address one above pool start (pool 1 start) failed",
134 "10.18.0.2", result.get(0).getPoolStart());
135 Assert.assertEquals("splitPool Test 3.3: address one above pool start (pool 1 end) failed",
136 "10.18.0.3", result.get(0).getPoolEnd());
137 Assert.assertEquals("splitPool Test 3.4: address one above pool start (pool 2 start) failed",
138 "10.18.0.5", result.get(1).getPoolStart());
139 Assert.assertEquals("splitPool Test 3.5: address one above pool start (pool 2 end) failed",
140 "10.18.0.6", result.get(1).getPoolEnd());
142 apUT = new NeutronSubnetIPAllocationPool();
143 apUT.setPoolStart("10.18.0.2");
144 apUT.setPoolEnd("10.18.0.6");
145 result = apUT.splitPool("10.18.0.5");
146 Assert.assertEquals("splitPool Test 4.1: address one above pool start (result size) failed",
148 Assert.assertEquals("splitPool Test 4.2: address one above pool start (pool 1 start) failed",
149 "10.18.0.2", result.get(0).getPoolStart());
150 Assert.assertEquals("splitPool Test 4.3: address one above pool start (pool 1 end) failed",
151 "10.18.0.4", result.get(0).getPoolEnd());
152 Assert.assertEquals("splitPool Test 4.4: address one above pool start (pool 2 start) failed",
153 "10.18.0.6", result.get(1).getPoolStart());
154 Assert.assertEquals("splitPool Test 4.5: address one above pool start (pool 2 end) failed",
155 "10.18.0.6", result.get(1).getPoolEnd());
157 apUT = new NeutronSubnetIPAllocationPool();
158 apUT.setPoolStart("10.18.0.2");
159 apUT.setPoolEnd("10.18.0.6");
160 result = apUT.splitPool("10.18.0.6");
161 Assert.assertEquals("splitPool Test 5.1: address == pool start (result size) failed",
163 Assert.assertEquals("splitPool Test 5.2: address == pool start (pool start) failed",
164 "10.18.0.2", result.get(0).getPoolStart());
165 Assert.assertEquals("splitPool Test 5.3: address == pool start (pool end) failed",
166 "10.18.0.5", result.get(0).getPoolEnd());
170 public void splitPoolV6Test() {
171 NeutronSubnetIPAllocationPool apUT = new NeutronSubnetIPAllocationPool();
172 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
173 apUT.setPoolEnd("2015:0:0:0:0:0:0:6");
174 List<NeutronSubnetIPAllocationPool> result = apUT.splitPoolV6("2015:0:0:0:0:0:0:2");
175 Assert.assertEquals("splitPoolV6 Test 1.1: address == pool start (result size) failed",
177 Assert.assertEquals("splitPoolV6 Test 1.2: address == pool start (pool start) failed",
178 "2015:0:0:0:0:0:0:3", result.get(0).getPoolStart());
179 Assert.assertEquals("splitPoolV6 Test 1.3: address == pool start (pool end) failed",
180 "2015:0:0:0:0:0:0:6", result.get(0).getPoolEnd());
182 apUT = new NeutronSubnetIPAllocationPool();
183 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
184 apUT.setPoolEnd("2015:0:0:0:0:0:0:6");
185 result = apUT.splitPoolV6("2015:0:0:0:0:0:0:3");
186 Assert.assertEquals("splitPoolV6 Test 2.1: address one above pool start (result size) failed",
188 Assert.assertEquals("splitPoolV6 Test 2.2: address one above pool start (pool 1 start) failed",
189 "2015:0:0:0:0:0:0:2", result.get(0).getPoolStart());
190 Assert.assertEquals("splitPoolV6 Test 2.3: address one above pool start (pool 1 end) failed",
191 "2015:0:0:0:0:0:0:2", result.get(0).getPoolEnd());
192 Assert.assertEquals("splitPoolV6 Test 2.4: address one above pool start (pool 2 start) failed",
193 "2015:0:0:0:0:0:0:4", result.get(1).getPoolStart());
194 Assert.assertEquals("splitPoolV6 Test 2.5: address one above pool start (pool 2 end) failed",
195 "2015:0:0:0:0:0:0:6", result.get(1).getPoolEnd());
197 apUT = new NeutronSubnetIPAllocationPool();
198 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
199 apUT.setPoolEnd("2015:0:0:0:0:0:0:6");
200 result = apUT.splitPoolV6("2015:0:0:0:0:0:0:4");
201 Assert.assertEquals("splitPoolV6 Test 3.1: address one above pool start (result size) failed",
203 Assert.assertEquals("splitPoolV6 Test 3.2: address one above pool start (pool 1 start) failed",
204 "2015:0:0:0:0:0:0:2", result.get(0).getPoolStart());
205 Assert.assertEquals("splitPoolV6 Test 3.3: address one above pool start (pool 1 end) failed",
206 "2015:0:0:0:0:0:0:3", result.get(0).getPoolEnd());
207 Assert.assertEquals("splitPoolV6 Test 3.4: address one above pool start (pool 2 start) failed",
208 "2015:0:0:0:0:0:0:5", result.get(1).getPoolStart());
209 Assert.assertEquals("splitPoolV6 Test 3.5: address one above pool start (pool 2 end) failed",
210 "2015:0:0:0:0:0:0:6", result.get(1).getPoolEnd());
212 apUT = new NeutronSubnetIPAllocationPool();
213 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
214 apUT.setPoolEnd("2015:0:0:0:0:0:0:6");
215 result = apUT.splitPoolV6("2015:0:0:0:0:0:0:5");
216 Assert.assertEquals("splitPoolV6 Test 4.1: address one above pool start (result size) failed",
218 Assert.assertEquals("splitPoolV6 Test 4.2: address one above pool start (pool 1 start) failed",
219 "2015:0:0:0:0:0:0:2", result.get(0).getPoolStart());
220 Assert.assertEquals("splitPoolV6 Test 4.3: address one above pool start (pool 1 end) failed",
221 "2015:0:0:0:0:0:0:4", result.get(0).getPoolEnd());
222 Assert.assertEquals("splitPoolV6 Test 4.4: address one above pool start (pool 2 start) failed",
223 "2015:0:0:0:0:0:0:6", result.get(1).getPoolStart());
224 Assert.assertEquals("splitPoolV6 Test 4.5: address one above pool start (pool 2 end) failed",
225 "2015:0:0:0:0:0:0:6", result.get(1).getPoolEnd());
227 apUT = new NeutronSubnetIPAllocationPool();
228 apUT.setPoolStart("2015:0:0:0:0:0:0:2");
229 apUT.setPoolEnd("2015:0:0:0:0:0:0:6");
230 result = apUT.splitPoolV6("2015:0:0:0:0:0:0:6");
231 Assert.assertEquals("splitPoolV6 Test 5.1: address == pool start (result size) failed",
233 Assert.assertEquals("splitPoolV6 Test 5.2: address == pool start (pool start) failed",
234 "2015:0:0:0:0:0:0:2", result.get(0).getPoolStart());
235 Assert.assertEquals("splitPoolV6 Test 5.3: address == pool start (pool end) failed",
236 "2015:0:0:0:0:0:0:5", result.get(0).getPoolEnd());