sunish vk
Committed by Gerrit Code Review

ONOS-4505: Bug Fixes

Change-Id: Ia030aa3aff9e2ad34a5e27fbe4ba088dda65bfa7
Showing 34 changed files with 1490 additions and 239 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
......
......@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
......@@ -35,10 +36,14 @@ import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static org.onlab.util.Tools.groupedThreads;
......@@ -48,12 +53,17 @@ import static org.onlab.util.Tools.groupedThreads;
public class Controller {
protected static final int BUFFER_SIZE = 4 * 1024 * 1024;
private static final Logger log = LoggerFactory.getLogger(Controller.class);
private static final int RETRY_INTERVAL = 4;
private final int peerWorkerThreads = 16;
byte[] configPacket = null;
private List<IsisProcess> processes = null;
private IsisChannelHandler isisChannelHandler;
private NioClientSocketChannelFactory peerExecFactory;
private ClientBootstrap peerBootstrap = null;
private TpPort isisPort = TpPort.tpPort(IsisConstants.SPORT);
private ScheduledExecutorService connectExecutor = null;
private int connectRetryCounter = 0;
private int connectRetryTime;
/**
* Deactivates ISIS controller.
......@@ -70,12 +80,11 @@ public class Controller {
*/
public void updateConfig(JsonNode jsonNode) throws Exception {
log.debug("Controller::UpdateConfig called");
byte[] configPacket = new byte[IsisConstants.CONFIG_LENGTH];
configPacket = new byte[IsisConstants.CONFIG_LENGTH];
byte numberOfInterface = 0; // number of interfaces to configure
configPacket[0] = (byte) 0xFF; // its a conf packet - identifier
List<IsisProcess> isisProcesses = getConfig(jsonNode);
for (IsisProcess isisProcess : isisProcesses) {
log.debug("IsisProcessDetails : " + isisProcess);
for (IsisInterface isisInterface : isisProcess.isisInterfaceList()) {
......@@ -100,17 +109,20 @@ public class Controller {
configPacket[1] = numberOfInterface;
//First time configuration
if (processes == null) {
if (isisProcesses.size() > 0) {
processes = isisProcesses;
//Initialize connection by creating a channel handler instance and sent the config packet);
initConnection();
connectPeer();
//Initializing the interface map in channel handler
if (isisChannelHandler != null) {
isisChannelHandler.initializeInterfaceMap();
}
}
} else {
isisChannelHandler.updateInterfaceMap(isisProcesses);
}
//Send the config packet
isisChannelHandler.sentConfigPacket(configPacket);
}
}
/**
* Initializes the netty client channel connection.
......@@ -182,10 +194,8 @@ public class Controller {
* @return list of processes configured
*/
private List<IsisProcess> getConfig(JsonNode json) throws Exception {
List<IsisProcess> isisProcessesList = new ArrayList<>();
JsonNode jsonNodes = json;
if (jsonNodes == null) {
return isisProcessesList;
}
......@@ -193,49 +203,335 @@ public class Controller {
List<IsisInterface> interfaceList = new ArrayList<>();
for (JsonNode jsonNode1 : jsonNode.path(IsisConstants.INTERFACE)) {
IsisInterface isisInterface = new DefaultIsisInterface();
isisInterface.setInterfaceIndex(jsonNode1.path(IsisConstants.INTERFACEINDEX).asInt());
isisInterface.setInterfaceIpAddress(Ip4Address.valueOf(jsonNode1
.path(IsisConstants.INTERFACEIP)
.asText()));
String index = jsonNode1.path(IsisConstants.INTERFACEINDEX).asText();
if (isPrimitive(index)) {
int input = Integer.parseInt(index);
if (input < 1 || input > 255) {
log.debug("Wrong interface index: {}", index);
continue;
}
isisInterface.setInterfaceIndex(Integer.parseInt(index));
} else {
log.debug("Wrong interface index {}", index);
continue;
}
Ip4Address ipAddress = getInterfaceIp(isisInterface.interfaceIndex());
if (ipAddress != null && !ipAddress.equals(IsisConstants.DEFAULTIP)) {
isisInterface.setInterfaceIpAddress(ipAddress);
} else {
log.debug("Wrong interface index {}. No matching interface in system.", index);
continue;
}
MacAddress macAddress = getInterfaceMac(isisInterface.interfaceIndex());
if (macAddress != null) {
isisInterface.setInterfaceMacAddress(macAddress);
} else {
log.debug("Wrong interface index {}. No matching interface in system.", index);
continue;
}
String mask = getInterfaceMask(isisInterface.interfaceIndex());
if (mask != null) {
try {
isisInterface.setNetworkMask(InetAddress.getByName((jsonNode1
.path(IsisConstants.NETWORKMASK).asText())).getAddress());
isisInterface.setNetworkMask(InetAddress.getByName(mask).getAddress());
} catch (UnknownHostException e) {
log.debug("Error:: Parsing network mask");
log.debug("Wrong interface index {}. Error while getting network mask.", index);
}
} else {
log.debug("Wrong interface index {}. Error while getting network mask.", index);
continue;
}
isisInterface.setInterfaceMacAddress(MacAddress.valueOf(jsonNode1
.path(IsisConstants.MACADDRESS)
.asText()));
isisInterface.setIntermediateSystemName(jsonNode1
.path(IsisConstants.INTERMEDIATESYSTEMNAME)
.asText());
isisInterface.setSystemId(jsonNode1.path(IsisConstants.SYSTEMID).asText());
isisInterface.setReservedPacketCircuitType(jsonNode1
.path(IsisConstants.RESERVEDPACKETCIRCUITTYPE)
.asInt());
if (isisInterface.reservedPacketCircuitType() == IsisRouterType.L1.value()) {
isisInterface.setL1LanId(jsonNode1.path(IsisConstants.LANID).asText());
}
isisInterface.setIdLength(jsonNode1.path(IsisConstants.IDLENGTH).asInt());
isisInterface.setMaxAreaAddresses(jsonNode1.path(IsisConstants.MAXAREAADDRESSES).asInt());
isisInterface.setNetworkType(IsisNetworkType.get(jsonNode1
.path(IsisConstants.NETWORKTYPE)
.asInt()));
isisInterface.setAreaAddress(jsonNode1.path(IsisConstants.AREAADDRESS).asText());
isisInterface.setAreaLength(jsonNode1.path(IsisConstants.AREALENGTH).asInt());
isisInterface.setLspId(jsonNode1.path(IsisConstants.LSPID).asText());
isisInterface.setCircuitId(jsonNode1.path(IsisConstants.CIRCUITID).asText());
isisInterface.setHoldingTime(jsonNode1.path(IsisConstants.HOLDINGTIME).asInt());
isisInterface.setPriority(jsonNode1.path(IsisConstants.PRIORITY).asInt());
isisInterface.setHelloInterval(jsonNode1.path(IsisConstants.HELLOINTERVAL).asInt());
String systemId = jsonNode1.path(IsisConstants.SYSTEMID).asText();
if (isValidSystemId(systemId)) {
isisInterface.setSystemId(systemId);
} else {
log.debug("Wrong systemId: {} for interface index {}.", systemId, index);
continue;
}
String circuitType = jsonNode1.path(IsisConstants.RESERVEDPACKETCIRCUITTYPE).asText();
if (isPrimitive(circuitType)) {
int input = Integer.parseInt(circuitType);
if (input < 1 || input > 3) {
log.debug("Wrong ReservedPacketCircuitType: {} for interface index {}.", circuitType, index);
continue;
}
isisInterface.setReservedPacketCircuitType(input);
} else {
log.debug("Wrong ReservedPacketCircuitType: {} for interface index {}.", circuitType, index);
continue;
}
String networkType = jsonNode1.path(IsisConstants.NETWORKTYPE).asText();
if (isPrimitive(networkType)) {
int input = Integer.parseInt(networkType);
if (input < 1 || input > 2) {
log.debug("Wrong networkType: {} for interface index {}.", networkType, index);
continue;
}
isisInterface.setNetworkType(IsisNetworkType.get(input));
} else {
log.debug("Wrong networkType: {} for interface index {}.", networkType, index);
continue;
}
String areaAddress = jsonNode1.path(IsisConstants.AREAADDRESS).asText();
if (isPrimitive(areaAddress)) {
if (areaAddress.length() > 7) {
log.debug("Wrong areaAddress: {} for interface index {}.", areaAddress, index);
continue;
}
isisInterface.setAreaAddress(areaAddress);
} else {
log.debug("Wrong areaAddress: {} for interface index {}.", areaAddress, index);
continue;
}
String circuitId = jsonNode1.path(IsisConstants.CIRCUITID).asText();
if (isPrimitive(circuitId)) {
int input = Integer.parseInt(circuitId);
if (input < 1) {
log.debug("Wrong circuitId: {} for interface index {}.", circuitId, index);
continue;
}
isisInterface.setCircuitId(circuitId);
} else {
log.debug("Wrong circuitId: {} for interface index {}.", circuitId, index);
continue;
}
String holdingTime = jsonNode1.path(IsisConstants.HOLDINGTIME).asText();
if (isPrimitive(holdingTime)) {
int input = Integer.parseInt(holdingTime);
if (input < 1 || input > 255) {
log.debug("Wrong holdingTime: {} for interface index {}.", holdingTime, index);
continue;
}
isisInterface.setHoldingTime(input);
} else {
log.debug("Wrong holdingTime: {} for interface index {}.", holdingTime, index);
continue;
}
String helloInterval = jsonNode1.path(IsisConstants.HELLOINTERVAL).asText();
if (isPrimitive(helloInterval)) {
int interval = Integer.parseInt(helloInterval);
if (interval > 0 && interval <= 255) {
isisInterface.setHelloInterval(interval);
} else {
log.debug("Wrong hello interval: {} for interface index {}.", helloInterval, index);
continue;
}
} else {
log.debug("Wrong hello interval: {} for interface index {}.", helloInterval, index);
continue;
}
interfaceList.add(isisInterface);
}
if (interfaceList.size() > 0) {
IsisProcess process = new DefaultIsisProcess();
process.setProcessId(jsonNode.path(IsisConstants.PROCESSESID).asText());
process.setIsisInterfaceList(interfaceList);
isisProcessesList.add(process);
}
});
return isisProcessesList;
}
/**
* Returns interface MAC by index.
*
* @param interfaceIndex interface index
* @return interface IP by index
*/
private MacAddress getInterfaceMac(int interfaceIndex) {
MacAddress macAddress = null;
try {
NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
macAddress = MacAddress.valueOf(networkInterface.getHardwareAddress());
} catch (Exception e) {
log.debug("Error while getting Interface IP by index");
return macAddress;
}
return macAddress;
}
/**
* Returns interface IP by index.
*
* @param interfaceIndex interface index
* @return interface IP by index
*/
private Ip4Address getInterfaceIp(int interfaceIndex) {
Ip4Address ipAddress = null;
try {
NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
Enumeration ipAddresses = networkInterface.getInetAddresses();
while (ipAddresses.hasMoreElements()) {
InetAddress address = (InetAddress) ipAddresses.nextElement();
if (!address.isLinkLocalAddress()) {
ipAddress = Ip4Address.valueOf(address.getAddress());
break;
}
}
} catch (Exception e) {
log.debug("Error while getting Interface IP by index");
return IsisConstants.DEFAULTIP;
}
return ipAddress;
}
/**
* Returns interface MAC by index.
*
* @param interfaceIndex interface index
* @return interface IP by index
*/
private String getInterfaceMask(int interfaceIndex) {
String subnetMask = null;
try {
Ip4Address ipAddress = getInterfaceIp(interfaceIndex);
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(
InetAddress.getByName(ipAddress.toString()));
Enumeration ipAddresses = networkInterface.getInetAddresses();
int index = 0;
while (ipAddresses.hasMoreElements()) {
InetAddress address = (InetAddress) ipAddresses.nextElement();
if (!address.isLinkLocalAddress()) {
break;
}
index++;
}
int prfLen = networkInterface.getInterfaceAddresses().get(index).getNetworkPrefixLength();
int shft = 0xffffffff << (32 - prfLen);
int oct1 = ((byte) ((shft & 0xff000000) >> 24)) & 0xff;
int oct2 = ((byte) ((shft & 0x00ff0000) >> 16)) & 0xff;
int oct3 = ((byte) ((shft & 0x0000ff00) >> 8)) & 0xff;
int oct4 = ((byte) (shft & 0x000000ff)) & 0xff;
subnetMask = oct1 + "." + oct2 + "." + oct3 + "." + oct4;
} catch (Exception e) {
log.debug("Error while getting Interface network mask by index");
return subnetMask;
}
return subnetMask;
}
/**
* Checks if primitive or not.
*
* @param value input value
* @return true if number else false
*/
private boolean isPrimitive(String value) {
boolean status = true;
value = value.trim();
if (value.length() < 1) {
return false;
}
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (!Character.isDigit(c)) {
status = false;
break;
}
}
return status;
}
/**
* Checks if system id is valid or not.
*
* @param value input value
* @return true if valid else false
*/
private boolean isValidSystemId(String value) {
value = value.trim();
boolean status = true;
if (value.length() != 14) {
return false;
}
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (!Character.isDigit(c)) {
if (!((i == 4 || i == 9) && c == '.')) {
status = false;
break;
}
}
}
return status;
}
/**
* Disconnects the executor.
*/
public void disconnectExecutor() {
if (connectExecutor != null) {
connectExecutor.shutdown();
connectExecutor = null;
}
}
/**
* Connects to peer.
*/
public void connectPeer() {
scheduleConnectionRetry(this.connectRetryTime);
}
/**
* Retry connection with exponential back-off mechanism.
*
* @param retryDelay retry delay
*/
private void scheduleConnectionRetry(long retryDelay) {
if (this.connectExecutor == null) {
this.connectExecutor = Executors.newSingleThreadScheduledExecutor();
}
this.connectExecutor.schedule(new ConnectionRetry(), retryDelay, TimeUnit.MINUTES);
}
/**
* Implements ISIS connection and manages connection to peer with back-off mechanism in case of failure.
*/
class ConnectionRetry implements Runnable {
@Override
public void run() {
log.debug("Connect to peer {}", IsisConstants.SHOST);
initConnection();
InetSocketAddress connectToSocket = new InetSocketAddress(IsisConstants.SHOST, isisPort.toInt());
try {
peerBootstrap.connect(connectToSocket).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
connectRetryCounter++;
log.error("Connection failed, ConnectRetryCounter {} remote host {}", connectRetryCounter,
IsisConstants.SHOST);
/*
* Reconnect to peer on failure is exponential till 4 mins, later on retry after every 4
* mins.
*/
if (connectRetryTime < RETRY_INTERVAL) {
connectRetryTime = (connectRetryTime != 0) ? connectRetryTime * 2 : 1;
}
scheduleConnectionRetry(connectRetryTime);
} else {
connectRetryCounter++;
log.info("Connected to remote host {}, Connect Counter {}", IsisConstants.SHOST,
connectRetryCounter);
disconnectExecutor();
isisChannelHandler.initializeInterfaceMap();
//Send the config packet
isisChannelHandler.sentConfigPacket(configPacket);
return;
}
}
});
} catch (Exception e) {
log.info("Connect peer exception : " + e.toString());
disconnectExecutor();
}
}
}
}
\ No newline at end of file
......
......@@ -69,15 +69,14 @@ public class DefaultIsisInterface implements IsisInterface {
private MacAddress interfaceMacAddress;
private String intermediateSystemName;
private String systemId;
private String l1LanId;
private String l2LanId;
private String l1LanId = IsisConstants.DEFAULTLANID;
private String l2LanId = IsisConstants.DEFAULTLANID;
private int idLength;
private int maxAreaAddresses;
private int reservedPacketCircuitType;
private IsisNetworkType networkType;
private String areaAddress;
private int areaLength;
private String lspId;
private int holdingTime;
private int priority;
private String circuitId;
......@@ -114,10 +113,25 @@ public class DefaultIsisInterface implements IsisInterface {
* @param isisNeighbor ISIS neighbor instance
*/
public void removeNeighbor(IsisNeighbor isisNeighbor) {
log.debug("Neighbor removed - {}", isisNeighbor.neighborMacAddress());
isisNeighbor.stopHoldingTimeCheck();
isisNeighbor.stopInactivityTimeCheck();
neighborList.remove(isisNeighbor.neighborMacAddress());
}
/**
* Removes all the neighbors.
*/
public void removeNeighbors() {
Set<MacAddress> neighbors = neighbors();
for (MacAddress mac : neighbors) {
removeNeighbor(lookup(mac));
log.debug("Neighbor removed - {}", mac);
}
neighborList.clear();
}
/**
* Returns the ISIS neighbor instance if exists.
*
* @param isisNeighborMac mac address of the neighbor router
......@@ -400,24 +414,6 @@ public class DefaultIsisInterface implements IsisInterface {
}
/**
* Returns LSP ID.
*
* @return LSP ID
*/
public String getLspId() {
return lspId;
}
/**
* Sets LSP ID.
*
* @param lspId link state packet ID
*/
public void setLspId(String lspId) {
this.lspId = lspId;
}
/**
* Returns holding time.
*
* @return holding time
......@@ -518,9 +514,21 @@ public class DefaultIsisInterface implements IsisInterface {
*/
public void processIsisMessage(IsisMessage isisMessage, IsisLsdb isisLsdb, Channel channel) {
log.debug("IsisInterfaceImpl::processIsisMessage...!!!");
if (channel == null) {
this.channel = channel;
if (isisMessage.sourceMac().equals(interfaceMacAddress)) {
log.debug("Received our own message {}...!!!", isisMessage.isisPduType());
return;
}
if (isisMessage.isisPduType() == IsisPduType.P2PHELLOPDU && networkType.equals(IsisNetworkType.BROADCAST)) {
return;
} else if ((isisMessage.isisPduType() == IsisPduType.L1HELLOPDU ||
isisMessage.isisPduType() == IsisPduType.L2HELLOPDU)
&& networkType.equals(IsisNetworkType.P2P)) {
return;
}
if (this.isisLsdb == null) {
this.isisLsdb = isisLsdb;
}
......@@ -543,7 +551,7 @@ public class DefaultIsisInterface implements IsisInterface {
break;
case L1PSNP:
case L2PSNP:
log.debug("Received a PSNP packet...!!!");
processPsnPduMessage(isisMessage, channel);
break;
default:
log.debug("Unknown packet to process...!!!");
......@@ -560,6 +568,13 @@ public class DefaultIsisInterface implements IsisInterface {
public boolean validateHelloMessage(HelloPdu helloPdu) {
boolean isValid = false;
if ((helloPdu.circuitType() == IsisRouterType.L1.value() &&
reservedPacketCircuitType == IsisRouterType.L2.value()) ||
(helloPdu.circuitType() == IsisRouterType.L2.value() &&
reservedPacketCircuitType == IsisRouterType.L1.value())) {
return false;
}
//Local InterfaceAddress TLV and compare with the IP Interface address and check if they are in same subnet
List<Ip4Address> interfaceIpAddresses = helloPdu.interfaceIpAddresses();
Ip4Address neighborIp = (helloPdu.interfaceIpAddresses() != null) ?
......@@ -569,12 +584,17 @@ public class DefaultIsisInterface implements IsisInterface {
}
//Verify if it's in same area, Areas which the router belongs to
if (helloPdu.circuitType() == IsisRouterType.L1.value()) {
List<String> areas = helloPdu.areaAddress();
for (String area : areas) {
if (areaAddress.equals(area)) {
isValid = true;
}
}
} else if (helloPdu.circuitType() == IsisRouterType.L2.value() ||
helloPdu.circuitType() == IsisRouterType.L1L2.value()) {
isValid = true;
}
return isValid;
}
......@@ -585,6 +605,7 @@ public class DefaultIsisInterface implements IsisInterface {
* @param neighborMac neighbor MAc address
* @return true if neighbor exist else false
*/
private boolean isNeighborInList(MacAddress neighborMac) {
return neighborList.containsKey(neighborMac);
}
......@@ -623,9 +644,8 @@ public class DefaultIsisInterface implements IsisInterface {
log.debug("IsisInterfaceImpl::processHelloMessage::Interface Type {} ISISInterfaceState {} ",
networkType, interfaceState);
//If L1 Hello, validate the area, network and max address
if (IsisPduType.get(helloPacket.pduType()) == IsisPduType.L1HELLOPDU &&
!validateHelloMessage(helloPacket)) {
//If validate the area, network and max address
if (!validateHelloMessage(helloPacket)) {
return;
}
......@@ -637,6 +657,7 @@ public class DefaultIsisInterface implements IsisInterface {
addNeighbouringRouter(neighbor);
}
neighbor.setHoldingTime(helloPacket.holdingTime());
neighbor.stopInactivityTimeCheck();
neighbor.startInactivityTimeCheck();
......@@ -644,34 +665,40 @@ public class DefaultIsisInterface implements IsisInterface {
String lanId = helloPacket.lanId();
if (IsisPduType.L1HELLOPDU == helloPacket.isisPduType()) {
buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel);
buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel,
IsisRouterType.get(helloPacket.circuitType()));
l1LanId = lanId;
neighbor.setL1LanId(lanId);
//if a change in lanid
} else if (IsisPduType.L2HELLOPDU == helloPacket.isisPduType()) {
buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel);
buildUpdateAndSendSelfGeneratedLspIfDisChange(l2LanId, lanId, channel,
IsisRouterType.get(helloPacket.circuitType()));
l2LanId = lanId;
neighbor.setL2LanId(lanId);
}
//Check in neighbors list our MAC address present
List<MacAddress> neighbors = helloPacket.neighborList();
if (neighbors != null) {
for (MacAddress macAddress : neighbors) {
if (interfaceMacAddress.equals(macAddress)) {
neighbor.setNeighborState(IsisInterfaceState.UP);
//Build Self LSP add in LSDB and sent it.
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel);
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel,
IsisRouterType.get(helloPacket.circuitType()));
break;
}
}
}
}
/**
* Builds and store and send self generated LSP.
*
* @param channel netty channel instance
*/
private void buildStoreAndSendSelfGeneratedLspIfNotExistInDb(Channel channel) {
private void buildStoreAndSendSelfGeneratedLspIfNotExistInDb(Channel channel, IsisRouterType neighborRouterType) {
this.channel = channel;
//Check our LSP is present in DB. else create a self LSP and store it and sent it
String lspKey = isisLsdb.lspKey(systemId);
LspWrapper wrapper = null;
......@@ -690,21 +717,28 @@ public class DefaultIsisInterface implements IsisInterface {
sendLsp(lsp, channel);
}
} else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) {
if ((neighborRouterType == IsisRouterType.L1 || neighborRouterType == IsisRouterType.L1L2)) {
wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
if (wrapper == null) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps);
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU,
allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
}
}
if ((neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2)) {
wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey);
if (wrapper == null) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU,
allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
}
}
}
}
/**
* Builds and update in DB and send self generated LSP.
......@@ -714,31 +748,37 @@ public class DefaultIsisInterface implements IsisInterface {
* @param channel netty channel instance
*/
private void buildUpdateAndSendSelfGeneratedLspIfDisChange(String previousLanId,
String latestLanId, Channel channel) {
String latestLanId, Channel channel,
IsisRouterType neighborRouterType) {
this.channel = channel;
//If DIS change then build and sent LSP
if (previousLanId != null && !previousLanId.equals(IsisConstants.DEFAULTLANID) &&
!previousLanId.equals(latestLanId)) {
if (!previousLanId.equals(latestLanId)) {
//Create a self LSP and Update it in DB and sent it
String lspKey = isisLsdb.lspKey(systemId);
if (reservedPacketCircuitType == IsisRouterType.L1.value()) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
} else if (reservedPacketCircuitType == IsisRouterType.L2.value()) {
} else if (reservedPacketCircuitType == IsisRouterType.L2.value() &&
(neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2)) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
} else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) {
//L1 LSPDU
if (neighborRouterType == IsisRouterType.L1 || neighborRouterType == IsisRouterType.L1L2) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
}
//L1 LSPDU
lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
if (neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2) {
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
isisLsdb.addLsp(lsp, true, this);
sendLsp(lsp, channel);
}
}
}
}
......@@ -756,8 +796,10 @@ public class DefaultIsisInterface implements IsisInterface {
lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
IsisConstants.CHECKSUMPOSITION + 1);
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex));
}
}
/**
* Processes P2P hello message.
......@@ -794,7 +836,7 @@ public class DefaultIsisInterface implements IsisInterface {
addNeighbouringRouter(neighbor);
}
neighbor.setNeighborState(IsisInterfaceState.DOWN);
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel);
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel, IsisRouterType.get(helloPacket.circuitType()));
} else if (stateTlv.adjacencyType() == IsisInterfaceState.DOWN.value()) {
neighbor = neighbouringRouter(isisMessage.sourceMac());
if (neighbor == null) {
......@@ -805,6 +847,10 @@ public class DefaultIsisInterface implements IsisInterface {
} else if (stateTlv.adjacencyType() == IsisInterfaceState.INITIAL.value()) {
//Neighbor already present in the list
neighbor = neighbouringRouter(isisMessage.sourceMac());
if (neighbor == null) {
neighbor = new DefaultIsisNeighbor(helloPacket, this);
addNeighbouringRouter(neighbor);
}
neighbor.setNeighborState(IsisInterfaceState.INITIAL);
neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId());
//interfaceState = IsisInterfaceState.UP;
......@@ -813,9 +859,10 @@ public class DefaultIsisInterface implements IsisInterface {
neighbor = neighbouringRouter(isisMessage.sourceMac());
neighbor.setNeighborState(IsisInterfaceState.UP);
neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId());
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel);
buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel, IsisRouterType.get(helloPacket.circuitType()));
}
neighbor.setHoldingTime(helloPacket.holdingTime());
neighbor.stopInactivityTimeCheck();
neighbor.startInactivityTimeCheck();
}
......@@ -828,12 +875,37 @@ public class DefaultIsisInterface implements IsisInterface {
*/
public void processLsPduMessage(IsisMessage isisMessage, Channel channel) {
log.debug("Enters processLsPduMessage ...!!!");
IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
return;
}
LsPdu lsPdu = (LsPdu) isisMessage;
LspWrapper wrapper = isisLsdb.findLsp(lsPdu.isisPduType(), lsPdu.lspId());
if (wrapper == null || isisLsdb.isNewerOrSameLsp(lsPdu, wrapper.lsPdu()).equalsIgnoreCase("latest")) {
if (wrapper != null) { // verify if the LSA - is your own LSA - get system ID and compare LSP
String lspKey = isisLsdb.lspKey(systemId);
if (lsPdu.lspId().equals(lspKey)) {
lsPdu.setSequenceNumber(lsPdu.sequenceNumber() + 1);
if (lsPdu.pduType() == IsisPduType.L1LSPDU.value()) {
// setting the ls sequence number
isisLsdb.setL1LspSeqNo(lsPdu.sequenceNumber());
} else if (lsPdu.pduType() == IsisPduType.L2LSPDU.value()) {
// setting the ls sequence number
isisLsdb.setL2LspSeqNo(lsPdu.sequenceNumber());
}
isisLsdb.addLsp(lsPdu, true, this);
sendLsp(lsPdu, channel);
} else {
isisLsdb.addLsp(lsPdu, false, this);
}
} else {
//not exist in the database or latest, then add it in database
isisLsdb.addLsp(lsPdu, false, this);
}
}
//If network type is P2P, acknowledge with a PSNP
if (networkType() == IsisNetworkType.P2P) {
......@@ -865,39 +937,29 @@ public class DefaultIsisInterface implements IsisInterface {
IsisConstants.RESERVEDPOSITION);
flagValue = false;
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
}
}
}
/**
* Processes CSN PDU message.
* Processes PSN PDU message.
* Checks for self originated LSP entries in PSNP message and sends the missing LSP.
*
* @param isisMessage CSN PDU message instance
* @param isisMessage PSN PDU message instance
* @param channel channel instance
*/
public void processCsnPduMessage(IsisMessage isisMessage, Channel channel) {
log.debug("Enters processCsnPduMessage ...!!!");
if (reservedPacketCircuitType == IsisRouterType.L1.value()) {
processOnL1CsnPdu(isisMessage, channel);
} else if (reservedPacketCircuitType == IsisRouterType.L2.value()) {
processOnL2CsnPdu(isisMessage, channel);
}
public void processPsnPduMessage(IsisMessage isisMessage, Channel channel) {
log.debug("Enters processPsnPduMessage ...!!!");
//If adjacency not formed don't process.
IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
return;
}
/**
* Process the isisMessage which belongs to L1 CSN PDU.
* checks the database for this LsPdu if it exists further check for sequence number
* sequence number is greater will send PsnPdu.
*
* @param isisMessage CSN PDU message instance
* @param channel netty channel instance
*/
private void processOnL1CsnPdu(IsisMessage isisMessage, Channel channel) {
Csnp csnPacket = (Csnp) isisMessage;
List<LspEntry> lspEntryRequestList = new ArrayList<>();
boolean selfOriginatedFound = false;
if (IsisPduType.L1CSNP.equals(csnPacket.isisPduType())) {
List<IsisTlv> isisTlvs = csnPacket.getAllTlv();
Psnp psnPacket = (Psnp) isisMessage;
List<IsisTlv> isisTlvs = psnPacket.getAllTlv();
Iterator iterator = isisTlvs.iterator();
while (iterator.hasNext()) {
IsisTlv isisTlv = (IsisTlv) iterator.next();
......@@ -908,52 +970,39 @@ public class DefaultIsisInterface implements IsisInterface {
while (lspEntryListIterator.hasNext()) {
LspEntry lspEntry = (LspEntry) lspEntryListIterator.next();
String lspKey = lspEntry.lspId();
LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
LspWrapper lspWrapper = isisLsdb.findLsp(psnPacket.isisPduType(), lspKey);
if (lspWrapper != null) {
LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu();
if (lspWrapper.isSelfOriginated()) {
selfOriginatedFound = true;
if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) {
sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel);
}
} else {
if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) {
lspEntryRequestList.add(lspEntry);
flagValue = true;
//Sent the LSP
sendLsp((LsPdu) lspWrapper.lsPdu(), channel);
}
}
} else {
lspEntryRequestList.add(lspEntry);
flagValue = true;
}
}
}
}
if (flagValue) {
sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel);
}
if (!selfOriginatedFound) {
String lspKey = isisLsdb.lspKey(systemId);
LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
sendLsp((LsPdu) wrapper.lsPdu(), channel);
}
}
}
/**
* Process the isisMessage which belongs to L2 CSNP.
* checks the database for this LsPdu if it exists further check for sequence number
* sequence number is greater will send PsnPdu.
* Processes CSN PDU message.
*
* @param isisMessage received CSNP message
* @param channel netty channel instance
* @param isisMessage CSN PDU message instance
* @param channel channel instance
*/
private void processOnL2CsnPdu(IsisMessage isisMessage, Channel channel) {
public void processCsnPduMessage(IsisMessage isisMessage, Channel channel) {
log.debug("Enters processCsnPduMessage ...!!!");
IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
return;
}
Csnp csnPacket = (Csnp) isisMessage;
IsisPduType psnPduType = (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) ?
IsisPduType.L2PSNP : IsisPduType.L1PSNP;
IsisPduType lsPduType = (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) ?
IsisPduType.L2LSPDU : IsisPduType.L1LSPDU;
List<LspEntry> lspEntryRequestList = new ArrayList<>();
boolean selfOriginatedFound = false;
if (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) {
List<IsisTlv> isisTlvs = csnPacket.getAllTlv();
Iterator iterator = isisTlvs.iterator();
while (iterator.hasNext()) {
......@@ -965,13 +1014,13 @@ public class DefaultIsisInterface implements IsisInterface {
while (lspEntryListIterator.hasNext()) {
LspEntry lspEntry = (LspEntry) lspEntryListIterator.next();
String lspKey = lspEntry.lspId();
LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey);
LspWrapper lspWrapper = isisLsdb.findLsp(lsPduType, lspKey);
if (lspWrapper != null) {
LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu();
if (lspWrapper.isSelfOriginated()) {
selfOriginatedFound = true;
if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) {
sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel);
if (lspEntry.lspSequenceNumber() < lsPdu.sequenceNumber()) {
sendLsp(lsPdu, channel);
}
} else {
if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) {
......@@ -987,13 +1036,14 @@ public class DefaultIsisInterface implements IsisInterface {
}
}
if (flagValue) {
sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel);
sendPsnPduMessage(lspEntryRequestList, psnPduType, channel);
lspEntryRequestList.clear();
}
if (!selfOriginatedFound) {
String lspKey = isisLsdb.lspKey(systemId);
LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey);
LspWrapper wrapper = isisLsdb.findLsp(lsPduType, lspKey);
if (wrapper != null) {
sendLsp((LsPdu) wrapper.lsPdu(), channel);
}
}
......@@ -1007,13 +1057,7 @@ public class DefaultIsisInterface implements IsisInterface {
* @param channel netty channel instance
*/
private void sendPsnPduMessage(List<LspEntry> lspEntryRequestList, IsisPduType isisPduType, Channel channel) {
IsisPduType psnpType = null;
if (isisPduType == IsisPduType.L1CSNP) {
psnpType = IsisPduType.L1PSNP;
} else if (reservedPacketCircuitType == IsisRouterType.L2.value()) {
psnpType = IsisPduType.L2PSNP;
}
IsisHeader isisHeader = new LspGenerator().getHeader(psnpType);
IsisHeader isisHeader = new LspGenerator().getHeader(isisPduType);
Psnp psnp = new Psnp(isisHeader);
psnp.setSourceId(lspKeyP2P(this.systemId));
TlvHeader tlvHeader = new TlvHeader();
......@@ -1021,6 +1065,9 @@ public class DefaultIsisInterface implements IsisInterface {
tlvHeader.setTlvLength(0);
LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
for (LspEntry lspEntry : lspEntryRequestList) {
lspEntry.setLspChecksum(0);
lspEntry.setLspSequenceNumber(0);
lspEntry.setRemainingTime(0);
lspEntriesTlv.addLspEntry(lspEntry);
}
psnp.addTlv(lspEntriesTlv);
......@@ -1031,8 +1078,10 @@ public class DefaultIsisInterface implements IsisInterface {
IsisConstants.RESERVEDPOSITION);
flagValue = false;
//write to the channel
if (channel != null && channel.isConnected() && channel.isOpen()) {
channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
}
}
/**
* Gets the LSP key.
......@@ -1048,28 +1097,6 @@ public class DefaultIsisInterface implements IsisInterface {
}
/**
* Sends the link state PDU with latest self generated lsp entry.
*
* @param sequenceNumber sequence number of the self generated lsp
* @param isisPduType intermediate system type
* @param channel netty channel instance
*/
private void sendLsPduMessage(int sequenceNumber, IsisPduType isisPduType, Channel channel) {
String lspKey = isisLsdb.lspKey(systemId);
LsPdu lsp = new LspGenerator().getLsp(this, lspKey, isisPduType, allConfiguredInterfaceIps);
lsp.setSequenceNumber(sequenceNumber);
byte[] lspBytes = lsp.asBytes();
lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION,
IsisConstants.LENGTHPOSITION + 1,
IsisConstants.RESERVEDPOSITION);
lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
IsisConstants.CHECKSUMPOSITION + 1);
//write to the channel
channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex));
}
/**
* Starts the hello timer which sends hello packet every configured seconds.
*
* @param channel netty channel instance
......@@ -1083,4 +1110,12 @@ public class DefaultIsisInterface implements IsisInterface {
exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0,
helloInterval, TimeUnit.SECONDS);
}
/**
* Stops the hello timer which sends hello packet every configured seconds.
*/
public void stopHelloSender() {
log.debug("IsisInterfaceImpl::stopHelloSender");
exServiceHello.shutdown();
}
}
\ 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 {
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;
}
......
......@@ -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,8 +232,16 @@ 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()));
}
}
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.isis.controller.impl;
import org.easymock.EasyMock;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -23,15 +27,30 @@ import org.onlab.packet.MacAddress;
import org.onosproject.isis.controller.IsisInterface;
import org.onosproject.isis.controller.IsisInterfaceState;
import org.onosproject.isis.controller.IsisLsdb;
import org.onosproject.isis.controller.IsisMessage;
import org.onosproject.isis.controller.IsisNeighbor;
import org.onosproject.isis.controller.IsisNetworkType;
import org.onosproject.isis.controller.IsisPduType;
import org.onosproject.isis.controller.IsisRouterType;
import org.onosproject.isis.controller.impl.lsdb.DefaultIsisLsdb;
import org.onosproject.isis.io.isispacket.IsisHeader;
import org.onosproject.isis.io.isispacket.pdu.HelloPdu;
import org.onosproject.isis.io.isispacket.pdu.Csnp;
import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
import org.onosproject.isis.io.isispacket.pdu.Psnp;
import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv;
import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
import org.onosproject.isis.io.isispacket.tlv.LspEntriesTlv;
import org.onosproject.isis.io.isispacket.tlv.LspEntry;
import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
import org.onosproject.isis.io.isispacket.tlv.TlvType;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
/**
......@@ -39,16 +58,26 @@ import static org.junit.Assert.assertThat;
*/
public class DefaultIsisInterfaceTest {
private final MacAddress macAddress = MacAddress.valueOf("AA:BB:CC:DD:EE:FF");
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
private final MacAddress macAddress1 = MacAddress.valueOf("AA:CC:CC:DD:EE:FF");
private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.0.0");
private final byte[] mask = {
(byte) 255, (byte) 255, (byte) 255, (byte) 224
};
private final byte[] mask1 = {
(byte) 0, (byte) 0, (byte) 0, (byte) 0
};
private final String intSysName = "ROUTER";
private final String sysId = "1111.1111.1111";
private final String areaAddr = "49.002";
private final byte[] csnpBytes = {
0, 67, 18, 52, 18, 52, 0,
18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
-1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0,
0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0,
0, 0, 0, 0, 1, 91, 126
};
private IsisInterfaceState resultIfState;
private DefaultIsisInterface defaultIsisInterface;
private HelloPdu helloPdu;
private IsisHeader isisHeader;
private IsisInterface isisInterface;
private Set<MacAddress> resultSet;
......@@ -60,18 +89,35 @@ public class DefaultIsisInterfaceTest {
private byte[] resultByteArr;
private String resultStr;
private IsisNetworkType resultNwType;
private List<Ip4Address> ip4Addresses = new ArrayList<>();
private DefaultIsisNeighbor defaultIsisNeighbor;
private IsisNeighbor result;
private IsisLsdb result1;
private Set<MacAddress> result2;
private Channel result3;
private IsisMessage isisMessage;
private IsisLsdb isisLsdb;
private Channel channel;
private L1L2HelloPdu helloPdu;
private LsPdu lsPdu;
private Csnp csnp;
private Psnp psnp;
private P2PHelloPdu p2PHelloPdu;
private boolean result4;
private String result5;
@Before
public void setUp() throws Exception {
channel = EasyMock.createNiceMock(Channel.class);
defaultIsisInterface = new DefaultIsisInterface();
defaultIsisInterface.setInterfaceMacAddress(macAddress);
isisHeader = new IsisHeader();
isisHeader.setIrpDiscriminator((byte) 1);
helloPdu = new L1L2HelloPdu(isisHeader);
isisInterface = new DefaultIsisInterface();
resultNeighborList = new DefaultIsisNeighbor(helloPdu, isisInterface);
defaultIsisNeighbor = new DefaultIsisNeighbor(helloPdu, isisInterface);
defaultIsisNeighbor.setNeighborMacAddress(macAddress);
isisLsdb = new DefaultIsisLsdb();
}
@After
......@@ -365,26 +411,6 @@ public class DefaultIsisInterfaceTest {
}
/**
* Tests getLspId() getter method.
*/
@Test
public void testGetLspId() throws Exception {
defaultIsisInterface.setLspId(sysId);
resultStr = defaultIsisInterface.getLspId();
assertThat(resultStr, is(sysId));
}
/**
* Tests getLspId() setter method.
*/
@Test
public void testSetLspId() throws Exception {
defaultIsisInterface.setLspId(sysId);
resultStr = defaultIsisInterface.getLspId();
assertThat(resultStr, is(sysId));
}
/**
* Tests holdingTime() getter method.
*/
@Test
......@@ -483,4 +509,369 @@ public class DefaultIsisInterfaceTest {
resultStr = defaultIsisInterface.circuitId();
assertThat(resultStr, is(sysId));
}
/**
* Tests setAllConfiguredInterfaceIps() setter method.
*/
@Test
public void testSetAllConfiguredInterfaceIps() throws Exception {
ip4Addresses.add(ip4Address);
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests setAllConfiguredInterfaceIps() method.
*/
@Test
public void testRemoveNeighbor() throws Exception {
defaultIsisInterface.removeNeighbor(defaultIsisNeighbor);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests lookup() method.
*/
@Test
public void testLookup() throws Exception {
result = defaultIsisInterface.lookup(defaultIsisNeighbor.neighborMacAddress());
assertThat(result, is(nullValue()));
}
/**
* Tests isisLsdb() method.
*/
@Test
public void testIsisLsdb() throws Exception {
result1 = defaultIsisInterface.isisLsdb();
assertThat(result1, is(nullValue()));
}
/**
* Tests neighbors() method.
*/
@Test
public void testNeighbors() throws Exception {
result2 = defaultIsisInterface.neighbors();
assertThat(result2, is(notNullValue()));
}
/**
* Tests channel() method.
*/
@Test
public void testChannel() throws Exception {
result3 = defaultIsisInterface.channel();
assertThat(result3, is(nullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test
public void testProcessIsisMessage() throws Exception {
helloPdu = new L1L2HelloPdu(isisHeader);
helloPdu.setSourceMac(macAddress1);
helloPdu.setIsisPduType(IsisPduType.L2HELLOPDU.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.BROADCAST);
isisMessage = helloPdu;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessIsisMessage1() throws Exception {
lsPdu = new LsPdu(isisHeader);
lsPdu.setSourceMac(macAddress1);
lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
isisMessage = lsPdu;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test
public void testProcessIsisMessage2() throws Exception {
csnp = new Csnp(isisHeader);
csnp.setSourceMac(macAddress1);
csnp.setIsisPduType(IsisPduType.L2CSNP.value());
isisMessage = csnp;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test
public void testProcessIsisMessage3() throws Exception {
psnp = new Psnp(isisHeader);
psnp.setSourceMac(macAddress1);
psnp.setIsisPduType(IsisPduType.L2PSNP.value());
isisMessage = psnp;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processIsisMessage() method.
*/
@Test
public void testProcessIsisMessage4() throws Exception {
p2PHelloPdu = new P2PHelloPdu(isisHeader);
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
isisMessage = p2PHelloPdu;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests validateHelloMessage() method.
*/
@Test
public void testValidateHelloMessage() throws Exception {
helloPdu = new L1L2HelloPdu(isisHeader);
result4 = defaultIsisInterface.validateHelloMessage(helloPdu);
assertThat(result4, is(false));
}
/**
* Tests processL1L2HelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessL1L2HelloPduMessage() throws Exception {
helloPdu = new L1L2HelloPdu(isisHeader);
helloPdu.setSourceMac(macAddress1);
helloPdu.setCircuitType((byte) IsisRouterType.L2.value());
defaultIsisInterface.processL1L2HelloPduMessage(helloPdu, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processP2pHelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processP2pHelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee1() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L2.value());
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
defaultIsisInterface.setInterfaceIpAddress(ip4Address);
defaultIsisInterface.setNetworkMask(mask1);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processP2pHelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee2() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(areaAddr);
p2PHelloPdu.addTlv(areaAddressTlv);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value());
defaultIsisInterface.setAreaAddress(areaAddr);
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
defaultIsisInterface.setInterfaceIpAddress(ip4Address);
defaultIsisInterface.setNetworkMask(mask1);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processP2pHelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee3() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
adjacencyStateTlv.setNeighborSystemId(sysId);
adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value());
p2PHelloPdu.addTlv(adjacencyStateTlv);
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(areaAddr);
p2PHelloPdu.addTlv(areaAddressTlv);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value());
defaultIsisInterface.setAreaAddress(areaAddr);
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
defaultIsisInterface.setInterfaceIpAddress(ip4Address);
defaultIsisInterface.setNetworkMask(mask1);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processP2pHelloPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee4() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
adjacencyStateTlv.setNeighborSystemId(sysId);
adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.INITIAL.value());
p2PHelloPdu.addTlv(adjacencyStateTlv);
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(areaAddr);
p2PHelloPdu.addTlv(areaAddressTlv);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value());
defaultIsisInterface.setAreaAddress(areaAddr);
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
defaultIsisInterface.setInterfaceIpAddress(ip4Address);
defaultIsisInterface.setNetworkMask(mask1);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
@Test(expected = Exception.class)
public void testProcessP2pHelloPduMessagee5() throws Exception {
defaultIsisInterface.setSystemId(sysId);
p2PHelloPdu = new P2PHelloPdu(isisHeader);
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
adjacencyStateTlv.setNeighborSystemId(sysId);
adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.UP.value());
p2PHelloPdu.addTlv(adjacencyStateTlv);
tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
areaAddressTlv.addAddress(areaAddr);
p2PHelloPdu.addTlv(areaAddressTlv);
p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
p2PHelloPdu.setSourceMac(macAddress1);
p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value());
defaultIsisInterface.setAreaAddress(areaAddr);
defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
defaultIsisInterface.setInterfaceIpAddress(ip4Address);
defaultIsisInterface.setNetworkMask(mask1);
defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests startHelloSender() method.
*/
@Test(expected = Exception.class)
public void testStartHelloSender() throws Exception {
defaultIsisInterface.startHelloSender(channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests lspKeyP2P() method.
*/
@Test
public void testLspKeyP2P() throws Exception {
result5 = defaultIsisInterface.lspKeyP2P(sysId);
assertThat(result5, is(notNullValue()));
}
/**
* Tests processLsPduMessage() method.
*/
@Test
public void testProcessLsPduMessage() throws Exception {
lsPdu = new LsPdu(isisHeader);
lsPdu.setSourceMac(macAddress1);
lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
lsPdu.setLspId(sysId);
isisMessage = lsPdu;
defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
defaultIsisInterface.setSystemId(sysId);
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processPsnPduMessage() method.
*/
@Test
public void testProcessPsnPduMessage() throws Exception {
psnp = new Psnp(isisHeader);
psnp.setSourceMac(macAddress1);
psnp.setIsisPduType(IsisPduType.L2PSNP.value());
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.LSPENTRY.value());
tlvHeader.setTlvLength(0);
LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
LspEntry lspEntry = new LspEntry();
lspEntry.setLspChecksum(0);
lspEntry.setLspSequenceNumber(0);
lspEntry.setRemainingTime(0);
lspEntriesTlv.addLspEntry(lspEntry);
psnp.addTlv(lspEntriesTlv);
isisMessage = psnp;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, is(notNullValue()));
}
/**
* Tests processCsnPduMessage() method.
*/
@Test(expected = Exception.class)
public void testProcessCsnPduMessage() throws Exception {
ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes);
csnp = new Csnp(isisHeader);
csnp.readFrom(channelBuffer);
csnp.setSourceMac(macAddress1);
csnp.setIsisPduType(IsisPduType.L2CSNP.value());
isisMessage = csnp;
defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
assertThat(defaultIsisInterface, 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
......
......@@ -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);
......
......@@ -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);
......