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 1365 additions and 10 deletions
......@@ -45,7 +45,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
private String neighborSystemId;
private Ip4Address interfaceIp;
private MacAddress neighborMacAddress;
private int holdingTime;
private volatile int holdingTime;
private int neighborDownInterval;
private IsisRouterType routerType;
private String l1LanId;
private String l2LanId;
......@@ -54,6 +55,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
private IsisInterfaceState neighborState = IsisInterfaceState.INITIAL;
private InternalInactivityTimeCheck inActivityTimeCheckTask;
private ScheduledExecutorService exServiceInActivity;
private InternalHoldingTimeCheck holdingTimeCheckTask;
private ScheduledExecutorService exServiceHoldingTimeCheck;
private boolean inActivityTimerScheduled = false;
private IsisInterface isisInterface;
......@@ -72,6 +75,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
this.interfaceIp = (helloMessage.interfaceIpAddresses() != null) ?
interfaceIpAddresses.get(0) : IsisConstants.DEFAULTIP;
this.holdingTime = helloMessage.holdingTime();
neighborDownInterval = holdingTime;
this.routerType = IsisRouterType.get(helloMessage.circuitType());
if (helloMessage instanceof L1L2HelloPdu) {
if (IsisPduType.L1HELLOPDU == helloMessage.isisPduType()) {
......@@ -83,6 +87,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
this.localCircuitId = ((P2PHelloPdu) helloMessage).localCircuitId();
}
this.isisInterface = isisInterface;
startHoldingTimeCheck();
}
/**
......@@ -244,7 +249,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
* @param l2LanId L2 lan ID
*/
public void setL2LanId(String l2LanId) {
this.l1LanId = l1LanId;
this.l2LanId = l2LanId;
}
/**
......@@ -293,6 +298,25 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
}
/**
* Starts the holding time check timer.
*/
public void startHoldingTimeCheck() {
log.debug("IsisNeighbor::startHoldingTimeCheck");
holdingTimeCheckTask = new InternalHoldingTimeCheck();
exServiceHoldingTimeCheck = Executors.newSingleThreadScheduledExecutor();
exServiceHoldingTimeCheck.scheduleAtFixedRate(holdingTimeCheckTask, 1,
1, TimeUnit.SECONDS);
}
/**
* Stops the holding time check timer.
*/
public void stopHoldingTimeCheck() {
log.debug("IsisNeighbor::stopHoldingTimeCheck ");
exServiceHoldingTimeCheck.shutdown();
}
/**
* Starts the inactivity timer.
*/
public void startInactivityTimeCheck() {
......@@ -300,8 +324,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
log.debug("IsisNeighbor::startInactivityTimeCheck");
inActivityTimeCheckTask = new InternalInactivityTimeCheck();
exServiceInActivity = Executors.newSingleThreadScheduledExecutor();
exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, holdingTime,
holdingTime, TimeUnit.SECONDS);
exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, neighborDownInterval,
neighborDownInterval, TimeUnit.SECONDS);
inActivityTimerScheduled = true;
}
}
......@@ -328,6 +352,8 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
isisInterface.setL2LanId(IsisConstants.DEFAULTLANID);
neighborState = IsisInterfaceState.DOWN;
stopInactivityTimeCheck();
stopHoldingTimeCheck();
isisInterface.removeNeighbor(this);
}
......@@ -347,4 +373,20 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
neighborDown();
}
}
/**
* Represents a Task which will decrement holding time for this neighbor.
*/
private class InternalHoldingTimeCheck implements Runnable {
/**
* Creates an instance.
*/
InternalHoldingTimeCheck() {
}
@Override
public void run() {
holdingTime--;
}
}
}
\ No newline at end of file
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.jboss.netty.buffer.ChannelBuffers;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisLsdb;
import org.onosproject.isis.controller.IsisLsdbAge;
......@@ -24,6 +25,7 @@ import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.controller.LspWrapper;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.util.IsisConstants;
import org.onosproject.isis.io.util.IsisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -41,6 +43,9 @@ public class DefaultIsisLsdb implements IsisLsdb {
private Map<String, LspWrapper> isisL1Db = new ConcurrentHashMap<>();
private Map<String, LspWrapper> isisL2Db = new ConcurrentHashMap<>();
private IsisLsdbAge lsdbAge = null;
private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
......@@ -59,6 +64,23 @@ public class DefaultIsisLsdb implements IsisLsdb {
}
/**
* Sets the level 1 link state sequence number.
*
* @param l1LspSeqNo link state sequence number
*/
public void setL1LspSeqNo(int l1LspSeqNo) {
this.l1LspSeqNo = l1LspSeqNo;
}
/**
* Sets the level 2 link state sequence number.
*
* @param l2LspSeqNo link state sequence number
*/
public void setL2LspSeqNo(int l2LspSeqNo) {
this.l2LspSeqNo = l2LspSeqNo;
}
/**
* Returns the LSDB LSP key.
*
* @param systemId system ID
......@@ -108,7 +130,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
* @return List of LSPs
*/
public List<LspWrapper> allLspHeaders(boolean excludeMaxAgeLsp) {
List<LspWrapper> summaryList = new CopyOnWriteArrayList();
List<LspWrapper> summaryList = new CopyOnWriteArrayList<>();
addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL1Db);
addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL2Db);
......@@ -187,9 +209,17 @@ public class DefaultIsisLsdb implements IsisLsdb {
*/
public boolean addLsp(IsisMessage isisMessage, boolean isSelfOriginated, IsisInterface isisInterface) {
LsPdu lspdu = (LsPdu) isisMessage;
if (isSelfOriginated) {
//Add length and checksum
byte[] lspBytes = lspdu.asBytes();
lspdu.setPduLength(lspBytes.length);
lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
IsisConstants.CHECKSUMPOSITION + 1);
byte[] checkSum = {lspBytes[IsisConstants.CHECKSUMPOSITION], lspBytes[IsisConstants.CHECKSUMPOSITION + 1]};
lspdu.setCheckSum(ChannelBuffers.copiedBuffer(checkSum).readUnsignedShort());
}
DefaultLspWrapper lspWrapper = new DefaultLspWrapper();
lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime());
lspWrapper.setRemainingLifetime(IsisConstants.LSPMAXAGE - lsdbAge.ageCounter());
lspWrapper.setLspType(IsisPduType.get(lspdu.pduType()));
lspWrapper.setLsPdu(lspdu);
lspWrapper.setAgeCounterWhenReceived(lsdbAge.ageCounter());
......@@ -198,7 +228,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
lspWrapper.setIsisInterface(isisInterface);
lspWrapper.setLsdbAge(lsdbAge);
addLsp(lspWrapper, lspdu.lspId());
log.debug("Added LSp In LSDB: {}", lspWrapper);
return true;
......@@ -217,9 +246,11 @@ public class DefaultIsisLsdb implements IsisLsdb {
switch (lspWrapper.lsPdu().isisPduType()) {
case L1LSPDU:
isisL1Db.remove(key);
isisL1Db.put(key, lspWrapper);
break;
case L2LSPDU:
isisL2Db.remove(key);
isisL2Db.put(key, lspWrapper);
break;
default:
......@@ -228,7 +259,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
}
//add it to bin
Integer binNumber = lsdbAge.age2Bin(IsisConstants.LSPMAXAGE - lspWrapper.remainingLifetime());
Integer binNumber = lsdbAge.age2Bin(IsisConstants.LSPMAXAGE - lspWrapper.lspAgeReceived());
IsisLspBin lspBin = lsdbAge.getLspBin(binNumber);
if (lspBin != null) {
//remove from existing
......@@ -264,7 +295,8 @@ public class DefaultIsisLsdb implements IsisLsdb {
public String isNewerOrSameLsp(IsisMessage lsp1, IsisMessage lsp2) {
LsPdu receivedLsp = (LsPdu) lsp1;
LsPdu lspFromDb = (LsPdu) lsp2;
if (receivedLsp.sequenceNumber() > lspFromDb.sequenceNumber()) {
if (receivedLsp.sequenceNumber() > lspFromDb.sequenceNumber() ||
receivedLsp.checkSum() != lspFromDb.checkSum()) {
return "latest";
} else if (receivedLsp.sequenceNumber() < lspFromDb.sequenceNumber()) {
return "old";
......@@ -312,4 +344,4 @@ public class DefaultIsisLsdb implements IsisLsdb {
break;
}
}
}
\ No newline at end of file
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for ControllerTest.
*/
public class ControllerTest {
private Controller controller;
@Before
public void setUp() throws Exception {
controller = new Controller();
}
@After
public void tearDown() throws Exception {
controller = null;
}
/**
* Tests isisDeactivate() method.
*/
@Test(expected = Exception.class)
public void testIsisDeactivate() throws Exception {
controller.isisDeactivate();
assertThat(controller, is(notNullValue()));
}
/**
* Tests getAllConfiguredProcesses() method.
*/
@Test
public void testGetAllConfiguredProcesses() throws Exception {
controller.getAllConfiguredProcesses();
assertThat(controller, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test case for DefaultIsisController.
*/
public class DefaultIsisControllerTest {
private DefaultIsisController defaultIsisController;
@Before
public void setUp() throws Exception {
defaultIsisController = new DefaultIsisController();
}
@After
public void tearDown() throws Exception {
defaultIsisController = null;
}
/**
* Tests activate() method.
*/
@Test
public void testActivate() throws Exception {
defaultIsisController.activate();
assertThat(defaultIsisController, is(notNullValue()));
}
/**
* Tests deactivate() method.
*/
@Test(expected = Exception.class)
public void testDeactivate() throws Exception {
defaultIsisController.activate();
defaultIsisController.deactivate();
assertThat(defaultIsisController, is(notNullValue()));
}
/**
* Tests allConfiguredProcesses() method.
*/
@Test
public void testAllConfiguredProcesses() throws Exception {
defaultIsisController.allConfiguredProcesses();
assertThat(defaultIsisController, is(notNullValue()));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisProcess;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for DefaultIsisProcess.
*/
public class DefaultIsisProcessTest {
private final String processId = "1";
private IsisProcess isisProcess;
private String result;
private IsisInterface isisInterface;
private List<IsisInterface> isisInterfaceList;
private List<IsisInterface> result1;
@Before
public void setUp() throws Exception {
isisProcess = new DefaultIsisProcess();
isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class);
}
@After
public void tearDown() throws Exception {
isisProcess = null;
}
/**
* Tests processId() setter method.
*/
@Test
public void testProcessId() throws Exception {
isisProcess.setProcessId(processId);
result = isisProcess.processId();
assertThat(result, is(processId));
}
/**
* Tests processId() getter method.
*/
@Test
public void testSetProcessId() throws Exception {
isisProcess.setProcessId(processId);
result = isisProcess.processId();
assertThat(result, is(processId));
}
/**
* Tests isisInterfaceList() setter method.
*/
@Test
public void testIsisInterfaceList() throws Exception {
isisProcess.setIsisInterfaceList(isisInterfaceList);
result1 = isisProcess.isisInterfaceList();
assertThat(result1, is(nullValue()));
}
/**
* Tests isisInterfaceList() getter method.
*/
@Test
public void testSetIsisInterfaceList() throws Exception {
isisProcess.setIsisInterfaceList(isisInterfaceList);
result1 = isisProcess.isisInterfaceList();
assertThat(result1, is(nullValue()));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.easymock.EasyMock;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisMessage;
import org.onosproject.isis.controller.IsisProcess;
import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IsisChannelHandler.
*/
public class IsisChannelHandlerTest {
private final String processId = "1";
private final byte[] config = {0, 0, 0, 0, 0, 0, 0};
private IsisChannelHandler isisChannelHandler;
private Controller controller;
private IsisProcess isisProcess;
private List<IsisProcess> isisProcessList;
private ChannelHandlerContext channelHandlerContext;
private ChannelStateEvent channelStateEvent;
private ExceptionEvent exceptionEvent;
private MessageEvent messageEvent;
private IsisMessage isisMessage;
@Before
public void setUp() throws Exception {
controller = EasyMock.createNiceMock(Controller.class);
isisProcess = EasyMock.createNiceMock(IsisProcess.class);
channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
messageEvent = EasyMock.createNiceMock(MessageEvent.class);
isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
isisMessage.setInterfaceIndex(2);
isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
}
@After
public void tearDown() throws Exception {
isisChannelHandler = null;
}
/**
* Tests initializeInterfaceMap() method.
*/
@Test(expected = Exception.class)
public void testInitializeInterfaceMap() throws Exception {
isisChannelHandler.initializeInterfaceMap();
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests updateInterfaceMap() method.
*/
@Test(expected = Exception.class)
public void testUpdateInterfaceMap() throws Exception {
isisChannelHandler.updateInterfaceMap(isisProcessList);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests initializeInterfaceIpList() method.
*/
@Test(expected = Exception.class)
public void testInitializeInterfaceIpList() throws Exception {
isisChannelHandler.initializeInterfaceIpList();
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests channelConnected() method.
*/
@Test(expected = Exception.class)
public void testChannelConnected() throws Exception {
isisChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests channelDisconnected() method.
*/
@Test
public void testChannelDisconnected() throws Exception {
isisChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests exceptionCaught() method.
*/
@Test(expected = Exception.class)
public void testExceptionCaught() throws Exception {
isisChannelHandler.exceptionCaught(channelHandlerContext, exceptionEvent);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests messageReceived() method.
*/
@Test
public void testMessageReceived() throws Exception {
isisChannelHandler.messageReceived(channelHandlerContext, messageEvent);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessIsisMessage() throws Exception {
isisChannelHandler.processIsisMessage(isisMessage, channelHandlerContext);
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests startHelloSender() method.
*/
@Test
public void testStartHelloSender() throws Exception {
isisChannelHandler.startHelloSender();
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests stopHelloSender() method.
*/
@Test
public void testStopHelloSender() throws Exception {
isisChannelHandler.stopHelloSender();
assertThat(isisChannelHandler, is(notNullValue()));
}
/**
* Tests sentConfigPacket() method.
*/
@Test
public void testSentConfigPacket() throws Exception {
isisChannelHandler.sentConfigPacket(config);
assertThat(isisChannelHandler, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.easymock.EasyMock;
import org.jboss.netty.channel.Channel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.isis.controller.IsisNetworkType;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IsisHelloPduSender.
*/
public class IsisHelloPduSenderTest {
private final String systemId = "1234.1234.1234";
private final String areaId = "490001";
private final String circuitId = "0";
private final String lanId = "0000.0000.0000.00";
private Channel channel;
private DefaultIsisInterface isisInterface;
private DefaultIsisInterface isisInterface1;
private IsisHelloPduSender isisHelloPduSender;
private IsisHelloPduSender isisHelloPduSender1;
private Ip4Address interfaceAddress = Ip4Address.valueOf("10.10.10.10");
@Before
public void setUp() throws Exception {
channel = EasyMock.createNiceMock(Channel.class);
isisInterface = new DefaultIsisInterface();
isisInterface1 = new DefaultIsisInterface();
}
@After
public void tearDown() throws Exception {
channel = null;
isisInterface = null;
}
/**
* Tests run() method.
*/
@Test
public void testRun() throws Exception {
isisInterface.setNetworkType(IsisNetworkType.P2P);
isisInterface.setCircuitId(circuitId);
isisInterface.setSystemId(systemId);
isisInterface.setAreaAddress("490001");
isisInterface.setInterfaceIpAddress(interfaceAddress);
isisHelloPduSender = new IsisHelloPduSender(channel, isisInterface);
isisHelloPduSender.run();
assertThat(isisHelloPduSender, is(notNullValue()));
isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
isisInterface1.setCircuitId(circuitId);
isisInterface1.setSystemId(systemId);
isisInterface1.setAreaAddress(areaId);
isisInterface1.setInterfaceIpAddress(interfaceAddress);
isisInterface1.setReservedPacketCircuitType(1);
isisInterface1.setL1LanId(lanId);
isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
isisHelloPduSender1.run();
assertThat(isisHelloPduSender1, is(notNullValue()));
isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
isisInterface1.setCircuitId(circuitId);
isisInterface1.setSystemId(systemId);
isisInterface1.setAreaAddress(areaId);
isisInterface1.setInterfaceIpAddress(interfaceAddress);
isisInterface1.setReservedPacketCircuitType(2);
isisInterface1.setL2LanId(lanId);
isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
isisHelloPduSender1.run();
assertThat(isisHelloPduSender1, is(notNullValue()));
isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
isisInterface1.setCircuitId(circuitId);
isisInterface1.setSystemId(systemId);
isisInterface1.setAreaAddress(areaId);
isisInterface1.setInterfaceIpAddress(interfaceAddress);
isisInterface1.setReservedPacketCircuitType(3);
isisInterface1.setL1LanId(lanId);
isisInterface1.setL2LanId(lanId);
isisHelloPduSender1 = new IsisHelloPduSender(channel, isisInterface1);
isisHelloPduSender1.run();
assertThat(isisHelloPduSender1, is(notNullValue()));
}
}
\ No newline at end of file
package org.onosproject.isis.controller.impl;
import com.google.common.primitives.Bytes;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.util.IsisUtil;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for IsisMessageDecoder.
*/
public class IsisMessageDecoderTest {
private final byte[] hello = {
-125, 20, 1, 0, 17, 1, 0, 0,
2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
};
private final String id = "127.0.0.1";
private IsisMessageDecoder isisMessageDecoder;
private ChannelHandlerContext ctx;
private Channel channel;
private SocketAddress socketAddress;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
isisMessageDecoder = new IsisMessageDecoder();
}
@After
public void tearDown() throws Exception {
isisMessageDecoder = null;
}
@Test
public void testDecode() throws Exception {
channel = EasyMock.createMock(Channel.class);
socketAddress = InetSocketAddress.createUnresolved(id, 7000);
byte[] array = IsisUtil.getPaddingTlvs(hello.length);
channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import com.google.common.primitives.Bytes;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.io.util.IsisUtil;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit test class for IsisMessageEncoder.
*/
public class IsisMessageEncoderTest {
private final String id = "127.0.0.1";
private final byte[] hello = {
-125, 20, 1, 0, 17, 1, 0, 0,
2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
};
private IsisMessageEncoder isisMessageEncoder;
private ChannelHandlerContext ctx;
private Channel channel;
private SocketAddress socketAddress;
private ChannelBuffer channelBuffer;
@Before
public void setUp() throws Exception {
channel = EasyMock.createMock(Channel.class);
isisMessageEncoder = new IsisMessageEncoder();
}
@After
public void tearDown() throws Exception {
channel = null;
isisMessageEncoder = null;
}
/**
* Tests encode() method.
*/
@Test
public void testEncode() throws Exception {
socketAddress = InetSocketAddress.createUnresolved(id, 7000);
byte[] array = IsisUtil.getPaddingTlvs(hello.length);
channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
assertThat(isisMessageEncoder.encode(ctx, channel, channelBuffer.array()),
is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl;
import org.jboss.netty.channel.ChannelPipeline;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisProcess;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* Unit test class for IsisPipelineFactory.
*/
public class IsisPipelineFactoryTest {
private IsisPipelineFactory isisPipelineFactory;
private IsisChannelHandler isisChannelHandler;
private List<IsisProcess> isisProcessList = new ArrayList<>();
private Controller controller;
private ChannelPipeline channelPipeline;
private DefaultIsisProcess isisProcess;
private String processId = "1";
private DefaultIsisInterface isisInterface;
private List<IsisInterface> isisInterfaces = new ArrayList<>();
@Before
public void setUp() throws Exception {
controller = new Controller();
isisProcess = new DefaultIsisProcess();
isisInterface = new DefaultIsisInterface();
isisInterfaces.add(isisInterface);
isisProcess.setIsisInterfaceList(isisInterfaces);
isisProcess.setProcessId(processId);
isisProcessList.add(isisProcess);
isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
isisPipelineFactory = new IsisPipelineFactory(isisChannelHandler);
}
@After
public void tearDown() throws Exception {
controller = null;
isisChannelHandler = null;
isisPipelineFactory = null;
}
/**
* Tests getPipeline() method.
*/
@Test
public void testGetPipeline() throws Exception {
channelPipeline = isisPipelineFactory.getPipeline();
assertThat(channelPipeline, is(instanceOf(ChannelPipeline.class)));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisLspBin;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
/**
* Unit test case for DefaultIsisLsdbAge.
*/
public class DefaultIsisLsdbAgeTest {
private DefaultIsisLsdbAge defaultIsisLsdbAge;
private IsisLspBin isisLspBin;
private int resultInt;
private IsisLspBin resultLspBin;
private DefaultLspWrapper lspWrapper;
private LsPdu lsPdu;
private IsisHeader isisHeader;
private String lspId = "1234.1234.1234";
@Before
public void setUp() throws Exception {
defaultIsisLsdbAge = new DefaultIsisLsdbAge();
isisLspBin = new DefaultIsisLspBin(1);
lspWrapper = new DefaultLspWrapper();
lspWrapper.setBinNumber(1);
isisHeader = new IsisHeader();
lsPdu = new LsPdu(isisHeader);
lsPdu.setLspId(lspId);
lspWrapper.setLsPdu(lsPdu);
}
@After
public void tearDown() throws Exception {
defaultIsisLsdbAge = null;
isisLspBin = null;
}
/**
* Tests ageCounter() method.
*/
@Test
public void testAgeCounter() throws Exception {
resultInt = defaultIsisLsdbAge.ageCounter();
assertThat(resultInt, is(0));
}
/**
* Tests ageCounterRollOver() method.
*/
@Test
public void testAgeCounterRollOver() throws Exception {
resultInt = defaultIsisLsdbAge.ageCounterRollOver();
assertThat(resultInt, is(0));
}
/**
* Tests addLspBin() method.
*/
@Test
public void testAddLspBin() throws Exception {
defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
resultLspBin = defaultIsisLsdbAge.getLspBin(1);
assertThat(resultLspBin, is(notNullValue()));
}
/**
* Tests getLspBin() method.
*/
@Test
public void testGetLspBin() throws Exception {
defaultIsisLsdbAge.addLspBin(1, isisLspBin);
resultLspBin = defaultIsisLsdbAge.getLspBin(1);
assertThat(resultLspBin, is(notNullValue()));
}
/**
* Tests removeLspFromBin() method.
*/
@Test
public void testRemoveLspFromBin() throws Exception {
defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
defaultIsisLsdbAge.removeLspFromBin(lspWrapper);
assertThat(resultLspBin, is(nullValue()));
}
/**
* Tests age2Bin() method.
*/
@Test
public void testAge2Bin() throws Exception {
defaultIsisLsdbAge.age2Bin(1);
assertThat(defaultIsisLsdbAge, is(notNullValue()));
defaultIsisLsdbAge.age2Bin(-1);
assertThat(defaultIsisLsdbAge, is(notNullValue()));
}
/**
* Tests startDbAging() method.
*/
@Test
public void testStartDbAging() throws Exception {
defaultIsisLsdbAge.startDbAging();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
}
/**
* Tests ageLsp() method.
*/
@Test
public void testAgeLsp() throws Exception {
defaultIsisLsdbAge.age2Bin(1);
defaultIsisLsdbAge.startDbAging();
defaultIsisLsdbAge.ageLsp();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
}
/**
* Tests maxAgeLsa() method.
*/
@Test
public void testMaxAgeLsa() throws Exception {
defaultIsisLsdbAge.age2Bin(1);
defaultIsisLsdbAge.startDbAging();
defaultIsisLsdbAge.maxAgeLsa();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
defaultIsisLsdbAge.age2Bin(1400);
defaultIsisLsdbAge.startDbAging();
defaultIsisLsdbAge.maxAgeLsa();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
}
/**
* Tests refreshLsa() method.
*/
@Test
public void testRefreshLsa() throws Exception {
defaultIsisLsdbAge.age2Bin(1);
defaultIsisLsdbAge.startDbAging();
defaultIsisLsdbAge.refreshLsa();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
defaultIsisLsdbAge.age2Bin(1400);
defaultIsisLsdbAge.startDbAging();
defaultIsisLsdbAge.refreshLsa();
assertThat(defaultIsisLsdbAge, is(notNullValue()));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisLsdb;
import org.onosproject.isis.controller.IsisLsdbAge;
import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.controller.LspWrapper;
import org.onosproject.isis.io.util.IsisConstants;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
/**
* Unit test case for DefaultIsisLsdb.
*/
public class DefaultIsisLsdbTest {
private final int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
private final int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
private final String srcId = "1111.1111.1111";
private DefaultIsisLsdb defaultIsisLsdb;
private IsisLsdbAge lsdbAge = null;
private int resultInt;
private Map<String, LspWrapper> resultMap = new ConcurrentHashMap<>();
private IsisLsdb resultLsdb;
private LspWrapper resultLspWrapper;
@Before
public void setUp() throws Exception {
defaultIsisLsdb = new DefaultIsisLsdb();
}
@After
public void tearDown() throws Exception {
defaultIsisLsdb = null;
}
/**
* Tests initializeDb() method.
*/
@Test
public void testInitializeDb() throws Exception {
defaultIsisLsdb.initializeDb();
assertThat(lsdbAge, is(nullValue()));
}
/**
* Tests setL1LspSeqNo() method.
*/
@Test
public void testSetL1LspSeqNo() throws Exception {
defaultIsisLsdb.setL1LspSeqNo(l1LspSeqNo);
assertThat(defaultIsisLsdb, is(notNullValue()));
}
/**
* Tests setL2LspSeqNo() method.
*/
@Test
public void testSetL2LspSeqNo() throws Exception {
defaultIsisLsdb.setL2LspSeqNo(l2LspSeqNo);
assertThat(defaultIsisLsdb, is(notNullValue()));
}
/**
* Tests setL2LspSeqNo() method.
*/
@Test
public void testLspKey() throws Exception {
defaultIsisLsdb.lspKey(srcId);
assertThat(defaultIsisLsdb, is(notNullValue()));
}
/**
* Tests setL2LspSeqNo() method.
*/
@Test
public void testGetL1Db() throws Exception {
resultMap = defaultIsisLsdb.getL1Db();
assertThat(resultMap.isEmpty(), is(true));
}
/**
* Tests setL2LspSeqNo() method.
*/
@Test
public void testGetL2Db() throws Exception {
resultMap = defaultIsisLsdb.getL2Db();
assertThat(resultMap.isEmpty(), is(true));
}
/**
* Tests setL2LspSeqNo() method.
*/
@Test
public void testIsisLsdb() throws Exception {
resultLsdb = defaultIsisLsdb.isisLsdb();
assertThat(resultLsdb, is(notNullValue()));
}
/**
* Tests findLsp() method.
*/
@Test
public void testFindLsp() throws Exception {
resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId);
assertThat(resultLspWrapper, is(nullValue()));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.LspWrapper;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test case for DefaultIsisLspBin.
*/
public class DefaultIsisLspBinTest {
private DefaultIsisLspBin defaultIsisLspBin;
private int result;
private String key = "1";
private LspWrapper lspWrapper;
private LspWrapper result1;
private Map<String, LspWrapper> listOfLsp;
@Before
public void setUp() throws Exception {
defaultIsisLspBin = new DefaultIsisLspBin(1);
lspWrapper = new DefaultLspWrapper();
}
@After
public void tearDown() throws Exception {
defaultIsisLspBin = null;
}
/**
* Tests addIsisLsp() method.
*/
@Test
public void testAddIsisLsp() throws Exception {
defaultIsisLspBin.addIsisLsp(key, lspWrapper);
assertThat(defaultIsisLspBin, is(notNullValue()));
}
/**
* Tests isisLsp() method.
*/
@Test
public void testIsisLsp() throws Exception {
defaultIsisLspBin.addIsisLsp(key, lspWrapper);
result1 = defaultIsisLspBin.isisLsp(key);
assertThat(result1, is(notNullValue()));
}
/**
* Tests removeIsisLsp() method.
*/
@Test
public void testRemoveIsisLsp() throws Exception {
defaultIsisLspBin.addIsisLsp(key, lspWrapper);
defaultIsisLspBin.removeIsisLsp(key, lspWrapper);
assertThat(defaultIsisLspBin, is(notNullValue()));
}
/**
* Tests listOfLsp() method.
*/
@Test
public void testListOfLsp() throws Exception {
defaultIsisLspBin.addIsisLsp(key, lspWrapper);
listOfLsp = defaultIsisLspBin.listOfLsp();
assertThat(listOfLsp.size(), is(1));
}
/**
* Tests binNumber() method.
*/
@Test
public void testBinNumber() throws Exception {
result = defaultIsisLspBin.binNumber();
assertThat(result, is(1));
}
/**
* Tests toString() method.
*/
@Test
public void testToString() throws Exception {
assertThat(defaultIsisLspBin.toString(), is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.impl.DefaultIsisInterface;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test case for DefaultLspWrapper.
*/
public class DefaultLspWrapperTest {
private DefaultLspWrapper defaultLspWrapper;
private String processing = "processing";
private String result;
private int result1;
private IsisInterface isisInterface;
private IsisInterface result2;
@Before
public void setUp() throws Exception {
defaultLspWrapper = new DefaultLspWrapper();
isisInterface = new DefaultIsisInterface();
}
@After
public void tearDown() throws Exception {
defaultLspWrapper = null;
}
/**
* Tests lspProcessing() getter method.
*/
@Test
public void testLspProcessing() throws Exception {
defaultLspWrapper.setLspProcessing(processing);
result = defaultLspWrapper.lspProcessing();
assertThat(result, is(notNullValue()));
}
/**
* Tests lspProcessing() setter method.
*/
@Test
public void testSetLspProcessing() throws Exception {
defaultLspWrapper.setLspProcessing(processing);
result = defaultLspWrapper.lspProcessing();
assertThat(result, is(notNullValue()));
}
/**
* Tests lspAgeReceived() getter method.
*/
@Test
public void testLspAgeReceived() throws Exception {
defaultLspWrapper.setLspAgeReceived(1);
result1 = defaultLspWrapper.lspAgeReceived();
assertThat(result1, is(notNullValue()));
}
/**
* Tests lspAgeReceived() setter method.
*/
@Test
public void testSetLspAgeReceived() throws Exception {
defaultLspWrapper.setLspAgeReceived(1);
result1 = defaultLspWrapper.lspAgeReceived();
assertThat(result1, is(notNullValue()));
}
/**
* Tests lspAgeReceived() getter method.
*/
@Test
public void testIsisInterface() throws Exception {
defaultLspWrapper.setIsisInterface(isisInterface);
result2 = defaultLspWrapper.isisInterface();
assertThat(result2, is(notNullValue()));
}
/**
* Tests lspAgeReceived() getter method.
*/
@Test
public void testSetIsisInterface() throws Exception {
defaultLspWrapper.setIsisInterface(isisInterface);
result2 = defaultLspWrapper.isisInterface();
assertThat(result2, is(notNullValue()));
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.concurrent.BlockingQueue;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
* Unit test case for IsisLspQueueConsumer.
*/
public class IsisLspQueueConsumerTest {
private IsisLspQueueConsumer isisLspQueueConsumer;
private BlockingQueue blockingQueue;
@Before
public void setUp() throws Exception {
isisLspQueueConsumer = new IsisLspQueueConsumer(blockingQueue);
}
@After
public void tearDown() throws Exception {
isisLspQueueConsumer = null;
}
/**
* Tests run() method.
*/
@Test
public void testRun() throws Exception {
isisLspQueueConsumer.run();
assertThat(isisLspQueueConsumer, is(notNullValue()));
}
}
\ No newline at end of file