Priyanka B
Committed by Gerrit Code Review

[ONOS-4167] Identify the impacted tunnels based on network events, reilency with UT

Change-Id: I2bae0b789a22b8a6854f4e12b692d03cd6f7415d
...@@ -52,6 +52,7 @@ import org.onosproject.incubator.net.tunnel.TunnelId; ...@@ -52,6 +52,7 @@ import org.onosproject.incubator.net.tunnel.TunnelId;
52 import org.onosproject.incubator.net.tunnel.TunnelListener; 52 import org.onosproject.incubator.net.tunnel.TunnelListener;
53 import org.onosproject.incubator.net.tunnel.TunnelName; 53 import org.onosproject.incubator.net.tunnel.TunnelName;
54 import org.onosproject.incubator.net.tunnel.TunnelService; 54 import org.onosproject.incubator.net.tunnel.TunnelService;
55 +import org.onosproject.mastership.MastershipService;
55 import org.onosproject.net.DefaultAnnotations; 56 import org.onosproject.net.DefaultAnnotations;
56 import org.onosproject.net.DefaultAnnotations.Builder; 57 import org.onosproject.net.DefaultAnnotations.Builder;
57 import org.onosproject.net.Device; 58 import org.onosproject.net.Device;
...@@ -63,6 +64,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveService; ...@@ -63,6 +64,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveService;
63 import org.onosproject.net.flowobjective.Objective; 64 import org.onosproject.net.flowobjective.Objective;
64 import org.onosproject.net.intent.Constraint; 65 import org.onosproject.net.intent.Constraint;
65 import org.onosproject.net.intent.constraint.BandwidthConstraint; 66 import org.onosproject.net.intent.constraint.BandwidthConstraint;
67 +import org.onosproject.net.link.LinkEvent;
66 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; 68 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
67 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; 69 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType;
68 import org.onosproject.pce.pceservice.constraint.CostConstraint; 70 import org.onosproject.pce.pceservice.constraint.CostConstraint;
...@@ -76,6 +78,9 @@ import org.onosproject.net.resource.Resources; ...@@ -76,6 +78,9 @@ import org.onosproject.net.resource.Resources;
76 import org.onosproject.net.topology.LinkWeight; 78 import org.onosproject.net.topology.LinkWeight;
77 import org.onosproject.net.topology.PathService; 79 import org.onosproject.net.topology.PathService;
78 import org.onosproject.net.topology.TopologyEdge; 80 import org.onosproject.net.topology.TopologyEdge;
81 +import org.onosproject.net.topology.TopologyEvent;
82 +import org.onosproject.net.topology.TopologyListener;
83 +import org.onosproject.net.topology.TopologyService;
79 import org.onosproject.pce.pceservice.api.PceService; 84 import org.onosproject.pce.pceservice.api.PceService;
80 import org.onosproject.pce.pcestore.PcePathInfo; 85 import org.onosproject.pce.pcestore.PcePathInfo;
81 import org.onosproject.pce.pcestore.PceccTunnelInfo; 86 import org.onosproject.pce.pcestore.PceccTunnelInfo;
...@@ -171,12 +176,19 @@ public class PceManager implements PceService { ...@@ -171,12 +176,19 @@ public class PceManager implements PceService {
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 176 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
172 protected FlowObjectiveService flowObjectiveService; 177 protected FlowObjectiveService flowObjectiveService;
173 178
179 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
180 + protected MastershipService mastershipService;
181 +
182 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
183 + protected TopologyService topologyService;
184 +
174 private TunnelListener listener = new InnerTunnelListener(); 185 private TunnelListener listener = new InnerTunnelListener();
175 private BasicPceccHandler crHandler; 186 private BasicPceccHandler crHandler;
176 private PceccSrTeBeHandler srTeHandler; 187 private PceccSrTeBeHandler srTeHandler;
177 private ApplicationId appId; 188 private ApplicationId appId;
178 189
179 private final PcepPacketProcessor processor = new PcepPacketProcessor(); 190 private final PcepPacketProcessor processor = new PcepPacketProcessor();
191 + private final TopologyListener topologyListener = new InternalTopologyListener();
180 192
181 /** 193 /**
182 * Creates new instance of PceManager. 194 * Creates new instance of PceManager.
...@@ -204,6 +216,7 @@ public class PceManager implements PceService { ...@@ -204,6 +216,7 @@ public class PceManager implements PceService {
204 .asDistributedSet(); 216 .asDistributedSet();
205 217
206 packetService.addProcessor(processor, PacketProcessor.director(4)); 218 packetService.addProcessor(processor, PacketProcessor.director(4));
219 + topologyService.addListener(topologyListener);
207 log.info("Started"); 220 log.info("Started");
208 } 221 }
209 222
...@@ -211,6 +224,7 @@ public class PceManager implements PceService { ...@@ -211,6 +224,7 @@ public class PceManager implements PceService {
211 protected void deactivate() { 224 protected void deactivate() {
212 tunnelService.removeListener(listener); 225 tunnelService.removeListener(listener);
213 packetService.removeProcessor(processor); 226 packetService.removeProcessor(processor);
227 + topologyService.removeListener(topologyListener);
214 log.info("Stopped"); 228 log.info("Stopped");
215 } 229 }
216 230
...@@ -395,6 +409,7 @@ public class PceManager implements PceService { ...@@ -395,6 +409,7 @@ public class PceManager implements PceService {
395 List<Link> links = tunnel.path().links(); 409 List<Link> links = tunnel.path().links();
396 String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE); 410 String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE);
397 double bwConstraintValue = 0; 411 double bwConstraintValue = 0;
412 + String costType = null;
398 SharedBandwidthConstraint shBwConstraint = null; 413 SharedBandwidthConstraint shBwConstraint = null;
399 BandwidthConstraint bwConstraint = null; 414 BandwidthConstraint bwConstraint = null;
400 CostConstraint costConstraint = null; 415 CostConstraint costConstraint = null;
...@@ -409,6 +424,7 @@ public class PceManager implements PceService { ...@@ -409,6 +424,7 @@ public class PceManager implements PceService {
409 bwConstraintValue = bwConstraint.bandwidth().bps(); 424 bwConstraintValue = bwConstraint.bandwidth().bps();
410 } else if (constraint instanceof CostConstraint) { 425 } else if (constraint instanceof CostConstraint) {
411 costConstraint = (CostConstraint) constraint; 426 costConstraint = (CostConstraint) constraint;
427 + costType = costConstraint.type().name();
412 } 428 }
413 } 429 }
414 430
...@@ -454,6 +470,9 @@ public class PceManager implements PceService { ...@@ -454,6 +470,9 @@ public class PceManager implements PceService {
454 470
455 Builder annotationBuilder = DefaultAnnotations.builder(); 471 Builder annotationBuilder = DefaultAnnotations.builder();
456 annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue)); 472 annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue));
473 + if (costType != null) {
474 + annotationBuilder.set(COST_TYPE, costType);
475 + }
457 annotationBuilder.set(LSP_SIG_TYPE, lspSigType); 476 annotationBuilder.set(LSP_SIG_TYPE, lspSigType);
458 annotationBuilder.set(PCE_INIT, TRUE); 477 annotationBuilder.set(PCE_INIT, TRUE);
459 annotationBuilder.set(DELEGATE, TRUE); 478 annotationBuilder.set(DELEGATE, TRUE);
...@@ -594,8 +613,61 @@ public class PceManager implements PceService { ...@@ -594,8 +613,61 @@ public class PceManager implements PceService {
594 } 613 }
595 } 614 }
596 615
616 + //TODO: annotations used for temporarily later projection/network config will be used
617 + private class InternalTopologyListener implements TopologyListener {
618 + @Override
619 + public void event(TopologyEvent event) {
620 + event.reasons().forEach(e -> {
621 + //If event type is link removed, get the impacted tunnel
622 + if (e instanceof LinkEvent) {
623 + LinkEvent linkEvent = (LinkEvent) e;
624 + if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
625 + tunnelService.queryTunnel(MPLS).forEach(t -> {
626 + if (t.path().links().contains(((Link) e.subject()))) {
627 + // Check whether this ONOS instance is master for ingress device if yes,
628 + // recompute and send update
629 + checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
630 + }
631 + });
632 + }
633 + }
634 + });
635 + }
636 + }
637 +
638 + private boolean checkForMasterAndUpdateTunnel(DeviceId src, Tunnel tunnel) {
639 + /**
640 + * Master of ingress node will recompute and also delegation flag must be set.
641 + */
642 + if (mastershipService.isLocalMaster(src)
643 + && Boolean.valueOf(tunnel.annotations().value(DELEGATE)) != null) {
644 + LinkedList<Constraint> constraintList = new LinkedList<>();
645 +
646 + if (tunnel.annotations().value(BANDWIDTH) != null) {
647 + //Requested bandwidth will be same as previous allocated bandwidth for the tunnel
648 + BandwidthConstraint localConst = new BandwidthConstraint(Bandwidth.bps(Double.parseDouble(tunnel
649 + .annotations().value(BANDWIDTH))));
650 + constraintList.add(localConst);
651 + }
652 + if (tunnel.annotations().value(COST_TYPE) != null) {
653 + constraintList.add(CostConstraint.of(CostConstraint.Type.valueOf(tunnel.annotations().value(
654 + COST_TYPE))));
655 + }
656 + if (!updatePath(tunnel.tunnelId(), constraintList)) {
657 + // If updation fails store in PCE store as failed path
658 + // then PCInitiate (Remove)
659 + pceStore.addFailedPathInfo(new PcePathInfo(tunnel.path().src().deviceId(), tunnel
660 + .path().dst().deviceId(), tunnel.tunnelName().value(), constraintList,
661 + LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))));
662 + //Release that tunnel calling PCInitiate
663 + releasePath(tunnel.tunnelId());
664 + }
665 + }
666 +
667 + return false;
668 + }
597 669
598 - // Allocates the bandwidth locally for PCECC tunnels. 670 + // Allocates the bandwidth locally for PCECC tunnels.
599 private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint, 671 private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint,
600 SharedBandwidthConstraint shBwConstraint) { 672 SharedBandwidthConstraint shBwConstraint) {
601 checkNotNull(computedPath); 673 checkNotNull(computedPath);
......