Avantika-Huawei

[ONOS-4743] - DB sync is suspended if PCEP session is formed before BGP devices are learnt

Change-Id: I543201c54883e06182c1c83c4c64dd16a18e096c
...@@ -1058,6 +1058,18 @@ public class PceManager implements PceService { ...@@ -1058,6 +1058,18 @@ public class PceManager implements PceService {
1058 // Node-label allocation is being done during Label DB Sync. 1058 // Node-label allocation is being done during Label DB Sync.
1059 // So, when device is detected, no need to do node-label 1059 // So, when device is detected, no need to do node-label
1060 // allocation. 1060 // allocation.
1061 + String lsrId = specificDevice.annotations().value(LSRID);
1062 + if (lsrId != null) {
1063 + pceStore.addLsrIdDevice(lsrId, specificDevice.id());
1064 +
1065 + // Search in failed DB sync store. If found, trigger label DB sync.
1066 + DeviceId pccDeviceId = DeviceId.deviceId(lsrId);
1067 + if (pceStore.hasPccLsr(pccDeviceId)) {
1068 + log.debug("Continue to perform label DB sync for device {}.", pccDeviceId.toString());
1069 + syncLabelDb(pccDeviceId);
1070 + pceStore.removePccLsr(pccDeviceId);
1071 + }
1072 + }
1061 break; 1073 break;
1062 1074
1063 case DEVICE_REMOVED: 1075 case DEVICE_REMOVED:
...@@ -1065,6 +1077,11 @@ public class PceManager implements PceService { ...@@ -1065,6 +1077,11 @@ public class PceManager implements PceService {
1065 if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { 1077 if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
1066 releaseNodeLabel(specificDevice); 1078 releaseNodeLabel(specificDevice);
1067 } 1079 }
1080 +
1081 + if (specificDevice.annotations().value(LSRID) != null) {
1082 + pceStore.removeLsrIdDevice(specificDevice.annotations().value(LSRID));
1083 + }
1084 +
1068 break; 1085 break;
1069 1086
1070 default: 1087 default:
...@@ -1252,13 +1269,20 @@ public class PceManager implements PceService { ...@@ -1252,13 +1269,20 @@ public class PceManager implements PceService {
1252 private boolean syncLabelDb(DeviceId deviceId) { 1269 private boolean syncLabelDb(DeviceId deviceId) {
1253 checkNotNull(deviceId); 1270 checkNotNull(deviceId);
1254 1271
1255 - Device specificDevice = deviceService.getDevice(deviceId); 1272 + DeviceId actualDevcieId = pceStore.getLsrIdDevice(deviceId.toString());
1273 + if (actualDevcieId == null) {
1274 + log.error("Device not available {}.", deviceId.toString());
1275 + pceStore.addPccLsr(deviceId);
1276 + return false;
1277 + }
1278 +
1279 + Device specificDevice = deviceService.getDevice(actualDevcieId);
1256 if (specificDevice == null) { 1280 if (specificDevice == null) {
1257 - log.error("Unable to find device for specific device id {}.", deviceId.toString()); 1281 + log.error("Unable to find device for specific device id {}.", actualDevcieId.toString());
1258 return false; 1282 return false;
1259 } 1283 }
1260 1284
1261 - if (pceStore.getGlobalNodeLabel(deviceId) != null) { 1285 + if (pceStore.getGlobalNodeLabel(actualDevcieId) != null) {
1262 Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels(); 1286 Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels();
1263 1287
1264 for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) { 1288 for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) {
...@@ -1279,7 +1303,7 @@ public class PceManager implements PceService { ...@@ -1279,7 +1303,7 @@ public class PceManager implements PceService {
1279 continue; 1303 continue;
1280 } 1304 }
1281 1305
1282 - srTeHandler.advertiseNodeLabelRule(deviceId, 1306 + srTeHandler.advertiseNodeLabelRule(actualDevcieId,
1283 entry.getValue(), 1307 entry.getValue(),
1284 IpPrefix.valueOf(IpAddress.valueOf(srcLsrId), PREFIX_LENGTH), 1308 IpPrefix.valueOf(IpAddress.valueOf(srcLsrId), PREFIX_LENGTH),
1285 Objective.Operation.ADD, false); 1309 Objective.Operation.ADD, false);
...@@ -1287,8 +1311,8 @@ public class PceManager implements PceService { ...@@ -1287,8 +1311,8 @@ public class PceManager implements PceService {
1287 1311
1288 Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels(); 1312 Map<Link, LabelResourceId> adjLabelMap = pceStore.getAdjLabels();
1289 for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) { 1313 for (Entry<Link, LabelResourceId> entry : adjLabelMap.entrySet()) {
1290 - if (entry.getKey().src().deviceId().equals(deviceId)) { 1314 + if (entry.getKey().src().deviceId().equals(actualDevcieId)) {
1291 - srTeHandler.installAdjLabelRule(deviceId, 1315 + srTeHandler.installAdjLabelRule(actualDevcieId,
1292 entry.getValue(), 1316 entry.getValue(),
1293 entry.getKey().src().port(), 1317 entry.getKey().src().port(),
1294 entry.getKey().dst().port(), 1318 entry.getKey().dst().port(),
...@@ -1297,12 +1321,12 @@ public class PceManager implements PceService { ...@@ -1297,12 +1321,12 @@ public class PceManager implements PceService {
1297 } 1321 }
1298 } 1322 }
1299 1323
1300 - srTeHandler.advertiseNodeLabelRule(deviceId, 1324 + srTeHandler.advertiseNodeLabelRule(actualDevcieId,
1301 LabelResourceId.labelResourceId(0), 1325 LabelResourceId.labelResourceId(0),
1302 IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX), 1326 IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX),
1303 Objective.Operation.ADD, true); 1327 Objective.Operation.ADD, true);
1304 1328
1305 - log.debug("End of label DB sync for device {}", deviceId); 1329 + log.debug("End of label DB sync for device {}", actualDevcieId);
1306 1330
1307 if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) { 1331 if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
1308 // Allocate node-label to this specific device. 1332 // Allocate node-label to this specific device.
......
...@@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 19
20 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.ImmutableSet;
21 21
22 +import java.util.HashMap;
23 +import java.util.HashSet;
22 import java.util.List; 24 import java.util.List;
23 import java.util.Map; 25 import java.util.Map;
24 import java.util.stream.Collectors; 26 import java.util.stream.Collectors;
...@@ -89,6 +91,13 @@ public class DistributedPceStore implements PceStore { ...@@ -89,6 +91,13 @@ public class DistributedPceStore implements PceStore {
89 // List of Failed path info 91 // List of Failed path info
90 private DistributedSet<PcePathInfo> failedPathSet; 92 private DistributedSet<PcePathInfo> failedPathSet;
91 93
94 + // Locally maintain LSRID to device id mapping for better performance.
95 + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
96 +
97 + // List of PCC LSR ids whose BGP device information was not available to perform
98 + // label db sync.
99 + private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet();
100 +
92 @Activate 101 @Activate
93 protected void activate() { 102 protected void activate() {
94 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder() 103 globalNodeLabelMap = storageService.<DeviceId, LabelResourceId>consistentMapBuilder()
...@@ -341,4 +350,50 @@ public class DistributedPceStore implements PceStore { ...@@ -341,4 +350,50 @@ public class DistributedPceStore implements PceStore {
341 } 350 }
342 return true; 351 return true;
343 } 352 }
353 +
354 + @Override
355 + public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
356 + checkNotNull(lsrId);
357 + checkNotNull(deviceId);
358 +
359 + lsrIdDeviceIdMap.put(lsrId, deviceId);
360 + return true;
361 + }
362 +
363 + @Override
364 + public boolean removeLsrIdDevice(String lsrId) {
365 + checkNotNull(lsrId);
366 +
367 + lsrIdDeviceIdMap.remove(lsrId);
368 + return true;
369 + }
370 +
371 + @Override
372 + public DeviceId getLsrIdDevice(String lsrId) {
373 + checkNotNull(lsrId);
374 +
375 + return lsrIdDeviceIdMap.get(lsrId);
376 +
377 + }
378 +
379 + @Override
380 + public boolean addPccLsr(DeviceId lsrId) {
381 + checkNotNull(lsrId);
382 + pendinglabelDbSyncPccMap.add(lsrId);
383 + return true;
384 + }
385 +
386 + @Override
387 + public boolean removePccLsr(DeviceId lsrId) {
388 + checkNotNull(lsrId);
389 + pendinglabelDbSyncPccMap.remove(lsrId);
390 + return true;
391 + }
392 +
393 + @Override
394 + public boolean hasPccLsr(DeviceId lsrId) {
395 + checkNotNull(lsrId);
396 + return pendinglabelDbSyncPccMap.contains(lsrId);
397 +
398 + }
344 } 399 }
......
...@@ -224,4 +224,54 @@ public interface PceStore { ...@@ -224,4 +224,54 @@ public interface PceStore {
224 * @return success or failure 224 * @return success or failure
225 */ 225 */
226 boolean removeFailedPathInfo(PcePathInfo failedPathInfo); 226 boolean removeFailedPathInfo(PcePathInfo failedPathInfo);
227 +
228 + /**
229 + * Adds lsrid to device id mapping.
230 + *
231 + * @param lsrId lsrId of the device
232 + * @param deviceId device id
233 + * @return success or failure
234 + */
235 + boolean addLsrIdDevice(String lsrId, DeviceId deviceId);
236 +
237 + /**
238 + * Removes lsrid to device id mapping.
239 + *
240 + * @param lsrId lsrId of the device
241 + * @return success or failure
242 + */
243 + boolean removeLsrIdDevice(String lsrId);
244 +
245 + /**
246 + * Gets lsrid to device id mapping.
247 + *
248 + * @param lsrId lsrId of the device
249 + * @return device id of the lsrId
250 + */
251 + DeviceId getLsrIdDevice(String lsrId);
252 +
253 + /**
254 + * Adds lsrId of the PCC in form of device id for the PCC for which sync is pending due to non-availability of BGP.
255 + * device.
256 + *
257 + * @param lsrId LSR id of the PCC in form of device id
258 + * @return success or failure
259 + */
260 + public boolean addPccLsr(DeviceId lsrId);
261 +
262 + /**
263 + * Removes lsrId of the PCC in form of device id for the PCC for which pending sync is done.
264 + *
265 + * @param lsrId LSR id of the PCC in form of device id
266 + * @return success or failure
267 + */
268 + public boolean removePccLsr(DeviceId lsrId);
269 +
270 + /**
271 + * Gets lsrId of the PCC in form of device id.
272 + *
273 + * @param lsrId LSR id of the PCC in form of device id
274 + * @return success or failure
275 + */
276 + public boolean hasPccLsr(DeviceId lsrId);
227 } 277 }
......
...@@ -690,6 +690,7 @@ public class PceManagerTest { ...@@ -690,6 +690,7 @@ public class PceManagerTest {
690 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); 690 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
691 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); 691 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
692 692
693 + pceManager.pceStore.addLsrIdDevice(deviceD1.annotations().value(LSRID), deviceD1.id());
693 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); 694 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
694 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); 695 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
695 696
...@@ -713,7 +714,7 @@ public class PceManagerTest { ...@@ -713,7 +714,7 @@ public class PceManagerTest {
713 eth.setEtherType(Ethernet.TYPE_IPV4); 714 eth.setEtherType(Ethernet.TYPE_IPV4);
714 eth.setPayload(ipv4); 715 eth.setPayload(ipv4);
715 716
716 - InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), 717 + InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(DeviceId.deviceId("1.1.1.1"),
717 PortNumber.portNumber(PCEP_PORT)), 718 PortNumber.portNumber(PCEP_PORT)),
718 eth, null); 719 eth, null);
719 720
......
...@@ -19,6 +19,8 @@ import com.google.common.collect.ImmutableSet; ...@@ -19,6 +19,8 @@ import com.google.common.collect.ImmutableSet;
19 19
20 import java.util.concurrent.ConcurrentHashMap; 20 import java.util.concurrent.ConcurrentHashMap;
21 import java.util.concurrent.ConcurrentMap; 21 import java.util.concurrent.ConcurrentMap;
22 +
23 +import java.util.HashMap;
22 import java.util.HashSet; 24 import java.util.HashSet;
23 import java.util.List; 25 import java.util.List;
24 import java.util.Map; 26 import java.util.Map;
...@@ -52,6 +54,9 @@ public class PceStoreAdapter implements PceStore { ...@@ -52,6 +54,9 @@ public class PceStoreAdapter implements PceStore {
52 // Set of Path info 54 // Set of Path info
53 private Set<PcePathInfo> failedPathInfoSet = new HashSet<>(); 55 private Set<PcePathInfo> failedPathInfoSet = new HashSet<>();
54 56
57 + // Locally maintain LSRID to device id mapping for better performance.
58 + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
59 +
55 @Override 60 @Override
56 public boolean existsGlobalNodeLabel(DeviceId id) { 61 public boolean existsGlobalNodeLabel(DeviceId id) {
57 return globalNodeLabelMap.containsKey(id); 62 return globalNodeLabelMap.containsKey(id);
...@@ -208,4 +213,39 @@ public class PceStoreAdapter implements PceStore { ...@@ -208,4 +213,39 @@ public class PceStoreAdapter implements PceStore {
208 } 213 }
209 return true; 214 return true;
210 } 215 }
216 +
217 + @Override
218 + public boolean addLsrIdDevice(String lsrId, DeviceId deviceId) {
219 + lsrIdDeviceIdMap.put(lsrId, deviceId);
220 + return true;
221 + }
222 +
223 + @Override
224 + public boolean removeLsrIdDevice(String lsrId) {
225 + lsrIdDeviceIdMap.remove(lsrId);
226 + return true;
227 + }
228 +
229 + @Override
230 + public DeviceId getLsrIdDevice(String lsrId) {
231 + return lsrIdDeviceIdMap.get(lsrId);
232 + }
233 +
234 + @Override
235 + public boolean addPccLsr(DeviceId lsrId) {
236 + // TODO Auto-generated method stub
237 + return false;
238 + }
239 +
240 + @Override
241 + public boolean removePccLsr(DeviceId lsrId) {
242 + // TODO Auto-generated method stub
243 + return false;
244 + }
245 +
246 + @Override
247 + public boolean hasPccLsr(DeviceId lsrId) {
248 + // TODO Auto-generated method stub
249 + return false;
250 + }
211 } 251 }
......
...@@ -12,9 +12,7 @@ import org.onlab.packet.Ethernet; ...@@ -12,9 +12,7 @@ import org.onlab.packet.Ethernet;
12 import org.onlab.packet.IPv4; 12 import org.onlab.packet.IPv4;
13 import org.onlab.packet.MacAddress; 13 import org.onlab.packet.MacAddress;
14 import org.onlab.packet.TCP; 14 import org.onlab.packet.TCP;
15 -import org.onosproject.net.AnnotationKeys;
16 import org.onosproject.net.ConnectPoint; 15 import org.onosproject.net.ConnectPoint;
17 -import org.onosproject.net.Device;
18 import org.onosproject.net.DeviceId; 16 import org.onosproject.net.DeviceId;
19 import org.onosproject.net.PortNumber; 17 import org.onosproject.net.PortNumber;
20 import org.onosproject.net.device.DeviceService; 18 import org.onosproject.net.device.DeviceService;
...@@ -96,22 +94,7 @@ public class PcepPacketProvider extends AbstractProvider implements PacketProvid ...@@ -96,22 +94,7 @@ public class PcepPacketProvider extends AbstractProvider implements PacketProvid
96 94
97 // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID. 95 // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
98 String lsrId = String.valueOf(pccId.ipAddress()); 96 String lsrId = String.valueOf(pccId.ipAddress());
99 - DeviceId pccDeviceId = null; 97 + DeviceId pccDeviceId = DeviceId.deviceId(lsrId);
100 -
101 - // Find PCC deviceID from lsrId stored as annotations
102 - Iterable<Device> devices = deviceService.getAvailableDevices();
103 - for (Device dev : devices) {
104 - if ("L3".equals(dev.annotations().value(AnnotationKeys.TYPE))
105 - && lsrId.equals(dev.annotations().value(LSRID))) {
106 - pccDeviceId = dev.id();
107 - break;
108 - }
109 - }
110 -
111 - if (pccDeviceId == null) {
112 - log.error("Device not found to perform label DB sync.");
113 - return;
114 - }
115 98
116 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId, 99 InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId,
117 PortNumber.portNumber(PCEP_PORT)), 100 PortNumber.portNumber(PCEP_PORT)),
......