chidambar babu
Committed by Gerrit Code Review

ONOS-4086 to ONOS-4091, ONOS-4098 to ONOS-4100:JUNIT for ISIS controller

Change-Id: If3501a55fcbf994cd69facfd97f43b4a4f0f7812
Showing 17 changed files with 1364 additions and 9 deletions
...@@ -45,7 +45,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -45,7 +45,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
45 private String neighborSystemId; 45 private String neighborSystemId;
46 private Ip4Address interfaceIp; 46 private Ip4Address interfaceIp;
47 private MacAddress neighborMacAddress; 47 private MacAddress neighborMacAddress;
48 - private int holdingTime; 48 + private volatile int holdingTime;
49 + private int neighborDownInterval;
49 private IsisRouterType routerType; 50 private IsisRouterType routerType;
50 private String l1LanId; 51 private String l1LanId;
51 private String l2LanId; 52 private String l2LanId;
...@@ -54,6 +55,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -54,6 +55,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
54 private IsisInterfaceState neighborState = IsisInterfaceState.INITIAL; 55 private IsisInterfaceState neighborState = IsisInterfaceState.INITIAL;
55 private InternalInactivityTimeCheck inActivityTimeCheckTask; 56 private InternalInactivityTimeCheck inActivityTimeCheckTask;
56 private ScheduledExecutorService exServiceInActivity; 57 private ScheduledExecutorService exServiceInActivity;
58 + private InternalHoldingTimeCheck holdingTimeCheckTask;
59 + private ScheduledExecutorService exServiceHoldingTimeCheck;
57 private boolean inActivityTimerScheduled = false; 60 private boolean inActivityTimerScheduled = false;
58 private IsisInterface isisInterface; 61 private IsisInterface isisInterface;
59 62
...@@ -72,6 +75,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -72,6 +75,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
72 this.interfaceIp = (helloMessage.interfaceIpAddresses() != null) ? 75 this.interfaceIp = (helloMessage.interfaceIpAddresses() != null) ?
73 interfaceIpAddresses.get(0) : IsisConstants.DEFAULTIP; 76 interfaceIpAddresses.get(0) : IsisConstants.DEFAULTIP;
74 this.holdingTime = helloMessage.holdingTime(); 77 this.holdingTime = helloMessage.holdingTime();
78 + neighborDownInterval = holdingTime;
75 this.routerType = IsisRouterType.get(helloMessage.circuitType()); 79 this.routerType = IsisRouterType.get(helloMessage.circuitType());
76 if (helloMessage instanceof L1L2HelloPdu) { 80 if (helloMessage instanceof L1L2HelloPdu) {
77 if (IsisPduType.L1HELLOPDU == helloMessage.isisPduType()) { 81 if (IsisPduType.L1HELLOPDU == helloMessage.isisPduType()) {
...@@ -83,6 +87,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -83,6 +87,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
83 this.localCircuitId = ((P2PHelloPdu) helloMessage).localCircuitId(); 87 this.localCircuitId = ((P2PHelloPdu) helloMessage).localCircuitId();
84 } 88 }
85 this.isisInterface = isisInterface; 89 this.isisInterface = isisInterface;
90 + startHoldingTimeCheck();
86 } 91 }
87 92
88 /** 93 /**
...@@ -244,7 +249,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -244,7 +249,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
244 * @param l2LanId L2 lan ID 249 * @param l2LanId L2 lan ID
245 */ 250 */
246 public void setL2LanId(String l2LanId) { 251 public void setL2LanId(String l2LanId) {
247 - this.l1LanId = l1LanId; 252 + this.l2LanId = l2LanId;
248 } 253 }
249 254
250 /** 255 /**
...@@ -293,6 +298,25 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -293,6 +298,25 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
293 } 298 }
294 299
295 /** 300 /**
301 + * Starts the holding time check timer.
302 + */
303 + public void startHoldingTimeCheck() {
304 + log.debug("IsisNeighbor::startHoldingTimeCheck");
305 + holdingTimeCheckTask = new InternalHoldingTimeCheck();
306 + exServiceHoldingTimeCheck = Executors.newSingleThreadScheduledExecutor();
307 + exServiceHoldingTimeCheck.scheduleAtFixedRate(holdingTimeCheckTask, 1,
308 + 1, TimeUnit.SECONDS);
309 + }
310 +
311 + /**
312 + * Stops the holding time check timer.
313 + */
314 + public void stopHoldingTimeCheck() {
315 + log.debug("IsisNeighbor::stopHoldingTimeCheck ");
316 + exServiceHoldingTimeCheck.shutdown();
317 + }
318 +
319 + /**
296 * Starts the inactivity timer. 320 * Starts the inactivity timer.
297 */ 321 */
298 public void startInactivityTimeCheck() { 322 public void startInactivityTimeCheck() {
...@@ -300,8 +324,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -300,8 +324,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
300 log.debug("IsisNeighbor::startInactivityTimeCheck"); 324 log.debug("IsisNeighbor::startInactivityTimeCheck");
301 inActivityTimeCheckTask = new InternalInactivityTimeCheck(); 325 inActivityTimeCheckTask = new InternalInactivityTimeCheck();
302 exServiceInActivity = Executors.newSingleThreadScheduledExecutor(); 326 exServiceInActivity = Executors.newSingleThreadScheduledExecutor();
303 - exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, holdingTime, 327 + exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, neighborDownInterval,
304 - holdingTime, TimeUnit.SECONDS); 328 + neighborDownInterval, TimeUnit.SECONDS);
305 inActivityTimerScheduled = true; 329 inActivityTimerScheduled = true;
306 } 330 }
307 } 331 }
...@@ -328,6 +352,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -328,6 +352,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
328 isisInterface.setL2LanId(IsisConstants.DEFAULTLANID); 352 isisInterface.setL2LanId(IsisConstants.DEFAULTLANID);
329 353
330 neighborState = IsisInterfaceState.DOWN; 354 neighborState = IsisInterfaceState.DOWN;
355 + stopInactivityTimeCheck();
356 + stopHoldingTimeCheck();
331 isisInterface.removeNeighbor(this); 357 isisInterface.removeNeighbor(this);
332 } 358 }
333 359
...@@ -347,4 +373,20 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -347,4 +373,20 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
347 neighborDown(); 373 neighborDown();
348 } 374 }
349 } 375 }
376 +
377 + /**
378 + * Represents a Task which will decrement holding time for this neighbor.
379 + */
380 + private class InternalHoldingTimeCheck implements Runnable {
381 + /**
382 + * Creates an instance.
383 + */
384 + InternalHoldingTimeCheck() {
385 + }
386 +
387 + @Override
388 + public void run() {
389 + holdingTime--;
390 + }
391 + }
350 } 392 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.isis.controller.impl.lsdb; 16 package org.onosproject.isis.controller.impl.lsdb;
17 17
18 +import org.jboss.netty.buffer.ChannelBuffers;
18 import org.onosproject.isis.controller.IsisInterface; 19 import org.onosproject.isis.controller.IsisInterface;
19 import org.onosproject.isis.controller.IsisLsdb; 20 import org.onosproject.isis.controller.IsisLsdb;
20 import org.onosproject.isis.controller.IsisLsdbAge; 21 import org.onosproject.isis.controller.IsisLsdbAge;
...@@ -24,6 +25,7 @@ import org.onosproject.isis.controller.IsisPduType; ...@@ -24,6 +25,7 @@ import org.onosproject.isis.controller.IsisPduType;
24 import org.onosproject.isis.controller.LspWrapper; 25 import org.onosproject.isis.controller.LspWrapper;
25 import org.onosproject.isis.io.isispacket.pdu.LsPdu; 26 import org.onosproject.isis.io.isispacket.pdu.LsPdu;
26 import org.onosproject.isis.io.util.IsisConstants; 27 import org.onosproject.isis.io.util.IsisConstants;
28 +import org.onosproject.isis.io.util.IsisUtil;
27 import org.slf4j.Logger; 29 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory; 30 import org.slf4j.LoggerFactory;
29 31
...@@ -41,6 +43,9 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -41,6 +43,9 @@ public class DefaultIsisLsdb implements IsisLsdb {
41 private Map<String, LspWrapper> isisL1Db = new ConcurrentHashMap<>(); 43 private Map<String, LspWrapper> isisL1Db = new ConcurrentHashMap<>();
42 private Map<String, LspWrapper> isisL2Db = new ConcurrentHashMap<>(); 44 private Map<String, LspWrapper> isisL2Db = new ConcurrentHashMap<>();
43 private IsisLsdbAge lsdbAge = null; 45 private IsisLsdbAge lsdbAge = null;
46 +
47 +
48 +
44 private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 49 private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
45 private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 50 private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
46 51
...@@ -59,6 +64,23 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -59,6 +64,23 @@ public class DefaultIsisLsdb implements IsisLsdb {
59 } 64 }
60 65
61 /** 66 /**
67 + * Sets the level 1 link state sequence number.
68 + *
69 + * @param l1LspSeqNo link state sequence number
70 + */
71 + public void setL1LspSeqNo(int l1LspSeqNo) {
72 + this.l1LspSeqNo = l1LspSeqNo;
73 + }
74 +
75 + /**
76 + * Sets the level 2 link state sequence number.
77 + *
78 + * @param l2LspSeqNo link state sequence number
79 + */
80 + public void setL2LspSeqNo(int l2LspSeqNo) {
81 + this.l2LspSeqNo = l2LspSeqNo;
82 + }
83 + /**
62 * Returns the LSDB LSP key. 84 * Returns the LSDB LSP key.
63 * 85 *
64 * @param systemId system ID 86 * @param systemId system ID
...@@ -108,7 +130,7 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -108,7 +130,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
108 * @return List of LSPs 130 * @return List of LSPs
109 */ 131 */
110 public List<LspWrapper> allLspHeaders(boolean excludeMaxAgeLsp) { 132 public List<LspWrapper> allLspHeaders(boolean excludeMaxAgeLsp) {
111 - List<LspWrapper> summaryList = new CopyOnWriteArrayList(); 133 + List<LspWrapper> summaryList = new CopyOnWriteArrayList<>();
112 addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL1Db); 134 addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL1Db);
113 addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL2Db); 135 addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL2Db);
114 136
...@@ -187,9 +209,17 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -187,9 +209,17 @@ public class DefaultIsisLsdb implements IsisLsdb {
187 */ 209 */
188 public boolean addLsp(IsisMessage isisMessage, boolean isSelfOriginated, IsisInterface isisInterface) { 210 public boolean addLsp(IsisMessage isisMessage, boolean isSelfOriginated, IsisInterface isisInterface) {
189 LsPdu lspdu = (LsPdu) isisMessage; 211 LsPdu lspdu = (LsPdu) isisMessage;
212 + if (isSelfOriginated) {
213 + //Add length and checksum
214 + byte[] lspBytes = lspdu.asBytes();
215 + lspdu.setPduLength(lspBytes.length);
216 + lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
217 + IsisConstants.CHECKSUMPOSITION + 1);
218 + byte[] checkSum = {lspBytes[IsisConstants.CHECKSUMPOSITION], lspBytes[IsisConstants.CHECKSUMPOSITION + 1]};
219 + lspdu.setCheckSum(ChannelBuffers.copiedBuffer(checkSum).readUnsignedShort());
220 + }
190 DefaultLspWrapper lspWrapper = new DefaultLspWrapper(); 221 DefaultLspWrapper lspWrapper = new DefaultLspWrapper();
191 lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime()); 222 lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime());
192 - lspWrapper.setRemainingLifetime(IsisConstants.LSPMAXAGE - lsdbAge.ageCounter());
193 lspWrapper.setLspType(IsisPduType.get(lspdu.pduType())); 223 lspWrapper.setLspType(IsisPduType.get(lspdu.pduType()));
194 lspWrapper.setLsPdu(lspdu); 224 lspWrapper.setLsPdu(lspdu);
195 lspWrapper.setAgeCounterWhenReceived(lsdbAge.ageCounter()); 225 lspWrapper.setAgeCounterWhenReceived(lsdbAge.ageCounter());
...@@ -198,7 +228,6 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -198,7 +228,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
198 lspWrapper.setIsisInterface(isisInterface); 228 lspWrapper.setIsisInterface(isisInterface);
199 lspWrapper.setLsdbAge(lsdbAge); 229 lspWrapper.setLsdbAge(lsdbAge);
200 addLsp(lspWrapper, lspdu.lspId()); 230 addLsp(lspWrapper, lspdu.lspId());
201 -
202 log.debug("Added LSp In LSDB: {}", lspWrapper); 231 log.debug("Added LSp In LSDB: {}", lspWrapper);
203 232
204 return true; 233 return true;
...@@ -217,9 +246,11 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -217,9 +246,11 @@ public class DefaultIsisLsdb implements IsisLsdb {
217 246
218 switch (lspWrapper.lsPdu().isisPduType()) { 247 switch (lspWrapper.lsPdu().isisPduType()) {
219 case L1LSPDU: 248 case L1LSPDU:
249 + isisL1Db.remove(key);
220 isisL1Db.put(key, lspWrapper); 250 isisL1Db.put(key, lspWrapper);
221 break; 251 break;
222 case L2LSPDU: 252 case L2LSPDU:
253 + isisL2Db.remove(key);
223 isisL2Db.put(key, lspWrapper); 254 isisL2Db.put(key, lspWrapper);
224 break; 255 break;
225 default: 256 default:
...@@ -228,7 +259,7 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -228,7 +259,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
228 } 259 }
229 260
230 //add it to bin 261 //add it to bin
231 - Integer binNumber = lsdbAge.age2Bin(IsisConstants.LSPMAXAGE - lspWrapper.remainingLifetime()); 262 + Integer binNumber = lsdbAge.age2Bin(IsisConstants.LSPMAXAGE - lspWrapper.lspAgeReceived());
232 IsisLspBin lspBin = lsdbAge.getLspBin(binNumber); 263 IsisLspBin lspBin = lsdbAge.getLspBin(binNumber);
233 if (lspBin != null) { 264 if (lspBin != null) {
234 //remove from existing 265 //remove from existing
...@@ -264,7 +295,8 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -264,7 +295,8 @@ public class DefaultIsisLsdb implements IsisLsdb {
264 public String isNewerOrSameLsp(IsisMessage lsp1, IsisMessage lsp2) { 295 public String isNewerOrSameLsp(IsisMessage lsp1, IsisMessage lsp2) {
265 LsPdu receivedLsp = (LsPdu) lsp1; 296 LsPdu receivedLsp = (LsPdu) lsp1;
266 LsPdu lspFromDb = (LsPdu) lsp2; 297 LsPdu lspFromDb = (LsPdu) lsp2;
267 - if (receivedLsp.sequenceNumber() > lspFromDb.sequenceNumber()) { 298 + if (receivedLsp.sequenceNumber() > lspFromDb.sequenceNumber() ||
299 + receivedLsp.checkSum() != lspFromDb.checkSum()) {
268 return "latest"; 300 return "latest";
269 } else if (receivedLsp.sequenceNumber() < lspFromDb.sequenceNumber()) { 301 } else if (receivedLsp.sequenceNumber() < lspFromDb.sequenceNumber()) {
270 return "old"; 302 return "old";
......
1 +/*
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 +
17 +package org.onosproject.isis.controller.impl;
18 +
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +
23 +import static org.hamcrest.CoreMatchers.is;
24 +import static org.hamcrest.CoreMatchers.notNullValue;
25 +import static org.junit.Assert.assertThat;
26 +
27 +/**
28 + * Unit test class for ControllerTest.
29 + */
30 +public class ControllerTest {
31 +
32 + private Controller controller;
33 +
34 + @Before
35 + public void setUp() throws Exception {
36 + controller = new Controller();
37 + }
38 +
39 + @After
40 + public void tearDown() throws Exception {
41 + controller = null;
42 + }
43 +
44 + /**
45 + * Tests isisDeactivate() method.
46 + */
47 + @Test(expected = Exception.class)
48 + public void testIsisDeactivate() throws Exception {
49 + controller.isisDeactivate();
50 + assertThat(controller, is(notNullValue()));
51 + }
52 +
53 + /**
54 + * Tests getAllConfiguredProcesses() method.
55 + */
56 + @Test
57 + public void testGetAllConfiguredProcesses() throws Exception {
58 + controller.getAllConfiguredProcesses();
59 + assertThat(controller, is(notNullValue()));
60 + }
61 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +
22 +import static org.hamcrest.CoreMatchers.is;
23 +import static org.hamcrest.CoreMatchers.notNullValue;
24 +import static org.junit.Assert.assertThat;
25 +
26 +/**
27 + * Unit test case for DefaultIsisController.
28 + */
29 +public class DefaultIsisControllerTest {
30 + private DefaultIsisController defaultIsisController;
31 +
32 + @Before
33 + public void setUp() throws Exception {
34 + defaultIsisController = new DefaultIsisController();
35 + }
36 +
37 + @After
38 + public void tearDown() throws Exception {
39 + defaultIsisController = null;
40 + }
41 +
42 + /**
43 + * Tests activate() method.
44 + */
45 + @Test
46 + public void testActivate() throws Exception {
47 + defaultIsisController.activate();
48 + assertThat(defaultIsisController, is(notNullValue()));
49 + }
50 +
51 + /**
52 + * Tests deactivate() method.
53 + */
54 + @Test(expected = Exception.class)
55 + public void testDeactivate() throws Exception {
56 + defaultIsisController.activate();
57 + defaultIsisController.deactivate();
58 + assertThat(defaultIsisController, is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests allConfiguredProcesses() method.
63 + */
64 + @Test
65 + public void testAllConfiguredProcesses() throws Exception {
66 + defaultIsisController.allConfiguredProcesses();
67 + assertThat(defaultIsisController, is(notNullValue()));
68 + }
69 +}
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import org.easymock.EasyMock;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.isis.controller.IsisInterface;
23 +import org.onosproject.isis.controller.IsisProcess;
24 +
25 +import java.util.List;
26 +
27 +import static org.hamcrest.CoreMatchers.is;
28 +import static org.hamcrest.CoreMatchers.nullValue;
29 +import static org.junit.Assert.assertThat;
30 +
31 +/**
32 + * Unit test class for DefaultIsisProcess.
33 + */
34 +public class DefaultIsisProcessTest {
35 +
36 + private final String processId = "1";
37 + private IsisProcess isisProcess;
38 + private String result;
39 + private IsisInterface isisInterface;
40 + private List<IsisInterface> isisInterfaceList;
41 + private List<IsisInterface> result1;
42 +
43 + @Before
44 + public void setUp() throws Exception {
45 + isisProcess = new DefaultIsisProcess();
46 + isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class);
47 + }
48 +
49 + @After
50 + public void tearDown() throws Exception {
51 + isisProcess = null;
52 + }
53 +
54 + /**
55 + * Tests processId() setter method.
56 + */
57 + @Test
58 + public void testProcessId() throws Exception {
59 + isisProcess.setProcessId(processId);
60 + result = isisProcess.processId();
61 + assertThat(result, is(processId));
62 + }
63 +
64 + /**
65 + * Tests processId() getter method.
66 + */
67 + @Test
68 + public void testSetProcessId() throws Exception {
69 + isisProcess.setProcessId(processId);
70 + result = isisProcess.processId();
71 + assertThat(result, is(processId));
72 + }
73 +
74 + /**
75 + * Tests isisInterfaceList() setter method.
76 + */
77 + @Test
78 + public void testIsisInterfaceList() throws Exception {
79 + isisProcess.setIsisInterfaceList(isisInterfaceList);
80 + result1 = isisProcess.isisInterfaceList();
81 + assertThat(result1, is(nullValue()));
82 + }
83 +
84 + /**
85 + * Tests isisInterfaceList() getter method.
86 + */
87 + @Test
88 + public void testSetIsisInterfaceList() throws Exception {
89 + isisProcess.setIsisInterfaceList(isisInterfaceList);
90 + result1 = isisProcess.isisInterfaceList();
91 + assertThat(result1, is(nullValue()));
92 + }
93 +}
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.channel.ChannelHandlerContext;
20 +import org.jboss.netty.channel.ChannelStateEvent;
21 +import org.jboss.netty.channel.ExceptionEvent;
22 +import org.jboss.netty.channel.MessageEvent;
23 +import org.junit.After;
24 +import org.junit.Before;
25 +import org.junit.Test;
26 +import org.onosproject.isis.controller.IsisMessage;
27 +import org.onosproject.isis.controller.IsisProcess;
28 +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
29 +
30 +import java.util.List;
31 +
32 +import static org.hamcrest.CoreMatchers.is;
33 +import static org.hamcrest.CoreMatchers.notNullValue;
34 +import static org.junit.Assert.assertThat;
35 +
36 +/**
37 + * Unit test class for IsisChannelHandler.
38 + */
39 +public class IsisChannelHandlerTest {
40 +
41 + private final String processId = "1";
42 + private final byte[] config = {0, 0, 0, 0, 0, 0, 0};
43 + private IsisChannelHandler isisChannelHandler;
44 + private Controller controller;
45 + private IsisProcess isisProcess;
46 + private List<IsisProcess> isisProcessList;
47 + private ChannelHandlerContext channelHandlerContext;
48 + private ChannelStateEvent channelStateEvent;
49 + private ExceptionEvent exceptionEvent;
50 + private MessageEvent messageEvent;
51 + private IsisMessage isisMessage;
52 +
53 + @Before
54 + public void setUp() throws Exception {
55 + controller = EasyMock.createNiceMock(Controller.class);
56 + isisProcess = EasyMock.createNiceMock(IsisProcess.class);
57 + channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
58 + channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
59 + exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
60 + messageEvent = EasyMock.createNiceMock(MessageEvent.class);
61 + isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
62 + isisMessage.setInterfaceIndex(2);
63 + isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
64 + }
65 +
66 + @After
67 + public void tearDown() throws Exception {
68 + isisChannelHandler = null;
69 + }
70 +
71 + /**
72 + * Tests initializeInterfaceMap() method.
73 + */
74 + @Test(expected = Exception.class)
75 + public void testInitializeInterfaceMap() throws Exception {
76 + isisChannelHandler.initializeInterfaceMap();
77 + assertThat(isisChannelHandler, is(notNullValue()));
78 + }
79 +
80 + /**
81 + * Tests updateInterfaceMap() method.
82 + */
83 + @Test(expected = Exception.class)
84 + public void testUpdateInterfaceMap() throws Exception {
85 + isisChannelHandler.updateInterfaceMap(isisProcessList);
86 + assertThat(isisChannelHandler, is(notNullValue()));
87 + }
88 +
89 + /**
90 + * Tests initializeInterfaceIpList() method.
91 + */
92 + @Test(expected = Exception.class)
93 + public void testInitializeInterfaceIpList() throws Exception {
94 + isisChannelHandler.initializeInterfaceIpList();
95 + assertThat(isisChannelHandler, is(notNullValue()));
96 + }
97 +
98 + /**
99 + * Tests channelConnected() method.
100 + */
101 + @Test(expected = Exception.class)
102 + public void testChannelConnected() throws Exception {
103 + isisChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
104 + assertThat(isisChannelHandler, is(notNullValue()));
105 + }
106 +
107 + /**
108 + * Tests channelDisconnected() method.
109 + */
110 + @Test
111 + public void testChannelDisconnected() throws Exception {
112 + isisChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent);
113 + assertThat(isisChannelHandler, is(notNullValue()));
114 + }
115 +
116 + /**
117 + * Tests exceptionCaught() method.
118 + */
119 + @Test(expected = Exception.class)
120 + public void testExceptionCaught() throws Exception {
121 + isisChannelHandler.exceptionCaught(channelHandlerContext, exceptionEvent);
122 + assertThat(isisChannelHandler, is(notNullValue()));
123 + }
124 +
125 + /**
126 + * Tests messageReceived() method.
127 + */
128 + @Test
129 + public void testMessageReceived() throws Exception {
130 + isisChannelHandler.messageReceived(channelHandlerContext, messageEvent);
131 + assertThat(isisChannelHandler, is(notNullValue()));
132 + }
133 +
134 + /**
135 + * Tests processIsisMessage() method.
136 + */
137 + @Test(expected = Exception.class)
138 + public void testProcessIsisMessage() throws Exception {
139 + isisChannelHandler.processIsisMessage(isisMessage, channelHandlerContext);
140 + assertThat(isisChannelHandler, is(notNullValue()));
141 + }
142 +
143 + /**
144 + * Tests startHelloSender() method.
145 + */
146 + @Test
147 + public void testStartHelloSender() throws Exception {
148 + isisChannelHandler.startHelloSender();
149 + assertThat(isisChannelHandler, is(notNullValue()));
150 + }
151 +
152 + /**
153 + * Tests stopHelloSender() method.
154 + */
155 + @Test
156 + public void testStopHelloSender() throws Exception {
157 + isisChannelHandler.stopHelloSender();
158 + assertThat(isisChannelHandler, is(notNullValue()));
159 + }
160 +
161 + /**
162 + * Tests sentConfigPacket() method.
163 + */
164 + @Test
165 + public void testSentConfigPacket() throws Exception {
166 + isisChannelHandler.sentConfigPacket(config);
167 + assertThat(isisChannelHandler, is(notNullValue()));
168 + }
169 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.channel.Channel;
20 +import org.junit.After;
21 +import org.junit.Before;
22 +import org.junit.Test;
23 +import org.onlab.packet.Ip4Address;
24 +import org.onosproject.isis.controller.IsisNetworkType;
25 +
26 +import static org.hamcrest.CoreMatchers.is;
27 +import static org.hamcrest.CoreMatchers.notNullValue;
28 +import static org.junit.Assert.assertThat;
29 +
30 +/**
31 + * Unit test class for IsisHelloPduSender.
32 + */
33 +public class IsisHelloPduSenderTest {
34 + private final String systemId = "1234.1234.1234";
35 + private final String areaId = "490001";
36 + private final String circuitId = "0";
37 + private final String lanId = "0000.0000.0000.00";
38 + private Channel channel;
39 + private DefaultIsisInterface isisInterface;
40 + private DefaultIsisInterface isisInterface1;
41 + private IsisHelloPduSender isisHelloPduSender;
42 + private IsisHelloPduSender isisHelloPduSender1;
43 + private Ip4Address interfaceAddress = Ip4Address.valueOf("10.10.10.10");
44 +
45 + @Before
46 + public void setUp() throws Exception {
47 + channel = EasyMock.createNiceMock(Channel.class);
48 + isisInterface = new DefaultIsisInterface();
49 + isisInterface1 = new DefaultIsisInterface();
50 + }
51 +
52 + @After
53 + public void tearDown() throws Exception {
54 + channel = null;
55 + isisInterface = null;
56 + }
57 +
58 + /**
59 + * Tests run() method.
60 + */
61 + @Test
62 + public void testRun() throws Exception {
63 + isisInterface.setNetworkType(IsisNetworkType.P2P);
64 + isisInterface.setCircuitId(circuitId);
65 + isisInterface.setSystemId(systemId);
66 + isisInterface.setAreaAddress("490001");
67 + isisInterface.setInterfaceIpAddress(interfaceAddress);
68 + isisHelloPduSender = new IsisHelloPduSender(channel, isisInterface);
69 + isisHelloPduSender.run();
70 + assertThat(isisHelloPduSender, is(notNullValue()));
71 +
72 + isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
73 + isisInterface1.setCircuitId(circuitId);
74 + isisInterface1.setSystemId(systemId);
75 + isisInterface1.setAreaAddress(areaId);
76 + isisInterface1.setInterfaceIpAddress(interfaceAddress);
77 + isisInterface1.setReservedPacketCircuitType(1);
78 + isisInterface1.setL1LanId(lanId);
79 + isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
80 + isisHelloPduSender1.run();
81 + assertThat(isisHelloPduSender1, is(notNullValue()));
82 +
83 + isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
84 + isisInterface1.setCircuitId(circuitId);
85 + isisInterface1.setSystemId(systemId);
86 + isisInterface1.setAreaAddress(areaId);
87 + isisInterface1.setInterfaceIpAddress(interfaceAddress);
88 + isisInterface1.setReservedPacketCircuitType(2);
89 + isisInterface1.setL2LanId(lanId);
90 + isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
91 + isisHelloPduSender1.run();
92 + assertThat(isisHelloPduSender1, is(notNullValue()));
93 +
94 + isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
95 + isisInterface1.setCircuitId(circuitId);
96 + isisInterface1.setSystemId(systemId);
97 + isisInterface1.setAreaAddress(areaId);
98 + isisInterface1.setInterfaceIpAddress(interfaceAddress);
99 + isisInterface1.setReservedPacketCircuitType(3);
100 + isisInterface1.setL1LanId(lanId);
101 + isisInterface1.setL2LanId(lanId);
102 + isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
103 + isisHelloPduSender1.run();
104 + assertThat(isisHelloPduSender1, is(notNullValue()));
105 + }
106 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onosproject.isis.controller.impl;
2 +
3 +import com.google.common.primitives.Bytes;
4 +import org.easymock.EasyMock;
5 +import org.jboss.netty.buffer.ChannelBuffer;
6 +import org.jboss.netty.buffer.ChannelBuffers;
7 +import org.jboss.netty.channel.Channel;
8 +import org.jboss.netty.channel.ChannelHandlerContext;
9 +import org.junit.After;
10 +import org.junit.Before;
11 +import org.junit.Test;
12 +import org.onosproject.isis.io.util.IsisUtil;
13 +
14 +import java.net.InetSocketAddress;
15 +import java.net.SocketAddress;
16 +
17 +import static org.hamcrest.CoreMatchers.is;
18 +import static org.hamcrest.CoreMatchers.nullValue;
19 +import static org.hamcrest.MatcherAssert.assertThat;
20 +
21 +/**
22 + * Unit test class for IsisMessageDecoder.
23 + */
24 +public class IsisMessageDecoderTest {
25 +
26 + private final byte[] hello = {
27 + -125, 20, 1, 0, 17, 1, 0, 0,
28 + 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
29 + 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
30 + };
31 + private final String id = "127.0.0.1";
32 + private IsisMessageDecoder isisMessageDecoder;
33 + private ChannelHandlerContext ctx;
34 + private Channel channel;
35 + private SocketAddress socketAddress;
36 + private ChannelBuffer channelBuffer;
37 +
38 + @Before
39 + public void setUp() throws Exception {
40 + isisMessageDecoder = new IsisMessageDecoder();
41 + }
42 +
43 + @After
44 + public void tearDown() throws Exception {
45 + isisMessageDecoder = null;
46 + }
47 +
48 + @Test
49 + public void testDecode() throws Exception {
50 + channel = EasyMock.createMock(Channel.class);
51 + socketAddress = InetSocketAddress.createUnresolved(id, 7000);
52 + byte[] array = IsisUtil.getPaddingTlvs(hello.length);
53 + channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
54 + assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
55 + }
56 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import com.google.common.primitives.Bytes;
19 +import org.easymock.EasyMock;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.jboss.netty.buffer.ChannelBuffers;
22 +import org.jboss.netty.channel.Channel;
23 +import org.jboss.netty.channel.ChannelHandlerContext;
24 +import org.junit.After;
25 +import org.junit.Before;
26 +import org.junit.Test;
27 +import org.onosproject.isis.io.util.IsisUtil;
28 +
29 +import java.net.InetSocketAddress;
30 +import java.net.SocketAddress;
31 +
32 +import static org.hamcrest.CoreMatchers.is;
33 +import static org.hamcrest.CoreMatchers.notNullValue;
34 +import static org.hamcrest.MatcherAssert.assertThat;
35 +
36 +/**
37 + * Unit test class for IsisMessageEncoder.
38 + */
39 +public class IsisMessageEncoderTest {
40 +
41 + private final String id = "127.0.0.1";
42 + private final byte[] hello = {
43 + -125, 20, 1, 0, 17, 1, 0, 0,
44 + 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
45 + 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
46 + };
47 + private IsisMessageEncoder isisMessageEncoder;
48 + private ChannelHandlerContext ctx;
49 + private Channel channel;
50 + private SocketAddress socketAddress;
51 + private ChannelBuffer channelBuffer;
52 +
53 + @Before
54 + public void setUp() throws Exception {
55 + channel = EasyMock.createMock(Channel.class);
56 + isisMessageEncoder = new IsisMessageEncoder();
57 + }
58 +
59 + @After
60 + public void tearDown() throws Exception {
61 + channel = null;
62 + isisMessageEncoder = null;
63 + }
64 +
65 + /**
66 + * Tests encode() method.
67 + */
68 + @Test
69 + public void testEncode() throws Exception {
70 + socketAddress = InetSocketAddress.createUnresolved(id, 7000);
71 + byte[] array = IsisUtil.getPaddingTlvs(hello.length);
72 + channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
73 + assertThat(isisMessageEncoder.encode(ctx, channel, channelBuffer.array()),
74 + is(notNullValue()));
75 + }
76 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl;
17 +
18 +import org.jboss.netty.channel.ChannelPipeline;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.isis.controller.IsisInterface;
23 +import org.onosproject.isis.controller.IsisProcess;
24 +
25 +import java.util.ArrayList;
26 +import java.util.List;
27 +
28 +import static org.hamcrest.CoreMatchers.instanceOf;
29 +import static org.hamcrest.CoreMatchers.is;
30 +import static org.junit.Assert.assertThat;
31 +
32 +/**
33 + * Unit test class for IsisPipelineFactory.
34 + */
35 +public class IsisPipelineFactoryTest {
36 +
37 + private IsisPipelineFactory isisPipelineFactory;
38 + private IsisChannelHandler isisChannelHandler;
39 + private List<IsisProcess> isisProcessList = new ArrayList<>();
40 + private Controller controller;
41 + private ChannelPipeline channelPipeline;
42 + private DefaultIsisProcess isisProcess;
43 + private String processId = "1";
44 + private DefaultIsisInterface isisInterface;
45 + private List<IsisInterface> isisInterfaces = new ArrayList<>();
46 +
47 + @Before
48 + public void setUp() throws Exception {
49 + controller = new Controller();
50 + isisProcess = new DefaultIsisProcess();
51 + isisInterface = new DefaultIsisInterface();
52 + isisInterfaces.add(isisInterface);
53 + isisProcess.setIsisInterfaceList(isisInterfaces);
54 + isisProcess.setProcessId(processId);
55 + isisProcessList.add(isisProcess);
56 + isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
57 + isisPipelineFactory = new IsisPipelineFactory(isisChannelHandler);
58 + }
59 +
60 + @After
61 + public void tearDown() throws Exception {
62 + controller = null;
63 + isisChannelHandler = null;
64 + isisPipelineFactory = null;
65 + }
66 +
67 + /**
68 + * Tests getPipeline() method.
69 + */
70 + @Test
71 + public void testGetPipeline() throws Exception {
72 + channelPipeline = isisPipelineFactory.getPipeline();
73 + assertThat(channelPipeline, is(instanceOf(ChannelPipeline.class)));
74 + }
75 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.isis.controller.IsisLspBin;
22 +import org.onosproject.isis.io.isispacket.IsisHeader;
23 +import org.onosproject.isis.io.isispacket.pdu.LsPdu;
24 +
25 +import static org.hamcrest.CoreMatchers.*;
26 +import static org.junit.Assert.assertThat;
27 +
28 +/**
29 + * Unit test case for DefaultIsisLsdbAge.
30 + */
31 +public class DefaultIsisLsdbAgeTest {
32 + private DefaultIsisLsdbAge defaultIsisLsdbAge;
33 + private IsisLspBin isisLspBin;
34 + private int resultInt;
35 + private IsisLspBin resultLspBin;
36 + private DefaultLspWrapper lspWrapper;
37 + private LsPdu lsPdu;
38 + private IsisHeader isisHeader;
39 + private String lspId = "1234.1234.1234";
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + defaultIsisLsdbAge = new DefaultIsisLsdbAge();
44 + isisLspBin = new DefaultIsisLspBin(1);
45 + lspWrapper = new DefaultLspWrapper();
46 + lspWrapper.setBinNumber(1);
47 + isisHeader = new IsisHeader();
48 + lsPdu = new LsPdu(isisHeader);
49 + lsPdu.setLspId(lspId);
50 + lspWrapper.setLsPdu(lsPdu);
51 + }
52 +
53 + @After
54 + public void tearDown() throws Exception {
55 + defaultIsisLsdbAge = null;
56 + isisLspBin = null;
57 + }
58 +
59 + /**
60 + * Tests ageCounter() method.
61 + */
62 + @Test
63 + public void testAgeCounter() throws Exception {
64 + resultInt = defaultIsisLsdbAge.ageCounter();
65 + assertThat(resultInt, is(0));
66 + }
67 +
68 + /**
69 + * Tests ageCounterRollOver() method.
70 + */
71 + @Test
72 + public void testAgeCounterRollOver() throws Exception {
73 + resultInt = defaultIsisLsdbAge.ageCounterRollOver();
74 + assertThat(resultInt, is(0));
75 + }
76 +
77 + /**
78 + * Tests addLspBin() method.
79 + */
80 + @Test
81 + public void testAddLspBin() throws Exception {
82 + defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
83 + resultLspBin = defaultIsisLsdbAge.getLspBin(1);
84 + assertThat(resultLspBin, is(notNullValue()));
85 + }
86 +
87 + /**
88 + * Tests getLspBin() method.
89 + */
90 + @Test
91 + public void testGetLspBin() throws Exception {
92 + defaultIsisLsdbAge.addLspBin(1, isisLspBin);
93 + resultLspBin = defaultIsisLsdbAge.getLspBin(1);
94 + assertThat(resultLspBin, is(notNullValue()));
95 + }
96 +
97 + /**
98 + * Tests removeLspFromBin() method.
99 + */
100 + @Test
101 + public void testRemoveLspFromBin() throws Exception {
102 + defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
103 + defaultIsisLsdbAge.removeLspFromBin(lspWrapper);
104 + assertThat(resultLspBin, is(nullValue()));
105 + }
106 +
107 + /**
108 + * Tests age2Bin() method.
109 + */
110 + @Test
111 + public void testAge2Bin() throws Exception {
112 + defaultIsisLsdbAge.age2Bin(1);
113 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
114 +
115 + defaultIsisLsdbAge.age2Bin(-1);
116 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
117 + }
118 +
119 + /**
120 + * Tests startDbAging() method.
121 + */
122 + @Test
123 + public void testStartDbAging() throws Exception {
124 + defaultIsisLsdbAge.startDbAging();
125 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
126 + }
127 +
128 + /**
129 + * Tests ageLsp() method.
130 + */
131 + @Test
132 + public void testAgeLsp() throws Exception {
133 + defaultIsisLsdbAge.age2Bin(1);
134 + defaultIsisLsdbAge.startDbAging();
135 + defaultIsisLsdbAge.ageLsp();
136 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
137 + }
138 +
139 + /**
140 + * Tests maxAgeLsa() method.
141 + */
142 + @Test
143 + public void testMaxAgeLsa() throws Exception {
144 + defaultIsisLsdbAge.age2Bin(1);
145 + defaultIsisLsdbAge.startDbAging();
146 + defaultIsisLsdbAge.maxAgeLsa();
147 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
148 +
149 + defaultIsisLsdbAge.age2Bin(1400);
150 + defaultIsisLsdbAge.startDbAging();
151 + defaultIsisLsdbAge.maxAgeLsa();
152 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
153 + }
154 +
155 + /**
156 + * Tests refreshLsa() method.
157 + */
158 + @Test
159 + public void testRefreshLsa() throws Exception {
160 + defaultIsisLsdbAge.age2Bin(1);
161 + defaultIsisLsdbAge.startDbAging();
162 + defaultIsisLsdbAge.refreshLsa();
163 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
164 +
165 + defaultIsisLsdbAge.age2Bin(1400);
166 + defaultIsisLsdbAge.startDbAging();
167 + defaultIsisLsdbAge.refreshLsa();
168 + assertThat(defaultIsisLsdbAge, is(notNullValue()));
169 + }
170 +}
171 +
1 +/*
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 +package org.onosproject.isis.controller.impl.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.isis.controller.IsisLsdb;
22 +import org.onosproject.isis.controller.IsisLsdbAge;
23 +import org.onosproject.isis.controller.IsisPduType;
24 +import org.onosproject.isis.controller.LspWrapper;
25 +import org.onosproject.isis.io.util.IsisConstants;
26 +
27 +import java.util.Map;
28 +import java.util.concurrent.ConcurrentHashMap;
29 +
30 +import static org.hamcrest.CoreMatchers.*;
31 +import static org.junit.Assert.assertThat;
32 +
33 +/**
34 + * Unit test case for DefaultIsisLsdb.
35 + */
36 +public class DefaultIsisLsdbTest {
37 + private final int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
38 + private final int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
39 + private final String srcId = "1111.1111.1111";
40 +
41 + private DefaultIsisLsdb defaultIsisLsdb;
42 + private IsisLsdbAge lsdbAge = null;
43 +
44 +
45 + private int resultInt;
46 + private Map<String, LspWrapper> resultMap = new ConcurrentHashMap<>();
47 + private IsisLsdb resultLsdb;
48 + private LspWrapper resultLspWrapper;
49 +
50 +
51 + @Before
52 + public void setUp() throws Exception {
53 + defaultIsisLsdb = new DefaultIsisLsdb();
54 + }
55 +
56 + @After
57 + public void tearDown() throws Exception {
58 + defaultIsisLsdb = null;
59 + }
60 +
61 + /**
62 + * Tests initializeDb() method.
63 + */
64 + @Test
65 + public void testInitializeDb() throws Exception {
66 + defaultIsisLsdb.initializeDb();
67 + assertThat(lsdbAge, is(nullValue()));
68 + }
69 +
70 + /**
71 + * Tests setL1LspSeqNo() method.
72 + */
73 + @Test
74 + public void testSetL1LspSeqNo() throws Exception {
75 + defaultIsisLsdb.setL1LspSeqNo(l1LspSeqNo);
76 + assertThat(defaultIsisLsdb, is(notNullValue()));
77 + }
78 +
79 + /**
80 + * Tests setL2LspSeqNo() method.
81 + */
82 + @Test
83 + public void testSetL2LspSeqNo() throws Exception {
84 + defaultIsisLsdb.setL2LspSeqNo(l2LspSeqNo);
85 + assertThat(defaultIsisLsdb, is(notNullValue()));
86 + }
87 +
88 + /**
89 + * Tests setL2LspSeqNo() method.
90 + */
91 + @Test
92 + public void testLspKey() throws Exception {
93 + defaultIsisLsdb.lspKey(srcId);
94 + assertThat(defaultIsisLsdb, is(notNullValue()));
95 + }
96 +
97 + /**
98 + * Tests setL2LspSeqNo() method.
99 + */
100 + @Test
101 + public void testGetL1Db() throws Exception {
102 + resultMap = defaultIsisLsdb.getL1Db();
103 + assertThat(resultMap.isEmpty(), is(true));
104 + }
105 +
106 + /**
107 + * Tests setL2LspSeqNo() method.
108 + */
109 + @Test
110 + public void testGetL2Db() throws Exception {
111 + resultMap = defaultIsisLsdb.getL2Db();
112 + assertThat(resultMap.isEmpty(), is(true));
113 + }
114 +
115 + /**
116 + * Tests setL2LspSeqNo() method.
117 + */
118 + @Test
119 + public void testIsisLsdb() throws Exception {
120 + resultLsdb = defaultIsisLsdb.isisLsdb();
121 + assertThat(resultLsdb, is(notNullValue()));
122 + }
123 +
124 + /**
125 + * Tests findLsp() method.
126 + */
127 + @Test
128 + public void testFindLsp() throws Exception {
129 + resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId);
130 + assertThat(resultLspWrapper, is(nullValue()));
131 + }
132 +}
133 +
1 +/*
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 +package org.onosproject.isis.controller.impl.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.isis.controller.LspWrapper;
22 +
23 +import java.util.Map;
24 +
25 +import static org.hamcrest.CoreMatchers.is;
26 +import static org.hamcrest.CoreMatchers.notNullValue;
27 +import static org.junit.Assert.assertThat;
28 +
29 +/**
30 + * Unit test case for DefaultIsisLspBin.
31 + */
32 +public class DefaultIsisLspBinTest {
33 +
34 + private DefaultIsisLspBin defaultIsisLspBin;
35 + private int result;
36 + private String key = "1";
37 + private LspWrapper lspWrapper;
38 + private LspWrapper result1;
39 + private Map<String, LspWrapper> listOfLsp;
40 +
41 + @Before
42 + public void setUp() throws Exception {
43 + defaultIsisLspBin = new DefaultIsisLspBin(1);
44 + lspWrapper = new DefaultLspWrapper();
45 + }
46 +
47 + @After
48 + public void tearDown() throws Exception {
49 + defaultIsisLspBin = null;
50 + }
51 +
52 + /**
53 + * Tests addIsisLsp() method.
54 + */
55 + @Test
56 + public void testAddIsisLsp() throws Exception {
57 + defaultIsisLspBin.addIsisLsp(key, lspWrapper);
58 + assertThat(defaultIsisLspBin, is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests isisLsp() method.
63 + */
64 + @Test
65 + public void testIsisLsp() throws Exception {
66 + defaultIsisLspBin.addIsisLsp(key, lspWrapper);
67 + result1 = defaultIsisLspBin.isisLsp(key);
68 + assertThat(result1, is(notNullValue()));
69 + }
70 +
71 + /**
72 + * Tests removeIsisLsp() method.
73 + */
74 + @Test
75 + public void testRemoveIsisLsp() throws Exception {
76 + defaultIsisLspBin.addIsisLsp(key, lspWrapper);
77 + defaultIsisLspBin.removeIsisLsp(key, lspWrapper);
78 + assertThat(defaultIsisLspBin, is(notNullValue()));
79 + }
80 +
81 + /**
82 + * Tests listOfLsp() method.
83 + */
84 + @Test
85 + public void testListOfLsp() throws Exception {
86 + defaultIsisLspBin.addIsisLsp(key, lspWrapper);
87 + listOfLsp = defaultIsisLspBin.listOfLsp();
88 + assertThat(listOfLsp.size(), is(1));
89 + }
90 +
91 + /**
92 + * Tests binNumber() method.
93 + */
94 + @Test
95 + public void testBinNumber() throws Exception {
96 + result = defaultIsisLspBin.binNumber();
97 + assertThat(result, is(1));
98 + }
99 +
100 + /**
101 + * Tests toString() method.
102 + */
103 + @Test
104 + public void testToString() throws Exception {
105 + assertThat(defaultIsisLspBin.toString(), is(notNullValue()));
106 + }
107 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onosproject.isis.controller.IsisInterface;
22 +import org.onosproject.isis.controller.impl.DefaultIsisInterface;
23 +
24 +import static org.hamcrest.CoreMatchers.is;
25 +import static org.hamcrest.CoreMatchers.notNullValue;
26 +import static org.junit.Assert.assertThat;
27 +
28 +/**
29 + * Unit test case for DefaultLspWrapper.
30 + */
31 +public class DefaultLspWrapperTest {
32 +
33 + private DefaultLspWrapper defaultLspWrapper;
34 + private String processing = "processing";
35 + private String result;
36 + private int result1;
37 + private IsisInterface isisInterface;
38 + private IsisInterface result2;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + defaultLspWrapper = new DefaultLspWrapper();
43 + isisInterface = new DefaultIsisInterface();
44 + }
45 +
46 + @After
47 + public void tearDown() throws Exception {
48 + defaultLspWrapper = null;
49 + }
50 +
51 + /**
52 + * Tests lspProcessing() getter method.
53 + */
54 + @Test
55 + public void testLspProcessing() throws Exception {
56 + defaultLspWrapper.setLspProcessing(processing);
57 + result = defaultLspWrapper.lspProcessing();
58 + assertThat(result, is(notNullValue()));
59 + }
60 +
61 + /**
62 + * Tests lspProcessing() setter method.
63 + */
64 + @Test
65 + public void testSetLspProcessing() throws Exception {
66 + defaultLspWrapper.setLspProcessing(processing);
67 + result = defaultLspWrapper.lspProcessing();
68 + assertThat(result, is(notNullValue()));
69 + }
70 +
71 + /**
72 + * Tests lspAgeReceived() getter method.
73 + */
74 + @Test
75 + public void testLspAgeReceived() throws Exception {
76 + defaultLspWrapper.setLspAgeReceived(1);
77 + result1 = defaultLspWrapper.lspAgeReceived();
78 + assertThat(result1, is(notNullValue()));
79 + }
80 +
81 + /**
82 + * Tests lspAgeReceived() setter method.
83 + */
84 + @Test
85 + public void testSetLspAgeReceived() throws Exception {
86 + defaultLspWrapper.setLspAgeReceived(1);
87 + result1 = defaultLspWrapper.lspAgeReceived();
88 + assertThat(result1, is(notNullValue()));
89 + }
90 +
91 + /**
92 + * Tests lspAgeReceived() getter method.
93 + */
94 + @Test
95 + public void testIsisInterface() throws Exception {
96 + defaultLspWrapper.setIsisInterface(isisInterface);
97 + result2 = defaultLspWrapper.isisInterface();
98 + assertThat(result2, is(notNullValue()));
99 + }
100 +
101 + /**
102 + * Tests lspAgeReceived() getter method.
103 + */
104 + @Test
105 + public void testSetIsisInterface() throws Exception {
106 + defaultLspWrapper.setIsisInterface(isisInterface);
107 + result2 = defaultLspWrapper.isisInterface();
108 + assertThat(result2, is(notNullValue()));
109 + }
110 +
111 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
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 +package org.onosproject.isis.controller.impl.lsdb;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +
22 +import java.util.concurrent.BlockingQueue;
23 +
24 +import static org.hamcrest.CoreMatchers.is;
25 +import static org.hamcrest.CoreMatchers.notNullValue;
26 +import static org.junit.Assert.assertThat;
27 +
28 +/**
29 + * Unit test case for IsisLspQueueConsumer.
30 + */
31 +public class IsisLspQueueConsumerTest {
32 +
33 + private IsisLspQueueConsumer isisLspQueueConsumer;
34 + private BlockingQueue blockingQueue;
35 +
36 + @Before
37 + public void setUp() throws Exception {
38 + isisLspQueueConsumer = new IsisLspQueueConsumer(blockingQueue);
39 + }
40 +
41 + @After
42 + public void tearDown() throws Exception {
43 + isisLspQueueConsumer = null;
44 + }
45 +
46 + /**
47 + * Tests run() method.
48 + */
49 + @Test
50 + public void testRun() throws Exception {
51 + isisLspQueueConsumer.run();
52 + assertThat(isisLspQueueConsumer, is(notNullValue()));
53 + }
54 +}
...\ No newline at end of file ...\ No newline at end of file