[ONOS] Cherry picked from master 1.7
Change-Id: I74a0c1634f9c425af2bcb646edc3d9170b3c087c
diff --git a/apps/pce/app/pom.xml b/apps/pce/app/pom.xml
index 1f5d837..a20469b 100644
--- a/apps/pce/app/pom.xml
+++ b/apps/pce/app/pom.xml
@@ -22,6 +22,7 @@
<groupId>org.onosproject</groupId>
<artifactId>onos-pce</artifactId>
<version>1.6.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-pce</artifactId>
<packaging>bundle</packaging>
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
index 904371d..89a685b 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
@@ -26,6 +26,12 @@
import java.util.Optional;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.IPv4;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -35,6 +41,7 @@
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
+import org.onlab.packet.TCP;
import org.onlab.util.Bandwidth;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
@@ -52,6 +59,7 @@
import org.onosproject.incubator.net.tunnel.TunnelListener;
import org.onosproject.incubator.net.tunnel.TunnelName;
import org.onosproject.incubator.net.tunnel.TunnelService;
+import org.onosproject.mastership.MastershipService;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.Device;
@@ -63,6 +71,7 @@
import org.onosproject.net.flowobjective.Objective;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
+import org.onosproject.net.link.LinkEvent;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
@@ -76,6 +85,9 @@
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.PathService;
import org.onosproject.net.topology.TopologyEdge;
+import org.onosproject.net.topology.TopologyEvent;
+import org.onosproject.net.topology.TopologyListener;
+import org.onosproject.net.topology.TopologyService;
import org.onosproject.pce.pceservice.api.PceService;
import org.onosproject.pce.pcestore.PcePathInfo;
import org.onosproject.pce.pcestore.PceccTunnelInfo;
@@ -131,6 +143,7 @@
private static final String TRUE = "true";
private static final String FALSE = "false";
private static final String END_OF_SYNC_IP_PREFIX = "0.0.0.0/32";
+ public static final int PCEP_PORT = 4189;
private IdGenerator localLspIdIdGen;
protected DistributedSet<Short> localLspIdFreeList;
@@ -171,12 +184,23 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowObjectiveService flowObjectiveService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected MastershipService mastershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TopologyService topologyService;
+
private TunnelListener listener = new InnerTunnelListener();
private BasicPceccHandler crHandler;
private PceccSrTeBeHandler srTeHandler;
private ApplicationId appId;
private final PcepPacketProcessor processor = new PcepPacketProcessor();
+ private final TopologyListener topologyListener = new InternalTopologyListener();
+ private ScheduledExecutorService executor;
+
+ public static final int INITIAL_DELAY = 30;
+ public static final int PERIODIC_DELAY = 30;
/**
* Creates new instance of PceManager.
@@ -204,6 +228,10 @@
.asDistributedSet();
packetService.addProcessor(processor, PacketProcessor.director(4));
+ topologyService.addListener(topologyListener);
+ executor = Executors.newSingleThreadScheduledExecutor();
+ //Start a timer when the component is up, with initial delay of 30min and periodic delays at 30min
+ executor.scheduleAtFixedRate(new GlobalOptimizationTimer(), INITIAL_DELAY, PERIODIC_DELAY, TimeUnit.MINUTES);
log.info("Started");
}
@@ -211,6 +239,9 @@
protected void deactivate() {
tunnelService.removeListener(listener);
packetService.removeProcessor(processor);
+ topologyService.removeListener(topologyListener);
+ //Shutdown the thread when component is deactivated
+ executor.shutdown();
log.info("Stopped");
}
@@ -395,6 +426,7 @@
List<Link> links = tunnel.path().links();
String lspSigType = tunnel.annotations().value(LSP_SIG_TYPE);
double bwConstraintValue = 0;
+ String costType = null;
SharedBandwidthConstraint shBwConstraint = null;
BandwidthConstraint bwConstraint = null;
CostConstraint costConstraint = null;
@@ -409,6 +441,7 @@
bwConstraintValue = bwConstraint.bandwidth().bps();
} else if (constraint instanceof CostConstraint) {
costConstraint = (CostConstraint) constraint;
+ costType = costConstraint.type().name();
}
}
@@ -454,6 +487,9 @@
Builder annotationBuilder = DefaultAnnotations.builder();
annotationBuilder.set(BANDWIDTH, String.valueOf(bwConstraintValue));
+ if (costType != null) {
+ annotationBuilder.set(COST_TYPE, costType);
+ }
annotationBuilder.set(LSP_SIG_TYPE, lspSigType);
annotationBuilder.set(PCE_INIT, TRUE);
annotationBuilder.set(DELEGATE, TRUE);
@@ -594,8 +630,66 @@
}
}
+ //TODO: annotations used for temporarily later projection/network config will be used
+ private class InternalTopologyListener implements TopologyListener {
+ @Override
+ public void event(TopologyEvent event) {
+ event.reasons().forEach(e -> {
+ //If event type is link removed, get the impacted tunnel
+ if (e instanceof LinkEvent) {
+ LinkEvent linkEvent = (LinkEvent) e;
+ if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
+ tunnelService.queryTunnel(MPLS).forEach(t -> {
+ if (t.path().links().contains((e.subject()))) {
+ // Check whether this ONOS instance is master for ingress device if yes,
+ // recompute and send update
+ checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
+ }
+ });
+ }
+ }
+ });
+ }
+ }
- // Allocates the bandwidth locally for PCECC tunnels.
+ private boolean checkForMasterAndUpdateTunnel(DeviceId src, Tunnel tunnel) {
+ /**
+ * Master of ingress node will recompute and also delegation flag must be set.
+ */
+ if (mastershipService.isLocalMaster(src)
+ && Boolean.valueOf(tunnel.annotations().value(DELEGATE)) != null) {
+ LinkedList<Constraint> constraintList = new LinkedList<>();
+
+ if (tunnel.annotations().value(BANDWIDTH) != null) {
+ //Requested bandwidth will be same as previous allocated bandwidth for the tunnel
+ BandwidthConstraint localConst = new BandwidthConstraint(Bandwidth.bps(Double.parseDouble(tunnel
+ .annotations().value(BANDWIDTH))));
+ constraintList.add(localConst);
+ }
+ if (tunnel.annotations().value(COST_TYPE) != null) {
+ constraintList.add(CostConstraint.of(CostConstraint.Type.valueOf(tunnel.annotations().value(
+ COST_TYPE))));
+ }
+
+ /*
+ * If tunnel was UP after recomputation failed then store failed path in PCE store send PCIntiate(remove)
+ * and If tunnel is failed and computation fails nothing to do because tunnel status will be same[Failed]
+ */
+ if (!updatePath(tunnel.tunnelId(), constraintList) && !tunnel.state().equals(Tunnel.State.FAILED)) {
+ // If updation fails store in PCE store as failed path
+ // then PCInitiate (Remove)
+ pceStore.addFailedPathInfo(new PcePathInfo(tunnel.path().src().deviceId(), tunnel
+ .path().dst().deviceId(), tunnel.tunnelName().value(), constraintList,
+ LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))));
+ //Release that tunnel calling PCInitiate
+ releasePath(tunnel.tunnelId());
+ }
+ }
+
+ return false;
+ }
+
+ // Allocates the bandwidth locally for PCECC tunnels.
private TunnelConsumerId reserveBandwidth(Path computedPath, double bandwidthConstraint,
SharedBandwidthConstraint shBwConstraint) {
checkNotNull(computedPath);
@@ -860,14 +954,72 @@
public void process(PacketContext context) {
// Stop processing if the packet has been handled, since we
// can't do any more to it.
-
if (context.isHandled()) {
return;
}
InboundPacket pkt = context.inPacket();
+ if (pkt == null) {
+ return;
+ }
+
+ Ethernet ethernet = pkt.parsed();
+ if (ethernet == null || ethernet.getEtherType() != Ethernet.TYPE_IPV4) {
+ return;
+ }
+
+ IPv4 ipPacket = (IPv4) ethernet.getPayload();
+ if (ipPacket == null || ipPacket.getProtocol() != IPv4.PROTOCOL_TCP) {
+ return;
+ }
+
+ TCP tcp = (TCP) ipPacket.getPayload();
+ if (tcp == null || tcp.getDestinationPort() != PCEP_PORT) {
+ return;
+ }
+
syncLabelDb(pkt.receivedFrom().deviceId());
}
}
+ //Computes path from tunnel store and also path failed to setup.
+ private void callForOptimization() {
+ //Recompute the LSPs which it was delegated [LSPs stored in PCE store (failed paths)]
+ for (PcePathInfo failedPathInfo : pceStore.getFailedPathInfos()) {
+ checkForMasterAndSetupPath(failedPathInfo);
+ }
+
+ //Recompute the LSPs for which it was delegated [LSPs stored in tunnel store]
+ tunnelService.queryTunnel(MPLS).forEach(t -> {
+ checkForMasterAndUpdateTunnel(t.path().src().deviceId(), t);
+ });
+ }
+
+ private boolean checkForMasterAndSetupPath(PcePathInfo failedPathInfo) {
+ /**
+ * Master of ingress node will setup the path failed stored in PCE store.
+ */
+ if (mastershipService.isLocalMaster(failedPathInfo.src())) {
+ if (setupPath(failedPathInfo.src(), failedPathInfo.dst(), failedPathInfo.name(),
+ failedPathInfo.constraints(), failedPathInfo.lspType())) {
+ // If computation is success remove that path
+ pceStore.removeFailedPathInfo(failedPathInfo);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ //Timer to call global optimization
+ private class GlobalOptimizationTimer implements Runnable {
+
+ public GlobalOptimizationTimer() {
+ }
+
+ @Override
+ public void run() {
+ callForOptimization();
+ }
+ }
}
\ No newline at end of file
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/BasicPceccHandlerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/BasicPceccHandlerTest.java
index 8c3de14..cd28f9e 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/BasicPceccHandlerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/BasicPceccHandlerTest.java
@@ -19,7 +19,6 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
-
import static org.onosproject.net.Link.Type.DIRECT;
import java.util.Iterator;
@@ -29,7 +28,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
import org.onlab.packet.IpAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
@@ -165,6 +163,7 @@
@After
public void tearDown() throws Exception {
+ PceManagerTest.flowsDownloaded = 0;
}
/**
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
index 5b0d869..2da22e5 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceManagerTest.java
@@ -15,13 +15,17 @@
import static org.onosproject.pce.pceservice.PathComputationTest.D2;
import static org.onosproject.pce.pceservice.PathComputationTest.D3;
import static org.onosproject.pce.pceservice.PathComputationTest.D4;
+import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
+import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
+import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
+import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
+import static org.onosproject.net.MastershipRole.MASTER;
import java.net.URISyntaxException;
-import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -35,14 +39,18 @@
import org.junit.Before;
import org.junit.Test;
import org.onlab.graph.GraphPathSearch;
+import org.onlab.junit.TestUtils;
+import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
+import org.onlab.packet.TCP;
import org.onlab.util.Bandwidth;
import org.onosproject.common.DefaultTopologyGraph;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.IdGenerator;
+import org.onosproject.event.Event;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
@@ -52,6 +60,7 @@
import org.onosproject.incubator.net.tunnel.TunnelEvent;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelListener;
+import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -60,6 +69,7 @@
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Device;
import org.onosproject.net.DefaultAnnotations.Builder;
+import org.onosproject.net.MastershipRole;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.DeviceId;
@@ -71,6 +81,7 @@
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
+import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.packet.DefaultInboundPacket;
import org.onosproject.net.packet.DefaultPacketContext;
import org.onosproject.net.packet.InboundPacket;
@@ -86,7 +97,9 @@
import org.onosproject.net.topology.PathServiceAdapter;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEdge;
+import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyGraph;
+import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyServiceAdapter;
import org.onosproject.net.topology.TopologyVertex;
import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
@@ -97,7 +110,9 @@
import org.onosproject.pce.util.TunnelServiceAdapter;
import org.onosproject.pce.util.FlowObjServiceAdapter;
import org.onosproject.store.service.TestStorageService;
+
import com.google.common.collect.ImmutableSet;
+import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
/**
* Tests the functions of PceManager.
@@ -107,6 +122,7 @@
private PathComputationTest pathCompTest = new PathComputationTest();
private MockPathResourceService resourceService = pathCompTest.new MockPathResourceService();
private MockTopologyService topologyService = new MockTopologyService();
+ private MockMastershipService mastershipService = new MockMastershipService();
private MockPathService pathService = new MockPathService();
private PceManager pceManager = new PceManager();
private MockCoreService coreService = new MockCoreService();
@@ -129,13 +145,19 @@
private Device deviceD1, deviceD2, deviceD3, deviceD4;
private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
private Link link1, link2, link3, link4;
- private static int flowsDownloaded;
+ protected static int flowsDownloaded;
private TunnelListener tunnelListener;
+ private TopologyListener listener;
+ private Topology topology;
+ private Set<TopologyEdge> edges;
+ private Set<TopologyVertex> vertexes;
@Before
- public void startUp() {
+ public void startUp() throws TestUtilsException {
+ listener = TestUtils.getField(pceManager, "topologyListener");
pceManager.pathService = pathService;
pceManager.resourceService = resourceService;
+ pceManager.topologyService = topologyService;
pceManager.tunnelService = tunnelService;
pceManager.coreService = coreService;
pceManager.storageService = storageService;
@@ -144,34 +166,52 @@
pceManager.labelRsrcService = labelResourceService;
pceManager.flowObjectiveService = flowObjectiveService;
pceManager.pceStore = pceStore;
+ pceManager.mastershipService = mastershipService;
pceManager.activate();
}
+ private class MockMastershipService extends MastershipServiceAdapter {
+ @Override
+ public MastershipRole getLocalRole(DeviceId deviceId) {
+ return MASTER;
+ }
+
+ @Override
+ public boolean isLocalMaster(DeviceId deviceId) {
+ return getLocalRole(deviceId) == MASTER;
+ }
+ }
+
private void build4RouterTopo(boolean setCost, boolean setPceccCap, boolean setSrCap,
boolean setLabelStackCap, int bandwidth) {
+ link1 = PathComputationTest.addLink(DEVICE1, 10, DEVICE2, 20, setCost, 50);
+ link2 = PathComputationTest.addLink(DEVICE2, 30, DEVICE4, 40, setCost, 20);
+ link3 = PathComputationTest.addLink(DEVICE1, 80, DEVICE3, 70, setCost, 100);
+ link4 = PathComputationTest.addLink(DEVICE3, 60, DEVICE4, 50, setCost, 80);
+
Set<TopologyVertex> vertexes = new HashSet<TopologyVertex>();
vertexes.add(D1);
vertexes.add(D2);
vertexes.add(D3);
vertexes.add(D4);
+ this.vertexes = vertexes;
+
Set<TopologyEdge> edges = new HashSet<TopologyEdge>();
- link1 = PathComputationTest.addLink(D1.deviceId().toString(), 10, D2.deviceId().toString(), 20, setCost, 50);
TopologyEdge edge1 = new DefaultTopologyEdge(D1, D2, link1);
edges.add(edge1);
- link2 = PathComputationTest.addLink(D2.deviceId().toString(), 30, D4.deviceId().toString(), 40, setCost, 20);
TopologyEdge edge2 = new DefaultTopologyEdge(D2, D4, link2);
edges.add(edge2);
- link3 = PathComputationTest.addLink(D1.deviceId().toString(), 80, D3.deviceId().toString(), 70, setCost, 100);
TopologyEdge edge3 = new DefaultTopologyEdge(D1, D3, link3);
edges.add(edge3);
- link4 = PathComputationTest.addLink(D3.deviceId().toString(), 60, D4.deviceId().toString(), 50, setCost, 80);
TopologyEdge edge4 = new DefaultTopologyEdge(D3, D4, link4);
edges.add(edge4);
+ this.edges = edges;
+
graph = new DefaultTopologyGraph(vertexes, edges);
DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
@@ -636,21 +676,18 @@
* Tests packet in to trigger label DB sync.
*/
@Test
- public void packetProcessingTest() throws URISyntaxException {
+ public void packetProcessingTest1() throws URISyntaxException {
build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
- final int srcHost = 2;
- final int dstHost = 5;
-
LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
- ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost));
- ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(dstHost));
+ ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
+ ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
.providerId(new ProviderId("eth", "1")).build();
@@ -658,24 +695,66 @@
LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
pceManager.pceStore.addAdjLabel(link1, link1Label);
- Ethernet eth;
- IPv4 ipv4;
+ TCP tcp = new TCP();
+ tcp.setDestinationPort(PCEP_PORT);
- ipv4 = new IPv4();
- eth = new Ethernet();
+ IPv4 ipv4 = new IPv4();
+ ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+ ipv4.setPayload(tcp);
+
+ Ethernet eth = new Ethernet();
eth.setEtherType(Ethernet.TYPE_IPV4);
eth.setPayload(ipv4);
- eth.setSourceMACAddress("00:00:00:10:00:0" + srcHost).setDestinationMACAddress("00:00:00:10:00:0" + dstHost);
-
- InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(), PortNumber.portNumber(srcHost)),
- eth, ByteBuffer.wrap(eth.serialize()));
+ InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
+ PortNumber.portNumber(PCEP_PORT)),
+ eth, null);
pktProcessor.process(new MockPcepPacketContext(inPkt, null));
assertThat(flowsDownloaded, is(4));
}
/**
+ * Tests faulty packet in to trigger label DB sync.
+ */
+ @Test
+ public void packetProcessingTest2() throws URISyntaxException {
+
+ build4RouterTopo(false, true, true, true, 0); // This also initializes devices etc.
+
+ LabelResourceId node1Label = LabelResourceId.labelResourceId(5200);
+ LabelResourceId node2Label = LabelResourceId.labelResourceId(5201);
+
+ pceManager.pceStore.addGlobalNodeLabel(D1.deviceId(), node1Label);
+ pceManager.pceStore.addGlobalNodeLabel(D2.deviceId(), node2Label);
+
+ ConnectPoint src = new ConnectPoint(D1.deviceId(), PortNumber.portNumber(1));
+ ConnectPoint dst = new ConnectPoint(D2.deviceId(), PortNumber.portNumber(2));
+
+ Link link1 = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).type(DIRECT)
+ .providerId(new ProviderId("eth", "1")).build();
+
+ LabelResourceId link1Label = LabelResourceId.labelResourceId(5204);
+ pceManager.pceStore.addAdjLabel(link1, link1Label);
+
+ TCP tcp = new TCP(); // Not set the pcep port.
+ IPv4 ipv4 = new IPv4();
+ ipv4.setProtocol(IPv4.PROTOCOL_TCP);
+ ipv4.setPayload(tcp);
+
+ Ethernet eth = new Ethernet();
+ eth.setEtherType(Ethernet.TYPE_IPV4);
+ eth.setPayload(ipv4);
+
+ InboundPacket inPkt = new DefaultInboundPacket(new ConnectPoint(D1.deviceId(),
+ PortNumber.portNumber(PCEP_PORT)),
+ eth, null);
+
+ pktProcessor.process(new MockPcepPacketContext(inPkt, null));
+ assertThat(flowsDownloaded, is(0));
+ }
+
+ /**
* Tests tunnel events added and removed.
*/
@Test
@@ -800,6 +879,390 @@
assertThat(pceStore.getFailedPathInfoCount(), is(1));
}
+ /**
+ * Tests resilency when L2 link is down.
+ */
+ @Test
+ public void resilencyTest1() {
+ build4RouterTopo(true, false, false, false, 10);
+
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+ assertThat(pceStore.getTunnelInfoCount(), is(1));
+ assertThat(pceStore.getFailedPathInfoCount(), is(0));
+
+ List<Event> reasons = new LinkedList<>();
+ final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove link2
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ topologyService.changeInTopology(getGraph(null, tempEdges));
+ listener.event(event);
+
+ List<Link> links = new LinkedList<>();
+ links.add(link3);
+ links.add(link4);
+
+ //Path is D1-D3-D4
+ assertThat(pathService.paths().iterator().next().links(), is(links));
+ assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
+ }
+
+ /**
+ * Tests resilency when L2 and L4 link is down.
+ */
+ @Test
+ public void resilencyTest2() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
+ reasons.add(linkEvent);
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove link2 and link4
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
+ topologyService.changeInTopology(getGraph(null, tempEdges));
+ listener.event(event);
+
+ //No Path
+ assertThat(pathService.paths().size(), is(0));
+ }
+
+ /**
+ * Tests resilency when D2 device is down.
+ */
+ @Test
+ public void resilencyTest3() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
+ reasons.add(linkEvent);
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove link2 and link1
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
+ topologyService.changeInTopology(getGraph(null, tempEdges));
+ listener.event(event);
+
+ List<Link> links = new LinkedList<>();
+ links.add(link3);
+ links.add(link4);
+
+ //Path is D1-D3-D4
+ assertThat(pathService.paths().iterator().next().links(), is(links));
+ assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
+ }
+
+ /**
+ * Tests resilency when ingress device is down.
+ */
+ @Test
+ public void resilencyTest4() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
+ reasons.add(linkEvent);
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove link2 and link1
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
+ tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
+ topologyService.changeInTopology(getGraph(null, tempEdges));
+ listener.event(event);
+
+ //No path
+ assertThat(pathService.paths().size(), is(0));
+ }
+
+ /**
+ * Tests resilency when D2 and D3 devices are down.
+ */
+ @Test
+ public void resilencyTest5() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
+ reasons.add(linkEvent);
+
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove device2, device3 and all links
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ tempEdges.add(new DefaultTopologyEdge(D1, D3, link3));
+ tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
+ Set<TopologyVertex> tempVertexes = new HashSet<>();
+ tempVertexes.add(D2);
+ tempVertexes.add(D3);
+ topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
+ listener.event(event);
+
+ //No path
+ assertThat(pathService.paths().size(), is(0));
+ }
+
+ /**
+ * Tests resilency when egress device is down.
+ */
+ @Test
+ public void resilencyTest6() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
+ reasons.add(linkEvent);
+
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove device4 , link2 and link4
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
+ Set<TopologyVertex> tempVertexes = new HashSet<>();
+ tempVertexes.add(D4);
+ topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
+ listener.event(event);
+
+ //No path
+ assertThat(pathService.paths().size(), is(0));
+ }
+
+ /**
+ * Tests resilency when egress device is down.
+ */
+ @Test
+ public void resilencyTest7() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
+ reasons.add(linkEvent);
+
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove device4 , link2 and link4
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ tempEdges.add(new DefaultTopologyEdge(D3, D4, link4));
+ Set<TopologyVertex> tempVertexes = new HashSet<>();
+ tempVertexes.add(D4);
+ topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
+ listener.event(event);
+
+ //No path
+ assertThat(pathService.paths().size(), is(0));
+ }
+
+ /**
+ * Tests resilency when D2 device is suspended.
+ */
+ @Test
+ public void resilencyTest8() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove device2 , link1 and link2
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ Set<TopologyVertex> tempVertexes = new HashSet<>();
+ tempVertexes.add(D2);
+ topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
+ listener.event(event);
+
+ List<Link> links = new LinkedList<>();
+ links.add(link3);
+ links.add(link4);
+
+ //Path is D1-D3-D4
+ assertThat(pathService.paths().iterator().next().links(), is(links));
+ assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
+ }
+
+ /**
+ * Tests resilency when D2 device availability is changed.
+ */
+ @Test
+ public void resilencyTest11() {
+ build4RouterTopo(true, false, false, false, 10);
+
+ List<Constraint> constraints = new LinkedList<Constraint>();
+ CostConstraint costConstraint = new CostConstraint(COST);
+ constraints.add(costConstraint);
+ BandwidthConstraint localBwConst = new BandwidthConstraint(Bandwidth.bps(10));
+ constraints.add(localBwConst);
+
+ //Setup the path , tunnel created
+ boolean result = pceManager.setupPath(D1.deviceId(), D4.deviceId(), "T123", constraints, WITH_SIGNALLING);
+ assertThat(result, is(true));
+
+ List<Event> reasons = new LinkedList<>();
+ LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link1);
+ reasons.add(linkEvent);
+ linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2);
+ reasons.add(linkEvent);
+
+ final TopologyEvent event = new TopologyEvent(
+ TopologyEvent.Type.TOPOLOGY_CHANGED,
+ topology,
+ reasons);
+
+ //Change Topology : remove device2 , link1 and link2
+ Set<TopologyEdge> tempEdges = new HashSet<>();
+ tempEdges.add(new DefaultTopologyEdge(D1, D2, link1));
+ tempEdges.add(new DefaultTopologyEdge(D2, D4, link2));
+ Set<TopologyVertex> tempVertexes = new HashSet<>();
+ tempVertexes.add(D2);
+ topologyService.changeInTopology(getGraph(tempVertexes, tempEdges));
+ listener.event(event);
+
+ List<Link> links = new LinkedList<>();
+ links.add(link3);
+ links.add(link4);
+
+ //Path is D1-D3-D4
+ assertThat(pathService.paths().iterator().next().links(), is(links));
+ assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
+ }
+
@After
public void tearDown() {
pceManager.deactivate();
@@ -813,10 +1276,16 @@
pceManager.labelRsrcService = null;
pceManager.flowObjectiveService = null;
pceManager.pceStore = null;
+ pceManager.topologyService = null;
+ pceManager.mastershipService = null;
flowsDownloaded = 0;
}
private class MockTopologyService extends TopologyServiceAdapter {
+ private void changeInTopology(TopologyGraph graphModified) {
+ graph = graphModified;
+ }
+
@Override
public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst, LinkWeight weight) {
DefaultTopologyVertex srcV = new DefaultTopologyVertex(src);
@@ -837,8 +1306,27 @@
}
}
- private class MockPathService extends PathServiceAdapter {
+ private TopologyGraph getGraph(Set<TopologyVertex> removedVertex, Set<TopologyEdge> removedEdges) {
+ if (removedVertex != null) {
+ vertexes.remove(removedVertex);
+ removedVertex.forEach(v ->
+ {
+ vertexes.remove(v);
+ });
+ }
+ if (removedEdges != null) {
+ removedEdges.forEach(e ->
+ {
+ edges.remove(e);
+ });
+ }
+
+ return new DefaultTopologyGraph(vertexes, edges);
+ }
+
+ private class MockPathService extends PathServiceAdapter {
+ Set<Path> computedPaths;
@Override
public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
// If either edge is null, bail with no paths.
@@ -848,7 +1336,12 @@
// Otherwise get all paths between the source and destination edge
// devices.
- return topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
+ computedPaths = topologyService.getPaths(null, (DeviceId) src, (DeviceId) dst, weight);
+ return computedPaths;
+ }
+
+ private Set<Path> paths() {
+ return computedPaths;
}
}
@@ -946,6 +1439,31 @@
return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
}
+
+ @Override
+ public Collection<Tunnel> queryAllTunnels() {
+ Collection<Tunnel> result = new HashSet<Tunnel>();
+
+ for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
+ result.add(tunnelIdAsKeyStore.get(tunnelId));
+ }
+
+ return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
+ }
+ @Override
+ public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
+ List<Tunnel> tunnelList = new LinkedList<>();
+
+ for (Tunnel t : tunnelIdAsKeyStore.values()) {
+ for (Link l : t.path().links()) {
+ if (l.src().deviceId().equals(deviceId) || l.dst().deviceId().equals(deviceId)) {
+ tunnelList.add(t);
+ break;
+ }
+ }
+ }
+ return tunnelList;
+ }
}
public static class MockCoreService extends CoreServiceAdapter {
diff --git a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
index 2a419b5..a49bb0b 100644
--- a/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
+++ b/apps/pce/app/src/test/java/org/onosproject/pce/pceservice/PceccSrTeBeHandlerTest.java
@@ -158,6 +158,7 @@
@After
public void tearDown() throws Exception {
+ PceManagerTest.flowsDownloaded = 0;
}
/**
diff --git a/apps/pce/pceweb/app.png b/apps/pce/pceweb/app.png
index abe34eb..01ea558 100644
--- a/apps/pce/pceweb/app.png
+++ b/apps/pce/pceweb/app.png
Binary files differ
diff --git a/apps/pce/pceweb/pom.xml b/apps/pce/pceweb/pom.xml
index b9b1435..9e815a0 100644
--- a/apps/pce/pceweb/pom.xml
+++ b/apps/pce/pceweb/pom.xml
@@ -23,6 +23,7 @@
<groupId>org.onosproject</groupId>
<artifactId>onos-pce</artifactId>
<version>1.6.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-pceweb</artifactId>
@@ -42,6 +43,11 @@
<artifactId>onos-cli</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-app-pce</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<properties>
diff --git a/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovMessageHandler.java b/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovMessageHandler.java
index 0c1a5b5..95e9f1f 100644
--- a/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovMessageHandler.java
+++ b/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovMessageHandler.java
@@ -17,33 +17,48 @@
package org.onosproject.pceweb;
import com.fasterxml.jackson.databind.node.ObjectNode;
-
-
import com.google.common.collect.ImmutableSet;
+
import org.onlab.osgi.ServiceDirectory;
+import org.onlab.packet.IpAddress;
+import org.onlab.util.DataRateUnit;
+import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.DisjointPath;
import org.onosproject.net.ElementId;
import org.onosproject.net.HostId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.PathService;
+import org.onosproject.net.topology.TopologyEvent;
+import org.onosproject.net.topology.TopologyListener;
import org.onosproject.net.topology.TopologyService;
import org.onosproject.ui.RequestHandler;
import org.onosproject.ui.UiConnection;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.topo.DeviceHighlight;
import org.onosproject.ui.topo.Highlights;
-import org.onosproject.ui.topo.HostHighlight;
import org.onosproject.ui.topo.NodeBadge;
import org.onosproject.ui.topo.TopoJson;
-
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.LspType;
+import org.onosproject.pce.pceservice.api.PceService;
+import org.onosproject.pce.pceservice.constraint.CostConstraint;
+import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelEvent;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelListener;
+import org.onosproject.incubator.net.tunnel.TunnelService;
+import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -56,47 +71,66 @@
private static final String PCEWEB_SET_SRC = "pceTopovSetSrc";
private static final String PCEWEB_SET_DST = "pceTopovSetDst";
private static final String PCEWEB_SET_PATH = "pceTopovSetMode";
-
+ private static final String PCEWEB_UPDATE_PATH_QUERY = "pceTopovUpdateQuery";
+ private static final String PCEWEB_UPDATE_PATH = "pceTopovUpdate";
+ private static final String PCEWEB_REMOVE_PATH_QUERY = "pceTopovRemQuery";
+ private static final String PCEWEB_REMOVE_PATH = "pceTopovRem";
+ private static final String PCEWEB_QUERY_TUNNELS = "pceTopovTunnelDisplay";
+ private static final String PCEWEB_SHOW_TUNNEL = "pceTopovShowTunnels";
+ private static final String PCEWEB_SHOW_TUNNEL_REMOVE = "pceTopovShowTunnelsRem";
private static final String ID = "id";
- private static final String MODE = "mode";
private static final String TYPE = "type";
- private static final String SWITCH = "switch";
- private static final String ENDSTATION = "endstation";
- public static final String DST = "Dst";
- public static final String SRC = "Src";
+ private static final String ROUTER = "router";
+ private static final String DST = "Egress";
+ private static final String SRC = "Ingress";
+ private static final String BANDWIDTH = "bw";
+ private static final String BANDWIDTHTYPE = "bwtype";
+ private static final String COSTTYPE = "ctype";
+ private static final String LSPTYPE = "lsptype";
+ private static final String SRCID = "srid";
+ private static final String DSTID = "dsid";
+ private static final String TUNNEL_ID = "tunnelid";
+ private static final String TUNNEL_NAME = "tunnelname";
+ private static final String COST_TYPE_IGP = "igp";
+ private static final String COST_TYPE_TE = "te";
+ private static final String BANDWIDTH_TYPE_KBPS = "kbps";
+ private static final String BUFFER_ARRAY = "a";
+ private static final String BANDWIDTH_BPS = "BPS";
+ private static final String LSP_TYPE_CR = "cr";
+ private static final String LSP_TYPE_SRBE = "srbe";
+ private static final String LSP_TYPE_SRTE = "srte";
+ private static final String STRING_NULL = "null";
// Delay for showHighlights event processing on GUI client side to
// account for addLink animation.
- public static final int DELAY_MS = 1100;
-
- private static final String CLASS = "class";
- private static final String UNKNOWN = "unknown";
- private static final String DEVICE = "device";
+ private static final int DELAY_MS = 1100;
+ private static final double BANDWIDTH_KBPS = 1_000;
+ private static final double BANDWIDTH_MBPS = 1_000_000;
private Set<Link> allPathLinks;
- private boolean listenersRemoved;
- private LinkWeight linkData;
private int highlightDelay;
-
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- private PathService pathService;
-
private ElementId src, dst;
private String srcType, dstType;
private List<Path> paths;
private int pathIndex;
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final TopologyListener topologyListener = new InternalTopologyListener();
+ private final TunnelListener tunnelListener = new InnerPceWebTunnelListener();
+
protected TopologyService topologyService;
+ protected TunnelService tunnelService;
+ protected PceService pceService;
protected DeviceService deviceService;
-
-
@Override
public void init(UiConnection connection, ServiceDirectory directory) {
super.init(connection, directory);
- //TODO: Need add listeners.
- //topologyService = directory.get(TopologyService.class);
- //addListeners();
+ topologyService = directory.get(TopologyService.class);
+ tunnelService = directory.get(TunnelService.class);
+ pceService = directory.get(PceService.class);
+ deviceService = directory.get(DeviceService.class);
+ topologyService.addListener(topologyListener);
+ tunnelService.addListener(tunnelListener);
}
@Override
@@ -105,7 +139,19 @@
new ClearHandler(),
new SetSrcHandler(),
new SetDstHandler(),
- new SetPathHandler());
+ new SetPathHandler(),
+ new UpdatePathQueryHandler(),
+ new UpdatePathHandler(),
+ new RemovePathQueryHandler(),
+ new RemovePathHandler(),
+ new ShowTunnelHandler());
+ }
+
+ @Override
+ public void destroy() {
+ topologyService.removeListener(topologyListener);
+ tunnelService.removeListener(tunnelListener);
+ super.destroy();
}
// Handler classes
@@ -137,7 +183,6 @@
@Override
public void process(long sid, ObjectNode payload) {
- log.info("PCE WEB Set source process method invoked");
String id = string(payload, ID);
src = elementId(id);
srcType = string(payload, TYPE);
@@ -146,7 +191,6 @@
}
sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
srcType, src.toString(), SRC)));
-
}
}
@@ -167,7 +211,6 @@
if (src.equals(dst)) {
src = null;
}
-
sendMessage(TopoJson.highlightsMessage(addBadge(new Highlights(),
dstType, dst.toString(), DST)));
@@ -175,7 +218,7 @@
}
/**
- * Handles the 'patchcalculation' event received from the client.
+ * Handles the 'path calculation' event received from the client.
*/
private final class SetPathHandler extends RequestHandler {
@@ -185,15 +228,168 @@
@Override
public void process(long sid, ObjectNode payload) {
- String mode = string(payload, MODE);
+ String bandWidth = string(payload, BANDWIDTH);
+ String bandWidthType = string(payload, BANDWIDTHTYPE);
+ String costType = string(payload, COSTTYPE);
+ String lspType = string(payload, LSPTYPE);
+ String tunnelName = string(payload, TUNNEL_NAME);
- // TODO: Read user input[constraints] and call the path calculation based on
- //given constrainsts.
- findAndSendPaths();
+ if (tunnelName.equals(STRING_NULL)) {
+ log.error("tunnel name should not be empty");
+ return;
+ }
+
+ if (pceService == null) {
+ log.error("PCE service is not active");
+ return;
+ }
+
+ if (lspType == null) {
+ log.error("PCE setup path is failed.");
+ }
+
+ if ((src != null) && (dst != null)) {
+ findAndSendPaths(src, dst, bandWidth, bandWidthType, costType, lspType, tunnelName);
+ }
}
}
- // === ------------
+ /**
+ * Handles the 'update path query' event received from the client.
+ */
+ private final class UpdatePathQueryHandler extends RequestHandler {
+
+ public UpdatePathQueryHandler() {
+ super(PCEWEB_UPDATE_PATH_QUERY);
+ }
+
+ @Override
+ public void process(long sid, ObjectNode payload) {
+ String srcId = string(payload, SRCID);
+ ElementId src = elementId(srcId);
+ String dstId = string(payload, DSTID);
+ ElementId dst = elementId(dstId);
+ Device srcDevice = deviceService.getDevice((DeviceId) src);
+ Device dstDevice = deviceService.getDevice((DeviceId) dst);
+
+ TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+ .valueOf(srcDevice.annotations().value("lsrId")));
+ TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+ .valueOf(dstDevice.annotations().value("lsrId")));
+
+ Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
+ ObjectNode result = objectNode();
+ ArrayNode arrayNode = arrayNode();
+ for (Tunnel tunnel : tunnelSet) {
+ if (tunnel.type() == MPLS) {
+ arrayNode.add(tunnel.tunnelId().toString());
+ }
+ }
+
+ result.putArray(BUFFER_ARRAY).addAll(arrayNode);
+ sendMessage(PCEWEB_SHOW_TUNNEL, sid, result);
+ }
+ }
+
+ /**
+ * Handles the 'update path' event received from the client.
+ */
+ private final class UpdatePathHandler extends RequestHandler {
+
+ public UpdatePathHandler() {
+ super(PCEWEB_UPDATE_PATH);
+ }
+
+ @Override
+ public void process(long sid, ObjectNode payload) {
+ String bandWidth = string(payload, BANDWIDTH);
+ String bandWidthType = string(payload, BANDWIDTHTYPE);
+ String costType = string(payload, COSTTYPE);
+ String tunnelId = string(payload, TUNNEL_ID);
+
+ if (tunnelId == null) {
+ log.error("PCE update path is failed.");
+ }
+
+ findAndSendPathsUpdate(bandWidth, bandWidthType, costType, tunnelId);
+ }
+ }
+
+ /**
+ * Handles the 'remove path query' event received from the client.
+ */
+ private final class RemovePathQueryHandler extends RequestHandler {
+
+ public RemovePathQueryHandler() {
+ super(PCEWEB_REMOVE_PATH_QUERY);
+ }
+
+ @Override
+ public void process(long sid, ObjectNode payload) {
+ String srcId = string(payload, SRCID);
+ ElementId src = elementId(srcId);
+ String dstId = string(payload, DSTID);
+ ElementId dst = elementId(dstId);
+
+ Device srcDevice = deviceService.getDevice((DeviceId) src);
+ Device dstDevice = deviceService.getDevice((DeviceId) dst);
+
+ TunnelEndPoint tunSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+ .valueOf(srcDevice.annotations().value("lsrId")));
+ TunnelEndPoint tunDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress
+ .valueOf(dstDevice.annotations().value("lsrId")));
+
+ Collection<Tunnel> tunnelSet = tunnelService.queryTunnel(tunSrc, tunDst);
+ ObjectNode result = objectNode();
+ ArrayNode arrayNode = arrayNode();
+
+ for (Tunnel tunnel : tunnelSet) {
+ if (tunnel.type() == MPLS) {
+ arrayNode.add(tunnel.tunnelId().toString());
+ }
+ }
+
+ result.putArray(BUFFER_ARRAY).addAll(arrayNode);
+ sendMessage(PCEWEB_SHOW_TUNNEL_REMOVE, sid, result);
+ }
+ }
+
+ /**
+ * Handles the 'remove path' event received from the client.
+ */
+ private final class RemovePathHandler extends RequestHandler {
+
+ public RemovePathHandler() {
+ super(PCEWEB_REMOVE_PATH);
+ }
+
+ @Override
+ public void process(long sid, ObjectNode payload) {
+ String tunnelId = string(payload, TUNNEL_ID);
+
+ if (tunnelId == null) {
+ log.error("PCE update path is failed.");
+ }
+
+ findAndSendPathsRemove(tunnelId);
+ }
+ }
+
+ /**
+ * Handles the 'show the existed tunnels' event received from the client.
+ */
+ private final class ShowTunnelHandler extends RequestHandler {
+
+ public ShowTunnelHandler() {
+ super(PCEWEB_QUERY_TUNNELS);
+ }
+
+ @Override
+ public void process(long sid, ObjectNode payload) {
+ findTunnelAndHighlights();
+ }
+ }
+
/**
* provides the element id.
*/
@@ -204,45 +400,170 @@
return HostId.hostId(id);
}
}
- //TODO: Need to pass constraints to this method
- private void findAndSendPaths() {
- log.info("src={}; dst={};", src, dst);
- if (src != null && dst != null) {
- //TBD: Need to call pathcalulation API here
- hilightAndSendPaths();
+ /**
+ * Handles the setup path and highlights the path.
+ *
+ * @param bandWidth
+ * @param bandWidthType is the kbps or mbps
+ * @param costType is igp or te
+ * @param lspType is WITH_SIGNALLING,WITHOUT_SIGNALLING_AND_WITHOUT_SR or SR_WITHOUT_SIGNALLING
+ * @param tunnelName tunnel id
+ */
+ private void findAndSendPaths(ElementId src, ElementId dst, String bandWidth, String bandWidthType,
+ String costType, String lspType, String tunnelName) {
+ log.debug("src={}; dst={};", src, dst);
+ boolean path;
+ List<Constraint> listConstrnt;
+
+ listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
+
+ //LSP type
+ LspType lspTypeVal = null;
+ switch (lspType) {
+ case LSP_TYPE_CR:
+ lspTypeVal = LspType.WITH_SIGNALLING;
+ break;
+ case LSP_TYPE_SRBE:
+ lspTypeVal = LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+ break;
+ case LSP_TYPE_SRTE:
+ lspTypeVal = LspType.SR_WITHOUT_SIGNALLING;
+ break;
+ default:
+ log.error("Invalid LSP type");
+ break;
}
+ path = pceService.setupPath((DeviceId) src, (DeviceId) dst, tunnelName, listConstrnt, lspTypeVal);
+ if (!path) {
+ log.error("setup path is failed");
+ return;
+ }
+
+ return;
}
- //TODO: The below code is not used. Once get path from PCE app then below code will be use.
- // the below code will get path and it will highlight the selected path.
- //Currently primary path in use, there is no use of secondary path.
- //secondary path need to remove based on path received by PCE app.
- private ImmutableSet.Builder<Link> buildPaths(
- ImmutableSet.Builder<Link> pathBuilder) {
+ /**
+ * Handles the update path and highlights the path.
+ *
+ * @param bandWidth bandWidth
+ * @param bandWidthType is the kbps or mbps
+ * @param costType is igp or te
+ * @param tunnelName tunnel id
+ */
+ private void findAndSendPathsUpdate(String bandWidth, String bandWidthType, String costType, String tunnelIdStr) {
+ if (tunnelIdStr != null) {
+ List<Constraint> listConstrnt;
+
+ if (tunnelIdStr.equals(STRING_NULL)) {
+ log.error("update path is failed");
+ return;
+ }
+
+ if (pceService == null) {
+ log.error("PCE service is not active");
+ return;
+ }
+
+ listConstrnt = addBandwidthCostTypeConstraints(bandWidth, bandWidthType, costType);
+ TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
+ boolean path = pceService.updatePath(tunnelId, listConstrnt);
+
+ if (!path) {
+ log.error("update path is failed");
+ return;
+ }
+ }
+ return;
+ }
+
+ /**
+ * Handles the remove path and highlights the paths if existed.
+ *
+ * @param tunnelIdName tunnelId
+ */
+ private void findAndSendPathsRemove(String tunnelIdStr) {
+ if (tunnelIdStr != null) {
+ if (pceService == null) {
+ log.error("PCE service is not active");
+ return;
+ }
+
+ TunnelId tunnelId = TunnelId.valueOf(tunnelIdStr);
+ boolean path = pceService.releasePath(tunnelId);
+ if (!path) {
+ log.error("remove path is failed");
+ return;
+ }
+ }
+ return;
+ }
+
+ private ImmutableSet.Builder<Link> buildPaths(ImmutableSet.Builder<Link> pathBuilder) {
paths.forEach(path -> path.links().forEach(pathBuilder::add));
return pathBuilder;
}
- private ImmutableSet.Builder<Link> buildDisjointPaths(
- ImmutableSet.Builder<Link> pathBuilder) {
- paths.forEach(path -> {
- DisjointPath dp = (DisjointPath) path;
- pathBuilder.addAll(dp.primary().links());
- pathBuilder.addAll(dp.backup().links());
- });
- return pathBuilder;
+ /**
+ * Handles the preparation of constraints list with given bandwidth and cost-type.
+ *
+ * @param bandWidth bandWidth
+ * @param bandWidthType is the kbps or mbps
+ * @param costType is igp or te
+ * @param listConstrnt list of constraints
+ * @return
+ */
+ private List<Constraint> addBandwidthCostTypeConstraints(String bandWidth,
+ String bandWidthType,
+ String costType) {
+ List<Constraint> listConstrnt = new LinkedList<>();
+ //bandwidth
+ double bwValue = 0.0;
+ if (!bandWidth.equals(STRING_NULL)) {
+ bwValue = Double.parseDouble(bandWidth);
+ }
+ if (bandWidthType.equals(BANDWIDTH_TYPE_KBPS)) {
+ bwValue = bwValue * BANDWIDTH_KBPS;
+ } else {
+ bwValue = bwValue * BANDWIDTH_MBPS;
+ }
+
+ //Cost type
+ CostConstraint.Type costTypeVal = null;
+ switch (costType) {
+ case COST_TYPE_IGP:
+ costTypeVal = CostConstraint.Type.COST;
+ break;
+ case COST_TYPE_TE:
+ costTypeVal = CostConstraint.Type.TE_COST;
+ break;
+ default:
+ log.error("Invalid cost type");
+ break;
+ }
+
+ if (bwValue != 0.0) {
+ listConstrnt.add(BandwidthConstraint.of(bwValue, DataRateUnit.valueOf(BANDWIDTH_BPS)));
+ }
+
+ if (costTypeVal != null) {
+ listConstrnt.add(CostConstraint.of(costTypeVal));
+ }
+
+ return listConstrnt;
}
+ /**
+ * Handles the highlights of selected path.
+ */
private void hilightAndSendPaths() {
PceWebLinkMap linkMap = new PceWebLinkMap();
allPathLinks.forEach(linkMap::add);
-
Set<Link> selectedPathLinks;
- selectedPathLinks = paths.isEmpty() ? ImmutableSet.of()
- : ImmutableSet.copyOf(paths.get(pathIndex).links());
+ selectedPathLinks = paths.isEmpty() ?
+ ImmutableSet.of() : ImmutableSet.copyOf(paths.get(pathIndex).links());
Highlights highlights = new Highlights();
if (highlightDelay > 0) {
@@ -261,16 +582,32 @@
sendMessage(TopoJson.highlightsMessage(highlights));
}
+ /**
+ * Handles the addition of badge and highlights.
+ *
+ * @param highlights highlights
+ * @param type device type
+ * @param elemId device to be add badge
+ * @param src device to be add badge
+ * @return
+ */
private Highlights addBadge(Highlights highlights, String type,
String elemId, String src) {
- if (SWITCH.equals(type)) {
+ if (ROUTER.equals(type)) {
highlights = addDeviceBadge(highlights, elemId, src);
- } else if (ENDSTATION.equals(type)) {
- highlights = addHostBadge(highlights, elemId, src);
}
+
return highlights;
}
+ /**
+ * Handles the badge add and highlights.
+ *
+ * @param h highlights
+ * @param elemId device to be add badge
+ * @param type device type
+ * @return highlights
+ */
private Highlights addDeviceBadge(Highlights h, String elemId, String type) {
DeviceHighlight dh = new DeviceHighlight(elemId);
dh.setBadge(createBadge(type));
@@ -278,18 +615,59 @@
return h;
}
- private Highlights addHostBadge(Highlights h, String elemId, String type) {
- HostHighlight hh = new HostHighlight(elemId);
- hh.setBadge(createBadge(type));
- h.add(hh);
- return h;
- }
-
+ /**
+ * Handles the node badge add and highlights.
+ *
+ * @param type device type
+ * @return badge of given node
+ */
private NodeBadge createBadge(String type) {
return NodeBadge.text(type);
}
- //TODO: Listeners need to add.
- //If topology changes then path need to be re calculate.
+ /**
+ * Handles the event of topology listeners.
+ */
+ private class InternalTopologyListener implements TopologyListener {
+ @Override
+ public void event(TopologyEvent event) {
+ highlightDelay = DELAY_MS;
+ findTunnelAndHighlights();
+ highlightDelay = 0;
+ }
+ }
+ /**
+ * Handles the event of tunnel listeners.
+ */
+ private class InnerPceWebTunnelListener implements TunnelListener {
+ @Override
+ public void event(TunnelEvent event) {
+ Tunnel tunnel = event.subject();
+ if (tunnel.type() == MPLS) {
+ highlightDelay = DELAY_MS;
+ findTunnelAndHighlights();
+ highlightDelay = 0;
+ }
+ }
+ }
+
+ /**
+ * Handles the event of topology listeners.
+ */
+ private void findTunnelAndHighlights() {
+ Collection<Tunnel> tunnelSet = null;
+ tunnelSet = tunnelService.queryTunnel(MPLS);
+ for (Tunnel tunnel : tunnelSet) {
+ if (tunnel.path() == null) {
+ log.info("path does not exist");
+ return;
+ }
+ paths.add(tunnel.path());
+ }
+
+ ImmutableSet.Builder<Link> builder = ImmutableSet.builder();
+ allPathLinks = buildPaths(builder).build();
+ hilightAndSendPaths();
+ }
}
diff --git a/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovOverlay.java b/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovOverlay.java
index 087f4bc..41f3243 100644
--- a/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovOverlay.java
+++ b/apps/pce/pceweb/src/main/java/org/onosproject/pceweb/PceWebTopovOverlay.java
@@ -63,7 +63,6 @@
public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) {
pp.title(MY_TITLE);
- log.info("Modify device details called.");
DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
diff --git a/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovDemo.js b/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovDemo.js
index 096f872..e16e15b 100644
--- a/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovDemo.js
+++ b/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovDemo.js
@@ -21,16 +21,23 @@
// injected refs
var $log, fs, flash, wss, tps, ns, tds, ds;
-
+ var tunnelNameData, tunnelNameDataRemove;
// constants
var srcMessage = 'pceTopovSetSrc',
dstMessage = 'pceTopovSetDst',
clearMessage = 'pceTopovClear',
- setModemsg = 'pceTopovSetMode',
- L3dev = 'requestIpDevDetails';
+ setPathmsg = 'pceTopovSetMode',
+ updatePathmsgQuery = 'pceTopovUpdateQuery',
+ remPathmsgQuery = 'pceTopovRemQuery',
+ updatePathmsg = 'pceTopovUpdate',
+ remPathmsg = 'pceTopovRem',
+ showTunnelInfoMsg = 'pceTopovShowTunnels',
+ queryDisplayTunnelMsg = 'pceTopovTunnelDisplay',
+ showTunnelInfoRemoveMsg = 'pceTopovShowTunnelsRem';
// internal state
var currentMode = null;
-
+ var handlerMap = {},
+ handlerMapRem = {};
// === ---------------------------
// === Helper functions
@@ -58,153 +65,326 @@
flash.flash('Cleared source and destination');
}
- function dOk() {
- var bandWidth = d3.select('#band-width-box').property("checked");
- var bandValue = null;
- var bandType = null;
-
- if (bandWidth) {
-
- bandValue = d3.select('#band-width-value').property("value");
-
- if (d3.select("#band-kpbs-val").property("checked")) {
- bandType = 'kbps';
- } else if (d3.select('#band-mpbs-val').property("checked")) {
- bandType = 'mbps';
- }
- }
-
- var costType = d3.select('#pce-cost-type').property("checked");
- var costTypeVal = null;
-
- if (costType) {
-
- if (d3.select("#pce-cost-type-igp").property("checked")) {
- costTypeVal = 'igp';
- } else if (d3.select('#pce-cost-type-te').property("checked")) {
- costTypeVal = 'te';
- }
- }
-
- var lspType = d3.select('#pce-lsp-type').property("checked");
- var lspTypeVal = null;
-
- if (lspType) {
-
- if (d3.select("#pce-lsp-type-cr").property("checked")) {
- lspTypeVal = 'cr';
- } else if (d3.select('#pce-lsp-type-srbe').property("checked")) {
- lspTypeVal = 'srbe';
- } else if (d3.select('#pce-lsp-type-srte').property("checked")) {
- lspTypeVal = 'srte';
- }
- }
-
- //TBD: Read the user inputs and need to send the event for calculating the path based on constrainsts.
- // TBD: Need to read IGP cost type and LSP type.
- //wss.sendEvent(setModemsg);
- //flash.flash('creat path message');
-
- $log.debug('Dialog OK button clicked');
- }
-
function dClose() {
$log.debug('Dialog Close button clicked (or Esc pressed)');
}
function createUserText() {
- var content = ds.createDiv();
- var form = content.append('form');
- var p = form.append('p');
+ var content = ds.createDiv('constraints-input'),
+ form = content.append('form'),
+ p = form.append('p');
+
+ function addAttribute(name, id, nameField, type) {
+ p.append('input').attr({
+ type: type,
+ name: name,
+ id: id
+ });
+
+ p.append('span').text(nameField);
+ p.append('br');
+ }
//Add the bandwidth related inputs.
- p.append('input').attr({
- id: 'band-width-box',
- type: 'checkbox',
- name: 'band-width-name'
- });
- p.append('span').text('Band Width');
- p.append('br');
- p.append('input').attr({
- id: 'band-width-value',
- type: 'number',
- name: 'band-width-value-name'
- });
- p.append('input').attr({
- id: 'band-kpbs-val',
- type: 'radio',
- name: 'pce-band-type'
- });
- p.append('span').text('kpbs');
- p.append('input').attr({
- id: 'band-mpbs-val',
- type: 'radio',
- name: 'pce-band-type'
- });
- p.append('span').text('mpbs');
- p.append('br');
-
+ addAttribute('band-width-name', 'band-width-box', 'Band Width', 'checkbox');
+ addAttribute('band-width-value-name', 'band-width-value', null, 'number');
+ addAttribute('pce-band-type', 'band-kpbs-val', 'kbps', 'radio');
+ addAttribute('pce-band-type', 'band-mpbs-val', 'mbps', 'radio');
//Add the cost type related inputs.
- p.append('input').attr({
- id: 'pce-cost-type',
- type: 'checkbox',
- name: 'pce-cost-type-name'
- });
- p.append('span').text('Cost Type');
- p.append('br');
- p.append('input').attr({
- id: 'pce-cost-type-igp',
- type: 'radio',
- name: 'pce-cost-type-valname'
- });
- p.append('span').text('IGP');
- p.append('input').attr({
- id: 'pce-cost-type-te',
- type: 'radio',
- name: 'pce-cost-type-valname'
- });
- p.append('span').text('TE');
- p.append('br');
-
+ addAttribute('pce-cost-type-name', 'pce-cost-type', 'Cost Type', 'checkbox');
+ addAttribute('pce-cost-type-valname', 'pce-cost-type-igp', 'IGP', 'radio');
+ addAttribute('pce-cost-type-valname', 'pce-cost-type-te', 'TE', 'radio');
//Add the LSP type related inputs.
- p.append('input').attr({
- id: 'pce-lsp-type',
- type: 'checkbox',
- name: 'pce-lsp-type-name'
- });
- p.append('span').text('Lsp Type');
- p.append('br');
- p.append('input').attr({
- id: 'pce-lsp-type-cr',
- type: 'radio',
- name: 'pce-lsp-type-valname'
- });
- p.append('span').text('CR');
- p.append('input').attr({
- id: 'pce-lsp-type-srbe',
- type: 'radio',
- name: 'pce-lsp-type-valname'
- });
- p.append('span').text('SR BE');
- p.append('input').attr({
- id: 'pce-lsp-type-srte',
- type: 'radio',
- name: 'pce-lsp-type-valname'
- });
- p.append('span').text('SR TE');
+ addAttribute('pce-lsp-type-name', 'pce-lsp-type', 'Lsp Type', 'checkbox');
+ addAttribute('pce-lsp-type-valname', 'pce-lsp-type-cr', 'WITH SIGNALLING', 'radio');
+ addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srbe', 'WITHOUT SR WITHOUT SIGNALLING', 'radio');
+ addAttribute('pce-lsp-type-valname', 'pce-lsp-type-srte', 'WITH SR WITHOUT SIGNALLING', 'radio');
+ //Add the tunnel name
+ addAttribute('pce-tunnel-name', 'pce-tunnel-name-id', 'Tunnel Name', 'text');
return content;
}
- function setMode() {
+ function createUserTextUpdate(data) {
+ var content = ds.createDiv(),
+ form = content.append('form'),
+ p = form.append('p');
+
+ p.append('span').text('Tunnel IDs');
+ p.append('br');
+
+ data.a.forEach( function (val, idx) {
+ p.append('input').attr({
+ id: 'tunnel-id-'+idx,
+ type: 'radio',
+ name: 'tunnel-id-name',
+ value: val
+ });
+
+ p.append('span').text(val);
+ p.append('br');
+
+ } );
+
+ return content;
+ }
+
+ function createUserTextUpdatePathEvent() {
+ var content = ds.createDiv(),
+ form = content.append('form'),
+ p = form.append('p');
+
+ function addAttribute(name, id, nameField, type) {
+ p.append('input').attr({
+ type: type,
+ name: name,
+ id: id
+ });
+
+ p.append('span').text(nameField);
+ p.append('br');
+ }
+
+ //Add the bandwidth related inputs.
+ addAttribute('band-width-name', 'update-band-width-box', 'Band Width', 'checkbox');
+ addAttribute('band-width-value-name', 'update-band-width-value', null, 'number');
+ addAttribute('pce-band-type', 'update-band-kpbs-val', 'kbps', 'radio');
+ addAttribute('pce-band-type', 'update-band-mpbs-val', 'mbps', 'radio');
+ //Add the cost type related inputs.
+ addAttribute('pce-cost-type', 'update-pce-cost-type', 'Cost Type', 'checkbox');
+ addAttribute('pce-cost-type-value', 'update-pce-cost-type-igp', 'IGP', 'radio');
+ addAttribute('pce-cost-type-value', 'update-pce-cost-type-te', 'TE', 'radio');
+
+ return content;
+ }
+
+ function createUserTextRemove(data) {
+
+ var content = ds.createDiv(),
+ form = content.append('form'),
+ p = form.append('p');
+
+ p.append('span').text('Tunnel IDs');
+ p.append('br');
+
+ data.a.forEach( function (val, idx) {
+ p.append('input').attr({
+ id: 'tunnel-id-remove-'+idx,
+ type: 'checkbox',
+ name: 'tunnel-id-name-remove',
+ value: val
+ });
+
+ p.append('span').text(val);
+ p.append('br');
+ } );
+
+ return content;
+ }
+
+ function isChecked(viewId) {
+ return d3.select('#' + viewId).property('checked');
+ }
+
+ function getCheckedValue(viewId) {
+ return d3.select('#' + viewId).property('value');
+ }
+
+ function showTunnelInformation(data) {
+ wss.unbindHandlers(handlerMap);
+ tunnelNameData = data;
+
+ function dOkUpdate() {
+ var tdString = '' ;
+ tunnelNameData.a.forEach( function (val, idx) {
+ var tunnelName = isChecked('tunnel-id-'+idx);
+ if (tunnelName)
+ {
+ tdString = val;
+ }
+ } );
+
+ if (tdString) {
+ constraintsUpdateDialog(tdString);
+ } else {
+ $log.debug("No tunnel id is selected.");
+ }
+
+ $log.debug('Dialog OK button clicked');
+ }
+
tds.openDialog()
- .setTitle('constraints user')
+ .setTitle('Available LSPs with selected device')
+ .addContent(createUserTextUpdate(data))
+ .addOkChained(dOkUpdate, 'GOTO Selection of constraints')
+ .addCancel(dClose, 'Close')
+ .bindKeys();
+ }
+
+ function constraintsUpdateDialog(tunnelId) {
+
+ // invoked when the OK button is pressed on this dialog
+ function dOkUpdateEvent() {
+ $log.debug('Select constraints for update path Dialog OK button pressed');
+
+ var bandWidth = isChecked('update-band-width-box'),
+ bandValue = null,
+ bandType = null;
+
+ if (bandWidth) {
+ bandValue = d3.select('#update-band-width-value');
+
+ if (isChecked('update-band-kpbs-val')) {
+ bandType = 'kbps';
+ } else if (isChecked('update-band-mpbs-val')) {
+ bandType = 'mbps';
+ }
+ }
+
+ var costType = isChecked('update-pce-cost-type'),
+ costTypeVal = null;
+
+ if (costType) {
+ if (isChecked('update-pce-cost-type-igp')) {
+ costTypeVal = 'igp';
+ } else if (isChecked('update-pce-cost-type-te')) {
+ costTypeVal = 'te';
+ }
+ }
+
+ wss.sendEvent(updatePathmsg, {
+ bw: bandValue,
+ ctype: costTypeVal,
+ tunnelname: tunnelId
+ });
+
+ flash.flash('update path message');
+
+ }
+
+ tds.openDialog()
+ .setTitle('Select constraints for update path')
+ .addContent(createUserTextUpdatePathEvent())
+ .addCancel()
+ .addOk(dOkUpdateEvent, 'Update Path') // NOTE: NOT the "chained" version!
+ .bindKeys();
+
+ }
+
+ function showTunnelInformationRemove(data) {
+
+ wss.unbindHandlers(handlerMapRem);
+ tunnelNameDataRemove = data;
+ tds.openDialog()
+ .setTitle('Available Tunnels for remove')
+ .addContent(createUserTextRemove(data))
+ .addOk(dOkRemove, 'Remove')
+ .addCancel(dClose, 'Close')
+ .bindKeys();
+ }
+
+ //setup path
+ function setMode() {
+
+ function dOk() {
+ var bandWidth = isChecked('band-width-box'),
+ bandValue = null,
+ bandType = null;
+
+ if (bandWidth) {
+ bandValue = getCheckedValue('band-width-value');
+
+ if (isChecked('band-kpbs-val')) {
+ bandType = 'kbps';
+ } else if (isChecked('band-mpbs-val')) {
+ bandType = 'mbps';
+ }
+ }
+
+ var costType = isChecked('pce-cost-type'),
+ costTypeVal = null;
+
+ if (costType) {
+ if (isChecked('pce-cost-type-igp')) {
+ costTypeVal = 'igp';
+ } else if (isChecked('pce-cost-type-te')) {
+ costTypeVal = 'te';
+ }
+ }
+
+ var lspType = isChecked('pce-lsp-type'),
+ lspTypeVal = null;
+
+ if (lspType) {
+ if (isChecked('pce-lsp-type-cr')) {
+ lspTypeVal = 'cr';
+ } else if (isChecked('pce-lsp-type-srbe')) {
+ lspTypeVal = 'srbe';
+ } else if (isChecked('pce-lsp-type-srte')) {
+ lspTypeVal = 'srte';
+ }
+ }
+
+ wss.sendEvent(setPathmsg, {
+ bw: bandValue,
+ bwtype: bandType,
+ ctype: costTypeVal,
+ lsptype: lspTypeVal,
+ tunnelname: getCheckedValue('pce-tunnel-name-id')
+ });
+
+ flash.flash('create path message');
+ $log.debug('Dialog OK button clicked');
+ }
+
+ tds.openDialog()
+ .setTitle('constraints selection')
.addContent(createUserText())
.addOk(dOk, 'OK')
.addCancel(dClose, 'Close')
.bindKeys();
}
+ function updatePath(node) {
+
+ wss.sendEvent(updatePathmsgQuery, {
+ srid: node[0],
+ dsid: node[1]
+ });
+
+ handlerMap[showTunnelInfoMsg] = showTunnelInformation;
+ wss.bindHandlers(handlerMap);
+
+ flash.flash('update path message');
+ }
+
+ function dOkRemove() {
+
+ tunnelNameDataRemove.a.forEach( function (val, idx) {
+ var tunnelNameVal = isChecked('tunnel-id-remove-'+idx);
+ if (tunnelNameVal) {
+ wss.sendEvent(remPathmsg, {
+ tunnelid: val
+ });
+ }
+ } );
+
+ flash.flash('remove path message');
+ }
+
+ function remPath(node) {
+ wss.sendEvent(remPathmsgQuery, {
+ srid: node[0],
+ dsid: node[1]
+ });
+
+ handlerMapRem[showTunnelInfoRemoveMsg] = showTunnelInformationRemove;
+ wss.bindHandlers(handlerMapRem);
+ }
+
+ function queryTunnelDisplay() {
+ wss.sendEvent(queryDisplayTunnelMsg);
+ }
// === ---------------------------
// === Module Factory Definition
@@ -227,8 +407,10 @@
setSrc: setSrc,
setDst: setDst,
clear: clear,
- setMode: setMode
-
+ setMode: setMode,
+ updatePath: updatePath,
+ remPath: remPath,
+ queryTunnelDisplay: queryTunnelDisplay
};
}]);
}());
diff --git a/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovOverlay.js b/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovOverlay.js
index 63a4d2d..4ad40a0 100644
--- a/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovOverlay.js
+++ b/apps/pce/pceweb/src/main/resources/app/view/pcewebTopov/pcewebTopovOverlay.js
@@ -34,7 +34,6 @@
glyphId: 'topo',
tooltip: 'PCE web Topo Overlay',
-
activate: function () {
$log.debug("PCE web topology overlay ACTIVATED");
},
@@ -112,11 +111,32 @@
},
1: {
cb: function () {
- pps.setMode("shortest");
+ pps.setMode();
},
- tt: 'Select constraints for LSP',
+ tt: 'Setup path',
+ gid: 'plus'
+ },
+ 2: {
+ cb: function () {
+ pps.updatePath(selection);
+ },
+ tt: 'Update path',
gid: '*jp'
},
+ 3: {
+ cb: function () {
+ pps.remPath(selection);
+ },
+ tt: 'Remove path',
+ gid: 'minus'
+ },
+ 4: {
+ cb: function () {
+ pps.queryTunnelDisplay();
+ },
+ tt: 'Show Tunnels',
+ gid: 'checkMark'
+ },
0: {
cb: function () {
pps.clear();
@@ -126,7 +146,7 @@
},
_keyOrder: [
- 'openBracket', 'closeBracket', '1', '0'
+ 'openBracket', 'closeBracket', '1', '2', '3', '4', '0'
]
},
hooks: {
@@ -145,6 +165,9 @@
},
single: function (data) {
selectionCallback(data);
+ },
+ multi: function (selectOrder) {
+ selectionCallback(selectOrder);
}
}
};
diff --git a/apps/pce/pom.xml b/apps/pce/pom.xml
index 7ba4bca..e6e6163 100644
--- a/apps/pce/pom.xml
+++ b/apps/pce/pom.xml
@@ -21,6 +21,7 @@
<groupId>org.onosproject</groupId>
<artifactId>onos-apps</artifactId>
<version>1.6.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>