Avantika-Huawei
Committed by Gerrit Code Review

[ONOS-4163] Provider side changes to support stateful PCE and PCECC

Change-Id: I0a57ed1d1e505a2e94921fd5f5d92426a105ad12
Showing 20 changed files with 1404 additions and 158 deletions
......@@ -52,6 +52,8 @@ import org.onosproject.pcepio.protocol.PcepOpenMsg;
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 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
@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 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
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 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
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
......
......@@ -25,7 +25,7 @@ import org.onosproject.pcepio.protocol.PcepLspObject;
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 @@ public class PcepLspObjectVer1 implements PcepLspObject {
switch (hType) {
case StatefulIPv4LspIdentidiersTlv.TYPE:
tlv = StatefulIPv4LspIdentidiersTlv.read(cb);
case StatefulIPv4LspIdentifiersTlv.TYPE:
tlv = StatefulIPv4LspIdentifiersTlv.read(cb);
break;
case StatefulLspErrorCodeTlv.TYPE:
iValue = cb.readInt();
......
......@@ -45,7 +45,7 @@ public class PathSetupTypeTlv implements PcepValueType {
*/
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;
......
......@@ -28,7 +28,7 @@ import com.google.common.base.MoreObjects;
/**
* Provides StatefulIPv4LspIdentidiersTlv.
*/
public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
public class StatefulIPv4LspIdentifiersTlv implements PcepValueType {
/* IPV4-LSP-IDENTIFIERS TLV format
*
......@@ -50,7 +50,7 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
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 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
* @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 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
* @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 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
}
/**
* Returns LSP id.
*
* @return lspId
*/
public short getLspId() {
return this.lspId;
}
/**
* Returns extendedTunnelId.
*
* @return extendedTunnelId
......@@ -157,8 +166,8 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
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 @@ public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
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);
}
......
......@@ -555,4 +555,40 @@ public class PcepOpenMsgTest {
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));
}
}
......
......@@ -184,14 +184,14 @@ public class PcepReportMsgExtTest {
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 @@ public class PcepReportMsgExtTest {
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));
}
}
......
......@@ -18,7 +18,10 @@ package org.onosproject.pcepio.types;
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 @@ public class StatefulIPv4LspIdentidiersTlvTest {
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 @@ public class StatefulIPv4LspIdentidiersTlvTest {
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 @@ public class StatefulIPv4LspIdentidiersTlvTest {
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();
......
/*
* 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;
}
}
/*
* 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";
}
/*
* 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;
}
}
}
......@@ -20,7 +20,7 @@ import java.util.Objects;
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 @@ public class PcepTunnelData {
private short tunnelId;
private int extTunnelId;
private short lspId;
private StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv;
private StatefulIPv4LspIdentifiersTlv statefulIpv4IndentifierTlv;
/**
* Default constructor.
......@@ -203,7 +203,7 @@ public class PcepTunnelData {
* Sets statefulIpv4Identifiers tlv.
* @param value statefulIpv4Identifiers tlv
*/
public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentidiersTlv value) {
public void setStatefulIpv4IndentifierTlv(StatefulIPv4LspIdentifiersTlv value) {
this.statefulIpv4IndentifierTlv = value;
}
......@@ -329,7 +329,7 @@ public class PcepTunnelData {
*
* @return statefulIpv4Indentifier tlv
*/
public StatefulIPv4LspIdentidiersTlv statefulIpv4IndentifierTlv() {
public StatefulIPv4LspIdentifiersTlv statefulIpv4IndentifierTlv() {
return this.statefulIpv4IndentifierTlv;
}
......
......@@ -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.IpTunnelEndPoint;
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.TunnelService;
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.PcepLspObject;
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 java.util.Optional;
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
*/
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
} 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>();
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()));
}
// 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>();
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
*/
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
// 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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
/**
* 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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 (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;
if (0 == lspObj.getOFlag()) {
log.warn("The tunnel is in down state");
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;
}
}
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;
}
if (!(pcepTunnelApiMapper.checkFromTunnelRequestQueue(srpId))) {
tunnelUpdated(td);
}
// 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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
}
/**
* 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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
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 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
// TODO
}
@Override
public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) {
TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id()));
......
......@@ -42,6 +42,7 @@ public class PcepClientAdapter implements PcepClient {
private ClientCapability capability;
private PcepVersion pcepVersion;
private boolean syncCompleted;
/**
* Initialize instance with specified parameters.
......@@ -109,11 +110,12 @@ public class PcepClientAdapter implements PcepClient {
@Override
public final boolean isSyncComplete() {
return false;
return syncCompleted;
}
@Override
public final void setIsSyncComplete(boolean value) {
syncCompleted = value;
}
@Override
......
......@@ -73,6 +73,9 @@ public class PcepClientControllerAdapter implements PcepClientController {
@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 @@ public class PcepClientControllerAdapter implements PcepClientController {
pc.setCapability(new ClientCapability(true, true, true));
}
pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
connectedClients.put(pccId, pc);
return pc;
}
......
......@@ -20,6 +20,10 @@ import static org.hamcrest.Matchers.nullValue;
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.IpTunnelEndPoint;
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.Link;
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 class PcepReleaseTunnelProviderTest {
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 @@ public class PcepReleaseTunnelProviderTest {
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 class PcepReleaseTunnelProviderTest {
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 @@ public class PcepReleaseTunnelProviderTest {
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 @@ public class PcepReleaseTunnelProviderTest {
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();
......
......@@ -20,6 +20,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
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.IpTunnelEndPoint;
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 @@ public class PcepSetupTunnelProviderTest {
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 @@ public class PcepSetupTunnelProviderTest {
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 @@ public class PcepSetupTunnelProviderTest {
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 @@ public class PcepSetupTunnelProviderTest {
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();
......
/*
* 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;
}
}
......@@ -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.IpTunnelEndPoint;
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 @@ public class PcepTunnelProviderTest {
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 @@ public class PcepTunnelProviderTest {
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 @@ public class PcepTunnelProviderTest {
tunnelProvider.pcepClientController = null;
tunnelProvider.tunnelProviderRegistry = null;
}
}
}
\ No newline at end of file
......
......@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.nullValue;
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.IpTunnelEndPoint;
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.Link;
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 @@ public class PcepUpdateTunnelProviderTest {
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 @@ public class PcepUpdateTunnelProviderTest {
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 @@ public class PcepUpdateTunnelProviderTest {
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 @@ public class PcepUpdateTunnelProviderTest {
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 @@ public class PcepUpdateTunnelProviderTest {
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();
......
......@@ -94,17 +94,17 @@ public class TunnelServiceAdapter implements TunnelService {
@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
......