1ff7b7f5ac940240803831b14a857cc66c09a075
[bgpcep.git] / pcep / tunnel-provider / src / main / java / org / opendaylight / bgpcep / pcep / tunnel / provider / NodeChangedListener.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.bgpcep.pcep.tunnel.provider;
9
10 import java.util.HashSet;
11 import java.util.Map;
12 import java.util.Set;
13
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
16 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
17 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
18 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.AdministrativeStatus;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.ReportedLsp1;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.lsp.identifiers.AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Case;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Case;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv6._case.Ipv6;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.Link1;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.Link1Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.SupportingNode1;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.SupportingNode1Builder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.rev130820.tunnel.pcep.supporting.node.attributes.PathComputationClientBuilder;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNodeBuilder;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNodeKey;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.TerminationPointType;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.Ip;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.IpBuilder;
59 import org.opendaylight.yangtools.yang.binding.DataObject;
60 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
61 import org.opendaylight.yangtools.yang.common.RpcResult;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
64
65 import com.google.common.base.Preconditions;
66 import com.google.common.collect.Lists;
67 import com.google.common.util.concurrent.FutureCallback;
68 import com.google.common.util.concurrent.Futures;
69 import com.google.common.util.concurrent.JdkFutureAdapters;
70
71 public final class NodeChangedListener implements DataChangeListener {
72         public static final Logger LOG = LoggerFactory.getLogger(NodeChangedListener.class);
73         private final InstanceIdentifier<Topology> target;
74         private final DataProviderService dataProvider;
75
76         NodeChangedListener(final DataProviderService dataProvider, final InstanceIdentifier<Topology> target) {
77                 this.dataProvider = Preconditions.checkNotNull(dataProvider);
78                 this.target = Preconditions.checkNotNull(target);
79         }
80
81         private static void categorizeIdentifier(final InstanceIdentifier<?> i, final Set<InstanceIdentifier<ReportedLsp>> changedLsps,
82                         final Set<InstanceIdentifier<Node>> changedNodes) {
83                 final InstanceIdentifier<ReportedLsp> li = i.firstIdentifierOf(ReportedLsp.class);
84                 if (li == null) {
85                         final InstanceIdentifier<Node> ni = i.firstIdentifierOf(Node.class);
86                         if (ni == null) {
87                                 LOG.warn("Ignoring uncategorized identifier {}", i);
88                         } else {
89                                 changedNodes.add(ni);
90                         }
91                 } else {
92                         changedLsps.add(li);
93                 }
94         }
95
96         private static void enumerateLsps(final InstanceIdentifier<Node> id, final Node node, final Set<InstanceIdentifier<ReportedLsp>> lsps) {
97                 if (node == null) {
98                         LOG.trace("Skipping null node", id);
99                         return;
100                 }
101                 final Node1 pccnode = node.getAugmentation(Node1.class);
102                 if (pccnode == null) {
103                         LOG.trace("Skipping non-PCEP-enabled node {}", id);
104                         return;
105                 }
106
107                 for (final ReportedLsp l : pccnode.getPathComputationClient().getReportedLsp()) {
108                         lsps.add(InstanceIdentifier.builder(id).augmentation(Node1.class).child(PathComputationClient.class).child(ReportedLsp.class,
109                                         l.getKey()).toInstance());
110                 }
111         }
112
113         private static LinkId linkIdForLsp(final InstanceIdentifier<ReportedLsp> i, final ReportedLsp lsp) {
114                 return new LinkId(i.firstKeyOf(Node.class, NodeKey.class).getNodeId().getValue() + "/lsps/" + lsp.getName());
115         }
116
117         private InstanceIdentifier<Link> linkForLsp(final LinkId linkId) {
118                 return InstanceIdentifier.builder(this.target).child(Link.class, new LinkKey(linkId)).toInstance();
119         }
120
121         private SupportingNode createSupportingNode(final NodeId sni, final Boolean inControl) {
122                 final SupportingNodeKey sk = new SupportingNodeKey(sni);
123                 final SupportingNodeBuilder snb = new SupportingNodeBuilder();
124                 snb.setNodeRef(sni);
125                 snb.setKey(sk);
126                 snb.addAugmentation(
127                                 SupportingNode1.class,
128                                 new SupportingNode1Builder().setPathComputationClient(new PathComputationClientBuilder().setControlling(inControl).build()).build());
129
130                 return snb.build();
131         }
132
133         private InstanceIdentifier<TerminationPoint> getIpTerminationPoint(final DataModificationTransaction trans, final IpAddress addr,
134                         final InstanceIdentifier<Node> sni, final Boolean inControl) {
135                 for (final Node n : ((Topology) trans.readOperationalData(this.target)).getNode()) {
136                         for (final TerminationPoint tp : n.getTerminationPoint()) {
137                                 final TerminationPoint1 tpa = tp.getAugmentation(TerminationPoint1.class);
138
139                                 if (tpa != null) {
140                                         final TerminationPointType tpt = tpa.getIgpTerminationPointAttributes().getTerminationPointType();
141
142                                         if (tpt instanceof Ip) {
143                                                 for (final IpAddress a : ((Ip) tpt).getIpAddress()) {
144                                                         if (addr.equals(a.getIpv6Address())) {
145                                                                 if (sni != null) {
146                                                                         final NodeKey k = InstanceIdentifier.keyOf(sni);
147                                                                         boolean have = false;
148
149                                                                         /*
150                                                                          * We may have found a termination point which has been created as a destination,
151                                                                          * so it does not have a supporting node pointer. Since we now know what it is,
152                                                                          * fill it in.
153                                                                          */
154                                                                         for (final SupportingNode sn : n.getSupportingNode()) {
155                                                                                 if (sn.getNodeRef().equals(k.getNodeId())) {
156                                                                                         have = true;
157                                                                                         break;
158                                                                                 }
159                                                                         }
160
161                                                                         if (!have) {
162                                                                                 final SupportingNode sn = createSupportingNode(k.getNodeId(), inControl);
163
164                                                                                 trans.putOperationalData(
165                                                                                                 InstanceIdentifier.builder(this.target).child(Node.class, n.getKey()).child(
166                                                                                                                 SupportingNode.class, sn.getKey()).toInstance(), sn);
167                                                                         }
168                                                                 }
169                                                                 return InstanceIdentifier.builder(this.target).child(Node.class, n.getKey()).child(TerminationPoint.class,
170                                                                                 tp.getKey()).toInstance();
171                                                         }
172                                                 }
173                                         } else {
174                                                 LOG.debug("Ignoring termination point type {}", tpt);
175                                         }
176                                 }
177                         }
178                 }
179
180                 LOG.debug("Termination point for {} not found, creating a new one", addr);
181
182                 final String url = "ip://" + addr.toString();
183                 final TerminationPointKey tpk = new TerminationPointKey(new TpId(url));
184                 final TerminationPointBuilder tpb = new TerminationPointBuilder();
185                 tpb.setKey(tpk).setTpId(tpk.getTpId());
186                 tpb.addAugmentation(
187                                 TerminationPoint1.class,
188                                 new TerminationPoint1Builder().setIgpTerminationPointAttributes(
189                                                 new IgpTerminationPointAttributesBuilder().setTerminationPointType(
190                                                                 new IpBuilder().setIpAddress(Lists.newArrayList(addr)).build()).build()).build());
191
192                 final NodeKey nk = new NodeKey(new NodeId(url));
193                 final NodeBuilder nb = new NodeBuilder();
194                 nb.setKey(nk).setNodeId(nk.getNodeId());
195                 nb.setTerminationPoint(Lists.newArrayList(tpb.build()));
196                 if (sni != null) {
197                         nb.setSupportingNode(Lists.newArrayList(createSupportingNode(InstanceIdentifier.keyOf(sni).getNodeId(), inControl)));
198                 }
199
200                 trans.putOperationalData(InstanceIdentifier.builder(this.target).child(Node.class, nb.getKey()).toInstance(), nb.build());
201                 return InstanceIdentifier.builder(this.target).child(Node.class, nb.getKey()).child(TerminationPoint.class, tpb.getKey()).toInstance();
202         }
203
204         private void create(final DataModificationTransaction trans, final InstanceIdentifier<ReportedLsp> i, final ReportedLsp value) {
205                 final InstanceIdentifier<Node> ni = i.firstIdentifierOf(Node.class);
206                 final ReportedLsp1 rl = value.getAugmentation(ReportedLsp1.class);
207
208                 final AddressFamily af = rl.getLsp().getTlvs().getLspIdentifiers().getAddressFamily();
209
210                 /*
211                  * We are trying to ensure we have source and destination nodes.
212                  */
213                 final IpAddress srcIp, dstIp;
214                 if (af instanceof Ipv4Case) {
215                         final Ipv4 ipv4 = ((Ipv4Case) af).getIpv4();
216                         srcIp = new IpAddress(ipv4.getSourceIpv4Address());
217                         dstIp = new IpAddress(ipv4.getDestinationIpv4Address());
218                 } else if (af instanceof Ipv6Case) {
219                         final Ipv6 ipv6 = ((Ipv6Case) af).getIpv6();
220                         srcIp = new IpAddress(ipv6.getSourceIpv6Address());
221                         dstIp = new IpAddress(ipv6.getDestinationIpv6Address());
222                 } else {
223                         throw new IllegalArgumentException("Unsupported address family: " + af.getImplementedInterface());
224                 }
225
226                 final Link1Builder lab = new Link1Builder(value.getPath().getLspa());
227                 lab.setBandwidth(value.getPath().getBandwidth().getBandwidth());
228                 lab.setClassType(value.getPath().getClassType().getClassType());
229                 lab.setSymbolicPathName(value.getName());
230
231                 final InstanceIdentifier<TerminationPoint> dst = getIpTerminationPoint(trans, dstIp, null, Boolean.FALSE);
232                 final InstanceIdentifier<TerminationPoint> src = getIpTerminationPoint(trans, srcIp, ni, rl.getLsp().isDelegate());
233
234                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Link1Builder slab = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Link1Builder();
235                 slab.setOperationalStatus(rl.getLsp().getOperational());
236                 slab.setAdministrativeStatus(rl.getLsp().isAdministrative() ? AdministrativeStatus.Active : AdministrativeStatus.Inactive);
237
238                 final LinkId id = linkIdForLsp(i, value);
239                 final LinkBuilder lb = new LinkBuilder();
240                 lb.setLinkId(id);
241
242                 lb.setSource(new SourceBuilder().setSourceNode(src.firstKeyOf(Node.class, NodeKey.class).getNodeId()).setSourceTp(
243                                 src.firstKeyOf(TerminationPoint.class, TerminationPointKey.class).getTpId()).build());
244                 lb.setDestination(new DestinationBuilder().setDestNode(dst.firstKeyOf(Node.class, NodeKey.class).getNodeId()).setDestTp(
245                                 dst.firstKeyOf(TerminationPoint.class, TerminationPointKey.class).getTpId()).build());
246                 lb.addAugmentation(Link1.class, lab.build());
247                 lb.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Link1.class, slab.build());
248
249                 trans.putOperationalData(linkForLsp(id), lb.build());
250         }
251
252         private InstanceIdentifier<TerminationPoint> tpIdentifier(final NodeId node, final TpId tp) {
253                 return InstanceIdentifier.builder(this.target).child(Node.class, new NodeKey(node)).child(TerminationPoint.class, new TerminationPointKey(tp)).toInstance();
254         }
255
256         private InstanceIdentifier<Node> nodeIdentifier(final NodeId node) {
257                 return InstanceIdentifier.builder(this.target).child(Node.class, new NodeKey(node)).toInstance();
258         }
259
260         private void remove(final DataModificationTransaction trans, final InstanceIdentifier<ReportedLsp> i, final ReportedLsp value) {
261                 final InstanceIdentifier<Link> li = linkForLsp(linkIdForLsp(i, value));
262
263                 final Link l = (Link) trans.readOperationalData(li);
264                 if (l != null) {
265                         LOG.debug("Removing link {} (was {})", li, l);
266                         trans.removeOperationalData(li);
267
268                         LOG.debug("Searching for orphan links/nodes");
269                         final Topology t = (Topology) trans.readOperationalData(InstanceIdentifier.builder(this.target).toInstance());
270
271                         NodeId srcNode = l.getSource().getSourceNode();
272                         NodeId dstNode = l.getDestination().getDestNode();
273                         TpId srcTp = l.getSource().getSourceTp();
274                         TpId dstTp = l.getDestination().getDestTp();
275
276                         boolean orphSrcNode = true, orphDstNode = true, orphDstTp = true, orphSrcTp = true;
277                         for (final Link lw : t.getLink()) {
278                                 LOG.trace("Checking link {}", lw);
279
280                                 final NodeId sn = lw.getSource().getSourceNode();
281                                 final NodeId dn = lw.getDestination().getDestNode();
282                                 final TpId st = lw.getSource().getSourceTp();
283                                 final TpId dt = lw.getDestination().getDestTp();
284
285                                 // Source node checks
286                                 if (srcNode.equals(sn)) {
287                                         if (orphSrcNode) {
288                                                 LOG.debug("Node {} held by source of link {}", srcNode, lw);
289                                                 orphSrcNode = false;
290                                         }
291                                         if (orphSrcTp && srcTp.equals(st)) {
292                                                 LOG.debug("TP {} held by source of link {}", srcTp, lw);
293                                                 orphSrcTp = false;
294                                         }
295                                 }
296                                 if (srcNode.equals(dn)) {
297                                         if (orphSrcNode) {
298                                                 LOG.debug("Node {} held by destination of link {}", srcNode, lw);
299                                                 orphSrcNode = false;
300                                         }
301                                         if (orphSrcTp && srcTp.equals(dt)) {
302                                                 LOG.debug("TP {} held by destination of link {}", srcTp, lw);
303                                                 orphSrcTp = false;
304                                         }
305                                 }
306
307                                 // Destination node checks
308                                 if (dstNode.equals(sn)) {
309                                         if (orphDstNode) {
310                                                 LOG.debug("Node {} held by source of link {}", dstNode, lw);
311                                                 orphDstNode = false;
312                                         }
313                                         if (orphDstTp && dstTp.equals(st)) {
314                                                 LOG.debug("TP {} held by source of link {}", dstTp, lw);
315                                                 orphDstTp = false;
316                                         }
317                                 }
318                                 if (dstNode.equals(dn)) {
319                                         if (orphDstNode) {
320                                                 LOG.debug("Node {} held by destination of link {}", dstNode, lw);
321                                                 orphDstNode = false;
322                                         }
323                                         if (orphDstTp && dstTp.equals(dt)) {
324                                                 LOG.debug("TP {} held by destination of link {}", dstTp, lw);
325                                                 orphDstTp = false;
326                                         }
327                                 }
328                         }
329
330                         if (orphSrcNode && !orphSrcTp) {
331                                 LOG.warn("Orphan source node {} but not TP {}, retaining the node", srcNode, srcTp);
332                                 orphSrcNode = false;
333                         }
334                         if (orphDstNode && !orphDstTp) {
335                                 LOG.warn("Orphan destination node {} but not TP {}, retaining the node", dstNode, dstTp);
336                                 orphDstNode = false;
337                         }
338
339                         if (orphSrcNode) {
340                                 LOG.debug("Removing orphan node {}", srcNode);
341                                 trans.removeOperationalData(nodeIdentifier(srcNode));
342                         } else if (orphSrcTp) {
343                                 LOG.debug("Removing orphan TP {} on node {}", srcTp, srcNode);
344                                 trans.removeOperationalData(tpIdentifier(srcNode, srcTp));
345                         }
346                         if (orphDstNode) {
347                                 LOG.debug("Removing orphan node {}", dstNode);
348                                 trans.removeOperationalData(nodeIdentifier(dstNode));
349                         } else if (orphDstTp) {
350                                 LOG.debug("Removing orphan TP {} on node {}", dstTp, dstNode);
351                                 trans.removeOperationalData(tpIdentifier(dstNode, dstTp));
352                         }
353                 }
354         }
355
356         @Override
357         public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
358                 final DataModificationTransaction trans = this.dataProvider.beginTransaction();
359
360                 final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
361                 final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();
362
363                 // Categorize reported identifiers
364                 for (final InstanceIdentifier<?> i : change.getRemovedOperationalData()) {
365                         categorizeIdentifier(i, lsps, nodes);
366                 }
367                 for (final InstanceIdentifier<?> i : change.getUpdatedOperationalData().keySet()) {
368                         categorizeIdentifier(i, lsps, nodes);
369                 }
370                 for (final InstanceIdentifier<?> i : change.getCreatedOperationalData().keySet()) {
371                         categorizeIdentifier(i, lsps, nodes);
372                 }
373
374                 // Get the subtrees
375                 final Map<InstanceIdentifier<?>, DataObject> o = change.getOriginalOperationalData();
376                 final Map<InstanceIdentifier<?>, DataObject> n = change.getUpdatedOperationalData();
377
378                 // Now walk all nodes, check for removals/additions and cascade them to LSPs
379                 for (final InstanceIdentifier<Node> i : nodes) {
380                         enumerateLsps(i, (Node) o.get(i), lsps);
381                         enumerateLsps(i, (Node) n.get(i), lsps);
382                 }
383
384                 // We now have list of all affected LSPs. Walk them create/remove them
385                 for (final InstanceIdentifier<ReportedLsp> i : lsps) {
386                         final ReportedLsp oldValue = (ReportedLsp) o.get(i);
387                         final ReportedLsp newValue = (ReportedLsp) n.get(i);
388
389                         LOG.debug("Updating lsp {} value {} -> {}", i, oldValue, newValue);
390                         if (oldValue != null) {
391                                 remove(trans, i, oldValue);
392                         }
393                         if (newValue != null) {
394                                 create(trans, i, newValue);
395                         }
396                 }
397
398                 Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.commit()), new FutureCallback<RpcResult<TransactionStatus>>() {
399                         @Override
400                         public void onSuccess(final RpcResult<TransactionStatus> result) {
401                                 LOG.trace("Topology change committed successfully");
402                         }
403
404                         @Override
405                         public void onFailure(final Throwable t) {
406                                 LOG.error("Failed to propagate a topology change, target topology became inconsistent", t);
407                         }
408                 });
409         }
410
411         public static InstanceIdentifier<Link> linkIdentifier(final InstanceIdentifier<Topology> topology, final NodeId node,
412                         final String name) {
413                 return InstanceIdentifier.builder(topology).child(Link.class, new LinkKey(new LinkId(node.getValue() + "/lsp/" + name))).toInstance();
414         }
415 }