Priyanka B
Committed by Priyankab-Huawei

[ONOS] Cherry picked from master 1.7

Change-Id: I74a0c1634f9c425af2bcb646edc3d9170b3c087c
Showing 73 changed files with 5086 additions and 757 deletions
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 <groupId>org.onosproject</groupId> 22 <groupId>org.onosproject</groupId>
23 <artifactId>onos-pce</artifactId> 23 <artifactId>onos-pce</artifactId>
24 <version>1.6.0-SNAPSHOT</version> 24 <version>1.6.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
25 </parent> 26 </parent>
26 <artifactId>onos-app-pce</artifactId> 27 <artifactId>onos-app-pce</artifactId>
27 <packaging>bundle</packaging> 28 <packaging>bundle</packaging>
......
...@@ -26,6 +26,12 @@ import java.util.Map; ...@@ -26,6 +26,12 @@ import java.util.Map;
26 import java.util.Optional; 26 import java.util.Optional;
27 import java.util.Map.Entry; 27 import java.util.Map.Entry;
28 import java.util.Set; 28 import java.util.Set;
29 +import java.util.concurrent.Executors;
30 +import java.util.concurrent.ScheduledExecutorService;
31 +import java.util.concurrent.TimeUnit;
32 +
33 +import org.onlab.packet.Ethernet;
34 +import org.onlab.packet.IPv4;
29 35
30 import org.apache.felix.scr.annotations.Activate; 36 import org.apache.felix.scr.annotations.Activate;
31 import org.apache.felix.scr.annotations.Component; 37 import org.apache.felix.scr.annotations.Component;
...@@ -35,6 +41,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -35,6 +41,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
35 import org.apache.felix.scr.annotations.Service; 41 import org.apache.felix.scr.annotations.Service;
36 import org.onlab.packet.IpAddress; 42 import org.onlab.packet.IpAddress;
37 import org.onlab.packet.IpPrefix; 43 import org.onlab.packet.IpPrefix;
44 +import org.onlab.packet.TCP;
38 import org.onlab.util.Bandwidth; 45 import org.onlab.util.Bandwidth;
39 import org.onosproject.core.ApplicationId; 46 import org.onosproject.core.ApplicationId;
40 import org.onosproject.core.CoreService; 47 import org.onosproject.core.CoreService;
...@@ -52,6 +59,7 @@ import org.onosproject.incubator.net.tunnel.TunnelId; ...@@ -52,6 +59,7 @@ import org.onosproject.incubator.net.tunnel.TunnelId;
52 import org.onosproject.incubator.net.tunnel.TunnelListener; 59 import org.onosproject.incubator.net.tunnel.TunnelListener;
53 import org.onosproject.incubator.net.tunnel.TunnelName; 60 import org.onosproject.incubator.net.tunnel.TunnelName;
54 import org.onosproject.incubator.net.tunnel.TunnelService; 61 import org.onosproject.incubator.net.tunnel.TunnelService;
62 +import org.onosproject.mastership.MastershipService;
55 import org.onosproject.net.DefaultAnnotations; 63 import org.onosproject.net.DefaultAnnotations;
56 import org.onosproject.net.DefaultAnnotations.Builder; 64 import org.onosproject.net.DefaultAnnotations.Builder;
57 import org.onosproject.net.Device; 65 import org.onosproject.net.Device;
...@@ -63,6 +71,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveService; ...@@ -63,6 +71,7 @@ import org.onosproject.net.flowobjective.FlowObjectiveService;
63 import org.onosproject.net.flowobjective.Objective; 71 import org.onosproject.net.flowobjective.Objective;
64 import org.onosproject.net.intent.Constraint; 72 import org.onosproject.net.intent.Constraint;
65 import org.onosproject.net.intent.constraint.BandwidthConstraint; 73 import org.onosproject.net.intent.constraint.BandwidthConstraint;
74 +import org.onosproject.net.link.LinkEvent;
66 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; 75 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
67 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; 76 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType;
68 import org.onosproject.pce.pceservice.constraint.CostConstraint; 77 import org.onosproject.pce.pceservice.constraint.CostConstraint;
...@@ -76,6 +85,9 @@ import org.onosproject.net.resource.Resources; ...@@ -76,6 +85,9 @@ import org.onosproject.net.resource.Resources;
76 import org.onosproject.net.topology.LinkWeight; 85 import org.onosproject.net.topology.LinkWeight;
77 import org.onosproject.net.topology.PathService; 86 import org.onosproject.net.topology.PathService;
78 import org.onosproject.net.topology.TopologyEdge; 87 import org.onosproject.net.topology.TopologyEdge;
88 +import org.onosproject.net.topology.TopologyEvent;
89 +import org.onosproject.net.topology.TopologyListener;
90 +import org.onosproject.net.topology.TopologyService;
79 import org.onosproject.pce.pceservice.api.PceService; 91 import org.onosproject.pce.pceservice.api.PceService;
80 import org.onosproject.pce.pcestore.PcePathInfo; 92 import org.onosproject.pce.pcestore.PcePathInfo;
81 import org.onosproject.pce.pcestore.PceccTunnelInfo; 93 import org.onosproject.pce.pcestore.PceccTunnelInfo;
...@@ -131,6 +143,7 @@ public class PceManager implements PceService { ...@@ -131,6 +143,7 @@ public class PceManager implements PceService {
131 private static final String TRUE = "true"; 143 private static final String TRUE = "true";
132 private static final String FALSE = "false"; 144 private static final String FALSE = "false";
133 private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32"; 145 private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32";
146 + public static final int PCEP_PORT = 4189;
134 147
135 private IdGenerator localLspIdIdGen; 148 private IdGenerator localLspIdIdGen;
136 protected DistributedSet<Short> localLspIdFreeList; 149 protected DistributedSet<Short> localLspIdFreeList;
...@@ -171,12 +184,23 @@ public class PceManager implements PceService { ...@@ -171,12 +184,23 @@ public class PceManager implements PceService {
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 184 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
172 protected FlowObjectiveService flowObjectiveService; 185 protected FlowObjectiveService flowObjectiveService;
173 186
187 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
188 + protected MastershipService mastershipService;
189 +
190 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
191 + protected TopologyService topologyService;
192 +
174 private TunnelListener listener = new InnerTunnelListener(); 193 private TunnelListener listener = new InnerTunnelListener();
175 private BasicPceccHandler crHandler; 194 private BasicPceccHandler crHandler;
176 private PceccSrTeBeHandler srTeHandler; 195 private PceccSrTeBeHandler srTeHandler;
177 private ApplicationId appId; 196 private ApplicationId appId;
178 197
179 private final PcepPacketProcessor processor = new PcepPacketProcessor(); 198 private final PcepPacketProcessor processor = new PcepPacketProcessor();
199 + private final TopologyListener topologyListener = new InternalTopologyListener();
200 + private ScheduledExecutorService executor;
201 +
202 + public static final int INITIAL_DELAY = 30;
203 + public static final int PERIODIC_DELAY = 30;
180 204
181 /** 205 /**
182 * Creates new instance of PceManager. 206 * Creates new instance of PceManager.
...@@ -204,6 +228,10 @@ public class PceManager implements PceService { ...@@ -204,6 +228,10 @@ public class PceManager implements PceService {
204 .asDistributedSet(); 228 .asDistributedSet();
205 229
206 packetService.addProcessor(processor, PacketProcessor.director(4)); 230 packetService.addProcessor(processor, PacketProcessor.director(4));
231 + topologyService.addListener(topologyListener);
232 + executor = Executors.newSingleThreadScheduledExecutor();
233 + //Start a timer when the component is up, with initial delay of 30min and periodic delays at 30min
234 + executor.scheduleAtFixedRate(new GlobalOptimizationTimer(), INITIAL_DELAY, PERIODIC_DELAY, TimeUnit.MINUTES);
207 log.info("Started"); 235 log.info("Started");
208 } 236 }
209 237
...@@ -211,6 +239,9 @@ public class PceManager implements PceService { ...@@ -211,6 +239,9 @@ public class PceManager implements PceService {
211 protected void deactivate() { 239 protected void deactivate() {
212 tunnelService.removeListener(listener); 240 tunnelService.removeListener(listener);
213 packetService.removeProcessor(processor); 241 packetService.removeProcessor(processor);
242 + topologyService.removeListener(topologyListener);
243 + //Shutdown the thread when component is deactivated
244 + executor.shutdown();
214 log.info("Stopped"); 245 log.info("Stopped");
215 } 246 }
216 247
...@@ -395,6 +426,7 @@ public class PceManager implements PceService { ...@@ -395,6 +426,7 @@ public class PceManager implements PceService {
395 List<Link> links = tunnel.path().links(); 426 List<Link> links = tunnel.path().links();
396 String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE); 427 String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE);
397 double bwConstraintValue = 0; 428 double bwConstraintValue = 0;
429 + String costType = null;
398 SharedBandwidthConstraint shBwConstraint = null; 430 SharedBandwidthConstraint shBwConstraint = null;
399 BandwidthConstraint bwConstraint = null; 431 BandwidthConstraint bwConstraint = null;
400 CostConstraint costConstraint = null; 432 CostConstraint costConstraint = null;
...@@ -409,6 +441,7 @@ public class PceManager implements PceService { ...@@ -409,6 +441,7 @@ public class PceManager implements PceService {
409 bwConstraintValue = bwConstraint.bandwidth().bps(); 441 bwConstraintValue = bwConstraint.bandwidth().bps();
410 } else if (constraint instanceof CostConstraint) { 442 } else if (constraint instanceof CostConstraint) {
411 costConstraint = (CostConstraint) constraint; 443 costConstraint = (CostConstraint) constraint;
444 + costType = costConstraint.type().name();
412 } 445 }
413 } 446 }
414 447
...@@ -454,6 +487,9 @@ public class PceManager implements PceService { ...@@ -454,6 +487,9 @@ public class PceManager implements PceService {
454 487
455 Builder annotationBuilder = DefaultAnnotations.builder(); 488 Builder annotationBuilder = DefaultAnnotations.builder();
456 annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue)); 489 annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue));
490 + if (costType != null) {
491 + annotationBuilder.set(COST_TYPE, costType);
492 + }
457 annotationBuilder.set(LSP_SIG_TYPE, lspSigType); 493 annotationBuilder.set(LSP_SIG_TYPE, lspSigType);
458 annotationBuilder.set(PCE_INIT, TRUE); 494 annotationBuilder.set(PCE_INIT, TRUE);
459 annotationBuilder.set(DELEGATE, TRUE); 495 annotationBuilder.set(DELEGATE, TRUE);
...@@ -594,8 +630,66 @@ public class PceManager implements PceService { ...@@ -594,8 +630,66 @@ public class PceManager implements PceService {
594 } 630 }
595 } 631 }
596 632
633 + //TODO: annotations used for temporarily later projection/network config will be used
634 + private class InternalTopologyListener implements TopologyListener {
635 + @Override
636 + public void event(TopologyEvent event) {
637 + event.reasons().forEach(e -> {
638 + //If event type is link removed, get the impacted tunnel
639 + if (e instanceof LinkEvent) {
640 + LinkEvent linkEvent = (LinkEvent) e;
641 + if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
642 + tunnelService.queryTunnel(MPLS).forEach(t -> {
643 + if (t.path().links().contains((e.subject()))) {
644 + // Check whether this ONOS instance is master for ingress device if yes,
645 + // recompute and send update
646 + checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
647 + }
648 + });
649 + }
650 + }
651 + });
652 + }
653 + }
597 654
598 - // Allocates the bandwidth locally for PCECC tunnels. 655 + private boolean checkForMasterAndUpdateTunnel(DeviceId src, Tunnel tunnel) {
656 + /**
657 + * Master of ingress node will recompute and also delegation flag must be set.
658 + */
659 + if (mastershipService.isLocalMaster(src)
660 + && Boolean.valueOf(tunnel.annotations().value(DELEGATE)) != null) {
661 + LinkedList<Constraint> constraintList = new LinkedList<>();
662 +
663 + if (tunnel.annotations().value(BANDWIDTH) != null) {
664 + //Requested bandwidth will be same as previous allocated bandwidth for the tunnel
665 + BandwidthConstraint localConst = new BandwidthConstraint(Bandwidth.bps(Double.parseDouble(tunnel
666 + .annotations().value(BANDWIDTH))));
667 + constraintList.add(localConst);
668 + }
669 + if (tunnel.annotations().value(COST_TYPE) != null) {
670 + constraintList.add(CostConstraint.of(CostConstraint.Type.valueOf(tunnel.annotations().value(
671 + COST_TYPE))));
672 + }
673 +
674 + /*
675 + * If tunnel was UP after recomputation failed then store failed path in PCE store send PCIntiate(remove)
676 + * and If tunnel is failed and computation fails nothing to do because tunnel status will be same[Failed]
677 + */
678 + if (!updatePath(tunnel.tunnelId(), constraintList) && !tunnel.state().equals(Tunnel.State.FAILED)) {
679 + // If updation fails store in PCE store as failed path
680 + // then PCInitiate (Remove)
681 + pceStore.addFailedPathInfo(new PcePathInfo(tunnel.path().src().deviceId(), tunnel
682 + .path().dst().deviceId(), tunnel.tunnelName().value(), constraintList,
683 + LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))));
684 + //Release that tunnel calling PCInitiate
685 + releasePath(tunnel.tunnelId());
686 + }
687 + }
688 +
689 + return false;
690 + }
691 +
692 + // Allocates the bandwidth locally for PCECC tunnels.
599 private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint, 693 private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint,
600 SharedBandwidthConstraint shBwConstraint) { 694 SharedBandwidthConstraint shBwConstraint) {
601 checkNotNull(computedPath); 695 checkNotNull(computedPath);
...@@ -860,14 +954,72 @@ public class PceManager implements PceService { ...@@ -860,14 +954,72 @@ public class PceManager implements PceService {
860 public void process(PacketContext context) { 954 public void process(PacketContext context) {
861 // Stop processing if the packet has been handled, since we 955 // Stop processing if the packet has been handled, since we
862 // can't do any more to it. 956 // can't do any more to it.
863 -
864 if (context.isHandled()) { 957 if (context.isHandled()) {
865 return; 958 return;
866 } 959 }
867 960
868 InboundPacket pkt = context.inPacket(); 961 InboundPacket pkt = context.inPacket();
962 + if (pkt == null) {
963 + return;
964 + }
965 +
966 + Ethernet ethernet = pkt.parsed();
967 + if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) {
968 + return;
969 + }
970 +
971 + IPv4 ipPacket = (IPv4) ethernet.getPayload();
972 + if (ipPacket == null || ipPacket.getProtocol() != IPv4.PROTOCOL_TCP) {
973 + return;
974 + }
975 +
976 + TCP tcp = (TCP) ipPacket.getPayload();
977 + if (tcp == null || tcp.getDestinationPort() != PCEP_PORT) {
978 + return;
979 + }
980 +
869 syncLabelDb(pkt.receivedFrom().deviceId()); 981 syncLabelDb(pkt.receivedFrom().deviceId());
870 } 982 }
871 } 983 }
872 984
985 + //Computes path from tunnel store and also path failed to setup.
986 + private void callForOptimization() {
987 + //Recompute the LSPs which it was delegated [LSPs stored in PCE store (failed paths)]
988 + for (PcePathInfo failedPathInfo : pceStore.getFailedPathInfos()) {
989 + checkForMasterAndSetupPath(failedPathInfo);
990 + }
991 +
992 + //Recompute the LSPs for which it was delegated [LSPs stored in tunnel store]
993 + tunnelService.queryTunnel(MPLS).forEach(t -> {
994 + checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
995 + });
996 + }
997 +
998 + private boolean checkForMasterAndSetupPath(PcePathInfo failedPathInfo) {
999 + /**
1000 + * Master of ingress node will setup the path failed stored in PCE store.
1001 + */
1002 + if (mastershipService.isLocalMaster(failedPathInfo.src())) {
1003 + if (setupPath(failedPathInfo.src(), failedPathInfo.dst(), failedPathInfo.name(),
1004 + failedPathInfo.constraints(), failedPathInfo.lspType())) {
1005 + // If computation is success remove that path
1006 + pceStore.removeFailedPathInfo(failedPathInfo);
1007 + return true;
1008 + }
1009 + }
1010 +
1011 + return false;
1012 + }
1013 +
1014 + //Timer to call global optimization
1015 + private class GlobalOptimizationTimer implements Runnable {
1016 +
1017 + public GlobalOptimizationTimer() {
1018 + }
1019 +
1020 + @Override
1021 + public void run() {
1022 + callForOptimization();
1023 + }
1024 + }
873 } 1025 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,7 +19,6 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -19,7 +19,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is; 19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.notNullValue; 20 import static org.hamcrest.Matchers.notNullValue;
21 import static org.hamcrest.Matchers.nullValue; 21 import static org.hamcrest.Matchers.nullValue;
22 -
23 import static org.onosproject.net.Link.Type.DIRECT; 22 import static org.onosproject.net.Link.Type.DIRECT;
24 23
25 import java.util.Iterator; 24 import java.util.Iterator;
...@@ -29,7 +28,6 @@ import java.util.LinkedList; ...@@ -29,7 +28,6 @@ import java.util.LinkedList;
29 import org.junit.After; 28 import org.junit.After;
30 import org.junit.Before; 29 import org.junit.Before;
31 import org.junit.Test; 30 import org.junit.Test;
32 -
33 import org.onlab.packet.IpAddress; 31 import org.onlab.packet.IpAddress;
34 import org.onosproject.core.ApplicationId; 32 import org.onosproject.core.ApplicationId;
35 import org.onosproject.core.CoreService; 33 import org.onosproject.core.CoreService;
...@@ -165,6 +163,7 @@ public class BasicPceccHandlerTest { ...@@ -165,6 +163,7 @@ public class BasicPceccHandlerTest {
165 163
166 @After 164 @After
167 public void tearDown() throws Exception { 165 public void tearDown() throws Exception {
166 + PceManagerTest.flowsDownloaded = 0;
168 } 167 }
169 168
170 /** 169 /**
......
...@@ -15,13 +15,17 @@ import static org.onosproject.pce.pceservice.PathComputationTest.D1; ...@@ -15,13 +15,17 @@ import static org.onosproject.pce.pceservice.PathComputationTest.D1;
15 import static org.onosproject.pce.pceservice.PathComputationTest.D2; 15 import static org.onosproject.pce.pceservice.PathComputationTest.D2;
16 import static org.onosproject.pce.pceservice.PathComputationTest.D3; 16 import static org.onosproject.pce.pceservice.PathComputationTest.D3;
17 import static org.onosproject.pce.pceservice.PathComputationTest.D4; 17 import static org.onosproject.pce.pceservice.PathComputationTest.D4;
18 +import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
19 +import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
20 +import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
21 +import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
18 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; 22 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
19 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; 23 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
20 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; 24 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
21 import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; 25 import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
26 +import static org.onosproject.net.MastershipRole.MASTER;
22 27
23 import java.net.URISyntaxException; 28 import java.net.URISyntaxException;
24 -import java.nio.ByteBuffer;
25 import java.util.Collection; 29 import java.util.Collection;
26 import java.util.Collections; 30 import java.util.Collections;
27 import java.util.HashMap; 31 import java.util.HashMap;
...@@ -35,14 +39,18 @@ import org.junit.After; ...@@ -35,14 +39,18 @@ import org.junit.After;
35 import org.junit.Before; 39 import org.junit.Before;
36 import org.junit.Test; 40 import org.junit.Test;
37 import org.onlab.graph.GraphPathSearch; 41 import org.onlab.graph.GraphPathSearch;
42 +import org.onlab.junit.TestUtils;
43 +import org.onlab.junit.TestUtils.TestUtilsException;
38 import org.onlab.packet.Ethernet; 44 import org.onlab.packet.Ethernet;
39 import org.onlab.packet.IPv4; 45 import org.onlab.packet.IPv4;
46 +import org.onlab.packet.TCP;
40 import org.onlab.util.Bandwidth; 47 import org.onlab.util.Bandwidth;
41 import org.onosproject.common.DefaultTopologyGraph; 48 import org.onosproject.common.DefaultTopologyGraph;
42 import org.onosproject.core.ApplicationId; 49 import org.onosproject.core.ApplicationId;
43 import org.onosproject.core.CoreServiceAdapter; 50 import org.onosproject.core.CoreServiceAdapter;
44 import org.onosproject.core.DefaultApplicationId; 51 import org.onosproject.core.DefaultApplicationId;
45 import org.onosproject.core.IdGenerator; 52 import org.onosproject.core.IdGenerator;
53 +import org.onosproject.event.Event;
46 import org.onosproject.incubator.net.resource.label.LabelResourceId; 54 import org.onosproject.incubator.net.resource.label.LabelResourceId;
47 import org.onosproject.incubator.net.resource.label.LabelResourceService; 55 import org.onosproject.incubator.net.resource.label.LabelResourceService;
48 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 56 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
...@@ -52,6 +60,7 @@ import org.onosproject.incubator.net.tunnel.TunnelEndPoint; ...@@ -52,6 +60,7 @@ import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
52 import org.onosproject.incubator.net.tunnel.TunnelEvent; 60 import org.onosproject.incubator.net.tunnel.TunnelEvent;
53 import org.onosproject.incubator.net.tunnel.TunnelId; 61 import org.onosproject.incubator.net.tunnel.TunnelId;
54 import org.onosproject.incubator.net.tunnel.TunnelListener; 62 import org.onosproject.incubator.net.tunnel.TunnelListener;
63 +import org.onosproject.mastership.MastershipServiceAdapter;
55 import org.onosproject.net.AnnotationKeys; 64 import org.onosproject.net.AnnotationKeys;
56 import org.onosproject.net.Annotations; 65 import org.onosproject.net.Annotations;
57 import org.onosproject.net.ConnectPoint; 66 import org.onosproject.net.ConnectPoint;
...@@ -60,6 +69,7 @@ import org.onosproject.net.DefaultDevice; ...@@ -60,6 +69,7 @@ import org.onosproject.net.DefaultDevice;
60 import org.onosproject.net.DefaultLink; 69 import org.onosproject.net.DefaultLink;
61 import org.onosproject.net.Device; 70 import org.onosproject.net.Device;
62 import org.onosproject.net.DefaultAnnotations.Builder; 71 import org.onosproject.net.DefaultAnnotations.Builder;
72 +import org.onosproject.net.MastershipRole;
63 import org.onosproject.net.device.DeviceServiceAdapter; 73 import org.onosproject.net.device.DeviceServiceAdapter;
64 import org.onosproject.net.flowobjective.ForwardingObjective; 74 import org.onosproject.net.flowobjective.ForwardingObjective;
65 import org.onosproject.net.DeviceId; 75 import org.onosproject.net.DeviceId;
...@@ -71,6 +81,7 @@ import org.onosproject.net.SparseAnnotations; ...@@ -71,6 +81,7 @@ import org.onosproject.net.SparseAnnotations;
71 import org.onosproject.net.intent.Constraint; 81 import org.onosproject.net.intent.Constraint;
72 import org.onosproject.net.intent.IntentId; 82 import org.onosproject.net.intent.IntentId;
73 import org.onosproject.net.intent.constraint.BandwidthConstraint; 83 import org.onosproject.net.intent.constraint.BandwidthConstraint;
84 +import org.onosproject.net.link.LinkEvent;
74 import org.onosproject.net.packet.DefaultInboundPacket; 85 import org.onosproject.net.packet.DefaultInboundPacket;
75 import org.onosproject.net.packet.DefaultPacketContext; 86 import org.onosproject.net.packet.DefaultPacketContext;
76 import org.onosproject.net.packet.InboundPacket; 87 import org.onosproject.net.packet.InboundPacket;
...@@ -86,7 +97,9 @@ import org.onosproject.net.topology.LinkWeight; ...@@ -86,7 +97,9 @@ import org.onosproject.net.topology.LinkWeight;
86 import org.onosproject.net.topology.PathServiceAdapter; 97 import org.onosproject.net.topology.PathServiceAdapter;
87 import org.onosproject.net.topology.Topology; 98 import org.onosproject.net.topology.Topology;
88 import org.onosproject.net.topology.TopologyEdge; 99 import org.onosproject.net.topology.TopologyEdge;
100 +import org.onosproject.net.topology.TopologyEvent;
89 import org.onosproject.net.topology.TopologyGraph; 101 import org.onosproject.net.topology.TopologyGraph;
102 +import org.onosproject.net.topology.TopologyListener;
90 import org.onosproject.net.topology.TopologyServiceAdapter; 103 import org.onosproject.net.topology.TopologyServiceAdapter;
91 import org.onosproject.net.topology.TopologyVertex; 104 import org.onosproject.net.topology.TopologyVertex;
92 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; 105 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
...@@ -97,7 +110,9 @@ import org.onosproject.pce.util.PceStoreAdapter; ...@@ -97,7 +110,9 @@ import org.onosproject.pce.util.PceStoreAdapter;
97 import org.onosproject.pce.util.TunnelServiceAdapter; 110 import org.onosproject.pce.util.TunnelServiceAdapter;
98 import org.onosproject.pce.util.FlowObjServiceAdapter; 111 import org.onosproject.pce.util.FlowObjServiceAdapter;
99 import org.onosproject.store.service.TestStorageService; 112 import org.onosproject.store.service.TestStorageService;
113 +
100 import com.google.common.collect.ImmutableSet; 114 import com.google.common.collect.ImmutableSet;
115 +import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
101 116
102 /** 117 /**
103 * Tests the functions of PceManager. 118 * Tests the functions of PceManager.
...@@ -107,6 +122,7 @@ public class PceManagerTest { ...@@ -107,6 +122,7 @@ public class PceManagerTest {
107 private PathComputationTest pathCompTest = new PathComputationTest(); 122 private PathComputationTest pathCompTest = new PathComputationTest();
108 private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService(); 123 private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService();
109 private MockTopologyService topologyService = new MockTopologyService(); 124 private MockTopologyService topologyService = new MockTopologyService();
125 + private MockMastershipService mastershipService = new MockMastershipService();
110 private MockPathService pathService = new MockPathService(); 126 private MockPathService pathService = new MockPathService();
111 private PceManager pceManager = new PceManager(); 127 private PceManager pceManager = new PceManager();
112 private MockCoreService coreService = new MockCoreService(); 128 private MockCoreService coreService = new MockCoreService();
...@@ -129,13 +145,19 @@ public class PceManagerTest { ...@@ -129,13 +145,19 @@ public class PceManagerTest {
129 private Device deviceD1, deviceD2, deviceD3, deviceD4; 145 private Device deviceD1, deviceD2, deviceD3, deviceD4;
130 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4; 146 private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
131 private Link link1, link2, link3, link4; 147 private Link link1, link2, link3, link4;
132 - private static int flowsDownloaded; 148 + protected static int flowsDownloaded;
133 private TunnelListener tunnelListener; 149 private TunnelListener tunnelListener;
150 + private TopologyListener listener;
151 + private Topology topology;
152 + private Set<TopologyEdge> edges;
153 + private Set<TopologyVertex> vertexes;
134 154
135 @Before 155 @Before
136 - public void startUp() { 156 + public void startUp() throws TestUtilsException {
157 + listener = TestUtils.getField(pceManager, "topologyListener");
137 pceManager.pathService = pathService; 158 pceManager.pathService = pathService;
138 pceManager.resourceService = resourceService; 159 pceManager.resourceService = resourceService;
160 + pceManager.topologyService = topologyService;
139 pceManager.tunnelService = tunnelService; 161 pceManager.tunnelService = tunnelService;
140 pceManager.coreService = coreService; 162 pceManager.coreService = coreService;
141 pceManager.storageService = storageService; 163 pceManager.storageService = storageService;
...@@ -144,34 +166,52 @@ public class PceManagerTest { ...@@ -144,34 +166,52 @@ public class PceManagerTest {
144 pceManager.labelRsrcService = labelResourceService; 166 pceManager.labelRsrcService = labelResourceService;
145 pceManager.flowObjectiveService = flowObjectiveService; 167 pceManager.flowObjectiveService = flowObjectiveService;
146 pceManager.pceStore = pceStore; 168 pceManager.pceStore = pceStore;
169 + pceManager.mastershipService = mastershipService;
147 pceManager.activate(); 170 pceManager.activate();
148 } 171 }
149 172
173 + private class MockMastershipService extends MastershipServiceAdapter {
174 + @Override
175 + public MastershipRole getLocalRole(DeviceId deviceId) {
176 + return MASTER;
177 + }
178 +
179 + @Override
180 + public boolean isLocalMaster(DeviceId deviceId) {
181 + return getLocalRole(deviceId) == MASTER;
182 + }
183 + }
184 +
150 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap, 185 private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
151 boolean setLabelStackCap, int bandwidth) { 186 boolean setLabelStackCap, int bandwidth) {
187 + link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
188 + link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
189 + link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
190 + link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
191 +
152 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>(); 192 Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
153 vertexes.add(D1); 193 vertexes.add(D1);
154 vertexes.add(D2); 194 vertexes.add(D2);
155 vertexes.add(D3); 195 vertexes.add(D3);
156 vertexes.add(D4); 196 vertexes.add(D4);
157 197
198 + this.vertexes = vertexes;
199 +
158 Set<TopologyEdge> edges = new HashSet<TopologyEdge>(); 200 Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
159 - link1 = PathComputationTest.addLink(D1.deviceId().toString(), 10, D2.deviceId().toString(), 20, setCost, 50);
160 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1); 201 TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
161 edges.add(edge1); 202 edges.add(edge1);
162 203
163 - link2 = PathComputationTest.addLink(D2.deviceId().toString(), 30, D4.deviceId().toString(), 40, setCost, 20);
164 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2); 204 TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
165 edges.add(edge2); 205 edges.add(edge2);
166 206
167 - link3 = PathComputationTest.addLink(D1.deviceId().toString(), 80, D3.deviceId().toString(), 70, setCost, 100);
168 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3); 207 TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
169 edges.add(edge3); 208 edges.add(edge3);
170 209
171 - link4 = PathComputationTest.addLink(D3.deviceId().toString(), 60, D4.deviceId().toString(), 50, setCost, 80);
172 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4); 210 TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
173 edges.add(edge4); 211 edges.add(edge4);
174 212
213 + this.edges = edges;
214 +
175 graph = new DefaultTopologyGraph(vertexes, edges); 215 graph = new DefaultTopologyGraph(vertexes, edges);
176 216
177 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); 217 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
...@@ -636,21 +676,18 @@ public class PceManagerTest { ...@@ -636,21 +676,18 @@ public class PceManagerTest {
636 * Tests packet in to trigger label DB sync. 676 * Tests packet in to trigger label DB sync.
637 */ 677 */
638 @Test 678 @Test
639 - public void packetProcessingTest() throws URISyntaxException { 679 + public void packetProcessingTest1() throws URISyntaxException {
640 680
641 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc. 681 build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
642 682
643 - final int srcHost = 2;
644 - final int dstHost = 5;
645 -
646 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200); 683 LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
647 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201); 684 LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
648 685
649 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label); 686 pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
650 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label); 687 pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
651 688
652 - ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)); 689 + ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
653 - ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(dstHost)); 690 + ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
654 691
655 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT) 692 Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
656 .providerId(new ProviderId("eth", "1")).build(); 693 .providerId(new ProviderId("eth", "1")).build();
...@@ -658,24 +695,66 @@ public class PceManagerTest { ...@@ -658,24 +695,66 @@ public class PceManagerTest {
658 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204); 695 LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
659 pceManager.pceStore.addAdjLabel(link1, link1Label); 696 pceManager.pceStore.addAdjLabel(link1, link1Label);
660 697
661 - Ethernet eth; 698 + TCP tcp = new TCP();
662 - IPv4 ipv4; 699 + tcp.setDestinationPort(PCEP_PORT);
663 700
664 - ipv4 = new IPv4(); 701 + IPv4 ipv4 = new IPv4();
665 - eth = new Ethernet(); 702 + ipv4.setProtocol(IPv4.PROTOCOL_TCP);
703 + ipv4.setPayload(tcp);
704 +
705 + Ethernet eth = new Ethernet();
666 eth.setEtherType(Ethernet.TYPE_IPV4); 706 eth.setEtherType(Ethernet.TYPE_IPV4);
667 eth.setPayload(ipv4); 707 eth.setPayload(ipv4);
668 708
669 - eth.setSourceMACAddress("00:00:00:10:00:0" + srcHost).setDestinationMACAddress("00:00:00:10:00:0" + dstHost); 709 + InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
670 - 710 + PortNumber.portNumber(PCEP_PORT)),
671 - InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)), 711 + eth, null);
672 - eth, ByteBuffer.wrap(eth.serialize()));
673 712
674 pktProcessor.process(new MockPcepPacketContext(inPkt, null)); 713 pktProcessor.process(new MockPcepPacketContext(inPkt, null));
675 assertThat(flowsDownloaded, is(4)); 714 assertThat(flowsDownloaded, is(4));
676 } 715 }
677 716
678 /** 717 /**
718 + * Tests faulty packet in to trigger label DB sync.
719 + */
720 + @Test
721 + public void packetProcessingTest2() throws URISyntaxException {
722 +
723 + build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
724 +
725 + LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
726 + LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
727 +
728 + pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
729 + pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
730 +
731 + ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
732 + ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
733 +
734 + Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
735 + .providerId(new ProviderId("eth", "1")).build();
736 +
737 + LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
738 + pceManager.pceStore.addAdjLabel(link1, link1Label);
739 +
740 + TCP tcp = new TCP(); // Not set the pcep port.
741 + IPv4 ipv4 = new IPv4();
742 + ipv4.setProtocol(IPv4.PROTOCOL_TCP);
743 + ipv4.setPayload(tcp);
744 +
745 + Ethernet eth = new Ethernet();
746 + eth.setEtherType(Ethernet.TYPE_IPV4);
747 + eth.setPayload(ipv4);
748 +
749 + InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
750 + PortNumber.portNumber(PCEP_PORT)),
751 + eth, null);
752 +
753 + pktProcessor.process(new MockPcepPacketContext(inPkt, null));
754 + assertThat(flowsDownloaded, is(0));
755 + }
756 +
757 + /**
679 * Tests tunnel events added and removed. 758 * Tests tunnel events added and removed.
680 */ 759 */
681 @Test 760 @Test
...@@ -800,6 +879,390 @@ public class PceManagerTest { ...@@ -800,6 +879,390 @@ public class PceManagerTest {
800 assertThat(pceStore.getFailedPathInfoCount(), is(1)); 879 assertThat(pceStore.getFailedPathInfoCount(), is(1));
801 } 880 }
802 881
882 + /**
883 + * Tests resilency when L2 link is down.
884 + */
885 + @Test
886 + public void resilencyTest1() {
887 + build4RouterTopo(true, false, false, false, 10);
888 +
889 +
890 + List<Constraint> constraints = new LinkedList<Constraint>();
891 + CostConstraint costConstraint = new CostConstraint(COST);
892 + constraints.add(costConstraint);
893 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
894 + constraints.add(localBwConst);
895 +
896 + //Setup the path , tunnel created
897 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
898 + assertThat(result, is(true));
899 + assertThat(pceStore.getTunnelInfoCount(), is(1));
900 + assertThat(pceStore.getFailedPathInfoCount(), is(0));
901 +
902 + List<Event> reasons = new LinkedList<>();
903 + final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
904 + reasons.add(linkEvent);
905 + final TopologyEvent event = new TopologyEvent(
906 + TopologyEvent.Type.TOPOLOGY_CHANGED,
907 + topology,
908 + reasons);
909 +
910 + //Change Topology : remove link2
911 + Set<TopologyEdge> tempEdges = new HashSet<>();
912 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
913 + topologyService.changeInTopology(getGraph(null, tempEdges));
914 + listener.event(event);
915 +
916 + List<Link> links = new LinkedList<>();
917 + links.add(link3);
918 + links.add(link4);
919 +
920 + //Path is D1-D3-D4
921 + assertThat(pathService.paths().iterator().next().links(), is(links));
922 + assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
923 + }
924 +
925 + /**
926 + * Tests resilency when L2 and L4 link is down.
927 + */
928 + @Test
929 + public void resilencyTest2() {
930 + build4RouterTopo(true, false, false, false, 10);
931 +
932 + List<Constraint> constraints = new LinkedList<Constraint>();
933 + CostConstraint costConstraint = new CostConstraint(COST);
934 + constraints.add(costConstraint);
935 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
936 + constraints.add(localBwConst);
937 +
938 + //Setup the path , tunnel created
939 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
940 + assertThat(result, is(true));
941 +
942 + List<Event> reasons = new LinkedList<>();
943 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
944 + reasons.add(linkEvent);
945 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
946 + reasons.add(linkEvent);
947 + final TopologyEvent event = new TopologyEvent(
948 + TopologyEvent.Type.TOPOLOGY_CHANGED,
949 + topology,
950 + reasons);
951 +
952 + //Change Topology : remove link2 and link4
953 + Set<TopologyEdge> tempEdges = new HashSet<>();
954 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
955 + tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
956 + topologyService.changeInTopology(getGraph(null, tempEdges));
957 + listener.event(event);
958 +
959 + //No Path
960 + assertThat(pathService.paths().size(), is(0));
961 + }
962 +
963 + /**
964 + * Tests resilency when D2 device is down.
965 + */
966 + @Test
967 + public void resilencyTest3() {
968 + build4RouterTopo(true, false, false, false, 10);
969 +
970 + List<Constraint> constraints = new LinkedList<Constraint>();
971 + CostConstraint costConstraint = new CostConstraint(COST);
972 + constraints.add(costConstraint);
973 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
974 + constraints.add(localBwConst);
975 +
976 + //Setup the path , tunnel created
977 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
978 + assertThat(result, is(true));
979 +
980 + List<Event> reasons = new LinkedList<>();
981 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
982 + reasons.add(linkEvent);
983 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
984 + reasons.add(linkEvent);
985 + final TopologyEvent event = new TopologyEvent(
986 + TopologyEvent.Type.TOPOLOGY_CHANGED,
987 + topology,
988 + reasons);
989 +
990 + //Change Topology : remove link2 and link1
991 + Set<TopologyEdge> tempEdges = new HashSet<>();
992 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
993 + tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
994 + topologyService.changeInTopology(getGraph(null, tempEdges));
995 + listener.event(event);
996 +
997 + List<Link> links = new LinkedList<>();
998 + links.add(link3);
999 + links.add(link4);
1000 +
1001 + //Path is D1-D3-D4
1002 + assertThat(pathService.paths().iterator().next().links(), is(links));
1003 + assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1004 + }
1005 +
1006 + /**
1007 + * Tests resilency when ingress device is down.
1008 + */
1009 + @Test
1010 + public void resilencyTest4() {
1011 + build4RouterTopo(true, false, false, false, 10);
1012 +
1013 + List<Constraint> constraints = new LinkedList<Constraint>();
1014 + CostConstraint costConstraint = new CostConstraint(COST);
1015 + constraints.add(costConstraint);
1016 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1017 + constraints.add(localBwConst);
1018 +
1019 + //Setup the path , tunnel created
1020 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1021 + assertThat(result, is(true));
1022 +
1023 + List<Event> reasons = new LinkedList<>();
1024 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1025 + reasons.add(linkEvent);
1026 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1027 + reasons.add(linkEvent);
1028 + final TopologyEvent event = new TopologyEvent(
1029 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1030 + topology,
1031 + reasons);
1032 +
1033 + //Change Topology : remove link2 and link1
1034 + Set<TopologyEdge> tempEdges = new HashSet<>();
1035 + tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1036 + tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1037 + topologyService.changeInTopology(getGraph(null, tempEdges));
1038 + listener.event(event);
1039 +
1040 + //No path
1041 + assertThat(pathService.paths().size(), is(0));
1042 + }
1043 +
1044 + /**
1045 + * Tests resilency when D2 and D3 devices are down.
1046 + */
1047 + @Test
1048 + public void resilencyTest5() {
1049 + build4RouterTopo(true, false, false, false, 10);
1050 +
1051 + List<Constraint> constraints = new LinkedList<Constraint>();
1052 + CostConstraint costConstraint = new CostConstraint(COST);
1053 + constraints.add(costConstraint);
1054 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1055 + constraints.add(localBwConst);
1056 +
1057 + //Setup the path , tunnel created
1058 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1059 + assertThat(result, is(true));
1060 +
1061 + List<Event> reasons = new LinkedList<>();
1062 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1063 + reasons.add(linkEvent);
1064 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1065 + reasons.add(linkEvent);
1066 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1067 + reasons.add(linkEvent);
1068 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1069 + reasons.add(linkEvent);
1070 +
1071 + final TopologyEvent event = new TopologyEvent(
1072 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1073 + topology,
1074 + reasons);
1075 +
1076 + //Change Topology : remove device2, device3 and all links
1077 + Set<TopologyEdge> tempEdges = new HashSet<>();
1078 + tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1079 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1080 + tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
1081 + tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1082 + Set<TopologyVertex> tempVertexes = new HashSet<>();
1083 + tempVertexes.add(D2);
1084 + tempVertexes.add(D3);
1085 + topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1086 + listener.event(event);
1087 +
1088 + //No path
1089 + assertThat(pathService.paths().size(), is(0));
1090 + }
1091 +
1092 + /**
1093 + * Tests resilency when egress device is down.
1094 + */
1095 + @Test
1096 + public void resilencyTest6() {
1097 + build4RouterTopo(true, false, false, false, 10);
1098 +
1099 + List<Constraint> constraints = new LinkedList<Constraint>();
1100 + CostConstraint costConstraint = new CostConstraint(COST);
1101 + constraints.add(costConstraint);
1102 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1103 + constraints.add(localBwConst);
1104 +
1105 + //Setup the path , tunnel created
1106 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1107 + assertThat(result, is(true));
1108 +
1109 + List<Event> reasons = new LinkedList<>();
1110 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1111 + reasons.add(linkEvent);
1112 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1113 + reasons.add(linkEvent);
1114 +
1115 + final TopologyEvent event = new TopologyEvent(
1116 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1117 + topology,
1118 + reasons);
1119 +
1120 + //Change Topology : remove device4 , link2 and link4
1121 + Set<TopologyEdge> tempEdges = new HashSet<>();
1122 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1123 + tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1124 + Set<TopologyVertex> tempVertexes = new HashSet<>();
1125 + tempVertexes.add(D4);
1126 + topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1127 + listener.event(event);
1128 +
1129 + //No path
1130 + assertThat(pathService.paths().size(), is(0));
1131 + }
1132 +
1133 + /**
1134 + * Tests resilency when egress device is down.
1135 + */
1136 + @Test
1137 + public void resilencyTest7() {
1138 + build4RouterTopo(true, false, false, false, 10);
1139 +
1140 + List<Constraint> constraints = new LinkedList<Constraint>();
1141 + CostConstraint costConstraint = new CostConstraint(COST);
1142 + constraints.add(costConstraint);
1143 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1144 + constraints.add(localBwConst);
1145 +
1146 + //Setup the path , tunnel created
1147 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1148 + assertThat(result, is(true));
1149 +
1150 + List<Event> reasons = new LinkedList<>();
1151 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1152 + reasons.add(linkEvent);
1153 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1154 + reasons.add(linkEvent);
1155 +
1156 + final TopologyEvent event = new TopologyEvent(
1157 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1158 + topology,
1159 + reasons);
1160 +
1161 + //Change Topology : remove device4 , link2 and link4
1162 + Set<TopologyEdge> tempEdges = new HashSet<>();
1163 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1164 + tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
1165 + Set<TopologyVertex> tempVertexes = new HashSet<>();
1166 + tempVertexes.add(D4);
1167 + topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1168 + listener.event(event);
1169 +
1170 + //No path
1171 + assertThat(pathService.paths().size(), is(0));
1172 + }
1173 +
1174 + /**
1175 + * Tests resilency when D2 device is suspended.
1176 + */
1177 + @Test
1178 + public void resilencyTest8() {
1179 + build4RouterTopo(true, false, false, false, 10);
1180 +
1181 + List<Constraint> constraints = new LinkedList<Constraint>();
1182 + CostConstraint costConstraint = new CostConstraint(COST);
1183 + constraints.add(costConstraint);
1184 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1185 + constraints.add(localBwConst);
1186 +
1187 + //Setup the path , tunnel created
1188 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1189 + assertThat(result, is(true));
1190 +
1191 + List<Event> reasons = new LinkedList<>();
1192 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1193 + reasons.add(linkEvent);
1194 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1195 + reasons.add(linkEvent);
1196 +
1197 + final TopologyEvent event = new TopologyEvent(
1198 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1199 + topology,
1200 + reasons);
1201 +
1202 + //Change Topology : remove device2 , link1 and link2
1203 + Set<TopologyEdge> tempEdges = new HashSet<>();
1204 + tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1205 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1206 + Set<TopologyVertex> tempVertexes = new HashSet<>();
1207 + tempVertexes.add(D2);
1208 + topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1209 + listener.event(event);
1210 +
1211 + List<Link> links = new LinkedList<>();
1212 + links.add(link3);
1213 + links.add(link4);
1214 +
1215 + //Path is D1-D3-D4
1216 + assertThat(pathService.paths().iterator().next().links(), is(links));
1217 + assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1218 + }
1219 +
1220 + /**
1221 + * Tests resilency when D2 device availability is changed.
1222 + */
1223 + @Test
1224 + public void resilencyTest11() {
1225 + build4RouterTopo(true, false, false, false, 10);
1226 +
1227 + List<Constraint> constraints = new LinkedList<Constraint>();
1228 + CostConstraint costConstraint = new CostConstraint(COST);
1229 + constraints.add(costConstraint);
1230 + BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
1231 + constraints.add(localBwConst);
1232 +
1233 + //Setup the path , tunnel created
1234 + boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
1235 + assertThat(result, is(true));
1236 +
1237 + List<Event> reasons = new LinkedList<>();
1238 + LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
1239 + reasons.add(linkEvent);
1240 + linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
1241 + reasons.add(linkEvent);
1242 +
1243 + final TopologyEvent event = new TopologyEvent(
1244 + TopologyEvent.Type.TOPOLOGY_CHANGED,
1245 + topology,
1246 + reasons);
1247 +
1248 + //Change Topology : remove device2 , link1 and link2
1249 + Set<TopologyEdge> tempEdges = new HashSet<>();
1250 + tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
1251 + tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
1252 + Set<TopologyVertex> tempVertexes = new HashSet<>();
1253 + tempVertexes.add(D2);
1254 + topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
1255 + listener.event(event);
1256 +
1257 + List<Link> links = new LinkedList<>();
1258 + links.add(link3);
1259 + links.add(link4);
1260 +
1261 + //Path is D1-D3-D4
1262 + assertThat(pathService.paths().iterator().next().links(), is(links));
1263 + assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1264 + }
1265 +
803 @After 1266 @After
804 public void tearDown() { 1267 public void tearDown() {
805 pceManager.deactivate(); 1268 pceManager.deactivate();
...@@ -813,10 +1276,16 @@ public class PceManagerTest { ...@@ -813,10 +1276,16 @@ public class PceManagerTest {
813 pceManager.labelRsrcService = null; 1276 pceManager.labelRsrcService = null;
814 pceManager.flowObjectiveService = null; 1277 pceManager.flowObjectiveService = null;
815 pceManager.pceStore = null; 1278 pceManager.pceStore = null;
1279 + pceManager.topologyService = null;
1280 + pceManager.mastershipService = null;
816 flowsDownloaded = 0; 1281 flowsDownloaded = 0;
817 } 1282 }
818 1283
819 private class MockTopologyService extends TopologyServiceAdapter { 1284 private class MockTopologyService extends TopologyServiceAdapter {
1285 + private void changeInTopology(TopologyGraph graphModified) {
1286 + graph = graphModified;
1287 + }
1288 +
820 @Override 1289 @Override
821 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) { 1290 public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
822 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src); 1291 DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
...@@ -837,8 +1306,27 @@ public class PceManagerTest { ...@@ -837,8 +1306,27 @@ public class PceManagerTest {
837 } 1306 }
838 } 1307 }
839 1308
840 - private class MockPathService extends PathServiceAdapter { 1309 + private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
1310 + if (removedVertex != null) {
1311 + vertexes.remove(removedVertex);
1312 + removedVertex.forEach(v ->
1313 + {
1314 + vertexes.remove(v);
1315 + });
1316 + }
1317 +
1318 + if (removedEdges != null) {
1319 + removedEdges.forEach(e ->
1320 + {
1321 + edges.remove(e);
1322 + });
1323 + }
1324 +
1325 + return new DefaultTopologyGraph(vertexes, edges);
1326 + }
841 1327
1328 + private class MockPathService extends PathServiceAdapter {
1329 + Set<Path> computedPaths;
842 @Override 1330 @Override
843 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { 1331 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
844 // If either edge is null, bail with no paths. 1332 // If either edge is null, bail with no paths.
...@@ -848,7 +1336,12 @@ public class PceManagerTest { ...@@ -848,7 +1336,12 @@ public class PceManagerTest {
848 1336
849 // Otherwise get all paths between the source and destination edge 1337 // Otherwise get all paths between the source and destination edge
850 // devices. 1338 // devices.
851 - return topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight); 1339 + computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
1340 + return computedPaths;
1341 + }
1342 +
1343 + private Set<Path> paths() {
1344 + return computedPaths;
852 } 1345 }
853 } 1346 }
854 1347
...@@ -946,6 +1439,31 @@ public class PceManagerTest { ...@@ -946,6 +1439,31 @@ public class PceManagerTest {
946 1439
947 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); 1440 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
948 } 1441 }
1442 +
1443 + @Override
1444 + public Collection<Tunnel> queryAllTunnels() {
1445 + Collection<Tunnel> result = new HashSet<Tunnel>();
1446 +
1447 + for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
1448 + result.add(tunnelIdAsKeyStore.get(tunnelId));
1449 + }
1450 +
1451 + return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1452 + }
1453 + @Override
1454 + public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1455 + List<Tunnel> tunnelList = new LinkedList<>();
1456 +
1457 + for (Tunnel t : tunnelIdAsKeyStore.values()) {
1458 + for (Link l : t.path().links()) {
1459 + if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
1460 + tunnelList.add(t);
1461 + break;
1462 + }
1463 + }
1464 + }
1465 + return tunnelList;
1466 + }
949 } 1467 }
950 1468
951 public static class MockCoreService extends CoreServiceAdapter { 1469 public static class MockCoreService extends CoreServiceAdapter {
......
...@@ -158,6 +158,7 @@ public class PceccSrTeBeHandlerTest { ...@@ -158,6 +158,7 @@ public class PceccSrTeBeHandlerTest {
158 158
159 @After 159 @After
160 public void tearDown() throws Exception { 160 public void tearDown() throws Exception {
161 + PceManagerTest.flowsDownloaded = 0;
161 } 162 }
162 163
163 /** 164 /**
......

7.44 KB | W: | H:

23.3 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
23 <groupId>org.onosproject</groupId> 23 <groupId>org.onosproject</groupId>
24 <artifactId>onos-pce</artifactId> 24 <artifactId>onos-pce</artifactId>
25 <version>1.6.0-SNAPSHOT</version> 25 <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
26 </parent> 27 </parent>
27 28
28 <artifactId>onos-app-pceweb</artifactId> 29 <artifactId>onos-app-pceweb</artifactId>
...@@ -42,6 +43,11 @@ ...@@ -42,6 +43,11 @@
42 <artifactId>onos-cli</artifactId> 43 <artifactId>onos-cli</artifactId>
43 <version>${project.version}</version> 44 <version>${project.version}</version>
44 </dependency> 45 </dependency>
46 + <dependency>
47 + <groupId>org.onosproject</groupId>
48 + <artifactId>onos-app-pce</artifactId>
49 + <version>${project.version}</version>
50 + </dependency>
45 </dependencies> 51 </dependencies>
46 52
47 <properties> 53 <properties>
......
...@@ -17,33 +17,48 @@ ...@@ -17,33 +17,48 @@
17 package org.onosproject.pceweb; 17 package org.onosproject.pceweb;
18 18
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 -
21 -
22 import com.google.common.collect.ImmutableSet; 20 import com.google.common.collect.ImmutableSet;
21 +
23 import org.onlab.osgi.ServiceDirectory; 22 import org.onlab.osgi.ServiceDirectory;
23 +import org.onlab.packet.IpAddress;
24 +import org.onlab.util.DataRateUnit;
25 +import org.onosproject.net.Device;
24 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
25 -import org.onosproject.net.DisjointPath;
26 import org.onosproject.net.ElementId; 27 import org.onosproject.net.ElementId;
27 import org.onosproject.net.HostId; 28 import org.onosproject.net.HostId;
28 import org.onosproject.net.Link; 29 import org.onosproject.net.Link;
29 import org.onosproject.net.Path; 30 import org.onosproject.net.Path;
30 -import org.onosproject.net.device.DeviceService; 31 +import org.onosproject.net.topology.TopologyEvent;
31 -import org.onosproject.net.topology.LinkWeight; 32 +import org.onosproject.net.topology.TopologyListener;
32 -import org.onosproject.net.topology.PathService;
33 import org.onosproject.net.topology.TopologyService; 33 import org.onosproject.net.topology.TopologyService;
34 import org.onosproject.ui.RequestHandler; 34 import org.onosproject.ui.RequestHandler;
35 import org.onosproject.ui.UiConnection; 35 import org.onosproject.ui.UiConnection;
36 import org.onosproject.ui.UiMessageHandler; 36 import org.onosproject.ui.UiMessageHandler;
37 import org.onosproject.ui.topo.DeviceHighlight; 37 import org.onosproject.ui.topo.DeviceHighlight;
38 import org.onosproject.ui.topo.Highlights; 38 import org.onosproject.ui.topo.Highlights;
39 -import org.onosproject.ui.topo.HostHighlight;
40 import org.onosproject.ui.topo.NodeBadge; 39 import org.onosproject.ui.topo.NodeBadge;
41 import org.onosproject.ui.topo.TopoJson; 40 import org.onosproject.ui.topo.TopoJson;
42 - 41 +import org.onosproject.net.device.DeviceService;
42 +import org.onosproject.net.intent.Constraint;
43 +import org.onosproject.pce.pceservice.LspType;
44 +import org.onosproject.pce.pceservice.api.PceService;
45 +import org.onosproject.pce.pceservice.constraint.CostConstraint;
46 +import org.onosproject.net.intent.constraint.BandwidthConstraint;
43 import org.slf4j.Logger; 47 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory; 48 import org.slf4j.LoggerFactory;
49 +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
50 +import org.onosproject.incubator.net.tunnel.Tunnel;
51 +import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
52 +import org.onosproject.incubator.net.tunnel.TunnelEvent;
53 +import org.onosproject.incubator.net.tunnel.TunnelId;
54 +import org.onosproject.incubator.net.tunnel.TunnelListener;
55 +import org.onosproject.incubator.net.tunnel.TunnelService;
56 +import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
57 +
58 +import com.fasterxml.jackson.databind.node.ArrayNode;
45 59
46 import java.util.Collection; 60 import java.util.Collection;
61 +import java.util.LinkedList;
47 import java.util.List; 62 import java.util.List;
48 import java.util.Set; 63 import java.util.Set;
49 64
...@@ -56,47 +71,66 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -56,47 +71,66 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
56 private static final String PCEWEB_SET_SRC = "pceTopovSetSrc"; 71 private static final String PCEWEB_SET_SRC = "pceTopovSetSrc";
57 private static final String PCEWEB_SET_DST = "pceTopovSetDst"; 72 private static final String PCEWEB_SET_DST = "pceTopovSetDst";
58 private static final String PCEWEB_SET_PATH = "pceTopovSetMode"; 73 private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
59 - 74 + private static final String PCEWEB_UPDATE_PATH_QUERY = "pceTopovUpdateQuery";
75 + private static final String PCEWEB_UPDATE_PATH = "pceTopovUpdate";
76 + private static final String PCEWEB_REMOVE_PATH_QUERY = "pceTopovRemQuery";
77 + private static final String PCEWEB_REMOVE_PATH = "pceTopovRem";
78 + private static final String PCEWEB_QUERY_TUNNELS = "pceTopovTunnelDisplay";
79 + private static final String PCEWEB_SHOW_TUNNEL = "pceTopovShowTunnels";
80 + private static final String PCEWEB_SHOW_TUNNEL_REMOVE = "pceTopovShowTunnelsRem";
60 private static final String ID = "id"; 81 private static final String ID = "id";
61 - private static final String MODE = "mode";
62 private static final String TYPE = "type"; 82 private static final String TYPE = "type";
63 - private static final String SWITCH = "switch"; 83 + private static final String ROUTER = "router";
64 - private static final String ENDSTATION = "endstation"; 84 + private static final String DST = "Egress";
65 - public static final String DST = "Dst"; 85 + private static final String SRC = "Ingress";
66 - public static final String SRC = "Src"; 86 + private static final String BANDWIDTH = "bw";
87 + private static final String BANDWIDTHTYPE = "bwtype";
88 + private static final String COSTTYPE = "ctype";
89 + private static final String LSPTYPE = "lsptype";
90 + private static final String SRCID = "srid";
91 + private static final String DSTID = "dsid";
92 + private static final String TUNNEL_ID = "tunnelid";
93 + private static final String TUNNEL_NAME = "tunnelname";
94 + private static final String COST_TYPE_IGP = "igp";
95 + private static final String COST_TYPE_TE = "te";
96 + private static final String BANDWIDTH_TYPE_KBPS = "kbps";
97 + private static final String BUFFER_ARRAY = "a";
98 + private static final String BANDWIDTH_BPS = "BPS";
99 + private static final String LSP_TYPE_CR = "cr";
100 + private static final String LSP_TYPE_SRBE = "srbe";
101 + private static final String LSP_TYPE_SRTE = "srte";
102 + private static final String STRING_NULL = "null";
67 // Delay for showHighlights event processing on GUI client side to 103 // Delay for showHighlights event processing on GUI client side to
68 // account for addLink animation. 104 // account for addLink animation.
69 - public static final int DELAY_MS = 1100; 105 + private static final int DELAY_MS = 1100;
70 - 106 + private static final double BANDWIDTH_KBPS = 1_000;
71 - private static final String CLASS = "class"; 107 + private static final double BANDWIDTH_MBPS = 1_000_000;
72 - private static final String UNKNOWN = "unknown";
73 - private static final String DEVICE = "device";
74 108
75 private Set<Link> allPathLinks; 109 private Set<Link> allPathLinks;
76 - private boolean listenersRemoved;
77 - private LinkWeight linkData;
78 private int highlightDelay; 110 private int highlightDelay;
79 -
80 - private final Logger log = LoggerFactory.getLogger(getClass());
81 -
82 - private PathService pathService;
83 -
84 private ElementId src, dst; 111 private ElementId src, dst;
85 private String srcType, dstType; 112 private String srcType, dstType;
86 private List<Path> paths; 113 private List<Path> paths;
87 private int pathIndex; 114 private int pathIndex;
88 115
116 + private final Logger log = LoggerFactory.getLogger(getClass());
117 + private final TopologyListener topologyListener = new InternalTopologyListener();
118 + private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
119 +
89 protected TopologyService topologyService; 120 protected TopologyService topologyService;
121 + protected TunnelService tunnelService;
122 + protected PceService pceService;
90 protected DeviceService deviceService; 123 protected DeviceService deviceService;
91 -
92 -
93 @Override 124 @Override
94 public void init(UiConnection connection, ServiceDirectory directory) { 125 public void init(UiConnection connection, ServiceDirectory directory) {
95 126
96 super.init(connection, directory); 127 super.init(connection, directory);
97 - //TODO: Need add listeners. 128 + topologyService = directory.get(TopologyService.class);
98 - //topologyService = directory.get(TopologyService.class); 129 + tunnelService = directory.get(TunnelService.class);
99 - //addListeners(); 130 + pceService = directory.get(PceService.class);
131 + deviceService = directory.get(DeviceService.class);
132 + topologyService.addListener(topologyListener);
133 + tunnelService.addListener(tunnelListener);
100 } 134 }
101 135
102 @Override 136 @Override
...@@ -105,7 +139,19 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -105,7 +139,19 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
105 new ClearHandler(), 139 new ClearHandler(),
106 new SetSrcHandler(), 140 new SetSrcHandler(),
107 new SetDstHandler(), 141 new SetDstHandler(),
108 - new SetPathHandler()); 142 + new SetPathHandler(),
143 + new UpdatePathQueryHandler(),
144 + new UpdatePathHandler(),
145 + new RemovePathQueryHandler(),
146 + new RemovePathHandler(),
147 + new ShowTunnelHandler());
148 + }
149 +
150 + @Override
151 + public void destroy() {
152 + topologyService.removeListener(topologyListener);
153 + tunnelService.removeListener(tunnelListener);
154 + super.destroy();
109 } 155 }
110 156
111 // Handler classes 157 // Handler classes
...@@ -137,7 +183,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -137,7 +183,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
137 183
138 @Override 184 @Override
139 public void process(long sid, ObjectNode payload) { 185 public void process(long sid, ObjectNode payload) {
140 - log.info("PCE WEB Set source process method invoked");
141 String id = string(payload, ID); 186 String id = string(payload, ID);
142 src = elementId(id); 187 src = elementId(id);
143 srcType = string(payload, TYPE); 188 srcType = string(payload, TYPE);
...@@ -146,7 +191,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -146,7 +191,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
146 } 191 }
147 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(), 192 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
148 srcType, src.toString(), SRC))); 193 srcType, src.toString(), SRC)));
149 -
150 } 194 }
151 } 195 }
152 196
...@@ -167,7 +211,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -167,7 +211,6 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
167 if (src.equals(dst)) { 211 if (src.equals(dst)) {
168 src = null; 212 src = null;
169 } 213 }
170 -
171 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(), 214 sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
172 dstType, dst.toString(), DST))); 215 dstType, dst.toString(), DST)));
173 216
...@@ -175,7 +218,7 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -175,7 +218,7 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
175 } 218 }
176 219
177 /** 220 /**
178 - * Handles the 'patchcalculation' event received from the client. 221 + * Handles the 'path calculation' event received from the client.
179 */ 222 */
180 private final class SetPathHandler extends RequestHandler { 223 private final class SetPathHandler extends RequestHandler {
181 224
...@@ -185,15 +228,168 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -185,15 +228,168 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
185 228
186 @Override 229 @Override
187 public void process(long sid, ObjectNode payload) { 230 public void process(long sid, ObjectNode payload) {
188 - String mode = string(payload, MODE); 231 + String bandWidth = string(payload, BANDWIDTH);
232 + String bandWidthType = string(payload, BANDWIDTHTYPE);
233 + String costType = string(payload, COSTTYPE);
234 + String lspType = string(payload, LSPTYPE);
235 + String tunnelName = string(payload, TUNNEL_NAME);
236 +
237 + if (tunnelName.equals(STRING_NULL)) {
238 + log.error("tunnel name should not be empty");
239 + return;
240 + }
241 +
242 + if (pceService == null) {
243 + log.error("PCE service is not active");
244 + return;
245 + }
189 246
190 - // TODO: Read user input[constraints] and call the path calculation based on 247 + if (lspType == null) {
191 - //given constrainsts. 248 + log.error("PCE setup path is failed.");
192 - findAndSendPaths(); 249 + }
250 +
251 + if ((src != null) && (dst != null)) {
252 + findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName);
253 + }
254 + }
255 + }
256 +
257 + /**
258 + * Handles the 'update path query' event received from the client.
259 + */
260 + private final class UpdatePathQueryHandler extends RequestHandler {
261 +
262 + public UpdatePathQueryHandler() {
263 + super(PCEWEB_UPDATE_PATH_QUERY);
264 + }
265 +
266 + @Override
267 + public void process(long sid, ObjectNode payload) {
268 + String srcId = string(payload, SRCID);
269 + ElementId src = elementId(srcId);
270 + String dstId = string(payload, DSTID);
271 + ElementId dst = elementId(dstId);
272 + Device srcDevice = deviceService.getDevice((DeviceId) src);
273 + Device dstDevice = deviceService.getDevice((DeviceId) dst);
274 +
275 + TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
276 + .valueOf(srcDevice.annotations().value("lsrId")));
277 + TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
278 + .valueOf(dstDevice.annotations().value("lsrId")));
279 +
280 + Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
281 + ObjectNode result = objectNode();
282 + ArrayNode arrayNode = arrayNode();
283 + for (Tunnel tunnel : tunnelSet) {
284 + if (tunnel.type() == MPLS) {
285 + arrayNode.add(tunnel.tunnelId().toString());
286 + }
287 + }
288 +
289 + result.putArray(BUFFER_ARRAY).addAll(arrayNode);
290 + sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
291 + }
292 + }
293 +
294 + /**
295 + * Handles the 'update path' event received from the client.
296 + */
297 + private final class UpdatePathHandler extends RequestHandler {
298 +
299 + public UpdatePathHandler() {
300 + super(PCEWEB_UPDATE_PATH);
301 + }
302 +
303 + @Override
304 + public void process(long sid, ObjectNode payload) {
305 + String bandWidth = string(payload, BANDWIDTH);
306 + String bandWidthType = string(payload, BANDWIDTHTYPE);
307 + String costType = string(payload, COSTTYPE);
308 + String tunnelId = string(payload, TUNNEL_ID);
309 +
310 + if (tunnelId == null) {
311 + log.error("PCE update path is failed.");
312 + }
313 +
314 + findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
315 + }
316 + }
317 +
318 + /**
319 + * Handles the 'remove path query' event received from the client.
320 + */
321 + private final class RemovePathQueryHandler extends RequestHandler {
322 +
323 + public RemovePathQueryHandler() {
324 + super(PCEWEB_REMOVE_PATH_QUERY);
325 + }
326 +
327 + @Override
328 + public void process(long sid, ObjectNode payload) {
329 + String srcId = string(payload, SRCID);
330 + ElementId src = elementId(srcId);
331 + String dstId = string(payload, DSTID);
332 + ElementId dst = elementId(dstId);
333 +
334 + Device srcDevice = deviceService.getDevice((DeviceId) src);
335 + Device dstDevice = deviceService.getDevice((DeviceId) dst);
336 +
337 + TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
338 + .valueOf(srcDevice.annotations().value("lsrId")));
339 + TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
340 + .valueOf(dstDevice.annotations().value("lsrId")));
341 +
342 + Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
343 + ObjectNode result = objectNode();
344 + ArrayNode arrayNode = arrayNode();
345 +
346 + for (Tunnel tunnel : tunnelSet) {
347 + if (tunnel.type() == MPLS) {
348 + arrayNode.add(tunnel.tunnelId().toString());
349 + }
350 + }
351 +
352 + result.putArray(BUFFER_ARRAY).addAll(arrayNode);
353 + sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result);
354 + }
355 + }
356 +
357 + /**
358 + * Handles the 'remove path' event received from the client.
359 + */
360 + private final class RemovePathHandler extends RequestHandler {
361 +
362 + public RemovePathHandler() {
363 + super(PCEWEB_REMOVE_PATH);
364 + }
365 +
366 + @Override
367 + public void process(long sid, ObjectNode payload) {
368 + String tunnelId = string(payload, TUNNEL_ID);
369 +
370 + if (tunnelId == null) {
371 + log.error("PCE update path is failed.");
372 + }
373 +
374 + findAndSendPathsRemove(tunnelId);
375 + }
376 + }
377 +
378 + /**
379 + * Handles the 'show the existed tunnels' event received from the client.
380 + */
381 + private final class ShowTunnelHandler extends RequestHandler {
382 +
383 + public ShowTunnelHandler() {
384 + super(PCEWEB_QUERY_TUNNELS);
385 + }
386 +
387 + @Override
388 + public void process(long sid, ObjectNode payload) {
389 + findTunnelAndHighlights();
193 } 390 }
194 } 391 }
195 392
196 - // === ------------
197 /** 393 /**
198 * provides the element id. 394 * provides the element id.
199 */ 395 */
...@@ -204,45 +400,170 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -204,45 +400,170 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
204 return HostId.hostId(id); 400 return HostId.hostId(id);
205 } 401 }
206 } 402 }
207 - //TODO: Need to pass constraints to this method
208 - private void findAndSendPaths() {
209 - log.info("src={}; dst={};", src, dst);
210 - if (src != null && dst != null) {
211 - //TBD: Need to call pathcalulation API here
212 - hilightAndSendPaths();
213 403
404 + /**
405 + * Handles the setup path and highlights the path.
406 + *
407 + * @param bandWidth
408 + * @param bandWidthType is the kbps or mbps
409 + * @param costType is igp or te
410 + * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING
411 + * @param tunnelName tunnel id
412 + */
413 + private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType,
414 + String costType, String lspType, String tunnelName) {
415 + log.debug("src={}; dst={};", src, dst);
416 + boolean path;
417 + List<Constraint> listConstrnt;
418 +
419 + listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
420 +
421 + //LSP type
422 + LspType lspTypeVal = null;
423 + switch (lspType) {
424 + case LSP_TYPE_CR:
425 + lspTypeVal = LspType.WITH_SIGNALLING;
426 + break;
427 + case LSP_TYPE_SRBE:
428 + lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
429 + break;
430 + case LSP_TYPE_SRTE:
431 + lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
432 + break;
433 + default:
434 + log.error("Invalid LSP type");
435 + break;
436 + }
437 +
438 + path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal);
439 + if (!path) {
440 + log.error("setup path is failed");
441 + return;
442 + }
443 +
444 + return;
445 + }
446 +
447 + /**
448 + * Handles the update path and highlights the path.
449 + *
450 + * @param bandWidth bandWidth
451 + * @param bandWidthType is the kbps or mbps
452 + * @param costType is igp or te
453 + * @param tunnelName tunnel id
454 + */
455 + private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) {
456 + if (tunnelIdStr != null) {
457 + List<Constraint> listConstrnt;
458 +
459 + if (tunnelIdStr.equals(STRING_NULL)) {
460 + log.error("update path is failed");
461 + return;
462 + }
463 +
464 + if (pceService == null) {
465 + log.error("PCE service is not active");
466 + return;
467 + }
468 +
469 + listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
470 + TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
471 + boolean path = pceService.updatePath(tunnelId, listConstrnt);
472 +
473 + if (!path) {
474 + log.error("update path is failed");
475 + return;
476 + }
214 } 477 }
478 + return;
479 + }
215 480
481 + /**
482 + * Handles the remove path and highlights the paths if existed.
483 + *
484 + * @param tunnelIdName tunnelId
485 + */
486 + private void findAndSendPathsRemove(String tunnelIdStr) {
487 + if (tunnelIdStr != null) {
488 + if (pceService == null) {
489 + log.error("PCE service is not active");
490 + return;
491 + }
492 +
493 + TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
494 + boolean path = pceService.releasePath(tunnelId);
495 + if (!path) {
496 + log.error("remove path is failed");
497 + return;
498 + }
499 + }
500 + return;
216 } 501 }
217 502
218 - //TODO: The below code is not used. Once get path from PCE app then below code will be use. 503 + private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
219 - // the below code will get path and it will highlight the selected path.
220 - //Currently primary path in use, there is no use of secondary path.
221 - //secondary path need to remove based on path received by PCE app.
222 - private ImmutableSet.Builder<Link> buildPaths(
223 - ImmutableSet.Builder<Link> pathBuilder) {
224 paths.forEach(path -> path.links().forEach(pathBuilder::add)); 504 paths.forEach(path -> path.links().forEach(pathBuilder::add));
225 return pathBuilder; 505 return pathBuilder;
226 } 506 }
227 507
228 - private ImmutableSet.Builder<Link> buildDisjointPaths( 508 + /**
229 - ImmutableSet.Builder<Link> pathBuilder) { 509 + * Handles the preparation of constraints list with given bandwidth and cost-type.
230 - paths.forEach(path -> { 510 + *
231 - DisjointPath dp = (DisjointPath) path; 511 + * @param bandWidth bandWidth
232 - pathBuilder.addAll(dp.primary().links()); 512 + * @param bandWidthType is the kbps or mbps
233 - pathBuilder.addAll(dp.backup().links()); 513 + * @param costType is igp or te
234 - }); 514 + * @param listConstrnt list of constraints
235 - return pathBuilder; 515 + * @return
516 + */
517 + private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
518 + String bandWidthType,
519 + String costType) {
520 + List<Constraint> listConstrnt = new LinkedList<>();
521 + //bandwidth
522 + double bwValue = 0.0;
523 + if (!bandWidth.equals(STRING_NULL)) {
524 + bwValue = Double.parseDouble(bandWidth);
525 + }
526 + if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
527 + bwValue = bwValue * BANDWIDTH_KBPS;
528 + } else {
529 + bwValue = bwValue * BANDWIDTH_MBPS;
530 + }
531 +
532 + //Cost type
533 + CostConstraint.Type costTypeVal = null;
534 + switch (costType) {
535 + case COST_TYPE_IGP:
536 + costTypeVal = CostConstraint.Type.COST;
537 + break;
538 + case COST_TYPE_TE:
539 + costTypeVal = CostConstraint.Type.TE_COST;
540 + break;
541 + default:
542 + log.error("Invalid cost type");
543 + break;
544 + }
545 +
546 + if (bwValue != 0.0) {
547 + listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
548 + }
549 +
550 + if (costTypeVal != null) {
551 + listConstrnt.add(CostConstraint.of(costTypeVal));
552 + }
553 +
554 + return listConstrnt;
236 } 555 }
237 556
557 + /**
558 + * Handles the highlights of selected path.
559 + */
238 private void hilightAndSendPaths() { 560 private void hilightAndSendPaths() {
239 PceWebLinkMap linkMap = new PceWebLinkMap(); 561 PceWebLinkMap linkMap = new PceWebLinkMap();
240 allPathLinks.forEach(linkMap::add); 562 allPathLinks.forEach(linkMap::add);
241 -
242 Set<Link> selectedPathLinks; 563 Set<Link> selectedPathLinks;
243 564
244 - selectedPathLinks = paths.isEmpty() ? ImmutableSet.of() 565 + selectedPathLinks = paths.isEmpty() ?
245 - : ImmutableSet.copyOf(paths.get(pathIndex).links()); 566 + ImmutableSet.of() : ImmutableSet.copyOf(paths.get(pathIndex).links());
246 567
247 Highlights highlights = new Highlights(); 568 Highlights highlights = new Highlights();
248 if (highlightDelay > 0) { 569 if (highlightDelay > 0) {
...@@ -261,16 +582,32 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -261,16 +582,32 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
261 sendMessage(TopoJson.highlightsMessage(highlights)); 582 sendMessage(TopoJson.highlightsMessage(highlights));
262 } 583 }
263 584
585 + /**
586 + * Handles the addition of badge and highlights.
587 + *
588 + * @param highlights highlights
589 + * @param type device type
590 + * @param elemId device to be add badge
591 + * @param src device to be add badge
592 + * @return
593 + */
264 private Highlights addBadge(Highlights highlights, String type, 594 private Highlights addBadge(Highlights highlights, String type,
265 String elemId, String src) { 595 String elemId, String src) {
266 - if (SWITCH.equals(type)) { 596 + if (ROUTER.equals(type)) {
267 highlights = addDeviceBadge(highlights, elemId, src); 597 highlights = addDeviceBadge(highlights, elemId, src);
268 - } else if (ENDSTATION.equals(type)) {
269 - highlights = addHostBadge(highlights, elemId, src);
270 } 598 }
599 +
271 return highlights; 600 return highlights;
272 } 601 }
273 602
603 + /**
604 + * Handles the badge add and highlights.
605 + *
606 + * @param h highlights
607 + * @param elemId device to be add badge
608 + * @param type device type
609 + * @return highlights
610 + */
274 private Highlights addDeviceBadge(Highlights h, String elemId, String type) { 611 private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
275 DeviceHighlight dh = new DeviceHighlight(elemId); 612 DeviceHighlight dh = new DeviceHighlight(elemId);
276 dh.setBadge(createBadge(type)); 613 dh.setBadge(createBadge(type));
...@@ -278,18 +615,59 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -278,18 +615,59 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
278 return h; 615 return h;
279 } 616 }
280 617
281 - private Highlights addHostBadge(Highlights h, String elemId, String type) { 618 + /**
282 - HostHighlight hh = new HostHighlight(elemId); 619 + * Handles the node badge add and highlights.
283 - hh.setBadge(createBadge(type)); 620 + *
284 - h.add(hh); 621 + * @param type device type
285 - return h; 622 + * @return badge of given node
286 - } 623 + */
287 -
288 private NodeBadge createBadge(String type) { 624 private NodeBadge createBadge(String type) {
289 return NodeBadge.text(type); 625 return NodeBadge.text(type);
290 } 626 }
291 627
292 - //TODO: Listeners need to add. 628 + /**
293 - //If topology changes then path need to be re calculate. 629 + * Handles the event of topology listeners.
630 + */
631 + private class InternalTopologyListener implements TopologyListener {
632 + @Override
633 + public void event(TopologyEvent event) {
634 + highlightDelay = DELAY_MS;
635 + findTunnelAndHighlights();
636 + highlightDelay = 0;
637 + }
638 + }
294 639
640 + /**
641 + * Handles the event of tunnel listeners.
642 + */
643 + private class InnerPceWebTunnelListener implements TunnelListener {
644 + @Override
645 + public void event(TunnelEvent event) {
646 + Tunnel tunnel = event.subject();
647 + if (tunnel.type() == MPLS) {
648 + highlightDelay = DELAY_MS;
649 + findTunnelAndHighlights();
650 + highlightDelay = 0;
651 + }
652 + }
653 + }
654 +
655 + /**
656 + * Handles the event of topology listeners.
657 + */
658 + private void findTunnelAndHighlights() {
659 + Collection<Tunnel> tunnelSet = null;
660 + tunnelSet = tunnelService.queryTunnel(MPLS);
661 + for (Tunnel tunnel : tunnelSet) {
662 + if (tunnel.path() == null) {
663 + log.info("path does not exist");
664 + return;
665 + }
666 + paths.add(tunnel.path());
667 + }
668 +
669 + ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
670 + allPathLinks = buildPaths(builder).build();
671 + hilightAndSendPaths();
672 + }
295 } 673 }
......
...@@ -63,7 +63,6 @@ public class PceWebTopovOverlay extends UiTopoOverlay { ...@@ -63,7 +63,6 @@ public class PceWebTopovOverlay extends UiTopoOverlay {
63 public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) { 63 public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) {
64 64
65 pp.title(MY_TITLE); 65 pp.title(MY_TITLE);
66 - log.info("Modify device details called.");
67 66
68 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); 67 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
69 68
......
...@@ -21,16 +21,23 @@ ...@@ -21,16 +21,23 @@
21 21
22 // injected refs 22 // injected refs
23 var $log, fs, flash, wss, tps, ns, tds, ds; 23 var $log, fs, flash, wss, tps, ns, tds, ds;
24 - 24 + var tunnelNameData, tunnelNameDataRemove;
25 // constants 25 // constants
26 var srcMessage = 'pceTopovSetSrc', 26 var srcMessage = 'pceTopovSetSrc',
27 dstMessage = 'pceTopovSetDst', 27 dstMessage = 'pceTopovSetDst',
28 clearMessage = 'pceTopovClear', 28 clearMessage = 'pceTopovClear',
29 - setModemsg = 'pceTopovSetMode', 29 + setPathmsg = 'pceTopovSetMode',
30 - L3dev = 'requestIpDevDetails'; 30 + updatePathmsgQuery = 'pceTopovUpdateQuery',
31 + remPathmsgQuery = 'pceTopovRemQuery',
32 + updatePathmsg = 'pceTopovUpdate',
33 + remPathmsg = 'pceTopovRem',
34 + showTunnelInfoMsg = 'pceTopovShowTunnels',
35 + queryDisplayTunnelMsg = 'pceTopovTunnelDisplay',
36 + showTunnelInfoRemoveMsg = 'pceTopovShowTunnelsRem';
31 // internal state 37 // internal state
32 var currentMode = null; 38 var currentMode = null;
33 - 39 + var handlerMap = {},
40 + handlerMapRem = {};
34 // === --------------------------- 41 // === ---------------------------
35 // === Helper functions 42 // === Helper functions
36 43
...@@ -58,153 +65,326 @@ ...@@ -58,153 +65,326 @@
58 flash.flash('Cleared source and destination'); 65 flash.flash('Cleared source and destination');
59 } 66 }
60 67
61 - function dOk() { 68 + function dClose() {
62 - var bandWidth = d3.select('#band-width-box').property("checked"); 69 + $log.debug('Dialog Close button clicked (or Esc pressed)');
63 - var bandValue = null; 70 + }
64 - var bandType = null;
65 -
66 - if (bandWidth) {
67 -
68 - bandValue = d3.select('#band-width-value').property("value");
69 71
70 - if (d3.select("#band-kpbs-val").property("checked")) { 72 + function createUserText() {
71 - bandType = 'kbps'; 73 + var content = ds.createDiv('constraints-input'),
72 - } else if (d3.select('#band-mpbs-val').property("checked")) { 74 + form = content.append('form'),
73 - bandType = 'mbps'; 75 + p = form.append('p');
74 - } 76 +
77 + function addAttribute(name, id, nameField, type) {
78 + p.append('input').attr({
79 + type: type,
80 + name: name,
81 + id: id
82 + });
83 +
84 + p.append('span').text(nameField);
85 + p.append('br');
75 } 86 }
76 87
77 - var costType = d3.select('#pce-cost-type').property("checked"); 88 + //Add the bandwidth related inputs.
78 - var costTypeVal = null; 89 + addAttribute('band-width-name', 'band-width-box', 'Band Width', 'checkbox');
90 + addAttribute('band-width-value-name', 'band-width-value', null, 'number');
91 + addAttribute('pce-band-type', 'band-kpbs-val', 'kbps', 'radio');
92 + addAttribute('pce-band-type', 'band-mpbs-val', 'mbps', 'radio');
93 + //Add the cost type related inputs.
94 + addAttribute('pce-cost-type-name', 'pce-cost-type', 'Cost Type', 'checkbox');
95 + addAttribute('pce-cost-type-valname', 'pce-cost-type-igp', 'IGP', 'radio');
96 + addAttribute('pce-cost-type-valname', 'pce-cost-type-te', 'TE', 'radio');
97 + //Add the LSP type related inputs.
98 + addAttribute('pce-lsp-type-name', 'pce-lsp-type', 'Lsp Type', 'checkbox');
99 + addAttribute('pce-lsp-type-valname', 'pce-lsp-type-cr', 'WITH SIGNALLING', 'radio');
100 + addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srbe', 'WITHOUT SR WITHOUT SIGNALLING', 'radio');
101 + addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srte', 'WITH SR WITHOUT SIGNALLING', 'radio');
102 + //Add the tunnel name
103 + addAttribute('pce-tunnel-name', 'pce-tunnel-name-id', 'Tunnel Name', 'text');
79 104
80 - if (costType) { 105 + return content;
106 + }
81 107
82 - if (d3.select("#pce-cost-type-igp").property("checked")) { 108 + function createUserTextUpdate(data) {
83 - costTypeVal = 'igp'; 109 + var content = ds.createDiv(),
84 - } else if (d3.select('#pce-cost-type-te').property("checked")) { 110 + form = content.append('form'),
85 - costTypeVal = 'te'; 111 + p = form.append('p');
86 - }
87 - }
88 112
89 - var lspType = d3.select('#pce-lsp-type').property("checked"); 113 + p.append('span').text('Tunnel IDs');
90 - var lspTypeVal = null; 114 + p.append('br');
91 115
92 - if (lspType) { 116 + data.a.forEach( function (val, idx) {
117 + p.append('input').attr({
118 + id: 'tunnel-id-'+idx,
119 + type: 'radio',
120 + name: 'tunnel-id-name',
121 + value: val
122 + });
93 123
94 - if (d3.select("#pce-lsp-type-cr").property("checked")) { 124 + p.append('span').text(val);
95 - lspTypeVal = 'cr'; 125 + p.append('br');
96 - } else if (d3.select('#pce-lsp-type-srbe').property("checked")) {
97 - lspTypeVal = 'srbe';
98 - } else if (d3.select('#pce-lsp-type-srte').property("checked")) {
99 - lspTypeVal = 'srte';
100 - }
101 - }
102 126
103 - //TBD: Read the user inputs and need to send the event for calculating the path based on constrainsts. 127 + } );
104 - // TBD: Need to read IGP cost type and LSP type.
105 - //wss.sendEvent(setModemsg);
106 - //flash.flash('creat path message');
107 128
108 - $log.debug('Dialog OK button clicked'); 129 + return content;
109 } 130 }
110 131
111 - function dClose() { 132 + function createUserTextUpdatePathEvent() {
112 - $log.debug('Dialog Close button clicked (or Esc pressed)'); 133 + var content = ds.createDiv(),
113 - } 134 + form = content.append('form'),
135 + p = form.append('p');
114 136
115 - function createUserText() { 137 + function addAttribute(name, id, nameField, type) {
116 - var content = ds.createDiv(); 138 + p.append('input').attr({
117 - var form = content.append('form'); 139 + type: type,
118 - var p = form.append('p'); 140 + name: name,
141 + id: id
142 + });
119 143
120 - //Add the bandwidth related inputs. 144 + p.append('span').text(nameField);
121 - p.append('input').attr({ 145 + p.append('br');
122 - id: 'band-width-box', 146 + }
123 - type: 'checkbox',
124 - name: 'band-width-name'
125 - });
126 - p.append('span').text('Band Width');
127 - p.append('br');
128 - p.append('input').attr({
129 - id: 'band-width-value',
130 - type: 'number',
131 - name: 'band-width-value-name'
132 - });
133 - p.append('input').attr({
134 - id: 'band-kpbs-val',
135 - type: 'radio',
136 - name: 'pce-band-type'
137 - });
138 - p.append('span').text('kpbs');
139 - p.append('input').attr({
140 - id: 'band-mpbs-val',
141 - type: 'radio',
142 - name: 'pce-band-type'
143 - });
144 - p.append('span').text('mpbs');
145 - p.append('br');
146 147
148 + //Add the bandwidth related inputs.
149 + addAttribute('band-width-name', 'update-band-width-box', 'Band Width', 'checkbox');
150 + addAttribute('band-width-value-name', 'update-band-width-value', null, 'number');
151 + addAttribute('pce-band-type', 'update-band-kpbs-val', 'kbps', 'radio');
152 + addAttribute('pce-band-type', 'update-band-mpbs-val', 'mbps', 'radio');
147 //Add the cost type related inputs. 153 //Add the cost type related inputs.
148 - p.append('input').attr({ 154 + addAttribute('pce-cost-type', 'update-pce-cost-type', 'Cost Type', 'checkbox');
149 - id: 'pce-cost-type', 155 + addAttribute('pce-cost-type-value', 'update-pce-cost-type-igp', 'IGP', 'radio');
150 - type: 'checkbox', 156 + addAttribute('pce-cost-type-value', 'update-pce-cost-type-te', 'TE', 'radio');
151 - name: 'pce-cost-type-name'
152 - });
153 - p.append('span').text('Cost Type');
154 - p.append('br');
155 - p.append('input').attr({
156 - id: 'pce-cost-type-igp',
157 - type: 'radio',
158 - name: 'pce-cost-type-valname'
159 - });
160 - p.append('span').text('IGP');
161 - p.append('input').attr({
162 - id: 'pce-cost-type-te',
163 - type: 'radio',
164 - name: 'pce-cost-type-valname'
165 - });
166 - p.append('span').text('TE');
167 - p.append('br');
168 157
169 - //Add the LSP type related inputs. 158 + return content;
170 - p.append('input').attr({ 159 + }
171 - id: 'pce-lsp-type', 160 +
172 - type: 'checkbox', 161 + function createUserTextRemove(data) {
173 - name: 'pce-lsp-type-name' 162 +
174 - }); 163 + var content = ds.createDiv(),
175 - p.append('span').text('Lsp Type'); 164 + form = content.append('form'),
165 + p = form.append('p');
166 +
167 + p.append('span').text('Tunnel IDs');
176 p.append('br'); 168 p.append('br');
177 - p.append('input').attr({ 169 +
178 - id: 'pce-lsp-type-cr', 170 + data.a.forEach( function (val, idx) {
179 - type: 'radio', 171 + p.append('input').attr({
180 - name: 'pce-lsp-type-valname' 172 + id: 'tunnel-id-remove-'+idx,
181 - }); 173 + type: 'checkbox',
182 - p.append('span').text('CR'); 174 + name: 'tunnel-id-name-remove',
183 - p.append('input').attr({ 175 + value: val
184 - id: 'pce-lsp-type-srbe', 176 + });
185 - type: 'radio', 177 +
186 - name: 'pce-lsp-type-valname' 178 + p.append('span').text(val);
187 - }); 179 + p.append('br');
188 - p.append('span').text('SR BE'); 180 + } );
189 - p.append('input').attr({
190 - id: 'pce-lsp-type-srte',
191 - type: 'radio',
192 - name: 'pce-lsp-type-valname'
193 - });
194 - p.append('span').text('SR TE');
195 181
196 return content; 182 return content;
197 } 183 }
198 184
185 + function isChecked(viewId) {
186 + return d3.select('#' + viewId).property('checked');
187 + }
188 +
189 + function getCheckedValue(viewId) {
190 + return d3.select('#' + viewId).property('value');
191 + }
192 +
193 + function showTunnelInformation(data) {
194 + wss.unbindHandlers(handlerMap);
195 + tunnelNameData = data;
196 +
197 + function dOkUpdate() {
198 + var tdString = '' ;
199 + tunnelNameData.a.forEach( function (val, idx) {
200 + var tunnelName = isChecked('tunnel-id-'+idx);
201 + if (tunnelName)
202 + {
203 + tdString = val;
204 + }
205 + } );
206 +
207 + if (tdString) {
208 + constraintsUpdateDialog(tdString);
209 + } else {
210 + $log.debug("No tunnel id is selected.");
211 + }
212 +
213 + $log.debug('Dialog OK button clicked');
214 + }
215 +
216 + tds.openDialog()
217 + .setTitle('Available LSPs with selected device')
218 + .addContent(createUserTextUpdate(data))
219 + .addOkChained(dOkUpdate, 'GOTO Selection of constraints')
220 + .addCancel(dClose, 'Close')
221 + .bindKeys();
222 + }
223 +
224 + function constraintsUpdateDialog(tunnelId) {
225 +
226 + // invoked when the OK button is pressed on this dialog
227 + function dOkUpdateEvent() {
228 + $log.debug('Select constraints for update path Dialog OK button pressed');
229 +
230 + var bandWidth = isChecked('update-band-width-box'),
231 + bandValue = null,
232 + bandType = null;
233 +
234 + if (bandWidth) {
235 + bandValue = d3.select('#update-band-width-value');
236 +
237 + if (isChecked('update-band-kpbs-val')) {
238 + bandType = 'kbps';
239 + } else if (isChecked('update-band-mpbs-val')) {
240 + bandType = 'mbps';
241 + }
242 + }
243 +
244 + var costType = isChecked('update-pce-cost-type'),
245 + costTypeVal = null;
246 +
247 + if (costType) {
248 + if (isChecked('update-pce-cost-type-igp')) {
249 + costTypeVal = 'igp';
250 + } else if (isChecked('update-pce-cost-type-te')) {
251 + costTypeVal = 'te';
252 + }
253 + }
254 +
255 + wss.sendEvent(updatePathmsg, {
256 + bw: bandValue,
257 + ctype: costTypeVal,
258 + tunnelname: tunnelId
259 + });
260 +
261 + flash.flash('update path message');
262 +
263 + }
264 +
265 + tds.openDialog()
266 + .setTitle('Select constraints for update path')
267 + .addContent(createUserTextUpdatePathEvent())
268 + .addCancel()
269 + .addOk(dOkUpdateEvent, 'Update Path') // NOTE: NOT the "chained" version!
270 + .bindKeys();
271 +
272 + }
273 +
274 + function showTunnelInformationRemove(data) {
275 +
276 + wss.unbindHandlers(handlerMapRem);
277 + tunnelNameDataRemove = data;
278 + tds.openDialog()
279 + .setTitle('Available Tunnels for remove')
280 + .addContent(createUserTextRemove(data))
281 + .addOk(dOkRemove, 'Remove')
282 + .addCancel(dClose, 'Close')
283 + .bindKeys();
284 + }
285 +
286 + //setup path
199 function setMode() { 287 function setMode() {
288 +
289 + function dOk() {
290 + var bandWidth = isChecked('band-width-box'),
291 + bandValue = null,
292 + bandType = null;
293 +
294 + if (bandWidth) {
295 + bandValue = getCheckedValue('band-width-value');
296 +
297 + if (isChecked('band-kpbs-val')) {
298 + bandType = 'kbps';
299 + } else if (isChecked('band-mpbs-val')) {
300 + bandType = 'mbps';
301 + }
302 + }
303 +
304 + var costType = isChecked('pce-cost-type'),
305 + costTypeVal = null;
306 +
307 + if (costType) {
308 + if (isChecked('pce-cost-type-igp')) {
309 + costTypeVal = 'igp';
310 + } else if (isChecked('pce-cost-type-te')) {
311 + costTypeVal = 'te';
312 + }
313 + }
314 +
315 + var lspType = isChecked('pce-lsp-type'),
316 + lspTypeVal = null;
317 +
318 + if (lspType) {
319 + if (isChecked('pce-lsp-type-cr')) {
320 + lspTypeVal = 'cr';
321 + } else if (isChecked('pce-lsp-type-srbe')) {
322 + lspTypeVal = 'srbe';
323 + } else if (isChecked('pce-lsp-type-srte')) {
324 + lspTypeVal = 'srte';
325 + }
326 + }
327 +
328 + wss.sendEvent(setPathmsg, {
329 + bw: bandValue,
330 + bwtype: bandType,
331 + ctype: costTypeVal,
332 + lsptype: lspTypeVal,
333 + tunnelname: getCheckedValue('pce-tunnel-name-id')
334 + });
335 +
336 + flash.flash('create path message');
337 + $log.debug('Dialog OK button clicked');
338 + }
339 +
200 tds.openDialog() 340 tds.openDialog()
201 - .setTitle('constraints user') 341 + .setTitle('constraints selection')
202 .addContent(createUserText()) 342 .addContent(createUserText())
203 .addOk(dOk, 'OK') 343 .addOk(dOk, 'OK')
204 .addCancel(dClose, 'Close') 344 .addCancel(dClose, 'Close')
205 .bindKeys(); 345 .bindKeys();
206 } 346 }
207 347
348 + function updatePath(node) {
349 +
350 + wss.sendEvent(updatePathmsgQuery, {
351 + srid: node[0],
352 + dsid: node[1]
353 + });
354 +
355 + handlerMap[showTunnelInfoMsg] = showTunnelInformation;
356 + wss.bindHandlers(handlerMap);
357 +
358 + flash.flash('update path message');
359 + }
360 +
361 + function dOkRemove() {
362 +
363 + tunnelNameDataRemove.a.forEach( function (val, idx) {
364 + var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
365 + if (tunnelNameVal) {
366 + wss.sendEvent(remPathmsg, {
367 + tunnelid: val
368 + });
369 + }
370 + } );
371 +
372 + flash.flash('remove path message');
373 + }
374 +
375 + function remPath(node) {
376 + wss.sendEvent(remPathmsgQuery, {
377 + srid: node[0],
378 + dsid: node[1]
379 + });
380 +
381 + handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
382 + wss.bindHandlers(handlerMapRem);
383 + }
384 +
385 + function queryTunnelDisplay() {
386 + wss.sendEvent(queryDisplayTunnelMsg);
387 + }
208 // === --------------------------- 388 // === ---------------------------
209 // === Module Factory Definition 389 // === Module Factory Definition
210 390
...@@ -227,8 +407,10 @@ ...@@ -227,8 +407,10 @@
227 setSrc: setSrc, 407 setSrc: setSrc,
228 setDst: setDst, 408 setDst: setDst,
229 clear: clear, 409 clear: clear,
230 - setMode: setMode 410 + setMode: setMode,
231 - 411 + updatePath: updatePath,
412 + remPath: remPath,
413 + queryTunnelDisplay: queryTunnelDisplay
232 }; 414 };
233 }]); 415 }]);
234 }()); 416 }());
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
34 glyphId: 'topo', 34 glyphId: 'topo',
35 tooltip: 'PCE web Topo Overlay', 35 tooltip: 'PCE web Topo Overlay',
36 36
37 -
38 activate: function () { 37 activate: function () {
39 $log.debug("PCE web topology overlay ACTIVATED"); 38 $log.debug("PCE web topology overlay ACTIVATED");
40 }, 39 },
...@@ -112,11 +111,32 @@ ...@@ -112,11 +111,32 @@
112 }, 111 },
113 1: { 112 1: {
114 cb: function () { 113 cb: function () {
115 - pps.setMode("shortest"); 114 + pps.setMode();
115 + },
116 + tt: 'Setup path',
117 + gid: 'plus'
118 + },
119 + 2: {
120 + cb: function () {
121 + pps.updatePath(selection);
116 }, 122 },
117 - tt: 'Select constraints for LSP', 123 + tt: 'Update path',
118 gid: '*jp' 124 gid: '*jp'
119 }, 125 },
126 + 3: {
127 + cb: function () {
128 + pps.remPath(selection);
129 + },
130 + tt: 'Remove path',
131 + gid: 'minus'
132 + },
133 + 4: {
134 + cb: function () {
135 + pps.queryTunnelDisplay();
136 + },
137 + tt: 'Show Tunnels',
138 + gid: 'checkMark'
139 + },
120 0: { 140 0: {
121 cb: function () { 141 cb: function () {
122 pps.clear(); 142 pps.clear();
...@@ -126,7 +146,7 @@ ...@@ -126,7 +146,7 @@
126 }, 146 },
127 147
128 _keyOrder: [ 148 _keyOrder: [
129 - 'openBracket', 'closeBracket', '1', '0' 149 + 'openBracket', 'closeBracket', '1', '2', '3', '4', '0'
130 ] 150 ]
131 }, 151 },
132 hooks: { 152 hooks: {
...@@ -145,6 +165,9 @@ ...@@ -145,6 +165,9 @@
145 }, 165 },
146 single: function (data) { 166 single: function (data) {
147 selectionCallback(data); 167 selectionCallback(data);
168 + },
169 + multi: function (selectOrder) {
170 + selectionCallback(selectOrder);
148 } 171 }
149 } 172 }
150 }; 173 };
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 <groupId>org.onosproject</groupId> 21 <groupId>org.onosproject</groupId>
22 <artifactId>onos-apps</artifactId> 22 <artifactId>onos-apps</artifactId>
23 <version>1.6.0-SNAPSHOT</version> 23 <version>1.6.0-SNAPSHOT</version>
24 + <relativePath>../pom.xml</relativePath>
24 </parent> 25 </parent>
25 <modelVersion>4.0.0</modelVersion> 26 <modelVersion>4.0.0</modelVersion>
26 27
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
23 <groupId>org.onosproject</groupId> 23 <groupId>org.onosproject</groupId>
24 <artifactId>onos-bgp</artifactId> 24 <artifactId>onos-bgp</artifactId>
25 <version>1.6.0-SNAPSHOT</version> 25 <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
26 </parent> 27 </parent>
27 28
28 <artifactId>onos-bgp-api</artifactId> 29 <artifactId>onos-bgp-api</artifactId>
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
23 <groupId>org.onosproject</groupId> 23 <groupId>org.onosproject</groupId>
24 <artifactId>onos-bgp</artifactId> 24 <artifactId>onos-bgp</artifactId>
25 <version>1.6.0-SNAPSHOT</version> 25 <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
26 </parent> 27 </parent>
27 28
28 <artifactId>onos-bgpio</artifactId> 29 <artifactId>onos-bgpio</artifactId>
......
...@@ -241,12 +241,11 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg { ...@@ -241,12 +241,11 @@ public class BgpUpdateMsgVer4 implements BgpUpdateMsg {
241 afi = mpUnReach.afi(); 241 afi = mpUnReach.afi();
242 safi = mpUnReach.safi(); 242 safi = mpUnReach.safi();
243 } 243 }
244 + }
244 245
245 - if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) 246 + if ((afi == Constants.AFI_FLOWSPEC_VALUE) || (afi == Constants.AFI_VALUE)) {
246 - || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { 247 + //unfeasible route length
247 - //unfeasible route length 248 + cb.writeShort(0);
248 - cb.writeShort(0);
249 - }
250 } 249 }
251 250
252 } 251 }
......
...@@ -171,15 +171,17 @@ public class As4Path implements BgpValueType { ...@@ -171,15 +171,17 @@ public class As4Path implements BgpValueType {
171 if ((as4pathSet != null) && (as4pathSeq != null)) { 171 if ((as4pathSet != null) && (as4pathSeq != null)) {
172 int iAsLenIndex = cb.writerIndex(); 172 int iAsLenIndex = cb.writerIndex();
173 cb.writeByte(0); 173 cb.writeByte(0);
174 - cb.writeByte(AsPath.ASPATH_SEQ_TYPE); 174 + if (as4pathSeq.size() != 0) {
175 - cb.writeByte(as4pathSeq.size()); 175 + cb.writeByte(AsPath.ASPATH_SEQ_TYPE);
176 + cb.writeByte(as4pathSeq.size());
176 177
177 - for (int j = 0; j < as4pathSeq.size(); j++) { 178 + for (int j = 0; j < as4pathSeq.size(); j++) {
178 - cb.writeInt(as4pathSeq.get(j)); 179 + cb.writeInt(as4pathSeq.get(j));
179 - } 180 + }
180 181
181 - int asLen = cb.writerIndex() - iAsLenIndex; 182 + int asLen = cb.writerIndex() - iAsLenIndex;
182 - cb.setByte(iAsLenIndex, (byte) (asLen - 1)); 183 + cb.setByte(iAsLenIndex, (byte) (asLen - 1));
184 + }
183 } else { 185 } else {
184 cb.writeByte(0); 186 cb.writeByte(0);
185 } 187 }
......
...@@ -208,15 +208,16 @@ public class AsPath implements BgpValueType { ...@@ -208,15 +208,16 @@ public class AsPath implements BgpValueType {
208 if (isaspathSet()) { 208 if (isaspathSet()) {
209 int iAsLenIndex = cb.writerIndex(); 209 int iAsLenIndex = cb.writerIndex();
210 cb.writeByte(0); 210 cb.writeByte(0);
211 - cb.writeByte(ASPATH_SEQ_TYPE); 211 + if (aspathSeq.size() != 0) {
212 - cb.writeByte(aspathSeq.size()); 212 + cb.writeByte(ASPATH_SEQ_TYPE);
213 + cb.writeByte(aspathSeq.size());
213 214
214 - for (int j = 0; j < aspathSeq.size(); j++) { 215 + for (int j = 0; j < aspathSeq.size(); j++) {
215 - cb.writeShort(aspathSeq.get(j)); 216 + cb.writeShort(aspathSeq.get(j));
217 + }
218 + int asLen = cb.writerIndex() - iAsLenIndex;
219 + cb.setByte(iAsLenIndex, (byte) (asLen - 1));
216 } 220 }
217 -
218 - int asLen = cb.writerIndex() - iAsLenIndex;
219 - cb.setByte(iAsLenIndex, (byte) (asLen - 1));
220 } else { 221 } else {
221 cb.writeByte(0); 222 cb.writeByte(0);
222 } 223 }
......
...@@ -106,7 +106,7 @@ public class LinkStateAttributes implements BgpValueType { ...@@ -106,7 +106,7 @@ public class LinkStateAttributes implements BgpValueType {
106 * 106 *
107 * @param linkStateAttribList Linked list of Link, Node and Prefix TLVs 107 * @param linkStateAttribList Linked list of Link, Node and Prefix TLVs
108 */ 108 */
109 - LinkStateAttributes(List<BgpValueType> linkStateAttribList) { 109 + public LinkStateAttributes(List<BgpValueType> linkStateAttribList) {
110 this.linkStateAttribList = linkStateAttribList; 110 this.linkStateAttribList = linkStateAttribList;
111 this.isLinkStateAttribute = true; 111 this.isLinkStateAttribute = true;
112 } 112 }
......
...@@ -163,7 +163,6 @@ public class WideCommunityAttrHeader implements BgpValueType { ...@@ -163,7 +163,6 @@ public class WideCommunityAttrHeader implements BgpValueType {
163 c.writeShort(TYPE); 163 c.writeShort(TYPE);
164 c.writeByte(flag); 164 c.writeByte(flag);
165 c.writeByte(hopCount); 165 c.writeByte(hopCount);
166 - c.writeShort(length);
167 return c.writerIndex() - iLenStartIndex; 166 return c.writerIndex() - iLenStartIndex;
168 } 167 }
169 168
......
...@@ -97,8 +97,8 @@ public class WideCommunityIpV4Neighbour implements BgpValueType { ...@@ -97,8 +97,8 @@ public class WideCommunityIpV4Neighbour implements BgpValueType {
97 while (listIterator.hasNext()) { 97 while (listIterator.hasNext()) {
98 IpV4Neighbour speaker = listIterator.next(); 98 IpV4Neighbour speaker = listIterator.next();
99 if (speaker instanceof IpV4Neighbour) { 99 if (speaker instanceof IpV4Neighbour) {
100 - c.writeInt(Integer.valueOf(speaker.localSpeaker.toString())); 100 + c.writeBytes(speaker.localSpeaker().toOctets());
101 - c.writeInt(Integer.valueOf(speaker.remoteSpeaker.toString())); 101 + c.writeBytes(speaker.remoteSpeaker().toOctets());
102 } 102 }
103 } 103 }
104 104
......
...@@ -96,7 +96,7 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType { ...@@ -96,7 +96,7 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType {
96 * 96 *
97 * @return Maximum link bandwidth 97 * @return Maximum link bandwidth
98 */ 98 */
99 - float linkAttrMaxLinkBandwidth() { 99 + public float linkAttrMaxLinkBandwidth() {
100 return maxBandwidth; 100 return maxBandwidth;
101 } 101 }
102 102
......
...@@ -43,10 +43,10 @@ import java.util.Objects; ...@@ -43,10 +43,10 @@ import java.util.Objects;
43 public class WideCommunity implements BgpValueType { 43 public class WideCommunity implements BgpValueType {
44 44
45 private static final Logger log = LoggerFactory.getLogger(WideCommunity.class); 45 private static final Logger log = LoggerFactory.getLogger(WideCommunity.class);
46 - public static final byte TYPE = (byte) 254; /* TODO: IANA Assigned */ 46 + public static final byte TYPE = (byte) 129;
47 public static final short LENGTH = 4; 47 public static final short LENGTH = 4;
48 public static final byte TYPE_LENGTH_SIZE = 3; 48 public static final byte TYPE_LENGTH_SIZE = 3;
49 - public static final byte FLAGS = (byte) 0x40; 49 + public static final byte FLAGS = (byte) 0x90;
50 private WideCommunityAttrHeader wideCommunityHeader; 50 private WideCommunityAttrHeader wideCommunityHeader;
51 private int community; 51 private int community;
52 private int localAsn; 52 private int localAsn;
...@@ -238,6 +238,9 @@ public class WideCommunity implements BgpValueType { ...@@ -238,6 +238,9 @@ public class WideCommunity implements BgpValueType {
238 238
239 wideCommunityHeader.write(c); 239 wideCommunityHeader.write(c);
240 240
241 + int iComLengthIndex = c.writerIndex();
242 + c.writeShort(0);
243 +
241 c.writeInt(community); 244 c.writeInt(community);
242 c.writeInt(localAsn); 245 c.writeInt(localAsn);
243 c.writeInt(contextAsn); 246 c.writeInt(contextAsn);
...@@ -275,6 +278,9 @@ public class WideCommunity implements BgpValueType { ...@@ -275,6 +278,9 @@ public class WideCommunity implements BgpValueType {
275 c.setShort(iTargetLenIndex, (short) (length - 2)); 278 c.setShort(iTargetLenIndex, (short) (length - 2));
276 } 279 }
277 280
281 + length = c.writerIndex() - iComLengthIndex;
282 + c.setShort(iComLengthIndex, (short) (length - 2));
283 +
278 length = c.writerIndex() - iLengthIndex; 284 length = c.writerIndex() - iLengthIndex;
279 c.setShort(iLengthIndex, (short) (length - 2)); 285 c.setShort(iLengthIndex, (short) (length - 2));
280 286
......
...@@ -46,6 +46,11 @@ ...@@ -46,6 +46,11 @@
46 <groupId>org.osgi</groupId> 46 <groupId>org.osgi</groupId>
47 <artifactId>org.osgi.compendium</artifactId> 47 <artifactId>org.osgi.compendium</artifactId>
48 </dependency> 48 </dependency>
49 + <dependency>
50 + <groupId>io.netty</groupId>
51 + <artifactId>netty-common</artifactId>
52 + <version>4.0.36.Final</version>
53 + </dependency>
49 </dependencies> 54 </dependencies>
50 55
51 <build> 56 <build>
......
...@@ -205,7 +205,7 @@ public class BgpConfig implements BgpCfg { ...@@ -205,7 +205,7 @@ public class BgpConfig implements BgpCfg {
205 lspeer.setSelfInnitConnection(true); 205 lspeer.setSelfInnitConnection(true);
206 206
207 if (lspeer.connectPeer() == null) { 207 if (lspeer.connectPeer() == null) {
208 - connectPeer = new BgpConnectPeerImpl(bgpController, routerid, Controller.getBgpPortNum()); 208 + connectPeer = new BgpConnectPeerImpl(bgpController, routerid, Controller.BGP_PORT_NUM);
209 lspeer.setConnectPeer(connectPeer); 209 lspeer.setConnectPeer(connectPeer);
210 connectPeer.connectPeer(); 210 connectPeer.connectPeer();
211 } 211 }
......
...@@ -135,7 +135,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -135,7 +135,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
135 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); 135 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
136 // Compare local RIB entry with the current attribute 136 // Compare local RIB entry with the current attribute
137 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib); 137 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
138 - if (decisionResult < 0) { 138 + if (decisionResult <= 0) {
139 for (BgpNodeListener l : bgpController.listener()) { 139 for (BgpNodeListener l : bgpController.listener()) {
140 l.addNode((BgpNodeLSNlriVer4) nlri, details); 140 l.addNode((BgpNodeLSNlriVer4) nlri, details);
141 } 141 }
...@@ -155,7 +155,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -155,7 +155,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
155 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); 155 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
156 // Compare local RIB entry with the current attribute 156 // Compare local RIB entry with the current attribute
157 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib); 157 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
158 - if (decisionResult < 0) { 158 + if (decisionResult <= 0) {
159 linkTree.replace(linkLsIdentifier, detailsLocRib); 159 linkTree.replace(linkLsIdentifier, detailsLocRib);
160 for (BgpLinkListener l : bgpController.linkListener()) { 160 for (BgpLinkListener l : bgpController.linkListener()) {
161 l.addLink((BgpLinkLsNlriVer4) nlri, details); 161 l.addLink((BgpLinkLsNlriVer4) nlri, details);
...@@ -175,7 +175,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -175,7 +175,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
175 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo(); 175 BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
176 // Compare local RIB entry with the current attribute 176 // Compare local RIB entry with the current attribute
177 decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib); 177 decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
178 - if (decisionResult < 0) { 178 + if (decisionResult <= 0) {
179 prefixTree.replace(prefixIdentifier, detailsLocRib); 179 prefixTree.replace(prefixIdentifier, detailsLocRib);
180 log.debug("Local RIB update prefix: {}", detailsLocRib.toString()); 180 log.debug("Local RIB update prefix: {}", detailsLocRib.toString());
181 } 181 }
......
...@@ -159,15 +159,16 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -159,15 +159,16 @@ public class BgpPeerImpl implements BgpPeer {
159 * Send flow specification update message to peer. 159 * Send flow specification update message to peer.
160 * 160 *
161 * @param operType operation type 161 * @param operType operation type
162 + * @param routeKey flow rule key
162 * @param flowSpec flow specification details 163 * @param flowSpec flow specification details
163 - * @param wideCommunity for route policy 164 + * @param wideCommunity for route policy
164 */ 165 */
165 public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, 166 public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey,
166 BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) { 167 BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) {
167 168
168 List<BgpValueType> attributesList = new LinkedList<>(); 169 List<BgpValueType> attributesList = new LinkedList<>();
169 byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1; 170 byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
170 - byte sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE; 171 + byte sAfi = Constants.SAFI_FLOWSPEC_VALUE;
171 172
172 boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, 173 boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE,
173 Constants.AFI_FLOWSPEC_VALUE, 174 Constants.AFI_FLOWSPEC_VALUE,
...@@ -190,10 +191,10 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -190,10 +191,10 @@ public class BgpPeerImpl implements BgpPeer {
190 return; 191 return;
191 } 192 }
192 193
193 - if ((wideCommunity != null) && (isVpnRpdCapabilitySet)) { 194 + if (isVpnFsCapabilitySet) {
194 - sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
195 - } else if (isVpnFsCapabilitySet) {
196 sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE; 195 sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE;
196 + } else if (isVpnRpdCapabilitySet) {
197 + sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
197 } 198 }
198 attributesList.add(new Origin((byte) 0)); 199 attributesList.add(new Origin((byte) 0));
199 200
...@@ -222,7 +223,9 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -222,7 +223,9 @@ public class BgpPeerImpl implements BgpPeer {
222 } 223 }
223 224
224 attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv())); 225 attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv()));
225 - attributesList.add(wideCommunity); 226 + if (wideCommunity != null) {
227 + attributesList.add(wideCommunity);
228 + }
226 229
227 if (operType == FlowSpecOperation.ADD) { 230 if (operType == FlowSpecOperation.ADD) {
228 attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi)); 231 attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 package org.onosproject.bgp.controller.impl; 16 package org.onosproject.bgp.controller.impl;
17 17
18 import static org.onlab.util.Tools.groupedThreads; 18 import static org.onlab.util.Tools.groupedThreads;
19 - 19 +import io.netty.util.internal.PlatformDependent;
20 import java.lang.management.ManagementFactory; 20 import java.lang.management.ManagementFactory;
21 import java.lang.management.RuntimeMXBean; 21 import java.lang.management.RuntimeMXBean;
22 import java.net.InetSocketAddress; 22 import java.net.InetSocketAddress;
...@@ -53,9 +53,11 @@ public class Controller { ...@@ -53,9 +53,11 @@ public class Controller {
53 public Channel serverChannel; 53 public Channel serverChannel;
54 54
55 // Configuration options 55 // Configuration options
56 - private static final short BGP_PORT_NUM = 179; 56 + protected static final short BGP_PORT_NUM = 179;
57 + private static final short BGP_PRIVILEGED_PORT = 1790; // server port used for non root users in linux
57 private static final short PORT_NUM_ZERO = 0; 58 private static final short PORT_NUM_ZERO = 0;
58 private static boolean isPortNumSet = false; 59 private static boolean isPortNumSet = false;
60 + private static short portNumber = BGP_PORT_NUM;
59 private final int workerThreads = 16; 61 private final int workerThreads = 16;
60 private final int peerWorkerThreads = 16; 62 private final int peerWorkerThreads = 16;
61 63
...@@ -219,6 +221,11 @@ public class Controller { ...@@ -219,6 +221,11 @@ public class Controller {
219 */ 221 */
220 public void start() { 222 public void start() {
221 log.info("Started"); 223 log.info("Started");
224 + if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot()) {
225 + portNumber = BGP_PRIVILEGED_PORT;
226 + } else {
227 + portNumber = BGP_PORT_NUM;
228 + }
222 this.init(); 229 this.init();
223 this.run(); 230 this.run();
224 } 231 }
...@@ -242,7 +249,8 @@ public class Controller { ...@@ -242,7 +249,8 @@ public class Controller {
242 if (isPortNumSet) { 249 if (isPortNumSet) {
243 return PORT_NUM_ZERO; 250 return PORT_NUM_ZERO;
244 } 251 }
245 - return BGP_PORT_NUM; 252 +
253 + return portNumber;
246 } 254 }
247 255
248 /** 256 /**
......
1 COMPILE_DEPS = [ 1 COMPILE_DEPS = [
2 '//lib:CORE_DEPS', 2 '//lib:CORE_DEPS',
3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', 3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
4 + '//apps/pcep-api:onos-apps-pcep-api',
5 + '//incubator/api:onos-incubator-api',
4 ] 6 ]
5 7
6 osgi_jar_with_tests ( 8 osgi_jar_with_tests (
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
23 <groupId>org.onosproject</groupId> 23 <groupId>org.onosproject</groupId>
24 <artifactId>onos-pcep-controller</artifactId> 24 <artifactId>onos-pcep-controller</artifactId>
25 <version>1.6.0-SNAPSHOT</version> 25 <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
26 </parent> 27 </parent>
27 28
28 <artifactId>onos-pcep-controller-api</artifactId> 29 <artifactId>onos-pcep-controller-api</artifactId>
...@@ -51,5 +52,9 @@ ...@@ -51,5 +52,9 @@
51 <groupId>org.onosproject</groupId> 52 <groupId>org.onosproject</groupId>
52 <artifactId>onlab-misc</artifactId> 53 <artifactId>onlab-misc</artifactId>
53 </dependency> 54 </dependency>
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
57 + <artifactId>onos-incubator-api</artifactId>
58 + </dependency>
54 </dependencies> 59 </dependencies>
55 </project> 60 </project>
......
...@@ -26,6 +26,8 @@ public class ClientCapability { ...@@ -26,6 +26,8 @@ public class ClientCapability {
26 private boolean pceccCapability; 26 private boolean pceccCapability;
27 private boolean statefulPceCapability; 27 private boolean statefulPceCapability;
28 private boolean pcInstantiationCapability; 28 private boolean pcInstantiationCapability;
29 + private boolean labelStackCapability;
30 + private boolean srCapability;
29 31
30 /** 32 /**
31 * Creates new instance of client capability. 33 * Creates new instance of client capability.
...@@ -33,11 +35,34 @@ public class ClientCapability { ...@@ -33,11 +35,34 @@ public class ClientCapability {
33 * @param pceccCapability represents PCECC capability 35 * @param pceccCapability represents PCECC capability
34 * @param statefulPceCapability represents stateful PCE capability 36 * @param statefulPceCapability represents stateful PCE capability
35 * @param pcInstantiationCapability represents PC initiation capability 37 * @param pcInstantiationCapability represents PC initiation capability
38 + * @param labelStackCapability represents S bit is set in PCECC capability
39 + * @param srCapability represents SR capability
36 */ 40 */
37 - public ClientCapability(boolean pceccCapability, boolean statefulPceCapability, boolean pcInstantiationCapability) { 41 + public ClientCapability(boolean pceccCapability, boolean statefulPceCapability, boolean pcInstantiationCapability,
42 + boolean labelStackCapability, boolean srCapability) {
38 this.pceccCapability = pceccCapability; 43 this.pceccCapability = pceccCapability;
39 this.statefulPceCapability = statefulPceCapability; 44 this.statefulPceCapability = statefulPceCapability;
40 this.pcInstantiationCapability = pcInstantiationCapability; 45 this.pcInstantiationCapability = pcInstantiationCapability;
46 + this.labelStackCapability = labelStackCapability;
47 + this.srCapability = srCapability;
48 + }
49 +
50 + /**
51 + * Obtains label stack capability.
52 + *
53 + * @return true if client supports PCECC capability with S bit set otherwise false
54 + */
55 + public boolean labelStackCapability() {
56 + return labelStackCapability;
57 + }
58 +
59 + /**
60 + * Obtains segment routing capability.
61 + *
62 + * @return true if client supports SR capability otherwise false
63 + */
64 + public boolean srCapability() {
65 + return srCapability;
41 } 66 }
42 67
43 /** 68 /**
...@@ -69,7 +94,8 @@ public class ClientCapability { ...@@ -69,7 +94,8 @@ public class ClientCapability {
69 94
70 @Override 95 @Override
71 public int hashCode() { 96 public int hashCode() {
72 - return Objects.hash(pceccCapability, statefulPceCapability, pcInstantiationCapability); 97 + return Objects.hash(pceccCapability, statefulPceCapability, pcInstantiationCapability, labelStackCapability,
98 + srCapability);
73 } 99 }
74 100
75 @Override 101 @Override
...@@ -81,7 +107,9 @@ public class ClientCapability { ...@@ -81,7 +107,9 @@ public class ClientCapability {
81 ClientCapability other = (ClientCapability) obj; 107 ClientCapability other = (ClientCapability) obj;
82 return Objects.equals(pceccCapability, other.pceccCapability) 108 return Objects.equals(pceccCapability, other.pceccCapability)
83 && Objects.equals(statefulPceCapability, other.statefulPceCapability) 109 && Objects.equals(statefulPceCapability, other.statefulPceCapability)
84 - && Objects.equals(pcInstantiationCapability, other.pcInstantiationCapability); 110 + && Objects.equals(pcInstantiationCapability, other.pcInstantiationCapability)
111 + && Objects.equals(labelStackCapability, other.labelStackCapability)
112 + && Objects.equals(srCapability, other.srCapability);
85 } 113 }
86 return false; 114 return false;
87 } 115 }
...@@ -92,6 +120,8 @@ public class ClientCapability { ...@@ -92,6 +120,8 @@ public class ClientCapability {
92 .add("pceccCapability", pceccCapability) 120 .add("pceccCapability", pceccCapability)
93 .add("statefulPceCapability", statefulPceCapability) 121 .add("statefulPceCapability", statefulPceCapability)
94 .add("pcInstantiationCapability", pcInstantiationCapability) 122 .add("pcInstantiationCapability", pcInstantiationCapability)
123 + .add("labelStackCapability", labelStackCapability)
124 + .add("srCapability", srCapability)
95 .toString(); 125 .toString();
96 } 126 }
97 } 127 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcep.controller;
17 +
18 +import java.util.Objects;
19 +
20 +import com.google.common.base.MoreObjects;
21 +
22 +/**
23 + * Representation of LSP info, it will be unique for each LSP.
24 + */
25 +public class LspKey {
26 + private int plspId;
27 + private short localLspId;
28 +
29 + /**
30 + * Creates new instance of LspInfo.
31 + *
32 + * @param plspId LSP id assigned per tunnel per session
33 + * @param localLspId LSP id assigned per tunnel
34 + */
35 + public LspKey(int plspId, short localLspId) {
36 + this.plspId = plspId;
37 + this.localLspId = localLspId;
38 + }
39 +
40 + /**
41 + * Obtains PLSP id.
42 + *
43 + * @return LSP id assigned per tunnel per session
44 + */
45 + public int plspId() {
46 + return plspId;
47 + }
48 +
49 + /**
50 + * Obtains local LSP id.
51 + *
52 + * @return LSP id assigned per tunnel
53 + */
54 + public short localLspId() {
55 + return localLspId;
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(plspId, localLspId);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 +
69 + if (obj instanceof LspKey) {
70 + LspKey other = (LspKey) obj;
71 + return Objects.equals(plspId, other.plspId)
72 + && Objects.equals(localLspId, other.localLspId);
73 + }
74 +
75 + return false;
76 + }
77 +
78 + @Override
79 + public String toString() {
80 + return MoreObjects.toStringHelper(getClass())
81 + .add("plspId", plspId)
82 + .add("localLspId", localLspId)
83 + .toString();
84 + }
85 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -19,6 +19,7 @@ import java.util.List; ...@@ -19,6 +19,7 @@ import java.util.List;
19 19
20 import org.onosproject.pcepio.protocol.PcepFactory; 20 import org.onosproject.pcepio.protocol.PcepFactory;
21 import org.onosproject.pcepio.protocol.PcepMessage; 21 import org.onosproject.pcepio.protocol.PcepMessage;
22 +import org.onosproject.pcepio.protocol.PcepStateReport;
22 23
23 /** 24 /**
24 * Represents to provider facing side of a path computation client(pcc). 25 * Represents to provider facing side of a path computation client(pcc).
...@@ -135,4 +136,64 @@ public interface PcepClient { ...@@ -135,4 +136,64 @@ public interface PcepClient {
135 * @return capability supported by client 136 * @return capability supported by client
136 */ 137 */
137 ClientCapability capability(); 138 ClientCapability capability();
139 +
140 + /**
141 + * Adds PCEP device when session is successfully established.
142 + *
143 + * @param pc PCEP client details
144 + */
145 + void addNode(PcepClient pc);
146 +
147 + /**
148 + * Removes PCEP device when session is disconnected.
149 + *
150 + * @param pccId PCEP client ID
151 + */
152 + void deleteNode(PccId pccId);
153 +
154 + /**
155 + * Sets D flag for the given LSP and its LSP info.
156 + *
157 + * @param lspKey contains LSP info
158 + * @param dFlag delegation flag in LSP object
159 + */
160 + void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag);
161 +
162 + /**
163 + * Returns delegation flag for the given LSP info.
164 + *
165 + * @param lspKey contains LSP info
166 + * @return delegation flag
167 + */
168 + Boolean delegationInfo(LspKey lspKey);
169 +
170 + /**
171 + * Creates a temporary cache to hold report messages received during LSPDB sync.
172 + *
173 + * @param pccId PCC id which is the key to store report messages
174 + */
175 + void initializeSyncMsgList(PccId pccId);
176 +
177 + /**
178 + * Returns the list of report messages received during LSPDB sync.
179 + *
180 + * @param pccId PCC id which is the key for all the report messages
181 + * @return list of report messages received during LSPDB sync
182 + */
183 + List<PcepStateReport> getSyncMsgList(PccId pccId);
184 +
185 + /**
186 + * Removes the list of report messages received during LSPDB sync.
187 + *
188 + * @param pccId PCC id which is the key for all the report messages
189 + */
190 + void removeSyncMsgList(PccId pccId);
191 +
192 + /**
193 + * Adds report message received during LSPDB sync into temporary cache.
194 + *
195 + * @param pccId PCC id which is the key to store report messages
196 + * @param rptMsg the report message to be stored
197 + */
198 + void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg);
138 } 199 }
......
...@@ -57,7 +57,7 @@ public interface PcepClientController { ...@@ -57,7 +57,7 @@ public interface PcepClientController {
57 void removeListener(PcepClientListener listener); 57 void removeListener(PcepClientListener listener);
58 58
59 /** 59 /**
60 - * Register a listener for OF msg events. 60 + * Register a listener for PCEP msg events.
61 * 61 *
62 * @param listener the listener to notify 62 * @param listener the listener to notify
63 */ 63 */
...@@ -71,6 +71,34 @@ public interface PcepClientController { ...@@ -71,6 +71,34 @@ public interface PcepClientController {
71 void removeEventListener(PcepEventListener listener); 71 void removeEventListener(PcepEventListener listener);
72 72
73 /** 73 /**
74 + * Register a listener for PCEP msg events[carrying node descriptor details].
75 + *
76 + * @param listener the listener to notify
77 + */
78 + void addNodeListener(PcepNodeListener listener);
79 +
80 + /**
81 + * Unregister a listener.
82 + *
83 + * @param listener the listener to be unregistered
84 + */
85 + void removeNodeListener(PcepNodeListener listener);
86 +
87 + /**
88 + * Register a listener for packet events.
89 + *
90 + * @param listener the listener to notify
91 + */
92 + void addPacketListener(PcepPacketListener listener);
93 +
94 + /**
95 + * Unregister a packet listener.
96 + *
97 + * @param listener the listener to unregister
98 + */
99 + void removePacketListener(PcepPacketListener listener);
100 +
101 + /**
74 * Send a message to a particular pcc client. 102 * Send a message to a particular pcc client.
75 * 103 *
76 * @param pccId the id of the client to send message. 104 * @param pccId the id of the client to send message.
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.pcep.controller; 16 package org.onosproject.pcep.controller;
17 17
18 +import org.onosproject.incubator.net.tunnel.Tunnel;
18 import org.onosproject.pcepio.protocol.PcepMessage; 19 import org.onosproject.pcepio.protocol.PcepMessage;
19 /** 20 /**
20 * Notifies providers about PCEP message events. 21 * Notifies providers about PCEP message events.
...@@ -28,4 +29,21 @@ public interface PcepEventListener { ...@@ -28,4 +29,21 @@ public interface PcepEventListener {
28 * @param msg the message 29 * @param msg the message
29 */ 30 */
30 void handleMessage(PccId pccId, PcepMessage msg); 31 void handleMessage(PccId pccId, PcepMessage msg);
32 +
33 + /**
34 + * Handles end of LSPDB sync actions.
35 + *
36 + * @param tunnel the tunnel on which action needs to be taken
37 + * @param endOfSyncAction the action that needs to be taken for the tunnel
38 + */
39 + void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction);
40 +
41 + /**
42 + * Handles sending PCEP message to client on end of LSPDB sync.
43 + *
44 + * @param pccId id of the pcc
45 + * @param msg the message to be sent
46 + * @param endOfSyncAction the action that needs to be taken in the message
47 + */
48 + void handleEndOfSyncAction(PccId pccId, PcepMessage msg, PcepLspSyncAction endOfSyncAction);
31 } 49 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcep.controller;
17 +
18 +/**
19 + * Representation of actions to be taken for LSPs on end of LSP-DB sync.
20 + */
21 +public enum PcepLspSyncAction {
22 +
23 + /**
24 + * Specifies that delete message for PCE intiiated tunnel should be sent.
25 + */
26 + SEND_DELETE(0),
27 +
28 + /**
29 + * Specifies that update message should be sent.
30 + */
31 + SEND_UPDATE(1),
32 +
33 + /**
34 + * Specifies that the tunnel should be removed from PCE.
35 + */
36 + REMOVE(2),
37 +
38 + /**
39 + * Specifies that the status of the tunnel should be set as unstable.
40 + */
41 + UNSTABLE(3);
42 +
43 + int value;
44 +
45 + /**
46 + * Assigns val with the value for actions to be taken for LSPs on end of LSP-DB sync.
47 + *
48 + * @param val sync status
49 + */
50 + PcepLspSyncAction(int val) {
51 + value = val;
52 + }
53 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcep.controller;
17 +
18 +/**
19 + * Notifies providers about PCEP node events.
20 + */
21 +public interface PcepNodeListener {
22 +
23 + /**
24 + * Notifies that the node was added.
25 + *
26 + * @param pc PCEP client details
27 + */
28 + void addNode(PcepClient pc);
29 +
30 + /**
31 + * Notifies that the node was removed.
32 + *
33 + * @param pccId PCEP client ID
34 + */
35 + void deleteNode(PccId pccId);
36 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcep.controller;
17 +
18 +public interface PcepPacketListener {
19 +
20 + void sendPacketIn(PccId pccId);
21 +
22 +}
...@@ -60,4 +60,25 @@ public interface PcepAgent { ...@@ -60,4 +60,25 @@ public interface PcepAgent {
60 */ 60 */
61 void processPcepMessage(PccId pccId, PcepMessage m); 61 void processPcepMessage(PccId pccId, PcepMessage m);
62 62
63 + /**
64 + * Adds PCEP device when session is successfully established.
65 + *
66 + * @param pc PCEP client details
67 + */
68 + void addNode(PcepClient pc);
69 +
70 + /**
71 + * Removes PCEP device when session is disconnected.
72 + *
73 + * @param pccId PCEP client ID
74 + */
75 + void deleteNode(PccId pccId);
76 +
77 + /**
78 + * Analyzes report messages received during LSP DB sync again tunnel store and takes necessary actions.
79 + *
80 + * @param pccId the id of pcc client
81 + * @return success or failure
82 + */
83 + boolean analyzeSyncMsgList(PccId pccId);
63 } 84 }
......
...@@ -2,6 +2,7 @@ COMPILE_DEPS = [ ...@@ -2,6 +2,7 @@ COMPILE_DEPS = [
2 '//lib:CORE_DEPS', 2 '//lib:CORE_DEPS',
3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', 3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
4 '//protocols/pcep/api:onos-protocols-pcep-api', 4 '//protocols/pcep/api:onos-protocols-pcep-api',
5 + '//incubator/api:onos-incubator-api',
5 ] 6 ]
6 7
7 osgi_jar_with_tests ( 8 osgi_jar_with_tests (
......
...@@ -55,6 +55,7 @@ import org.onosproject.pcepio.protocol.PcepVersion; ...@@ -55,6 +55,7 @@ import org.onosproject.pcepio.protocol.PcepVersion;
55 import org.onosproject.pcepio.types.IPv4RouterIdOfLocalNodeSubTlv; 55 import org.onosproject.pcepio.types.IPv4RouterIdOfLocalNodeSubTlv;
56 import org.onosproject.pcepio.types.NodeAttributesTlv; 56 import org.onosproject.pcepio.types.NodeAttributesTlv;
57 import org.onosproject.pcepio.types.PceccCapabilityTlv; 57 import org.onosproject.pcepio.types.PceccCapabilityTlv;
58 +import org.onosproject.pcepio.types.SrPceCapabilityTlv;
58 import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; 59 import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
59 import org.onosproject.pcepio.types.PcepErrorDetailInfo; 60 import org.onosproject.pcepio.types.PcepErrorDetailInfo;
60 import org.onosproject.pcepio.types.PcepValueType; 61 import org.onosproject.pcepio.types.PcepValueType;
...@@ -260,6 +261,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -260,6 +261,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
260 disconnectDuplicate(h); 261 disconnectDuplicate(h);
261 } else { 262 } else {
262 h.setState(ESTABLISHED); 263 h.setState(ESTABLISHED);
264 + //Session is established, add a PCEP device
265 + h.addNode();
263 } 266 }
264 } 267 }
265 } 268 }
...@@ -469,6 +472,20 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -469,6 +472,20 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
469 } 472 }
470 473
471 /** 474 /**
475 + * Adds PCEP device once session is established.
476 + */
477 + private void addNode() {
478 + pc.addNode(pc);
479 + }
480 +
481 + /**
482 + * Deletes PCEP device when session is disconnected.
483 + */
484 + private void deleteNode() {
485 + pc.deleteNode(pc.getPccId());
486 + }
487 +
488 + /**
472 * Return a string describing this client based on the already available 489 * Return a string describing this client based on the already available
473 * information (ip address and/or remote socket). 490 * information (ip address and/or remote socket).
474 * 491 *
...@@ -523,6 +540,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -523,6 +540,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
523 boolean pceccCapability = false; 540 boolean pceccCapability = false;
524 boolean statefulPceCapability = false; 541 boolean statefulPceCapability = false;
525 boolean pcInstantiationCapability = false; 542 boolean pcInstantiationCapability = false;
543 + boolean labelStackCapability = false;
544 + boolean srCapability = false;
526 545
527 ListIterator<PcepValueType> listIterator = tlvList.listIterator(); 546 ListIterator<PcepValueType> listIterator = tlvList.listIterator();
528 while (listIterator.hasNext()) { 547 while (listIterator.hasNext()) {
...@@ -531,6 +550,9 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -531,6 +550,9 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
531 switch (tlv.getType()) { 550 switch (tlv.getType()) {
532 case PceccCapabilityTlv.TYPE: 551 case PceccCapabilityTlv.TYPE:
533 pceccCapability = true; 552 pceccCapability = true;
553 + if (((PceccCapabilityTlv) tlv).sBit()) {
554 + labelStackCapability = true;
555 + }
534 break; 556 break;
535 case StatefulPceCapabilityTlv.TYPE: 557 case StatefulPceCapabilityTlv.TYPE:
536 statefulPceCapability = true; 558 statefulPceCapability = true;
...@@ -539,11 +561,15 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -539,11 +561,15 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
539 pcInstantiationCapability = true; 561 pcInstantiationCapability = true;
540 } 562 }
541 break; 563 break;
564 + case SrPceCapabilityTlv.TYPE:
565 + srCapability = true;
566 + break;
542 default: 567 default:
543 continue; 568 continue;
544 } 569 }
545 } 570 }
546 - this.capability = new ClientCapability(pceccCapability, statefulPceCapability, pcInstantiationCapability); 571 + this.capability = new ClientCapability(pceccCapability, statefulPceCapability, pcInstantiationCapability,
572 + labelStackCapability, srCapability);
547 } 573 }
548 574
549 /** 575 /**
...@@ -563,6 +589,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -563,6 +589,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
563 */ 589 */
564 private void sendErrMsgAndCloseChannel() { 590 private void sendErrMsgAndCloseChannel() {
565 // TODO send error message 591 // TODO send error message
592 + //Remove PCEP device from topology
593 + deleteNode();
566 channel.close(); 594 channel.close();
567 } 595 }
568 596
......
...@@ -15,34 +15,66 @@ ...@@ -15,34 +15,66 @@
15 */ 15 */
16 package org.onosproject.pcep.controller.impl; 16 package org.onosproject.pcep.controller.impl;
17 17
18 +import java.util.Arrays;
18 import java.util.Collection; 19 import java.util.Collection;
19 import java.util.Collections; 20 import java.util.Collections;
21 +import java.util.HashMap;
20 import java.util.HashSet; 22 import java.util.HashSet;
23 +import java.util.Iterator;
21 import java.util.LinkedList; 24 import java.util.LinkedList;
25 +import java.util.List;
26 +import java.util.ListIterator;
27 +import java.util.Map;
22 import java.util.Set; 28 import java.util.Set;
23 import java.util.concurrent.ConcurrentHashMap; 29 import java.util.concurrent.ConcurrentHashMap;
24 30
25 import org.apache.felix.scr.annotations.Activate; 31 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 32 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 33 import org.apache.felix.scr.annotations.Deactivate;
34 +import org.apache.felix.scr.annotations.Reference;
35 +import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.apache.felix.scr.annotations.Service; 36 import org.apache.felix.scr.annotations.Service;
37 +import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
38 +import org.onosproject.incubator.net.tunnel.Tunnel;
39 +import org.onosproject.incubator.net.tunnel.TunnelService;
40 +import org.onosproject.incubator.net.tunnel.Tunnel.State;
41 +import org.onosproject.net.device.DeviceService;
42 +import org.onosproject.pcep.controller.LspKey;
29 import org.onosproject.pcep.controller.PccId; 43 import org.onosproject.pcep.controller.PccId;
30 import org.onosproject.pcep.controller.PcepClient; 44 import org.onosproject.pcep.controller.PcepClient;
31 import org.onosproject.pcep.controller.PcepClientController; 45 import org.onosproject.pcep.controller.PcepClientController;
32 import org.onosproject.pcep.controller.PcepClientListener; 46 import org.onosproject.pcep.controller.PcepClientListener;
33 import org.onosproject.pcep.controller.PcepEventListener; 47 import org.onosproject.pcep.controller.PcepEventListener;
48 +import org.onosproject.pcep.controller.PcepNodeListener;
49 +import org.onosproject.pcep.controller.PcepPacketListener;
50 +import org.onosproject.pcep.controller.PcepSyncStatus;
34 import org.onosproject.pcep.controller.driver.PcepAgent; 51 import org.onosproject.pcep.controller.driver.PcepAgent;
52 +import org.onosproject.pcepio.exceptions.PcepParseException;
53 +import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
35 import org.onosproject.pcepio.protocol.PcepError; 54 import org.onosproject.pcepio.protocol.PcepError;
36 import org.onosproject.pcepio.protocol.PcepErrorInfo; 55 import org.onosproject.pcepio.protocol.PcepErrorInfo;
37 import org.onosproject.pcepio.protocol.PcepErrorMsg; 56 import org.onosproject.pcepio.protocol.PcepErrorMsg;
38 import org.onosproject.pcepio.protocol.PcepErrorObject; 57 import org.onosproject.pcepio.protocol.PcepErrorObject;
39 import org.onosproject.pcepio.protocol.PcepFactory; 58 import org.onosproject.pcepio.protocol.PcepFactory;
59 +import org.onosproject.pcepio.protocol.PcepInitiateMsg;
60 +import org.onosproject.pcepio.protocol.PcepLspObject;
40 import org.onosproject.pcepio.protocol.PcepMessage; 61 import org.onosproject.pcepio.protocol.PcepMessage;
62 +import org.onosproject.pcepio.protocol.PcepReportMsg;
63 +import org.onosproject.pcepio.protocol.PcepStateReport;
64 +import org.onosproject.pcepio.types.PcepValueType;
65 +import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
66 +import org.onosproject.pcepio.types.SymbolicPathNameTlv;
41 import org.slf4j.Logger; 67 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory; 68 import org.slf4j.LoggerFactory;
43 69
44 import com.google.common.collect.Sets; 70 import com.google.common.collect.Sets;
71 +import static com.google.common.base.Preconditions.checkNotNull;
45 72
73 +import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
74 +import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
75 +import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
76 +import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_DELETE;
77 +import static org.onosproject.pcep.controller.PcepLspSyncAction.UNSTABLE;
46 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19; 78 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
47 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5; 79 import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
48 80
...@@ -55,6 +87,9 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -55,6 +87,9 @@ public class PcepClientControllerImpl implements PcepClientController {
55 87
56 private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); 88 private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class);
57 89
90 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 + protected DeviceService deviceService;
92 +
58 protected ConcurrentHashMap<PccId, PcepClient> connectedClients = 93 protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
59 new ConcurrentHashMap<>(); 94 new ConcurrentHashMap<>();
60 95
...@@ -62,9 +97,23 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -62,9 +97,23 @@ public class PcepClientControllerImpl implements PcepClientController {
62 protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); 97 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
63 98
64 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); 99 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
100 + protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
101 + protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
65 102
66 private final Controller ctrl = new Controller(); 103 private final Controller ctrl = new Controller();
67 104
105 + public static final String BANDWIDTH = "bandwidth";
106 + public static final String LSP_SIG_TYPE = "lspSigType";
107 + public static final String PCC_TUNNEL_ID = "PccTunnelId";
108 + public static final String PLSP_ID = "PLspId";
109 + public static final String LOCAL_LSP_ID = "localLspId";
110 + public static final String PCE_INIT = "pceInit";
111 + public static final String COST_TYPE = "costType";
112 + public static final String DELEGATE = "delegation";
113 +
114 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
115 + protected TunnelService tunnelService;
116 +
68 @Activate 117 @Activate
69 public void activate() { 118 public void activate() {
70 ctrl.start(agent); 119 ctrl.start(agent);
...@@ -112,11 +161,31 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -112,11 +161,31 @@ public class PcepClientControllerImpl implements PcepClientController {
112 } 161 }
113 162
114 @Override 163 @Override
164 + public void addPacketListener(PcepPacketListener listener) {
165 + pcepPacketListener.add(listener);
166 + }
167 +
168 + @Override
169 + public void removePacketListener(PcepPacketListener listener) {
170 + pcepPacketListener.remove(listener);
171 + }
172 +
173 + @Override
115 public void writeMessage(PccId pccId, PcepMessage msg) { 174 public void writeMessage(PccId pccId, PcepMessage msg) {
116 this.getClient(pccId).sendMessage(msg); 175 this.getClient(pccId).sendMessage(msg);
117 } 176 }
118 177
119 @Override 178 @Override
179 + public void addNodeListener(PcepNodeListener listener) {
180 + pcepNodeListener.add(listener);
181 + }
182 +
183 + @Override
184 + public void removeNodeListener(PcepNodeListener listener) {
185 + pcepNodeListener.remove(listener);
186 + }
187 +
188 + @Override
120 public void processClientMessage(PccId pccId, PcepMessage msg) { 189 public void processClientMessage(PccId pccId, PcepMessage msg) {
121 PcepClient pc = getClient(pccId); 190 PcepClient pc = getClient(pccId);
122 191
...@@ -162,8 +231,48 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -162,8 +231,48 @@ public class PcepClientControllerImpl implements PcepClientController {
162 case REPORT: 231 case REPORT:
163 //Only update the listener if respective capability is supported else send PCEP-ERR msg 232 //Only update the listener if respective capability is supported else send PCEP-ERR msg
164 if (pc.capability().statefulPceCapability()) { 233 if (pc.capability().statefulPceCapability()) {
165 - for (PcepEventListener l : pcepEventListener) { 234 +
166 - l.handleMessage(pccId, msg); 235 + ListIterator<PcepStateReport> listIterator = ((PcepReportMsg) msg).getStateReportList().listIterator();
236 + while (listIterator.hasNext()) {
237 + PcepStateReport stateRpt = listIterator.next();
238 + if (stateRpt.getLspObject().getSFlag()) {
239 + if (pc.lspDbSyncStatus() != PcepSyncStatus.IN_SYNC) {
240 + // Initialize LSP DB sync and temporary cache.
241 + pc.setLspDbSyncStatus(PcepSyncStatus.IN_SYNC);
242 + pc.initializeSyncMsgList(pccId);
243 + }
244 + // Store stateRpt in temporary cache.
245 + pc.addSyncMsgToList(pccId, stateRpt);
246 +
247 + // Don't send to provider as of now.
248 + continue;
249 + } else {
250 + if (pc.lspDbSyncStatus() == PcepSyncStatus.IN_SYNC) {
251 + // Set end of LSPDB sync.
252 + pc.setLspDbSyncStatus(PcepSyncStatus.SYNCED);
253 +
254 + // Call packet provider to initiate label DB sync (only if PCECC capable).
255 + if (pc.capability().pceccCapability()) {
256 + pc.setLabelDbSyncStatus(IN_SYNC);
257 + for (PcepPacketListener l : pcepPacketListener) {
258 + l.sendPacketIn(pccId);
259 + }
260 + } else {
261 + // If label db sync is not to be done, handle end of LSPDB sync actions.
262 + agent.analyzeSyncMsgList(pccId);
263 + }
264 + continue;
265 + }
266 + }
267 +
268 + // It's a usual report message while sync is not undergoing. So process it immediately.
269 + LinkedList<PcepStateReport> llPcRptList = new LinkedList<>();
270 + llPcRptList.add(stateRpt);
271 + PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList))
272 + .build();
273 + for (PcepEventListener l : pcepEventListener) {
274 + l.handleMessage(pccId, pcReportMsg);
275 + }
167 } 276 }
168 } else { 277 } else {
169 // Send PCEP-ERROR message. 278 // Send PCEP-ERROR message.
...@@ -173,6 +282,8 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -173,6 +282,8 @@ public class PcepClientControllerImpl implements PcepClientController {
173 break; 282 break;
174 case LABEL_RANGE_RESERV: 283 case LABEL_RANGE_RESERV:
175 break; 284 break;
285 + case LS_REPORT: //TODO: need to handle LS report to add or remove node
286 + break;
176 case MAX: 287 case MAX:
177 break; 288 break;
178 case END: 289 case END:
...@@ -270,5 +381,176 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -270,5 +381,176 @@ public class PcepClientControllerImpl implements PcepClientController {
270 public void processPcepMessage(PccId pccId, PcepMessage m) { 381 public void processPcepMessage(PccId pccId, PcepMessage m) {
271 processClientMessage(pccId, m); 382 processClientMessage(pccId, m);
272 } 383 }
384 +
385 + @Override
386 + public void addNode(PcepClient pc) {
387 + for (PcepNodeListener l : pcepNodeListener) {
388 + l.addNode(pc);
389 + }
390 + }
391 +
392 + @Override
393 + public void deleteNode(PccId pccId) {
394 + for (PcepNodeListener l : pcepNodeListener) {
395 + l.deleteNode(pccId);
396 + }
397 + }
398 +
399 + @SuppressWarnings({ "unchecked", "rawtypes" })
400 + @Override
401 + public boolean analyzeSyncMsgList(PccId pccId) {
402 + PcepClient pc = getClient(pccId);
403 + /*
404 + * PLSP_ID is null while tunnel is created at PCE and PCInit msg carries it as 0. It is allocated by PCC and
405 + * in that case it becomes the first PCRpt msg from PCC for this LSP, and hence symbolic path name must be
406 + * carried in the PCRpt msg. Draft says: The SYMBOLIC-PATH-NAME TLV "MUST" be included in the LSP object in
407 + * the LSP State Report (PCRpt) message when during a given PCEP session an LSP is "first" reported to a
408 + * PCE. So two separate lists with separate keys are maintained.
409 + */
410 + Map<LspKey, Tunnel> preSyncLspDbByKey = new HashMap<>();
411 + Map<String, Tunnel> preSyncLspDbByName = new HashMap<>();
412 +
413 + // Query tunnel service and fetch all the tunnels with this PCC as ingress.
414 + // Organize into two maps, with LSP key if known otherwise with symbolic path name, for quick search.
415 + Collection<Tunnel> queriedTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS);
416 + for (Tunnel tunnel : queriedTunnels) {
417 + if (((IpTunnelEndPoint) tunnel.src()).ip().equals(pccId.ipAddress())) {
418 + String pLspId = tunnel.annotations().value(PLSP_ID);
419 + if (pLspId != null) {
420 + String localLspId = tunnel.annotations().value(LOCAL_LSP_ID);
421 + checkNotNull(localLspId);
422 + LspKey lspKey = new LspKey(Integer.valueOf(pLspId), Short.valueOf(localLspId));
423 + preSyncLspDbByKey.put(lspKey, tunnel);
424 + } else {
425 + preSyncLspDbByName.put(tunnel.tunnelName().value(), tunnel);
426 + }
427 + }
428 + }
429 +
430 + List<PcepStateReport> syncStateRptList = pc.getSyncMsgList(pccId);
431 + Iterator<PcepStateReport> stateRptListIterator = syncStateRptList.iterator();
432 +
433 + // For every report, fetch PLSP id, local LSP id and symbolic path name from the message.
434 + while (syncStateRptList.iterator().hasNext()) {
435 + PcepStateReport stateRpt = stateRptListIterator.next();
436 + Tunnel tunnel = null;
437 +
438 + PcepLspObject lspObj = stateRpt.getLspObject();
439 + ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
440 + StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv = null;
441 + SymbolicPathNameTlv pathNameTlv = null;
442 +
443 + while (listTlvIterator.hasNext()) {
444 + PcepValueType tlv = listTlvIterator.next();
445 + switch (tlv.getType()) {
446 + case StatefulIPv4LspIdentifiersTlv.TYPE:
447 + ipv4LspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
448 + break;
449 +
450 + case SymbolicPathNameTlv.TYPE:
451 + pathNameTlv = (SymbolicPathNameTlv) tlv;
452 + break;
453 +
454 + default:
455 + break;
456 + }
457 + }
458 +
459 + LspKey lspKeyOfRpt = new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId());
460 + tunnel = preSyncLspDbByKey.get(lspKeyOfRpt);
461 + // PCE tunnel is matched with PCRpt LSP. Now delete it from the preSyncLspDb list as the residual
462 + // non-matching list will be processed at the end.
463 + if (tunnel != null) {
464 + preSyncLspDbByKey.remove(lspKeyOfRpt);
465 + } else if (pathNameTlv != null) {
466 + tunnel = preSyncLspDbByName.get(Arrays.toString(pathNameTlv.getValue()));
467 + if (tunnel != null) {
468 + preSyncLspDbByName.remove(tunnel.tunnelName());
469 + }
470 + }
471 +
472 + if (tunnel == null) {
473 + // If remove flag is set, and tunnel is not known to PCE, ignore it.
474 + if (lspObj.getCFlag() && !lspObj.getRFlag()) {
475 + // For initiated LSP, need to send PCInit delete msg.
476 + try {
477 + PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest()
478 + .setLspObject(lspObj).build();
479 + LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList
480 + = new LinkedList<PcInitiatedLspRequest>();
481 + llPcInitiatedLspRequestList.add(releaseLspRequest);
482 +
483 + PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
484 + .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
485 +
486 + for (PcepEventListener l : pcepEventListener) {
487 + l.handleEndOfSyncAction(pccId, pcInitiateMsg, SEND_DELETE);
488 + }
489 +
490 + } catch (PcepParseException e) {
491 + log.error("Exception occured while sending initiate delete message {}", e.getMessage());
492 + }
493 + }
494 + continue;
495 + }
496 +
497 + if (!lspObj.getCFlag()) {
498 + // For learned LSP process both add/update PCRpt.
499 + LinkedList<PcepStateReport> llPcRptList = new LinkedList<>();
500 + llPcRptList.add(stateRpt);
501 + PcepMessage pcReportMsg = pc.factory().buildReportMsg().setStateReportList((llPcRptList))
502 + .build();
503 +
504 + for (PcepEventListener l : pcepEventListener) {
505 + l.handleMessage(pccId, pcReportMsg);
506 + }
507 + continue;
508 + }
509 +
510 + // Implied that tunnel != null and lspObj.getCFlag() is set
511 + // State different for PCC sent LSP and PCE known LSP, send PCUpd msg.
512 + State tunnelState = PcepLspStatus
513 + .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
514 + if (tunnelState != tunnel.state()) {
515 + for (PcepEventListener l : pcepEventListener) {
516 + l.handleEndOfSyncAction(tunnel, SEND_UPDATE);
517 + }
518 + }
519 + }
520 +
521 + // Check which tunnels are extra at PCE that were not reported by PCC.
522 + Map<Object, Tunnel> preSyncLspDb = (Map) preSyncLspDbByKey;
523 + handleResidualTunnels(preSyncLspDb);
524 + preSyncLspDbByKey = null;
525 +
526 + preSyncLspDb = (Map) preSyncLspDbByName;
527 + handleResidualTunnels(preSyncLspDb);
528 + preSyncLspDbByName = null;
529 + preSyncLspDb = null;
530 +
531 + pc.removeSyncMsgList(pccId);
532 + return true;
533 + }
534 +
535 + /*
536 + * Go through the tunnels which are known by PCE but were not reported by PCC during LSP DB sync and take
537 + * appropriate actions.
538 + */
539 + private void handleResidualTunnels(Map<Object, Tunnel> preSyncLspDb) {
540 + for (Tunnel pceExtraTunnel : preSyncLspDb.values()) {
541 + if (pceExtraTunnel.annotations().value(PCE_INIT) == null
542 + || "false".equalsIgnoreCase(pceExtraTunnel.annotations().value(PCE_INIT))) {
543 + // PCC initiated tunnels should be removed from tunnel store.
544 + for (PcepEventListener l : pcepEventListener) {
545 + l.handleEndOfSyncAction(pceExtraTunnel, REMOVE);
546 + }
547 + } else {
548 + // PCE initiated tunnels should be initiated again.
549 + for (PcepEventListener l : pcepEventListener) {
550 + l.handleEndOfSyncAction(pceExtraTunnel, UNSTABLE);
551 + }
552 + }
553 + }
554 + }
273 } 555 }
274 } 556 }
......
...@@ -19,13 +19,18 @@ package org.onosproject.pcep.controller.impl; ...@@ -19,13 +19,18 @@ package org.onosproject.pcep.controller.impl;
19 import java.net.InetSocketAddress; 19 import java.net.InetSocketAddress;
20 import java.net.SocketAddress; 20 import java.net.SocketAddress;
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.HashMap;
23 +import java.util.LinkedList;
22 import java.util.List; 24 import java.util.List;
25 +import java.util.Map;
23 import java.util.concurrent.RejectedExecutionException; 26 import java.util.concurrent.RejectedExecutionException;
24 27
25 import org.jboss.netty.channel.Channel; 28 import org.jboss.netty.channel.Channel;
26 import org.onlab.packet.IpAddress; 29 import org.onlab.packet.IpAddress;
27 import org.onosproject.pcep.controller.ClientCapability; 30 import org.onosproject.pcep.controller.ClientCapability;
31 +import org.onosproject.pcep.controller.LspKey;
28 import org.onosproject.pcep.controller.PccId; 32 import org.onosproject.pcep.controller.PccId;
33 +import org.onosproject.pcep.controller.PcepClient;
29 import org.onosproject.pcep.controller.PcepPacketStats; 34 import org.onosproject.pcep.controller.PcepPacketStats;
30 import org.onosproject.pcep.controller.PcepSyncStatus; 35 import org.onosproject.pcep.controller.PcepSyncStatus;
31 import org.onosproject.pcep.controller.driver.PcepAgent; 36 import org.onosproject.pcep.controller.driver.PcepAgent;
...@@ -33,6 +38,7 @@ import org.onosproject.pcep.controller.driver.PcepClientDriver; ...@@ -33,6 +38,7 @@ import org.onosproject.pcep.controller.driver.PcepClientDriver;
33 import org.onosproject.pcepio.protocol.PcepFactories; 38 import org.onosproject.pcepio.protocol.PcepFactories;
34 import org.onosproject.pcepio.protocol.PcepFactory; 39 import org.onosproject.pcepio.protocol.PcepFactory;
35 import org.onosproject.pcepio.protocol.PcepMessage; 40 import org.onosproject.pcepio.protocol.PcepMessage;
41 +import org.onosproject.pcepio.protocol.PcepStateReport;
36 import org.onosproject.pcepio.protocol.PcepVersion; 42 import org.onosproject.pcepio.protocol.PcepVersion;
37 import org.slf4j.Logger; 43 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory; 44 import org.slf4j.LoggerFactory;
...@@ -66,6 +72,8 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -66,6 +72,8 @@ public class PcepClientImpl implements PcepClientDriver {
66 private byte deadTime; 72 private byte deadTime;
67 private byte sessionId; 73 private byte sessionId;
68 private PcepPacketStatsImpl pktStats; 74 private PcepPacketStatsImpl pktStats;
75 + private Map<LspKey, Boolean> lspDelegationInfo;
76 + private Map<PccId, List<PcepStateReport>> sycRptCache = new HashMap<>();
69 77
70 @Override 78 @Override
71 public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) { 79 public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) {
...@@ -188,7 +196,14 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -188,7 +196,14 @@ public class PcepClientImpl implements PcepClientDriver {
188 196
189 @Override 197 @Override
190 public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) { 198 public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) {
199 +
200 + PcepSyncStatus syncOldStatus = labelDbSyncStatus();
191 this.labelDbSyncStatus = syncStatus; 201 this.labelDbSyncStatus = syncStatus;
202 +
203 + if ((syncOldStatus == PcepSyncStatus.IN_SYNC) && (syncStatus == PcepSyncStatus.SYNCED)) {
204 + // Perform end of LSP DB sync actions.
205 + this.agent.analyzeSyncMsgList(pccId);
206 + }
192 } 207 }
193 208
194 @Override 209 @Override
...@@ -203,6 +218,16 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -203,6 +218,16 @@ public class PcepClientImpl implements PcepClientDriver {
203 } 218 }
204 219
205 @Override 220 @Override
221 + public void addNode(PcepClient pc) {
222 + this.agent.addNode(pc);
223 + }
224 +
225 + @Override
226 + public void deleteNode(PccId pccId) {
227 + this.agent.deleteNode(pccId);
228 + }
229 +
230 + @Override
206 public final boolean connectClient() { 231 public final boolean connectClient() {
207 return this.agent.addConnectedClient(pccId, this); 232 return this.agent.addConnectedClient(pccId, this);
208 } 233 }
...@@ -230,6 +255,39 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -230,6 +255,39 @@ public class PcepClientImpl implements PcepClientDriver {
230 } 255 }
231 256
232 @Override 257 @Override
258 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
259 + lspDelegationInfo.put(lspKey, dFlag);
260 + }
261 +
262 + @Override
263 + public Boolean delegationInfo(LspKey lspKey) {
264 + return lspDelegationInfo.get(lspKey);
265 + }
266 +
267 + @Override
268 + public void initializeSyncMsgList(PccId pccId) {
269 + List<PcepStateReport> rptMsgList = new LinkedList<>();
270 + sycRptCache.put(pccId, rptMsgList);
271 + }
272 +
273 + @Override
274 + public List<PcepStateReport> getSyncMsgList(PccId pccId) {
275 + return sycRptCache.get(pccId);
276 + }
277 +
278 + @Override
279 + public void removeSyncMsgList(PccId pccId) {
280 + sycRptCache.remove(pccId);
281 + }
282 +
283 + @Override
284 + public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
285 + List<PcepStateReport> rptMsgList = sycRptCache.get(pccId);
286 + rptMsgList.add(rptMsg);
287 + sycRptCache.put(pccId, rptMsgList);
288 + }
289 +
290 + @Override
233 public boolean isOptical() { 291 public boolean isOptical() {
234 return false; 292 return false;
235 } 293 }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.pcep.tunnel.impl; 16 +package org.onosproject.pcep.controller.impl;
17 17
18 import org.onosproject.incubator.net.tunnel.Tunnel.State; 18 import org.onosproject.incubator.net.tunnel.Tunnel.State;
19 19
...@@ -51,6 +51,7 @@ public enum PcepLspStatus { ...@@ -51,6 +51,7 @@ public enum PcepLspStatus {
51 * Returns the applicable PCEP LSP status corresponding to ONOS tunnel state. 51 * Returns the applicable PCEP LSP status corresponding to ONOS tunnel state.
52 * 52 *
53 * @param tunnelState ONOS tunnel state 53 * @param tunnelState ONOS tunnel state
54 + * @return LSP status as per protocol
54 */ 55 */
55 public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) { 56 public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) {
56 57
...@@ -76,6 +77,7 @@ public enum PcepLspStatus { ...@@ -76,6 +77,7 @@ public enum PcepLspStatus {
76 * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status. 77 * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status.
77 * 78 *
78 * @param lspState PCEP LSP status 79 * @param lspState PCEP LSP status
80 + * @return tunnel state
79 */ 81 */
80 public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) { 82 public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) {
81 83
......
...@@ -29,14 +29,14 @@ public interface PcepBandwidthObject { ...@@ -29,14 +29,14 @@ public interface PcepBandwidthObject {
29 * 29 *
30 * @return bandwidth value 30 * @return bandwidth value
31 */ 31 */
32 - int getBandwidth(); 32 + float getBandwidth();
33 33
34 /** 34 /**
35 * Sets bandwidth with specified value. 35 * Sets bandwidth with specified value.
36 * 36 *
37 * @param iBandwidth Bandwidth's value 37 * @param iBandwidth Bandwidth's value
38 */ 38 */
39 - void setBandwidth(int iBandwidth); 39 + void setBandwidth(float iBandwidth);
40 40
41 /** 41 /**
42 * Writes the BandwidthObject into channel buffer. 42 * Writes the BandwidthObject into channel buffer.
......
...@@ -51,6 +51,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -51,6 +51,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
51 public static final byte BANDWIDTH_OBJ_TYPE = 1; 51 public static final byte BANDWIDTH_OBJ_TYPE = 1;
52 public static final byte BANDWIDTH_OBJ_CLASS = 5; 52 public static final byte BANDWIDTH_OBJ_CLASS = 5;
53 public static final byte BANDWIDTH_OBJECT_VERSION = 1; 53 public static final byte BANDWIDTH_OBJECT_VERSION = 1;
54 + public static final int NO_OF_BITS = 8;
54 public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8; 55 public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8;
55 56
56 static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS, 57 static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS,
...@@ -58,7 +59,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -58,7 +59,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
58 BANDWIDTH_OBJ_MINIMUM_LENGTH); 59 BANDWIDTH_OBJ_MINIMUM_LENGTH);
59 60
60 private PcepObjectHeader bandwidthObjHeader; 61 private PcepObjectHeader bandwidthObjHeader;
61 - private int iBandwidth; 62 + private float iBandwidth;
62 63
63 /** 64 /**
64 * Constructor to bandwidth object header and bandwidth. 65 * Constructor to bandwidth object header and bandwidth.
...@@ -66,7 +67,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -66,7 +67,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
66 * @param bandwidthObjHeader bandwidth object header 67 * @param bandwidthObjHeader bandwidth object header
67 * @param iBandwidth bandwidth value 68 * @param iBandwidth bandwidth value
68 */ 69 */
69 - public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) { 70 + public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, float iBandwidth) {
70 this.bandwidthObjHeader = bandwidthObjHeader; 71 this.bandwidthObjHeader = bandwidthObjHeader;
71 this.iBandwidth = iBandwidth; 72 this.iBandwidth = iBandwidth;
72 } 73 }
...@@ -76,7 +77,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -76,7 +77,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
76 * 77 *
77 * @param iBandwidth bandwidth value 78 * @param iBandwidth bandwidth value
78 */ 79 */
79 - public PcepBandwidthObjectVer1(int iBandwidth) { 80 + public PcepBandwidthObjectVer1(float iBandwidth) {
80 this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER; 81 this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER;
81 this.iBandwidth = iBandwidth; 82 this.iBandwidth = iBandwidth;
82 } 83 }
...@@ -100,12 +101,12 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -100,12 +101,12 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
100 } 101 }
101 102
102 @Override 103 @Override
103 - public int getBandwidth() { 104 + public float getBandwidth() {
104 return this.iBandwidth; 105 return this.iBandwidth;
105 } 106 }
106 107
107 @Override 108 @Override
108 - public void setBandwidth(int iBandwidth) { 109 + public void setBandwidth(float iBandwidth) {
109 this.iBandwidth = iBandwidth; 110 this.iBandwidth = iBandwidth;
110 } 111 }
111 112
...@@ -119,12 +120,25 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -119,12 +120,25 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
119 public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException { 120 public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException {
120 121
121 PcepObjectHeader bandwidthObjHeader; 122 PcepObjectHeader bandwidthObjHeader;
122 - int iBandwidth; 123 + float bandwidth;
123 124
124 bandwidthObjHeader = PcepObjectHeader.read(cb); 125 bandwidthObjHeader = PcepObjectHeader.read(cb);
125 - iBandwidth = cb.readInt(); 126 + bandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
126 127
127 - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); 128 + return new PcepBandwidthObjectVer1(bandwidthObjHeader, bandwidth);
129 + }
130 +
131 + /**
132 + * Parse the IEEE floating point notation and returns it in normal float.
133 + *
134 + * @param iVal IEEE floating point number
135 + * @return normal float
136 + */
137 + public static float ieeeToFloatRead(int iVal) {
138 + iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
139 + | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
140 +
141 + return Float.intBitsToFloat(iVal);
128 } 142 }
129 143
130 @Override 144 @Override
...@@ -138,7 +152,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -138,7 +152,7 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
138 throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex); 152 throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex);
139 } 153 }
140 154
141 - cb.writeInt(iBandwidth); 155 + cb.writeInt(Float.floatToIntBits(iBandwidth));
142 short hLength = (short) (cb.writerIndex() - objStartIndex); 156 short hLength = (short) (cb.writerIndex() - objStartIndex);
143 cb.setShort(objLenIndex, hLength); 157 cb.setShort(objLenIndex, hLength);
144 //will be helpful during print(). 158 //will be helpful during print().
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
16 16
17 package org.onosproject.pcepio.protocol.ver1; 17 package org.onosproject.pcepio.protocol.ver1;
18 18
19 +import java.util.Iterator;
19 import java.util.LinkedList; 20 import java.util.LinkedList;
20 import java.util.ListIterator; 21 import java.util.ListIterator;
22 +import java.util.Objects;
21 23
22 import org.jboss.netty.buffer.ChannelBuffer; 24 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.onosproject.pcepio.exceptions.PcepParseException; 25 import org.onosproject.pcepio.exceptions.PcepParseException;
...@@ -399,10 +401,47 @@ public class PcepEroObjectVer1 implements PcepEroObject { ...@@ -399,10 +401,47 @@ public class PcepEroObjectVer1 implements PcepEroObject {
399 } 401 }
400 402
401 @Override 403 @Override
404 + public int hashCode() {
405 + return Objects.hash(eroObjHeader, subObjectList);
406 + }
407 +
408 + @Override
402 public String toString() { 409 public String toString() {
403 return MoreObjects.toStringHelper(getClass()).omitNullValues() 410 return MoreObjects.toStringHelper(getClass()).omitNullValues()
404 .add("EroObjHeader", eroObjHeader) 411 .add("EroObjHeader", eroObjHeader)
405 .add("SubObjects", subObjectList) 412 .add("SubObjects", subObjectList)
406 .toString(); 413 .toString();
407 } 414 }
415 +
416 + @Override
417 + public boolean equals(Object obj) {
418 + if (this == obj) {
419 + return true;
420 + }
421 +
422 + if (obj instanceof PcepEroObjectVer1) {
423 + int countObjSubTlv = 0;
424 + int countOtherSubTlv = 0;
425 + boolean isCommonSubTlv = true;
426 + PcepEroObjectVer1 other = (PcepEroObjectVer1) obj;
427 + Iterator<PcepValueType> objListIterator = other.subObjectList.iterator();
428 + countOtherSubTlv = other.subObjectList.size();
429 + countObjSubTlv = subObjectList.size();
430 + if (countObjSubTlv != countOtherSubTlv) {
431 + return false;
432 + } else {
433 + while (objListIterator.hasNext() && isCommonSubTlv) {
434 + PcepValueType subTlv = objListIterator.next();
435 + if (subObjectList.contains(subTlv)) {
436 + isCommonSubTlv = Objects.equals(subObjectList.get(subObjectList.indexOf(subTlv)),
437 + other.subObjectList.get(other.subObjectList.indexOf(subTlv)));
438 + } else {
439 + isCommonSubTlv = false;
440 + }
441 + }
442 + return isCommonSubTlv && Objects.equals(eroObjHeader, other.eroObjHeader);
443 + }
444 + }
445 + return false;
446 + }
408 } 447 }
......
...@@ -57,6 +57,10 @@ public class PcepMetricObjectVer1 implements PcepMetricObject { ...@@ -57,6 +57,10 @@ public class PcepMetricObjectVer1 implements PcepMetricObject {
57 public static final int BFLAG_RESET = 0; 57 public static final int BFLAG_RESET = 0;
58 public static final byte CFLAG_CHECK = 0x02; 58 public static final byte CFLAG_CHECK = 0x02;
59 59
60 + public static final byte IGP_METRIC = 0x01;
61 + public static final byte TE_METRIC = 0x02;
62 + public static final byte HOP_COUNT_METRIC = 0x03;
63 +
60 static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS, 64 static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS,
61 METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, 65 METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
62 METRIC_OBJ_MINIMUM_LENGTH); 66 METRIC_OBJ_MINIMUM_LENGTH);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.pcepio.types; 17 package org.onosproject.pcepio.types;
18 18
19 +import java.util.Objects;
20 +
19 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.slf4j.Logger; 22 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
...@@ -212,6 +214,27 @@ public class PcepObjectHeader { ...@@ -212,6 +214,27 @@ public class PcepObjectHeader {
212 } 214 }
213 215
214 @Override 216 @Override
217 + public int hashCode() {
218 + return Objects.hash(objClass, objType, bPFlag, bIFlag, objLen);
219 + }
220 +
221 + @Override
222 + public boolean equals(Object obj) {
223 + if (this == obj) {
224 + return true;
225 + }
226 + if (obj instanceof PcepObjectHeader) {
227 + PcepObjectHeader other = (PcepObjectHeader) obj;
228 + return Objects.equals(objClass, other.objClass)
229 + && Objects.equals(objType, other.objType)
230 + && Objects.equals(bPFlag, other.bPFlag)
231 + && Objects.equals(bIFlag, other.bIFlag)
232 + && Objects.equals(objLen, other.objLen);
233 + }
234 + return false;
235 + }
236 +
237 + @Override
215 public String toString() { 238 public String toString() {
216 return MoreObjects.toStringHelper(getClass()) 239 return MoreObjects.toStringHelper(getClass())
217 .add("ObjectClass", objClass) 240 .add("ObjectClass", objClass)
......
...@@ -40,6 +40,11 @@ ...@@ -40,6 +40,11 @@
40 </dependency> 40 </dependency>
41 <dependency> 41 <dependency>
42 <groupId>org.onosproject</groupId> 42 <groupId>org.onosproject</groupId>
43 + <artifactId>onos-incubator-api</artifactId>
44 + <version>${project.version}</version>
45 + </dependency>
46 + <dependency>
47 + <groupId>org.onosproject</groupId>
43 <artifactId>onos-api</artifactId> 48 <artifactId>onos-api</artifactId>
44 <classifier>tests</classifier> 49 <classifier>tests</classifier>
45 <scope>test</scope> 50 <scope>test</scope>
......
...@@ -3,6 +3,7 @@ COMPILE_DEPS = [ ...@@ -3,6 +3,7 @@ COMPILE_DEPS = [
3 '//protocols/bgp/api:onos-protocols-bgp-api', 3 '//protocols/bgp/api:onos-protocols-bgp-api',
4 '//protocols/bgp/bgpio:onos-protocols-bgp-bgpio', 4 '//protocols/bgp/bgpio:onos-protocols-bgp-bgpio',
5 '//incubator/store:onos-incubator-store', 5 '//incubator/store:onos-incubator-store',
6 + '//incubator/api:onos-incubator-api',
6 ] 7 ]
7 8
8 TEST_DEPS = [ 9 TEST_DEPS = [
......
...@@ -17,11 +17,16 @@ import static org.onosproject.bgp.controller.BgpDpid.uri; ...@@ -17,11 +17,16 @@ import static org.onosproject.bgp.controller.BgpDpid.uri;
17 import static org.onosproject.net.DeviceId.deviceId; 17 import static org.onosproject.net.DeviceId.deviceId;
18 import static org.onosproject.net.Device.Type.ROUTER; 18 import static org.onosproject.net.Device.Type.ROUTER;
19 import static org.onosproject.net.Device.Type.VIRTUAL; 19 import static org.onosproject.net.Device.Type.VIRTUAL;
20 +import static org.onosproject.incubator.net.resource.label.LabelResourceId.labelResourceId;
21 +import static java.util.stream.Collectors.toList;
20 22
23 +import java.util.LinkedList;
21 import java.util.List; 24 import java.util.List;
22 import java.util.Set; 25 import java.util.Set;
23 26
24 import org.onlab.packet.ChassisId; 27 import org.onlab.packet.ChassisId;
28 +import org.onlab.packet.Ip4Address;
29 +import org.onlab.util.Bandwidth;
25 import org.apache.felix.scr.annotations.Activate; 30 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 31 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 32 import org.apache.felix.scr.annotations.Deactivate;
...@@ -45,9 +50,21 @@ import org.onosproject.bgpio.types.IPv4AddressTlv; ...@@ -45,9 +50,21 @@ import org.onosproject.bgpio.types.IPv4AddressTlv;
45 import org.onosproject.bgpio.types.IsIsNonPseudonode; 50 import org.onosproject.bgpio.types.IsIsNonPseudonode;
46 import org.onosproject.bgpio.types.IsIsPseudonode; 51 import org.onosproject.bgpio.types.IsIsPseudonode;
47 import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; 52 import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
53 +import org.onosproject.bgpio.types.LinkStateAttributes;
48 import org.onosproject.bgpio.types.OspfNonPseudonode; 54 import org.onosproject.bgpio.types.OspfNonPseudonode;
49 import org.onosproject.bgpio.types.OspfPseudonode; 55 import org.onosproject.bgpio.types.OspfPseudonode;
56 +import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv;
57 +import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId;
58 +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
59 +import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric;
60 +import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth;
61 +import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
50 import org.onosproject.core.CoreService; 62 import org.onosproject.core.CoreService;
63 +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
64 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
65 +import org.onosproject.mastership.MastershipEvent;
66 +import org.onosproject.mastership.MastershipListener;
67 +import org.onosproject.mastership.MastershipService;
51 import org.onosproject.net.AnnotationKeys; 68 import org.onosproject.net.AnnotationKeys;
52 import org.onosproject.net.ConnectPoint; 69 import org.onosproject.net.ConnectPoint;
53 import org.onosproject.net.DefaultAnnotations; 70 import org.onosproject.net.DefaultAnnotations;
...@@ -56,12 +73,15 @@ import org.onosproject.net.DeviceId; ...@@ -56,12 +73,15 @@ import org.onosproject.net.DeviceId;
56 import org.onosproject.net.Link; 73 import org.onosproject.net.Link;
57 import org.onosproject.net.MastershipRole; 74 import org.onosproject.net.MastershipRole;
58 import org.onosproject.net.PortNumber; 75 import org.onosproject.net.PortNumber;
76 +import org.onosproject.net.config.NetworkConfigService;
59 import org.onosproject.net.device.DefaultDeviceDescription; 77 import org.onosproject.net.device.DefaultDeviceDescription;
78 +import org.onosproject.net.device.DefaultPortDescription;
60 import org.onosproject.net.device.DeviceDescription; 79 import org.onosproject.net.device.DeviceDescription;
61 import org.onosproject.net.device.DeviceProvider; 80 import org.onosproject.net.device.DeviceProvider;
62 import org.onosproject.net.device.DeviceProviderRegistry; 81 import org.onosproject.net.device.DeviceProviderRegistry;
63 import org.onosproject.net.device.DeviceProviderService; 82 import org.onosproject.net.device.DeviceProviderService;
64 import org.onosproject.net.device.DeviceService; 83 import org.onosproject.net.device.DeviceService;
84 +import org.onosproject.net.device.PortDescription;
65 import org.onosproject.net.link.DefaultLinkDescription; 85 import org.onosproject.net.link.DefaultLinkDescription;
66 import org.onosproject.net.link.LinkDescription; 86 import org.onosproject.net.link.LinkDescription;
67 import org.onosproject.net.link.LinkProvider; 87 import org.onosproject.net.link.LinkProvider;
...@@ -70,6 +90,7 @@ import org.onosproject.net.link.LinkProviderService; ...@@ -70,6 +90,7 @@ import org.onosproject.net.link.LinkProviderService;
70 import org.onosproject.net.link.LinkService; 90 import org.onosproject.net.link.LinkService;
71 import org.onosproject.net.provider.AbstractProvider; 91 import org.onosproject.net.provider.AbstractProvider;
72 import org.onosproject.net.provider.ProviderId; 92 import org.onosproject.net.provider.ProviderId;
93 +import org.onosproject.net.config.basics.BandwidthCapacity;
73 import org.slf4j.Logger; 94 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory; 95 import org.slf4j.LoggerFactory;
75 96
...@@ -106,16 +127,39 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -106,16 +127,39 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 127 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected CoreService coreService; 128 protected CoreService coreService;
108 129
130 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
131 + protected MastershipService mastershipService;
132 +
133 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
134 + protected LabelResourceAdminService labelResourceAdminService;
135 +
136 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
137 + protected NetworkConfigService networkConfigService;
138 +
109 private DeviceProviderService deviceProviderService; 139 private DeviceProviderService deviceProviderService;
110 private LinkProviderService linkProviderService; 140 private LinkProviderService linkProviderService;
111 141
142 + private InternalMastershipListener masterListener = new InternalMastershipListener();
112 private InternalBgpProvider listener = new InternalBgpProvider(); 143 private InternalBgpProvider listener = new InternalBgpProvider();
113 private static final String UNKNOWN = "unknown"; 144 private static final String UNKNOWN = "unknown";
114 public static final long IDENTIFIER_SET = 0x100000000L; 145 public static final long IDENTIFIER_SET = 0x100000000L;
115 public static final String AS_NUMBER = "asNumber"; 146 public static final String AS_NUMBER = "asNumber";
116 public static final String DOMAIN_IDENTIFIER = "domainIdentifier"; 147 public static final String DOMAIN_IDENTIFIER = "domainIdentifier";
117 public static final String ROUTING_UNIVERSE = "routingUniverse"; 148 public static final String ROUTING_UNIVERSE = "routingUniverse";
149 +
150 + public static final String EXTERNAL_BIT = "externalBit";
151 + public static final String ABR_BIT = "abrBit";
152 + public static final String INTERNAL_BIT = "internalBit";
153 + public static final String PSEUDO = "psuedo";
154 + public static final String AREAID = "areaId";
155 + public static final String LSRID = "lsrId";
156 + public static final String COST = "cost";
157 + public static final String TE_COST = "teCost";
158 +
118 public static final long PSEUDO_PORT = 0xffffffff; 159 public static final long PSEUDO_PORT = 0xffffffff;
160 + public static final int DELAY = 2;
161 + private LabelResourceId beginLabel = labelResourceId(5122);
162 + private LabelResourceId endLabel = labelResourceId(9217);
119 163
120 @Activate 164 @Activate
121 public void activate() { 165 public void activate() {
...@@ -123,6 +167,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -123,6 +167,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
123 deviceProviderService = deviceProviderRegistry.register(this); 167 deviceProviderService = deviceProviderRegistry.register(this);
124 linkProviderService = linkProviderRegistry.register(this); 168 linkProviderService = linkProviderRegistry.register(this);
125 controller.addListener(listener); 169 controller.addListener(listener);
170 + mastershipService.addListener(masterListener);
126 controller.addLinkListener(listener); 171 controller.addLinkListener(listener);
127 } 172 }
128 173
...@@ -135,6 +180,27 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -135,6 +180,27 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
135 linkProviderService = null; 180 linkProviderService = null;
136 controller.removeListener(listener); 181 controller.removeListener(listener);
137 controller.removeLinkListener(listener); 182 controller.removeLinkListener(listener);
183 + mastershipService.removeListener(masterListener);
184 + }
185 +
186 + private class InternalMastershipListener implements MastershipListener {
187 + @Override
188 + public void event(MastershipEvent event) {
189 + if (event.type() == MastershipEvent.Type.MASTER_CHANGED) {
190 + if (mastershipService.getMasterFor(event.subject()) != null) {
191 + //Only for L3 device create label pool for that device
192 + Device device = deviceService.getDevice(event.subject());
193 + if (device == null) {
194 + log.debug("Device {} doesn't exist", event.subject());
195 + return;
196 + }
197 + //Reserve device label pool for L3 devices
198 + if (device.annotations().value(LSRID) != null) {
199 + createDevicePool(event.subject());
200 + }
201 + }
202 + }
203 + }
138 } 204 }
139 205
140 /* 206 /*
...@@ -146,7 +212,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -146,7 +212,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
146 public void addNode(BgpNodeLSNlriVer4 nodeNlri, PathAttrNlriDetails details) { 212 public void addNode(BgpNodeLSNlriVer4 nodeNlri, PathAttrNlriDetails details) {
147 log.debug("Add node {}", nodeNlri.toString()); 213 log.debug("Add node {}", nodeNlri.toString());
148 214
149 - if (deviceProviderService == null) { 215 + if (deviceProviderService == null || deviceService == null) {
150 return; 216 return;
151 } 217 }
152 Device.Type deviceType = ROUTER; 218 Device.Type deviceType = ROUTER;
...@@ -154,6 +220,13 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -154,6 +220,13 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
154 DeviceId deviceId = deviceId(uri(nodeUri.toString())); 220 DeviceId deviceId = deviceId(uri(nodeUri.toString()));
155 ChassisId cId = new ChassisId(); 221 ChassisId cId = new ChassisId();
156 222
223 + /*
224 + * Check if device is already there (available) , if yes not updating to core.
225 + */
226 + if (deviceService.isAvailable(deviceId)) {
227 + return;
228 + }
229 +
157 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); 230 DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
158 231
159 newBuilder.set(AnnotationKeys.TYPE, "L3"); 232 newBuilder.set(AnnotationKeys.TYPE, "L3");
...@@ -183,11 +256,13 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -183,11 +256,13 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
183 } 256 }
184 } 257 }
185 } 258 }
259 + DefaultAnnotations.Builder anntotations = DefaultAnnotations.builder();
260 + anntotations = getAnnotations(newBuilder, true, details);
186 261
187 DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), deviceType, UNKNOWN, 262 DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), deviceType, UNKNOWN,
188 - UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); 263 + UNKNOWN, UNKNOWN, UNKNOWN, cId, anntotations.build());
189 - deviceProviderService.deviceConnected(deviceId, description);
190 264
265 + deviceProviderService.deviceConnected(deviceId, description);
191 } 266 }
192 267
193 @Override 268 @Override
...@@ -200,6 +275,12 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -200,6 +275,12 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
200 275
201 BgpDpid deviceUri = new BgpDpid(nodeNlri); 276 BgpDpid deviceUri = new BgpDpid(nodeNlri);
202 DeviceId deviceId = deviceId(uri(deviceUri.toString())); 277 DeviceId deviceId = deviceId(uri(deviceUri.toString()));
278 +
279 + if (labelResourceAdminService != null) {
280 + //Destroy local device label pool reserved for that device
281 + labelResourceAdminService.destroyDevicePool(deviceId);
282 + }
283 +
203 deviceProviderService.deviceDisconnected(deviceId); 284 deviceProviderService.deviceDisconnected(deviceId);
204 } 285 }
205 286
...@@ -211,6 +292,24 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -211,6 +292,24 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
211 return; 292 return;
212 } 293 }
213 LinkDescription linkDes = buildLinkDes(linkNlri, details, true); 294 LinkDescription linkDes = buildLinkDes(linkNlri, details, true);
295 +
296 + /*
297 + * Update link ports and configure bandwidth on source and destination port using networkConfig service
298 + * Only master of source link registers for bandwidth
299 + */
300 + if (mastershipService.isLocalMaster(linkDes.src().deviceId())) {
301 + registerBandwidth(linkDes, details);
302 + }
303 +
304 + //Updating ports of the link
305 + List<PortDescription> srcPortDescriptions = new LinkedList<>();
306 + srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
307 + deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
308 +
309 + List<PortDescription> dstPortDescriptions = new LinkedList<>();
310 + dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
311 + deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
312 +
214 linkProviderService.linkDetected(linkDes); 313 linkProviderService.linkDetected(linkDes);
215 } 314 }
216 315
...@@ -273,7 +372,12 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -273,7 +372,12 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
273 372
274 addOrDeletePseudoNode(isAddLink, localPseduo, remotePseduo, srcNodeNlri, 373 addOrDeletePseudoNode(isAddLink, localPseduo, remotePseduo, srcNodeNlri,
275 dstNodeNlri, srcId, dstId, details); 374 dstNodeNlri, srcId, dstId, details);
276 - return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false); 375 + DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
376 + if (details != null) {
377 + annotationBuilder = getAnnotations(annotationBuilder, false, details);
378 + }
379 +
380 + return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false, annotationBuilder.build());
277 } 381 }
278 382
279 private void addOrDeletePseudoNode(boolean isAddLink, boolean localPseduo, boolean remotePseduo, 383 private void addOrDeletePseudoNode(boolean isAddLink, boolean localPseduo, boolean remotePseduo,
...@@ -322,10 +426,140 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -322,10 +426,140 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
322 } 426 }
323 427
324 LinkDescription linkDes = buildLinkDes(linkNlri, null, false); 428 LinkDescription linkDes = buildLinkDes(linkNlri, null, false);
429 +
430 + /*
431 + * Only master for the link src will release the bandwidth resource.
432 + */
433 + if (networkConfigService != null && mastershipService.isLocalMaster(linkDes.src().deviceId())) {
434 + // Releases registered resource for this link
435 + networkConfigService.removeConfig(linkDes.src(), BandwidthCapacity.class);
436 + networkConfigService.removeConfig(linkDes.dst(), BandwidthCapacity.class);
437 + }
438 +
325 linkProviderService.linkVanished(linkDes); 439 linkProviderService.linkVanished(linkDes);
326 } 440 }
327 } 441 }
328 442
443 + // Creates label resource pool for the specific device. For all devices label range is 5122-9217
444 + private void createDevicePool(DeviceId deviceId) {
445 + if (labelResourceAdminService == null) {
446 + return;
447 + }
448 +
449 + labelResourceAdminService.createDevicePool(deviceId, beginLabel, endLabel);
450 + }
451 +
452 + private void registerBandwidth(LinkDescription linkDes, PathAttrNlriDetails details) {
453 + if (details == null) {
454 + log.error("Couldnot able to register bandwidth ");
455 + return;
456 + }
457 +
458 + List<BgpValueType> attribute = details.pathAttributes().stream()
459 + .filter(attr -> attr instanceof LinkStateAttributes).collect(toList());
460 + if (attribute.isEmpty()) {
461 + return;
462 + }
463 +
464 + List<BgpValueType> tlvs = ((LinkStateAttributes) attribute.iterator().next()).linkStateAttributes();
465 + float maxReservableBw = 0;
466 +
467 + for (BgpValueType tlv : tlvs) {
468 + switch (tlv.getType()) {
469 + case LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH:
470 + maxReservableBw = ((BgpLinkAttrMaxLinkBandwidth) tlv).linkAttrMaxLinkBandwidth();
471 + break;
472 + default: // do nothing
473 + }
474 + }
475 +
476 + if (maxReservableBw == 0.0) {
477 + return;
478 + }
479 +
480 + //Configure bandwidth for src and dst port
481 + BandwidthCapacity config = networkConfigService.addConfig(linkDes.src(), BandwidthCapacity.class);
482 + config.capacity(Bandwidth.bps(maxReservableBw)).apply();
483 +
484 + config = networkConfigService.addConfig(linkDes.dst(), BandwidthCapacity.class);
485 + config.capacity(Bandwidth.bps(maxReservableBw)).apply();
486 + }
487 +
488 + private DefaultAnnotations.Builder getAnnotations(DefaultAnnotations.Builder annotationBuilder, boolean isNode,
489 + PathAttrNlriDetails details) {
490 +
491 + List<BgpValueType> attribute = details.pathAttributes().stream()
492 + .filter(attr -> attr instanceof LinkStateAttributes).collect(toList());
493 + if (attribute.isEmpty()) {
494 + return annotationBuilder;
495 + }
496 + List<BgpValueType> tlvs = ((LinkStateAttributes) attribute.iterator().next()).linkStateAttributes();
497 + boolean abrBit = false;
498 + boolean externalBit = false;
499 + boolean pseudo = false;
500 + int igpMetric = 0;
501 + int teMetric = 0;
502 + byte[] areaId = null;
503 + Ip4Address routerId = null;
504 + for (BgpValueType tlv : tlvs) {
505 + switch (tlv.getType()) {
506 + case LinkStateAttributes.ATTR_NODE_FLAG_BITS:
507 + abrBit = ((BgpAttrNodeFlagBitTlv) tlv).abrBit();
508 + externalBit = ((BgpAttrNodeFlagBitTlv) tlv).externalBit();
509 + break;
510 + case NodeDescriptors.IGP_ROUTERID_TYPE:
511 + if (tlv instanceof IsIsPseudonode || tlv instanceof OspfPseudonode) {
512 + pseudo = true;
513 + }
514 + break;
515 + case LinkStateAttributes.ATTR_NODE_ISIS_AREA_ID:
516 + areaId = ((BgpAttrNodeIsIsAreaId) tlv).attrNodeIsIsAreaId();
517 + break;
518 + case LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID:
519 + routerId = ((BgpAttrRouterIdV4) tlv).attrRouterId();
520 + break;
521 + case LinkStateAttributes.ATTR_LINK_IGP_METRIC:
522 + igpMetric = ((BgpLinkAttrIgpMetric) tlv).attrLinkIgpMetric();
523 + break;
524 + case LinkStateAttributes.ATTR_LINK_TE_DEFAULT_METRIC:
525 + teMetric = ((BgpLinkAttrTeDefaultMetric) tlv).attrLinkDefTeMetric();
526 + break;
527 + default: // do nothing
528 + }
529 + }
530 +
531 + // Annotations for device
532 + if (isNode) {
533 + boolean internalBit = false;
534 + if (!abrBit && !externalBit) {
535 + internalBit = true;
536 + }
537 +
538 + annotationBuilder.set(EXTERNAL_BIT, String.valueOf(externalBit));
539 + annotationBuilder.set(ABR_BIT, String.valueOf(abrBit));
540 + annotationBuilder.set(INTERNAL_BIT, String.valueOf(internalBit));
541 + annotationBuilder.set(PSEUDO, String.valueOf(pseudo));
542 +
543 + if (areaId != null) {
544 + annotationBuilder.set(AREAID, new String(areaId));
545 + }
546 + if (routerId != null) {
547 + // LsrID
548 + annotationBuilder.set(LSRID, String.valueOf(routerId));
549 + }
550 + } else {
551 + // Annotations for link
552 + if (igpMetric != 0) {
553 + annotationBuilder.set(COST, String.valueOf(igpMetric));
554 + }
555 +
556 + if (teMetric != 0) {
557 + annotationBuilder.set(TE_COST, String.valueOf(teMetric));
558 + }
559 + }
560 + return annotationBuilder;
561 + }
562 +
329 @Override 563 @Override
330 public void triggerProbe(DeviceId deviceId) { 564 public void triggerProbe(DeviceId deviceId) {
331 // TODO Auto-generated method stub 565 // TODO Auto-generated method stub
......
...@@ -16,6 +16,8 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -16,6 +16,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.core.Is.is; 16 import static org.hamcrest.core.Is.is;
17 import static org.hamcrest.core.IsNot.not; 17 import static org.hamcrest.core.IsNot.not;
18 import static org.onosproject.net.Link.State.ACTIVE; 18 import static org.onosproject.net.Link.State.ACTIVE;
19 +import static org.onosproject.net.MastershipRole.MASTER;
20 +import static org.hamcrest.Matchers.nullValue;
19 21
20 import java.util.Collection; 22 import java.util.Collection;
21 import java.util.HashMap; 23 import java.util.HashMap;
...@@ -29,7 +31,11 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -29,7 +31,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
29 import org.junit.After; 31 import org.junit.After;
30 import org.junit.Before; 32 import org.junit.Before;
31 import org.junit.Test; 33 import org.junit.Test;
34 +import org.onlab.junit.TestUtils;
35 +import org.onlab.junit.TestUtils.TestUtilsException;
32 import org.onlab.packet.ChassisId; 36 import org.onlab.packet.ChassisId;
37 +import org.onlab.packet.Ip4Address;
38 +import org.onlab.util.Bandwidth;
33 import org.onosproject.bgp.controller.BgpLinkListener; 39 import org.onosproject.bgp.controller.BgpLinkListener;
34 import org.onosproject.bgp.controller.BgpNodeListener; 40 import org.onosproject.bgp.controller.BgpNodeListener;
35 import org.onosproject.bgpio.exceptions.BgpParseException; 41 import org.onosproject.bgpio.exceptions.BgpParseException;
...@@ -43,9 +49,26 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; ...@@ -43,9 +49,26 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
43 import org.onosproject.bgpio.types.AutonomousSystemTlv; 49 import org.onosproject.bgpio.types.AutonomousSystemTlv;
44 import org.onosproject.bgpio.types.BgpValueType; 50 import org.onosproject.bgpio.types.BgpValueType;
45 import org.onosproject.bgpio.types.IsIsNonPseudonode; 51 import org.onosproject.bgpio.types.IsIsNonPseudonode;
52 +import org.onosproject.bgpio.types.LinkStateAttributes;
53 +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
54 +import org.onosproject.incubator.net.resource.label.LabelResourceId;
55 +import org.onosproject.incubator.net.resource.label.LabelResourcePool;
56 +import org.onosproject.mastership.MastershipEvent;
57 +import org.onosproject.mastership.MastershipListener;
58 +import org.onosproject.mastership.MastershipServiceAdapter;
59 +import org.onosproject.mastership.MastershipEvent.Type;
60 +import org.onosproject.net.link.LinkServiceAdapter;
46 import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; 61 import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
47 import org.onosproject.bgpio.types.RouteDistinguisher; 62 import org.onosproject.bgpio.types.RouteDistinguisher;
63 +import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv;
64 +import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId;
65 +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
66 +import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric;
67 +import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth;
68 +import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric;
48 import org.onosproject.bgpio.util.Constants; 69 import org.onosproject.bgpio.util.Constants;
70 +import org.onosproject.cluster.NodeId;
71 +import org.onosproject.cluster.RoleInfo;
49 import org.onosproject.net.ConnectPoint; 72 import org.onosproject.net.ConnectPoint;
50 import org.onosproject.net.DefaultDevice; 73 import org.onosproject.net.DefaultDevice;
51 import org.onosproject.net.DefaultLink; 74 import org.onosproject.net.DefaultLink;
...@@ -53,6 +76,11 @@ import org.onosproject.net.Device; ...@@ -53,6 +76,11 @@ import org.onosproject.net.Device;
53 import org.onosproject.net.DeviceId; 76 import org.onosproject.net.DeviceId;
54 import org.onosproject.net.Link; 77 import org.onosproject.net.Link;
55 import org.onosproject.net.MastershipRole; 78 import org.onosproject.net.MastershipRole;
79 +import org.onosproject.net.PortNumber;
80 +import org.onosproject.net.config.Config;
81 +import org.onosproject.net.config.ConfigApplyDelegate;
82 +import org.onosproject.net.config.ConfigFactory;
83 +import org.onosproject.net.config.NetworkConfigRegistryAdapter;
56 import org.onosproject.net.device.DeviceDescription; 84 import org.onosproject.net.device.DeviceDescription;
57 import org.onosproject.net.device.DeviceProvider; 85 import org.onosproject.net.device.DeviceProvider;
58 import org.onosproject.net.device.DeviceProviderRegistry; 86 import org.onosproject.net.device.DeviceProviderRegistry;
...@@ -65,6 +93,15 @@ import org.onosproject.net.link.LinkProvider; ...@@ -65,6 +93,15 @@ import org.onosproject.net.link.LinkProvider;
65 import org.onosproject.net.link.LinkProviderRegistry; 93 import org.onosproject.net.link.LinkProviderRegistry;
66 import org.onosproject.net.link.LinkProviderService; 94 import org.onosproject.net.link.LinkProviderService;
67 import org.onosproject.net.provider.ProviderId; 95 import org.onosproject.net.provider.ProviderId;
96 +import org.onosproject.net.config.basics.BandwidthCapacity;
97 +import org.onosproject.net.resource.Resource;
98 +import org.onosproject.net.resource.ResourceAdminService;
99 +import org.onosproject.net.resource.ResourceId;
100 +
101 +import com.fasterxml.jackson.databind.JsonNode;
102 +import com.fasterxml.jackson.databind.ObjectMapper;
103 +import com.fasterxml.jackson.databind.node.JsonNodeFactory;
104 +import com.fasterxml.jackson.databind.node.ObjectNode;
68 105
69 /** 106 /**
70 * Test for BGP topology provider. 107 * Test for BGP topology provider.
...@@ -73,21 +110,31 @@ public class BgpTopologyProviderTest { ...@@ -73,21 +110,31 @@ public class BgpTopologyProviderTest {
73 private static final DeviceId DID2 = DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10"); 110 private static final DeviceId DID2 = DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10");
74 private static final String UNKNOWN = new String("unknown"); 111 private static final String UNKNOWN = new String("unknown");
75 public static ProviderId providerId = new ProviderId("l3", "foo"); 112 public static ProviderId providerId = new ProviderId("l3", "foo");
113 + private static final NodeId NODE1 = new NodeId("Master1");
76 114
77 private final BgpTopologyProvider provider = new BgpTopologyProvider(); 115 private final BgpTopologyProvider provider = new BgpTopologyProvider();
78 private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); 116 private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
79 private final TestLinkRegistry linkRegistry = new TestLinkRegistry(); 117 private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
80 private final MockBgpController controller = new MockBgpController(); 118 private final MockBgpController controller = new MockBgpController();
81 private MockDeviceService deviceService = new MockDeviceService(); 119 private MockDeviceService deviceService = new MockDeviceService();
120 + private MockLinkService linkService = new MockLinkService();
121 + private MockMastershipService mastershipService = new MockMastershipService();
122 + private MockNetConfigRegistryAdapter networkConfigService = new MockNetConfigRegistryAdapter();
123 + private MockLabelResourceService labelResourceAdminService = new MockLabelResourceService();
82 private Map<DeviceId, Device> deviceMap = new HashMap<>(); 124 private Map<DeviceId, Device> deviceMap = new HashMap<>();
83 - 125 + private MastershipListener listener;
84 126
85 @Before 127 @Before
86 - public void startUp() { 128 + public void startUp() throws TestUtilsException {
87 provider.deviceProviderRegistry = nodeRegistry; 129 provider.deviceProviderRegistry = nodeRegistry;
88 provider.linkProviderRegistry = linkRegistry; 130 provider.linkProviderRegistry = linkRegistry;
89 provider.controller = controller; 131 provider.controller = controller;
90 provider.deviceService = deviceService; 132 provider.deviceService = deviceService;
133 + provider.linkService = linkService;
134 + provider.labelResourceAdminService = labelResourceAdminService;
135 + provider.mastershipService = mastershipService;
136 + provider.networkConfigService = networkConfigService;
137 + listener = TestUtils.getField(provider, "masterListener");
91 provider.activate(); 138 provider.activate();
92 assertThat("device provider should be registered", not(nodeRegistry.provider)); 139 assertThat("device provider should be registered", not(nodeRegistry.provider));
93 assertThat("link provider should be registered", not(linkRegistry.linkProvider)); 140 assertThat("link provider should be registered", not(linkRegistry.linkProvider));
...@@ -101,15 +148,177 @@ public class BgpTopologyProviderTest { ...@@ -101,15 +148,177 @@ public class BgpTopologyProviderTest {
101 provider.controller = null; 148 provider.controller = null;
102 provider.deviceService = null; 149 provider.deviceService = null;
103 provider.deviceProviderRegistry = null; 150 provider.deviceProviderRegistry = null;
151 + provider.linkService = null;
152 + provider.mastershipService = null;
153 + provider.networkConfigService = null;
154 + provider.labelResourceAdminService = null;
104 assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>())); 155 assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>()));
105 assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>())); 156 assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>()));
106 } 157 }
107 158
159 + private class MockLabelResourceService implements LabelResourceAdminService {
160 +
161 + Map<DeviceId, LabelResourcePool> resourcePool = new HashMap<>();
162 +
163 + @Override
164 + public boolean createDevicePool(DeviceId deviceId, LabelResourceId beginLabel, LabelResourceId endLabel) {
165 + LabelResourcePool labelResource = new LabelResourcePool(deviceId.toString(),
166 + beginLabel.labelId(),
167 + endLabel.labelId());
168 + if (resourcePool.containsValue(labelResource)) {
169 + return false;
170 + }
171 +
172 + resourcePool.put(deviceId, labelResource);
173 + return true;
174 + }
175 +
176 + @Override
177 + public boolean createGlobalPool(LabelResourceId beginLabel, LabelResourceId endLabel) {
178 + // TODO Auto-generated method stub
179 + return false;
180 + }
181 +
182 + @Override
183 + public boolean destroyDevicePool(DeviceId deviceId) {
184 + LabelResourcePool devicePool = resourcePool.get(deviceId);
185 +
186 + if (devicePool == null) {
187 + return false;
188 + }
189 +
190 + resourcePool.remove(deviceId);
191 + return true;
192 + }
193 +
194 + @Override
195 + public boolean destroyGlobalPool() {
196 + // TODO Auto-generated method stub
197 + return false;
198 + }
199 + }
200 +
201 + /* Mock test for device service */
202 + private class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter {
203 + private ConfigFactory cfgFactory;
204 + private Map<ConnectPoint, BandwidthCapacity> classConfig = new HashMap<>();
205 +
206 + @Override
207 + public void registerConfigFactory(ConfigFactory configFactory) {
208 + cfgFactory = configFactory;
209 + }
210 +
211 + @Override
212 + public void unregisterConfigFactory(ConfigFactory configFactory) {
213 + cfgFactory = null;
214 + }
215 +
216 + @Override
217 + public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
218 + if (configClass == BandwidthCapacity.class) {
219 + BandwidthCapacity devCap = new BandwidthCapacity();
220 + classConfig.put((ConnectPoint) subject, devCap);
221 +
222 + JsonNode node = new ObjectNode(new MockJsonNode());
223 + ObjectMapper mapper = new ObjectMapper();
224 + ConfigApplyDelegate delegate = new InternalApplyDelegate();
225 + devCap.init((ConnectPoint) subject, null, node, mapper, delegate);
226 + return (C) devCap;
227 + }
228 +
229 + return null;
230 + }
231 +
232 + @Override
233 + public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
234 + classConfig.remove(subject);
235 + }
236 +
237 + @Override
238 + public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
239 + if (configClass == BandwidthCapacity.class) {
240 + return (C) classConfig.get(subject);
241 + }
242 + return null;
243 + }
244 +
245 + private class MockJsonNode extends JsonNodeFactory {
246 + }
247 +
248 + // Auxiliary delegate to receive notifications about changes applied to
249 + // the network configuration - by the apps.
250 + private class InternalApplyDelegate implements ConfigApplyDelegate {
251 + @Override
252 + public void onApply(Config config) {
253 + }
254 + }
255 + }
256 +
257 + private class MockMastershipService extends MastershipServiceAdapter {
258 + @Override
259 + public MastershipRole getLocalRole(DeviceId deviceId) {
260 + return MASTER;
261 + }
262 +
263 + @Override
264 + public boolean isLocalMaster(DeviceId deviceId) {
265 + return getLocalRole(deviceId) == MASTER;
266 + }
267 +
268 + @Override
269 + public NodeId getMasterFor(DeviceId deviceId) {
270 + return NODE1;
271 + }
272 + }
273 +
274 + private class MockResourceAdminService implements ResourceAdminService {
275 + Map<ResourceId, List<Resource>> registeredRes = new HashMap<>();
276 +
277 + @Override
278 + public boolean register(List<Resource> resources) {
279 + for (Resource res : resources) {
280 + List<Resource> resource = new LinkedList<>();
281 + resource.add(res);
282 + if (registeredRes.containsKey(res.id())) {
283 + resource.addAll(registeredRes.get(res.id()));
284 + }
285 + registeredRes.put(res.id(), resource);
286 + }
287 + return true;
288 + }
289 +
290 + @Override
291 + public boolean unregister(List<ResourceId> ids) {
292 + for (ResourceId id : ids) {
293 + if (registeredRes.containsKey(id)) {
294 + registeredRes.remove(id);
295 + } else {
296 + return false;
297 + }
298 + }
299 + return true;
300 + }
301 + }
302 +
303 + private class MockLinkService extends LinkServiceAdapter {
304 +
305 + @Override
306 + public Link getLink(ConnectPoint src, ConnectPoint dst) {
307 + for (Link link : linkRegistry.links) {
308 + if (link.src().equals(src) && link.dst().equals(dst)) {
309 + return link;
310 + }
311 + }
312 + return null;
313 + }
314 + }
315 +
108 /* Class implement device test registry */ 316 /* Class implement device test registry */
109 private class TestDeviceRegistry implements DeviceProviderRegistry { 317 private class TestDeviceRegistry implements DeviceProviderRegistry {
110 DeviceProvider provider; 318 DeviceProvider provider;
111 319
112 Set<DeviceId> connected = new HashSet<>(); 320 Set<DeviceId> connected = new HashSet<>();
321 + Map<DeviceId, List<PortDescription>> portUpdated = new HashMap<>();
113 322
114 @Override 323 @Override
115 public DeviceProviderService register(DeviceProvider provider) { 324 public DeviceProviderService register(DeviceProvider provider) {
...@@ -138,7 +347,7 @@ public class BgpTopologyProviderTest { ...@@ -138,7 +347,7 @@ public class BgpTopologyProviderTest {
138 if (!deviceId.equals(DID2)) { 347 if (!deviceId.equals(DID2)) {
139 connected.add(deviceId); 348 connected.add(deviceId);
140 Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER, 349 Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER,
141 - UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId()); 350 + UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId(), deviceDescription.annotations());
142 deviceMap.put(deviceId, device); 351 deviceMap.put(deviceId, device);
143 } 352 }
144 } 353 }
...@@ -153,8 +362,7 @@ public class BgpTopologyProviderTest { ...@@ -153,8 +362,7 @@ public class BgpTopologyProviderTest {
153 362
154 @Override 363 @Override
155 public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { 364 public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
156 - // TODO Auto-generated method stub 365 + portUpdated.put(deviceId, portDescriptions);
157 -
158 } 366 }
159 367
160 @Override 368 @Override
...@@ -202,9 +410,14 @@ public class BgpTopologyProviderTest { ...@@ -202,9 +410,14 @@ public class BgpTopologyProviderTest {
202 410
203 @Override 411 @Override
204 public void linkDetected(LinkDescription linkDescription) { 412 public void linkDetected(LinkDescription linkDescription) {
205 - links.add(DefaultLink.builder().src(linkDescription.src()) 413 + links.add(DefaultLink.builder()
206 - .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type()) 414 + .src(linkDescription.src())
207 - .providerId(BgpTopologyProviderTest.providerId).build()); 415 + .dst(linkDescription.dst())
416 + .state(ACTIVE)
417 + .type(linkDescription.type())
418 + .providerId(BgpTopologyProviderTest.providerId)
419 + .annotations(linkDescription.annotations())
420 + .build());
208 } 421 }
209 422
210 @Override 423 @Override
...@@ -349,6 +562,59 @@ public class BgpTopologyProviderTest { ...@@ -349,6 +562,59 @@ public class BgpTopologyProviderTest {
349 } 562 }
350 } 563 }
351 564
565 +
566 + /**
567 + * Validate node is added to the device with all device annotations.
568 + */
569 + @Test
570 + public void bgpTopologyProviderTestAddDevice4() {
571 + LinkedList<BgpValueType> subTlvs = new LinkedList<>();
572 + BgpValueType tlv = new AutonomousSystemTlv(100);
573 + short deslength = AutonomousSystemTlv.LENGTH;
574 + short desType = AutonomousSystemTlv.TYPE;
575 +
576 + subTlvs.add(tlv);
577 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
578 + desType));
579 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
580 + new RouteDistinguisher());
581 +
582 + PathAttrNlriDetails details = new PathAttrNlriDetails();
583 + details.setIdentifier(0);
584 + details.setProtocolID(ProtocolType.DIRECT);
585 + List<BgpValueType> pathAttributes = new LinkedList<>();
586 + List<BgpValueType> linkStateAttr = new LinkedList<>();
587 + tlv = BgpAttrNodeFlagBitTlv.of(true, true, true, false);
588 + linkStateAttr.add(tlv);
589 + tlv = BgpAttrNodeIsIsAreaId.of(new byte[] {01, 01, 01, 01});
590 + linkStateAttr.add(tlv);
591 + tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
592 + linkStateAttr.add(tlv);
593 + pathAttributes.add(new LinkStateAttributes(linkStateAttr));
594 + details.setPathAttribute(pathAttributes);
595 +
596 + for (BgpNodeListener l : controller.nodeListener) {
597 + l.addNode(nodeNlri, details);
598 +
599 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.ABR_BIT),
600 + is("false"));
601 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.EXTERNAL_BIT),
602 + is("true"));
603 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.INTERNAL_BIT),
604 + is("false"));
605 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.PSEUDO),
606 + is("false"));
607 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.AREAID).getBytes(),
608 + is(new byte[] {01, 01, 01, 01}));
609 + assertThat(deviceMap.values().iterator().next().annotations().value(BgpTopologyProvider.LSRID),
610 + is("1.1.1.1"));
611 +
612 + assertThat(nodeRegistry.connected.size(), is(1));
613 + l.deleteNode(nodeNlri);
614 + assertThat(nodeRegistry.connected.size(), is(0));
615 + }
616 + }
617 +
352 /** 618 /**
353 * Add a link and two devices. 619 * Add a link and two devices.
354 * 620 *
...@@ -460,6 +726,82 @@ public class BgpTopologyProviderTest { ...@@ -460,6 +726,82 @@ public class BgpTopologyProviderTest {
460 } 726 }
461 727
462 /** 728 /**
729 + * Add a link and delete a link with registering/unregistering bandwidth.
730 + *
731 + * @throws BgpParseException while adding or removing the link
732 + * @throws InterruptedException while registering for bandwidth
733 + */
734 + @Test
735 + public void bgpTopologyProviderTestAddLink3() throws BgpParseException, InterruptedException {
736 + LinkedList<BgpValueType> localTlvs = new LinkedList<>();
737 + LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
738 + LinkedList<BgpValueType> linkdes = new LinkedList<>();
739 + BgpValueType tlv = new AutonomousSystemTlv(10);
740 + short deslength = AutonomousSystemTlv.LENGTH;
741 + short desType = AutonomousSystemTlv.TYPE;
742 +
743 + localTlvs.add(tlv);
744 + remoteTlvs.add(tlv);
745 + tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
746 + localTlvs.add(tlv);
747 + tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
748 + remoteTlvs.add(tlv);
749 + NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
750 + NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
751 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
752 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
753 + new RouteDistinguisher());
754 +
755 + BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
756 + BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
757 + new RouteDistinguisher());
758 +
759 + PathAttrNlriDetails details = new PathAttrNlriDetails();
760 + details.setIdentifier(0);
761 + details.setProtocolID(ProtocolType.DIRECT);
762 + List<BgpValueType> pathAttributes = new LinkedList<>();
763 + details.setPathAttribute(pathAttributes);
764 +
765 + tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
766 + linkdes.add(tlv);
767 + BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
768 + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
769 + new RouteDistinguisher(), false);
770 +
771 + for (BgpNodeListener l : controller.nodeListener) {
772 + l.addNode(nodeNlri, details);
773 + assertThat(nodeRegistry.connected.size(), is(1));
774 + l.addNode(remNodeNlri, details);
775 + assertThat(nodeRegistry.connected.size(), is(2));
776 + l.deleteNode(remNodeNlri);
777 + assertThat(nodeRegistry.connected.size(), is(1));
778 + }
779 +
780 + List<BgpValueType> linkPathAttributes = new LinkedList<>();
781 + List<BgpValueType> linkStateAttr = new LinkedList<>();
782 + tlv = BgpLinkAttrIgpMetric.of(10, 4);
783 + linkStateAttr.add(tlv);
784 + tlv = BgpLinkAttrTeDefaultMetric.of(20);
785 + linkStateAttr.add(tlv);
786 + tlv = BgpLinkAttrMaxLinkBandwidth.of(30, LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
787 + linkStateAttr.add(tlv);
788 + linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
789 + details.setPathAttribute(linkPathAttributes);
790 +
791 + for (BgpLinkListener l : controller.linkListener) {
792 + l.addLink(linkNlri, details);
793 + assertThat(linkRegistry.links.size(), is(1));
794 + assertThat(linkRegistry.links.iterator().next().annotations().value(BgpTopologyProvider.COST),
795 + is("10"));
796 + assertThat(linkRegistry.links.iterator().next().annotations().value(BgpTopologyProvider.TE_COST),
797 + is("20"));
798 +
799 + l.deleteLink(linkNlri);
800 + assertThat(linkRegistry.links.size(), is(0));
801 + }
802 + }
803 +
804 + /**
463 * Invalid link. 805 * Invalid link.
464 * 806 *
465 * @throws BgpParseException while adding or deleting a link 807 * @throws BgpParseException while adding or deleting a link
...@@ -512,4 +854,188 @@ public class BgpTopologyProviderTest { ...@@ -512,4 +854,188 @@ public class BgpTopologyProviderTest {
512 assertThat(linkRegistry.links.size(), is(0)); 854 assertThat(linkRegistry.links.size(), is(0));
513 } 855 }
514 } 856 }
857 +
858 + /**
859 + * Add device check label registration is done.
860 + *
861 + * @throws BgpParseException while adding a device
862 + */
863 + @Test
864 + public void bgpTopologyProviderDeviceTestLabel1() throws BgpParseException {
865 + LinkedList<BgpValueType> subTlvs = new LinkedList<>();
866 + BgpValueType tlv = new AutonomousSystemTlv(100);
867 + short deslength = AutonomousSystemTlv.LENGTH;
868 + short desType = AutonomousSystemTlv.TYPE;
869 +
870 + subTlvs.add(tlv);
871 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
872 + desType));
873 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
874 + new RouteDistinguisher());
875 +
876 + PathAttrNlriDetails details = new PathAttrNlriDetails();
877 + details.setIdentifier(0);
878 + details.setProtocolID(ProtocolType.DIRECT);
879 + List<BgpValueType> pathAttributes = new LinkedList<>();
880 + List<BgpValueType> linkStateAttributes = new LinkedList<>();
881 + tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
882 + linkStateAttributes.add(tlv);
883 + pathAttributes.add(new LinkStateAttributes(linkStateAttributes));
884 + details.setPathAttribute(pathAttributes);
885 +
886 + for (BgpNodeListener l : controller.nodeListener) {
887 + l.addNode(nodeNlri, details);
888 + assertThat(nodeRegistry.connected.size(), is(1));
889 + }
890 +
891 + MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
892 + new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
893 +
894 + listener.event(event);
895 + assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
896 + }
897 +
898 + /**
899 + * Add device check label registration is done and delete node destroy label pool.
900 + *
901 + * @throws BgpParseException while adding a device
902 + */
903 + @Test
904 + public void bgpTopologyProviderDeviceTestLabel2() throws BgpParseException {
905 + LinkedList<BgpValueType> subTlvs = new LinkedList<>();
906 + BgpValueType tlv = new AutonomousSystemTlv(100);
907 + short deslength = AutonomousSystemTlv.LENGTH;
908 + short desType = AutonomousSystemTlv.TYPE;
909 +
910 + subTlvs.add(tlv);
911 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
912 + desType));
913 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
914 + new RouteDistinguisher());
915 +
916 + PathAttrNlriDetails details = new PathAttrNlriDetails();
917 + details.setIdentifier(0);
918 + details.setProtocolID(ProtocolType.DIRECT);
919 + List<BgpValueType> pathAttributes = new LinkedList<>();
920 + List<BgpValueType> linkStateAttributes = new LinkedList<>();
921 + tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
922 + linkStateAttributes.add(tlv);
923 + pathAttributes.add(new LinkStateAttributes(linkStateAttributes));
924 + details.setPathAttribute(pathAttributes);
925 +
926 + for (BgpNodeListener l : controller.nodeListener) {
927 + l.addNode(nodeNlri, details);
928 + assertThat(nodeRegistry.connected.size(), is(1));
929 + // Check label resource reserved for that device
930 + MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
931 + new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
932 + listener.event(event);
933 + assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
934 +
935 + l.deleteNode(nodeNlri);
936 + assertThat(nodeRegistry.connected.size(), is(0));
937 + assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(0));
938 + }
939 + }
940 +
941 + /**
942 + * Add a link register bandwidth and remove link unregister bandwidth.
943 + *
944 + * @throws BgpParseException while registering/unregistering bandwidth
945 + */
946 + @Test
947 + public void bgpTopologyProviderDeviceTestLabel3() throws BgpParseException {
948 + LinkedList<BgpValueType> localTlvs = new LinkedList<>();
949 + LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
950 + LinkedList<BgpValueType> linkdes = new LinkedList<>();
951 + BgpValueType tlv = new AutonomousSystemTlv(10);
952 + short deslength = AutonomousSystemTlv.LENGTH;
953 + short desType = AutonomousSystemTlv.TYPE;
954 +
955 + localTlvs.add(tlv);
956 + remoteTlvs.add(tlv);
957 + tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
958 + localTlvs.add(tlv);
959 + tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
960 + remoteTlvs.add(tlv);
961 + NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
962 + NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
963 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
964 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
965 + new RouteDistinguisher());
966 +
967 + BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
968 + BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
969 + new RouteDistinguisher());
970 +
971 + PathAttrNlriDetails details = new PathAttrNlriDetails();
972 + details.setIdentifier(0);
973 + details.setProtocolID(ProtocolType.DIRECT);
974 + List<BgpValueType> pathAttributes = new LinkedList<>();
975 + List<BgpValueType> linkStateAttributes = new LinkedList<>();
976 + tlv = BgpAttrRouterIdV4.of(Ip4Address.valueOf("1.1.1.1"), LinkStateAttributes.ATTR_NODE_IPV4_LOCAL_ROUTER_ID);
977 + linkStateAttributes.add(tlv);
978 + pathAttributes.add(new LinkStateAttributes(linkStateAttributes));
979 + details.setPathAttribute(pathAttributes);
980 +
981 + tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
982 + linkdes.add(tlv);
983 + BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
984 + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
985 + new RouteDistinguisher(), false);
986 +
987 + for (BgpNodeListener l : controller.nodeListener) {
988 + l.addNode(nodeNlri, details);
989 + assertThat(nodeRegistry.connected.size(), is(1));
990 + //Check label resource reserved for that device
991 + MastershipEvent event = new MastershipEvent(Type.MASTER_CHANGED, nodeRegistry.connected.iterator().next(),
992 + new RoleInfo(NodeId.nodeId("Node1"), new LinkedList<>()));
993 + listener.event(event);
994 + assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
995 + l.addNode(remNodeNlri, details);
996 + assertThat(nodeRegistry.connected.size(), is(2));
997 + l.deleteNode(remNodeNlri);
998 + assertThat(nodeRegistry.connected.size(), is(1));
999 + assertThat(labelResourceAdminService.resourcePool.keySet().size(), is(1));
1000 + }
1001 +
1002 + List<BgpValueType> linkPathAttributes = new LinkedList<>();
1003 + List<BgpValueType> linkStateAttr = new LinkedList<>();
1004 + tlv = BgpLinkAttrIgpMetric.of(10, 4);
1005 + linkStateAttr.add(tlv);
1006 + tlv = BgpLinkAttrTeDefaultMetric.of(20);
1007 + linkStateAttr.add(tlv);
1008 + tlv = BgpLinkAttrMaxLinkBandwidth.of(70, LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
1009 + linkStateAttr.add(tlv);
1010 + linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
1011 + details.setPathAttribute(linkPathAttributes);
1012 +
1013 + for (BgpLinkListener l : controller.linkListener) {
1014 + l.addLink(linkNlri, details);
1015 + assertThat(linkRegistry.links.size(), is(1));
1016 + assertThat(linkRegistry.links.iterator().next().annotations().value(BgpTopologyProvider.COST),
1017 + is("10"));
1018 + assertThat(linkRegistry.links.iterator().next().annotations().value(BgpTopologyProvider.TE_COST),
1019 + is("20"));
1020 +
1021 + ConnectPoint src = new ConnectPoint(
1022 + DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10:isoid=1414.1414.0014"),
1023 + PortNumber.portNumber(4294967395L));
1024 + ConnectPoint dst = new ConnectPoint(
1025 + DeviceId.deviceId("l3:rd=0::routinguniverse=0:asn=10:isoid=1e1e.1e1e.001e"),
1026 + PortNumber.portNumber(4294967396L));
1027 + BandwidthCapacity bandwidth = networkConfigService.getConfig(src, BandwidthCapacity.class);
1028 + assertThat(bandwidth.capacity().bps(), is(70.0 * 1_000_000L));
1029 +
1030 + bandwidth = networkConfigService.getConfig(dst, BandwidthCapacity.class);
1031 + assertThat(bandwidth.capacity(), is(Bandwidth.bps(70.0 * 1_000_000L)));
1032 +
1033 + l.deleteLink(linkNlri);
1034 + assertThat(linkRegistry.links.size(), is(0));
1035 + bandwidth = networkConfigService.getConfig(src, BandwidthCapacity.class);
1036 + assertThat(bandwidth, is(nullValue()));
1037 + bandwidth = networkConfigService.getConfig(dst, BandwidthCapacity.class);
1038 + assertThat(bandwidth, is(nullValue()));
1039 + }
1040 + }
515 } 1041 }
......
1 +<!--
2 + ~ Copyright 2016-present Open Networking Laboratory
3 + ~
4 + ~ Licensed under the Apache License, Version 2.0 (the "License");
5 + ~ you may not use this file except in compliance with the License.
6 + ~ You may obtain a copy of the License at
7 + ~
8 + ~ http://www.apache.org/licenses/LICENSE-2.0
9 + ~
10 + ~ Unless required by applicable law or agreed to in writing, software
11 + ~ distributed under the License is distributed on an "AS IS" BASIS,
12 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + ~ See the License for the specific language governing permissions and
14 + ~ limitations under the License.
15 + -->
16 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 + <parent>
20 + <groupId>org.onosproject</groupId>
21 + <artifactId>onos-pcep-providers</artifactId>
22 + <version>1.6.0-SNAPSHOT</version>
23 + </parent>
24 + <artifactId>onos-pcep-provider-packet</artifactId>
25 + <packaging>bundle</packaging>
26 + <description>PCEP packet provider</description>
27 + <dependencies>
28 + <dependency>
29 + <groupId>org.onosproject</groupId>
30 + <artifactId>onos-pcep-controller-api</artifactId>
31 + </dependency>
32 + </dependencies>
33 +</project>
1 +package org.onosproject.provider.pcep.packet.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import org.apache.felix.scr.annotations.Activate;
6 +import org.apache.felix.scr.annotations.Component;
7 +import org.apache.felix.scr.annotations.Deactivate;
8 +import org.apache.felix.scr.annotations.Reference;
9 +import org.apache.felix.scr.annotations.ReferenceCardinality;
10 +import org.apache.felix.scr.annotations.Service;
11 +import org.onlab.packet.Ethernet;
12 +import org.onlab.packet.IPv4;
13 +import org.onlab.packet.TCP;
14 +import org.onosproject.net.AnnotationKeys;
15 +import org.onosproject.net.ConnectPoint;
16 +import org.onosproject.net.Device;
17 +import org.onosproject.net.DeviceId;
18 +import org.onosproject.net.PortNumber;
19 +import org.onosproject.net.device.DeviceService;
20 +import org.onosproject.net.packet.DefaultInboundPacket;
21 +import org.onosproject.net.packet.DefaultPacketContext;
22 +import org.onosproject.net.packet.InboundPacket;
23 +import org.onosproject.net.packet.OutboundPacket;
24 +import org.onosproject.net.packet.PacketProvider;
25 +import org.onosproject.net.packet.PacketProviderRegistry;
26 +import org.onosproject.net.packet.PacketProviderService;
27 +import org.onosproject.net.provider.AbstractProvider;
28 +import org.onosproject.net.provider.ProviderId;
29 +import org.onosproject.pcep.controller.PccId;
30 +import org.onosproject.pcep.controller.PcepClientController;
31 +import org.onosproject.pcep.controller.PcepPacketListener;
32 +import org.slf4j.Logger;
33 +
34 +/**
35 + * Provider which uses an PCEP controller to process packets.
36 + */
37 +@Component(immediate = true)
38 +@Service
39 +public class PcepPacketProvider extends AbstractProvider implements PacketProvider {
40 +
41 + private static final Logger log = getLogger(PcepPacketProvider.class);
42 + static final String PROVIDER_ID = "org.onosproject.provider.packet.pcep";
43 +
44 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
45 + protected PacketProviderRegistry packetProviderRegistry;
46 +
47 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 + protected PcepClientController pcepClientController;
49 +
50 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 + protected DeviceService deviceService;
52 +
53 + PacketProviderService packetProviderService;
54 +
55 + private InnerPacketProvider listener = new InnerPacketProvider();
56 + public static final String LSRID = "lsrId";
57 + public static final int PCEP_PORT = 4189;
58 +
59 + /**
60 + * Creates a Packet provider.
61 + */
62 + public PcepPacketProvider() {
63 + super(new ProviderId("pcep", PROVIDER_ID));
64 + }
65 +
66 + @Activate
67 + public void activate() {
68 + packetProviderService = packetProviderRegistry.register(this);
69 + pcepClientController.addPacketListener(listener);
70 + log.info("Started");
71 + }
72 +
73 + @Deactivate
74 + public void deactivate() {
75 + packetProviderRegistry.unregister(this);
76 + pcepClientController.removePacketListener(listener);
77 + log.info("Stopped");
78 + }
79 +
80 + private class InnerPacketProvider implements PcepPacketListener {
81 + @Override
82 + public void sendPacketIn(PccId pccId) {
83 + TCP tcp = new TCP();
84 + // Set the well known PCEP port. To be used to decide to process/discard the packet while processing.
85 + tcp.setDestinationPort(PCEP_PORT);
86 +
87 + IPv4 ipv4 = new IPv4();
88 + ipv4.setProtocol(IPv4.PROTOCOL_TCP);
89 + ipv4.setPayload(tcp);
90 +
91 + Ethernet eth = new Ethernet();
92 + eth.setEtherType(Ethernet.TYPE_IPV4);
93 + eth.setPayload(ipv4);
94 +
95 + // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
96 + String lsrId = String.valueOf(pccId.ipAddress());
97 + DeviceId pccDeviceId = null;
98 +
99 + // Find PCC deviceID from lsrId stored as annotations
100 + Iterable<Device> devices = deviceService.getAvailableDevices();
101 + for (Device dev : devices) {
102 + if ("L3".equals(dev.annotations().value(AnnotationKeys.TYPE))
103 + && lsrId.equals(dev.annotations().value(LSRID))) {
104 + pccDeviceId = dev.id();
105 + break;
106 + }
107 + }
108 +
109 + if (pccDeviceId == null) {
110 + return;
111 + }
112 +
113 + InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(pccDeviceId,
114 + PortNumber.portNumber(PCEP_PORT)),
115 + eth, null);
116 +
117 + packetProviderService.processPacket(new PcepPacketContext(inPkt, null));
118 + }
119 + }
120 +
121 + // Minimal PacketContext to make core and applications happy.
122 + private final class PcepPacketContext extends DefaultPacketContext {
123 + private PcepPacketContext(InboundPacket inPkt, OutboundPacket outPkt) {
124 + super(System.currentTimeMillis(), inPkt, outPkt, false);
125 + }
126 +
127 + @Override
128 + public void send() {
129 + // We don't send anything out.
130 + return;
131 + }
132 + }
133 +
134 + @Override
135 + public void emit(OutboundPacket packet) {
136 + // Nothing to emit
137 + return;
138 +
139 + }
140 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +/**
17 + *Provider that uses PCEP controller as a means to send packets.
18 + */
19 +package org.onosproject.provider.pcep.packet.impl;
...\ No newline at end of file ...\ No newline at end of file
...@@ -27,5 +27,6 @@ ...@@ -27,5 +27,6 @@
27 <module>topology</module> 27 <module>topology</module>
28 <module>tunnel</module> 28 <module>tunnel</module>
29 <module>app</module> 29 <module>app</module>
30 + <module>packet</module>
30 </modules> 31 </modules>
31 </project> 32 </project>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,6 +3,9 @@ COMPILE_DEPS = [ ...@@ -3,6 +3,9 @@ COMPILE_DEPS = [
3 '//protocols/ovsdb/api:onos-protocols-ovsdb-api', 3 '//protocols/ovsdb/api:onos-protocols-ovsdb-api',
4 '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', 4 '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
5 '//apps/pcep-api:onos-apps-pcep-api', 5 '//apps/pcep-api:onos-apps-pcep-api',
6 + '//protocols/pcep/api:onos-protocols-pcep-api',
7 + '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
8 + '//core/api:onos-api-tests',
6 ] 9 ]
7 10
8 osgi_jar_with_tests ( 11 osgi_jar_with_tests (
......
...@@ -23,10 +23,20 @@ ...@@ -23,10 +23,20 @@
23 <artifactId>onos-pcep-provider-topology</artifactId> 23 <artifactId>onos-pcep-provider-topology</artifactId>
24 <packaging>bundle</packaging> 24 <packaging>bundle</packaging>
25 <description>PCEP topology provider</description> 25 <description>PCEP topology provider</description>
26 - <dependencies> 26 + <dependencies>
27 - <dependency> 27 + <dependency>
28 - <groupId>org.onosproject</groupId> 28 + <groupId>org.onosproject</groupId>
29 - <artifactId>onos-app-pcep-api</artifactId> 29 + <artifactId>onos-app-pcep-api</artifactId>
30 - </dependency> 30 + </dependency>
31 - </dependencies> 31 + <dependency>
32 + <groupId>org.onosproject</groupId>
33 + <artifactId>onos-pcep-controller-api</artifactId>
34 + </dependency>
35 + <dependency>
36 + <groupId>org.onosproject</groupId>
37 + <artifactId>onos-api</artifactId>
38 + <classifier>tests</classifier>
39 + <scope>test</scope>
40 + </dependency>
41 + </dependencies>
32 </project> 42 </project>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -62,6 +62,10 @@ import org.onosproject.pcep.api.PcepLinkListener; ...@@ -62,6 +62,10 @@ import org.onosproject.pcep.api.PcepLinkListener;
62 import org.onosproject.pcep.api.PcepOperator.OperationType; 62 import org.onosproject.pcep.api.PcepOperator.OperationType;
63 import org.onosproject.pcep.api.PcepSwitch; 63 import org.onosproject.pcep.api.PcepSwitch;
64 import org.onosproject.pcep.api.PcepSwitchListener; 64 import org.onosproject.pcep.api.PcepSwitchListener;
65 +import org.onosproject.pcep.controller.PccId;
66 +import org.onosproject.pcep.controller.PcepClient;
67 +import org.onosproject.pcep.controller.PcepClientController;
68 +import org.onosproject.pcep.controller.PcepNodeListener;
65 import org.slf4j.Logger; 69 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory; 70 import org.slf4j.LoggerFactory;
67 71
...@@ -115,18 +119,40 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -115,18 +119,40 @@ public class PcepTopologyProvider extends AbstractProvider
115 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
116 protected ClusterService clusterService; 120 protected ClusterService clusterService;
117 121
122 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 + protected PcepClientController pcepClientController;
124 +
118 private DeviceProviderService deviceProviderService; 125 private DeviceProviderService deviceProviderService;
119 private LinkProviderService linkProviderService; 126 private LinkProviderService linkProviderService;
120 127
121 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>(); 128 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>();
122 private InternalLinkProvider listener = new InternalLinkProvider(); 129 private InternalLinkProvider listener = new InternalLinkProvider();
123 130
131 + /*
132 + * For the client supporting SR capability.
133 + */
134 + public static final String SR_CAPABILITY = "srCapability";
135 +
136 + /*
137 + * For the client supporting PCECC capability.
138 + */
139 + public static final String PCECC_CAPABILITY = "pceccCapability";
140 +
141 + /*
142 + * For the client supporting label stack capability.
143 + */
144 + public static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
145 +
146 + public static final String LSRID = "lsrId";
147 + private static final String UNKNOWN = "unknown";
148 +
124 @Activate 149 @Activate
125 public void activate() { 150 public void activate() {
126 linkProviderService = linkProviderRegistry.register(this); 151 linkProviderService = linkProviderRegistry.register(this);
127 deviceProviderService = deviceProviderRegistry.register(this); 152 deviceProviderService = deviceProviderRegistry.register(this);
128 controller.addListener(listener); 153 controller.addListener(listener);
129 controller.addLinkListener(listener); 154 controller.addLinkListener(listener);
155 + pcepClientController.addNodeListener(listener);
130 } 156 }
131 157
132 @Deactivate 158 @Deactivate
...@@ -135,6 +161,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -135,6 +161,7 @@ public class PcepTopologyProvider extends AbstractProvider
135 linkProviderService = null; 161 linkProviderService = null;
136 controller.removeListener(listener); 162 controller.removeListener(listener);
137 controller.removeLinkListener(listener); 163 controller.removeLinkListener(listener);
164 + pcepClientController.removeNodeListener(listener);
138 } 165 }
139 166
140 private List<PortDescription> buildPortDescriptions(PcepDpid dpid, 167 private List<PortDescription> buildPortDescriptions(PcepDpid dpid,
...@@ -225,7 +252,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -225,7 +252,7 @@ public class PcepTopologyProvider extends AbstractProvider
225 } 252 }
226 253
227 private class InternalLinkProvider 254 private class InternalLinkProvider
228 - implements PcepSwitchListener, PcepLinkListener { 255 + implements PcepSwitchListener, PcepLinkListener, PcepNodeListener {
229 256
230 @Override 257 @Override
231 public void switchAdded(PcepDpid dpid) { 258 public void switchAdded(PcepDpid dpid) {
...@@ -306,6 +333,51 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -306,6 +333,51 @@ public class PcepTopologyProvider extends AbstractProvider
306 } 333 }
307 } 334 }
308 335
336 + @Override
337 + public void addNode(PcepClient pc) {
338 + if (deviceProviderService == null) {
339 + return;
340 + }
341 +
342 + //Right now device URI for PCEP devices is their LSRID
343 + DeviceId deviceId = deviceId(uri(new PcepDpid(pc.getPccId().id().getIp4Address().toInt())));
344 + ChassisId cId = new ChassisId();
345 +
346 + Device.Type deviceType = Device.Type.ROUTER;
347 +
348 + DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
349 + //PCC capabilities (SR, PCECC and PCECC-SR)
350 + annotationBuilder.set(SR_CAPABILITY, String.valueOf(pc.capability().srCapability()));
351 + annotationBuilder.set(PCECC_CAPABILITY, String.valueOf(pc.capability().pceccCapability()));
352 + annotationBuilder.set(LABEL_STACK_CAPABILITY, String.valueOf(pc.capability().labelStackCapability()));
353 + //PccId is the lsrId contained in openMsg, if not present it will be the socket address
354 + annotationBuilder.set(LSRID, String.valueOf(pc.getPccId().id()));
355 +
356 + DeviceDescription description = new DefaultDeviceDescription(
357 + deviceId.uri(),
358 + deviceType,
359 + UNKNOWN,
360 + UNKNOWN,
361 + UNKNOWN,
362 + UNKNOWN,
363 + cId,
364 + annotationBuilder.build());
365 +
366 + deviceProviderService.deviceConnected(deviceId, description);
367 + }
368 +
369 + @Override
370 + public void deleteNode(PccId pccId) {
371 + if (deviceProviderService == null || deviceService == null) {
372 + return;
373 + }
374 + //TODO: In device manager, in deviceDisconnected() method, get the device but null check is not validated
375 + if (deviceService.getDevice(DeviceId.deviceId(uri(new PcepDpid(pccId.id()
376 + .getIp4Address().toInt())))) == null) {
377 + return;
378 + }
379 + deviceProviderService.deviceDisconnected(deviceId(uri(new PcepDpid(pccId.id().getIp4Address().toInt()))));
380 + }
309 } 381 }
310 382
311 @Override 383 @Override
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.pcep.topology.impl;
17 +
18 +import static org.junit.Assert.assertNotNull;
19 +
20 +import java.util.HashMap;
21 +import java.util.List;
22 +import java.util.Map;
23 +import java.util.concurrent.RejectedExecutionException;
24 +
25 +import org.jboss.netty.channel.Channel;
26 +import org.onosproject.pcep.controller.ClientCapability;
27 +import org.onosproject.pcep.controller.PccId;
28 +import org.onosproject.pcep.controller.LspKey;
29 +import org.onosproject.pcep.controller.PcepClient;
30 +import org.onosproject.pcep.controller.PcepSyncStatus;
31 +import org.onosproject.pcepio.protocol.PcepFactories;
32 +import org.onosproject.pcepio.protocol.PcepFactory;
33 +import org.onosproject.pcepio.protocol.PcepMessage;
34 +import org.onosproject.pcepio.protocol.PcepStateReport;
35 +import org.onosproject.pcepio.protocol.PcepVersion;
36 +
37 +/**
38 + * Representation of PCEP client adapter.
39 + */
40 +public class PcepClientAdapter implements PcepClient {
41 +
42 + private Channel channel;
43 + protected String channelId;
44 +
45 + private boolean connected;
46 + private PccId pccId;
47 + private ClientCapability capability;
48 +
49 + private PcepVersion pcepVersion;
50 + private PcepSyncStatus lspDbSyncStatus;
51 + private PcepSyncStatus labelDbSyncStatus;
52 + private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
53 +
54 + /**
55 + * Initialize instance with specified parameters.
56 + *
57 + * @param pccId PCC id
58 + * @param pcepVersion PCEP message version
59 + */
60 + public void init(PccId pccId, PcepVersion pcepVersion) {
61 + this.pccId = pccId;
62 + this.pcepVersion = pcepVersion;
63 + }
64 +
65 + @Override
66 + public final void disconnectClient() {
67 + this.channel.close();
68 + }
69 +
70 + @Override
71 + public final void sendMessage(PcepMessage m) {
72 + }
73 +
74 + @Override
75 + public final void sendMessage(List<PcepMessage> msgs) {
76 + try {
77 + PcepMessage pcepMsg = msgs.get(0);
78 + assertNotNull("PCEP MSG should be created.", pcepMsg);
79 + } catch (RejectedExecutionException e) {
80 + throw e;
81 + }
82 + }
83 +
84 + @Override
85 + public final boolean isConnected() {
86 + return this.connected;
87 + }
88 +
89 + @Override
90 + public String channelId() {
91 + return channelId;
92 + }
93 +
94 + @Override
95 + public final PccId getPccId() {
96 + return this.pccId;
97 + };
98 +
99 + @Override
100 + public final String getStringId() {
101 + return this.pccId.toString();
102 + }
103 +
104 + @Override
105 + public final void handleMessage(PcepMessage m) {
106 + }
107 +
108 + @Override
109 + public boolean isOptical() {
110 + return false;
111 + }
112 +
113 + @Override
114 + public PcepFactory factory() {
115 + return PcepFactories.getFactory(pcepVersion);
116 + }
117 +
118 + @Override
119 + public void setLspDbSyncStatus(PcepSyncStatus syncStatus) {
120 + this.lspDbSyncStatus = syncStatus;
121 + }
122 +
123 + @Override
124 + public PcepSyncStatus lspDbSyncStatus() {
125 + return lspDbSyncStatus;
126 + }
127 +
128 + @Override
129 + public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) {
130 + this.labelDbSyncStatus = syncStatus;
131 + }
132 +
133 + @Override
134 + public PcepSyncStatus labelDbSyncStatus() {
135 + return labelDbSyncStatus;
136 + }
137 +
138 + @Override
139 + public void setCapability(ClientCapability capability) {
140 + this.capability = capability;
141 + }
142 +
143 + @Override
144 + public ClientCapability capability() {
145 + return capability;
146 + }
147 +
148 + @Override
149 + public void addNode(PcepClient pc) {
150 + }
151 +
152 + @Override
153 + public void deleteNode(PccId pccId) {
154 + }
155 +
156 + @Override
157 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
158 + lspDelegationInfo.put(lspKey, dFlag);
159 + }
160 +
161 + @Override
162 + public Boolean delegationInfo(LspKey lspKey) {
163 + return lspDelegationInfo.get(lspKey);
164 + }
165 +
166 + @Override
167 + public void initializeSyncMsgList(PccId pccId) {
168 + // TODO Auto-generated method stub
169 +
170 + }
171 +
172 + @Override
173 + public List<PcepStateReport> getSyncMsgList(PccId pccId) {
174 + // TODO Auto-generated method stub
175 + return null;
176 + }
177 +
178 + @Override
179 + public void removeSyncMsgList(PccId pccId) {
180 + // TODO Auto-generated method stub
181 +
182 + }
183 +
184 + @Override
185 + public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
186 + // TODO Auto-generated method stub
187 +
188 + }
189 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.pcep.topology.impl;
17 +
18 +import java.util.Collection;
19 +import java.util.Collections;
20 +import java.util.HashSet;
21 +import java.util.LinkedList;
22 +import java.util.Set;
23 +import java.util.concurrent.ConcurrentHashMap;
24 +
25 +import org.apache.felix.scr.annotations.Activate;
26 +import org.apache.felix.scr.annotations.Deactivate;
27 +import org.onlab.packet.IpAddress;
28 +import org.onosproject.pcep.controller.ClientCapability;
29 +import org.onosproject.pcep.controller.PccId;
30 +import org.onosproject.pcep.controller.PcepClient;
31 +import org.onosproject.pcep.controller.PcepClientController;
32 +import org.onosproject.pcep.controller.PcepClientListener;
33 +import org.onosproject.pcep.controller.PcepEventListener;
34 +import org.onosproject.pcep.controller.PcepNodeListener;
35 +import org.onosproject.pcep.controller.PcepPacketListener;
36 +import org.onosproject.pcep.controller.driver.PcepAgent;
37 +import org.onosproject.pcepio.protocol.PcepError;
38 +import org.onosproject.pcepio.protocol.PcepErrorInfo;
39 +import org.onosproject.pcepio.protocol.PcepErrorMsg;
40 +import org.onosproject.pcepio.protocol.PcepErrorObject;
41 +import org.onosproject.pcepio.protocol.PcepFactory;
42 +import org.onosproject.pcepio.protocol.PcepMessage;
43 +import org.onosproject.pcepio.protocol.PcepVersion;
44 +
45 +import com.google.common.collect.Sets;
46 +
47 +import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
48 +import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
49 +
50 +/**
51 + * Representation of PCEP client controller adapter.
52 + */
53 +public class PcepClientControllerAdapter implements PcepClientController {
54 +
55 + protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
56 + new ConcurrentHashMap<PccId, PcepClient>();
57 +
58 + protected PcepClientAgent agent = new PcepClientAgent();
59 + protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
60 +
61 + protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
62 + public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
63 +
64 + @Activate
65 + public void activate() {
66 + }
67 +
68 + @Deactivate
69 + public void deactivate() {
70 + }
71 +
72 + @Override
73 + public Collection<PcepClient> getClients() {
74 + return connectedClients.values();
75 + }
76 +
77 + @Override
78 + public PcepClient getClient(PccId pccId) {
79 + if (null != connectedClients.get(pccId)) {
80 + return connectedClients.get(pccId);
81 + }
82 + PcepClientAdapter pc = new PcepClientAdapter();
83 + if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103))
84 + || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
85 + pc.setCapability(new ClientCapability(true, false, false, false, false));
86 + } else {
87 + pc.setCapability(new ClientCapability(true, true, true, false, false));
88 + }
89 + pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
90 + connectedClients.put(pccId, pc);
91 + return pc;
92 + }
93 +
94 + @Override
95 + public void addListener(PcepClientListener listener) {
96 + if (!pcepClientListener.contains(listener)) {
97 + this.pcepClientListener.add(listener);
98 + }
99 + }
100 +
101 + @Override
102 + public void addNodeListener(PcepNodeListener listener) {
103 + pcepNodeListener.add(listener);
104 + }
105 +
106 + @Override
107 + public void removeNodeListener(PcepNodeListener listener) {
108 + pcepNodeListener.remove(listener);
109 + }
110 +
111 + @Override
112 + public void removeListener(PcepClientListener listener) {
113 + this.pcepClientListener.remove(listener);
114 + }
115 +
116 + @Override
117 + public void addEventListener(PcepEventListener listener) {
118 + pcepEventListener.add(listener);
119 + }
120 +
121 + @Override
122 + public void removeEventListener(PcepEventListener listener) {
123 + pcepEventListener.remove(listener);
124 + }
125 +
126 + @Override
127 + public void writeMessage(PccId pccId, PcepMessage msg) {
128 + this.getClient(pccId).sendMessage(msg);
129 + }
130 +
131 + @Override
132 + public void processClientMessage(PccId pccId, PcepMessage msg) {
133 +
134 + PcepClient pc = getClient(pccId);
135 +
136 + switch (msg.getType()) {
137 + case NONE:
138 + break;
139 + case OPEN:
140 + break;
141 + case KEEP_ALIVE:
142 + //log.debug("Sending Keep Alive Message to {" + pccIpAddress.toString() + "}");
143 + pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build()));
144 + break;
145 + case PATH_COMPUTATION_REQUEST:
146 + break;
147 + case PATH_COMPUTATION_REPLY:
148 + break;
149 + case NOTIFICATION:
150 + break;
151 + case ERROR:
152 + break;
153 + case CLOSE:
154 + //log.debug("Sending Close Message to { }", pccIpAddress.toString());
155 + pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build()));
156 + break;
157 + case INITIATE:
158 + if (!pc.capability().pcInstantiationCapability()) {
159 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
160 + ERROR_TYPE_19, ERROR_VALUE_5)));
161 + }
162 + break;
163 + case REPORT:
164 + //Only update the listener if respective capability is supported else send PCEP-ERR msg
165 + if (pc.capability().statefulPceCapability()) {
166 + for (PcepEventListener l : pcepEventListener) {
167 + l.handleMessage(pccId, msg);
168 + }
169 + } else {
170 + // Send PCEP-ERROR message.
171 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
172 + ERROR_TYPE_19, ERROR_VALUE_5)));
173 + }
174 + break;
175 + case UPDATE:
176 + if (!pc.capability().statefulPceCapability()) {
177 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
178 + ERROR_TYPE_19, ERROR_VALUE_5)));
179 + }
180 + break;
181 + case LABEL_UPDATE:
182 + if (!pc.capability().pceccCapability()) {
183 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
184 + ERROR_TYPE_19, ERROR_VALUE_5)));
185 + }
186 + break;
187 + case MAX:
188 + break;
189 + case END:
190 + break;
191 + default:
192 + break;
193 + }
194 + }
195 +
196 + @Override
197 + public void closeConnectedClients() {
198 + PcepClient pc;
199 + for (PccId id : connectedClients.keySet()) {
200 + pc = getClient(id);
201 + pc.disconnectClient();
202 + }
203 + }
204 +
205 + private PcepErrorMsg getErrMsg(PcepFactory factory, byte errorType, byte errorValue) {
206 + LinkedList<PcepError> llPcepErr = new LinkedList<>();
207 +
208 + LinkedList<PcepErrorObject> llerrObj = new LinkedList<>();
209 + PcepErrorMsg errMsg;
210 +
211 + PcepErrorObject errObj = factory.buildPcepErrorObject().setErrorValue(errorValue).setErrorType(errorType)
212 + .build();
213 +
214 + llerrObj.add(errObj);
215 + PcepError pcepErr = factory.buildPcepError().setErrorObjList(llerrObj).build();
216 +
217 + llPcepErr.add(pcepErr);
218 +
219 + PcepErrorInfo errInfo = factory.buildPcepErrorInfo().setPcepErrorList(llPcepErr).build();
220 +
221 + errMsg = factory.buildPcepErrorMsg().setPcepErrorInfo(errInfo).build();
222 + return errMsg;
223 + }
224 +
225 + /**
226 + * Implementation of an Pcep Agent which is responsible for
227 + * keeping track of connected clients and the state in which
228 + * they are.
229 + */
230 + public class PcepClientAgent implements PcepAgent {
231 +
232 + @Override
233 + public boolean addConnectedClient(PccId pccId, PcepClient pc) {
234 +
235 + if (connectedClients.get(pccId) != null) {
236 + return false;
237 + } else {
238 + connectedClients.put(pccId, pc);
239 + for (PcepClientListener l : pcepClientListener) {
240 + l.clientConnected(pccId);
241 + }
242 + return true;
243 + }
244 + }
245 +
246 + @Override
247 + public boolean validActivation(PccId pccId) {
248 + if (connectedClients.get(pccId) == null) {
249 + //log.error("Trying to activate client but is not in "
250 + // + "connected switches: pccIp {}. Aborting ..", pccIpAddress.toString());
251 + return false;
252 + }
253 +
254 + return true;
255 + }
256 +
257 + @Override
258 + public void removeConnectedClient(PccId pccId) {
259 + connectedClients.remove(pccId);
260 + for (PcepClientListener l : pcepClientListener) {
261 + //log.warn("removal for {}", pccIpAddress.toString());
262 + l.clientDisconnected(pccId);
263 + }
264 + }
265 +
266 + @Override
267 + public void processPcepMessage(PccId pccId, PcepMessage m) {
268 + processClientMessage(pccId, m);
269 + }
270 +
271 + @Override
272 + public void addNode(PcepClient pc) {
273 + for (PcepNodeListener l : pcepNodeListener) {
274 + l.addNode(pc);
275 + }
276 + }
277 +
278 + @Override
279 + public void deleteNode(PccId pccId) {
280 + for (PcepNodeListener l : pcepNodeListener) {
281 + l.deleteNode(pccId);
282 + }
283 + }
284 +
285 + @Override
286 + public boolean analyzeSyncMsgList(PccId pccId) {
287 + // TODO Auto-generated method stub
288 + return false;
289 + }
290 + }
291 +
292 + @Override
293 + public void addPacketListener(PcepPacketListener listener) {
294 + // TODO Auto-generated method stub
295 +
296 + }
297 +
298 + @Override
299 + public void removePacketListener(PcepPacketListener listener) {
300 + // TODO Auto-generated method stub
301 +
302 + }
303 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.provider.pcep.topology.impl;
18 +
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.pcep.api.PcepController;
21 +import org.onosproject.pcep.api.PcepDpid;
22 +import org.onosproject.pcep.api.PcepLinkListener;
23 +import org.onosproject.pcep.api.PcepSwitch;
24 +import org.onosproject.pcep.api.PcepSwitchListener;
25 +import org.onosproject.pcep.api.PcepTunnel;
26 +import org.onosproject.pcep.api.PcepTunnelListener;
27 +
28 +/**
29 + * Implementation of PCEP controller.
30 + */
31 +public class PcepControllerAdapter implements PcepController {
32 +
33 + @Override
34 + public Iterable<PcepSwitch> getSwitches() {
35 + return null;
36 + }
37 +
38 + @Override
39 + public PcepSwitch getSwitch(PcepDpid did) {
40 + return null;
41 + }
42 +
43 + @Override
44 + public void addListener(PcepSwitchListener listener) {
45 +
46 + }
47 +
48 + @Override
49 + public void removeListener(PcepSwitchListener listener) {
50 + }
51 +
52 + @Override
53 + public void addLinkListener(PcepLinkListener listener) {
54 + }
55 +
56 + @Override
57 + public void removeLinkListener(PcepLinkListener listener) {
58 + }
59 +
60 + @Override
61 + public void addTunnelListener(PcepTunnelListener listener) {
62 + }
63 +
64 + @Override
65 + public void removeTunnelListener(PcepTunnelListener listener) {
66 + }
67 +
68 + @Override
69 + public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid, long srcPort, long dstPort, long bandwidth,
70 + String name) {
71 + return null;
72 + }
73 +
74 + @Override
75 + public Boolean deleteTunnel(String id) {
76 + return null;
77 + }
78 +
79 + @Override
80 + public Boolean updateTunnelBandwidth(String id, long bandwidth) {
81 + return null;
82 + }
83 +
84 + @Override
85 + public void getTunnelStatistics(String pcepTunnelId) {
86 +
87 + }
88 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 + * the License. You may obtain a copy of the License at
6 + *
7 + * http://www.apache.org/licenses/LICENSE-2.0
8 + *
9 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 + * specific language governing permissions and limitations under the License.
12 + */
13 +package org.onosproject.provider.pcep.topology.impl;
14 +
15 +import static org.hamcrest.MatcherAssert.assertThat;
16 +import static org.hamcrest.core.Is.is;
17 +import static org.onosproject.net.Link.State.ACTIVE;
18 +import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.LABEL_STACK_CAPABILITY;
19 +import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.LSRID;
20 +import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.PCECC_CAPABILITY;
21 +import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.SR_CAPABILITY;
22 +
23 +import java.util.Collection;
24 +import java.util.HashMap;
25 +import java.util.HashSet;
26 +import java.util.List;
27 +import java.util.Map;
28 +import java.util.Set;
29 +
30 +import org.junit.After;
31 +import org.junit.Before;
32 +import org.junit.Test;
33 +import org.onlab.packet.ChassisId;
34 +import org.onlab.packet.IpAddress;
35 +import org.onosproject.net.ConnectPoint;
36 +import org.onosproject.net.DefaultDevice;
37 +import org.onosproject.net.DefaultLink;
38 +import org.onosproject.net.Device;
39 +import org.onosproject.net.DeviceId;
40 +import org.onosproject.net.Link;
41 +import org.onosproject.net.MastershipRole;
42 +import org.onosproject.net.device.DeviceDescription;
43 +import org.onosproject.net.device.DeviceProvider;
44 +import org.onosproject.net.device.DeviceProviderRegistry;
45 +import org.onosproject.net.device.DeviceProviderService;
46 +import org.onosproject.net.device.DeviceServiceAdapter;
47 +import org.onosproject.net.device.PortDescription;
48 +import org.onosproject.net.device.PortStatistics;
49 +import org.onosproject.net.link.LinkDescription;
50 +import org.onosproject.net.link.LinkProvider;
51 +import org.onosproject.net.link.LinkProviderRegistry;
52 +import org.onosproject.net.link.LinkProviderService;
53 +import org.onosproject.net.provider.ProviderId;
54 +import org.onosproject.pcep.controller.ClientCapability;
55 +import org.onosproject.pcep.controller.PccId;
56 +import org.onosproject.pcep.controller.PcepClient;
57 +import org.onosproject.pcep.controller.PcepNodeListener;
58 +
59 +/**
60 + * Test for PCEP topology provider.
61 + */
62 +public class PcepTopologyProviderTest {
63 + private static final String UNKNOWN = new String("unknown");
64 + public static ProviderId providerId = new ProviderId("l3", "foo");
65 + private final PcepClientControllerAdapter clientController = new PcepClientControllerAdapter();
66 + private final PcepTopologyProvider provider = new PcepTopologyProvider();
67 + private final MockDeviceRegistry nodeRegistry = new MockDeviceRegistry();
68 + private final PcepControllerAdapter controller = new PcepControllerAdapter();
69 + private final MockLinkRegistry linkRegistry = new MockLinkRegistry();
70 + private final MockDeviceService deviceService = new MockDeviceService();
71 + private Map<DeviceId, Device> deviceMap = new HashMap<>();
72 +
73 + @Before
74 + public void startUp() {
75 + provider.pcepClientController = clientController;
76 + provider.deviceProviderRegistry = nodeRegistry;
77 + provider.linkProviderRegistry = linkRegistry;
78 + provider.controller = controller;
79 + provider.deviceService = deviceService;
80 + provider.activate();
81 + }
82 +
83 + @After
84 + public void tearDown() {
85 + provider.deactivate();
86 + provider.deviceProviderRegistry = null;
87 + provider.pcepClientController = null;
88 + provider.linkProviderRegistry = null;
89 + provider.controller = null;
90 + provider.deviceService = null;
91 + }
92 +
93 + /* Class implement device test registry */
94 + private class MockLinkRegistry implements LinkProviderRegistry {
95 + LinkProvider linkProvider;
96 + Set<Link> links = new HashSet<>();
97 +
98 + @Override
99 + public LinkProviderService register(LinkProvider provider) {
100 + this.linkProvider = provider;
101 + return new MockProviderService();
102 + }
103 +
104 + @Override
105 + public void unregister(LinkProvider provider) {
106 + // TODO Auto-generated method stub
107 + }
108 +
109 + @Override
110 + public Set<ProviderId> getProviders() {
111 + return null;
112 + }
113 +
114 + private class MockProviderService implements LinkProviderService {
115 +
116 + @Override
117 + public void linkDetected(LinkDescription linkDescription) {
118 + links.add(DefaultLink.builder().src(linkDescription.src())
119 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
120 + .providerId(ProviderId.NONE).build());
121 + }
122 +
123 + @Override
124 + public void linkVanished(LinkDescription linkDescription) {
125 + links.remove(DefaultLink.builder().src(linkDescription.src())
126 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
127 + .providerId(ProviderId.NONE).build());
128 + }
129 +
130 + @Override
131 + public void linksVanished(ConnectPoint connectPoint) {
132 + // TODO Auto-generated method stub
133 + }
134 +
135 + @Override
136 + public void linksVanished(DeviceId deviceId) {
137 + // TODO Auto-generated method stub
138 + }
139 +
140 + @Override
141 + public LinkProvider provider() {
142 + // TODO Auto-generated method stub
143 + return null;
144 + }
145 + }
146 + }
147 +
148 + /* Class implement device test registry */
149 + private class MockDeviceRegistry implements DeviceProviderRegistry {
150 + DeviceProvider provider;
151 +
152 + Set<DeviceId> connected = new HashSet<>();
153 +
154 + @Override
155 + public DeviceProviderService register(DeviceProvider provider) {
156 + this.provider = provider;
157 + return new MockProviderService();
158 + }
159 +
160 + @Override
161 + public void unregister(DeviceProvider provider) {
162 + }
163 +
164 + @Override
165 + public Set<ProviderId> getProviders() {
166 + return null;
167 + }
168 +
169 + private class MockProviderService implements DeviceProviderService {
170 +
171 + @Override
172 + public DeviceProvider provider() {
173 + return null;
174 + }
175 +
176 + @Override
177 + public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
178 + connected.add(deviceId);
179 + Device device = new DefaultDevice(ProviderId.NONE, deviceId, Device.Type.ROUTER, UNKNOWN, UNKNOWN,
180 + UNKNOWN, UNKNOWN, new ChassisId(), deviceDescription.annotations());
181 + deviceMap.put(deviceId, device);
182 + }
183 +
184 + @Override
185 + public void deviceDisconnected(DeviceId deviceId) {
186 + connected.remove(deviceId);
187 + deviceMap.remove(deviceId);
188 + }
189 +
190 + @Override
191 + public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
192 + // TODO Auto-generated method stub
193 + }
194 +
195 + @Override
196 + public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
197 + // TODO Auto-generated method stub
198 + }
199 +
200 + @Override
201 + public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
202 + // TODO Auto-generated method stub
203 + }
204 +
205 + @Override
206 + public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
207 + // TODO Auto-generated method stub
208 + }
209 + }
210 + }
211 +
212 + /* Mock test for device service */
213 + private class MockDeviceService extends DeviceServiceAdapter {
214 + @Override
215 + public Device getDevice(DeviceId deviceId) {
216 + return deviceMap.get(deviceId);
217 + }
218 + }
219 +
220 + /**
221 + * Adds the PCEP device and removes it.
222 + */
223 + @Test
224 + public void testPcepTopologyProviderTestAddDevice1() {
225 + PcepClient pc = clientController.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1")));
226 + for (PcepNodeListener l : clientController.pcepNodeListener) {
227 + pc.setCapability(new ClientCapability(true, true, false, true, true));
228 + l.addNode(pc);
229 + assertThat(nodeRegistry.connected.size(), is(1));
230 + assertThat(deviceMap.keySet().iterator().next(), is(DeviceId.deviceId("l3:1.1.1.1")));
231 + assertThat(deviceMap.values().iterator().next().annotations().value(LABEL_STACK_CAPABILITY), is("true"));
232 + assertThat(deviceMap.values().iterator().next().annotations().value(LSRID), is("1.1.1.1"));
233 + assertThat(deviceMap.values().iterator().next().annotations().value(PCECC_CAPABILITY), is("true"));
234 + assertThat(deviceMap.values().iterator().next().annotations().value(SR_CAPABILITY), is("true"));
235 +
236 + l.deleteNode(pc.getPccId());
237 + assertThat(nodeRegistry.connected.size(), is(0));
238 + }
239 + }
240 +}
...@@ -6,6 +6,7 @@ COMPILE_DEPS = [ ...@@ -6,6 +6,7 @@ COMPILE_DEPS = [
6 '//incubator/api:onos-incubator-api', 6 '//incubator/api:onos-incubator-api',
7 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', 7 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
8 '//protocols/pcep/api:onos-protocols-pcep-api', 8 '//protocols/pcep/api:onos-protocols-pcep-api',
9 + '//protocols/pcep/ctl:onos-protocols-pcep-ctl',
9 ] 10 ]
10 11
11 TEST_DEPS = [ 12 TEST_DEPS = [
......
...@@ -49,5 +49,10 @@ ...@@ -49,5 +49,10 @@
49 <version>${project.version} </version> 49 <version>${project.version} </version>
50 <scope>test</scope> 50 <scope>test</scope>
51 </dependency> 51 </dependency>
52 + <dependency>
53 + <groupId>org.onosproject</groupId>
54 + <artifactId>onos-pcep-controller-impl</artifactId>
55 + <version>${project.version} </version>
56 + </dependency>
52 </dependencies> 57 </dependencies>
53 </project> 58 </project>
......
...@@ -36,6 +36,7 @@ import org.onosproject.incubator.net.tunnel.OpticalLogicId; ...@@ -36,6 +36,7 @@ import org.onosproject.incubator.net.tunnel.OpticalLogicId;
36 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; 36 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
37 import org.onosproject.incubator.net.tunnel.Tunnel; 37 import org.onosproject.incubator.net.tunnel.Tunnel;
38 import org.onosproject.incubator.net.tunnel.Tunnel.State; 38 import org.onosproject.incubator.net.tunnel.Tunnel.State;
39 +import org.onosproject.incubator.net.tunnel.TunnelAdminService;
39 import org.onosproject.incubator.net.tunnel.TunnelDescription; 40 import org.onosproject.incubator.net.tunnel.TunnelDescription;
40 import org.onosproject.incubator.net.tunnel.TunnelEndPoint; 41 import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 42 import org.onosproject.incubator.net.tunnel.TunnelId;
...@@ -45,11 +46,14 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; ...@@ -45,11 +46,14 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
45 import org.onosproject.incubator.net.tunnel.TunnelProviderService; 46 import org.onosproject.incubator.net.tunnel.TunnelProviderService;
46 import org.onosproject.incubator.net.tunnel.TunnelService; 47 import org.onosproject.incubator.net.tunnel.TunnelService;
47 import org.onosproject.incubator.net.tunnel.TunnelStatistics; 48 import org.onosproject.incubator.net.tunnel.TunnelStatistics;
49 +import org.onosproject.mastership.MastershipService;
50 +import org.onosproject.net.AnnotationKeys;
48 import org.onosproject.net.ConnectPoint; 51 import org.onosproject.net.ConnectPoint;
49 import org.onosproject.net.DefaultAnnotations; 52 import org.onosproject.net.DefaultAnnotations;
50 import org.onosproject.net.DefaultAnnotations.Builder; 53 import org.onosproject.net.DefaultAnnotations.Builder;
51 import org.onosproject.net.DefaultLink; 54 import org.onosproject.net.DefaultLink;
52 import org.onosproject.net.DefaultPath; 55 import org.onosproject.net.DefaultPath;
56 +import org.onosproject.net.Device;
53 import org.onosproject.net.DeviceId; 57 import org.onosproject.net.DeviceId;
54 import org.onosproject.net.ElementId; 58 import org.onosproject.net.ElementId;
55 import org.onosproject.net.IpElementId; 59 import org.onosproject.net.IpElementId;
...@@ -57,6 +61,7 @@ import org.onosproject.net.Link; ...@@ -57,6 +61,7 @@ import org.onosproject.net.Link;
57 import org.onosproject.net.Path; 61 import org.onosproject.net.Path;
58 import org.onosproject.net.PortNumber; 62 import org.onosproject.net.PortNumber;
59 import org.onosproject.net.SparseAnnotations; 63 import org.onosproject.net.SparseAnnotations;
64 +import org.onosproject.net.device.DeviceService;
60 import org.onosproject.net.provider.AbstractProvider; 65 import org.onosproject.net.provider.AbstractProvider;
61 import org.onosproject.net.provider.ProviderId; 66 import org.onosproject.net.provider.ProviderId;
62 import org.onosproject.pcep.api.PcepController; 67 import org.onosproject.pcep.api.PcepController;
...@@ -68,12 +73,14 @@ import org.onosproject.pcep.api.PcepTunnel.PathState; ...@@ -68,12 +73,14 @@ import org.onosproject.pcep.api.PcepTunnel.PathState;
68 import org.onosproject.pcep.api.PcepTunnel.PathType; 73 import org.onosproject.pcep.api.PcepTunnel.PathType;
69 import org.onosproject.pcep.api.PcepTunnelListener; 74 import org.onosproject.pcep.api.PcepTunnelListener;
70 import org.onosproject.pcep.api.PcepTunnelStatistics; 75 import org.onosproject.pcep.api.PcepTunnelStatistics;
76 +import org.onosproject.pcep.controller.LspKey;
71 import org.onosproject.pcep.controller.PccId; 77 import org.onosproject.pcep.controller.PccId;
72 import org.onosproject.pcep.controller.PcepClient; 78 import org.onosproject.pcep.controller.PcepClient;
73 import org.onosproject.pcep.controller.PcepClientController; 79 import org.onosproject.pcep.controller.PcepClientController;
74 import org.onosproject.pcep.controller.PcepClientListener; 80 import org.onosproject.pcep.controller.PcepClientListener;
75 import org.onosproject.pcep.controller.PcepEventListener; 81 import org.onosproject.pcep.controller.PcepEventListener;
76 -import org.onosproject.pcep.controller.PcepSyncStatus; 82 +import org.onosproject.pcep.controller.PcepLspSyncAction;
83 +import org.onosproject.pcep.controller.impl.PcepLspStatus;
77 import org.onosproject.pcepio.exceptions.PcepParseException; 84 import org.onosproject.pcepio.exceptions.PcepParseException;
78 import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; 85 import org.onosproject.pcepio.protocol.PcInitiatedLspRequest;
79 import org.onosproject.pcepio.protocol.PcepAttribute; 86 import org.onosproject.pcepio.protocol.PcepAttribute;
...@@ -83,6 +90,7 @@ import org.onosproject.pcepio.protocol.PcepEroObject; ...@@ -83,6 +90,7 @@ import org.onosproject.pcepio.protocol.PcepEroObject;
83 import org.onosproject.pcepio.protocol.PcepInitiateMsg; 90 import org.onosproject.pcepio.protocol.PcepInitiateMsg;
84 import org.onosproject.pcepio.protocol.PcepLspObject; 91 import org.onosproject.pcepio.protocol.PcepLspObject;
85 import org.onosproject.pcepio.protocol.PcepMessage; 92 import org.onosproject.pcepio.protocol.PcepMessage;
93 +import org.onosproject.pcepio.protocol.PcepMetricObject;
86 import org.onosproject.pcepio.protocol.PcepMsgPath; 94 import org.onosproject.pcepio.protocol.PcepMsgPath;
87 import org.onosproject.pcepio.protocol.PcepReportMsg; 95 import org.onosproject.pcepio.protocol.PcepReportMsg;
88 import org.onosproject.pcepio.protocol.PcepSrpObject; 96 import org.onosproject.pcepio.protocol.PcepSrpObject;
...@@ -107,8 +115,10 @@ import java.util.HashMap; ...@@ -107,8 +115,10 @@ import java.util.HashMap;
107 import java.util.LinkedList; 115 import java.util.LinkedList;
108 import java.util.List; 116 import java.util.List;
109 import java.util.ListIterator; 117 import java.util.ListIterator;
110 -import java.util.Map;
111 import java.util.Optional; 118 import java.util.Optional;
119 +import java.util.concurrent.Executors;
120 +import java.util.concurrent.ScheduledExecutorService;
121 +import java.util.concurrent.TimeUnit;
112 122
113 import static com.google.common.base.Preconditions.checkNotNull; 123 import static com.google.common.base.Preconditions.checkNotNull;
114 import static com.google.common.base.Strings.isNullOrEmpty; 124 import static com.google.common.base.Strings.isNullOrEmpty;
...@@ -125,14 +135,18 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL ...@@ -125,14 +135,18 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL
125 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; 135 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
126 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID; 136 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
127 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID; 137 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
128 -import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCE_INIT; 138 +import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
139 +import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.COST_TYPE;
129 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE; 140 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
130 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE; 141 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
131 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT; 142 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
132 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE; 143 import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE;
133 -import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
134 -import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
135 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; 144 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
145 +import static org.onosproject.pcep.controller.PcepLspSyncAction.REMOVE;
146 +import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_UPDATE;
147 +import static org.onosproject.pcep.controller.PcepLspSyncAction.SEND_DELETE;
148 +import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.IGP_METRIC;
149 +import static org.onosproject.pcepio.protocol.ver1.PcepMetricObjectVer1.TE_METRIC;
136 import static org.slf4j.LoggerFactory.getLogger; 150 import static org.slf4j.LoggerFactory.getLogger;
137 151
138 /** 152 /**
...@@ -148,6 +162,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -148,6 +162,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
148 private static final long MIN_BANDWIDTH = 64; 162 private static final long MIN_BANDWIDTH = 64;
149 private static final String BANDWIDTH_UINT = "kbps"; 163 private static final String BANDWIDTH_UINT = "kbps";
150 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; 164 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
165 + public static final long IDENTIFIER_SET = 0x100000000L;
166 + public static final long SET = 0xFFFFFFFFL;
167 + private static final int DELAY = 2;
168 + private static final int WAIT_TIME = 5;
169 + public static final String LSRID = "lsrId";
151 170
152 static final int POLL_INTERVAL = 10; 171 static final int POLL_INTERVAL = 10;
153 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL, 172 @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL,
...@@ -171,6 +190,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -171,6 +190,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 190 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
172 protected ComponentConfigService cfgService; 191 protected ComponentConfigService cfgService;
173 192
193 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
194 + protected TunnelAdminService tunnelAdminService;
195 +
196 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
197 + protected MastershipService mastershipService;
198 +
199 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
200 + protected DeviceService deviceService;
201 +
174 TunnelProviderService service; 202 TunnelProviderService service;
175 203
176 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); 204 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
...@@ -182,10 +210,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -182,10 +210,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
182 protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper(); 210 protected PcepTunnelApiMapper pcepTunnelApiMapper = new PcepTunnelApiMapper();
183 private static final int DEFAULT_BANDWIDTH_VALUE = 10; 211 private static final int DEFAULT_BANDWIDTH_VALUE = 10;
184 212
185 - private Map<IpAddress, Map<TunnelId, Tunnel>> preSyncLspDbMap = new HashMap<>();
186 - private Map<IpAddress, List<Tunnel>> syncCompleteDeleteList = new HashMap<>();
187 - private Map<IpAddress, List<Tunnel>> syncCompleteUpdateList = new HashMap<>();
188 -
189 /** 213 /**
190 * Creates a Tunnel provider. 214 * Creates a Tunnel provider.
191 */ 215 */
...@@ -263,7 +287,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -263,7 +287,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
263 } 287 }
264 288
265 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg 289 //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
266 - if (pc.capability().pcInstantiationCapability()) { 290 + //Only master will initiate setup tunnel
291 + if (pc.capability().pcInstantiationCapability() && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
267 pcepSetupTunnel(tunnel, path, pc); 292 pcepSetupTunnel(tunnel, path, pc);
268 } 293 }
269 } 294 }
...@@ -300,7 +325,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -300,7 +325,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
300 return; 325 return;
301 } 326 }
302 327
303 - if (pc.capability().pcInstantiationCapability()) { 328 + //If stateful and PC Initiation capability is not supported by client not sending Initiate msg
329 + //Only master will initiate setup tunnel
330 + if (pc.capability().pcInstantiationCapability()
331 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
304 pcepSetupTunnel(tunnel, path, pc); 332 pcepSetupTunnel(tunnel, path, pc);
305 } 333 }
306 } 334 }
...@@ -327,7 +355,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -327,7 +355,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
327 return; 355 return;
328 } 356 }
329 357
330 - if (pc.capability().pcInstantiationCapability()) { 358 + //Only master will release tunnel
359 + if (pc.capability().pcInstantiationCapability()
360 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
331 pcepReleaseTunnel(tunnel, pc); 361 pcepReleaseTunnel(tunnel, pc);
332 } 362 }
333 } 363 }
...@@ -358,7 +388,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -358,7 +388,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
358 return; 388 return;
359 } 389 }
360 390
361 - if (pc.capability().pcInstantiationCapability()) { 391 + //Only master will release tunnel
392 + if (pc.capability().pcInstantiationCapability()
393 + && mastershipService.isLocalMaster(getDevice(pc.getPccId()))) {
362 pcepReleaseTunnel(tunnel, pc); 394 pcepReleaseTunnel(tunnel, pc);
363 } 395 }
364 } 396 }
...@@ -384,7 +416,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -384,7 +416,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
384 return; 416 return;
385 } 417 }
386 418
387 - if (pc.capability().statefulPceCapability()) { 419 + // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
420 + // LSP].If annotation is null D flag is not set else it is set.
421 + if (pc.capability().statefulPceCapability()
422 + && pc.delegationInfo(
423 + new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
424 + .annotations().value(LOCAL_LSP_ID)))) != null) {
388 pcepUpdateTunnel(tunnel, path, pc); 425 pcepUpdateTunnel(tunnel, path, pc);
389 } 426 }
390 } 427 }
...@@ -416,7 +453,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -416,7 +453,12 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
416 return; 453 return;
417 } 454 }
418 455
419 - if (pc.capability().statefulPceCapability()) { 456 + // If delegation flag is set then only send update message[means delegated PCE can send update msg for that
457 + // LSP].If annotation is null D flag is not set else it is set.
458 + if (pc.capability().statefulPceCapability()
459 + && pc.delegationInfo(
460 + new LspKey(Integer.valueOf(tunnel.annotations().value(PLSP_ID)), Short.valueOf(tunnel
461 + .annotations().value(LOCAL_LSP_ID)))) != null) {
420 pcepUpdateTunnel(tunnel, path, pc); 462 pcepUpdateTunnel(tunnel, path, pc);
421 } 463 }
422 } 464 }
...@@ -480,6 +522,43 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -480,6 +522,43 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
480 return tunnelId; 522 return tunnelId;
481 } 523 }
482 524
525 + private void tunnelUpdated(Tunnel tunnel, Path path) {
526 + handleTunnelUpdate(tunnel, path);
527 + }
528 +
529 + //Handles tunnel updated using tunnel admin service[specially to update annotations].
530 + private void handleTunnelUpdate(Tunnel tunnel, Path path) {
531 +
532 + if (tunnel.type() == MPLS) {
533 + pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.tunnelId());
534 +
535 + tunnelAdminService.updateTunnel(tunnel, path);
536 +
537 + return;
538 + }
539 +
540 + Tunnel tunnelOld = tunnelQueryById(tunnel.tunnelId());
541 + if (tunnelOld.type() != Tunnel.Type.VLAN) {
542 + error("Illegal tunnel type. Only support VLAN tunnel update.");
543 + return;
544 + }
545 +
546 + long bandwidth = Long
547 + .parseLong(tunnel.annotations().value("bandwidth"));
548 + if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
549 + error("Update failed, invalid bandwidth.");
550 + return;
551 + }
552 + String pcepTunnelId = getPcepTunnelKey(tunnel.tunnelId());
553 +
554 + checkNotNull(pcepTunnelId, "Invalid tunnel id");
555 + if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) {
556 + error("Update failed,maybe invalid bandwidth.");
557 + return;
558 + }
559 + tunnelAdminService.updateTunnel(tunnel, path);
560 + }
561 +
483 @Override 562 @Override
484 public void tunnelRemoved(TunnelDescription tunnel) { 563 public void tunnelRemoved(TunnelDescription tunnel) {
485 if (tunnel.type() == MPLS) { 564 if (tunnel.type() == MPLS) {
...@@ -681,7 +760,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -681,7 +760,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
681 path, 760 path,
682 annotations); 761 annotations);
683 return tunnel; 762 return tunnel;
684 -
685 } 763 }
686 764
687 /** 765 /**
...@@ -1098,41 +1176,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1098,41 +1176,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1098 log.debug("SRP ID in handle message " + srpId); 1176 log.debug("SRP ID in handle message " + srpId);
1099 1177
1100 if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) { 1178 if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
1101 - 1179 + // For PCRpt without matching SRP id.
1102 - // Check the sync status 1180 + handleRptWithoutSrpId(stateRpt, pccId);
1103 - if (lspObj.getSFlag()) {
1104 - if (pcepClientController.getClient(pccId).lspDbSyncStatus() != IN_SYNC) {
1105 - pcepClientController.getClient(pccId).setLspDbSyncStatus(IN_SYNC);
1106 -
1107 - // On starting LSP-DB sync, store LSP DB locally for this PCC.
1108 - Map<TunnelId, Tunnel> preSyncLspDb = new HashMap<>();
1109 - Collection<Tunnel> queriedTunnels = tunnelService.queryTunnel(MPLS);
1110 -
1111 - for (Tunnel tunnel : queriedTunnels) {
1112 - if (((IpTunnelEndPoint) tunnel.src()).ip().equals(pccId.ipAddress())) {
1113 - preSyncLspDb.put(tunnel.tunnelId(), tunnel);
1114 - }
1115 - }
1116 -
1117 - preSyncLspDbMap.put(pccId.ipAddress(), preSyncLspDb);
1118 - syncCompleteDeleteList.put(pccId.ipAddress(), new LinkedList<>());
1119 - syncCompleteUpdateList.put(pccId.ipAddress(), new LinkedList<>());
1120 - }
1121 - handleRptWithoutSrpId(stateRpt, pccId, IN_SYNC);
1122 - continue;
1123 -
1124 - } else if (pcepClientController.getClient(pccId).lspDbSyncStatus() == IN_SYNC) {
1125 - // If sync flag is not set in the msg, and the
1126 - // previous state was "in sync" means this is
1127 - // end of sync message. PCRpt for end of sync
1128 - // does not carry any LSP report.
1129 - pcepClientController.getClient(pccId).setLspDbSyncStatus(SYNCED);
1130 - handleEndOfSyncAction(pccId);
1131 - continue;
1132 - }
1133 -
1134 - // For PCRpt without matching SRP id not during LSPDB sync.
1135 - handleRptWithoutSrpId(stateRpt, pccId, SYNCED);
1136 continue; 1181 continue;
1137 } 1182 }
1138 1183
...@@ -1226,27 +1271,30 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1226,27 +1271,30 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1226 } 1271 }
1227 } 1272 }
1228 1273
1229 - private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId, PcepSyncStatus syncStatus) { 1274 + private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv,
1230 - ProviderId providerId = new ProviderId("pcep", PROVIDER_ID); 1275 + float bandwidth, LspType lspType, String costType) {
1231 - PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
1232 - checkNotNull(msgPath);
1233 - PcepEroObject eroObj = msgPath.getEroObject();
1234 - if (eroObj == null) {
1235 - log.error("ERO object is null in report message.");
1236 - return;
1237 - }
1238 - Path path = buildPathFromEroObj(eroObj, providerId);
1239 1276
1240 - int bandwidth = 0; 1277 + Builder builder = DefaultAnnotations.builder();
1241 - if (msgPath.getBandwidthObject() != null) {
1242 - bandwidth = msgPath.getBandwidthObject().getBandwidth();
1243 - }
1244 1278
1245 /* 1279 /*
1246 - * To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action 1280 + * [RFC 5440] The absence of the METRIC object MUST be interpreted by the PCE as a path computation request
1247 - * from PCE. 1281 + * for which no constraints need be applied to any of the metrics.
1248 */ 1282 */
1249 - PcepSrpObject srpObj = stateRpt.getSrpObject(); 1283 + if (costType != null) {
1284 + builder.set(COST_TYPE, costType);
1285 + }
1286 +
1287 + SparseAnnotations annotations = builder
1288 + .set(BANDWIDTH, (new Float(bandwidth)).toString()).set(LSP_SIG_TYPE, lspType.name())
1289 + .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1290 + .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1291 + .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId()))
1292 + .set(DELEGATE, String.valueOf(lspObj.getDFlag()))
1293 + .build();
1294 + return annotations;
1295 + }
1296 +
1297 + private LspType getLspType(PcepSrpObject srpObj) {
1250 LspType lspType = WITH_SIGNALLING; 1298 LspType lspType = WITH_SIGNALLING;
1251 1299
1252 if (null != srpObj) { 1300 if (null != srpObj) {
...@@ -1266,6 +1314,55 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1266,6 +1314,55 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1266 } 1314 }
1267 } 1315 }
1268 } 1316 }
1317 + return lspType;
1318 + }
1319 +
1320 + private void handleRptWithoutSrpId(PcepStateReport stateRpt, PccId pccId) {
1321 + ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
1322 + String costType = null;
1323 + PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
1324 + checkNotNull(msgPath);
1325 + PcepEroObject eroObj = msgPath.getEroObject();
1326 + if (eroObj == null) {
1327 + log.error("ERO object is null in report message.");
1328 + return;
1329 + }
1330 +
1331 + PcepAttribute attributes = msgPath.getPcepAttribute();
1332 + int cost = 0;
1333 + if (attributes != null && attributes.getMetricObjectList() != null) {
1334 + ListIterator<PcepMetricObject> iterator = attributes.getMetricObjectList().listIterator();
1335 + PcepMetricObject metricObj = iterator.next();
1336 +
1337 + while (metricObj != null) {
1338 + if (metricObj.getBType() == IGP_METRIC) {
1339 + costType = "COST";
1340 + } else if (metricObj.getBType() == TE_METRIC) {
1341 + costType = "TE_COST";
1342 + }
1343 +
1344 + if (costType != null) {
1345 + cost = metricObj.getMetricVal();
1346 + log.debug("Path cost {}", cost);
1347 + break;
1348 + }
1349 + metricObj = iterator.next();
1350 + }
1351 + }
1352 +
1353 + Path path = buildPathFromEroObj(eroObj, providerId, cost);
1354 +
1355 + float bandwidth = 0;
1356 + if (msgPath.getBandwidthObject() != null) {
1357 + bandwidth = msgPath.getBandwidthObject().getBandwidth();
1358 + }
1359 +
1360 + /*
1361 + * To carry PST TLV, SRP object can be present with value 0 even when PCRpt is not in response to any action
1362 + * from PCE.
1363 + */
1364 + PcepSrpObject srpObj = stateRpt.getSrpObject();
1365 + LspType lspType = getLspType(srpObj);
1269 1366
1270 PcepLspObject lspObj = stateRpt.getLspObject(); 1367 PcepLspObject lspObj = stateRpt.getLspObject();
1271 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator(); 1368 ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
...@@ -1287,7 +1384,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1287,7 +1384,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1287 break; 1384 break;
1288 } 1385 }
1289 } 1386 }
1290 -
1291 /* 1387 /*
1292 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for 1388 * Draft says: The LSP-IDENTIFIERS TLV MUST be included in the LSP object in PCRpt messages for
1293 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory. 1389 * RSVP-signaled LSPs. For ONOS PCECC implementation, it is mandatory.
...@@ -1303,6 +1399,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1303,6 +1399,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1303 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress())); 1399 .ipTunnelPoint(IpAddress.valueOf(ipv4LspIdenTlv.getIpv4EgressAddress()));
1304 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst); 1400 Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
1305 1401
1402 + // Store delegation flag info and that LSP info because only delegated PCE sends update message
1403 + // Storing if D flag is set, if not dont store. while checking whether delegation if annotation for D flag
1404 + // not present then non-delegated , if present it is delegated.
1405 + if (lspObj.getDFlag()) {
1406 + pcepClientController.getClient(pccId).setLspAndDelegationInfo(
1407 + new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId()), lspObj.getDFlag());
1408 + }
1409 +
1306 Tunnel tunnel = null; 1410 Tunnel tunnel = null;
1307 // Asynchronous status change message from PCC for LSP reported earlier. 1411 // Asynchronous status change message from PCC for LSP reported earlier.
1308 for (Tunnel tunnelObj : tunnelQueryResult) { 1412 for (Tunnel tunnelObj : tunnelQueryResult) {
...@@ -1321,7 +1425,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1321,7 +1425,6 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1321 } 1425 }
1322 continue; 1426 continue;
1323 } 1427 }
1324 -
1325 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId()) && (Integer 1428 if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId()) && (Integer
1326 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) { 1429 .valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID)) == ipv4LspIdenTlv.getLspId())) {
1327 tunnel = tunnelObj; 1430 tunnel = tunnelObj;
...@@ -1330,6 +1433,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1330,6 +1433,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1330 } 1433 }
1331 1434
1332 DefaultTunnelDescription td; 1435 DefaultTunnelDescription td;
1436 + SparseAnnotations annotations = null;
1333 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]); 1437 State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
1334 if (tunnel == null) { 1438 if (tunnel == null) {
1335 if (lspObj.getRFlag()) { 1439 if (lspObj.getRFlag()) {
...@@ -1340,91 +1444,96 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1340,91 +1444,96 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1340 return; 1444 return;
1341 } 1445 }
1342 1446
1343 - if (lspObj.getCFlag()) { 1447 + DeviceId deviceId = getDevice(pccId);
1344 - /* 1448 + if (deviceId == null) {
1345 - * While in sync, if PCRpt is received for PCE init LSP and PCE doesn't have entry, mark to send 1449 + log.error("Ingress deviceId not found");
1346 - * delete message on end of sync. 1450 + return;
1347 - */ 1451 + }
1348 - SparseAnnotations annotations = DefaultAnnotations.builder() 1452 + annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
1349 - .set(BANDWIDTH, (new Integer(bandwidth)).toString())
1350 - .set(LSP_SIG_TYPE, lspType.name())
1351 - .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId()))
1352 - .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
1353 - .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId())).build();
1354 -
1355 - // Gnenerate tunnel id for the temporary tunnel.
1356 - String onosTunnelId = "PCC" + String.valueOf(ipv4LspIdenTlv.getTunnelId());
1357 - Tunnel tunnelToBeDeleted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1358 - new DefaultGroupId(0), TunnelId.valueOf(onosTunnelId),
1359 - TunnelName.tunnelName(String
1360 - .valueOf(pathNameTlv.getValue())),
1361 - path, annotations);
1362 1453
1363 - /* 1454 + td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
1364 - * Need to send PCInitiate delete msg for a tunnel which does not exist at PCE. For that some dummy 1455 + 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
1365 - * data-structures need to be populated. 1456 + annotations);
1366 - */
1367 - PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelToBeDeleted, path, RequestType.DELETE);
1368 - pcepTunnelData.setPlspId(lspObj.getPlspId());
1369 - pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1370 - pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1371 - pcepTunnelApiMapper.handleCreateTunnelRequestQueue(0, pcepTunnelData);
1372 1457
1373 - /* 1458 + // Do not support PCC initiated LSP after LSP DB sync is completed.
1374 - * Add to the list of tunnels for which PCInit delete will be sent at the end of sync. 1459 + if (!lspObj.getSFlag() && !lspObj.getCFlag()) {
1375 - */ 1460 + log.error("Received PCC initiated LSP while not in sync.");
1376 - List<Tunnel> tunnelToBeDeletedList = syncCompleteDeleteList.get(pccId.ipAddress());
1377 - tunnelToBeDeletedList.add(tunnelToBeDeleted);
1378 - syncCompleteDeleteList.put(pccId.ipAddress(), tunnelToBeDeletedList);
1379 return; 1461 return;
1380 } 1462 }
1381 1463
1382 - SparseAnnotations annotations = DefaultAnnotations.builder() 1464 + /*
1383 - .set(BANDWIDTH, (new Integer(bandwidth)).toString()) 1465 + * If ONOS instance is master for PCC then set delegated flag as annotation and add the tunnel to store.
1384 - .set(LSP_SIG_TYPE, lspType.name()) 1466 + * Because all LSPs need not be delegated, hence mastership for the PCC is confirmed whereas not the
1385 - .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId())) 1467 + * delegation set to all LSPs.If ONOS is not the master for that PCC then check if D flag is set, if yes
1386 - .set(PLSP_ID, String.valueOf(lspObj.getPlspId())) 1468 + * wait for 2 seconds [while master has added the tunnel to the store] then update the tunnel. Tunnel is
1387 - .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId())).build(); 1469 + * updated because in case of resilency only delegated LSPs are recomputed and only delegated PCE can
1388 - 1470 + * send update message to that client.
1389 - td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, 1471 + *
1390 - new DefaultGroupId(0), providerId, 1472 + * 1)Master can 1st get the Rpt message
1391 - TunnelName.tunnelName(String.valueOf(pathNameTlv.getValue())), path, 1473 + * a)Master adds the tunnel into core.
1392 - annotations); 1474 + * b)If a non-master for ingress gets Rpt message with D flag set[as delegation owner]
1393 - 1475 + * after master, then runs timer then update the tunnel with D flag set.
1394 - TunnelId tId = tunnelAdded(td, tunnelState); 1476 + * 2)Non-Master can 1st get the Rpt message
1395 - Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS, 1477 + * a)Non-Master runs the timer check for the tunnel then updates the tunnel with D flag set
1396 - tunnelState, new DefaultGroupId(0), tId, 1478 + * b)Master would have got the message while the non-master running timer, hence master adds
1397 - TunnelName.tunnelName(String.valueOf(pathNameTlv.getValue())), 1479 + * tunnel to core
1398 - path, annotations); 1480 + *
1399 - 1481 + * In general always master adds the tunnel to the core
1400 - PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT); 1482 + * while delegated owner [master or non-master with D flag set] always updates the tunnel running timer
1401 - pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv); 1483 + */
1402 - pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 1484 + if (mastershipService.isLocalMaster(deviceId)) {
1485 + TunnelId tId = tunnelAdded(td, tunnelState);
1486 + Tunnel tunnelInserted = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
1487 + tunnelState, new DefaultGroupId(0), tId, TunnelName.tunnelName(String.valueOf(pathNameTlv
1488 + .getValue())), path, annotations);
1489 +
1490 + PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnelInserted, path, LSP_STATE_RPT);
1491 + pcepTunnelData.setStatefulIpv4IndentifierTlv(ipv4LspIdenTlv);
1492 + pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
1493 + } else if (!mastershipService.isLocalMaster(deviceId) && lspObj.getDFlag()) {
1494 + //Start timer then update the tunnel with D flag
1495 + tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
1496 + }
1403 return; 1497 return;
1404 } 1498 }
1405 1499
1406 - if ((syncStatus == IN_SYNC) && (lspObj.getCFlag()) && (tunnelState != tunnel.state())) { 1500 + //delegated owner will update can be a master or non-master
1407 - // Mark to send PCUpd msg with state known at PCE. 1501 + if (lspObj.getDFlag()) {
1408 - List<Tunnel> tunnelToBeUpdateList = syncCompleteUpdateList.get(pccId.ipAddress()); 1502 + annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
1409 - tunnelToBeUpdateList.add(tunnel); 1503 + td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
1410 - syncCompleteUpdateList.put(pccId.ipAddress(), tunnelToBeUpdateList); 1504 + 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path,
1411 - return; 1505 + annotations);
1506 + tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
1412 } 1507 }
1508 + removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState);
1509 + return;
1510 + }
1413 1511
1414 - td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(), 1512 + private void removeOrUpdatetunnel(Tunnel tunnel, PccId pccId, PcepLspObject lspObj, ProviderId providerId,
1415 - tunnel.type(), tunnel.groupId(), providerId, 1513 + State tunnelState) {
1416 - tunnel.tunnelName(), tunnel.path(), 1514 + DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(), tunnel.dst(),
1417 - (SparseAnnotations) tunnel.annotations()); 1515 + tunnel.type(), tunnel.groupId(), providerId, tunnel.tunnelName(), tunnel.path(),
1418 - 1516 + (SparseAnnotations) tunnel.annotations());
1419 if (lspObj.getRFlag()) { 1517 if (lspObj.getRFlag()) {
1420 tunnelRemoved(td); 1518 tunnelRemoved(td);
1421 } else { 1519 } else {
1422 - if (syncStatus == IN_SYNC) {
1423 - markLspDbEntryAsLatest(pccId, tunnel.tunnelId());
1424 - }
1425 tunnelUpdated(td, tunnelState); 1520 tunnelUpdated(td, tunnelState);
1426 } 1521 }
1427 - return; 1522 + }
1523 +
1524 + private void tunnelUpdateInDelegatedCase(PccId pccId, SparseAnnotations annotations,
1525 + DefaultTunnelDescription td, ProviderId providerId) {
1526 + //Wait for 2sec then query tunnel based on ingress PLSP-ID and local LSP-ID
1527 +
1528 + /*
1529 + * If ONOS is not the master for that PCC then check if D flag is set, if yes wait [while
1530 + * master has added the tunnel to the store] then update the tunnel.
1531 + */
1532 + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
1533 +
1534 + // Thread is started after 2 seconds first time later periodically after 2 seconds to update the tunnel
1535 + executor.scheduleAtFixedRate(new UpdateDelegation(td, providerId, annotations, pccId,
1536 + executor), DELAY, DELAY, TimeUnit.SECONDS);
1428 } 1537 }
1429 1538
1430 /** 1539 /**
...@@ -1432,9 +1541,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1432,9 +1541,10 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1432 * 1541 *
1433 * @param eroObj ERO object 1542 * @param eroObj ERO object
1434 * @param providerId provider id 1543 * @param providerId provider id
1544 + * @param cost cost of path
1435 * @return path object 1545 * @return path object
1436 */ 1546 */
1437 - private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) { 1547 + private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId, int cost) {
1438 checkNotNull(eroObj); 1548 checkNotNull(eroObj);
1439 List<Link> links = new ArrayList<Link>(); 1549 List<Link> links = new ArrayList<Link>();
1440 LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects(); 1550 LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
...@@ -1474,7 +1584,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1474,7 +1584,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1474 // the other sub objects are not required 1584 // the other sub objects are not required
1475 } 1585 }
1476 } 1586 }
1477 - return new DefaultPath(providerId, links, 0, EMPTY); 1587 +
1588 + return new DefaultPath(providerId, links, cost, EMPTY);
1478 } 1589 }
1479 1590
1480 @Override 1591 @Override
...@@ -1493,44 +1604,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1493,44 +1604,14 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1493 TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics); 1604 TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics);
1494 tunnelStatisticsMap.put(id, tunnelStatistics); 1605 tunnelStatisticsMap.put(id, tunnelStatistics);
1495 } 1606 }
1496 - }
1497 -
1498 - @Override
1499 - public Tunnel tunnelQueryById(TunnelId tunnelId) {
1500 - return service.tunnelQueryById(tunnelId);
1501 - }
1502 -
1503 - /**
1504 - * Removes the entry from temporary copy of LSPDB, signifying its status as upto date.
1505 - *
1506 - * @param pccId the key for temporary LSPDB
1507 - * @param tunnelId the tunnel id for which information is updated.
1508 - */
1509 - private void markLspDbEntryAsLatest(PccId pccId, TunnelId tunnelId) {
1510 - checkNotNull(pccId);
1511 - checkNotNull(tunnelId);
1512 -
1513 - Map<TunnelId, Tunnel> preSyncLspDb = preSyncLspDbMap.get(pccId.ipAddress());
1514 - checkNotNull(preSyncLspDb);
1515 1607
1516 - preSyncLspDb.remove(tunnelId); 1608 + @Override
1517 - preSyncLspDbMap.put(pccId.ipAddress(), preSyncLspDb); 1609 + public void handleEndOfSyncAction(Tunnel tunnel, PcepLspSyncAction endOfSyncAction) {
1518 - }
1519 -
1520 - /**
1521 - * Sends PCInit, PCInit(R) or PCUpd messages for initiated LSPs at the end
1522 - * of LSP DB sync based on actions decided while sync was in progress. Also
1523 - * triggers label DB sync.
1524 - *
1525 - * @param pccId the key for temporary DBs storing required end of sync
1526 - * actions.
1527 - */
1528 - private void handleEndOfSyncAction(PccId pccId) {
1529 -
1530 - Map<TunnelId, Tunnel> preSyncLspDb = preSyncLspDbMap.get(pccId.ipAddress());
1531 - checkNotNull(preSyncLspDb);
1532 1610
1533 - for (Tunnel tunnel : preSyncLspDb.values()) { 1611 + if (endOfSyncAction == SEND_UPDATE) {
1612 + updateTunnel(tunnel, tunnel.path());
1613 + return;
1614 + }
1534 1615
1535 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), 1616 TunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(),
1536 tunnel.src(), tunnel.dst(), 1617 tunnel.src(), tunnel.dst(),
...@@ -1541,41 +1622,133 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1541,41 +1622,133 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1541 tunnel.path(), 1622 tunnel.path(),
1542 (SparseAnnotations) tunnel.annotations()); 1623 (SparseAnnotations) tunnel.annotations());
1543 1624
1544 - if ((tunnel.annotations().value(PCE_INIT) == null)
1545 - || (tunnel.annotations().value(PCE_INIT).equals("false"))) {
1546 1625
1547 - tunnelRemoved(td); 1626 + if (endOfSyncAction == PcepLspSyncAction.UNSTABLE) {
1548 - } else { 1627 +
1549 // Send PCInit msg again after global reoptimization. 1628 // Send PCInit msg again after global reoptimization.
1550 tunnelUpdated(td, UNSTABLE); 1629 tunnelUpdated(td, UNSTABLE);
1551 1630
1552 // To remove the old tunnel from store whose PLSPID is not 1631 // To remove the old tunnel from store whose PLSPID is not
1553 // recognized by ingress PCC. 1632 // recognized by ingress PCC.
1554 tunnelRemoved(td); 1633 tunnelRemoved(td);
1634 +
1635 + } else if (endOfSyncAction == REMOVE) {
1636 + tunnelRemoved(td);
1555 } 1637 }
1556 } 1638 }
1557 1639
1558 - List<Tunnel> tunnelsToBeDeletedList = syncCompleteDeleteList.get(pccId.ipAddress()); 1640 + @Override
1559 - checkNotNull(tunnelsToBeDeletedList); 1641 + public void handleEndOfSyncAction(PccId pccId, PcepMessage msg, PcepLspSyncAction endOfSyncAction) {
1560 - for (Tunnel tunnel: tunnelsToBeDeletedList) { 1642 + try {
1561 - releaseTunnel(tunnel); 1643 + if ((msg instanceof PcepInitiateMsg) && (endOfSyncAction == SEND_DELETE)) {
1644 + PcepClient pc = pcepClientController.getClient(pccId);
1645 + LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = ((PcepInitiateMsg) msg)
1646 + .getPcInitiatedLspRequestList();
1647 + PcInitiatedLspRequest pcInitMsg = llPcInitiatedLspRequestList.iterator().next();
1648 +
1649 + if (pcInitMsg != null) {
1650 + PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(SrpIdGenerators.create())
1651 + .setRFlag(true).build();
1652 +
1653 + PcInitiatedLspRequest releaseLspRequest = pc.factory().buildPcInitiatedLspRequest()
1654 + .setLspObject(pcInitMsg.getLspObject()).setSrpObject(srpobj).build();
1655 +
1656 + llPcInitiatedLspRequestList.remove(pcInitMsg);
1657 + llPcInitiatedLspRequestList.add(releaseLspRequest);
1658 +
1659 + PcepInitiateMsg pcInitiateMsg = pc.factory().buildPcepInitiateMsg()
1660 + .setPcInitiatedLspRequestList(llPcInitiatedLspRequestList).build();
1661 +
1662 + pc.sendMessage(Collections.singletonList(pcInitiateMsg));
1663 + }
1664 + }
1665 + } catch (PcepParseException e) {
1666 + log.error("Exception occured while sending initiate delete message {}", e.getMessage());
1667 + }
1562 } 1668 }
1669 + }
1670 + @Override
1671 + public Tunnel tunnelQueryById(TunnelId tunnelId) {
1672 + return service.tunnelQueryById(tunnelId);
1673 + }
1674 +
1563 1675
1564 - List<Tunnel> tunnelsToBeUpdatedList = syncCompleteUpdateList.get(pccId.ipAddress()); 1676 + private DeviceId getDevice(PccId pccId) {
1565 - checkNotNull(tunnelsToBeUpdatedList); 1677 + // Get lsrId of the PCEP client from the PCC ID. Session info is based on lsrID.
1566 - for (Tunnel tunnel: tunnelsToBeUpdatedList) { 1678 + IpAddress lsrId = pccId.ipAddress();
1567 - updateTunnel(tunnel, tunnel.path()); 1679 + String lsrIdentifier = String.valueOf(lsrId);
1680 +
1681 + // Find PCC deviceID from lsrId stored as annotations
1682 + Iterable<Device> devices = deviceService.getAvailableDevices();
1683 + for (Device dev : devices) {
1684 + if (dev.annotations().value(AnnotationKeys.TYPE).equals("L3")
1685 + && dev.annotations().value(LSRID).equals(lsrIdentifier)) {
1686 + return dev.id();
1687 + }
1688 + }
1689 + return null;
1690 + }
1691 +
1692 + /**
1693 + * Updates the tunnel with updated tunnel annotation after a delay of two seconds and checks it till
1694 + * tunnel is found.
1695 + */
1696 + private class UpdateDelegation implements Runnable {
1697 + DefaultTunnelDescription td;
1698 + ProviderId providerId;
1699 + SparseAnnotations annotations;
1700 + PccId pccId;
1701 + ScheduledExecutorService executor;
1702 +
1703 + /**
1704 + * Creates an instance of UpdateDelegation.
1705 + *
1706 + * @param td tunnel description
1707 + * @param providerId provider id
1708 + * @param annotations tunnel annotations
1709 + * @param pccId PCEP client id
1710 + * @param executor service of delegated owner
1711 + */
1712 + public UpdateDelegation(DefaultTunnelDescription td, ProviderId providerId, SparseAnnotations annotations,
1713 + PccId pccId, ScheduledExecutorService executor) {
1714 + this.td = td;
1715 + this.providerId = providerId;
1716 + this.annotations = annotations;
1717 + this.pccId = pccId;
1718 + this.executor = executor;
1568 } 1719 }
1569 1720
1570 - /* On end of sync, empty all temporary data structures. */ 1721 + //Temporary using annotations later will use projection/network config service
1571 - preSyncLspDbMap.remove(pccId.ipAddress()); 1722 + @Override
1572 - syncCompleteDeleteList.remove(pccId.ipAddress()); 1723 + public void run() {
1573 - syncCompleteUpdateList.remove(pccId.ipAddress()); 1724 + Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(td.src(), td.dst());
1725 + TunnelId tempTunnelId = null;
1726 + for (Tunnel t : tunnelQueryResult) {
1727 + if (t.annotations().value(LOCAL_LSP_ID) == null || t.annotations().value(PLSP_ID) == null) {
1728 + continue;
1729 + }
1574 1730
1575 - // TODO: If SR capable, send a notification to 1731 + if (t.annotations().value(LOCAL_LSP_ID).equals(td.annotations().value(LOCAL_LSP_ID))
1576 - // PCE APP to start label DB sync. 1732 + && t.annotations().value(PLSP_ID).equals(td.annotations().value(PLSP_ID))
1577 - if (true) { 1733 + && ((IpTunnelEndPoint) t.src()).ip().equals(pccId.id())) {
1578 - pcepClientController.getClient(pccId).setLabelDbSyncStatus(IN_SYNC); 1734 + tempTunnelId = t.tunnelId();
1735 + break;
1736 + }
1737 + }
1738 +
1739 + //If tunnel is found update the tunnel and shutdown the thread otherwise thread will be executing
1740 + //periodically
1741 + if (tempTunnelId != null) {
1742 + Tunnel tunnel = new DefaultTunnel(providerId, td.src(), td.dst(), MPLS, new DefaultGroupId(0),
1743 + tempTunnelId, td.tunnelName(), td.path(), annotations);
1744 + tunnelUpdated(tunnel, td.path());
1745 + executor.shutdown();
1746 + try {
1747 + executor.awaitTermination(WAIT_TIME, TimeUnit.SECONDS);
1748 + } catch (InterruptedException e) {
1749 + log.error("updating delegation failed");
1750 + }
1751 + }
1579 } 1752 }
1580 } 1753 }
1581 } 1754 }
......
...@@ -17,17 +17,22 @@ package org.onosproject.provider.pcep.tunnel.impl; ...@@ -17,17 +17,22 @@ package org.onosproject.provider.pcep.tunnel.impl;
17 17
18 import static org.junit.Assert.assertNotNull; 18 import static org.junit.Assert.assertNotNull;
19 19
20 +import java.util.HashMap;
21 +import java.util.LinkedList;
20 import java.util.List; 22 import java.util.List;
23 +import java.util.Map;
21 import java.util.concurrent.RejectedExecutionException; 24 import java.util.concurrent.RejectedExecutionException;
22 25
23 import org.jboss.netty.channel.Channel; 26 import org.jboss.netty.channel.Channel;
24 import org.onosproject.pcep.controller.ClientCapability; 27 import org.onosproject.pcep.controller.ClientCapability;
28 +import org.onosproject.pcep.controller.LspKey;
25 import org.onosproject.pcep.controller.PccId; 29 import org.onosproject.pcep.controller.PccId;
26 import org.onosproject.pcep.controller.PcepClient; 30 import org.onosproject.pcep.controller.PcepClient;
27 import org.onosproject.pcep.controller.PcepSyncStatus; 31 import org.onosproject.pcep.controller.PcepSyncStatus;
28 import org.onosproject.pcepio.protocol.PcepFactories; 32 import org.onosproject.pcepio.protocol.PcepFactories;
29 import org.onosproject.pcepio.protocol.PcepFactory; 33 import org.onosproject.pcepio.protocol.PcepFactory;
30 import org.onosproject.pcepio.protocol.PcepMessage; 34 import org.onosproject.pcepio.protocol.PcepMessage;
35 +import org.onosproject.pcepio.protocol.PcepStateReport;
31 import org.onosproject.pcepio.protocol.PcepVersion; 36 import org.onosproject.pcepio.protocol.PcepVersion;
32 37
33 /** 38 /**
...@@ -45,6 +50,8 @@ public class PcepClientAdapter implements PcepClient { ...@@ -45,6 +50,8 @@ public class PcepClientAdapter implements PcepClient {
45 private PcepVersion pcepVersion; 50 private PcepVersion pcepVersion;
46 private PcepSyncStatus lspDbSyncStatus; 51 private PcepSyncStatus lspDbSyncStatus;
47 private PcepSyncStatus labelDbSyncStatus; 52 private PcepSyncStatus labelDbSyncStatus;
53 + private Map<LspKey, Boolean> lspDelegationInfo = new HashMap<>();
54 + private Map<PccId, List<PcepStateReport>> sycRptCache = new HashMap<>();
48 55
49 /** 56 /**
50 * Initialize instance with specified parameters. 57 * Initialize instance with specified parameters.
...@@ -139,4 +146,45 @@ public class PcepClientAdapter implements PcepClient { ...@@ -139,4 +146,45 @@ public class PcepClientAdapter implements PcepClient {
139 public ClientCapability capability() { 146 public ClientCapability capability() {
140 return capability; 147 return capability;
141 } 148 }
149 +
150 + @Override
151 + public void addNode(PcepClient pc) {
152 + }
153 +
154 + @Override
155 + public void deleteNode(PccId pccId) {
156 + }
157 +
158 + @Override
159 + public void setLspAndDelegationInfo(LspKey lspKey, boolean dFlag) {
160 + lspDelegationInfo.put(lspKey, dFlag);
161 + }
162 +
163 + @Override
164 + public Boolean delegationInfo(LspKey lspKey) {
165 + return lspDelegationInfo.get(lspKey);
166 + }
167 +
168 + @Override
169 + public void initializeSyncMsgList(PccId pccId) {
170 + List<PcepStateReport> rptMsgList = new LinkedList<>();
171 + sycRptCache.put(pccId, rptMsgList);
172 + }
173 +
174 + @Override
175 + public List<PcepStateReport> getSyncMsgList(PccId pccId) {
176 + return sycRptCache.get(pccId);
177 + }
178 +
179 + @Override
180 + public void removeSyncMsgList(PccId pccId) {
181 + sycRptCache.remove(pccId);
182 + }
183 +
184 + @Override
185 + public void addSyncMsgToList(PccId pccId, PcepStateReport rptMsg) {
186 + List<PcepStateReport> rptMsgList = sycRptCache.get(pccId);
187 + rptMsgList.add(rptMsg);
188 + sycRptCache.put(pccId, rptMsgList);
189 + }
142 } 190 }
......
...@@ -24,13 +24,13 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -24,13 +24,13 @@ import java.util.concurrent.ConcurrentHashMap;
24 24
25 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Deactivate; 26 import org.apache.felix.scr.annotations.Deactivate;
27 -import org.onlab.packet.IpAddress;
28 -import org.onosproject.pcep.controller.ClientCapability;
29 import org.onosproject.pcep.controller.PccId; 27 import org.onosproject.pcep.controller.PccId;
30 import org.onosproject.pcep.controller.PcepClient; 28 import org.onosproject.pcep.controller.PcepClient;
31 import org.onosproject.pcep.controller.PcepClientController; 29 import org.onosproject.pcep.controller.PcepClientController;
32 import org.onosproject.pcep.controller.PcepClientListener; 30 import org.onosproject.pcep.controller.PcepClientListener;
33 import org.onosproject.pcep.controller.PcepEventListener; 31 import org.onosproject.pcep.controller.PcepEventListener;
32 +import org.onosproject.pcep.controller.PcepNodeListener;
33 +import org.onosproject.pcep.controller.PcepPacketListener;
34 import org.onosproject.pcep.controller.driver.PcepAgent; 34 import org.onosproject.pcep.controller.driver.PcepAgent;
35 import org.onosproject.pcepio.protocol.PcepError; 35 import org.onosproject.pcepio.protocol.PcepError;
36 import org.onosproject.pcepio.protocol.PcepErrorInfo; 36 import org.onosproject.pcepio.protocol.PcepErrorInfo;
...@@ -57,6 +57,8 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -57,6 +57,8 @@ public class PcepClientControllerAdapter implements PcepClientController {
57 protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); 57 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
58 58
59 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); 59 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
60 + public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
61 + protected Set<PcepPacketListener> pcepPacketListener = Sets.newHashSet();
60 62
61 @Activate 63 @Activate
62 public void activate() { 64 public void activate() {
...@@ -73,16 +75,11 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -73,16 +75,11 @@ public class PcepClientControllerAdapter implements PcepClientController {
73 75
74 @Override 76 @Override
75 public PcepClient getClient(PccId pccId) { 77 public PcepClient getClient(PccId pccId) {
76 - if (null != connectedClients.get(pccId)) { 78 + if (connectedClients.get(pccId) != null) {
77 return connectedClients.get(pccId); 79 return connectedClients.get(pccId);
78 } 80 }
79 PcepClientAdapter pc = new PcepClientAdapter(); 81 PcepClientAdapter pc = new PcepClientAdapter();
80 - if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103)) 82 +
81 - || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
82 - pc.setCapability(new ClientCapability(true, false, false));
83 - } else {
84 - pc.setCapability(new ClientCapability(true, true, true));
85 - }
86 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1); 83 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
87 connectedClients.put(pccId, pc); 84 connectedClients.put(pccId, pc);
88 return pc; 85 return pc;
...@@ -96,6 +93,16 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -96,6 +93,16 @@ public class PcepClientControllerAdapter implements PcepClientController {
96 } 93 }
97 94
98 @Override 95 @Override
96 + public void addNodeListener(PcepNodeListener listener) {
97 + pcepNodeListener.add(listener);
98 + }
99 +
100 + @Override
101 + public void removeNodeListener(PcepNodeListener listener) {
102 + pcepNodeListener.remove(listener);
103 + }
104 +
105 + @Override
99 public void removeListener(PcepClientListener listener) { 106 public void removeListener(PcepClientListener listener) {
100 this.pcepClientListener.remove(listener); 107 this.pcepClientListener.remove(listener);
101 } 108 }
...@@ -111,6 +118,16 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -111,6 +118,16 @@ public class PcepClientControllerAdapter implements PcepClientController {
111 } 118 }
112 119
113 @Override 120 @Override
121 + public void addPacketListener(PcepPacketListener listener) {
122 + pcepPacketListener.add(listener);
123 + }
124 +
125 + @Override
126 + public void removePacketListener(PcepPacketListener listener) {
127 + pcepPacketListener.remove(listener);
128 + }
129 +
130 + @Override
114 public void writeMessage(PccId pccId, PcepMessage msg) { 131 public void writeMessage(PccId pccId, PcepMessage msg) {
115 this.getClient(pccId).sendMessage(msg); 132 this.getClient(pccId).sendMessage(msg);
116 } 133 }
...@@ -254,5 +271,25 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -254,5 +271,25 @@ public class PcepClientControllerAdapter implements PcepClientController {
254 public void processPcepMessage(PccId pccId, PcepMessage m) { 271 public void processPcepMessage(PccId pccId, PcepMessage m) {
255 processClientMessage(pccId, m); 272 processClientMessage(pccId, m);
256 } 273 }
274 +
275 + @Override
276 + public void addNode(PcepClient pc) {
277 + for (PcepNodeListener l : pcepNodeListener) {
278 + l.addNode(pc);
279 + }
280 + }
281 +
282 + @Override
283 + public void deleteNode(PccId pccId) {
284 + for (PcepNodeListener l : pcepNodeListener) {
285 + l.deleteNode(pccId);
286 + }
287 + }
288 +
289 + @Override
290 + public boolean analyzeSyncMsgList(PccId pccId) {
291 + // TODO Auto-generated method stub
292 + return false;
293 + }
257 } 294 }
258 } 295 }
......
...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
40 import org.onosproject.incubator.net.tunnel.Tunnel; 40 import org.onosproject.incubator.net.tunnel.Tunnel;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 41 import org.onosproject.incubator.net.tunnel.TunnelId;
42 import org.onosproject.incubator.net.tunnel.TunnelName; 42 import org.onosproject.incubator.net.tunnel.TunnelName;
43 +import org.onosproject.mastership.MastershipServiceAdapter;
43 import org.onosproject.net.Annotations; 44 import org.onosproject.net.Annotations;
44 import org.onosproject.net.ConnectPoint; 45 import org.onosproject.net.ConnectPoint;
45 import org.onosproject.net.DefaultAnnotations; 46 import org.onosproject.net.DefaultAnnotations;
...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId; ...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId;
49 import org.onosproject.net.Link; 50 import org.onosproject.net.Link;
50 import org.onosproject.net.Path; 51 import org.onosproject.net.Path;
51 import org.onosproject.net.PortNumber; 52 import org.onosproject.net.PortNumber;
53 +import org.onosproject.net.device.DeviceServiceAdapter;
52 import org.onosproject.net.provider.ProviderId; 54 import org.onosproject.net.provider.ProviderId;
55 +import org.onosproject.pcep.controller.ClientCapability;
56 +import org.onosproject.pcep.controller.PccId;
53 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; 57 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
54 58
55 /** 59 /**
...@@ -64,12 +68,16 @@ public class PcepReleaseTunnelProviderTest { ...@@ -64,12 +68,16 @@ public class PcepReleaseTunnelProviderTest {
64 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 68 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
65 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 69 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
66 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 70 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
71 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
72 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
67 73
68 @Before 74 @Before
69 public void setUp() throws IOException { 75 public void setUp() throws IOException {
70 tunnelProvider.tunnelProviderRegistry = registry; 76 tunnelProvider.tunnelProviderRegistry = registry;
71 tunnelProvider.pcepClientController = controller; 77 tunnelProvider.pcepClientController = controller;
72 tunnelProvider.controller = ctl; 78 tunnelProvider.controller = ctl;
79 + tunnelProvider.deviceService = deviceService;
80 + tunnelProvider.mastershipService = mastershipService;
73 tunnelProvider.tunnelService = tunnelService; 81 tunnelProvider.tunnelService = tunnelService;
74 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; 82 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
75 tunnelProvider.cfgService = new ComponentConfigAdapter(); 83 tunnelProvider.cfgService = new ComponentConfigAdapter();
...@@ -125,6 +133,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -125,6 +133,8 @@ public class PcepReleaseTunnelProviderTest {
125 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 133 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
126 134
127 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 135 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
136 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
137 + new ClientCapability(true, true, true, true, true));
128 138
129 tunnelProvider.releaseTunnel(tunnel); 139 tunnelProvider.releaseTunnel(tunnel);
130 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 140 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -179,6 +189,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -179,6 +189,8 @@ public class PcepReleaseTunnelProviderTest {
179 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 189 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
180 190
181 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 191 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
192 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E22))).setCapability(
193 + new ClientCapability(true, false, false, true, true));
182 194
183 tunnelProvider.releaseTunnel(tunnel); 195 tunnelProvider.releaseTunnel(tunnel);
184 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 196 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
...@@ -233,6 +245,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -233,6 +245,8 @@ public class PcepReleaseTunnelProviderTest {
233 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 245 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
234 246
235 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 247 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
248 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
249 + new ClientCapability(true, true, true, true, true));
236 250
237 tunnelProvider.releaseTunnel(tunnel); 251 tunnelProvider.releaseTunnel(tunnel);
238 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 252 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -287,6 +301,8 @@ public class PcepReleaseTunnelProviderTest { ...@@ -287,6 +301,8 @@ public class PcepReleaseTunnelProviderTest {
287 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData); 301 tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
288 302
289 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 303 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
304 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xB6024E20))).setCapability(
305 + new ClientCapability(true, true, true, true, true));
290 306
291 tunnelProvider.releaseTunnel(tunnel); 307 tunnelProvider.releaseTunnel(tunnel);
292 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 308 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -298,5 +314,7 @@ public class PcepReleaseTunnelProviderTest { ...@@ -298,5 +314,7 @@ public class PcepReleaseTunnelProviderTest {
298 tunnelProvider.controller = null; 314 tunnelProvider.controller = null;
299 tunnelProvider.pcepClientController = null; 315 tunnelProvider.pcepClientController = null;
300 tunnelProvider.tunnelProviderRegistry = null; 316 tunnelProvider.tunnelProviderRegistry = null;
317 + tunnelProvider.deviceService = null;
318 + tunnelProvider.mastershipService = null;
301 } 319 }
302 } 320 }
......
...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -40,6 +40,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
40 import org.onosproject.incubator.net.tunnel.Tunnel; 40 import org.onosproject.incubator.net.tunnel.Tunnel;
41 import org.onosproject.incubator.net.tunnel.TunnelId; 41 import org.onosproject.incubator.net.tunnel.TunnelId;
42 import org.onosproject.incubator.net.tunnel.TunnelName; 42 import org.onosproject.incubator.net.tunnel.TunnelName;
43 +import org.onosproject.mastership.MastershipServiceAdapter;
43 import org.onosproject.net.Annotations; 44 import org.onosproject.net.Annotations;
44 import org.onosproject.net.ConnectPoint; 45 import org.onosproject.net.ConnectPoint;
45 import org.onosproject.net.DefaultAnnotations; 46 import org.onosproject.net.DefaultAnnotations;
...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId; ...@@ -49,7 +50,10 @@ import org.onosproject.net.IpElementId;
49 import org.onosproject.net.Link; 50 import org.onosproject.net.Link;
50 import org.onosproject.net.Path; 51 import org.onosproject.net.Path;
51 import org.onosproject.net.PortNumber; 52 import org.onosproject.net.PortNumber;
53 +import org.onosproject.net.device.DeviceServiceAdapter;
52 import org.onosproject.net.provider.ProviderId; 54 import org.onosproject.net.provider.ProviderId;
55 +import org.onosproject.pcep.controller.ClientCapability;
56 +import org.onosproject.pcep.controller.PccId;
53 57
54 /** 58 /**
55 * Test for PCEP setup tunnel. 59 * Test for PCEP setup tunnel.
...@@ -62,12 +66,16 @@ public class PcepSetupTunnelProviderTest { ...@@ -62,12 +66,16 @@ public class PcepSetupTunnelProviderTest {
62 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 66 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
63 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 67 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
64 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 68 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
69 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
70 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
65 71
66 @Before 72 @Before
67 public void setUp() throws IOException { 73 public void setUp() throws IOException {
68 tunnelProvider.tunnelProviderRegistry = registry; 74 tunnelProvider.tunnelProviderRegistry = registry;
69 tunnelProvider.pcepClientController = controller; 75 tunnelProvider.pcepClientController = controller;
70 tunnelProvider.controller = ctl; 76 tunnelProvider.controller = ctl;
77 + tunnelProvider.deviceService = deviceService;
78 + tunnelProvider.mastershipService = mastershipService;
71 tunnelProvider.cfgService = new ComponentConfigAdapter(); 79 tunnelProvider.cfgService = new ComponentConfigAdapter();
72 tunnelProvider.tunnelService = tunnelService; 80 tunnelProvider.tunnelService = tunnelService;
73 tunnelProvider.activate(); 81 tunnelProvider.activate();
...@@ -111,6 +119,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -111,6 +119,8 @@ public class PcepSetupTunnelProviderTest {
111 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 119 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
112 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 120 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
113 path, annotations); 121 path, annotations);
122 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
123 + new ClientCapability(true, true, true, true, true));
114 124
115 tunnelProvider.setupTunnel(tunnel, path); 125 tunnelProvider.setupTunnel(tunnel, path);
116 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 126 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -154,6 +164,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -154,6 +164,8 @@ public class PcepSetupTunnelProviderTest {
154 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 164 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
155 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 165 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
156 path, annotations); 166 path, annotations);
167 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010103))).setCapability(
168 + new ClientCapability(true, true, true, true, true));
157 169
158 tunnelProvider.setupTunnel(tunnel, path); 170 tunnelProvider.setupTunnel(tunnel, path);
159 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 171 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
...@@ -197,6 +209,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -197,6 +209,8 @@ public class PcepSetupTunnelProviderTest {
197 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 209 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
198 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 210 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
199 path, annotations); 211 path, annotations);
212 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
213 + new ClientCapability(true, true, true, true, true));
200 214
201 tunnelProvider.setupTunnel(tunnel, path); 215 tunnelProvider.setupTunnel(tunnel, path);
202 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 216 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -240,6 +254,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -240,6 +254,8 @@ public class PcepSetupTunnelProviderTest {
240 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 254 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
241 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 255 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
242 path, annotations); 256 path, annotations);
257 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
258 + new ClientCapability(true, true, true, true, true));
243 259
244 tunnelProvider.setupTunnel(tunnel, path); 260 tunnelProvider.setupTunnel(tunnel, path);
245 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 261 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
...@@ -251,5 +267,7 @@ public class PcepSetupTunnelProviderTest { ...@@ -251,5 +267,7 @@ public class PcepSetupTunnelProviderTest {
251 tunnelProvider.controller = null; 267 tunnelProvider.controller = null;
252 tunnelProvider.pcepClientController = null; 268 tunnelProvider.pcepClientController = null;
253 tunnelProvider.tunnelProviderRegistry = null; 269 tunnelProvider.tunnelProviderRegistry = null;
270 + tunnelProvider.deviceService = null;
271 + tunnelProvider.mastershipService = null;
254 } 272 }
255 } 273 }
......
...@@ -24,27 +24,35 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL ...@@ -24,27 +24,35 @@ import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL
24 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE; 24 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
25 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID; 25 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
26 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID; 26 import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
27 +import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.DELEGATE;
27 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; 28 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
28 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; 29 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
29 -import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC; 30 +import static org.onosproject.net.Device.Type.ROUTER;
31 +import static org.onosproject.net.MastershipRole.MASTER;
30 32
31 import java.io.IOException; 33 import java.io.IOException;
32 import java.util.Collection; 34 import java.util.Collection;
33 import java.util.Collections; 35 import java.util.Collections;
34 import java.util.HashMap; 36 import java.util.HashMap;
35 import java.util.HashSet; 37 import java.util.HashSet;
38 +import java.util.LinkedList;
39 +import java.util.List;
40 +import java.util.concurrent.TimeUnit;
36 41
37 import org.jboss.netty.buffer.ChannelBuffer; 42 import org.jboss.netty.buffer.ChannelBuffer;
38 import org.jboss.netty.buffer.ChannelBuffers; 43 import org.jboss.netty.buffer.ChannelBuffers;
39 import org.junit.After; 44 import org.junit.After;
40 import org.junit.Before; 45 import org.junit.Before;
41 import org.junit.Test; 46 import org.junit.Test;
47 +import org.onlab.packet.ChassisId;
42 import org.onlab.packet.IpAddress; 48 import org.onlab.packet.IpAddress;
43 import org.onosproject.cfg.ComponentConfigAdapter; 49 import org.onosproject.cfg.ComponentConfigAdapter;
44 import org.onosproject.core.ApplicationId; 50 import org.onosproject.core.ApplicationId;
45 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 51 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
46 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 52 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
47 import org.onosproject.incubator.net.tunnel.Tunnel; 53 import org.onosproject.incubator.net.tunnel.Tunnel;
54 +import org.onosproject.incubator.net.tunnel.Tunnel.Type;
55 +import org.onosproject.incubator.net.tunnel.TunnelAdminService;
48 import org.onosproject.incubator.net.tunnel.TunnelDescription; 56 import org.onosproject.incubator.net.tunnel.TunnelDescription;
49 import org.onosproject.incubator.net.tunnel.TunnelEndPoint; 57 import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
50 import org.onosproject.incubator.net.tunnel.TunnelId; 58 import org.onosproject.incubator.net.tunnel.TunnelId;
...@@ -52,16 +60,26 @@ import org.onosproject.incubator.net.tunnel.TunnelName; ...@@ -52,16 +60,26 @@ import org.onosproject.incubator.net.tunnel.TunnelName;
52 import org.onosproject.incubator.net.tunnel.TunnelProvider; 60 import org.onosproject.incubator.net.tunnel.TunnelProvider;
53 import org.onosproject.incubator.net.tunnel.TunnelProviderService; 61 import org.onosproject.incubator.net.tunnel.TunnelProviderService;
54 import org.onosproject.incubator.net.tunnel.Tunnel.State; 62 import org.onosproject.incubator.net.tunnel.Tunnel.State;
63 +import org.onosproject.mastership.MastershipServiceAdapter;
64 +import org.onosproject.net.AnnotationKeys;
55 import org.onosproject.net.DefaultAnnotations; 65 import org.onosproject.net.DefaultAnnotations;
66 +import org.onosproject.net.DefaultDevice;
67 +import org.onosproject.net.Device;
68 +import org.onosproject.net.DeviceId;
56 import org.onosproject.net.ElementId; 69 import org.onosproject.net.ElementId;
70 +import org.onosproject.net.MastershipRole;
57 import org.onosproject.net.Path; 71 import org.onosproject.net.Path;
58 import org.onosproject.net.SparseAnnotations; 72 import org.onosproject.net.SparseAnnotations;
73 +import org.onosproject.net.device.DeviceServiceAdapter;
74 +import org.onosproject.net.provider.ProviderId;
59 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; 75 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
60 import org.onosproject.pcepio.exceptions.PcepParseException; 76 import org.onosproject.pcepio.exceptions.PcepParseException;
61 import org.onosproject.pcepio.protocol.PcepFactories; 77 import org.onosproject.pcepio.protocol.PcepFactories;
62 import org.onosproject.pcepio.protocol.PcepMessage; 78 import org.onosproject.pcepio.protocol.PcepMessage;
63 import org.onosproject.pcepio.protocol.PcepMessageReader; 79 import org.onosproject.pcepio.protocol.PcepMessageReader;
80 +import org.onosproject.pcepio.protocol.PcepVersion;
64 import org.onosproject.pcep.controller.ClientCapability; 81 import org.onosproject.pcep.controller.ClientCapability;
82 +import org.onosproject.pcep.controller.LspKey;
65 import org.onosproject.pcep.controller.PccId; 83 import org.onosproject.pcep.controller.PccId;
66 84
67 import com.google.common.collect.ImmutableSet; 85 import com.google.common.collect.ImmutableSet;
...@@ -71,13 +89,73 @@ import com.google.common.collect.ImmutableSet; ...@@ -71,13 +89,73 @@ import com.google.common.collect.ImmutableSet;
71 */ 89 */
72 public class PcepTunnelAddedTest { 90 public class PcepTunnelAddedTest {
73 91
74 - static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; 92 + public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
93 + public static final String UNKOWN = "UNKOWN";
75 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); 94 PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
76 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter(); 95 private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
77 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 96 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
78 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 97 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
79 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 98 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
80 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); 99 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
100 + public final MockDeviceService deviceService = new MockDeviceService();
101 + private final MockMasterShipService masterShipService = new MockMasterShipService();
102 + private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
103 +
104 + private class MockTunnelAdminService implements TunnelAdminService {
105 +
106 + @Override
107 + public void removeTunnel(TunnelId tunnelId) {
108 + // TODO Auto-generated method stub
109 + }
110 +
111 + @Override
112 + public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, ProviderId producerName) {
113 + // TODO Auto-generated method stub
114 + }
115 +
116 + @Override
117 + public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type, ProviderId producerName) {
118 + // TODO Auto-generated method stub
119 + }
120 +
121 + @Override
122 + public void updateTunnel(Tunnel tunnel, Path path) {
123 + if (tunnelService.tunnelIdAsKeyStore.containsKey(tunnel.tunnelId())) {
124 + tunnelService.tunnelIdAsKeyStore.replace(tunnel.tunnelId(), tunnel);
125 + }
126 + }
127 + }
128 +
129 + private class MockMasterShipService extends MastershipServiceAdapter {
130 + boolean set;
131 +
132 + private void setMaster(boolean isMaster) {
133 + this.set = isMaster;
134 + }
135 +
136 + @Override
137 + public MastershipRole getLocalRole(DeviceId deviceId) {
138 + return set ? MastershipRole.MASTER : MastershipRole.STANDBY;
139 + }
140 +
141 + @Override
142 + public boolean isLocalMaster(DeviceId deviceId) {
143 + return getLocalRole(deviceId) == MASTER;
144 + }
145 + }
146 +
147 + private class MockDeviceService extends DeviceServiceAdapter {
148 + List<Device> devices = new LinkedList<>();
149 +
150 + private void addDevice(Device dev) {
151 + devices.add(dev);
152 + }
153 +
154 + @Override
155 + public Iterable<Device> getAvailableDevices() {
156 + return devices;
157 + }
158 + }
81 159
82 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter { 160 private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
83 public long tunnelIdCounter; 161 public long tunnelIdCounter;
...@@ -97,12 +175,34 @@ public class PcepTunnelAddedTest { ...@@ -97,12 +175,34 @@ public class PcepTunnelAddedTest {
97 175
98 @Override 176 @Override
99 public TunnelId tunnelAdded(TunnelDescription tunnel) { 177 public TunnelId tunnelAdded(TunnelDescription tunnel) {
100 - return TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); 178 + TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
179 + Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
180 + tunnel.src(), tunnel.dst(),
181 + tunnel.type(),
182 + tunnel.groupId(),
183 + id,
184 + tunnel.tunnelName(),
185 + tunnel.path(),
186 + tunnel.resource(),
187 + tunnel.annotations());
188 + tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
189 + return id;
101 } 190 }
102 191
103 @Override 192 @Override
104 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) { 193 public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
105 - return TunnelId.valueOf(String.valueOf(++tunnelIdCounter)); 194 + TunnelId id = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
195 + Tunnel storedTunnel = new DefaultTunnel(ProviderId.NONE,
196 + tunnel.src(), tunnel.dst(),
197 + tunnel.type(),
198 + tunnel.groupId(),
199 + id,
200 + tunnel.tunnelName(),
201 + tunnel.path(),
202 + tunnel.resource(),
203 + tunnel.annotations());
204 + tunnelService.tunnelIdAsKeyStore.put(id, storedTunnel);
205 + return id;
106 } 206 }
107 207
108 @Override 208 @Override
...@@ -168,9 +268,12 @@ public class PcepTunnelAddedTest { ...@@ -168,9 +268,12 @@ public class PcepTunnelAddedTest {
168 tunnelProvider.tunnelProviderRegistry = registry; 268 tunnelProvider.tunnelProviderRegistry = registry;
169 tunnelProvider.pcepClientController = controller; 269 tunnelProvider.pcepClientController = controller;
170 tunnelProvider.controller = ctl; 270 tunnelProvider.controller = ctl;
271 + tunnelProvider.deviceService = deviceService;
272 + tunnelProvider.mastershipService = masterShipService;
171 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper; 273 tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
172 tunnelProvider.cfgService = new ComponentConfigAdapter(); 274 tunnelProvider.cfgService = new ComponentConfigAdapter();
173 tunnelProvider.tunnelService = tunnelService; 275 tunnelProvider.tunnelService = tunnelService;
276 + tunnelProvider.tunnelAdminService = tunnelAdminService;
174 tunnelProvider.service = registry.register(tunnelProvider); 277 tunnelProvider.service = registry.register(tunnelProvider);
175 tunnelProvider.activate(); 278 tunnelProvider.activate();
176 } 279 }
...@@ -210,6 +313,19 @@ public class PcepTunnelAddedTest { ...@@ -210,6 +313,19 @@ public class PcepTunnelAddedTest {
210 313
211 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 314 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
212 PcepMessage message = reader.readFrom(buffer); 315 PcepMessage message = reader.readFrom(buffer);
316 +
317 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
318 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
319 + newBuilder.set(AnnotationKeys.TYPE, "L3");
320 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
321 + UNKOWN, UNKOWN, UNKOWN,
322 + UNKOWN, new ChassisId(),
323 + newBuilder.build());
324 +
325 + deviceService.addDevice(device);
326 + controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
327 + new ClientCapability(true, true, true, true, true));
328 + masterShipService.setMaster(true);
213 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); 329 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
214 330
215 assertThat(registry.tunnelIdCounter, is((long) 1)); 331 assertThat(registry.tunnelIdCounter, is((long) 1));
...@@ -254,14 +370,20 @@ public class PcepTunnelAddedTest { ...@@ -254,14 +370,20 @@ public class PcepTunnelAddedTest {
254 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) 370 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
255 .set(PCC_TUNNEL_ID, String.valueOf(1)) 371 .set(PCC_TUNNEL_ID, String.valueOf(1))
256 .set(PLSP_ID, String.valueOf(1)) 372 .set(PLSP_ID, String.valueOf(1))
257 - .set(LOCAL_LSP_ID, String.valueOf(1)).build(); 373 + .set(LOCAL_LSP_ID, String.valueOf(1))
374 + .set(DELEGATE, String.valueOf("true"))
375 + .build();
258 376
259 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null, 377 Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
260 TunnelName.tunnelName("T123"), null, annotations); 378 TunnelName.tunnelName("T123"), null, annotations);
261 tunnelService.setupTunnel(null, null, tunnel, null); 379 tunnelService.setupTunnel(null, null, tunnel, null);
262 380
263 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400)); 381 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
264 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 382 + PcepClientAdapter pc = new PcepClientAdapter();
383 + pc.init(pccId, PcepVersion.PCEP_1);
384 + masterShipService.setMaster(true);
385 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
386 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
265 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 387 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
266 388
267 // Process update message. 389 // Process update message.
...@@ -281,7 +403,7 @@ public class PcepTunnelAddedTest { ...@@ -281,7 +403,7 @@ public class PcepTunnelAddedTest {
281 0x00, 0x00, 0x00, 0x00, 403 0x00, 0x00, 0x00, 0x00,
282 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV 404 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
283 0x00, 0x00, 0x00, 0x02, 405 0x00, 0x00, 0x00, 0x02,
284 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object 406 + 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
285 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV 407 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
286 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV 408 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
287 0x01, 0x01, 0x01, 0x01, 409 0x01, 0x01, 0x01, 0x01,
...@@ -308,167 +430,139 @@ public class PcepTunnelAddedTest { ...@@ -308,167 +430,139 @@ public class PcepTunnelAddedTest {
308 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); 430 PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
309 PcepMessage message = reader.readFrom(buffer); 431 PcepMessage message = reader.readFrom(buffer);
310 432
433 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
434 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
435 + newBuilder.set(AnnotationKeys.TYPE, "L3");
436 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
437 + UNKOWN, UNKOWN, UNKOWN,
438 + UNKOWN, new ChassisId(),
439 + newBuilder.build());
440 +
441 + deviceService.addDevice(device);
442 +
311 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 443 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
312 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 444 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
313 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 445 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
446 +
447 + PcepClientAdapter pc = new PcepClientAdapter();
448 + pc.init(pccId, PcepVersion.PCEP_1);
449 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
450 + masterShipService.setMaster(true);
314 controller.processClientMessage(pccId, message); 451 controller.processClientMessage(pccId, message);
315 452
316 assertThat(registry.tunnelIdCounter, is((long) 1)); 453 assertThat(registry.tunnelIdCounter, is((long) 1));
317 } 454 }
318 455
319 /** 456 /**
320 - * Tests LSPDB sync where PCC reports less LSPs than known by PCE and PCE deletes at the end of DB sync. 457 + * Tests PCRpt msg with D flag set and delegated to non-master.
458 + *
459 + * @throws InterruptedException while waiting for delay
321 */ 460 */
322 @Test 461 @Test
323 - public void testCaseLspDbSync1() throws PcepParseException, PcepOutOfBoundMessageException { 462 + public void tunnelProviderAddedTest4() throws PcepParseException, PcepOutOfBoundMessageException,
324 - /* Step 1 create 2 LSPs */ 463 + InterruptedException {
325 - byte[] reportMsg1 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, 464 + byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
326 - 0x21, 0x10, 0x00, 0x14, //SRP object 465 + 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
327 - 0x00, 0x00, 0x00, 0x00, 466 + 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
328 - 0x00, 0x00, 0x00, 0x00, 467 + 0x00, 0x00, 0x00, 0x02,
329 - 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV 468 + 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x02, //LSP object
330 - 0x00, 0x00, 0x00, 0x00, 469 + 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
331 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object 470 + 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
332 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV 471 + 0x01, 0x01, 0x01, 0x01,
333 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV 472 + 0x00, 0x01, 0x00, 0x01,
334 - 0x01, 0x01, 0x01, 0x01, 473 + 0x01, 0x01, 0x01, 0x01,
335 - 0x00, 0x01, 0x00, 0x01, 474 + 0x05, 0x05, 0x05, 0x05,
336 - 0x01, 0x01, 0x01, 0x01,
337 - 0x05, 0x05, 0x05, 0x05,
338 475
339 - 0x07, 0x10, 0x00, 0x14, //ERO object 476 + 0x07, 0x10, 0x00, 0x14, //ERO object
340 - 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects 477 + 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
341 - 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, 478 + 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
342 479
343 - 0x08, 0x10, 0x00, 0x34, //RRO object 480 + 0x08, 0x10, 0x00, 0x34, //RRO object
344 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects 481 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
345 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, 482 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
346 - 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, 483 + 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
347 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, 484 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
348 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, 485 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
349 - 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 486 + 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
350 - }; 487 + };
351 488
352 - ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); 489 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
353 - buffer1.writeBytes(reportMsg1); 490 + buffer.writeBytes(reportMsg);
354 491
355 - PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader(); 492 + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
356 - PcepMessage message1 = reader1.readFrom(buffer1); 493 + PcepMessage message = reader.readFrom(buffer);
357 494
358 - PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 495 + //PCC 1.1.1.1, D=0, ONOS as master
359 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 496 + masterShipService.setMaster(true);
360 - controller.processClientMessage(pccId, message1); 497 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
498 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
499 + newBuilder.set(AnnotationKeys.TYPE, "L3");
500 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
501 + UNKOWN, UNKOWN, UNKOWN,
502 + UNKOWN, new ChassisId(),
503 + newBuilder.build());
504 +
505 + deviceService.addDevice(device);
506 + controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
507 + new ClientCapability(true, true, true, true, true));
508 + controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
509 + assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
510 + is("false"));
361 511
362 - /* create 2nd LSP */ 512 + //PCC 1.1.1.1, D=1, non-master
363 - byte[] reportMsg2 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, 513 + masterShipService.setMaster(false);
364 - 0x21, 0x10, 0x00, 0x14, //SRP object
365 - 0x00, 0x00, 0x00, 0x00,
366 - 0x00, 0x00, 0x00, 0x00,
367 - 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
368 - 0x00, 0x00, 0x00, 0x00,
369 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x20, 0x19, // LSP object
370 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
371 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
372 - 0x01, 0x01, 0x01, 0x01,
373 - 0x00, 0x02, 0x00, 0x02,
374 - 0x01, 0x01, 0x01, 0x01,
375 - 0x05, 0x05, 0x05, 0x05,
376 514
377 - 0x07, 0x10, 0x00, 0x14, //ERO object 515 + reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
378 - 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects 516 + 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
379 - 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, 517 + 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
518 + 0x00, 0x00, 0x00, 0x02,
519 + 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
520 + 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
521 + 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
522 + 0x01, 0x01, 0x01, 0x01,
523 + 0x00, 0x01, 0x00, 0x01,
524 + 0x01, 0x01, 0x01, 0x01,
525 + 0x05, 0x05, 0x05, 0x05,
380 526
381 - 0x08, 0x10, 0x00, 0x34, //RRO object 527 + 0x07, 0x10, 0x00, 0x14, //ERO object
382 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects 528 + 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
383 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00, 529 + 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
384 - 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00, 530 +
385 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00, 531 + 0x08, 0x10, 0x00, 0x34, //RRO object
386 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, 532 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
387 - 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 533 + 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
388 - }; 534 + 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
535 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
536 + 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
537 + 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
538 + };
539 +
540 + buffer = ChannelBuffers.dynamicBuffer();
541 + buffer.writeBytes(reportMsg);
389 542
390 - ChannelBuffer buffer2 = ChannelBuffers.dynamicBuffer(); 543 + reader = PcepFactories.getGenericReader();
391 - buffer2.writeBytes(reportMsg2); 544 + message = reader.readFrom(buffer);
392 - 545 +
393 - PcepMessageReader<PcepMessage> reader2 = PcepFactories.getGenericReader(); 546 + controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
394 - PcepMessage message2 = reader2.readFrom(buffer2); 547 + TimeUnit.MILLISECONDS.sleep(4000);
395 - 548 + assertThat(registry.tunnelIdCounter, is((long) 1));
396 - controller.processClientMessage(pccId, message2); 549 + assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
397 - 550 + is("true"));
398 - /* Assert number of LSPs in DB to be 2. */
399 - assertThat(registry.tunnelIdCounter, is((long) 2));
400 -
401 - /* Step 2 send sync begin message and LSP 1. */
402 - byte[] reportMsg3 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
403 - 0x21, 0x10, 0x00, 0x14, //SRP object
404 - 0x00, 0x00, 0x00, 0x00,
405 - 0x00, 0x00, 0x00, 0x00,
406 - 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
407 - 0x00, 0x00, 0x00, 0x00,
408 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x1B, // LSP object
409 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
410 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
411 - 0x01, 0x01, 0x01, 0x01,
412 - 0x00, 0x01, 0x00, 0x01,
413 - 0x01, 0x01, 0x01, 0x01,
414 - 0x05, 0x05, 0x05, 0x05,
415 -
416 - 0x07, 0x10, 0x00, 0x14, //ERO object
417 - 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
418 - 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
419 -
420 - 0x08, 0x10, 0x00, 0x34, //RRO object
421 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
422 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
423 - 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
424 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
425 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
426 - 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
427 - };
428 -
429 - ChannelBuffer buffer3 = ChannelBuffers.dynamicBuffer();
430 - buffer3.writeBytes(reportMsg3);
431 - PcepMessageReader<PcepMessage> reader3 = PcepFactories.getGenericReader();
432 - PcepMessage message3 = reader3.readFrom(buffer3);
433 - controller.processClientMessage(pccId, message3);
434 -
435 - assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(IN_SYNC));
436 -
437 - /* Step 3 send end of sync marker */
438 - byte[] reportMsg4 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x24,
439 - 0x20, 0x10, 0x00, 0x1C, // LSP object
440 - 0x00, 0x00, 0x10, 0x19,
441 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
442 - 0x00, 0x00, 0x00, 0x00,
443 - 0x00, 0x00, 0x00, 0x00,
444 - 0x00, 0x00, 0x00, 0x00,
445 - 0x00, 0x00, 0x00, 0x00,
446 - 0x07, 0x10, 0x00, 0x04, //ERO object
447 - };
448 -
449 - ChannelBuffer buffer4 = ChannelBuffers.dynamicBuffer();
450 - buffer4.writeBytes(reportMsg4);
451 - PcepMessageReader<PcepMessage> reader4 = PcepFactories.getGenericReader();
452 - PcepMessage message4 = reader4.readFrom(buffer4);
453 - controller.processClientMessage(pccId, message4);
454 -
455 - assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(SYNCED));
456 } 551 }
457 552
458 /** 553 /**
459 - * Tests PCC PCRpt PCE initiated LSP which PCE doesn't know and hence should send PCInit delete msg. 554 + * Tests adding PCC Init LSP after LSP DB sync is over.
460 */ 555 */
461 @Test 556 @Test
462 - public void testCaseLspDbSync2() throws PcepParseException, PcepOutOfBoundMessageException { 557 + public void tunnelProviderAddedTest5() throws PcepParseException, PcepOutOfBoundMessageException {
463 - /* Step 1 create 2 LSPs */ 558 + byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
464 - byte[] reportMsg1 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
465 0x21, 0x10, 0x00, 0x14, //SRP object 559 0x21, 0x10, 0x00, 0x14, //SRP object
466 0x00, 0x00, 0x00, 0x00, 560 0x00, 0x00, 0x00, 0x00,
467 0x00, 0x00, 0x00, 0x00, 561 0x00, 0x00, 0x00, 0x00,
468 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV 562 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
469 - 0x00, 0x00, 0x00, 0x00, 563 + 0x00, 0x00, 0x00, 0x02,
470 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object 564 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
471 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV 565 + 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
472 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV 566 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
473 0x01, 0x01, 0x01, 0x01, 567 0x01, 0x01, 0x01, 0x01,
474 0x00, 0x01, 0x00, 0x01, 568 0x00, 0x01, 0x00, 0x01,
...@@ -488,110 +582,33 @@ public class PcepTunnelAddedTest { ...@@ -488,110 +582,33 @@ public class PcepTunnelAddedTest {
488 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00 582 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
489 }; 583 };
490 584
491 - ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); 585 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
492 - buffer1.writeBytes(reportMsg1); 586 + buffer.writeBytes(reportMsg);
493 -
494 - PcepMessageReader<PcepMessage> reader1 = PcepFactories.getGenericReader();
495 - PcepMessage message1 = reader1.readFrom(buffer1);
496 -
497 - PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
498 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true));
499 - controller.processClientMessage(pccId, message1);
500 587
501 - /* create 2nd LSP */ 588 + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
502 - byte[] reportMsg2 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84, 589 + PcepMessage message = reader.readFrom(buffer);
503 - 0x21, 0x10, 0x00, 0x14, //SRP object
504 - 0x00, 0x00, 0x00, 0x00,
505 - 0x00, 0x00, 0x00, 0x00,
506 - 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
507 - 0x00, 0x00, 0x00, 0x00,
508 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x20, 0x19, // LSP object
509 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
510 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
511 - 0x01, 0x01, 0x01, 0x01,
512 - 0x00, 0x02, 0x00, 0x02,
513 - 0x01, 0x01, 0x01, 0x01,
514 - 0x05, 0x05, 0x05, 0x05,
515 590
516 - 0x07, 0x10, 0x00, 0x14, //ERO object 591 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
517 - 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects 592 + newBuilder.set(PcepTunnelProvider.LSRID, "1.1.1.1");
518 - 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, 593 + newBuilder.set(AnnotationKeys.TYPE, "L3");
594 + Device device = new DefaultDevice(ProviderId.NONE, DeviceId.deviceId("1.1.1.1"), ROUTER,
595 + UNKOWN, UNKOWN, UNKOWN,
596 + UNKOWN, new ChassisId(),
597 + newBuilder.build());
519 598
520 - 0x08, 0x10, 0x00, 0x34, //RRO object 599 + deviceService.addDevice(device);
521 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
522 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
523 - 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
524 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
525 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
526 - 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
527 - };
528 600
529 - ChannelBuffer buffer2 = ChannelBuffers.dynamicBuffer(); 601 + PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
530 - buffer2.writeBytes(reportMsg2); 602 + controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
531 - 603 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
532 - PcepMessageReader<PcepMessage> reader2 = PcepFactories.getGenericReader();
533 - PcepMessage message2 = reader2.readFrom(buffer2);
534 -
535 - controller.processClientMessage(pccId, message2);
536 -
537 - /* Assert number of LSPs in DB to be 2. */
538 - assertThat(registry.tunnelIdCounter, is((long) 2));
539 -
540 - /* Step 2 send sync begin message and LSP 1. */
541 - byte[] reportMsg3 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
542 - 0x21, 0x10, 0x00, 0x14, //SRP object
543 - 0x00, 0x00, 0x00, 0x00,
544 - 0x00, 0x00, 0x00, 0x00,
545 - 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
546 - 0x00, 0x00, 0x00, 0x00,
547 - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, (byte) 0x9B, // LSP object
548 - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
549 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
550 - 0x01, 0x01, 0x01, 0x01,
551 - 0x00, 0x01, 0x00, 0x03,
552 - 0x01, 0x01, 0x01, 0x01,
553 - 0x05, 0x05, 0x05, 0x05,
554 -
555 - 0x07, 0x10, 0x00, 0x14, //ERO object
556 - 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
557 - 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
558 -
559 - 0x08, 0x10, 0x00, 0x34, //RRO object
560 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
561 - 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
562 - 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
563 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
564 - 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
565 - 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
566 - };
567 -
568 - ChannelBuffer buffer3 = ChannelBuffers.dynamicBuffer();
569 - buffer3.writeBytes(reportMsg3);
570 - PcepMessageReader<PcepMessage> reader3 = PcepFactories.getGenericReader();
571 - PcepMessage message3 = reader3.readFrom(buffer3);
572 - controller.processClientMessage(pccId, message3);
573 -
574 - assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(IN_SYNC));
575 -
576 - /* Step 3 send end of sync marker */
577 - byte[] reportMsg4 = new byte[] {0x20, 0x0a, 0x00, (byte) 0x24,
578 - 0x20, 0x10, 0x00, 0x1C, // LSP object
579 - 0x00, 0x00, 0x10, 0x19,
580 - 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
581 - 0x00, 0x00, 0x00, 0x00,
582 - 0x00, 0x00, 0x00, 0x00,
583 - 0x00, 0x00, 0x00, 0x00,
584 - 0x00, 0x00, 0x00, 0x00,
585 - 0x07, 0x10, 0x00, 0x04, //ERO object
586 - };
587 604
588 - ChannelBuffer buffer4 = ChannelBuffers.dynamicBuffer(); 605 + PcepClientAdapter pc = new PcepClientAdapter();
589 - buffer4.writeBytes(reportMsg4); 606 + pc.init(pccId, PcepVersion.PCEP_1);
590 - PcepMessageReader<PcepMessage> reader4 = PcepFactories.getGenericReader(); 607 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
591 - PcepMessage message4 = reader4.readFrom(buffer4); 608 + masterShipService.setMaster(true);
592 - controller.processClientMessage(pccId, message4); 609 + controller.processClientMessage(pccId, message);
593 610
594 - assertThat(controller.getClient(pccId).lspDbSyncStatus(), is(SYNCED)); 611 + assertThat(registry.tunnelIdCounter, is((long) 0));
595 } 612 }
596 613
597 @After 614 @After
...@@ -604,6 +621,9 @@ public class PcepTunnelAddedTest { ...@@ -604,6 +621,9 @@ public class PcepTunnelAddedTest {
604 tunnelProvider.pcepTunnelApiMapper = null; 621 tunnelProvider.pcepTunnelApiMapper = null;
605 tunnelProvider.cfgService = null; 622 tunnelProvider.cfgService = null;
606 tunnelProvider.tunnelService = null; 623 tunnelProvider.tunnelService = null;
624 + tunnelProvider.tunnelAdminService = null;
625 + tunnelProvider.deviceService = null;
626 + tunnelProvider.mastershipService = null;
607 tunnelProvider.service = null; 627 tunnelProvider.service = null;
608 } 628 }
609 } 629 }
......
...@@ -35,6 +35,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; ...@@ -35,6 +35,7 @@ import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
35 import org.onosproject.incubator.net.tunnel.Tunnel; 35 import org.onosproject.incubator.net.tunnel.Tunnel;
36 import org.onosproject.incubator.net.tunnel.TunnelId; 36 import org.onosproject.incubator.net.tunnel.TunnelId;
37 import org.onosproject.incubator.net.tunnel.TunnelName; 37 import org.onosproject.incubator.net.tunnel.TunnelName;
38 +import org.onosproject.mastership.MastershipServiceAdapter;
38 import org.onosproject.net.Annotations; 39 import org.onosproject.net.Annotations;
39 import org.onosproject.net.ConnectPoint; 40 import org.onosproject.net.ConnectPoint;
40 import org.onosproject.net.DefaultAnnotations; 41 import org.onosproject.net.DefaultAnnotations;
...@@ -44,7 +45,10 @@ import org.onosproject.net.IpElementId; ...@@ -44,7 +45,10 @@ import org.onosproject.net.IpElementId;
44 import org.onosproject.net.Link; 45 import org.onosproject.net.Link;
45 import org.onosproject.net.Path; 46 import org.onosproject.net.Path;
46 import org.onosproject.net.PortNumber; 47 import org.onosproject.net.PortNumber;
48 +import org.onosproject.net.device.DeviceServiceAdapter;
47 import org.onosproject.net.provider.ProviderId; 49 import org.onosproject.net.provider.ProviderId;
50 +import org.onosproject.pcep.controller.ClientCapability;
51 +import org.onosproject.pcep.controller.PccId;
48 import org.onosproject.cfg.ComponentConfigAdapter; 52 import org.onosproject.cfg.ComponentConfigAdapter;
49 53
50 public class PcepTunnelProviderTest { 54 public class PcepTunnelProviderTest {
...@@ -55,6 +59,8 @@ public class PcepTunnelProviderTest { ...@@ -55,6 +59,8 @@ public class PcepTunnelProviderTest {
55 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 59 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
56 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 60 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
57 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter(); 61 private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
62 + private final DeviceServiceAdapter deviceService = new DeviceServiceAdapter();
63 + private final MastershipServiceAdapter mastershipService = new MastershipServiceAdapter();
58 64
59 @Test 65 @Test
60 public void testCasePcepSetupTunnel() { 66 public void testCasePcepSetupTunnel() {
...@@ -62,6 +68,8 @@ public class PcepTunnelProviderTest { ...@@ -62,6 +68,8 @@ public class PcepTunnelProviderTest {
62 tunnelProvider.tunnelProviderRegistry = registry; 68 tunnelProvider.tunnelProviderRegistry = registry;
63 tunnelProvider.pcepClientController = controller; 69 tunnelProvider.pcepClientController = controller;
64 tunnelProvider.controller = ctl; 70 tunnelProvider.controller = ctl;
71 + tunnelProvider.deviceService = deviceService;
72 + tunnelProvider.mastershipService = mastershipService;
65 tunnelProvider.cfgService = new ComponentConfigAdapter(); 73 tunnelProvider.cfgService = new ComponentConfigAdapter();
66 tunnelProvider.tunnelService = tunnelService; 74 tunnelProvider.tunnelService = tunnelService;
67 tunnelProvider.activate(); 75 tunnelProvider.activate();
...@@ -99,6 +107,8 @@ public class PcepTunnelProviderTest { ...@@ -99,6 +107,8 @@ public class PcepTunnelProviderTest {
99 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 107 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
100 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), 108 new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
101 path, annotations); 109 path, annotations);
110 + controller.getClient(PccId.pccId(IpAddress.valueOf(0xC010101))).setCapability(
111 + new ClientCapability(true, true, true, true, true));
102 112
103 tunnelProvider.setupTunnel(tunnel, path); 113 tunnelProvider.setupTunnel(tunnel, path);
104 114
...@@ -109,6 +119,8 @@ public class PcepTunnelProviderTest { ...@@ -109,6 +119,8 @@ public class PcepTunnelProviderTest {
109 public void tearDown() throws IOException { 119 public void tearDown() throws IOException {
110 tunnelProvider.deactivate(); 120 tunnelProvider.deactivate();
111 tunnelProvider.controller = null; 121 tunnelProvider.controller = null;
122 + tunnelProvider.deviceService = null;
123 + tunnelProvider.mastershipService = null;
112 tunnelProvider.pcepClientController = null; 124 tunnelProvider.pcepClientController = null;
113 tunnelProvider.tunnelProviderRegistry = null; 125 tunnelProvider.tunnelProviderRegistry = null;
114 } 126 }
......
...@@ -47,6 +47,10 @@ import org.onosproject.net.Link; ...@@ -47,6 +47,10 @@ import org.onosproject.net.Link;
47 import org.onosproject.net.Path; 47 import org.onosproject.net.Path;
48 import org.onosproject.net.PortNumber; 48 import org.onosproject.net.PortNumber;
49 import org.onosproject.net.provider.ProviderId; 49 import org.onosproject.net.provider.ProviderId;
50 +import org.onosproject.pcep.controller.ClientCapability;
51 +import org.onosproject.pcep.controller.LspKey;
52 +import org.onosproject.pcep.controller.PccId;
53 +import org.onosproject.pcepio.protocol.PcepVersion;
50 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv; 54 import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
51 55
52 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING; 56 import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
...@@ -99,7 +103,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -99,7 +103,7 @@ public class PcepUpdateTunnelProviderTest {
99 103
100 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 104 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
101 105
102 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 106 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
103 107
104 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 108 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
105 .type(Link.Type.DIRECT).build(); 109 .type(Link.Type.DIRECT).build();
...@@ -108,6 +112,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -108,6 +112,8 @@ public class PcepUpdateTunnelProviderTest {
108 path = new DefaultPath(pid, links, 20, EMPTY); 112 path = new DefaultPath(pid, links, 20, EMPTY);
109 113
110 Annotations annotations = DefaultAnnotations.builder() 114 Annotations annotations = DefaultAnnotations.builder()
115 + .set(PcepAnnotationKeys.PLSP_ID, "1")
116 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
111 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) 117 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
112 .build(); 118 .build();
113 119
...@@ -124,6 +130,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -124,6 +130,12 @@ public class PcepUpdateTunnelProviderTest {
124 130
125 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 131 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
126 132
133 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
134 + PcepClientAdapter pc = new PcepClientAdapter();
135 + pc.init(pccId, PcepVersion.PCEP_1);
136 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
137 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
138 +
127 tunnelProvider.updateTunnel(tunnel, path); 139 tunnelProvider.updateTunnel(tunnel, path);
128 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 140 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
129 } 141 }
...@@ -137,7 +149,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -137,7 +149,7 @@ public class PcepUpdateTunnelProviderTest {
137 Path path; 149 Path path;
138 ProviderId pid = new ProviderId("pcep", PROVIDER_ID); 150 ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
139 List<Link> links = new ArrayList<>(); 151 List<Link> links = new ArrayList<>();
140 - IpAddress srcIp = IpAddress.valueOf(0xC010103); 152 + IpAddress srcIp = IpAddress.valueOf(0xD010101);
141 IpElementId srcElementId = IpElementId.ipElement(srcIp); 153 IpElementId srcElementId = IpElementId.ipElement(srcIp);
142 154
143 IpAddress dstIp = IpAddress.valueOf(0xD010102); 155 IpAddress dstIp = IpAddress.valueOf(0xD010102);
...@@ -151,7 +163,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -151,7 +163,7 @@ public class PcepUpdateTunnelProviderTest {
151 163
152 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 164 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
153 165
154 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 166 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
155 167
156 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 168 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
157 .type(Link.Type.DIRECT).build(); 169 .type(Link.Type.DIRECT).build();
...@@ -161,6 +173,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -161,6 +173,8 @@ public class PcepUpdateTunnelProviderTest {
161 173
162 Annotations annotations = DefaultAnnotations.builder() 174 Annotations annotations = DefaultAnnotations.builder()
163 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name()) 175 .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
176 + .set(PcepAnnotationKeys.PLSP_ID, "1")
177 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
164 .build(); 178 .build();
165 179
166 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 180 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -176,6 +190,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -176,6 +190,12 @@ public class PcepUpdateTunnelProviderTest {
176 190
177 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 191 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
178 192
193 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
194 + PcepClientAdapter pc = new PcepClientAdapter();
195 + pc.init(pccId, PcepVersion.PCEP_1);
196 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
197 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
198 +
179 tunnelProvider.updateTunnel(tunnel, path); 199 tunnelProvider.updateTunnel(tunnel, path);
180 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false)); 200 assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
181 } 201 }
...@@ -203,7 +223,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -203,7 +223,7 @@ public class PcepUpdateTunnelProviderTest {
203 223
204 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 224 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
205 225
206 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 226 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
207 227
208 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 228 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
209 .type(Link.Type.DIRECT).build(); 229 .type(Link.Type.DIRECT).build();
...@@ -213,6 +233,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -213,6 +233,8 @@ public class PcepUpdateTunnelProviderTest {
213 233
214 Annotations annotations = DefaultAnnotations.builder() 234 Annotations annotations = DefaultAnnotations.builder()
215 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name()) 235 .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
236 + .set(PcepAnnotationKeys.PLSP_ID, "1")
237 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
216 .build(); 238 .build();
217 239
218 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 240 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -228,6 +250,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -228,6 +250,12 @@ public class PcepUpdateTunnelProviderTest {
228 250
229 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 251 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
230 252
253 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
254 + PcepClientAdapter pc = new PcepClientAdapter();
255 + pc.init(pccId, PcepVersion.PCEP_1);
256 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
257 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
258 +
231 tunnelProvider.updateTunnel(tunnel, path); 259 tunnelProvider.updateTunnel(tunnel, path);
232 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 260 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
233 } 261 }
...@@ -255,7 +283,7 @@ public class PcepUpdateTunnelProviderTest { ...@@ -255,7 +283,7 @@ public class PcepUpdateTunnelProviderTest {
255 283
256 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023)); 284 ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
257 285
258 - ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023)); 286 + ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10024));
259 287
260 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst) 288 Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
261 .type(Link.Type.DIRECT).build(); 289 .type(Link.Type.DIRECT).build();
...@@ -265,6 +293,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -265,6 +293,8 @@ public class PcepUpdateTunnelProviderTest {
265 293
266 Annotations annotations = DefaultAnnotations.builder() 294 Annotations annotations = DefaultAnnotations.builder()
267 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name()) 295 .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
296 + .set(PcepAnnotationKeys.PLSP_ID, "1")
297 + .set(PcepAnnotationKeys.LOCAL_LSP_ID, "1")
268 .build(); 298 .build();
269 299
270 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, 300 tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
...@@ -280,6 +310,12 @@ public class PcepUpdateTunnelProviderTest { ...@@ -280,6 +310,12 @@ public class PcepUpdateTunnelProviderTest {
280 310
281 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData); 311 tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
282 312
313 + PccId pccId = PccId.pccId(IpAddress.valueOf(0xD010101));
314 + PcepClientAdapter pc = new PcepClientAdapter();
315 + pc.init(pccId, PcepVersion.PCEP_1);
316 + controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
317 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
318 +
283 tunnelProvider.updateTunnel(tunnel, path); 319 tunnelProvider.updateTunnel(tunnel, path);
284 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue())); 320 assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
285 } 321 }
......