blob: 1017e721af41f96eca6527e577e8521a7ad1b0bb [file] [log] [blame]
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +02001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.sdxl2;
18
pierventre3849e562016-05-11 11:47:32 +020019import com.google.common.collect.Sets;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020020import org.junit.After;
21import org.junit.Before;
Carolina Fernandezad893432016-07-18 11:11:34 +020022import org.junit.Rule;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020023import org.junit.Test;
Carolina Fernandezad893432016-07-18 11:11:34 +020024import org.junit.rules.ExpectedException;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020025import org.onosproject.TestApplicationId;
Carolina Fernandezad893432016-07-18 11:11:34 +020026import org.onosproject.core.IdGenerator;
27import org.onosproject.net.intent.Intent;
28import org.onosproject.net.intent.MockIdGenerator;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020029
Carolina Fernandezad893432016-07-18 11:11:34 +020030import java.util.Collections;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020031import java.util.HashSet;
pierventre3849e562016-05-11 11:47:32 +020032import java.util.Optional;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020033import java.util.Set;
34
Carolina Fernandezad893432016-07-18 11:11:34 +020035import static java.lang.String.format;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020036import static org.junit.Assert.assertEquals;
37import static org.junit.Assert.assertNotEquals;
Carolina Fernandezad893432016-07-18 11:11:34 +020038import static org.junit.Assert.assertNull;
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020039
40/**
pierventre3849e562016-05-11 11:47:32 +020041 * Tests SdxL2Manager functionality.
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020042 */
43public class SdxL2ManagerTest {
44
Carolina Fernandezad893432016-07-18 11:11:34 +020045 public static final String SDXL2 = "test";
46 public static final String SDXL2_2 = "test2";
47 public static final String CP1 = "of:00000000000001/1";
48 public static final String CP2 = "of:00000000000002/1";
49 public static final String CP3 = "of:00000000000003/1";
50 public static final String CP4 = "of:00000000000003/2";
51 public static final String CP5 = "of:00000000000004/2";
52 public static final String VLANS1 = "1,2,3,4";
53 public static final String VLANS2 = "-1";
54 public static final String VLANS3 = "1,2,3";
55 public static final String VLANS4 = "2,2,2";
56 public static final String VLANS7 = "5";
57 public static final String VLANS8 = "3,2,1";
58 public static final String CEMAC1 = "52:40:00:12:44:01";
59 public static final String CEMAC2 = "52:44:00:12:44:01";
60 public static final String CEMAC3 = "54:40:00:12:44:01";
61 public static final String CEMAC4 = "52:40:00:12:42:01";
62 public static final String CEMAC5 = "52:40:00:10:44:01";
63 public static final String CEMAC6 = "52:40:00:12:46:01";
64 public static final String CP6 = "of:00000000000004/3";
65 public static final String CP7 = "of:00000000000004/3";
66 public static final String CP8 = "of:00000000000005/2";
67 public static final String VLANS6 = "1,2,3,4";
68 public static final String VLANS5 = "8,9,10";
69 public static final String CEMAC7 = "52:40:00:12:46:01";
70 public static final String CEMAC8 = "52:40:90:12:46:01";
71 @Rule
72 public ExpectedException exceptionAddVC1 = ExpectedException.none();
73 @Rule
74 public ExpectedException exceptionAddVC2 = ExpectedException.none();
75 @Rule
76 public ExpectedException exceptionRemoveVC1 = ExpectedException.none();
77 @Rule
78 public ExpectedException exceptionRemoveVC2 = ExpectedException.none();
79 @Rule
80 public ExpectedException exceptionSdxL2Name = ExpectedException.none();
81 @Rule
82 public ExpectedException exceptionDelSdxL2Name = ExpectedException.none();
83 @Rule
84 public ExpectedException exceptionGetVC2 = ExpectedException.none();
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020085 protected SdxL2Manager manager;
Carolina Fernandezad893432016-07-18 11:11:34 +020086 protected IdGenerator idGenerator = new MockIdGenerator();
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020087
88 @Before
89 public void setUp() {
90 manager = new SdxL2Manager();
91 manager.appId = new TestApplicationId("sdxl2-test");
pierventre3849e562016-05-11 11:47:32 +020092 SdxL2DistributedStore store = new SdxL2DistributedStore();
93 store.initForTest();
94 manager.sdxL2Store = store;
Carolina Fernandezad893432016-07-18 11:11:34 +020095 SdxL2MacVCManager vcManager = new SdxL2MacVCManager(
96 manager.appId, manager.sdxL2Store, new IntentServiceTest());
97 manager.vcManager = vcManager;
98 Intent.bindIdGenerator(idGenerator);
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +020099 }
100
101 @After
102 public void tearDown() {
Carolina Fernandezad893432016-07-18 11:11:34 +0200103 Intent.unbindIdGenerator(idGenerator);
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200104 }
105
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200106 @Test
107 public void testCreateSdxL2s() {
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200108 manager.createSdxL2(SDXL2);
109 manager.createSdxL2(SDXL2_2);
110 manager.createSdxL2(SDXL2);
111 }
112
113 @Test
114 public void testRemoveSdxL2s() {
115 manager.createSdxL2(SDXL2);
116 manager.createSdxL2(SDXL2_2);
117 manager.deleteSdxL2(SDXL2);
118 manager.deleteSdxL2(SDXL2_2);
119 manager.deleteSdxL2(SDXL2);
120 }
121
122 @Test
123 public void testGetSdxL2s() {
124 Set<String> old = new HashSet<String>();
125 old.add(SDXL2_2);
126 old.add(SDXL2);
127 manager.createSdxL2(SDXL2);
128 manager.createSdxL2(SDXL2_2);
129 Set<String> sdxl2 = manager.getSdxL2s();
130 assertEquals(sdxl2, old);
131 manager.deleteSdxL2(SDXL2);
132 sdxl2 = manager.getSdxL2s();
133 assertNotEquals(sdxl2, old);
134 }
135
pierventre3849e562016-05-11 11:47:32 +0200136 @Test
Carolina Fernandezad893432016-07-18 11:11:34 +0200137 public void testAddSdxL2ConnectionPoint() {
pierventre3849e562016-05-11 11:47:32 +0200138
139 manager.createSdxL2(SDXL2);
140 manager.createSdxL2(SDXL2_2);
141 manager.createSdxL2("test1");
142
143 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
144 manager.addSdxL2ConnectionPoint(SDXL2, one);
145
146 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
147 manager.addSdxL2ConnectionPoint(SDXL2, three);
148
149 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1);
150 manager.addSdxL2ConnectionPoint(SDXL2_2, six);
151
152 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1);
153 manager.addSdxL2ConnectionPoint(SDXL2, seven);
154
155 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1);
156 manager.addSdxL2ConnectionPoint(SDXL2_2, nine);
157
158 SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1);
159 manager.addSdxL2ConnectionPoint(SDXL2, ten);
160
Carolina Fernandezad893432016-07-18 11:11:34 +0200161 SdxL2ConnectionPoint fourteen = SdxL2ConnectionPoint.
162 sdxl2ConnectionPoint("RO1", "of:0000000000000003/3", "1", "52:54:00:04:E5:9E");
pierventre3849e562016-05-11 11:47:32 +0200163 manager.addSdxL2ConnectionPoint("test1", fourteen);
164
Carolina Fernandezad893432016-07-18 11:11:34 +0200165 SdxL2ConnectionPoint fifteen = SdxL2ConnectionPoint.
166 sdxl2ConnectionPoint("RO2", "of:0000000000000009/3", "1", "52:54:00:68:F7:D9");
pierventre3849e562016-05-11 11:47:32 +0200167 manager.addSdxL2ConnectionPoint("test1", fifteen);
168
169 SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP2, VLANS1, CEMAC1);
170 manager.addSdxL2ConnectionPoint(SDXL2, two);
171
172 SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
173 manager.addSdxL2ConnectionPoint(SDXL2_2, four);
174
175 SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS2, CEMAC1);
176 manager.addSdxL2ConnectionPoint(SDXL2_2, five);
177
178 SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM4", CP3, VLANS4, CEMAC1);
179 manager.addSdxL2ConnectionPoint(SDXL2, eight);
180
181 SdxL2ConnectionPoint eleven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI3", CP5, VLANS1, CEMAC1);
182 manager.addSdxL2ConnectionPoint(SDXL2_2, eleven);
183
184 SdxL2ConnectionPoint twelve = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS1, CEMAC1);
185 manager.addSdxL2ConnectionPoint(SDXL2_2, twelve);
186
187 SdxL2ConnectionPoint thirteen = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS8, CEMAC1);
188 manager.addSdxL2ConnectionPoint(SDXL2_2, thirteen);
189
190 }
191
192 @Test
Carolina Fernandezad893432016-07-18 11:11:34 +0200193 public void testGetSdxL2ConnectionPoints() {
pierventre3849e562016-05-11 11:47:32 +0200194
195 manager.createSdxL2(SDXL2);
196 manager.createSdxL2(SDXL2_2);
197
198 Set<String> allExt = Sets.newHashSet();
199 Set<String> allExtBySdxl2 = Sets.newHashSet();
Carolina Fernandezad893432016-07-18 11:11:34 +0200200 Set<String> allExtBySdxl2Aux = Sets.newHashSet();
pierventre3849e562016-05-11 11:47:32 +0200201
202 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
203 manager.addSdxL2ConnectionPoint(SDXL2, one);
204 allExt.add(one.name());
205 allExtBySdxl2.add(one.name());
206 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
207 manager.addSdxL2ConnectionPoint(SDXL2, three);
208 allExt.add(three.name());
209 allExtBySdxl2.add(three.name());
210 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1);
211 manager.addSdxL2ConnectionPoint(SDXL2_2, six);
212 allExt.add(six.name());
Carolina Fernandezad893432016-07-18 11:11:34 +0200213 allExtBySdxl2Aux.add(six.name());
pierventre3849e562016-05-11 11:47:32 +0200214 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1);
215 manager.addSdxL2ConnectionPoint(SDXL2, seven);
216 allExt.add(seven.name());
217 allExtBySdxl2.add(seven.name());
218 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1);
219 manager.addSdxL2ConnectionPoint(SDXL2_2, nine);
220 allExt.add(nine.name());
Carolina Fernandezad893432016-07-18 11:11:34 +0200221 allExtBySdxl2Aux.add(nine.name());
pierventre3849e562016-05-11 11:47:32 +0200222 SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1);
223 manager.addSdxL2ConnectionPoint(SDXL2, ten);
224 allExt.add(ten.name());
225 allExtBySdxl2.add(ten.name());
226
227 Set<String> all = manager.getSdxL2ConnectionPoints(Optional.ofNullable(null));
228 Set<String> allBySdxl2 = manager.getSdxL2ConnectionPoints(Optional.of(SDXL2));
229 Set<String> allBySdxl22 = manager.getSdxL2ConnectionPoints(Optional.of(SDXL2_2));
230
231 assertEquals(allExt, all);
232 assertNotEquals(allExtBySdxl2, all);
Carolina Fernandezad893432016-07-18 11:11:34 +0200233 assertNotEquals(allExtBySdxl2Aux, all);
pierventre3849e562016-05-11 11:47:32 +0200234
235 assertNotEquals(allExt, allBySdxl2);
236 assertEquals(allExtBySdxl2, allBySdxl2);
Carolina Fernandezad893432016-07-18 11:11:34 +0200237 assertNotEquals(allExtBySdxl2Aux, allBySdxl2);
pierventre3849e562016-05-11 11:47:32 +0200238
239 assertNotEquals(allExt, allBySdxl22);
240 assertNotEquals(allExtBySdxl2, allBySdxl22);
Carolina Fernandezad893432016-07-18 11:11:34 +0200241 assertEquals(allExtBySdxl2Aux, allBySdxl22);
pierventre3849e562016-05-11 11:47:32 +0200242
243 }
244
245 @Test
Carolina Fernandezad893432016-07-18 11:11:34 +0200246 public void testRemoveSdxL2ConnectionPoint() {
pierventre3849e562016-05-11 11:47:32 +0200247
248 manager.createSdxL2(SDXL2);
249 manager.createSdxL2(SDXL2_2);
250
251 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
252 manager.addSdxL2ConnectionPoint(SDXL2, one);
253
254 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
255 manager.addSdxL2ConnectionPoint(SDXL2, three);
256
257 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1);
258 manager.addSdxL2ConnectionPoint(SDXL2_2, six);
259
260 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1);
261 manager.addSdxL2ConnectionPoint(SDXL2, seven);
262
263 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1);
264 manager.addSdxL2ConnectionPoint(SDXL2_2, nine);
265
266 SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1);
267 manager.addSdxL2ConnectionPoint(SDXL2, ten);
268
269 manager.removeSdxL2ConnectionPoint(one.name());
270 manager.removeSdxL2ConnectionPoint(six.name());
271 manager.removeSdxL2ConnectionPoint(one.name());
272 manager.removeSdxL2ConnectionPoint("ROM");
273
274 }
275
pierventre1483e642016-06-08 18:52:29 +0200276 @Test
Carolina Fernandezad893432016-07-18 11:11:34 +0200277 public void test2RemoveSdxL2s() {
278 manager.createSdxL2(SDXL2);
279 manager.createSdxL2(SDXL2_2);
280
281 Set<String> sdxL2CPs = Sets.newHashSet();
282 Set<String> sdxl2CPsAux = Sets.newHashSet();
283
284 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
285 sdxL2CPs.add(one.name());
286 manager.addSdxL2ConnectionPoint(SDXL2, one);
287
288 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
289 sdxL2CPs.add(three.name());
290 manager.addSdxL2ConnectionPoint(SDXL2, three);
291
292 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1);
293 sdxl2CPsAux.add(six.name());
294 manager.addSdxL2ConnectionPoint(SDXL2_2, six);
295
296 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1);
297 sdxL2CPs.add(seven.name());
298 manager.addSdxL2ConnectionPoint(SDXL2, seven);
299
300 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1);
301 sdxl2CPsAux.add(nine.name());
302 manager.addSdxL2ConnectionPoint(SDXL2_2, nine);
303
304 SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1);
305 sdxL2CPs.add(ten.name());
306 manager.addSdxL2ConnectionPoint(SDXL2, ten);
307
308 manager.deleteSdxL2(SDXL2);
309
310 assertEquals(sdxl2CPsAux, this.manager.getSdxL2ConnectionPoints(Optional.of(SDXL2_2)));
311 assertEquals(sdxl2CPsAux, this.manager.getSdxL2ConnectionPoints(Optional.ofNullable(null)));
312 manager.deleteSdxL2(SDXL2_2);
313
314 assertEquals(Collections.emptySet(), this.manager.getSdxL2ConnectionPoints(Optional.of(SDXL2)));
315 assertEquals(Collections.emptySet(), this.manager.getSdxL2ConnectionPoints(Optional.of(SDXL2_2)));
316
317 }
318
319 @Test
320 public void testGetSdxL2ConnectionPoint() {
pierventre1483e642016-06-08 18:52:29 +0200321
322 manager.createSdxL2(SDXL2);
323 manager.createSdxL2(SDXL2_2);
324
325 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
326 SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP2, VLANS1, CEMAC1);
327 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC1);
328 SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS1, CEMAC1);
329 SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS2, CEMAC1);
330 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC1);
331 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC1);
332 SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM4", CP3, VLANS4, CEMAC1);
333 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC1);
334 SdxL2ConnectionPoint ten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC1);
335 SdxL2ConnectionPoint eleven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI3", CP5, VLANS1, CEMAC1);
336 SdxL2ConnectionPoint twelve = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS1, CEMAC1);
337 SdxL2ConnectionPoint thirteen = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI31", CP5, VLANS8, CEMAC1);
338
339 manager.addSdxL2ConnectionPoint(SDXL2, one);
340 manager.addSdxL2ConnectionPoint(SDXL2, three);
341 manager.addSdxL2ConnectionPoint(SDXL2_2, six);
342 manager.addSdxL2ConnectionPoint(SDXL2, seven);
343 manager.addSdxL2ConnectionPoint(SDXL2_2, nine);
344 manager.addSdxL2ConnectionPoint(SDXL2, ten);
345
346 assertEquals(one, manager.getSdxL2ConnectionPoint(one.name()));
347 assertNotEquals(two, manager.getSdxL2ConnectionPoint(two.name()));
348 assertEquals(three, manager.getSdxL2ConnectionPoint(three.name()));
349 assertNotEquals(four, manager.getSdxL2ConnectionPoint(four.name()));
350 assertNotEquals(five, manager.getSdxL2ConnectionPoint(five.name()));
351 assertEquals(six, manager.getSdxL2ConnectionPoint(six.name()));
352 assertEquals(seven, manager.getSdxL2ConnectionPoint(seven.name()));
353 assertEquals(nine, manager.getSdxL2ConnectionPoint(nine.name()));
354 assertEquals(ten, manager.getSdxL2ConnectionPoint(ten.name()));
355
356 assertNotEquals(eight, manager.getSdxL2ConnectionPoint(eight.name()));
357 assertNotEquals(eleven, manager.getSdxL2ConnectionPoint(eleven.name()));
358 assertNotEquals(twelve, manager.getSdxL2ConnectionPoint(twelve.name()));
359 assertNotEquals(thirteen, manager.getSdxL2ConnectionPoint(thirteen.name()));
360
361 }
362
Carolina Fernandezad893432016-07-18 11:11:34 +0200363 @Test
364 public void testAddVCChecks() {
365
366 manager.createSdxL2(SDXL2);
367 manager.createSdxL2(SDXL2_2);
368
369 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
370 SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC2);
371 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC3);
372 SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC4);
373 SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC5);
374 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC6);
375 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI23", CP6, VLANS6, CEMAC7);
376 SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI24", CP7, VLANS5, CEMAC8);
377 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI25", CP8, VLANS5, CEMAC8);
378
379 manager.addSdxL2ConnectionPoint(SDXL2, one);
380 manager.addSdxL2ConnectionPoint(SDXL2, two);
381 manager.addSdxL2ConnectionPoint(SDXL2_2, three);
382 manager.addSdxL2ConnectionPoint(SDXL2, four);
383 manager.addSdxL2ConnectionPoint(SDXL2_2, five);
384 manager.addSdxL2ConnectionPoint(SDXL2, six);
385 manager.addSdxL2ConnectionPoint(SDXL2, seven);
386 manager.addSdxL2ConnectionPoint(SDXL2, eight);
387 manager.addSdxL2ConnectionPoint(SDXL2, nine);
388
389 manager.addVC(SDXL2, two.name(), six.name());
390 manager.addVC(SDXL2, seven.name(), nine.name());
391 manager.addVC(SDXL2, one.name(), two.name());
392 manager.addVC(SDXL2, one.name(), four.name());
393 manager.addVC(SDXL2, one.name(), six.name());
394 manager.addVC(SDXL2, two.name(), four.name());
395 manager.addVC(SDXL2, seven.name(), eight.name());
396
397 exceptionAddVC2.expect(IllegalStateException.class);
398 manager.addVC(SDXL2, four.name() + "x", five.name());
399 manager.addVC(SDXL2, one.name(), three.name());
400 manager.addVC(SDXL2, one.name(), five.name());
401 manager.addVC(SDXL2, two.name(), three.name());
402 manager.addVC(SDXL2, two.name(), five.name());
403 manager.addVC(SDXL2, three.name(), four.name());
404 manager.addVC(SDXL2, three.name(), five.name());
405 manager.addVC(SDXL2, three.name(), six.name());
406 manager.addVC(SDXL2, four.name(), five.name());
407 }
408
409 @Test
410 public void testRemoveVCChecks() {
411
412 manager.createSdxL2(SDXL2);
413 manager.createSdxL2(SDXL2_2);
414
415 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
416 SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC2);
417 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC3);
418 SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC4);
419 SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC5);
420 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC6);
421 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI23", CP6, VLANS6, CEMAC7);
422 SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI24", CP7, VLANS5, CEMAC8);
423 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI25", CP8, VLANS5, CEMAC8);
424
425 manager.addSdxL2ConnectionPoint(SDXL2, one);
426 manager.addSdxL2ConnectionPoint(SDXL2, two);
427 manager.addSdxL2ConnectionPoint(SDXL2_2, three);
428 manager.addSdxL2ConnectionPoint(SDXL2, four);
429 manager.addSdxL2ConnectionPoint(SDXL2_2, five);
430 manager.addSdxL2ConnectionPoint(SDXL2, six);
431 manager.addSdxL2ConnectionPoint(SDXL2, seven);
432 manager.addSdxL2ConnectionPoint(SDXL2, eight);
433 manager.addSdxL2ConnectionPoint(SDXL2, nine);
434
435 manager.addVC(SDXL2, two.name(), six.name());
436 manager.addVC(SDXL2, seven.name(), nine.name());
437
438 String vc;
439 vc = two.name().compareTo(six.name().toString()) < 0 ?
440 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), six.name()) :
441 format(SdxL2VCManager.NAME_FORMAT, SDXL2, six.name(), two.name());
442 manager.removeVC(vc);
443
444 vc = seven.name().compareTo(nine.name().toString()) < 0 ?
445 format(SdxL2VCManager.NAME_FORMAT, SDXL2, seven.name(), nine.name()) :
446 format(SdxL2VCManager.NAME_FORMAT, SDXL2, seven.name(), nine.name());
447 manager.removeVC(vc);
448
449 vc = one.name().compareTo(four.name().toString()) < 0 ?
450 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), four.name()) :
451 format(SdxL2VCManager.NAME_FORMAT, SDXL2, four.name(), one.name());
452 manager.removeVC(vc);
453 vc = one.name().compareTo(five.name().toString()) < 0 ?
454 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), five.name()) :
455 format(SdxL2VCManager.NAME_FORMAT, SDXL2, five.name(), one.name());
456 manager.removeVC(vc);
457 vc = one.name().compareTo(six.name().toString()) < 0 ?
458 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), six.name()) :
459 format(SdxL2VCManager.NAME_FORMAT, SDXL2, six.name(), one.name());
460 manager.removeVC(vc);
461 vc = two.name().compareTo(three.name().toString()) < 0 ?
462 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), three.name()) :
463 format(SdxL2VCManager.NAME_FORMAT, SDXL2, three.name(), two.name());
464 manager.removeVC(vc);
465 vc = two.name().compareTo(four.name().toString()) < 0 ?
466 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), four.name()) :
467 format(SdxL2VCManager.NAME_FORMAT, SDXL2, four.name(), two.name());
468 manager.removeVC(vc);
469 vc = two.name().compareTo(five.name().toString()) < 0 ?
470 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), five.name()) :
471 format(SdxL2VCManager.NAME_FORMAT, SDXL2, five.name(), two.name());
472 manager.removeVC(vc);
473 vc = three.name().compareTo(four.name().toString()) < 0 ?
474 format(SdxL2VCManager.NAME_FORMAT, SDXL2, three.name(), four.name()) :
475 format(SdxL2VCManager.NAME_FORMAT, SDXL2, four.name(), three.name());
476 manager.removeVC(vc);
477 vc = three.name().compareTo(five.name().toString()) < 0 ?
478 format(SdxL2VCManager.NAME_FORMAT, SDXL2, three.name(), five.name()) :
479 format(SdxL2VCManager.NAME_FORMAT, SDXL2, five.name(), three.name());
480 manager.removeVC(vc);
481 vc = three.name().compareTo(six.name().toString()) < 0 ?
482 format(SdxL2VCManager.NAME_FORMAT, SDXL2, three.name(), six.name()) :
483 format(SdxL2VCManager.NAME_FORMAT, SDXL2, six.name(), three.name());
484 manager.removeVC(vc);
485 vc = four.name().compareTo(five.name().toString()) < 0 ?
486 format(SdxL2VCManager.NAME_FORMAT, SDXL2, four.name(), five.name()) :
487 format(SdxL2VCManager.NAME_FORMAT, SDXL2, five.name(), four.name());
488 manager.removeVC(vc);
489 vc = seven.name().compareTo(eight.name().toString()) < 0 ?
490 format(SdxL2VCManager.NAME_FORMAT, SDXL2, seven.name(), eight.name()) :
491 format(SdxL2VCManager.NAME_FORMAT, SDXL2, eight.name(), seven.name());
492 manager.removeVC(vc);
493 vc = seven.name().compareTo(nine.name().toString()) < 0 ?
494 format(SdxL2VCManager.NAME_FORMAT, SDXL2_2, seven.name(), nine.name()) :
495 format(SdxL2VCManager.NAME_FORMAT, SDXL2, seven.name(), nine.name());
496 manager.removeVC(vc);
497 vc = seven.name().compareTo(nine.name().toString()) < 0 ?
498 format(SdxL2VCManager.NAME_FORMAT, SDXL2 + "x", seven.name(), nine.name()) :
499 format(SdxL2VCManager.NAME_FORMAT, SDXL2, seven.name(), nine.name());
500 manager.removeVC(vc);
501
502 exceptionRemoveVC1.expect(IllegalStateException.class);
503 vc = one.name().compareTo(three.name().toString()) < 0 ?
504 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), three.name()) :
505 format(SdxL2VCManager.NAME_FORMAT, SDXL2, three.name(), one.name());
506 manager.removeVC(vc);
507 manager.removeVC(":A");
508 manager.removeVC("A:B");
509
510 vc = four.name().compareTo(five.name().toString()) < 0 ?
511 format(SdxL2VCManager.NAME_FORMAT, SDXL2, four.name() + "x", five.name()) :
512 format(SdxL2VCManager.NAME_FORMAT, SDXL2, five.name(), four.name() + "x");
513 manager.removeVC(vc);
514
515 vc = one.name().compareTo(two.name().toString()) < 0 ?
516 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), two.name()) :
517 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), one.name());
518 manager.removeVC(vc);
519 }
520
521 @Test
522 public void testSdxL2NameChecks() {
523 String sdxL2 = "";
524 String sdxL2Aux = "test3,4";
525
526 exceptionSdxL2Name.expect(NullPointerException.class);
527 exceptionSdxL2Name.expectMessage("name cannot be null");
528 manager.createSdxL2(null);
529
530 manager.createSdxL2(sdxL2);
531
532 exceptionSdxL2Name.expect(IllegalStateException.class);
533 exceptionSdxL2Name.expectMessage("names cannot contain commas");
534 manager.createSdxL2(sdxL2Aux);
535 }
536
537 @Test
538 public void testDeleteSdxL2NameChecks() {
539 String sdxL2 = "";
540 exceptionDelSdxL2Name.expect(NullPointerException.class);
541 exceptionDelSdxL2Name.expectMessage("name cannot be null");
542 manager.deleteSdxL2(null);
543 manager.createSdxL2(sdxL2);
544 manager.deleteSdxL2(sdxL2);
545 }
546
547 @Test
548 public void testGetVC() {
549 manager.createSdxL2(SDXL2);
550 manager.createSdxL2(SDXL2_2);
551
552 SdxL2ConnectionPoint one = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM1", CP1, VLANS1, CEMAC1);
553 SdxL2ConnectionPoint two = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM2", CP2, VLANS2, CEMAC2);
554 SdxL2ConnectionPoint three = SdxL2ConnectionPoint.sdxl2ConnectionPoint("ROM3", CP1, VLANS7, CEMAC3);
555 SdxL2ConnectionPoint four = SdxL2ConnectionPoint.sdxl2ConnectionPoint("MI3", CP3, VLANS3, CEMAC4);
556 SdxL2ConnectionPoint five = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI1", CP4, VLANS8, CEMAC5);
557 SdxL2ConnectionPoint six = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI2", CP5, VLANS2, CEMAC6);
558 SdxL2ConnectionPoint seven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI23", CP6, VLANS6, CEMAC7);
559 SdxL2ConnectionPoint eight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI24", CP7, VLANS5, CEMAC8);
560 SdxL2ConnectionPoint nine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("FI25", CP8, VLANS5, CEMAC8);
561
562 String vc;
563 VirtualCircuit expectedVC;
564 VirtualCircuit actualVC;
565
566 manager.addSdxL2ConnectionPoint(SDXL2, one);
567 manager.addSdxL2ConnectionPoint(SDXL2, two);
568 manager.addSdxL2ConnectionPoint(SDXL2_2, three);
569 manager.addSdxL2ConnectionPoint(SDXL2, four);
570 manager.addSdxL2ConnectionPoint(SDXL2_2, five);
571 manager.addSdxL2ConnectionPoint(SDXL2, six);
572 manager.addSdxL2ConnectionPoint(SDXL2, seven);
573 manager.addSdxL2ConnectionPoint(SDXL2, eight);
574 manager.addSdxL2ConnectionPoint(SDXL2, nine);
575
576 // VC created using the manager, check against manually generates
577 manager.addVC(SDXL2, two.name(), six.name());
578 vc = two.name().compareTo(six.name().toString()) < 0 ?
579 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), six.name()) :
580 format(SdxL2VCManager.NAME_FORMAT, SDXL2, six.name(), two.name());
581 expectedVC = new VirtualCircuit(two, six);
582 actualVC = manager.getVirtualCircuit(vc);
583 assertEquals(expectedVC, actualVC);
584
585 // VC not created, check that getVC returns null if VC does not exist
586 vc = one.name().compareTo(two.name().toString()) < 0 ?
587 format(SdxL2VCManager.NAME_FORMAT, SDXL2, one.name(), two.name()) :
588 format(SdxL2VCManager.NAME_FORMAT, SDXL2, two.name(), one.name());
589 expectedVC = new VirtualCircuit(one, two);
590 actualVC = manager.getVirtualCircuit(vc);
591 assertNotEquals(expectedVC, actualVC);
592 assertNull(actualVC);
593
594 // Testing illegal character
595 exceptionGetVC2.expect(IllegalStateException.class);
596 manager.getVirtualCircuit(":A");
597 manager.getVirtualCircuit("A:B");
598 }
Pier Luigi Ventre0a023f42016-04-30 11:03:15 +0200599}