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;
}
......
......@@ -40,6 +40,10 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.Device.Type;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.resource.ContinuousResource;
......@@ -60,7 +64,11 @@ import org.onosproject.net.topology.TopologyVertex;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pceservice.constraint.SharedBandwidthConstraint;
import org.onosproject.pcep.api.DeviceCapability;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
......@@ -94,6 +102,7 @@ public class PathComputationTest {
private final MockPathResourceService resourceService = new MockPathResourceService();
private final MockDeviceService deviceService = new MockDeviceService();
private final MockNetConfigRegistryAdapter netConfigRegistry = new MockNetConfigRegistryAdapter();
private PceManager pceManager = new PceManager();
public static ProviderId providerId = new ProviderId("pce", "foo");
public static final String DEVICE1 = "D001";
......@@ -123,6 +132,7 @@ public class PathComputationTest {
public void startUp() {
pceManager.resourceService = resourceService;
pceManager.deviceService = deviceService;
pceManager.netCfgService = netConfigRegistry;
}
/**
......@@ -164,6 +174,7 @@ public class PathComputationTest {
public void tearDown() {
pceManager.resourceService = null;
pceManager.deviceService = null;
pceManager.netCfgService = null;
}
/**
......@@ -234,6 +245,7 @@ public class PathComputationTest {
}
}
@Override
public double weight(TopologyEdge edge) {
if (!constraints.iterator().hasNext()) {
//Takes default cost/hopcount as 1 if no constraints specified
......@@ -247,7 +259,8 @@ public class PathComputationTest {
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,
netConfigRegistry) ? 1 : -1;
} else {
cost = constraint.cost(edge.link(), resourceService::isAvailable);
}
......@@ -346,6 +359,63 @@ public class PathComputationTest {
}
}
/* Mock test for network config registry. */
public static class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter {
private ConfigFactory cfgFactory;
private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>();
@Override
public void registerConfigFactory(ConfigFactory configFactory) {
cfgFactory = configFactory;
}
@Override
public void unregisterConfigFactory(ConfigFactory configFactory) {
cfgFactory = null;
}
@Override
public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
if (configClass == DeviceCapability.class) {
DeviceCapability devCap = new DeviceCapability();
classConfig.put((DeviceId) subject, devCap);
JsonNode node = new ObjectNode(new MockJsonNode());
ObjectMapper mapper = new ObjectMapper();
ConfigApplyDelegate delegate = new InternalApplyDelegate();
devCap.init((DeviceId) subject, null, node, mapper, delegate);
return (C) devCap;
}
return null;
}
@Override
public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
classConfig.remove(subject);
}
@Override
public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
if (configClass == DeviceCapability.class) {
return (C) classConfig.get(subject);
}
return null;
}
private class MockJsonNode extends JsonNodeFactory {
}
// Auxiliary delegate to receive notifications about changes applied to
// the network configuration - by the apps.
private class InternalApplyDelegate implements ConfigApplyDelegate {
@Override
public void onApply(Config config) {
//configs.put(config.subject(), config.node());
}
}
}
/**
* All links with different costs with L1-L2 as least cost path.
*/
......@@ -614,24 +684,48 @@ public class PathComputationTest {
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(false)
.setLocalLabelCap(false)
.setSrCap(false)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(false)
.setLocalLabelCap(false)
.setSrCap(false)
.apply();
//Device3
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "3.3.3.3");
addDevice(DEVICE3, builder);
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(false)
.setLocalLabelCap(false)
.setSrCap(false)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(false)
.setLocalLabelCap(false)
.setSrCap(false)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
List<Link> links = new LinkedList<>();
......@@ -663,32 +757,44 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device3
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "3.3.3.3");
addDevice(DEVICE3, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE3, builder);
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
......@@ -721,36 +827,44 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device3
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "3.3.3.3");
addDevice(DEVICE3, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE3, builder);
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
List<Link> links = new LinkedList<>();
......@@ -783,36 +897,45 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device3
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "3.3.3.3");
addDevice(DEVICE3, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE3, builder);
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
List<Link> links = new LinkedList<>();
......@@ -842,36 +965,45 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device3
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "3.3.3.3");
addDevice(DEVICE3, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE3, builder);
DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
device3Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(SR_CAPABILITY, "true");
builder.set(LABEL_STACK_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(true)
.setLocalLabelCap(false)
.setSrCap(true)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
List<Link> links = new LinkedList<>();
......@@ -969,24 +1101,33 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE1, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
List<Link> links = new LinkedList<>();
......@@ -1019,24 +1160,33 @@ public class PathComputationTest {
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "1.1.1.1");
addDevice(DEVICE2, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE1, builder);
DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
device1Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device2
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "2.2.2.2");
addDevice(DEVICE2, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE2, builder);
DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
device2Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
//Device4
builder = DefaultAnnotations.builder();
builder.set(AnnotationKeys.TYPE, L3);
builder.set(LSRID, "4.4.4.4");
addDevice(DEVICE4, builder);
builder.set(PCECC_CAPABILITY, "true");
addDevice(PCEPDEVICE4, builder);
DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
device4Cap.setLabelStackCap(false)
.setLocalLabelCap(true)
.setSrCap(false)
.apply();
Set<Path> paths = computePath(link1, link2, link3, link4, constraints);
assertThat(paths, is(new HashSet<>()));
......
......@@ -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<>();
......