Manikandan K
Committed by Gerrit Code Review

ONOS-4107: ISIS Provider - Bug Fixes

Change-Id: I3c5cb3d1f45f7cf417267fe975256cba2dd066ab
......@@ -45,8 +45,6 @@ import java.util.concurrent.BlockingQueue;
public class LspEventConsumer implements Runnable {
private static final Logger log = LoggerFactory.getLogger(LspEventConsumer.class);
public static List<LsPdu> lsPdus = new ArrayList<>();
private String lspAdded = "LSP_ADDED";
private String lspRemoved = "LSP_REMOVED";
private BlockingQueue queue = null;
private Controller controller = null;
private TopologyForDeviceAndLinkImpl deviceAndLink = new TopologyForDeviceAndLinkImpl();
......@@ -64,28 +62,25 @@ public class LspEventConsumer implements Runnable {
@Override
public void run() {
log.debug("LspsForProvider:run...!!!");
try {
while (true) {
if (!queue.isEmpty()) {
LspWrapper wrapper = (LspWrapper) queue.take();
LsPdu lsPdu = (LsPdu) wrapper.lsPdu();
if (wrapper.lspProcessing().equals(IsisConstants.LSPREMOVED)) {
callTopologyToRemoveInfo(lsPdu);
} else if (wrapper.lspProcessing().equals(IsisConstants.LSPADDED)) {
for (IsisTlv isisTlv : lsPdu.tlvs()) {
if ((isisTlv instanceof IpExtendedReachabilityTlv) ||
(isisTlv instanceof IsExtendedReachability)) {
lsPdus.add(lsPdu);
if (wrapper.lspProcessing().equals(lspAdded)) {
callTopologyToSendInfo(lsPdu, wrapper.isisInterface().networkType(),
wrapper.isisInterface().systemId() + ".00");
}
if (wrapper.lspProcessing().equals(lspRemoved)) {
callTopologyToRemoveInfo(lsPdu);
}
break;
}
}
}
}
}
} catch (Exception e) {
log.debug("Error::LspsForProvider::{}", e.getMessage());
}
......@@ -99,6 +94,9 @@ public class LspEventConsumer implements Runnable {
*/
private void callTopologyToSendInfo(LsPdu lsPdu, IsisNetworkType isisNetworkType,
String ownSystemId) {
if ((lsPdu.lspId().equals(ownSystemId + "-00"))) {
return;
}
if (isisNetworkType.equals(IsisNetworkType.BROADCAST)) {
sendDeviceInfo(lsPdu);
boolean isDis = IsisUtil.checkIsDis(lsPdu.lspId());
......@@ -106,9 +104,7 @@ public class LspEventConsumer implements Runnable {
sendLinkInfo(lsPdu, ownSystemId);
}
} else if (isisNetworkType.equals(IsisNetworkType.P2P)) {
sendDeviceInfo(lsPdu);
for (LsPdu wrapper : lsPdus) {
LsPdu lsPduStored = wrapper;
List<String> neStringList = neighborList(lsPduStored, ownSystemId);
......@@ -117,7 +113,6 @@ public class LspEventConsumer implements Runnable {
sendLinkInfo(lsPduStored, ownSystemId);
}
}
List<String> neStringList = neighborList(lsPdu, ownSystemId);
Map<String, IsisRouter> routerPresence = deviceAndLink.isisDeviceList();
for (String neighbor : neStringList) {
......@@ -137,7 +132,8 @@ public class LspEventConsumer implements Runnable {
* @param lsPdu ls pdu instance
*/
private void callTopologyToRemoveInfo(LsPdu lsPdu) {
removeDeviceInfo(lsPdu);
IsisRouter isisRouter = deviceAndLink.isisRouter(lsPdu.lspId());
removeDeviceInfo(isisRouter);
removeLinkInfo(lsPdu);
}
......@@ -195,13 +191,13 @@ public class LspEventConsumer implements Runnable {
/**
* Removes the device information from topology provider.
*
* @param lsPdu ls pdu instance
* @param isisRouter ISIS router instance
*/
private void removeDeviceInfo(LsPdu lsPdu) {
IsisRouter isisRouter = deviceAndLink.removeDeviceAndLinkInfo(lsPdu);
private void removeDeviceInfo(IsisRouter isisRouter) {
if (isisRouter.systemId() != null) {
controller.removeDeviceDetails(isisRouter);
}
deviceAndLink.removeRouter(isisRouter.systemId());
}
/**
......@@ -228,7 +224,7 @@ public class LspEventConsumer implements Runnable {
* @param lsPdu ls pdu instance
*/
private void removeLinkInfo(LsPdu lsPdu) {
Map<String, LinkInformation> linkInformationList = deviceAndLink.removeLinkInfo(lsPdu);
Map<String, LinkInformation> linkInformationList = deviceAndLink.removeLinkInfo(lsPdu.lspId());
for (String key : linkInformationList.keySet()) {
LinkInformation linkInformation = linkInformationList.get(key);
controller.removeLinkDetails(createIsisLink(linkInformation, lsPdu));
......
......@@ -22,21 +22,24 @@ import org.onosproject.isis.controller.topology.LinkInformation;
import org.onosproject.isis.controller.topology.TopologyForDeviceAndLink;
import org.onosproject.isis.controller.topology.IsisLinkTed;
import org.onosproject.isis.io.isispacket.pdu.LsPdu;
import org.onosproject.isis.io.isispacket.tlv.IpExtendedReachabilityTlv;
import org.onosproject.isis.io.isispacket.tlv.IsExtendedReachability;
import org.onosproject.isis.io.isispacket.tlv.IsisTlv;
import org.onosproject.isis.io.isispacket.tlv.NeighborForExtendedIs;
import org.onosproject.isis.io.isispacket.tlv.subtlv.AdministrativeGroup;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
import org.onosproject.isis.io.isispacket.tlv.subtlv.InterfaceIpAddress;
import org.onosproject.isis.io.isispacket.tlv.subtlv.NeighborIpAddress;
import org.onosproject.isis.io.isispacket.tlv.subtlv.AdministrativeGroup;
import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringMetric;
import org.onosproject.isis.io.isispacket.tlv.subtlv.UnreservedBandwidth;
import org.onosproject.isis.io.isispacket.tlv.subtlv.MaximumReservableBandwidth;
import org.onosproject.isis.io.isispacket.tlv.subtlv.MaximumBandwidth;
import org.onosproject.isis.io.util.IsisConstants;
import org.onosproject.isis.io.util.IsisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -52,7 +55,6 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
private Map<String, DeviceInformation> deviceInformationMapForPointToPoint = new LinkedHashMap<>();
private Map<String, DeviceInformation> deviceInformationMapToDelete = new LinkedHashMap<>();
private Map<String, LinkInformation> addedLinkInformationMap = new LinkedHashMap<>();
private Map<String, LinkInformation> removeLinkInformationMap = new LinkedHashMap<>();
/**
* Gets device information.
......@@ -226,11 +228,33 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
}
/**
* Creates Device and Link instance.
* Returns the ISIS router instance.
*
* @param lsPdu ISIS LSPDU instance
* @param systemId system ID to get router details
* @return ISIS router instance
*/
public IsisRouter isisRouter(String systemId) {
String routerId = IsisUtil.removeTailingZeros(systemId);
IsisRouter isisRouter = isisRouterDetails.get(routerId);
if (isisRouter != null) {
return isisRouter;
} else {
log.debug("IsisRouter is not available");
IsisRouter isisRouterCheck = new DefaultIsisRouter();
isisRouterCheck.setSystemId(routerId);
return isisRouterCheck;
}
}
/**
* Removes the ISIS router instance from map.
*
* @param systemId system ID to remove router details
*/
public void removeRouter(String systemId) {
String routerId = IsisUtil.removeTailingZeros(systemId);
isisRouterDetails.remove(systemId);
}
/**
* Creates Device instance.
......@@ -249,18 +273,18 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
}
}
return isisRouter;
}
}/*
/**
*//**
* Removes Device and Link instance.
*
* @param lsPdu ISIS LSPDU instance
* @return isisRouter isisRouter instance
*/
*//*
public IsisRouter removeDeviceAndLinkInfo(LsPdu lsPdu) {
IsisRouter isisRouter = createIsisRouter(lsPdu);
return isisRouter;
}
}*/
/**
* Creates link information.
......@@ -302,13 +326,14 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
/**
* Removes link information.
*
* @param lsPdu ls pdu instance
* @param systemId system ID to remove link information
* @return updated link information
*/
public Map<String, LinkInformation> removeLinkInfo(LsPdu lsPdu) {
String lspId = lsPdu.lspId();
public Map<String, LinkInformation> removeLinkInfo(String systemId) {
String routerId = IsisUtil.removeTailingZeros(systemId);
Map<String, LinkInformation> removeLinkInformationMap = new LinkedHashMap<>();
for (String key : addedLinkInformationMap.keySet()) {
if (key.contains(lspId)) {
if (key.contains(routerId)) {
removeLinkInformationMap.put(key, addedLinkInformationMap.get(key));
}
}
......@@ -328,22 +353,24 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
LinkInformation linkInformation = new DefaultIsisLinkInformation();
IsisRouter isisRouter = isisRouterDetails.get(neighborId);
for (IsisTlv isisTlv : lsPdu.tlvs()) {
if (isisTlv instanceof IpExtendedReachabilityTlv) {
IpExtendedReachabilityTlv ipExtendedReachabilityTlv = (IpExtendedReachabilityTlv) isisTlv;
List<TrafficEngineeringSubTlv> trafEnginSubTlv = ipExtendedReachabilityTlv.teTlvs();
for (TrafficEngineeringSubTlv teTlv : trafEnginSubTlv) {
if (teTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress localIpAddress = (InterfaceIpAddress) isisTlv;
if (isisTlv instanceof IsExtendedReachability) {
IsExtendedReachability isExtendedReachability = (IsExtendedReachability) isisTlv;
List<NeighborForExtendedIs> neighbours = isExtendedReachability.neighbours();
for (NeighborForExtendedIs teTlv : neighbours) {
List<TrafficEngineeringSubTlv> teSubTlvs = teTlv.teSubTlv();
for (TrafficEngineeringSubTlv teSubTlv : teSubTlvs) {
if (teSubTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress localIpAddress = (InterfaceIpAddress) teSubTlv;
linkInformation.setInterfaceIp(localIpAddress.localInterfaceIPAddress());
} else if (teSubTlv instanceof NeighborIpAddress) {
NeighborIpAddress neighborIpAddress = (NeighborIpAddress) teSubTlv;
linkInformation.setNeighborIp(neighborIpAddress.neighborIPAddress());
}
}
} else {
linkInformation.setInterfaceIp(IsisConstants.DEFAULTIP);
linkInformation.setNeighborIp(IsisConstants.DEFAULTIP);
}
}
linkInformation.setNeighborIp(IsisConstants.DEFAULTIP);
}
linkInformation.setLinkId(linkId);
linkInformation.setAlreadyCreated(false);
linkInformation.setLinkDestinationId(neighborId);
......@@ -366,21 +393,22 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
}
isisRouter.setSystemId(IsisUtil.removeTailingZeros(lsPdu.lspId()));
for (IsisTlv isisTlv : lsPdu.tlvs()) {
if (isisTlv instanceof IpExtendedReachabilityTlv) {
IpExtendedReachabilityTlv ipExtendedReachabilityTlv = (IpExtendedReachabilityTlv) isisTlv;
List<TrafficEngineeringSubTlv> trafEnginSubTlv = ipExtendedReachabilityTlv.teTlvs();
for (TrafficEngineeringSubTlv teTlv : trafEnginSubTlv) {
if (teTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress localIpAddress = (InterfaceIpAddress) isisTlv;
if (isisTlv instanceof IsExtendedReachability) {
IsExtendedReachability isExtendedReachability = (IsExtendedReachability) isisTlv;
List<NeighborForExtendedIs> neighbours = isExtendedReachability.neighbours();
for (NeighborForExtendedIs teTlv : neighbours) {
List<TrafficEngineeringSubTlv> teSubTlvs = teTlv.teSubTlv();
for (TrafficEngineeringSubTlv teSubTlv : teSubTlvs) {
if (teSubTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress localIpAddress = (InterfaceIpAddress) teSubTlv;
isisRouter.setInterfaceId(localIpAddress.localInterfaceIPAddress());
}
if (teTlv instanceof NeighborIpAddress) {
NeighborIpAddress neighborIpAddress = (NeighborIpAddress) isisTlv;
} else if (teSubTlv instanceof NeighborIpAddress) {
NeighborIpAddress neighborIpAddress = (NeighborIpAddress) teSubTlv;
isisRouter.setNeighborRouterId(neighborIpAddress.neighborIPAddress());
}
}
}
} else {
log.info("Invalid TLV");
}
}
return isisRouter;
......@@ -398,6 +426,7 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
isisRouter.setDis(false);
isisRouter.setInterfaceId(IsisConstants.DEFAULTIP);
isisRouter.setNeighborRouterId(IsisConstants.DEFAULTIP);
return isisRouter;
}
......@@ -410,26 +439,50 @@ public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
public IsisLinkTed createIsisLinkTedInfo(LsPdu lsPdu) {
IsisLinkTed isisLinkTed = new DefaultIsisLinkTed();
for (IsisTlv isisTlv : lsPdu.tlvs()) {
if (isisTlv instanceof IpExtendedReachabilityTlv) {
IpExtendedReachabilityTlv ipExtendedReachabilityTlv = (IpExtendedReachabilityTlv) isisTlv;
List<TrafficEngineeringSubTlv> trafficEngSubTlv = ipExtendedReachabilityTlv.teTlvs();
for (TrafficEngineeringSubTlv teTlv : trafficEngSubTlv) {
if (teTlv instanceof AdministrativeGroup) {
AdministrativeGroup ag = (AdministrativeGroup) isisTlv;
if (isisTlv instanceof IsExtendedReachability) {
IsExtendedReachability isExtendedReachability = (IsExtendedReachability) isisTlv;
List<NeighborForExtendedIs> neighbours = isExtendedReachability.neighbours();
for (NeighborForExtendedIs teTlv : neighbours) {
List<TrafficEngineeringSubTlv> teSubTlvs = teTlv.teSubTlv();
for (TrafficEngineeringSubTlv teSubTlv : teSubTlvs) {
if (teSubTlv instanceof AdministrativeGroup) {
AdministrativeGroup ag = (AdministrativeGroup) teSubTlv;
isisLinkTed.setAdministrativeGroup(ag.administrativeGroup());
}
if (teTlv instanceof TrafficEngineeringMetric) {
TrafficEngineeringMetric teM = (TrafficEngineeringMetric) isisTlv;
if (teSubTlv instanceof InterfaceIpAddress) {
InterfaceIpAddress localIpAddress = (InterfaceIpAddress) teSubTlv;
isisLinkTed.setIpv4InterfaceAddress(localIpAddress.localInterfaceIPAddress());
}
if (teSubTlv instanceof NeighborIpAddress) {
NeighborIpAddress neighborIpAddress = (NeighborIpAddress) teSubTlv;
isisLinkTed.setIpv4NeighborAddress(neighborIpAddress.neighborIPAddress());
}
if (teSubTlv instanceof TrafficEngineeringMetric) {
TrafficEngineeringMetric teM = (TrafficEngineeringMetric) teSubTlv;
isisLinkTed.setTeDefaultMetric(teM.getTrafficEngineeringMetricValue());
}
if (teTlv instanceof MaximumReservableBandwidth) {
MaximumReservableBandwidth reservableBw = (MaximumReservableBandwidth) isisTlv;
if (teSubTlv instanceof MaximumBandwidth) {
MaximumBandwidth maxLinkBandwidth = (MaximumBandwidth) teSubTlv;
isisLinkTed.setMaximumLinkBandwidth(
Bandwidth.bps(maxLinkBandwidth.getMaximumBandwidthValue()));
}
if (teSubTlv instanceof MaximumReservableBandwidth) {
MaximumReservableBandwidth maxReservableBw = (MaximumReservableBandwidth) teSubTlv;
isisLinkTed.setMaximumReservableLinkBandwidth(
Bandwidth.bps(reservableBw.getMaximumBandwidthValue()));
Bandwidth.bps(maxReservableBw.getMaximumBandwidthValue()));
}
if (teSubTlv instanceof UnreservedBandwidth) {
UnreservedBandwidth unReservedBandwidth = (UnreservedBandwidth) teSubTlv;
List<Bandwidth> bandwidthList = new ArrayList<>();
List<Float> unReservedBandwidthList = unReservedBandwidth.unReservedBandwidthValue();
for (Float unReservedBandwidthFloatValue : unReservedBandwidthList) {
Bandwidth bandwidth = Bandwidth.bps(unReservedBandwidthFloatValue);
bandwidthList.add(bandwidth);
}
isisLinkTed.setUnreservedBandwidth(bandwidthList);
}
}
}
} else {
log.debug("TLV type not supported");
}
}
return isisLinkTed;
......
......@@ -46,6 +46,15 @@ public class NeighborForExtendedIs {
}
/**
* Returns list of sub tlvs.
*
* @return teSubTlv list of sub tlvs
*/
public List<TrafficEngineeringSubTlv> teSubTlv() {
return teSubTlv;
}
/**
* Sets neighbor ID.
*
* @param neighborId neighbor ID
......
......@@ -67,10 +67,15 @@ public final class SubTlvFinder {
subTlv = unreservedBandwidth;
break;
case INTERFACEADDRESS:
NeighborIpAddress ipInterfaceAddressTlv = new NeighborIpAddress(tlvHeader);
InterfaceIpAddress ipInterfaceAddressTlv = new InterfaceIpAddress(tlvHeader);
ipInterfaceAddressTlv.readFrom(channelBuffer);
subTlv = ipInterfaceAddressTlv;
break;
case NEIGHBORADDRESS:
NeighborIpAddress ipNeighborAddressTlv = new NeighborIpAddress(tlvHeader);
ipNeighborAddressTlv.readFrom(channelBuffer);
subTlv = ipNeighborAddressTlv;
break;
default:
//TODO
break;
......
......@@ -54,7 +54,7 @@ public class UnreservedBandwidth extends TlvHeader implements TrafficEngineering
*
* @return List of un reserved bandwidth
*/
public List<Float> getUnReservedBandwidthValue() {
public List<Float> unReservedBandwidthValue() {
return this.unReservedBandwidth;
}
......
......@@ -59,6 +59,7 @@ import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -132,7 +133,7 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
@Override
public boolean isReachable(DeviceId deviceId) {
log.debug("IsisDeviceProvider::isReachable...!!!!");
return false;
return true;
}
@Override
......@@ -149,6 +150,8 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
private LinkDescription buildLinkDes(IsisLink isisLink) {
long srcAddress = 0;
long dstAddress = 0;
boolean localPseduo = false;
boolean remotePseduo = false;
String localSystemId = isisLink.localSystemId();
String remoteSystemId = isisLink.remoteSystemId();
//Changing of port numbers
......@@ -156,9 +159,17 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
dstAddress = isisLink.neighborIp().toInt();
DeviceId srcId = DeviceId.deviceId(IsisRouterId.uri(localSystemId));
DeviceId dstId = DeviceId.deviceId(IsisRouterId.uri(remoteSystemId));
if (srcAddress == 0) {
if (checkIsDis(isisLink.localSystemId())) {
localPseduo = true;
} else if (checkIsDis(isisLink.remoteSystemId())) {
remotePseduo = true;
} else {
log.debug("IsisDeviceProvider::buildLinkDes : unknown type.!");
}
if (localPseduo && srcAddress == 0) {
srcAddress = PSEUDO_PORT;
} else if (dstAddress == 0) {
} else if (remotePseduo && dstAddress == 0) {
dstAddress = PSEUDO_PORT;
}
......@@ -173,6 +184,28 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
}
/**
* Return the DIS value from the systemId.
*
* @param systemId system Id.
* @return return true if DIS else false
*/
public static boolean checkIsDis(String systemId) {
StringTokenizer stringTokenizer = new StringTokenizer(systemId, "." + "-");
int count = 0;
while (stringTokenizer.hasMoreTokens()) {
String str = stringTokenizer.nextToken();
if (count == 3) {
int x = Integer.parseInt(str);
if (x > 0) {
return true;
}
}
count++;
}
return false;
}
/**
* Builds port description.
*
* @param deviceId device ID for the port
......@@ -181,9 +214,7 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
*/
private List<PortDescription> buildPortDescriptions(DeviceId deviceId,
PortNumber portNumber) {
List<PortDescription> portList;
if (portMap.containsKey(deviceId)) {
portList = portMap.get(deviceId);
} else {
......@@ -193,8 +224,8 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
PortDescription portDescriptions = new DefaultPortDescription(portNumber, true);
portList.add(portDescriptions);
}
portMap.put(deviceId, portList);
return portList;
}
......@@ -215,6 +246,7 @@ public class IsisTopologyProvider extends AbstractProvider implements DeviceProv
//TE Info
IsisLinkTed isisLinkTed = isisLink.linkTed();
log.info("Ted Information: {}", isisLinkTed.toString());
administrativeGroup = isisLinkTed.administrativeGroup();
teMetric = isisLinkTed.teDefaultMetric();
maxReservableBandwidth = isisLinkTed.maximumReservableLinkBandwidth();
......