sunish vk
Committed by Gerrit Code Review

ONOS-4505: Bug Fixes

Change-Id: Ia030aa3aff9e2ad34a5e27fbe4ba088dda65bfa7
Showing 34 changed files with 584 additions and 55 deletions
......@@ -195,13 +195,6 @@ public interface IsisInterface {
void setAreaLength(int areaLength);
/**
* Sets link state packet ID.
*
* @param lspId link state packet ID
*/
void setLspId(String lspId);
/**
* Returns holding time.
*
* @return holding time
......@@ -251,6 +244,11 @@ public interface IsisInterface {
void startHelloSender(Channel channel);
/**
* Stops the hello timer which sends hello packet every configured seconds.
*/
void stopHelloSender();
/**
* Processes an ISIS message which is received on this interface.
*
* @param isisMessage ISIS message instance
......@@ -315,4 +313,9 @@ public interface IsisInterface {
* @param isisNeighbor ISIS neighbor instance
*/
void removeNeighbor(IsisNeighbor isisNeighbor);
/**
* Removes all the neighbors.
*/
void removeNeighbors();
}
......
......@@ -108,4 +108,18 @@ public interface IsisLsdb {
* @return neighbor database information
*/
Map<String, LspWrapper> getL2Db();
/**
* Sets the level 1 link state sequence number.
*
* @param l1LspSeqNo link state sequence number
*/
void setL1LspSeqNo(int l1LspSeqNo);
/**
* Sets the level 2 link state sequence number.
*
* @param l2LspSeqNo link state sequence number
*/
void setL2LspSeqNo(int l2LspSeqNo);
}
\ No newline at end of file
......
......@@ -108,4 +108,16 @@ public interface IsisNeighbor {
* Stops the inactivity timer.
*/
void stopInactivityTimeCheck();
}
/**
* Stops the holding time check timer.
*/
void stopHoldingTimeCheck();
/**
* Returns router type.
*
* @return router type
*/
IsisRouterType routerType();
}
\ No newline at end of file
......
......@@ -88,6 +88,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
}
this.isisInterface = isisInterface;
startHoldingTimeCheck();
log.debug("Neighbor added - {}", neighborMacAddress);
}
/**
......@@ -387,6 +388,10 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
@Override
public void run() {
holdingTime--;
if (holdingTime <= 0) {
log.debug("Calling neighbor down. Holding time is 0.");
neighborDown();
}
}
}
}
\ No newline at end of file
......
......@@ -94,13 +94,35 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
for (IsisInterface isisUpdatedInterface : isisUpdatedProcess.isisInterfaceList()) {
IsisInterface isisInterface = isisInterfaceMap.get(isisUpdatedInterface.interfaceIndex());
if (isisInterface == null) {
isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface);
interfaceIps.add(isisInterface.interfaceIpAddress());
isisInterfaceMap.put(isisUpdatedInterface.interfaceIndex(), isisUpdatedInterface);
interfaceIps.add(isisUpdatedInterface.interfaceIpAddress());
} else {
isisInterface.setReservedPacketCircuitType(isisUpdatedInterface.reservedPacketCircuitType());
isisInterface.setNetworkType(isisUpdatedInterface.networkType());
isisInterface.setHoldingTime(isisUpdatedInterface.holdingTime());
isisInterface.setHelloInterval(isisUpdatedInterface.helloInterval());
if (isisInterface.intermediateSystemName() != isisUpdatedInterface.intermediateSystemName()) {
isisInterface.setIntermediateSystemName(isisUpdatedInterface.intermediateSystemName());
}
if (isisInterface.reservedPacketCircuitType() != isisUpdatedInterface.reservedPacketCircuitType()) {
isisInterface.setReservedPacketCircuitType(isisUpdatedInterface.reservedPacketCircuitType());
isisInterface.removeNeighbors();
}
if (isisInterface.circuitId() != isisUpdatedInterface.circuitId()) {
isisInterface.setCircuitId(isisUpdatedInterface.circuitId());
}
if (isisInterface.networkType() != isisUpdatedInterface.networkType()) {
isisInterface.setNetworkType(isisUpdatedInterface.networkType());
isisInterface.removeNeighbors();
}
if (isisInterface.areaAddress() != isisUpdatedInterface.areaAddress()) {
isisInterface.setAreaAddress(isisUpdatedInterface.areaAddress());
}
if (isisInterface.holdingTime() != isisUpdatedInterface.holdingTime()) {
isisInterface.setHoldingTime(isisUpdatedInterface.holdingTime());
}
if (isisInterface.helloInterval() != isisUpdatedInterface.helloInterval()) {
isisInterface.setHelloInterval(isisUpdatedInterface.helloInterval());
isisInterface.stopHelloSender();
isisInterface.startHelloSender(channel);
}
isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface);
}
}
......@@ -144,6 +166,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
log.debug("IsisChannelHandler::channelDisconnected...!!!");
if (controller != null) {
controller.connectPeer();
}
}
@Override
......@@ -169,8 +194,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
} else if (e.getCause() instanceof RejectedExecutionException) {
log.warn("Could not process message: queue full");
} else {
log.error("Error while processing message from ISIS {}",
e.getChannel().getRemoteAddress());
log.error("Error while processing message from ISIS {}, {}",
e.getChannel().getRemoteAddress(), e.getCause().getMessage());
e.getCause().printStackTrace();
}
}
......
......@@ -45,7 +45,7 @@ public class IsisHelloPduSender implements Runnable {
@Override
public void run() {
if (channel != null) {
if (channel != null && channel.isConnected() && channel.isOpen()) {
try {
byte[] helloPdu = null;
byte[] interfaceIndex = {(byte) isisInterface.interfaceIndex()};
......
......@@ -44,7 +44,6 @@ public class IsisMessageDecoder extends FrameDecoder {
log.info("Channel is not connected.");
return null;
}
IsisMessageReader messageReader = new IsisMessageReader();
List<IsisMessage> isisMessageList = new LinkedList<>();
int dataLength = buffer.readableBytes();
......@@ -74,8 +73,7 @@ public class IsisMessageDecoder extends FrameDecoder {
isisMessageList.add(message);
}
}
return isisMessageList;
return (isisMessageList.size() > 0) ? isisMessageList : null;
}
/**
......
......@@ -45,7 +45,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
private IsisLsdbAge lsdbAge = null;
private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
......@@ -80,6 +79,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
public void setL2LspSeqNo(int l2LspSeqNo) {
this.l2LspSeqNo = l2LspSeqNo;
}
/**
* Returns the LSDB LSP key.
*
......@@ -96,6 +96,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
return lspKey.toString();
}
/**
* Returns the neighbor L1 database information.
*
......@@ -218,7 +219,12 @@ public class DefaultIsisLsdb implements IsisLsdb {
byte[] checkSum = {lspBytes[IsisConstants.CHECKSUMPOSITION], lspBytes[IsisConstants.CHECKSUMPOSITION + 1]};
lspdu.setCheckSum(ChannelBuffers.copiedBuffer(checkSum).readUnsignedShort());
}
DefaultLspWrapper lspWrapper = new DefaultLspWrapper();
DefaultLspWrapper lspWrapper = (DefaultLspWrapper) findLsp(lspdu.isisPduType(), lspdu.lspId());
if (lspWrapper == null) {
lspWrapper = new DefaultLspWrapper();
}
lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime());
lspWrapper.setLspType(IsisPduType.get(lspdu.pduType()));
lspWrapper.setLsPdu(lspdu);
......@@ -228,8 +234,8 @@ public class DefaultIsisLsdb implements IsisLsdb {
lspWrapper.setIsisInterface(isisInterface);
lspWrapper.setLsdbAge(lsdbAge);
addLsp(lspWrapper, lspdu.lspId());
log.debug("Added LSp In LSDB: {}", lspWrapper);
log.debug("Added LSp In LSDB: {}", lspWrapper);
return true;
}
......@@ -270,7 +276,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
lspWrapper.lsPdu().isisPduType(),
binNumber, lspWrapper.remainingLifetime());
}
return false;
}
......@@ -344,4 +349,4 @@ public class DefaultIsisLsdb implements IsisLsdb {
break;
}
}
}
}
\ No newline at end of file
......
......@@ -36,10 +36,10 @@ import java.util.concurrent.TimeUnit;
*/
public class DefaultIsisLsdbAge implements IsisLsdbAge {
private static final Logger log = LoggerFactory.getLogger(DefaultIsisLsdbAge.class);
protected static int ageCounter = 0;
protected int ageCounter = 0;
private InternalAgeTimer dbAgeTimer;
private ScheduledExecutorService exServiceage;
private Integer maxBins = 1200;
private Integer maxBins = IsisConstants.LSPMAXAGE;
private Map<Integer, IsisLspBin> ageBins = new ConcurrentHashMap<>(maxBins);
private int ageCounterRollOver = 0;
private IsisLspQueueConsumer queueConsumer = null;
......@@ -202,7 +202,7 @@ public class DefaultIsisLsdbAge implements IsisLsdbAge {
} else {
binNumber = ageCounter - IsisConstants.LSPREFRESH;
}
if (binNumber > IsisConstants.LSPMAXAGE) {
if (binNumber >= IsisConstants.LSPMAXAGE) {
binNumber = binNumber - IsisConstants.LSPMAXAGE;
}
IsisLspBin lspBin = ageBins.get(binNumber);
......
......@@ -21,11 +21,14 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Representation of LSP wrapper where the LSPs are stored with metadata.
*/
public class DefaultLspWrapper implements LspWrapper {
private static final Logger log = LoggerFactory.getLogger(DefaultLspWrapper.class);
private int binNumber = -1;
private boolean selfOriginated = false;
private IsisPduType lspType;
......@@ -229,7 +232,15 @@ public class DefaultLspWrapper implements LspWrapper {
int currentAge = 0;
//ls age received
if (lsdbAge.ageCounter() >= ageCounterWhenReceived) {
if (!selfOriginated) {
if (ageCounterRollOverWhenAdded == lsdbAge.ageCounterRollOver()) {
currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived);
} else {
return IsisConstants.LSPMAXAGE;
}
} else {
currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived);
}
} else {
currentAge = lspAgeReceived + ((IsisConstants.LSPMAXAGE + lsdbAge.ageCounter())
- ageCounterWhenReceived);
......@@ -245,6 +256,8 @@ public class DefaultLspWrapper implements LspWrapper {
return currentAge;
}
/**
* Returns remaining time.
*
......@@ -252,7 +265,7 @@ public class DefaultLspWrapper implements LspWrapper {
*/
public int remainingLifetime() {
//Calculate the remaining lifetime
remainingLifetime = IsisConstants.LSPMAXAGE - lsdbAge.ageCounter();
remainingLifetime = IsisConstants.LSPMAXAGE - currentAge();
return remainingLifetime;
}
......
......@@ -100,7 +100,9 @@ public class IsisLspQueueConsumer implements Runnable {
IsisConstants.CHECKSUMPOSITION + 1);
//write to the channel
channel.write(IsisUtil.framePacket(lspBytes, isisInterface.interfaceIndex()));
// Updating the database with resetting remaining life time to default.
IsisLsdb isisDb = isisInterface.isisLsdb();
isisDb.addLsp(lsPdu, true, isisInterface);
log.debug("LSPQueueConsumer: processRefreshLsp - Flooded SelfOriginated LSP {}",
wrapper.lsPdu());
}
......
......@@ -16,6 +16,8 @@
package org.onosproject.isis.controller.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -30,10 +32,65 @@ import static org.junit.Assert.assertThat;
public class ControllerTest {
private Controller controller;
private ObjectMapper mapper;
private JsonNode jsonNode;
private JsonNode jsonNode1;
private String jsonString = "{" +
" \"processes\": [{" +
" \"processId\": \"4.4.4.4\"," +
" \"interface\": [{" +
" \"interfaceIndex\": \"2\"," +
" \"macAddress\": \"08:00:27:b7:ab:bf\"," +
" \"interfaceIp\": \"192.168.56.101\"," +
" \"networkMask\": \"255.255.255.224\"," +
" \"intermediateSystemName\": \"ROUTERONE\"," +
" \"systemId\": \"2929.2929.2929\"," +
" \"lanId\": \"0000.0000.0000.00\"," +
" \"idLength\": \"0\"," +
" \"maxAreaAddresses\": \"3\"," +
" \"reservedPacketCircuitType\": \"1\"," +
" \"circuitId\": \"10\"," +
" \"networkType\": \"2\"," +
" \"areaAddress\": \"490000\"," +
" \"areaLength\": \"3\"," +
" \"lspId\": \"1313131313130000\"," +
" \"holdingTime\": \"50\"," +
" \"helloInterval\": \"10\"," +
" \"priority\": \"0\"" +
" }]" +
" }]" +
"}";
private String jsonString1 = "{" +
" \"processes\": {" +
" \"interface\": [{" +
" \"interfaceIndex\": \"2\"," +
" \"interfaceIp\": \"100.100.100.100\"," +
" \"macAddress\": \"08:00:27:b7:ab:bf\"," +
" \"networkMask\": \"255.255.255.224\"," +
" \"intermediateSystemName\": \"ROUTERONE\"," +
" \"systemId\": \"2929.2929.2929\"," +
" \"lanId\": \"0000.0000.0000.00\"," +
" \"idLength\": \"0\"," +
" \"maxAreaAddresses\": \"3\"," +
" \"reservedPacketCircuitType\": \"1\"," +
" \"circuitId\": \"10\"," +
" \"networkType\": \"2\"," +
" \"areaAddress\": \"490000\"," +
" \"areaLength\": \"3\"," +
" \"lspId\": \"1313131313130000\"," +
" \"holdingTime\": \"50\"," +
" \"helloInterval\": \"10\"," +
" \"priority\": \"0\"" +
" }]" +
" }" +
"}";
@Before
public void setUp() throws Exception {
controller = new Controller();
mapper = new ObjectMapper();
jsonNode = mapper.readTree(jsonString);
jsonNode1 = mapper.readTree(jsonString1);
}
@After
......@@ -58,4 +115,18 @@ public class ControllerTest {
controller.getAllConfiguredProcesses();
assertThat(controller, is(notNullValue()));
}
/**
* Tests updateConfig() method.
*/
@Test
public void testUpdateConfig() throws Exception {
jsonNode.path("interface");
controller.updateConfig(jsonNode);
assertThat(controller, is(notNullValue()));
controller.updateConfig(jsonNode1);
assertThat(controller, is(notNullValue()));
}
}
\ No newline at end of file
......
......@@ -15,9 +15,13 @@
*/
package org.onosproject.isis.controller.impl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.topology.IsisRouterListener;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
......@@ -27,11 +31,43 @@ import static org.junit.Assert.assertThat;
* Unit test case for DefaultIsisController.
*/
public class DefaultIsisControllerTest {
private ObjectMapper mapper;
private JsonNode jsonNode;
private DefaultIsisController defaultIsisController;
private String jsonString = "{" +
" \"processes\": [{" +
" \"processId\": \"4.4.4.4\"," +
" \"interface\": [{" +
" \"interfaceIndex\": \"2\"," +
" \"macAddress\": \"08:00:27:b7:ab:bf\"," +
" \"interfaceIp\": \"192.168.56.101\"," +
" \"networkMask\": \"255.255.255.224\"," +
" \"intermediateSystemName\": \"ROUTERONE\"," +
" \"systemId\": \"2929.2929.2929\"," +
" \"lanId\": \"0000.0000.0000.00\"," +
" \"idLength\": \"0\"," +
" \"maxAreaAddresses\": \"3\"," +
" \"reservedPacketCircuitType\": \"1\"," +
" \"circuitId\": \"10\"," +
" \"networkType\": \"2\"," +
" \"areaAddress\": \"490000\"," +
" \"areaLength\": \"3\"," +
" \"lspId\": \"1313131313130000\"," +
" \"holdingTime\": \"50\"," +
" \"helloInterval\": \"10\"," +
" \"priority\": \"0\"" +
" }]" +
" }]" +
"}";
private IsisRouterListener isisRouterListener;
@Before
public void setUp() throws Exception {
defaultIsisController = new DefaultIsisController();
mapper = new ObjectMapper();
jsonNode = mapper.readTree(jsonString);
isisRouterListener = EasyMock.createNiceMock(IsisRouterListener.class);
}
@After
......@@ -66,4 +102,31 @@ public class DefaultIsisControllerTest {
defaultIsisController.allConfiguredProcesses();
assertThat(defaultIsisController, is(notNullValue()));
}
/**
* Tests updateConfig() method.
*/
@Test
public void testUpdateConfig() throws Exception {
defaultIsisController.updateConfig(jsonNode);
assertThat(defaultIsisController, is(notNullValue()));
}
/**
* Tests addRouterListener() method.
*/
@Test
public void testaddRouterListener() throws Exception {
defaultIsisController.addRouterListener(isisRouterListener);
assertThat(defaultIsisController, is(notNullValue()));
}
/**
* Tests removeRouterListener() method.
*/
@Test
public void testremoveRouterListener() throws Exception {
defaultIsisController.removeRouterListener(isisRouterListener);
assertThat(defaultIsisController, is(notNullValue()));
}
}
......
......@@ -36,6 +36,7 @@ public class DefaultIsisProcessTest {
private final String processId = "1";
private IsisProcess isisProcess;
private String result;
private IsisProcess defaultIsisProcess;
private IsisInterface isisInterface;
private List<IsisInterface> isisInterfaceList;
private List<IsisInterface> result1;
......@@ -44,6 +45,7 @@ public class DefaultIsisProcessTest {
public void setUp() throws Exception {
isisProcess = new DefaultIsisProcess();
isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class);
defaultIsisProcess = new DefaultIsisProcess();
}
@After
......@@ -90,4 +92,4 @@ public class DefaultIsisProcessTest {
result1 = isisProcess.isisInterfaceList();
assertThat(result1, is(nullValue()));
}
}
}
\ No newline at end of file
......
......@@ -23,10 +23,14 @@ import org.jboss.netty.channel.MessageEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisMessage;
import org.onosproject.isis.controller.IsisNetworkType;
import org.onosproject.isis.controller.IsisProcess;
import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
......@@ -43,12 +47,14 @@ public class IsisChannelHandlerTest {
private IsisChannelHandler isisChannelHandler;
private Controller controller;
private IsisProcess isisProcess;
private List<IsisProcess> isisProcessList;
private List<IsisProcess> isisProcessList = new ArrayList();
private ChannelHandlerContext channelHandlerContext;
private ChannelStateEvent channelStateEvent;
private ExceptionEvent exceptionEvent;
private MessageEvent messageEvent;
private IsisMessage isisMessage;
private List<IsisInterface> isisInterfaceList = new ArrayList<>();
private Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
@Before
public void setUp() throws Exception {
......@@ -71,7 +77,7 @@ public class IsisChannelHandlerTest {
/**
* Tests initializeInterfaceMap() method.
*/
@Test(expected = Exception.class)
@Test
public void testInitializeInterfaceMap() throws Exception {
isisChannelHandler.initializeInterfaceMap();
assertThat(isisChannelHandler, is(notNullValue()));
......@@ -82,6 +88,32 @@ public class IsisChannelHandlerTest {
*/
@Test(expected = Exception.class)
public void testUpdateInterfaceMap() throws Exception {
IsisInterface isisInterface = new DefaultIsisInterface();
IsisInterface isisInterface1 = new DefaultIsisInterface();
isisInterface.setInterfaceIpAddress(ip4Address);
isisInterface.setInterfaceIndex(1);
isisInterfaceList.add(isisInterface);
IsisProcess isisProcess = new DefaultIsisProcess();
isisProcess.setIsisInterfaceList(isisInterfaceList);
isisProcessList.add(isisProcess);
isisChannelHandler.updateInterfaceMap(isisProcessList);
assertThat(isisChannelHandler, is(notNullValue()));
isisProcessList = new ArrayList<>();
isisInterface1.setInterfaceIpAddress(ip4Address);
isisInterface1.setInterfaceIndex(1);
isisInterface1.setInterfaceIpAddress(ip4Address);
isisInterface1.setInterfaceIndex(1);
isisInterface1.setSystemId("9999.9999.9999");
isisInterface1.setIntermediateSystemName("router");
isisInterface1.setReservedPacketCircuitType(3);
isisInterface1.setCircuitId("10");
isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
isisInterface1.setAreaAddress("490001");
isisInterface1.setHoldingTime(50);
isisInterface1.setHelloInterval(10);
isisInterfaceList.add(isisInterface1);
isisProcess.setIsisInterfaceList(isisInterfaceList);
isisProcessList.add(isisProcess);
isisChannelHandler.updateInterfaceMap(isisProcessList);
assertThat(isisChannelHandler, is(notNullValue()));
}
......@@ -89,7 +121,7 @@ public class IsisChannelHandlerTest {
/**
* Tests initializeInterfaceIpList() method.
*/
@Test(expected = Exception.class)
@Test
public void testInitializeInterfaceIpList() throws Exception {
isisChannelHandler.initializeInterfaceIpList();
assertThat(isisChannelHandler, is(notNullValue()));
......
......@@ -58,7 +58,7 @@ public class IsisHelloPduSenderTest {
/**
* Tests run() method.
*/
@Test
@Test(expected = Exception.class)
public void testRun() throws Exception {
isisInterface.setNetworkType(IsisNetworkType.P2P);
isisInterface.setCircuitId(circuitId);
......
......@@ -24,11 +24,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class IsisMessageDecoderTest {
private final byte[] hello = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-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 byte[] array2 = {0, 0, 0, 0, 0, 0, 0};
private final String id = "127.0.0.1";
private byte[] array1;
private IsisMessageDecoder isisMessageDecoder;
private ChannelHandlerContext ctx;
private Channel channel;
......@@ -49,7 +52,8 @@ public class IsisMessageDecoderTest {
public void testDecode() throws Exception {
channel = EasyMock.createMock(Channel.class);
socketAddress = InetSocketAddress.createUnresolved(id, 7000);
byte[] array = IsisUtil.getPaddingTlvs(hello.length);
byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17);
array1 = Bytes.concat(hello, array);
channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
}
......
......@@ -22,8 +22,13 @@ 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.controller.impl.DefaultIsisInterface;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.util.IsisConstants;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -37,19 +42,27 @@ 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;
private List<LspWrapper> lspWrapperList;
private LsPdu lsPdu;
private IsisHeader isisHeader;
private DefaultIsisInterface defaultIsisInterface;
private String lspId = "1234.1234.1234.00-00";
private String result;
@Before
public void setUp() throws Exception {
defaultIsisInterface = new DefaultIsisInterface();
isisHeader = new IsisHeader();
lsPdu = new LsPdu(isisHeader);
lsPdu.setLspId(lspId);
lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
lsPdu.setIsisPduType(IsisPduType.L1LSPDU.value());
defaultIsisLsdb = new DefaultIsisLsdb();
}
......@@ -129,5 +142,60 @@ public class DefaultIsisLsdbTest {
resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId);
assertThat(resultLspWrapper, is(nullValue()));
}
/**
* Tests allLspHeaders() method.
*/
@Test
public void testAllLspHeaders() throws Exception {
defaultIsisLsdb.addLsp(lsPdu, false, defaultIsisInterface);
lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
assertThat(lspWrapperList, is(notNullValue()));
defaultIsisLsdb.addLsp(lsPdu, true, defaultIsisInterface);
lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
assertThat(lspWrapperList, is(notNullValue()));
}
/**
* Tests isNewerOrSameLsp() method.
*/
@Test
public void testIsNewerOrSameLsp() throws Exception {
result = defaultIsisLsdb.isNewerOrSameLsp(lsPdu, lsPdu);
assertThat(result, is("same"));
}
/**
* Tests lsSequenceNumber() method.
*/
@Test
public void testLsSequenceNumber() throws Exception {
resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1LSPDU);
assertThat(resultInt, is(1));
resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L2LSPDU);
assertThat(resultInt, is(1));
resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1CSNP);
assertThat(resultInt, is(1));
}
/**
* Tests deleteLsp() method.
*/
@Test
public void testdeleteLsp() throws Exception {
defaultIsisLsdb.deleteLsp(lsPdu);
assertThat(defaultIsisLsdb, is(notNullValue()));
lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
defaultIsisLsdb.deleteLsp(lsPdu);
assertThat(defaultIsisLsdb, is(notNullValue()));
lsPdu.setIsisPduType(IsisPduType.L1CSNP.value());
defaultIsisLsdb.deleteLsp(lsPdu);
assertThat(defaultIsisLsdb, is(notNullValue()));
}
}
......
......@@ -19,7 +19,11 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisLsdbAge;
import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.controller.impl.DefaultIsisInterface;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
......@@ -36,11 +40,20 @@ public class DefaultLspWrapperTest {
private int result1;
private IsisInterface isisInterface;
private IsisInterface result2;
private IsisPduType isisPduType;
private boolean result3;
private LsPdu lsPdu;
private LsPdu pdu;
private DefaultIsisLsdbAge defaultIsisLsdbAge;
private IsisLsdbAge lsdbAge;
@Before
public void setUp() throws Exception {
defaultLspWrapper = new DefaultLspWrapper();
isisInterface = new DefaultIsisInterface();
pdu = new LsPdu(new IsisHeader());
defaultIsisLsdbAge = new DefaultIsisLsdbAge();
defaultIsisLsdbAge.startDbAging();
}
@After
......@@ -108,4 +121,169 @@ public class DefaultLspWrapperTest {
assertThat(result2, is(notNullValue()));
}
/**
* Tests ageCounterWhenReceived() getter method.
*/
@Test
public void testAgeCounterWhenReceived() throws Exception {
defaultLspWrapper.setAgeCounterWhenReceived(1);
result1 = defaultLspWrapper.ageCounterWhenReceived();
assertThat(result1, is(notNullValue()));
}
/**
* Tests ageCounterWhenReceived() setter method.
*/
@Test
public void testSetAgeCounterWhenReceived() throws Exception {
defaultLspWrapper.setAgeCounterWhenReceived(1);
result1 = defaultLspWrapper.ageCounterWhenReceived();
assertThat(result1, is(notNullValue()));
}
/**
* Tests ageCounterRollOverWhenAdded() getter method.
*/
@Test
public void testAgeCounterRollOverWhenAdded() throws Exception {
defaultLspWrapper.setAgeCounterRollOverWhenAdded(1);
result1 = defaultLspWrapper.ageCounterRollOverWhenAdded();
assertThat(result1, is(notNullValue()));
}
/**
* Tests ageCounterRollOverWhenAdded() setter method.
*/
@Test
public void testSetAgeCounterRollOverWhenAdded() throws Exception {
defaultLspWrapper.setAgeCounterRollOverWhenAdded(1);
result1 = defaultLspWrapper.ageCounterRollOverWhenAdded();
assertThat(result1, is(notNullValue()));
}
/**
* Tests lspType() getter method.
*/
@Test
public void testLspType() throws Exception {
defaultLspWrapper.setLspType(IsisPduType.L1LSPDU);
isisPduType = defaultLspWrapper.lspType();
assertThat(isisPduType, is(IsisPduType.L1LSPDU));
}
/**
* Tests lspType() setter method.
*/
@Test
public void testSetLspType() throws Exception {
defaultLspWrapper.setLspType(IsisPduType.L1LSPDU);
isisPduType = defaultLspWrapper.lspType();
assertThat(isisPduType, is(IsisPduType.L1LSPDU));
}
/**
* Tests isSelfOriginated() getter method.
*/
@Test
public void testIsSelfOriginated() throws Exception {
defaultLspWrapper.setSelfOriginated(true);
result3 = defaultLspWrapper.isSelfOriginated();
assertThat(result3, is(true));
}
/**
* Tests isSelfOriginated() setter method.
*/
@Test
public void testSetSelfOriginated() throws Exception {
defaultLspWrapper.setSelfOriginated(true);
result3 = defaultLspWrapper.isSelfOriginated();
assertThat(result3, is(true));
}
/**
* Tests binNumber() getter method.
*/
@Test
public void testBinNumber() throws Exception {
defaultLspWrapper.setBinNumber(1);
result1 = defaultLspWrapper.binNumber();
assertThat(result1, is(1));
}
/**
* Tests binNumber() setter method.
*/
@Test
public void testSetBinNumber() throws Exception {
defaultLspWrapper.setBinNumber(1);
result1 = defaultLspWrapper.binNumber();
assertThat(result1, is(1));
}
/**
* Tests lsPdu() getter method.
*/
@Test
public void testLsPdu() throws Exception {
defaultLspWrapper.setLsPdu(pdu);
lsPdu = defaultLspWrapper.lsPdu();
assertThat(lsPdu, is(pdu));
}
/**
* Tests lsPdu() setter method.
*/
@Test
public void testSetLsPdu() throws Exception {
defaultLspWrapper.setLsPdu(pdu);
lsPdu = defaultLspWrapper.lsPdu();
assertThat(lsPdu, is(pdu));
}
/**
* Tests lsdbAge() getter method.
*/
@Test
public void testlsdbAge() throws Exception {
defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
lsdbAge = defaultLspWrapper.lsdbAge();
assertThat(lsdbAge, is(defaultIsisLsdbAge));
}
/**
* Tests lsdbAge() setter method.
*/
@Test
public void testSetLsdbAge() throws Exception {
defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
lsdbAge = defaultLspWrapper.lsdbAge();
assertThat(lsdbAge, is(defaultIsisLsdbAge));
}
/**
* Tests remainingLifetime() getter method.
*/
@Test
public void testRemainingLifetime() throws Exception {
defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
defaultLspWrapper.setAgeCounterWhenReceived(1);
defaultLspWrapper.currentAge();
defaultLspWrapper.setRemainingLifetime(1);
result1 = defaultLspWrapper.remainingLifetime();
assertThat(result1, is(1));
}
/**
* Tests remainingLifetime() setter method.
*/
@Test
public void testSetRemainingLifetime() throws Exception {
defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
defaultLspWrapper.setAgeCounterWhenReceived(1);
defaultLspWrapper.currentAge();
defaultLspWrapper.setRemainingLifetime(1);
result1 = defaultLspWrapper.remainingLifetime();
assertThat(result1, is(1));
}
}
\ No newline at end of file
......
......@@ -18,7 +18,11 @@ package org.onosproject.isis.controller.impl.lsdb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.isis.controller.impl.DefaultIsisInterface;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import static org.hamcrest.CoreMatchers.is;
......@@ -31,10 +35,22 @@ import static org.junit.Assert.assertThat;
public class IsisLspQueueConsumerTest {
private IsisLspQueueConsumer isisLspQueueConsumer;
private BlockingQueue blockingQueue;
private BlockingQueue blockingQueue = new ArrayBlockingQueue(1024);
private DefaultLspWrapper lspWrapper;
private DefaultLspWrapper lspWrapper1;
private SocketAddress socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
@Before
public void setUp() throws Exception {
lspWrapper = new DefaultLspWrapper();
lspWrapper.setLspProcessing("refreshLsp");
lspWrapper.setSelfOriginated(true);
lspWrapper.setIsisInterface(new DefaultIsisInterface());
lspWrapper1 = new DefaultLspWrapper();
lspWrapper1.setLspProcessing("maxAgeLsp");
lspWrapper1.setIsisInterface(new DefaultIsisInterface());
blockingQueue.add(lspWrapper);
blockingQueue.add(lspWrapper1);
isisLspQueueConsumer = new IsisLspQueueConsumer(blockingQueue);
}
......
......@@ -33,6 +33,7 @@ public final class IsisConstants {
public static final int IRPDISCRIMINATOR = 131;
public static final int ISISVERSION = 1;
public static final int RESERVED = 0;
public static final int PRIORITY = 0;
public static final int MAXAREAADDRESS = 0;
public static final int SYSTEMIDLENGTH = 0;
public static final int PROTOCOLSUPPORTED = 204;
......@@ -55,24 +56,15 @@ public final class IsisConstants {
public static final String DEFAULTLANID = "0000.0000.0000.00";
public static final String PROCESSESID = "processId";
public static final String INTERFACE = "interface";
public static final String INTERFACEIP = "interfaceIp";
public static final String NETWORKMASK = "networkMask";
public static final String INTERFACEINDEX = "interfaceIndex";
public static final String INTERMEDIATESYSTEMNAME = "intermediateSystemName";
public static final String SYSTEMID = "systemId";
public static final String LANID = "lanId";
public static final String IDLENGTH = "idLength";
public static final String MAXAREAADDRESSES = "maxAreaAddresses";
public static final String RESERVEDPACKETCIRCUITTYPE = "reservedPacketCircuitType";
public static final String CIRCUITID = "circuitId";
public static final String NETWORKTYPE = "networkType";
public static final String AREAADDRESS = "areaAddress";
public static final String AREALENGTH = "areaLength";
public static final String LSPID = "lspId";
public static final String HOLDINGTIME = "holdingTime";
public static final String HELLOINTERVAL = "helloInterval";
public static final String PRIORITY = "priority";
public static final String MACADDRESS = "macAddress";
/**
* Non parameterized constructor.
......
......@@ -22,6 +22,7 @@ import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisInterfaceState;
import org.onosproject.isis.controller.IsisNeighbor;
import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.controller.IsisRouterType;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
......@@ -394,7 +395,6 @@ public final class IsisUtil {
isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH);
isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
//isisHeader.setReserved((byte) IsisConstants.RESERVED);
isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION);
isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
P2PHelloPdu p2pHelloPdu = new P2PHelloPdu(isisHeader);
......@@ -510,14 +510,32 @@ public final class IsisUtil {
l1L2HelloPdu.addTlv(areaAddressTlv);
Set<MacAddress> neighbors = isisInterface.neighbors();
if (neighbors.size() > 0) {
List<MacAddress> neighborMacs = new ArrayList<>();
for (MacAddress neighbor : neighbors) {
IsisNeighbor isisNeighbor = isisInterface.lookup(neighbor);
if (isisPduType == IsisPduType.L1HELLOPDU) {
if (isisNeighbor.routerType() == IsisRouterType.L1 ||
isisNeighbor.routerType() == IsisRouterType.L1L2) {
neighborMacs.add(neighbor);
}
} else if (isisPduType == IsisPduType.L2HELLOPDU) {
if (isisNeighbor.routerType() == IsisRouterType.L2 ||
isisNeighbor.routerType() == IsisRouterType.L1L2) {
neighborMacs.add(neighbor);
}
}
}
tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value());
tlvHeader.setTlvLength(0);
IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
for (MacAddress neighbor : neighbors) {
for (MacAddress neighbor : neighborMacs) {
isisNeighborTlv.addNeighbor(neighbor);
}
l1L2HelloPdu.addTlv(isisNeighborTlv);
}
tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
tlvHeader.setTlvLength(0);
ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
......@@ -708,4 +726,4 @@ public final class IsisUtil {
}
return Bytes.toArray(byteList);
}
}
}
\ No newline at end of file
......
......@@ -140,8 +140,15 @@ public class LspGenerator {
metricOfIntRea.setExpenseIsInternal(true);
Ip4Address ip4Address = isisInterface.interfaceIpAddress();
byte[] ipAddress = ip4Address.toOctets();
ipAddress[ipAddress.length - 1] = 0;
metricOfIntRea.setIpAddress(Ip4Address.valueOf(ipAddress));
// ipAddress[ipAddress.length - 1] = 0;
byte[] networkmass = isisInterface.networkMask();
// metric calculation part
byte[] result = new byte[ipAddress.length];
result[0] = (byte) (ipAddress[0] & networkmass[0]);
result[1] = (byte) (ipAddress[1] & networkmass[1]);
result[2] = (byte) (ipAddress[2] & networkmass[2]);
result[3] = (byte) (ipAddress[3] & networkmass[3]);
metricOfIntRea.setIpAddress(Ip4Address.valueOf(result));
metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask()));
ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
lsp.addTlv(ipInterReacTlv);
......