Avantika-Huawei

[ONOS-4166] Use device capapbility set using network config for path computation

Change-Id: I5f904f3838aafd5d1ab21d335043d9cfcdd2bce2
(cherry picked from commit 032a9873)
......@@ -60,6 +60,7 @@ import org.onosproject.incubator.net.tunnel.TunnelListener;
import org.onosproject.incubator.net.tunnel.TunnelName;
import org.onosproject.incubator.net.tunnel.TunnelService;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.Device;
......@@ -92,6 +93,7 @@ import org.onosproject.pce.pceservice.api.PceService;
import org.onosproject.pce.pcestore.PcePathInfo;
import org.onosproject.pce.pcestore.PceccTunnelInfo;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.DistributedSet;
import org.onosproject.store.service.Serializer;
......@@ -176,6 +178,9 @@ public class PceManager implements PceService {
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService netCfgService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LabelResourceAdminService labelRsrcAdminService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -304,6 +309,14 @@ public class PceManager implements PceService {
return false;
}
// Get device config from netconfig, to ascertain that session with ingress is present.
DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(srcLsrId), DeviceCapability.class);
if (cfg == null) {
log.debug("No session to ingress.");
pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType));
return false;
}
TunnelEndPoint srcEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(srcLsrId));
TunnelEndPoint dstEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dstLsrId));
......@@ -441,7 +454,7 @@ public class PceManager implements PceService {
bwConstraintValue = bwConstraint.bandwidth().bps();
} else if (constraint instanceof CostConstraint) {
costConstraint = (CostConstraint) constraint;
costType = costConstraint.type().name();
costType = costConstraint.type().name();
}
}
......@@ -621,7 +634,8 @@ public class PceManager implements PceService {
while (it.hasNext() && cost > 0) {
Constraint constraint = it.next();
if (constraint instanceof CapabilityConstraint) {
cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService) ? 1 : -1;
cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService,
netCfgService) ? 1 : -1;
} else {
cost = constraint.cost(edge.link(), resourceService::isAvailable);
}
......
......@@ -406,6 +406,7 @@ public final class PceccSrTeBeHandler {
/**
* Install a rule for pushing unique global labels to the device.
*
* @param deviceId device to which flow should be pushed
* @param labelId label for the device
* @param type type of operation
......@@ -437,6 +438,7 @@ public final class PceccSrTeBeHandler {
/**
* Install a rule for pushing node labels to the device of other nodes.
*
* @param deviceId device to which flow should be pushed
* @param labelId label for the device
* @param ipPrefix device for which label is pushed
......@@ -474,7 +476,8 @@ public final class PceccSrTeBeHandler {
}
/**
* Install a rule for pushing Adjacency labels to the device.
* Install a rule for pushing Adjacency labels to the device.
*
* @param deviceId device to which flow should be pushed
* @param labelId label for the adjacency
* @param srcPortNum local port of the adjacency
......
......@@ -15,12 +15,14 @@
*/
package org.onosproject.pce.pceservice.constraint;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.intent.constraint.BooleanConstraint;
import org.onosproject.pcep.api.DeviceCapability;
import java.util.Objects;
......@@ -32,11 +34,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
public final class CapabilityConstraint extends BooleanConstraint {
private final CapabilityType capabilityType;
public static final String PCECC_CAPABILITY = "pceccCapability";
public static final String SR_CAPABILITY = "srCapability";
public static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
public static final String LSRID = "lsrId";
public static final String L3 = "L3";
public static final String TRUE = "true";
/**
......@@ -117,45 +115,33 @@ public final class CapabilityConstraint extends BooleanConstraint {
*
* @param link to validate source and destination based on capability constraint
* @param deviceService instance of DeviceService
* @param netCfgService instance of NetworkConfigService
* @return true if link satisfies capability constraint otherwise false
*/
public boolean isValidLink(Link link, DeviceService deviceService) {
if (deviceService == null) {
public boolean isValidLink(Link link, DeviceService deviceService, NetworkConfigService netCfgService) {
if (deviceService == null || netCfgService == null) {
return false;
}
Device srcDevice = deviceService.getDevice(link.src().deviceId());
Device dstDevice = deviceService.getDevice(link.dst().deviceId());
//TODO: Usage of annotations are for transient solution. In future will be replaces with the
//TODO: Usage of annotations are for transient solution. In future will be replaced with the
// network config service / Projection model.
// L3 device
if (srcDevice == null
|| dstDevice == null
|| srcDevice.annotations().value(AnnotationKeys.TYPE) == null
|| dstDevice.annotations().value(AnnotationKeys.TYPE) == null
|| !srcDevice.annotations().value(AnnotationKeys.TYPE).equals(L3)
|| !dstDevice.annotations().value(AnnotationKeys.TYPE).equals(L3)) {
if (srcDevice == null || dstDevice == null) {
return false;
}
String scrLsrId = srcDevice.annotations().value(LSRID);
String srcLsrId = srcDevice.annotations().value(LSRID);
String dstLsrId = dstDevice.annotations().value(LSRID);
Device srcCapDevice = null;
Device dstCapDevice = null;
// Get Capability device
Iterable<Device> devices = deviceService.getAvailableDevices();
for (Device dev : devices) {
if (dev.annotations().value(LSRID).equals(scrLsrId)) {
srcCapDevice = dev;
} else if (dev.annotations().value(LSRID).equals(dstLsrId)) {
dstCapDevice = dev;
}
}
DeviceCapability srcDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(srcLsrId),
DeviceCapability.class);
DeviceCapability dstDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(dstLsrId),
DeviceCapability.class);
if (srcCapDevice == null || dstCapDevice == null) {
if (srcDeviceConfig == null || dstDeviceConfig == null) {
return false;
}
......@@ -163,23 +149,11 @@ public final class CapabilityConstraint extends BooleanConstraint {
case WITH_SIGNALLING:
return true;
case WITHOUT_SIGNALLING_AND_WITHOUT_SR:
if (srcCapDevice.annotations().value(PCECC_CAPABILITY) != null
&& dstCapDevice.annotations().value(PCECC_CAPABILITY) != null) {
return srcCapDevice.annotations().value(PCECC_CAPABILITY).equals(TRUE)
&& dstCapDevice.annotations().value(PCECC_CAPABILITY).equals(TRUE);
}
return false;
return srcDeviceConfig.localLabelCap() && dstDeviceConfig.localLabelCap();
case SR_WITHOUT_SIGNALLING:
if (srcCapDevice.annotations().value(LABEL_STACK_CAPABILITY) != null
&& dstCapDevice.annotations().value(LABEL_STACK_CAPABILITY) != null
&& srcCapDevice.annotations().value(SR_CAPABILITY) != null
&& dstCapDevice.annotations().value(SR_CAPABILITY) != null) {
return srcCapDevice.annotations().value(LABEL_STACK_CAPABILITY).equals(TRUE)
&& dstCapDevice.annotations().value(LABEL_STACK_CAPABILITY).equals(TRUE)
&& srcCapDevice.annotations().value(SR_CAPABILITY).equals(TRUE)
&& dstCapDevice.annotations().value(SR_CAPABILITY).equals(TRUE);
}
return false;
return srcDeviceConfig.srCap() && dstDeviceConfig.srCap()
&& srcDeviceConfig.labelStackCap() && dstDeviceConfig.labelStackCap();
default:
return false;
}
......
......@@ -102,12 +102,14 @@ import org.onosproject.net.topology.TopologyGraph;
import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyServiceAdapter;
import org.onosproject.net.topology.TopologyVertex;
import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pcestore.api.PceStore;
import org.onosproject.pce.util.LabelResourceAdapter;
import org.onosproject.pce.util.PceStoreAdapter;
import org.onosproject.pce.util.TunnelServiceAdapter;
import org.onosproject.pcep.api.DeviceCapability;
import org.onosproject.pce.util.FlowObjServiceAdapter;
import org.onosproject.store.service.TestStorageService;
......@@ -130,6 +132,7 @@ public class PceManagerTest {
private TestStorageService storageService = new TestStorageService();
private PacketService packetService = new MockPacketService();
private MockDeviceService deviceService = new MockDeviceService();
private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
private MockFlowObjService flowObjectiveService = new MockFlowObjService();
private PceStore pceStore = new PceStoreAdapter();
private LabelResourceService labelResourceService = new LabelResourceAdapter();
......@@ -137,13 +140,9 @@ public class PceManagerTest {
public static ProviderId providerId = new ProviderId("pce", "foo");
private static final String L3 = "L3";
private static final String LSRID = "lsrId";
private static final String PCECC_CAPABILITY = "pceccCapability";
private static final String SR_CAPABILITY = "srCapability";
private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
private TopologyGraph graph = null;
private Device deviceD1, deviceD2, deviceD3, deviceD4;
private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
private Link link1, link2, link3, link4;
protected static int flowsDownloaded;
private TunnelListener tunnelListener;
......@@ -163,6 +162,7 @@ public class PceManagerTest {
pceManager.storageService = storageService;
pceManager.packetService = packetService;
pceManager.deviceService = deviceService;
pceManager.netCfgService = netConfigRegistry;
pceManager.labelRsrcService = labelResourceService;
pceManager.flowObjectiveService = flowObjectiveService;
pceManager.pceStore = pceStore;
......@@ -231,27 +231,6 @@ public class PceManagerTest {
builderDev4.set(AnnotationKeys.TYPE, L3);
builderDev4.set(LSRID, "4.4.4.4");
if (setSrCap) {
builderDev1.set(SR_CAPABILITY, "true");
builderDev2.set(SR_CAPABILITY, "true");
builderDev3.set(SR_CAPABILITY, "true");
builderDev4.set(SR_CAPABILITY, "true");
}
if (setPceccCap) {
builderDev1.set(PCECC_CAPABILITY, "true");
builderDev2.set(PCECC_CAPABILITY, "true");
builderDev3.set(PCECC_CAPABILITY, "true");
builderDev4.set(PCECC_CAPABILITY, "true");
}
if (setLabelStackCap) {
builderDev1.set(LABEL_STACK_CAPABILITY, "true");
builderDev2.set(LABEL_STACK_CAPABILITY, "true");
builderDev3.set(LABEL_STACK_CAPABILITY, "true");
builderDev4.set(LABEL_STACK_CAPABILITY, "true");
}
deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
......@@ -262,17 +241,29 @@ public class PceManagerTest {
deviceService.addDevice(deviceD3);
deviceService.addDevice(deviceD4);
pcepDeviceD1 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE1), builderDev1.build());
deviceService.addDevice(pcepDeviceD1);
pcepDeviceD2 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE2), builderDev1.build());
deviceService.addDevice(pcepDeviceD2);
pcepDeviceD3 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE3), builderDev1.build());
deviceService.addDevice(pcepDeviceD3);
pcepDeviceD4 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE4), builderDev1.build());
deviceService.addDevice(pcepDeviceD4);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(setLabelStackCap)
.setLocalLabelCap(setPceccCap)
.setSrCap(setSrCap)
.apply();
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(setLabelStackCap)
.setLocalLabelCap(setPceccCap)
.setSrCap(setSrCap)
.apply();
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(setLabelStackCap)
.setLocalLabelCap(setPceccCap)
.setSrCap(setSrCap)
.apply();
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(setLabelStackCap)
.setLocalLabelCap(setPceccCap)
.setSrCap(setSrCap)
.apply();
if (bandwidth != 0) {
List<Resource> resources = new LinkedList<>();
......