Avantika-Huawei

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

Change-Id: I5f904f3838aafd5d1ab21d335043d9cfcdd2bce2
...@@ -60,6 +60,7 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; ...@@ -60,6 +60,7 @@ import org.onosproject.incubator.net.tunnel.TunnelListener;
60 import org.onosproject.incubator.net.tunnel.TunnelName; 60 import org.onosproject.incubator.net.tunnel.TunnelName;
61 import org.onosproject.incubator.net.tunnel.TunnelService; 61 import org.onosproject.incubator.net.tunnel.TunnelService;
62 import org.onosproject.mastership.MastershipService; 62 import org.onosproject.mastership.MastershipService;
63 +import org.onosproject.net.config.NetworkConfigService;
63 import org.onosproject.net.DefaultAnnotations; 64 import org.onosproject.net.DefaultAnnotations;
64 import org.onosproject.net.DefaultAnnotations.Builder; 65 import org.onosproject.net.DefaultAnnotations.Builder;
65 import org.onosproject.net.Device; 66 import org.onosproject.net.Device;
...@@ -92,6 +93,7 @@ import org.onosproject.pce.pceservice.api.PceService; ...@@ -92,6 +93,7 @@ import org.onosproject.pce.pceservice.api.PceService;
92 import org.onosproject.pce.pcestore.PcePathInfo; 93 import org.onosproject.pce.pcestore.PcePathInfo;
93 import org.onosproject.pce.pcestore.PceccTunnelInfo; 94 import org.onosproject.pce.pcestore.PceccTunnelInfo;
94 import org.onosproject.pce.pcestore.api.PceStore; 95 import org.onosproject.pce.pcestore.api.PceStore;
96 +import org.onosproject.pcep.api.DeviceCapability;
95 import org.onosproject.store.serializers.KryoNamespaces; 97 import org.onosproject.store.serializers.KryoNamespaces;
96 import org.onosproject.store.service.DistributedSet; 98 import org.onosproject.store.service.DistributedSet;
97 import org.onosproject.store.service.Serializer; 99 import org.onosproject.store.service.Serializer;
...@@ -176,6 +178,9 @@ public class PceManager implements PceService { ...@@ -176,6 +178,9 @@ public class PceManager implements PceService {
176 protected DeviceService deviceService; 178 protected DeviceService deviceService;
177 179
178 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 180 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
181 + protected NetworkConfigService netCfgService;
182 +
183 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
179 protected LabelResourceAdminService labelRsrcAdminService; 184 protected LabelResourceAdminService labelRsrcAdminService;
180 185
181 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 186 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -304,6 +309,14 @@ public class PceManager implements PceService { ...@@ -304,6 +309,14 @@ public class PceManager implements PceService {
304 return false; 309 return false;
305 } 310 }
306 311
312 + // Get device config from netconfig, to ascertain that session with ingress is present.
313 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(srcLsrId), DeviceCapability.class);
314 + if (cfg == null) {
315 + log.debug("No session to ingress.");
316 + pceStore.addFailedPathInfo(new PcePathInfo(src, dst, tunnelName, constraints, lspType));
317 + return false;
318 + }
319 +
307 TunnelEndPoint srcEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(srcLsrId)); 320 TunnelEndPoint srcEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(srcLsrId));
308 TunnelEndPoint dstEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dstLsrId)); 321 TunnelEndPoint dstEndPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dstLsrId));
309 322
...@@ -441,7 +454,7 @@ public class PceManager implements PceService { ...@@ -441,7 +454,7 @@ public class PceManager implements PceService {
441 bwConstraintValue = bwConstraint.bandwidth().bps(); 454 bwConstraintValue = bwConstraint.bandwidth().bps();
442 } else if (constraint instanceof CostConstraint) { 455 } else if (constraint instanceof CostConstraint) {
443 costConstraint = (CostConstraint) constraint; 456 costConstraint = (CostConstraint) constraint;
444 - costType = costConstraint.type().name(); 457 + costType = costConstraint.type().name();
445 } 458 }
446 } 459 }
447 460
...@@ -621,7 +634,8 @@ public class PceManager implements PceService { ...@@ -621,7 +634,8 @@ public class PceManager implements PceService {
621 while (it.hasNext() && cost > 0) { 634 while (it.hasNext() && cost > 0) {
622 Constraint constraint = it.next(); 635 Constraint constraint = it.next();
623 if (constraint instanceof CapabilityConstraint) { 636 if (constraint instanceof CapabilityConstraint) {
624 - cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService) ? 1 : -1; 637 + cost = ((CapabilityConstraint) constraint).isValidLink(edge.link(), deviceService,
638 + netCfgService) ? 1 : -1;
625 } else { 639 } else {
626 cost = constraint.cost(edge.link(), resourceService::isAvailable); 640 cost = constraint.cost(edge.link(), resourceService::isAvailable);
627 } 641 }
......
...@@ -406,6 +406,7 @@ public final class PceccSrTeBeHandler { ...@@ -406,6 +406,7 @@ public final class PceccSrTeBeHandler {
406 406
407 /** 407 /**
408 * Install a rule for pushing unique global labels to the device. 408 * Install a rule for pushing unique global labels to the device.
409 + *
409 * @param deviceId device to which flow should be pushed 410 * @param deviceId device to which flow should be pushed
410 * @param labelId label for the device 411 * @param labelId label for the device
411 * @param type type of operation 412 * @param type type of operation
...@@ -437,6 +438,7 @@ public final class PceccSrTeBeHandler { ...@@ -437,6 +438,7 @@ public final class PceccSrTeBeHandler {
437 438
438 /** 439 /**
439 * Install a rule for pushing node labels to the device of other nodes. 440 * Install a rule for pushing node labels to the device of other nodes.
441 + *
440 * @param deviceId device to which flow should be pushed 442 * @param deviceId device to which flow should be pushed
441 * @param labelId label for the device 443 * @param labelId label for the device
442 * @param ipPrefix device for which label is pushed 444 * @param ipPrefix device for which label is pushed
...@@ -474,7 +476,8 @@ public final class PceccSrTeBeHandler { ...@@ -474,7 +476,8 @@ public final class PceccSrTeBeHandler {
474 } 476 }
475 477
476 /** 478 /**
477 - * Install a rule for pushing Adjacency labels to the device. 479 + * Install a rule for pushing Adjacency labels to the device.
480 + *
478 * @param deviceId device to which flow should be pushed 481 * @param deviceId device to which flow should be pushed
479 * @param labelId label for the adjacency 482 * @param labelId label for the adjacency
480 * @param srcPortNum local port of the adjacency 483 * @param srcPortNum local port of the adjacency
......
...@@ -15,12 +15,14 @@ ...@@ -15,12 +15,14 @@
15 */ 15 */
16 package org.onosproject.pce.pceservice.constraint; 16 package org.onosproject.pce.pceservice.constraint;
17 17
18 -import org.onosproject.net.AnnotationKeys;
19 import org.onosproject.net.Device; 18 import org.onosproject.net.Device;
19 +import org.onosproject.net.DeviceId;
20 import org.onosproject.net.Link; 20 import org.onosproject.net.Link;
21 +import org.onosproject.net.config.NetworkConfigService;
21 import org.onosproject.net.device.DeviceService; 22 import org.onosproject.net.device.DeviceService;
22 import org.onosproject.net.intent.ResourceContext; 23 import org.onosproject.net.intent.ResourceContext;
23 import org.onosproject.net.intent.constraint.BooleanConstraint; 24 import org.onosproject.net.intent.constraint.BooleanConstraint;
25 +import org.onosproject.pcep.api.DeviceCapability;
24 26
25 import java.util.Objects; 27 import java.util.Objects;
26 28
...@@ -32,11 +34,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -32,11 +34,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
32 public final class CapabilityConstraint extends BooleanConstraint { 34 public final class CapabilityConstraint extends BooleanConstraint {
33 35
34 private final CapabilityType capabilityType; 36 private final CapabilityType capabilityType;
35 - public static final String PCECC_CAPABILITY = "pceccCapability";
36 - public static final String SR_CAPABILITY = "srCapability";
37 - public static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
38 public static final String LSRID = "lsrId"; 37 public static final String LSRID = "lsrId";
39 - public static final String L3 = "L3";
40 public static final String TRUE = "true"; 38 public static final String TRUE = "true";
41 39
42 /** 40 /**
...@@ -117,45 +115,33 @@ public final class CapabilityConstraint extends BooleanConstraint { ...@@ -117,45 +115,33 @@ public final class CapabilityConstraint extends BooleanConstraint {
117 * 115 *
118 * @param link to validate source and destination based on capability constraint 116 * @param link to validate source and destination based on capability constraint
119 * @param deviceService instance of DeviceService 117 * @param deviceService instance of DeviceService
118 + * @param netCfgService instance of NetworkConfigService
120 * @return true if link satisfies capability constraint otherwise false 119 * @return true if link satisfies capability constraint otherwise false
121 */ 120 */
122 - public boolean isValidLink(Link link, DeviceService deviceService) { 121 + public boolean isValidLink(Link link, DeviceService deviceService, NetworkConfigService netCfgService) {
123 - if (deviceService == null) { 122 + if (deviceService == null || netCfgService == null) {
124 return false; 123 return false;
125 } 124 }
126 125
127 Device srcDevice = deviceService.getDevice(link.src().deviceId()); 126 Device srcDevice = deviceService.getDevice(link.src().deviceId());
128 Device dstDevice = deviceService.getDevice(link.dst().deviceId()); 127 Device dstDevice = deviceService.getDevice(link.dst().deviceId());
129 128
130 - //TODO: Usage of annotations are for transient solution. In future will be replaces with the 129 + //TODO: Usage of annotations are for transient solution. In future will be replaced with the
131 // network config service / Projection model. 130 // network config service / Projection model.
132 // L3 device 131 // L3 device
133 - if (srcDevice == null 132 + if (srcDevice == null || dstDevice == null) {
134 - || dstDevice == null
135 - || srcDevice.annotations().value(AnnotationKeys.TYPE) == null
136 - || dstDevice.annotations().value(AnnotationKeys.TYPE) == null
137 - || !srcDevice.annotations().value(AnnotationKeys.TYPE).equals(L3)
138 - || !dstDevice.annotations().value(AnnotationKeys.TYPE).equals(L3)) {
139 return false; 133 return false;
140 } 134 }
141 135
142 - String scrLsrId = srcDevice.annotations().value(LSRID); 136 + String srcLsrId = srcDevice.annotations().value(LSRID);
143 String dstLsrId = dstDevice.annotations().value(LSRID); 137 String dstLsrId = dstDevice.annotations().value(LSRID);
144 138
145 - Device srcCapDevice = null; 139 + DeviceCapability srcDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(srcLsrId),
146 - Device dstCapDevice = null; 140 + DeviceCapability.class);
147 - 141 + DeviceCapability dstDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(dstLsrId),
148 - // Get Capability device 142 + DeviceCapability.class);
149 - Iterable<Device> devices = deviceService.getAvailableDevices();
150 - for (Device dev : devices) {
151 - if (dev.annotations().value(LSRID).equals(scrLsrId)) {
152 - srcCapDevice = dev;
153 - } else if (dev.annotations().value(LSRID).equals(dstLsrId)) {
154 - dstCapDevice = dev;
155 - }
156 - }
157 143
158 - if (srcCapDevice == null || dstCapDevice == null) { 144 + if (srcDeviceConfig == null || dstDeviceConfig == null) {
159 return false; 145 return false;
160 } 146 }
161 147
...@@ -163,23 +149,11 @@ public final class CapabilityConstraint extends BooleanConstraint { ...@@ -163,23 +149,11 @@ public final class CapabilityConstraint extends BooleanConstraint {
163 case WITH_SIGNALLING: 149 case WITH_SIGNALLING:
164 return true; 150 return true;
165 case WITHOUT_SIGNALLING_AND_WITHOUT_SR: 151 case WITHOUT_SIGNALLING_AND_WITHOUT_SR:
166 - if (srcCapDevice.annotations().value(PCECC_CAPABILITY) != null 152 + return srcDeviceConfig.localLabelCap() && dstDeviceConfig.localLabelCap();
167 - && dstCapDevice.annotations().value(PCECC_CAPABILITY) != null) { 153 +
168 - return srcCapDevice.annotations().value(PCECC_CAPABILITY).equals(TRUE)
169 - && dstCapDevice.annotations().value(PCECC_CAPABILITY).equals(TRUE);
170 - }
171 - return false;
172 case SR_WITHOUT_SIGNALLING: 154 case SR_WITHOUT_SIGNALLING:
173 - if (srcCapDevice.annotations().value(LABEL_STACK_CAPABILITY) != null 155 + return srcDeviceConfig.srCap() && dstDeviceConfig.srCap()
174 - && dstCapDevice.annotations().value(LABEL_STACK_CAPABILITY) != null 156 + && srcDeviceConfig.labelStackCap() && dstDeviceConfig.labelStackCap();
175 - && srcCapDevice.annotations().value(SR_CAPABILITY) != null
176 - && dstCapDevice.annotations().value(SR_CAPABILITY) != null) {
177 - return srcCapDevice.annotations().value(LABEL_STACK_CAPABILITY).equals(TRUE)
178 - && dstCapDevice.annotations().value(LABEL_STACK_CAPABILITY).equals(TRUE)
179 - && srcCapDevice.annotations().value(SR_CAPABILITY).equals(TRUE)
180 - && dstCapDevice.annotations().value(SR_CAPABILITY).equals(TRUE);
181 - }
182 - return false;
183 default: 157 default:
184 return false; 158 return false;
185 } 159 }
......
...@@ -102,12 +102,14 @@ import org.onosproject.net.topology.TopologyGraph; ...@@ -102,12 +102,14 @@ import org.onosproject.net.topology.TopologyGraph;
102 import org.onosproject.net.topology.TopologyListener; 102 import org.onosproject.net.topology.TopologyListener;
103 import org.onosproject.net.topology.TopologyServiceAdapter; 103 import org.onosproject.net.topology.TopologyServiceAdapter;
104 import org.onosproject.net.topology.TopologyVertex; 104 import org.onosproject.net.topology.TopologyVertex;
105 +import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
105 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; 106 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
106 import org.onosproject.pce.pceservice.constraint.CostConstraint; 107 import org.onosproject.pce.pceservice.constraint.CostConstraint;
107 import org.onosproject.pce.pcestore.api.PceStore; 108 import org.onosproject.pce.pcestore.api.PceStore;
108 import org.onosproject.pce.util.LabelResourceAdapter; 109 import org.onosproject.pce.util.LabelResourceAdapter;
109 import org.onosproject.pce.util.PceStoreAdapter; 110 import org.onosproject.pce.util.PceStoreAdapter;
110 import org.onosproject.pce.util.TunnelServiceAdapter; 111 import org.onosproject.pce.util.TunnelServiceAdapter;
112 +import org.onosproject.pcep.api.DeviceCapability;
111 import org.onosproject.pce.util.FlowObjServiceAdapter; 113 import org.onosproject.pce.util.FlowObjServiceAdapter;
112 import org.onosproject.store.service.TestStorageService; 114 import org.onosproject.store.service.TestStorageService;
113 115
...@@ -130,6 +132,7 @@ public class PceManagerTest { ...@@ -130,6 +132,7 @@ public class PceManagerTest {
130 private TestStorageService storageService = new TestStorageService(); 132 private TestStorageService storageService = new TestStorageService();
131 private PacketService packetService = new MockPacketService(); 133 private PacketService packetService = new MockPacketService();
132 private MockDeviceService deviceService = new MockDeviceService(); 134 private MockDeviceService deviceService = new MockDeviceService();
135 + private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
133 private MockFlowObjService flowObjectiveService = new MockFlowObjService(); 136 private MockFlowObjService flowObjectiveService = new MockFlowObjService();
134 private PceStore pceStore = new PceStoreAdapter(); 137 private PceStore pceStore = new PceStoreAdapter();
135 private LabelResourceService labelResourceService = new LabelResourceAdapter(); 138 private LabelResourceService labelResourceService = new LabelResourceAdapter();
...@@ -137,13 +140,9 @@ public class PceManagerTest { ...@@ -137,13 +140,9 @@ public class PceManagerTest {
137 public static ProviderId providerId = new ProviderId("pce", "foo"); 140 public static ProviderId providerId = new ProviderId("pce", "foo");
138 private static final String L3 = "L3"; 141 private static final String L3 = "L3";
139 private static final String LSRID = "lsrId"; 142 private static final String LSRID = "lsrId";
140 - private static final String PCECC_CAPABILITY = "pceccCapability";
141 - private static final String SR_CAPABILITY = "srCapability";
142 - private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
143 143
144 private TopologyGraph graph = null; 144 private TopologyGraph graph = null;
145 private Device deviceD1, deviceD2, deviceD3, deviceD4; 145 private Device deviceD1, deviceD2, deviceD3, deviceD4;
146 - private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
147 private Link link1, link2, link3, link4; 146 private Link link1, link2, link3, link4;
148 protected static int flowsDownloaded; 147 protected static int flowsDownloaded;
149 private TunnelListener tunnelListener; 148 private TunnelListener tunnelListener;
...@@ -163,6 +162,7 @@ public class PceManagerTest { ...@@ -163,6 +162,7 @@ public class PceManagerTest {
163 pceManager.storageService = storageService; 162 pceManager.storageService = storageService;
164 pceManager.packetService = packetService; 163 pceManager.packetService = packetService;
165 pceManager.deviceService = deviceService; 164 pceManager.deviceService = deviceService;
165 + pceManager.netCfgService = netConfigRegistry;
166 pceManager.labelRsrcService = labelResourceService; 166 pceManager.labelRsrcService = labelResourceService;
167 pceManager.flowObjectiveService = flowObjectiveService; 167 pceManager.flowObjectiveService = flowObjectiveService;
168 pceManager.pceStore = pceStore; 168 pceManager.pceStore = pceStore;
...@@ -231,27 +231,6 @@ public class PceManagerTest { ...@@ -231,27 +231,6 @@ public class PceManagerTest {
231 builderDev4.set(AnnotationKeys.TYPE, L3); 231 builderDev4.set(AnnotationKeys.TYPE, L3);
232 builderDev4.set(LSRID, "4.4.4.4"); 232 builderDev4.set(LSRID, "4.4.4.4");
233 233
234 - if (setSrCap) {
235 - builderDev1.set(SR_CAPABILITY, "true");
236 - builderDev2.set(SR_CAPABILITY, "true");
237 - builderDev3.set(SR_CAPABILITY, "true");
238 - builderDev4.set(SR_CAPABILITY, "true");
239 - }
240 -
241 - if (setPceccCap) {
242 - builderDev1.set(PCECC_CAPABILITY, "true");
243 - builderDev2.set(PCECC_CAPABILITY, "true");
244 - builderDev3.set(PCECC_CAPABILITY, "true");
245 - builderDev4.set(PCECC_CAPABILITY, "true");
246 - }
247 -
248 - if (setLabelStackCap) {
249 - builderDev1.set(LABEL_STACK_CAPABILITY, "true");
250 - builderDev2.set(LABEL_STACK_CAPABILITY, "true");
251 - builderDev3.set(LABEL_STACK_CAPABILITY, "true");
252 - builderDev4.set(LABEL_STACK_CAPABILITY, "true");
253 - }
254 -
255 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build()); 234 deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
256 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build()); 235 deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
257 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build()); 236 deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
...@@ -262,17 +241,29 @@ public class PceManagerTest { ...@@ -262,17 +241,29 @@ public class PceManagerTest {
262 deviceService.addDevice(deviceD3); 241 deviceService.addDevice(deviceD3);
263 deviceService.addDevice(deviceD4); 242 deviceService.addDevice(deviceD4);
264 243
265 - pcepDeviceD1 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE1), builderDev1.build()); 244 + DeviceCapability device1Cap = netConfigRegistry.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
266 - deviceService.addDevice(pcepDeviceD1); 245 + device1Cap.setLabelStackCap(setLabelStackCap)
267 - 246 + .setLocalLabelCap(setPceccCap)
268 - pcepDeviceD2 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE2), builderDev1.build()); 247 + .setSrCap(setSrCap)
269 - deviceService.addDevice(pcepDeviceD2); 248 + .apply();
270 - 249 +
271 - pcepDeviceD3 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE3), builderDev1.build()); 250 + DeviceCapability device2Cap = netConfigRegistry.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
272 - deviceService.addDevice(pcepDeviceD3); 251 + device2Cap.setLabelStackCap(setLabelStackCap)
273 - 252 + .setLocalLabelCap(setPceccCap)
274 - pcepDeviceD4 = new MockDevice(DeviceId.deviceId(PathComputationTest.PCEPDEVICE4), builderDev1.build()); 253 + .setSrCap(setSrCap)
275 - deviceService.addDevice(pcepDeviceD4); 254 + .apply();
255 +
256 + DeviceCapability device3Cap = netConfigRegistry.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
257 + device3Cap.setLabelStackCap(setLabelStackCap)
258 + .setLocalLabelCap(setPceccCap)
259 + .setSrCap(setSrCap)
260 + .apply();
261 +
262 + DeviceCapability device4Cap = netConfigRegistry.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
263 + device4Cap.setLabelStackCap(setLabelStackCap)
264 + .setLocalLabelCap(setPceccCap)
265 + .setSrCap(setSrCap)
266 + .apply();
276 267
277 if (bandwidth != 0) { 268 if (bandwidth != 0) {
278 List<Resource> resources = new LinkedList<>(); 269 List<Resource> resources = new LinkedList<>();
......