[ONOS-4163] Provider side changes to support stateful PCE and PCECC
Change-Id: I0a57ed1d1e505a2e94921fd5f5d92426a105ad12
diff --git a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java
index dd5d5f5..9f61b2a 100644
--- a/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java
+++ b/protocols/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java
@@ -52,6 +52,8 @@
import org.onosproject.pcepio.protocol.PcepOpenObject;
import org.onosproject.pcepio.protocol.PcepType;
import org.onosproject.pcepio.protocol.PcepVersion;
+import org.onosproject.pcepio.types.IPv4RouterIdOfLocalNodeSubTlv;
+import org.onosproject.pcepio.types.NodeAttributesTlv;
import org.onosproject.pcepio.types.PceccCapabilityTlv;
import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
@@ -136,7 +138,7 @@
@Override
void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException {
- log.debug("Message received in OPEN WAIT State");
+ log.info("Message received in OPEN WAIT State");
//check for open message
if (m.getType() != PcepType.OPEN) {
@@ -166,6 +168,33 @@
h.deadTime = DEADTIMER_MAXIMUM_VALUE;
}
}
+
+ LinkedList<PcepValueType> optionalTlvs = pOpenmsg.getPcepOpenObject().getOptionalTlv();
+ for (PcepValueType optionalTlv : optionalTlvs) {
+ if (optionalTlv instanceof NodeAttributesTlv) {
+ List<PcepValueType> subTlvs = ((NodeAttributesTlv) optionalTlv)
+ .getllNodeAttributesSubTLVs();
+ for (PcepValueType subTlv : subTlvs) {
+ if (subTlv instanceof IPv4RouterIdOfLocalNodeSubTlv) {
+ h.thispccId = PccId.pccId(IpAddress
+ .valueOf(((IPv4RouterIdOfLocalNodeSubTlv) subTlv).getInt()));
+ break;
+ }
+ }
+ break;
+ }
+ }
+
+ if (h.thispccId == null) {
+ final SocketAddress address = h.channel.getRemoteAddress();
+ if (!(address instanceof InetSocketAddress)) {
+ throw new IOException("Invalid client connection. Pcc is indentifed based on IP");
+ }
+
+ final InetSocketAddress inetAddress = (InetSocketAddress) address;
+ h.thispccId = PccId.pccId(IpAddress.valueOf(inetAddress.getAddress()));
+ }
+
h.sendHandshakeOpenMessage();
h.pcepPacketStats.addOutPacket();
h.setState(KEEPWAIT);
@@ -178,23 +207,16 @@
KEEPWAIT(false) {
@Override
void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException {
- log.debug("message received in KEEPWAIT state");
+ log.info("message received in KEEPWAIT state");
//check for keep alive message
if (m.getType() != PcepType.KEEP_ALIVE) {
// When the message type is not keep alive message increment the wrong packet statistics
h.processUnknownMsg();
- log.debug("message is not KEEPALIVE message");
+ log.error("message is not KEEPALIVE message");
} else {
// Set the client connected status
h.pcepPacketStats.addInPacket();
- final SocketAddress address = h.channel.getRemoteAddress();
- if (!(address instanceof InetSocketAddress)) {
- throw new IOException("Invalid client connection. Pcc is indentifed based on IP");
- }
log.debug("sending keep alive message in KEEPWAIT state");
-
- final InetSocketAddress inetAddress = (InetSocketAddress) address;
- h.thispccId = PccId.pccId(IpAddress.valueOf(inetAddress.getAddress()));
h.pc = h.controller.getPcepClientInstance(h.thispccId, h.sessionId, h.pcepVersion,
h.pcepPacketStats);
//Get pc instance and set capabilities
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java
index 0b68845..a2a4d72 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java
@@ -25,7 +25,7 @@
import org.onosproject.pcepio.types.PcepErrorDetailInfo;
import org.onosproject.pcepio.types.PcepObjectHeader;
import org.onosproject.pcepio.types.PcepValueType;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.StatefulLspDbVerTlv;
import org.onosproject.pcepio.types.StatefulLspErrorCodeTlv;
import org.onosproject.pcepio.types.StatefulRsvpErrorSpecTlv;
@@ -325,8 +325,8 @@
switch (hType) {
- case StatefulIPv4LspIdentidiersTlv.TYPE:
- tlv = StatefulIPv4LspIdentidiersTlv.read(cb);
+ case StatefulIPv4LspIdentifiersTlv.TYPE:
+ tlv = StatefulIPv4LspIdentifiersTlv.read(cb);
break;
case StatefulLspErrorCodeTlv.TYPE:
iValue = cb.readInt();
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java
index 5fe0777..fd5a47a 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java
@@ -45,7 +45,7 @@
*/
protected static final Logger log = LoggerFactory.getLogger(PathSetupTypeTlv.class);
- public static final short TYPE = 0; //TODO : need to reassign the value as per RFC
+ public static final short TYPE = 28;
public static final short LENGTH = 4;
private final byte pst;
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlv.java
similarity index 90%
rename from protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java
rename to protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlv.java
index 3c9e9aa..a063d60 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlv.java
@@ -28,7 +28,7 @@
/**
* Provides StatefulIPv4LspIdentidiersTlv.
*/
-public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
+public class StatefulIPv4LspIdentifiersTlv implements PcepValueType {
/* IPV4-LSP-IDENTIFIERS TLV format
*
@@ -50,7 +50,7 @@
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
- protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class);
+ protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentifiersTlv.class);
public static final short TYPE = 18;
public static final short LENGTH = 16;
@@ -70,7 +70,7 @@
* @param extendedTunnelId extended tunnel id
* @param ipv4EgressAddress egress ipv4 address
*/
- public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
+ public StatefulIPv4LspIdentifiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
int ipv4EgressAddress) {
this.ipv4IngressAddress = ipv4IngressAddress;
@@ -90,9 +90,9 @@
* @param ipv4EgressAddress egress ipv4 address
* @return object of StatefulIPv4LspIdentidiersTlv
*/
- public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
+ public static StatefulIPv4LspIdentifiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
int extendedTunnelId, int ipv4EgressAddress) {
- return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
+ return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
ipv4EgressAddress);
}
@@ -106,6 +106,15 @@
}
/**
+ * Returns LSP id.
+ *
+ * @return lspId
+ */
+ public short getLspId() {
+ return this.lspId;
+ }
+
+ /**
* Returns extendedTunnelId.
*
* @return extendedTunnelId
@@ -157,8 +166,8 @@
if (this == obj) {
return true;
}
- if (obj instanceof StatefulIPv4LspIdentidiersTlv) {
- StatefulIPv4LspIdentidiersTlv other = (StatefulIPv4LspIdentidiersTlv) obj;
+ if (obj instanceof StatefulIPv4LspIdentifiersTlv) {
+ StatefulIPv4LspIdentifiersTlv other = (StatefulIPv4LspIdentifiersTlv) obj;
return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress)
&& Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId)
&& Objects.equals(this.extendedTunnelId, other.extendedTunnelId)
@@ -193,7 +202,7 @@
short tunnelId = c.readShort();
int extendedTunnelId = c.readInt();
int ipv4EgressAddress = c.readInt();
- return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
+ return new StatefulIPv4LspIdentifiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
ipv4EgressAddress);
}
diff --git a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepOpenMsgTest.java b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepOpenMsgTest.java
index debef2f..ce8a452 100644
--- a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepOpenMsgTest.java
+++ b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepOpenMsgTest.java
@@ -555,4 +555,40 @@
assertThat(testOpenMsg, is(openMsg));
}
+
+ /**
+ * This test case checks open object with LSR id encoded.
+ */
+ @Test
+ public void openMessageTest16() throws PcepParseException, PcepOutOfBoundMessageException {
+
+ byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, // common header
+ 0x01, 0x10, 0x00, 0x14, // common object header
+ 0x20, 0x05, 0x1E, 0x01, // OPEN object
+ (byte) 0xFF, 0x05, 0x00, 0x08, // Node attribute TLV
+ 0x00, 0x11, 0x00, 0x04, // PCEP-LS-IPv4-ROUTER-ID sub tlv
+ 0x02, 0x02, 0x02, 0x02
+ };
+
+ byte[] testOpenMsg = {0};
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(openMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = null;
+
+ message = reader.readFrom(buffer);
+
+ assertThat(message, instanceOf(PcepOpenMsg.class));
+
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+ message.writeTo(buf);
+ testOpenMsg = buf.array();
+
+ int readLen = buf.writerIndex() - 0;
+ testOpenMsg = new byte[readLen];
+ buf.readBytes(testOpenMsg, 0, readLen);
+ assertThat(testOpenMsg, is(openMsg));
+
+ }
}
diff --git a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepReportMsgExtTest.java b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepReportMsgExtTest.java
index 1804b38..9692119 100644
--- a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepReportMsgExtTest.java
+++ b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/protocol/PcepReportMsgExtTest.java
@@ -184,14 +184,14 @@
0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
0x07, 0x10, 0x00, 0x14, //ERO object
- 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //ERO IPv4 subobjects
0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object
0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object
- 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
+ 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, //RRO IPv4 subobjects
0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
@@ -216,4 +216,83 @@
assertThat(testReportMsg, is(reportMsg));
}
+
+ /**
+ * Tests PCRpt msg with Path-Setup-Type TLV as SR.
+ *
+ * @throws PcepParseException
+ * @throws PcepOutOfBoundMessageException
+ */
+ @Test
+ public void reportMessageTest43() throws PcepParseException, PcepOutOfBoundMessageException {
+
+ byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x3C,
+ 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
+ 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+ 0x00, 0x00, 0x00, 0x01,
+ 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
+ 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
+ 0x07, 0x10, 0x00, 0x14, //ERO object
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //ERO IPv4 subobjects
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
+ };
+
+ byte[] testReportMsg = {0};
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(reportMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = null;
+
+ message = reader.readFrom(buffer);
+ assertThat(message, instanceOf(PcepReportMsg.class));
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+ message.writeTo(buf);
+
+ int readLen = buf.writerIndex();
+ testReportMsg = new byte[readLen];
+ buf.readBytes(testReportMsg, 0, readLen);
+
+ assertThat(testReportMsg, is(reportMsg));
+ }
+
+ /**
+ * Tests PCRpt msg with Path-Setup-Type TLV as "without SR and without signalling".
+ *
+ * @throws PcepParseException
+ * @throws PcepOutOfBoundMessageException
+ */
+ @Test
+ public void reportMessageTest44() throws PcepParseException, PcepOutOfBoundMessageException {
+
+ byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x3C,
+ 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
+ 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+ 0x00, 0x00, 0x00, 0x02,
+ 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
+ 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
+ 0x07, 0x10, 0x00, 0x14, //ERO object
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //ERO IPv4 subobjects
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
+ };
+
+ byte[] testReportMsg = {0};
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(reportMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = null;
+
+ message = reader.readFrom(buffer);
+ assertThat(message, instanceOf(PcepReportMsg.class));
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+ message.writeTo(buf);
+
+ int readLen = buf.writerIndex();
+ testReportMsg = new byte[readLen];
+ buf.readBytes(testReportMsg, 0, readLen);
+
+ assertThat(testReportMsg, is(reportMsg));
+ }
+
}
diff --git a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlvTest.java b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlvTest.java
similarity index 75%
rename from protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlvTest.java
rename to protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlvTest.java
index f59a95c..46fc453 100644
--- a/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlvTest.java
+++ b/protocols/pcep/pcepio/src/test/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentifiersTlvTest.java
@@ -18,7 +18,10 @@
import com.google.common.testing.EqualsTester;
import org.junit.Test;
-public class StatefulIPv4LspIdentidiersTlvTest {
+/**
+ * Tests class StatefulIPv4LspIdentifiersTlv.
+ */
+public class StatefulIPv4LspIdentifiersTlvTest {
private final int ipv4IngressAddress = 1;
private final short lspId = 1;
@@ -26,7 +29,7 @@
private final int extendedTunnelId = 1;
private final int ipv4EgressAddress = 1;
- private final StatefulIPv4LspIdentidiersTlv tlv1 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress, lspId,
+ private final StatefulIPv4LspIdentifiersTlv tlv1 = StatefulIPv4LspIdentifiersTlv.of(ipv4IngressAddress, lspId,
tunnelId, extendedTunnelId, ipv4EgressAddress);
private final int ipv4IngressAddress1 = 1;
@@ -35,7 +38,7 @@
private final int extendedTunnelId1 = 1;
private final int ipv4EgressAddress1 = 1;
- private final StatefulIPv4LspIdentidiersTlv tlv2 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress1, lspId1,
+ private final StatefulIPv4LspIdentifiersTlv tlv2 = StatefulIPv4LspIdentifiersTlv.of(ipv4IngressAddress1, lspId1,
tunnelId1, extendedTunnelId1, ipv4EgressAddress1);
private final int ipv4IngressAddress2 = 2;
@@ -44,9 +47,12 @@
private final int extendedTunnelId2 = 2;
private final int ipv4EgressAddress2 = 2;
- private final StatefulIPv4LspIdentidiersTlv tlv3 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress2, lspId2,
+ private final StatefulIPv4LspIdentifiersTlv tlv3 = StatefulIPv4LspIdentifiersTlv.of(ipv4IngressAddress2, lspId2,
tunnelId2, extendedTunnelId2, ipv4EgressAddress2);
+ /**
+ * Tests equality of objects of class StatefulIPv4LspIdentifiersTlv.
+ */
@Test
public void basics() {
new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/LspType.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/LspType.java
new file mode 100644
index 0000000..8efa5f2
--- /dev/null
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/LspType.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.provider.pcep.tunnel.impl;
+
+/**
+ * Representation of LSP type.
+ */
+public enum LspType {
+ /**
+ * Signifies that path is created via signaling mode.
+ */
+ WITH_SIGNALLING(0),
+
+ /**
+ * Signifies that path is created via SR mode.
+ */
+ SR_WITHOUT_SIGNALLING(1),
+
+ /**
+ * Signifies that path is created via without signaling and without SR mode.
+ */
+ WITHOUT_SIGNALLING_AND_WITHOUT_SR(2);
+
+ int value;
+
+ /**
+ * Assign val with the value as the LSP type.
+ *
+ * @param val LSP type
+ */
+ LspType(int val) {
+ value = val;
+ }
+
+ /**
+ * Returns value of LSP type.
+ *
+ * @return LSP type
+ */
+ public byte type() {
+ return (byte) value;
+ }
+}
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepAnnotationKeys.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepAnnotationKeys.java
new file mode 100644
index 0000000..5b9ef66
--- /dev/null
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepAnnotationKeys.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+/**
+ * Collection of keys for annotation for PCEP tunnels.
+ */
+public final class PcepAnnotationKeys {
+
+ /**
+ * Prohibits instantiation.
+ */
+ private PcepAnnotationKeys() {
+ }
+
+ /**
+ * Annotation key for bandwidth.
+ * The value for this key is interpreted as Mbps.
+ */
+ public static final String BANDWIDTH = "bandwidth";
+
+ /**
+ * Annotation key for the LSP signaling type.
+ */
+ public static final String LSP_SIG_TYPE = "lspSigType";
+
+ /**
+ * Annotation key for the PCC tunnel id.
+ */
+ public static final String PCC_TUNNEL_ID = "PccTunnelId";
+
+ /**
+ * Annotation key for the LSP id assigned per tunnel per session.
+ */
+ public static final String PLSP_ID = "PLspId";
+
+ /**
+ * Annotation key for the LSP id assigned per tunnel.
+ */
+ public static final String LOCAL_LSP_ID = "localLspId";
+}
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java
new file mode 100644
index 0000000..ef628ed
--- /dev/null
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepLspStatus.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+
+/**
+ * Representation of the PCEP LSP state.
+ */
+public enum PcepLspStatus {
+
+ /**
+ * Signifies that the LSP is not active.
+ */
+ DOWN,
+
+ /**
+ * Signifies that the LSP is signalled.
+ */
+ UP,
+
+ /**
+ * Signifies that the LSP is up and carrying traffic.
+ */
+ ACTIVE,
+
+ /**
+ * Signifies that the LSP is being torn down, resources are being released.
+ */
+ GOING_DOWN,
+
+ /**
+ * Signifies that the LSP is being signalled.
+ */
+ GOING_UP;
+
+ /**
+ * Returns the applicable PCEP LSP status corresponding to ONOS tunnel state.
+ *
+ * @param tunnelState ONOS tunnel state
+ */
+ public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) {
+
+ switch (tunnelState) {
+
+ case INIT:
+ return PcepLspStatus.DOWN;
+
+ case ESTABLISHED:
+ return PcepLspStatus.GOING_UP;
+
+ case ACTIVE:
+ return PcepLspStatus.UP;
+
+ case FAILED: // fall through
+ case INACTIVE: // LSP is administratively down.
+ default:
+ return PcepLspStatus.DOWN;
+ }
+ }
+
+ /**
+ * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status.
+ *
+ * @param lspState PCEP LSP status
+ */
+ public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) {
+
+ switch (lspState) {
+
+ case DOWN:
+ return State.FAILED;
+
+ case UP: // fall through
+ case ACTIVE:
+ return State.ACTIVE;
+
+ case GOING_DOWN:
+ return State.FAILED;
+
+ case GOING_UP:
+ return State.ESTABLISHED;
+
+ default:
+ return State.FAILED;
+ }
+ }
+}
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelData.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelData.java
index 57d0a66..569a28a 100644
--- a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelData.java
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelData.java
@@ -20,7 +20,7 @@
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.net.ElementId;
import org.onosproject.net.Path;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import com.google.common.base.MoreObjects;
@@ -43,7 +43,7 @@
private short tunnelId;
private int extTunnelId;
private short lspId;
- private StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv;
+ private StatefulIPv4LspIdentifiersTlv statefulIpv4IndentifierTlv;
/**
* Default constructor.
@@ -203,7 +203,7 @@
* Sets statefulIpv4Identifiers tlv.
* @param value statefulIpv4Identifiers tlv
*/
- public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentidiersTlv value) {
+ public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentifiersTlv value) {
this.statefulIpv4IndentifierTlv = value;
}
@@ -329,7 +329,7 @@
*
* @return statefulIpv4Indentifier tlv
*/
- public StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv() {
+ public StatefulIPv4LspIdentifiersTlv statefulIpv4IndentifierTlv() {
return this.statefulIpv4IndentifierTlv;
}
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
index 50d54dc..0ac46a9 100644
--- a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
@@ -16,6 +16,7 @@
package org.onosproject.provider.pcep.tunnel.impl;
import com.google.common.collect.Maps;
+
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -34,6 +35,7 @@
import org.onosproject.incubator.net.tunnel.OpticalLogicId;
import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
import org.onosproject.incubator.net.tunnel.TunnelDescription;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
import org.onosproject.incubator.net.tunnel.TunnelId;
@@ -45,6 +47,7 @@
import org.onosproject.incubator.net.tunnel.TunnelStatistics;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultAnnotations.Builder;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.DeviceId;
@@ -81,20 +84,21 @@
import org.onosproject.pcepio.protocol.PcepMessage;
import org.onosproject.pcepio.protocol.PcepMsgPath;
import org.onosproject.pcepio.protocol.PcepReportMsg;
-import org.onosproject.pcepio.protocol.PcepRroObject;
import org.onosproject.pcepio.protocol.PcepSrpObject;
import org.onosproject.pcepio.protocol.PcepStateReport;
import org.onosproject.pcepio.protocol.PcepUpdateMsg;
import org.onosproject.pcepio.protocol.PcepUpdateRequest;
import org.onosproject.pcepio.types.IPv4SubObject;
+import org.onosproject.pcepio.types.PathSetupTypeTlv;
import org.onosproject.pcepio.types.PcepValueType;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Modified;
import org.slf4j.Logger;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -106,10 +110,21 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.util.Tools.get;
+import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
import static org.onosproject.net.DefaultAnnotations.EMPTY;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.PortNumber.portNumber;
import static org.onosproject.pcep.api.PcepDpid.uri;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.BANDWIDTH;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL_LSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.RequestType.CREATE;
+import static org.onosproject.provider.pcep.tunnel.impl.RequestType.DELETE;
+import static org.onosproject.provider.pcep.tunnel.impl.RequestType.LSP_STATE_RPT;
+import static org.onosproject.provider.pcep.tunnel.impl.RequestType.UPDATE;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -215,7 +230,7 @@
@Override
public void setupTunnel(Tunnel tunnel, Path path) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -244,7 +259,12 @@
@Override
public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.annotations().value(PLSP_ID) != null) {
+ updateTunnel(tunnel, path);
+ return;
+ }
+
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -276,7 +296,7 @@
@Override
public void releaseTunnel(Tunnel tunnel) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -302,7 +322,7 @@
@Override
public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -333,7 +353,7 @@
@Override
public void updateTunnel(Tunnel tunnel, Path path) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -360,7 +380,7 @@
@Override
public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
- if (tunnel.type() != Tunnel.Type.MPLS) {
+ if (tunnel.type() != MPLS) {
log.error("Tunnel Type MPLS is only supported");
return;
}
@@ -391,13 +411,26 @@
@Override
public TunnelId tunnelAdded(TunnelDescription tunnel) {
- if (tunnel.type() == Tunnel.Type.MPLS) {
+ return handleTunnelAdded(tunnel, null);
+ }
+
+ public TunnelId tunnelAdded(TunnelDescription tunnel, State tunnelState) {
+ return handleTunnelAdded(tunnel, tunnelState);
+ }
+
+ private TunnelId handleTunnelAdded(TunnelDescription tunnel, State tunnelState) {
+
+ if (tunnel.type() == MPLS) {
pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
- return service.tunnelAdded(tunnel);
+
+ if (tunnelState == null) {
+ return service.tunnelAdded(tunnel);
+ } else {
+ return service.tunnelAdded(tunnel, tunnelState);
+ }
}
- long bandwidth = Long
- .parseLong(tunnel.annotations().value("bandwidth"));
+ long bandwidth = Long.parseLong(tunnel.annotations().value(BANDWIDTH));
if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) {
error("Update failed, invalid bandwidth.");
@@ -437,7 +470,7 @@
@Override
public void tunnelRemoved(TunnelDescription tunnel) {
- if (tunnel.type() == Tunnel.Type.MPLS) {
+ if (tunnel.type() == MPLS) {
pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
service.tunnelRemoved(tunnel);
}
@@ -460,9 +493,23 @@
@Override
public void tunnelUpdated(TunnelDescription tunnel) {
- if (tunnel.type() == Tunnel.Type.MPLS) {
+ handleTunnelUpdate(tunnel, null);
+ }
+
+ public void tunnelUpdated(TunnelDescription tunnel, State tunnelState) {
+ handleTunnelUpdate(tunnel, tunnelState);
+ }
+
+ private void handleTunnelUpdate(TunnelDescription tunnel, State tunnelState) {
+ if (tunnel.type() == MPLS) {
pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
- service.tunnelUpdated(tunnel);
+
+ if (tunnelState == null) {
+ service.tunnelUpdated(tunnel);
+ } else {
+ service.tunnelUpdated(tunnel, tunnelState);
+ }
+ return;
}
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
@@ -724,15 +771,31 @@
return null;
}
- //build SRP object
- PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build();
-
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
+
+ // set PathSetupTypeTlv of SRP object
+ tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)).type());
+ llOptionalTlv.add(tlv);
+
+ // build SRP object
+ PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
+ .setOptionalTlv(llOptionalTlv).build();
+
+ llOptionalTlv = new LinkedList<PcepValueType>();
LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
+
// set LSP identifiers TLV
- tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
- (short) 0, (short) 0, 0,
- (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()));
+ short localLspId = 0;
+ if (LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE)) != WITH_SIGNALLING) {
+ String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
+ if (localLspIdString != null) {
+ localLspId = Short.valueOf(localLspIdString);
+ }
+ }
+
+ tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
+ localLspId, (short) 0, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
+ .getIp4Address().toInt()));
llOptionalTlv.add(tlv);
//set SymbolicPathNameTlv of LSP object
tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
@@ -752,8 +815,8 @@
PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
int iBandwidth = DEFAULT_BANDWIDTH_VALUE;
- if (tunnel.annotations().value("bandwidth") != null) {
- iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth"));
+ if (tunnel.annotations().value(BANDWIDTH) != null) {
+ iBandwidth = Integer.parseInt(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
@@ -777,7 +840,7 @@
private void pcepSetupTunnel(Tunnel tunnel, Path path, PcepClient pc) {
try {
int srpId = SrpIdGenerators.create();
- PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.CREATE);
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, CREATE);
pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
@@ -809,12 +872,11 @@
*/
private void pcepReleaseTunnel(Tunnel tunnel, PcepClient pc) {
try {
- PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, RequestType.DELETE);
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, DELETE);
pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
int srpId = SrpIdGenerators.create();
TunnelId tunnelId = tunnel.tunnelId();
int plspId = 0;
- StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv = null;
if (!(pcepTunnelApiMapper.checkFromTunnelDBQueue(tunnelId))) {
log.error("Tunnel doesnot exists. Tunnel id {}" + tunnelId.toString());
@@ -822,24 +884,23 @@
} else {
PcepTunnelData pcepTunnelDbData = pcepTunnelApiMapper.getDataFromTunnelDBQueue(tunnelId);
plspId = pcepTunnelDbData.plspId();
- statefulIpv4IndentifierTlv = pcepTunnelDbData.statefulIpv4IndentifierTlv();
}
- // build srp object
- PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true).build();
PcepValueType tlv;
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
+
+ // set PathSetupTypeTlv of SRP object
+ tlv = new PathSetupTypeTlv(LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE))
+ .type());
+ llOptionalTlv.add(tlv);
+
+ // build SRP object
+ PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(true)
+ .setOptionalTlv(llOptionalTlv).build();
+
+ llOptionalTlv = new LinkedList<PcepValueType>();
LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList = new LinkedList<PcInitiatedLspRequest>();
- if (statefulIpv4IndentifierTlv != null) {
- tlv = statefulIpv4IndentifierTlv;
- } else {
- tlv = new StatefulIPv4LspIdentidiersTlv((
- ((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
- (short) 0, (short) 0, 0,
- (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()));
- }
- llOptionalTlv.add(tlv);
tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
llOptionalTlv.add(tlv);
// build lsp object, set r flag as false to delete the tunnel
@@ -871,7 +932,7 @@
*/
private void pcepUpdateTunnel(Tunnel tunnel, Path path, PcepClient pc) {
try {
- PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, UPDATE);
pcepTunnelApiMapper.addToCoreTunnelRequestQueue(pcepTunnelData);
int srpId = SrpIdGenerators.create();
TunnelId tunnelId = tunnel.tunnelId();
@@ -882,8 +943,16 @@
LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
LinkedList<PcepUpdateRequest> llUpdateRequestList = new LinkedList<PcepUpdateRequest>();
- //build SRP object
- PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false).build();
+ // set PathSetupTypeTlv of SRP object
+ LspType lspSigType = LspType.valueOf(tunnel.annotations().value(LSP_SIG_TYPE));
+ tlv = new PathSetupTypeTlv(lspSigType.type());
+ llOptionalTlv.add(tlv);
+
+ // build SRP object
+ PcepSrpObject srpobj = pc.factory().buildSrpObject().setSrpID(srpId).setRFlag(false)
+ .setOptionalTlv(llOptionalTlv).build();
+
+ llOptionalTlv = new LinkedList<PcepValueType>();
if (!(pcepTunnelApiMapper.checkFromTunnelDBQueue(tunnelId))) {
log.error("Tunnel doesnot exists in DB");
@@ -893,10 +962,26 @@
plspId = pcepTunnelDBData.plspId();
}
- tlv = new StatefulIPv4LspIdentidiersTlv((((IpTunnelEndPoint) tunnel.src()).ip().getIp4Address().toInt()),
- (short) 0, (short) 0, 0,
- (((IpTunnelEndPoint) tunnel.dst()).ip().getIp4Address().toInt()));
- llOptionalTlv.add(tlv);
+ if (lspSigType != WITH_SIGNALLING) {
+ String localLspIdString = tunnel.annotations().value(LOCAL_LSP_ID);
+ String pccTunnelIdString = tunnel.annotations().value(PCC_TUNNEL_ID);
+ short localLspId = 0;
+ short pccTunnelId = 0;
+
+ if (localLspIdString != null) {
+ localLspId = Short.valueOf(localLspIdString);
+ }
+
+ if (pccTunnelIdString != null) {
+ pccTunnelId = Short.valueOf(pccTunnelIdString);
+ }
+
+ tlv = new StatefulIPv4LspIdentifiersTlv((((IpTunnelEndPoint) tunnel.src())
+ .ip().getIp4Address().toInt()),
+ localLspId, pccTunnelId, 0, (((IpTunnelEndPoint) tunnel.dst()).ip()
+ .getIp4Address().toInt()));
+ llOptionalTlv.add(tlv);
+ }
if (tunnel.tunnelName().value() != null) {
tlv = new SymbolicPathNameTlv(tunnel.tunnelName().value().getBytes());
@@ -910,8 +995,8 @@
PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
int iBandwidth = DEFAULT_BANDWIDTH_VALUE;
- if (tunnel.annotations().value("bandwidth") != null) {
- iBandwidth = Integer.parseInt(tunnel.annotations().value("bandwidth"));
+ if (tunnel.annotations().value(BANDWIDTH) != null) {
+ iBandwidth = Integer.parseInt(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
@@ -1005,14 +1090,15 @@
// Check the sync status
if (lspObj.getSFlag()) {
handleSyncReport(stateRpt);
+ continue;
} else if (!pcepClientController.getClient(pccId).isSyncComplete()) {
// sync is done
pcepClientController.getClient(pccId).setIsSyncComplete(true);
+ continue;
}
- continue;
}
- handleReportMessage(srpId, lspObj);
+ handleReportMessage(srpId, lspObj, stateRpt);
}
break;
@@ -1027,13 +1113,18 @@
/**
* Handles report message for setup/update/delete tunnel request.
*
- * @param srpId unique identifier for pcep message
- * @param lspObj lsp object
+ * @param srpId unique identifier for PCEP message
+ * @param lspObj LSP object
+ * @param stateRpt parsed PCEP report msg.
*/
- private void handleReportMessage(int srpId, PcepLspObject lspObj) {
+ private void handleReportMessage(int srpId, PcepLspObject lspObj, PcepStateReport stateRpt) {
ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
PcepTunnelData pcepTunnelData = pcepTunnelApiMapper.getDataFromTunnelRequestQueue(srpId);
- SparseAnnotations annotations = (SparseAnnotations) pcepTunnelData.tunnel().annotations();
+
+ if (pcepTunnelData == null) {
+ handleRptWithoutSrpId(stateRpt);
+ return;
+ }
// store the values required from report message
pcepTunnelData.setPlspId(lspObj.getPlspId());
@@ -1041,12 +1132,12 @@
pcepTunnelData.setLspOFlag(lspObj.getOFlag());
pcepTunnelData.setLspDFlag(lspObj.getDFlag());
- StatefulIPv4LspIdentidiersTlv ipv4LspTlv = null;
+ StatefulIPv4LspIdentifiersTlv ipv4LspTlv = null;
ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
while (listTlvIterator.hasNext()) {
PcepValueType tlv = listTlvIterator.next();
- if (tlv.getType() == StatefulIPv4LspIdentidiersTlv.TYPE) {
- ipv4LspTlv = (StatefulIPv4LspIdentidiersTlv) tlv;
+ if (tlv.getType() == StatefulIPv4LspIdentifiersTlv.TYPE) {
+ ipv4LspTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
break;
}
}
@@ -1056,38 +1147,113 @@
Path path = pcepTunnelData.path();
Tunnel tunnel = pcepTunnelData.tunnel();
+ Builder annotationBuilder = DefaultAnnotations.builder();
+ annotationBuilder.putAll(pcepTunnelData.tunnel().annotations());
+
+ // PCRpt in response to PCInitate msg will carry PLSP id allocated by PCC.
+ if (tunnel.annotations().value(PLSP_ID) == null) {
+ annotationBuilder.set(PLSP_ID, String.valueOf(lspObj.getPlspId()));
+ }
+
+ // Signalled LSPs will carry local LSP id allocated by signalling protocol(PCC).
+ if (tunnel.annotations().value(LOCAL_LSP_ID) == null) {
+ annotationBuilder.set(LOCAL_LSP_ID, String.valueOf(ipv4LspTlv.getLspId()));
+ }
+
+ SparseAnnotations annotations = annotationBuilder.build();
DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(),
tunnel.dst(), tunnel.type(), tunnel.groupId(),
providerId, tunnel.tunnelName(), path,
annotations);
- if (RequestType.CREATE == pcepTunnelData.requestType()) {
- log.debug("Report received for create request");
-
+ if (CREATE == pcepTunnelData.requestType()) {
pcepTunnelApiMapper.handleCreateTunnelRequestQueue(srpId, pcepTunnelData);
- if (0 == lspObj.getOFlag()) {
- log.warn("The tunnel is in down state");
- }
- tunnelAdded(td);
- }
- if (RequestType.DELETE == pcepTunnelData.requestType()) {
- log.debug("Report received for delete request");
+ } else if (DELETE == pcepTunnelData.requestType()) {
pcepTunnelApiMapper.handleRemoveFromTunnelRequestQueue(srpId, pcepTunnelData);
- tunnelRemoved(td);
- }
-
- if (RequestType.UPDATE == pcepTunnelData.requestType()) {
- log.debug("Report received for update request");
+ } else if (UPDATE == pcepTunnelData.requestType()) {
pcepTunnelData.setRptFlag(true);
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
pcepTunnelApiMapper.handleUpdateTunnelRequestQueue(srpId, pcepTunnelData);
+ }
- if (0 == lspObj.getOFlag()) {
- log.warn("The tunnel is in down state");
+ if (lspObj.getRFlag()) {
+ tunnelRemoved(td);
+ } else {
+ State tunnelState = PcepLspStatus
+ .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
+ tunnelUpdated(td, tunnelState);
+ }
+ }
+
+ /**
+ * Handles asynchronous report messages from PCC when LSPDB sync is not in progress.
+ *
+ * @param stateRpt parsed PCEP report msg.
+ */
+ private void handleRptWithoutSrpId(PcepStateReport stateRpt) {
+ ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
+ StatefulIPv4LspIdentifiersTlv ipv4LspTlv = null;
+
+ PcepLspObject lspObj = stateRpt.getLspObject();
+ ListIterator<PcepValueType> listTlvIterator = lspObj.getOptionalTlv().listIterator();
+
+ while (listTlvIterator.hasNext()) {
+ PcepValueType tlv = listTlvIterator.next();
+ if (tlv.getType() == StatefulIPv4LspIdentifiersTlv.TYPE) {
+ ipv4LspTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
+ break;
}
- if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
- tunnelUpdated(td);
+ }
+
+ checkNotNull(ipv4LspTlv);
+
+ IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(ipv4LspTlv
+ .getIpv4IngressAddress()));
+ IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(ipv4LspTlv
+ .getIpv4EgressAddress()));
+
+ Collection<Tunnel> tunnelQueryResult = tunnelService.queryTunnel(tunnelEndPointSrc, tunnelEndPointDst);
+
+ Tunnel tunnel = null;
+ // Asynchronous status change message from PCC for LSP reported earlier.
+ for (Tunnel tunnelObj : tunnelQueryResult) {
+ if ((tunnelObj.annotations().value(PLSP_ID) == null)
+ || (tunnelObj.annotations().value(LOCAL_LSP_ID) == null)) {
+ /*
+ * Can skip this tunnel as this is one for which PCE has
+ * sent PCInit/PCUpd msg and waiting for a PCRpt.
+ */
+ continue;
}
+
+ if ((Integer.valueOf(tunnelObj.annotations().value(PLSP_ID)) == lspObj.getPlspId())
+ && (Integer.valueOf(tunnelObj.annotations().value(LOCAL_LSP_ID))
+ == ipv4LspTlv.getLspId())) {
+ tunnel = tunnelObj;
+ break;
+ }
+ }
+
+ // Status report for a new LSP when LSPDB sync was already completed sometime.
+ // No need to add the tunnel if msg is for remove but store doesn't have an entry.
+ if (tunnel == null) {
+ if (!lspObj.getRFlag()) {
+ handleSyncReport(stateRpt);
+ }
+ return;
+ }
+
+ DefaultTunnelDescription td = new DefaultTunnelDescription(tunnel.tunnelId(), tunnel.src(),
+ tunnel.dst(), tunnel.type(), tunnel.groupId(),
+ providerId, tunnel.tunnelName(), tunnel.path(),
+ (SparseAnnotations) tunnel.annotations());
+
+ if (lspObj.getRFlag()) {
+ tunnelRemoved(td); // This will happen only for PCC initiated tunnels.
+ } else {
+ State tunnelState = PcepLspStatus
+ .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
+ tunnelUpdated(td, tunnelState);
}
}
@@ -1100,9 +1266,9 @@
PcepLspObject lspObj = stateRpt.getLspObject();
PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath();
checkNotNull(msgPath);
- PcepRroObject rroObj = msgPath.getRroObject();
- if (rroObj == null) {
- log.debug("RRO object is null in sate report");
+ PcepEroObject eroObj = msgPath.getEroObject();
+ if (eroObj == null) {
+ log.debug("ERO object is null in sate report");
return;
}
int bandwidth = 0;
@@ -1118,20 +1284,44 @@
bandwidth = msgPath.getBandwidthObject().getBandwidth();
}
- buildAndStorePcepTunnelData(lspObj, rroObj, bandwidth);
+ // To carry PST TLV, SRP object can be present with value 0 even
+ // when PCRpt is
+ // not in response to any action from PCE.
+ PcepSrpObject srpObj = stateRpt.getSrpObject();
+ LspType lspType = WITH_SIGNALLING;
+
+ if (null != srpObj) {
+ LinkedList<PcepValueType> llOptionalTlv = srpObj.getOptionalTlv();
+ ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
+
+ while (listIterator.hasNext()) {
+ PcepValueType tlv = listIterator.next();
+
+ switch (tlv.getType()) {
+ case PathSetupTypeTlv.TYPE:
+ lspType = LspType.values()[Integer.valueOf(((PathSetupTypeTlv) tlv).getPst())];
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ buildAndStorePcepTunnelData(lspObj, eroObj, bandwidth, lspType);
}
/**
- * To build Path in network from RRO object.
+ * To build Path in network from ERO object.
*
- * @param rroObj rro object
+ * @param eroObj ERO object
* @param providerId provider id
* @return path object
*/
- private Path buildPathFromRroObj(PcepRroObject rroObj, ProviderId providerId) {
- checkNotNull(rroObj);
+ private Path buildPathFromEroObj(PcepEroObject eroObj, ProviderId providerId) {
+ checkNotNull(eroObj);
List<Link> links = new ArrayList<Link>();
- LinkedList<PcepValueType> llSubObj = rroObj.getSubObjects();
+ LinkedList<PcepValueType> llSubObj = eroObj.getSubObjects();
if (0 == llSubObj.size()) {
log.error("RRO in report message does not have hop information");
}
@@ -1172,27 +1362,29 @@
}
/**
- * To build pcepTunnelData and informs core about the pcc reported tunnel.
+ * To build pcepTunnelData and informs core about the PCC reported
+ * tunnel.
*
- * @param lspObj pcep lsp object
- * @param rroObj pcep rro object
+ * @param lspObj PCEP LSP object
+ * @param eroObj PCEP ERO object
* @param bandwidth bandwidth of tunnel
+ * @param lspType path setup type/signaling type of the LSP.
*/
- private void buildAndStorePcepTunnelData(PcepLspObject lspObj, PcepRroObject rroObj,
- int bandwidth) {
+ private void buildAndStorePcepTunnelData(PcepLspObject lspObj, PcepEroObject eroObj, int bandwidth,
+ LspType lspType) {
ProviderId providerId = new ProviderId("pcep", PROVIDER_ID);
// StatefulIPv4LspIdentidiersTlv in LSP object will have the source and destination address.
- StatefulIPv4LspIdentidiersTlv lspIdenTlv = null;
+ StatefulIPv4LspIdentifiersTlv lspIdenTlv = null;
SymbolicPathNameTlv pathNameTlv = null;
LinkedList<PcepValueType> llOptionalTlv = lspObj.getOptionalTlv();
ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
while (listIterator.hasNext()) {
PcepValueType tlv = listIterator.next();
switch (tlv.getType()) {
- case StatefulIPv4LspIdentidiersTlv.TYPE:
- lspIdenTlv = (StatefulIPv4LspIdentidiersTlv) tlv;
+ case StatefulIPv4LspIdentifiersTlv.TYPE:
+ lspIdenTlv = (StatefulIPv4LspIdentifiersTlv) tlv;
break;
case SymbolicPathNameTlv.TYPE:
pathNameTlv = (SymbolicPathNameTlv) tlv;
@@ -1207,24 +1399,28 @@
IpTunnelEndPoint tunnelEndPointDst;
tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(lspIdenTlv.getIpv4EgressAddress()));
- Path path = buildPathFromRroObj(rroObj, providerId);
+ Path path = buildPathFromEroObj(eroObj, providerId);
SparseAnnotations annotations = DefaultAnnotations.builder()
- .set("bandwidth", (new Integer(bandwidth)).toString())
- .build();
+ .set(BANDWIDTH, (new Integer(bandwidth)).toString())
+ .set(LSP_SIG_TYPE, lspType.name())
+ .set(PCC_TUNNEL_ID, String.valueOf(lspIdenTlv.getTunnelId()))
+ .set(PLSP_ID, String.valueOf(lspObj.getPlspId()))
+ .set(LOCAL_LSP_ID, String.valueOf(lspIdenTlv.getLspId())).build();
DefaultTunnelDescription td = new DefaultTunnelDescription(null, tunnelEndPointSrc,
- tunnelEndPointDst, Tunnel.Type.MPLS,
+ tunnelEndPointDst, MPLS,
new DefaultGroupId(0), providerId,
TunnelName.tunnelName(pathNameTlv.toString()),
path, annotations);
- TunnelId tId = tunnelAdded(td);
+ State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
+ TunnelId tId = tunnelAdded(td, tunnelState);
- Tunnel tunnel = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, Tunnel.Type.MPLS,
+ Tunnel tunnel = new DefaultTunnel(providerId, tunnelEndPointSrc, tunnelEndPointDst, MPLS,
new DefaultGroupId(0), tId,
TunnelName.tunnelName(pathNameTlv.toString()), path, annotations);
- PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.LSP_STATE_RPT);
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, LSP_STATE_RPT);
pcepTunnelData.setStatefulIpv4IndentifierTlv(lspIdenTlv);
pcepTunnelApiMapper.addPccTunnelDB(pcepTunnelData);
pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
@@ -1240,8 +1436,6 @@
// TODO
}
-
-
@Override
public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) {
TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id()));
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
index efb4d95..2f519ec 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientAdapter.java
@@ -42,6 +42,7 @@
private ClientCapability capability;
private PcepVersion pcepVersion;
+ private boolean syncCompleted;
/**
* Initialize instance with specified parameters.
@@ -109,11 +110,12 @@
@Override
public final boolean isSyncComplete() {
- return false;
+ return syncCompleted;
}
@Override
public final void setIsSyncComplete(boolean value) {
+ syncCompleted = value;
}
@Override
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
index 91a68fc..822d8b6 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepClientControllerAdapter.java
@@ -73,6 +73,9 @@
@Override
public PcepClient getClient(PccId pccId) {
+ if (null != connectedClients.get(pccId)) {
+ return connectedClients.get(pccId);
+ }
PcepClientAdapter pc = new PcepClientAdapter();
if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103))
|| pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
@@ -81,6 +84,7 @@
pc.setCapability(new ClientCapability(true, true, true));
}
pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
+ connectedClients.put(pccId, pc);
return pc;
}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
index 027f396..ec9c1aa 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepReleaseTunnelProviderTest.java
@@ -20,6 +20,10 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,7 +40,9 @@
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.IpElementId;
@@ -44,7 +50,7 @@
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
/**
* Test for PCEP release tunnel.
@@ -77,7 +83,7 @@
public void testCasePcepReleaseTunnel() {
Tunnel tunnel;
Path path;
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
@@ -103,14 +109,18 @@
path = new DefaultPath(pid, links, 20, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
// for releasing tunnel tunnel should exist in db
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
pcepTunnelData.setPlspId(1);
- StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
@@ -127,7 +137,7 @@
public void testCasePcepReleaseTunnel2() {
Tunnel tunnel;
Path path;
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
@@ -153,14 +163,18 @@
path = new DefaultPath(pid, links, 20, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
// for releasing tunnel tunnel should exist in db
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
pcepTunnelData.setPlspId(1);
- StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
@@ -170,6 +184,114 @@
assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
}
+ /**
+ * Tests releasing SR based tunnel.
+ */
+ @Test
+ public void testCasePcepReleaseSrTunnel() {
+ Tunnel tunnel;
+ Path path;
+ List<Link> links = new ArrayList<>();
+
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+
+ IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ // for releasing tunnel tunnel should exist in db
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
+ pcepTunnelData.setPlspId(1);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.releaseTunnel(tunnel);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
+ /**
+ * Tests releasing tunnel without SR and without signalling.
+ */
+ @Test
+ public void testCasePcepReleaseTunnelWithoutSigSr() {
+ Tunnel tunnel;
+ Path path;
+ List<Link> links = new ArrayList<>();
+
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+
+ IpAddress srcIp = IpAddress.valueOf(0xB6024E20);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xB6024E21);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ // for releasing tunnel tunnel should exist in db
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.DELETE);
+ pcepTunnelData.setPlspId(1);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.releaseTunnel(tunnel);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
@After
public void tearDown() throws IOException {
tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
index 5b41d41..d2c4d5e 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepSetupTunnelProviderTest.java
@@ -20,6 +20,10 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.Matchers.nullValue;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,7 +40,9 @@
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.IpElementId;
@@ -75,7 +81,7 @@
Tunnel tunnel;
Path path;
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
IpAddress srcIp = IpAddress.valueOf(0xC010101);
IpElementId srcElementId = IpElementId.ipElement(srcIp);
@@ -98,9 +104,13 @@
path = new DefaultPath(pid, links, 10, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
tunnelProvider.setupTunnel(tunnel, path);
assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
@@ -114,7 +124,7 @@
Tunnel tunnel;
Path path;
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
IpAddress srcIp = IpAddress.valueOf(0xC010103);
IpElementId srcElementId = IpElementId.ipElement(srcIp);
@@ -137,14 +147,104 @@
path = new DefaultPath(pid, links, 10, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
tunnelProvider.setupTunnel(tunnel, path);
assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
}
+ /**
+ * Sends PCInitiate msg to setup a SR based tunnel.
+ */
+ @Test
+ public void testCasePcepSetupSrTunnel() {
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<>();
+ IpAddress srcIp = IpAddress.valueOf(0xC010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xC010102);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 10, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ tunnelProvider.setupTunnel(tunnel, path);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
+ /**
+ * Sends PCInitiate msg to setup a tunnel without signalling and without SR.
+ */
+ @Test
+ public void testCasePcepSetupTunnelWithoutSigSr() {
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<>();
+ IpAddress srcIp = IpAddress.valueOf(0xC010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xC010102);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 10, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ tunnelProvider.setupTunnel(tunnel, path);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
@After
public void tearDown() throws IOException {
tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java
new file mode 100644
index 0000000..76f2bb0
--- /dev/null
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelAddedTest.java
@@ -0,0 +1,329 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.pcep.tunnel.impl;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
+import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.BANDWIDTH;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LOCAL_LSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PCC_TUNNEL_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.PLSP_ID;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cfg.ComponentConfigAdapter;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.incubator.net.tunnel.DefaultTunnel;
+import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelDescription;
+import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
+import org.onosproject.incubator.net.tunnel.TunnelId;
+import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.incubator.net.tunnel.TunnelProvider;
+import org.onosproject.incubator.net.tunnel.TunnelProviderService;
+import org.onosproject.incubator.net.tunnel.Tunnel.State;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.ElementId;
+import org.onosproject.net.Path;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
+import org.onosproject.pcepio.exceptions.PcepParseException;
+import org.onosproject.pcepio.protocol.PcepFactories;
+import org.onosproject.pcepio.protocol.PcepMessage;
+import org.onosproject.pcepio.protocol.PcepMessageReader;
+import org.onosproject.pcep.controller.ClientCapability;
+import org.onosproject.pcep.controller.PccId;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests handling of PCEP report message.
+ */
+public class PcepTunnelAddedTest {
+
+ static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
+ PcepTunnelProvider tunnelProvider = new PcepTunnelProvider();
+ private final MockTunnelProviderRegistryAdapter registry = new MockTunnelProviderRegistryAdapter();
+ private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
+ private final PcepControllerAdapter ctl = new PcepControllerAdapter();
+ private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
+ private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
+
+ private class MockTunnelProviderRegistryAdapter extends TunnelProviderRegistryAdapter {
+ public long tunnelIdCounter;
+
+ @Override
+ public TunnelProviderService register(TunnelProvider provider) {
+ this.provider = provider;
+ return new TestProviderService();
+ }
+
+ private class TestProviderService implements TunnelProviderService {
+
+ @Override
+ public TunnelProvider provider() {
+ return null;
+ }
+
+ @Override
+ public TunnelId tunnelAdded(TunnelDescription tunnel) {
+ return TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+ }
+
+ @Override
+ public TunnelId tunnelAdded(TunnelDescription tunnel, State state) {
+ return TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+ }
+
+ @Override
+ public void tunnelRemoved(TunnelDescription tunnel) {
+ }
+
+ @Override
+ public void tunnelUpdated(TunnelDescription tunnel) {
+ }
+
+ @Override
+ public void tunnelUpdated(TunnelDescription tunnel, State state) {
+ }
+
+ @Override
+ public Tunnel tunnelQueryById(TunnelId tunnelId) {
+ return null;
+ }
+ }
+ }
+
+ private class MockTunnelServiceAdapter extends TunnelServiceAdapter {
+ private HashMap<TunnelId, Tunnel> tunnelIdAsKeyStore = new HashMap<>();
+ private int tunnelIdCounter = 0;
+
+ @Override
+ public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
+ TunnelId tunnelId = TunnelId.valueOf(String.valueOf(++tunnelIdCounter));
+ tunnelIdAsKeyStore.put(tunnelId, tunnel);
+ return tunnelId;
+ }
+
+ @Override
+ public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
+ Collection<Tunnel> result = new HashSet<>();
+ Tunnel tunnel = null;
+ for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
+ tunnel = tunnelIdAsKeyStore.get(tunnelId);
+
+ if ((null != tunnel) && (src.equals(tunnel.src())) && (dst.equals(tunnel.dst()))) {
+ result.add(tunnel);
+ }
+ }
+
+ return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
+ }
+
+ @Override
+ public Collection<Tunnel> queryAllTunnels() {
+ Collection<Tunnel> result = new HashSet<>();
+
+ for (TunnelId tunnelId : tunnelIdAsKeyStore.keySet()) {
+ result.add(tunnelIdAsKeyStore.get(tunnelId));
+ }
+
+ return result.isEmpty() ? Collections.emptySet() : ImmutableSet.copyOf(result);
+
+ }
+ }
+
+ @Before
+ public void preSetup() {
+ tunnelProvider.tunnelProviderRegistry = registry;
+ tunnelProvider.pcepClientController = controller;
+ tunnelProvider.controller = ctl;
+ tunnelProvider.pcepTunnelApiMapper = pcepTunnelAPIMapper;
+ tunnelProvider.cfgService = new ComponentConfigAdapter();
+ tunnelProvider.tunnelService = tunnelService;
+ tunnelProvider.service = registry.register(tunnelProvider);
+ tunnelProvider.activate();
+ }
+
+ /**
+ * Tests PCRpt msg with sync flag set.
+ */
+ @Test
+ public void tunnelProviderAddedTest1() throws PcepParseException, PcepOutOfBoundMessageException {
+ byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
+ 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object
+ 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+ 0x00, 0x00, 0x00, 0x02,
+ 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object
+ 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
+ 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+ 0x01, 0x01, 0x01, 0x01,
+ 0x00, 0x01, 0x00, 0x01,
+ 0x01, 0x01, 0x01, 0x01,
+ 0x05, 0x05, 0x05, 0x05,
+
+ 0x07, 0x10, 0x00, 0x14, //ERO object
+ 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
+ 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
+
+ 0x08, 0x10, 0x00, 0x34, //RRO object
+ 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
+ 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
+ 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
+ 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
+ 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
+ 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
+ };
+
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(reportMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = reader.readFrom(buffer);
+ controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
+
+ assertThat(registry.tunnelIdCounter, is((long) 1));
+ }
+
+ /**
+ * Tests updating an existing tunnel on receiving asynchronous PCRpt msg,
+ * i.e. without any SRP id.
+ */
+ @Test
+ public void tunnelProviderAddedTest2() throws PcepParseException, PcepOutOfBoundMessageException {
+ byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x50,
+ 0x21, 0x10, 0x00, 0x14, //SRP object
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+ 0x00, 0x00, 0x00, 0x02,
+ 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, //LSP object
+ 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path TLV
+ 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+ 0x4e, 0x1f, 0x04, 0x00,
+ 0x00, 0x01, 0x00, 0x01,
+ 0x4e, 0x1f, 0x04, 0x00,
+ 0x4e, 0x20, 0x04, 0x00,
+ 0x07, 0x10, 0x00, 0x14, //ERO object
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // ERO IPv4 sub objects
+ 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
+ };
+
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(reportMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = reader.readFrom(buffer);
+
+ // create an existing tunnel.
+ IpTunnelEndPoint tunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e1f0400));
+ IpTunnelEndPoint tunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(0x4e200400));
+
+ SparseAnnotations annotations = DefaultAnnotations.builder()
+ .set(BANDWIDTH, (new Integer(1)).toString())
+ .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+ .set(PCC_TUNNEL_ID, String.valueOf(1))
+ .set(PLSP_ID, String.valueOf(1))
+ .set(LOCAL_LSP_ID, String.valueOf(1)).build();
+
+ Tunnel tunnel = new DefaultTunnel(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, INIT, null, null,
+ TunnelName.tunnelName("T123"), null, annotations);
+ tunnelService.setupTunnel(null, null, tunnel, null);
+
+ PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
+ controller.getClient(pccId).setCapability(new ClientCapability(true, true, true));
+ controller.getClient(pccId).setIsSyncComplete(true);
+
+ // Process update message.
+ controller.processClientMessage(pccId, message);
+ assertThat(tunnelService.queryAllTunnels().size(), is(1));
+ }
+
+ /**
+ * Tests adding a new tunnel on receiving asynchronous PCRpt msg,
+ * i.e. without any SRP id.
+ */
+ @Test
+ public void tunnelProviderAddedTest3() throws PcepParseException, PcepOutOfBoundMessageException {
+ byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x84,
+ 0x21, 0x10, 0x00, 0x14, //SRP object
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
+ 0x00, 0x00, 0x00, 0x02,
+ 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x19, // LSP object
+ 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, // symbolic path TLV
+ 0x00, 0x12, 0x00, 0x10, // IPv4-LSP-IDENTIFIER-TLV
+ 0x01, 0x01, 0x01, 0x01,
+ 0x00, 0x01, 0x00, 0x01,
+ 0x01, 0x01, 0x01, 0x01,
+ 0x05, 0x05, 0x05, 0x05,
+
+ 0x07, 0x10, 0x00, 0x14, //ERO object
+ 0x01, 0x08, (byte) 0x01, 0x01, 0x01, 0x01, 0x04, 0x00, // ERO IPv4 sub objects
+ 0x01, 0x08, (byte) 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
+
+ 0x08, 0x10, 0x00, 0x34, //RRO object
+ 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, // RRO IPv4 sub objects
+ 0x01, 0x08, 0x11, 0x01, 0x01, 0x02, 0x04, 0x00,
+ 0x01, 0x08, 0x06, 0x06, 0x06, 0x06, 0x04, 0x00,
+ 0x01, 0x08, 0x12, 0x01, 0x01, 0x02, 0x04, 0x00,
+ 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00,
+ 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00
+ };
+
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ buffer.writeBytes(reportMsg);
+
+ PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
+ PcepMessage message = reader.readFrom(buffer);
+
+ PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
+ controller.getClient(pccId).setIsSyncComplete(true);
+ controller.getClient(pccId).setCapability(new ClientCapability(true, true, true));
+ controller.processClientMessage(pccId, message);
+
+ assertThat(registry.tunnelIdCounter, is((long) 1));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ tunnelProvider.deactivate();
+ tunnelProvider.controller = null;
+ tunnelProvider.pcepClientController = null;
+ tunnelProvider.tunnelProviderRegistry = null;
+
+ tunnelProvider.pcepTunnelApiMapper = null;
+ tunnelProvider.cfgService = null;
+ tunnelProvider.tunnelService = null;
+ tunnelProvider.service = null;
+ }
+}
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
index d357d46..2922537 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProviderTest.java
@@ -15,7 +15,12 @@
*/
package org.onosproject.provider.pcep.tunnel.impl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.IsNot.not;
import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
import java.io.IOException;
import java.util.ArrayList;
@@ -30,7 +35,9 @@
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.IpElementId;
@@ -62,7 +69,7 @@
Tunnel tunnel;
Path path;
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
IpAddress srcIp = IpAddress.valueOf(0xC010101);
IpElementId srcElementId = IpElementId.ipElement(srcIp);
@@ -85,11 +92,17 @@
path = new DefaultPath(pid, links, 10, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
tunnelProvider.setupTunnel(tunnel, path);
+
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
}
@After
@@ -99,4 +112,4 @@
tunnelProvider.pcepClientController = null;
tunnelProvider.tunnelProviderRegistry = null;
}
-}
+}
\ No newline at end of file
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
index 23a2213..2c9961f 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/PcepUpdateTunnelProviderTest.java
@@ -20,6 +20,7 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.onosproject.net.DefaultAnnotations.EMPTY;
+import static org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys.LSP_SIG_TYPE;
import java.io.IOException;
import java.util.ArrayList;
@@ -36,7 +37,9 @@
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.tunnel.TunnelName;
+import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
import org.onosproject.net.IpElementId;
@@ -44,8 +47,11 @@
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
-import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
+import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITH_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.SR_WITHOUT_SIGNALLING;
+import static org.onosproject.provider.pcep.tunnel.impl.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
/**
* Test for PCEP update tunnel.
*/
@@ -78,7 +84,7 @@
Tunnel tunnel;
Path path;
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
IpAddress srcIp = IpAddress.valueOf(0xD010101);
IpElementId srcElementId = IpElementId.ipElement(srcIp);
@@ -101,14 +107,18 @@
path = new DefaultPath(pid, links, 20, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
// for updating tunnel tunnel should exist in db
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
pcepTunnelData.setPlspId(1);
- StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
@@ -126,7 +136,7 @@
Tunnel tunnel;
Path path;
ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
- List<Link> links = new ArrayList<Link>();
+ List<Link> links = new ArrayList<>();
IpAddress srcIp = IpAddress.valueOf(0xC010103);
IpElementId srcElementId = IpElementId.ipElement(srcIp);
@@ -149,14 +159,18 @@
path = new DefaultPath(pid, links, 20, EMPTY);
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITH_SIGNALLING.name())
+ .build();
+
tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
- path, EMPTY);
+ path, annotations);
// for updating tunnel tunnel should exist in db
PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
pcepTunnelData.setPlspId(1);
- StatefulIPv4LspIdentidiersTlv tlv = new StatefulIPv4LspIdentidiersTlv(0, (short) 1, (short) 2, 3, 4);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
@@ -166,6 +180,110 @@
assertThat(tunnelProvider.pcepTunnelApiMapper.checkFromTunnelRequestQueue(1), is(false));
}
+ /**
+ * Sends update message to PCC for SR based tunnel.
+ */
+ @Test
+ public void testCasePcepUpdateSrTunnel() {
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<>();
+ IpAddress srcIp = IpAddress.valueOf(0xD010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xD010102);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, SR_WITHOUT_SIGNALLING.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ // for updating tunnel tunnel should exist in db
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+ pcepTunnelData.setPlspId(1);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.updateTunnel(tunnel, path);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
+ /**
+ * Sends update message to PCC for tunnel without signalling and without SR.
+ */
+ @Test
+ public void testCasePcepUpdateTunnelWithoutSigSr() {
+ Tunnel tunnel;
+ Path path;
+ ProviderId pid = new ProviderId("pcep", PROVIDER_ID);
+ List<Link> links = new ArrayList<>();
+ IpAddress srcIp = IpAddress.valueOf(0xD010101);
+ IpElementId srcElementId = IpElementId.ipElement(srcIp);
+
+ IpAddress dstIp = IpAddress.valueOf(0xD010102);
+ IpElementId dstElementId = IpElementId.ipElement(dstIp);
+
+ IpTunnelEndPoint ipTunnelEndPointSrc;
+ ipTunnelEndPointSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp);
+
+ IpTunnelEndPoint ipTunnelEndPointDst;
+ ipTunnelEndPointDst = IpTunnelEndPoint.ipTunnelPoint(dstIp);
+
+ ConnectPoint src = new ConnectPoint(srcElementId, PortNumber.portNumber(10023));
+
+ ConnectPoint dst = new ConnectPoint(dstElementId, PortNumber.portNumber(10023));
+
+ Link link = DefaultLink.builder().providerId(pid).src(src).dst(dst)
+ .type(Link.Type.DIRECT).build();
+ links.add(link);
+
+ path = new DefaultPath(pid, links, 20, EMPTY);
+
+ Annotations annotations = DefaultAnnotations.builder()
+ .set(LSP_SIG_TYPE, WITHOUT_SIGNALLING_AND_WITHOUT_SR.name())
+ .build();
+
+ tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS,
+ new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"),
+ path, annotations);
+
+ // for updating tunnel tunnel should exist in db
+ PcepTunnelData pcepTunnelData = new PcepTunnelData(tunnel, path, RequestType.UPDATE);
+ pcepTunnelData.setPlspId(1);
+ StatefulIPv4LspIdentifiersTlv tlv = new StatefulIPv4LspIdentifiersTlv(0, (short) 1, (short) 2, 3, 4);
+ pcepTunnelData.setStatefulIpv4IndentifierTlv(tlv);
+ tunnelProvider.pcepTunnelApiMapper.addToTunnelIdMap(pcepTunnelData);
+
+ tunnelProvider.pcepTunnelApiMapper.handleCreateTunnelRequestQueue(1, pcepTunnelData);
+
+ tunnelProvider.updateTunnel(tunnel, path);
+ assertThat(tunnelProvider.pcepTunnelApiMapper, not(nullValue()));
+ }
+
@After
public void tearDown() throws IOException {
tunnelProvider.deactivate();
diff --git a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
index 10be5f5..8e31508 100644
--- a/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
+++ b/providers/pcep/tunnel/src/test/java/org/onosproject/provider/pcep/tunnel/impl/TunnelServiceAdapter.java
@@ -94,17 +94,17 @@
@Override
public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
- return null;
+ return Collections.emptySet();
}
@Override
public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
- return null;
+ return Collections.emptySet();
}
@Override
public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
- return null;
+ return Collections.emptySet();
}
@Override