-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
package org.opendaylight.protocol.pcep.segment.routing;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.sr.subobject.nai.UnnumberedAdjacencyBuilder;
import org.opendaylight.yangtools.yang.binding.DataContainer;
-final class SrSubobjectParserUtil {
+public abstract class AbstractSrSubobjectParser {
- public static final int MINIMAL_LENGTH = 4;
- public static final int BITSET_LENGTH = 8;
+ protected static final int MINIMAL_LENGTH = 4;
+ protected static final int BITSET_LENGTH = 8;
+ protected static final int M_FLAG_POSITION = 7;
+ protected static final int C_FLAG_POSITION = 6;
+ protected static final int S_FLAG_POSITION = 5;
+ protected static final int F_FLAG_POSITION = 4;
+ protected static final int MPLS_LABEL_OFFSET = 12;
private static final int SID_TYPE_BITS_OFFSET = 4;
- private SrSubobjectParserUtil() {
- throw new UnsupportedOperationException();
- }
-
- public static ByteBuf serializeSrSubobject(final SrSubobject srSubobject, final BitArray bits) {
- Preconditions.checkArgument(srSubobject.getNai() != null || srSubobject.getSid() != null,
- "Both SID and NAI are absent in SR subobject.");
- final ByteBuf body = Unpooled.buffer(MINIMAL_LENGTH);
- writeUnsignedByte((short)(srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET), body);
- bits.toByteBuf(body);
+ public ByteBuf serializeSubobject(final SrSubobject srSubobject) {
+ final ByteBuf buffer = Unpooled.buffer(MINIMAL_LENGTH);
+ // sid type
+ writeUnsignedByte((short)(srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET), buffer);
+ final BitArray bits = new BitArray(BITSET_LENGTH);
+ bits.set(M_FLAG_POSITION, srSubobject.isMFlag());
+ bits.set(C_FLAG_POSITION, srSubobject.isCFlag());
+ if (srSubobject.getSid() == null) {
+ bits.set(S_FLAG_POSITION, Boolean.TRUE);
+ }
+ if (srSubobject.getNai() == null) {
+ bits.set(F_FLAG_POSITION, Boolean.TRUE);
+ }
+ // bits
+ bits.toByteBuf(buffer);
+ // sid
+ Preconditions.checkArgument(srSubobject.getNai() != null || srSubobject.getSid() != null, "Both SID and NAI are absent in SR subobject.");
if (srSubobject.getSid() != null) {
- writeUnsignedInt(srSubobject.getSid(), body);
+ if (srSubobject.isMFlag()) {
+ writeUnsignedInt(srSubobject.getSid() << MPLS_LABEL_OFFSET, buffer);
+ } else {
+ writeUnsignedInt(srSubobject.getSid(), buffer);
+ }
}
+ // nai
final Nai nai = srSubobject.getNai();
if (nai != null) {
switch (srSubobject.getSidType()) {
case Ipv4NodeId:
- writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4Address(), body);
+ writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4Address(), buffer);
break;
case Ipv6NodeId:
- writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6Address(), body);
+ writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6Address(), buffer);
break;
case Ipv4Adjacency:
- writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4Address(), body);
- writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4Address(), body);
+ writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4Address(), buffer);
+ writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4Address(), buffer);
break;
case Ipv6Adjacency:
- writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6Address(), body);
- writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6Address(), body);
+ writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6Address(), buffer);
+ writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6Address(), buffer);
break;
case Unnumbered:
final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), body);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), body);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), body);
- ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), body);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), buffer);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), buffer);
break;
default:
break;
}
}
- return body;
+ return buffer;
}
- public static SrSubobject parseSrSubobject(final ByteBuf buffer, final Function<BitArray, Void> getFlags, final int fPosition, final int sPosition)
- throws PCEPDeserializerException {
+ protected final SrSubobject parseSrSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
final int sidTypeByte = buffer.readByte() >> SID_TYPE_BITS_OFFSET;
final SidType sidType = SidType.forValue(sidTypeByte);
-
final BitArray bitSet = BitArray.valueOf(buffer.readByte());
- getFlags.apply(bitSet);
- final boolean f = bitSet.get(fPosition);
- final boolean s = bitSet.get(sPosition);
+ final boolean f = bitSet.get(F_FLAG_POSITION);
+ final boolean s = bitSet.get(S_FLAG_POSITION);
+ final boolean c = bitSet.get(C_FLAG_POSITION);
+ final boolean m = bitSet.get(M_FLAG_POSITION);
if (f && s) {
throw new PCEPDeserializerException("Both SID and NAI are absent in SR subobject.");
}
- final Long sid;
+ Long tmp = null;
if (!s) {
- sid = buffer.readUnsignedInt();
- } else {
- sid = null;
+ if (m) {
+ tmp = buffer.readUnsignedInt() >>> MPLS_LABEL_OFFSET;
+ } else {
+ tmp = buffer.readUnsignedInt();
+ }
}
-
+ final Long sid = tmp;
final Nai nai;
if (sidType != null && !f) {
} else {
nai = null;
}
-
return new SrSubobject() {
+
@Override
public Class<? extends DataContainer> getImplementedInterface() {
return SrSubobject.class;
}
+
+ @Override
+ public Boolean isMFlag() {
+ return m;
+ }
+
+ @Override
+ public Boolean isCFlag() {
+ return c;
+ }
+
@Override
public SidType getSidType() {
return sidType;
}
+
@Override
public Long getSid() {
return sid;
}
+
@Override
public Nai getNai() {
return nai;
}
};
}
-}
\ No newline at end of file
+}
*/
package org.opendaylight.protocol.pcep.segment.routing;
-import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUtil.BITSET_LENGTH;
-
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
+
import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrEroSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.add.lsp.input.arguments.ero.subobject.subobject.type.SrEroTypeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
-public class SrEroSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+public class SrEroSubobjectParser extends AbstractSrSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
public static final int TYPE = 5;
- private static final int M_FLAG_POSITION = 7;
- private static final int C_FLAG_POSITION = 6;
- private static final int S_FLAG_POSITION = 5;
- private static final int F_FLAG_POSITION = 4;
- private static final int MPLS_LABEL_OFFSET = 12;
-
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrEroSubobject,
- "Unknown subobject instance. Passed %s. Needed SrEroSubobject.", subobject.getSubobjectType()
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject,
+ "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType()
.getClass());
- final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
- final SrEroTypeBuilder builder = new SrEroTypeBuilder(srEroSubobject);
- if (srEroSubobject.isMFlag() != null && srEroSubobject.isMFlag() && srEroSubobject.getSid() != null) {
- builder.setSid(srEroSubobject.getSid() << MPLS_LABEL_OFFSET);
- }
- final BitArray bits = new BitArray(BITSET_LENGTH);
- bits.set(M_FLAG_POSITION, srEroSubobject.isMFlag());
- bits.set(C_FLAG_POSITION, srEroSubobject.isCFlags());
- if (srEroSubobject.getSid() == null) {
- bits.set(S_FLAG_POSITION, Boolean.TRUE);
- }
- if (srEroSubobject.getNai() == null) {
- bits.set(F_FLAG_POSITION, Boolean.TRUE);
- }
- final ByteBuf body = SrSubobjectParserUtil.serializeSrSubobject(builder.build(), bits);
+ final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
+ final ByteBuf body = serializeSubobject(srSubobject);
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.readableBytes() <= SrSubobjectParserUtil.MINIMAL_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
- }
- final BitArray flags = new BitArray(BITSET_LENGTH);
- final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitArray, Void>() {
- @Override
- public Void apply(final BitArray input) {
- flags.set(C_FLAG_POSITION, input.get(C_FLAG_POSITION));
- flags.set(M_FLAG_POSITION, input.get(M_FLAG_POSITION));
- return null;
- }
- }, F_FLAG_POSITION, S_FLAG_POSITION);
- final SrEroTypeBuilder srEroSubobjectBuilder = new SrEroTypeBuilder(srSubobject);
- srEroSubobjectBuilder.setCFlags(flags.get(C_FLAG_POSITION));
- srEroSubobjectBuilder.setMFlag(flags.get(M_FLAG_POSITION));
- if (srEroSubobjectBuilder.isMFlag() != null && srEroSubobjectBuilder.isMFlag() && srEroSubobjectBuilder.getSid() != null) {
- srEroSubobjectBuilder.setSid(srEroSubobjectBuilder.getSid() >> MPLS_LABEL_OFFSET);
- }
+ final SrEroTypeBuilder srEroSubobjectBuilder = new SrEroTypeBuilder(parseSrSubobject(buffer));
final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
subobjectBuilder.setLoose(loose);
subobjectBuilder.setSubobjectType(srEroSubobjectBuilder.build());
return subobjectBuilder.build();
}
-
}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.segment.routing;
-
-import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.Srp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrEroSubobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupType;
-
-public final class SrEroUtil {
-
- private static final int MPLS_LABEL_MIN_VALUE = 16;
-
- private SrEroUtil() {
- throw new UnsupportedOperationException();
- }
-
- protected static PCEPErrors validateSrEroSubobjects(final Ero ero) {
- if (ero.getSubobject() != null) {
- for (final Subobject subobject : ero.getSubobject()) {
- if (!(subobject.getSubobjectType() instanceof SrEroSubobject)) {
- return PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS;
- }
- final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
- if (srEroSubobject.isMFlag() != null && srEroSubobject.isMFlag() && srEroSubobject.getSid() < MPLS_LABEL_MIN_VALUE) {
- return PCEPErrors.BAD_LABEL_VALUE;
- }
- }
- }
- return null;
- }
-
- protected static boolean isSegmentRoutingPath(final Srp srp) {
- if (srp != null && srp.getTlvs() != null && isSrTePst(srp.getTlvs().getPathSetupType())) {
- return true;
- }
- return false;
- }
-
- private static boolean isSrTePst(final PathSetupType tlv) {
- if (tlv != null && tlv.getPst() == 1) {
- return true;
- }
- return false;
- }
-
-}
package org.opendaylight.protocol.pcep.segment.routing;
-import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUtil.BITSET_LENGTH;
-import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUtil.MINIMAL_LENGTH;
-
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
+
import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
-import org.opendaylight.protocol.util.BitArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrRroSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.add.lsp.input.arguments.rro.subobject.subobject.type.SrRroTypeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder;
-public class SrRroSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
+public class SrRroSubobjectParser extends AbstractSrSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
public static final int TYPE = 6;
- private static final int S_FLAG_POSITION = 7;
- private static final int F_FLAG_POSITION = 6;
-
@Override
- public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrRroSubobject,
- "Unknown subobject instance. Passed %s. Needed SrRroSubobject.", subobject.getSubobjectType()
+ public void serializeSubobject(Subobject subobject, ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrSubobject,
+ "Unknown subobject instance. Passed %s. Needed SrSubobject.", subobject.getSubobjectType()
.getClass());
-
- final SrRroSubobject srRroSubobject = (SrRroSubobject) subobject.getSubobjectType();
- final BitArray bits = new BitArray(BITSET_LENGTH);
- if (srRroSubobject.getSid() == null) {
- bits.set(S_FLAG_POSITION, Boolean.TRUE);
- }
- if (srRroSubobject.getNai() == null) {
- bits.set(F_FLAG_POSITION, Boolean.TRUE);
- }
- final ByteBuf body = SrSubobjectParserUtil.serializeSrSubobject(srRroSubobject, bits);
+ final SrSubobject srSubobject = (SrSubobject) subobject.getSubobjectType();
+ final ByteBuf body = serializeSubobject(srSubobject);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.readableBytes() <= MINIMAL_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
- }
-
- final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitArray, Void>() {
- @Override
- public Void apply(final BitArray input) {
- return null;
- }
- }, F_FLAG_POSITION, S_FLAG_POSITION);
- final SrRroTypeBuilder srRroSubobjectBuilder = new SrRroTypeBuilder(srSubobject);
-
+ final SrRroTypeBuilder srRroSubobjectBuilder = new SrRroTypeBuilder(parseSrSubobject(buffer));
final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
subobjectBuilder.setSubobjectType(srRroSubobjectBuilder.build());
return subobjectBuilder.build();
description
"This module contains the data model of PCEP Extensions for Segment Routing,
- draft-ietf-pce-segment-routing-00.
+ draft-ietf-pce-segment-routing-01.
Copyright (c)2015 Cisco Systems, Inc. All rights reserved.
revision "2015-01-12" {
description
"Upgrade from draft-sivabalan-pce-segment-routing-02.";
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01";
}
grouping sr-pce-capability-tlv {
description "SR-PCE-CAPABILITY TLV";
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.1.1";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.1.1";
container sr-pce-capability {
uses pcep:tlv;
}
augment "/msg:open/msg:open-message/msg:open/msg:tlvs" {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.1";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.1";
uses sr-pce-capability-tlv;
}
augment "/msg:pcerr/msg:pcerr-message/msg:error-type/msg:session-case/msg:session/msg:open/msg:tlvs" {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.1";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.1";
uses sr-pce-capability-tlv;
}
typedef sid-type {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.3.1";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.3.1";
type enumeration {
enum ipv4-node-id {
value 1;
}
grouping sr-subobject {
+ description "Common grouping for both SR-ERO and SR-RRO subobjects as they share the same content representation.";
+ leaf c-flag {
+ type boolean;
+ default false;
+ }
+ leaf m-flag {
+ type boolean;
+ default false;
+ }
leaf sid-type {
type sid-type;
}
-
leaf sid {
description "Segment Identifier";
type uint32;
}
-
choice nai {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.3.2";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.3.2";
description "Node or Adjacency Identifier";
case ip-node-id {
when "../sid-type = 'ipv4-node-id' or ../sid-type = 'ipv6-node-id'";
}
}
+ // kept both groupings in case draft changes and they won't be equal
grouping sr-ero-subobject {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.3.1";
- leaf c-flags {
- type boolean;
- default false;
- }
- leaf m-flag {
- type boolean;
- default false;
- }
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.3.1";
uses sr-subobject;
}
grouping sr-rro-subobject {
- reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-00#section-5.4";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-segment-routing-01#section-5.4";
uses sr-subobject;
}
private static final byte[] srEroSubobjectWithoutNAI = {
0x05,0x08,(byte) 0x10,0x08,
- 0x00,0x01,(byte) 0xe2,0x40,
+ 0x00,0x01,(byte) 0xe2,0x40
};
private static final byte[] srEroSubobjectWithoutSID = {
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv4Address("74.125.43.99"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv6NodeId);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729c"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv4Adjacency);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(new Ipv4Address("74.125.43.99")))
.setRemoteIpAddress(new IpAddress(new Ipv4Address("74.125.43.100"))).build());
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv6Adjacency);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729c")))
.setRemoteIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729d"))).build());
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Unnumbered);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new UnnumberedAdjacencyBuilder().setLocalNodeId(1L).setLocalInterfaceId(2L).setRemoteNodeId(3L).setRemoteInterfaceId(4L).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
builder.setSid(123456L);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
final SrEroSubobjectParser parser = new SrEroSubobjectParser();
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(false);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv4Address("74.125.43.99"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build()).setLoose(false);
public void testSrEroSubobjectIpv4NodeIdNAIMFlag() throws PCEPDeserializerException {
final SrEroSubobjectParser parser = new SrEroSubobjectParser();
final SrEroTypeBuilder builder = new SrEroTypeBuilder();
- builder.setCFlags(false);
+ builder.setCFlag(false);
builder.setMFlag(true);
builder.setSidType(SidType.Ipv4NodeId);
builder.setSid(30140L);
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.segment.routing;
-
-import com.google.common.collect.Lists;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collections;
-import java.util.List;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.SrpBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.pcinitiate.pcinitiate.message.requests.ero.subobject.subobject.type.SrEroTypeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupTypeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
-
-public class SrEroUtilTest {
-
- @Test(expected=UnsupportedOperationException.class)
- public void testPrivateConstructor() throws Throwable {
- final Constructor<SrEroUtil> c = SrEroUtil.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (final InvocationTargetException e) {
- throw e.getCause();
- }
- }
-
- @Test
- public void testValidateSrEroSubobjects() {
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject()))));
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Collections.<Subobject>emptyList())));
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(null)));
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, true)))));
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(20L, false)))));
- Assert.assertNull(SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, false)))));
- Assert.assertEquals(PCEPErrors.BAD_LABEL_VALUE, SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createSRSubobject(10L, true)))));
- Assert.assertEquals(PCEPErrors.NON_IDENTICAL_ERO_SUBOBJECTS,
- SrEroUtil.validateSrEroSubobjects(createEro(Lists.newArrayList(createIpPrefixSubobject()))));
- }
-
- @Test
- public void testIsSegmentRoutingPath() {
- Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(null));
- Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(new SrpBuilder().build()));
- Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(new SrpBuilder().setTlvs(new TlvsBuilder().build()).build()));
- Assert.assertFalse(SrEroUtil.isSegmentRoutingPath(new SrpBuilder().setTlvs(new TlvsBuilder().setPathSetupType(new PathSetupTypeBuilder().setPst((short) 8).build()).build()).build()));
- Assert.assertTrue(SrEroUtil.isSegmentRoutingPath(new SrpBuilder().setTlvs(new TlvsBuilder().setPathSetupType(new PathSetupTypeBuilder().setPst((short) 1).build()).build()).build()));
- }
-
- private Ero createEro(final List<Subobject> subobejcts) {
- return new EroBuilder().setSubobject(subobejcts).build();
- }
-
- private Subobject createSRSubobject() {
- final SubobjectBuilder builder = new SubobjectBuilder();
- builder.setSubobjectType(new SrEroTypeBuilder().build());
- return builder.build();
- }
-
- private Subobject createSRSubobject(final long sid, final boolean isM) {
- final SubobjectBuilder builder = new SubobjectBuilder();
- builder.setSubobjectType(new SrEroTypeBuilder().setMFlag(isM).setSid(sid).build());
- return builder.build();
- }
-
- private Subobject createIpPrefixSubobject() {
- final SubobjectBuilder builder = new SubobjectBuilder();
- builder.setSubobjectType(new IpPrefixCaseBuilder().build());
- return builder.build();
- }
-}
final List<Subobject> subobjects = Lists.newArrayList();
final SrEroTypeBuilder srEroSubBuilder = new SrEroTypeBuilder();
- srEroSubBuilder.setCFlags(false);
+ srEroSubBuilder.setCFlag(false);
srEroSubBuilder.setMFlag(false);
srEroSubBuilder.setSidType(SidType.Ipv4NodeId);
srEroSubBuilder.setSid(123456L);
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
};
private static final byte[] srRroSubobjectWithoutNAI = {
- 0x06,0x08,(byte) 0x10,0x02,
- 0x00,0x01,(byte) 0xe2,0x40,
+ 0x06,0x08, (byte) 0x10,0xb,
+ 0x1e,0x24,(byte) (byte)-32, 0x00,
};
private static final byte[] srRroSubobjectWithoutSID = {
- 0x06,0x08,(byte) 0x10,0x01,
+ 0x06,0x08,(byte) 0x10,0x04,
0x4A,0x7D,0x2b,0x63,
};
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
builder.setSid(123456L);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv4Address("74.125.43.99"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
final SrRroSubobjectParser parser = new SrRroSubobjectParser();
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv6NodeId);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setSid(123456L);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729c"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv4Adjacency);
builder.setSid(123456L);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(new Ipv4Address("74.125.43.99")))
.setRemoteIpAddress(new IpAddress(new Ipv4Address("74.125.43.100"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv6Adjacency);
builder.setSid(123456L);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729c")))
.setRemoteIpAddress(new IpAddress(new Ipv6Address("fe80:cd00::211e:729d"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Unnumbered);
builder.setSid(123456L);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setNai(new UnnumberedAdjacencyBuilder().setLocalNodeId(1L).setLocalInterfaceId(2L).setRemoteNodeId(3L).setRemoteInterfaceId(4L).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
final SrRroSubobjectParser parser = new SrRroSubobjectParser();
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
- builder.setSid(123456L);
+ builder.setSid(123470L);
+ builder.setCFlag(true);
+ builder.setMFlag(true);
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
assertEquals(subobjBuilder.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(srRroSubobjectWithoutNAI, 2))));
final SrRroSubobjectParser parser = new SrRroSubobjectParser();
final SrRroTypeBuilder builder = new SrRroTypeBuilder();
builder.setSidType(SidType.Ipv4NodeId);
+ builder.setCFlag(false);
+ builder.setMFlag(false);
builder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(new Ipv4Address("74.125.43.99"))).build());
final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(builder.build());
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.pcep.segment.routing;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import org.junit.Test;
-
-public class SrSubobjectParserUtilTest {
-
- @Test(expected=UnsupportedOperationException.class)
- public void testPrivateConstructor() throws Throwable {
- final Constructor<SrSubobjectParserUtil> c = SrSubobjectParserUtil.class.getDeclaredConstructor();
- c.setAccessible(true);
- try {
- c.newInstance();
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
-}
private static Ero createSrEroObject(final String nai) {
final SrEroTypeBuilder srEroBuilder = new SrEroTypeBuilder();
- srEroBuilder.setCFlags(false);
+ srEroBuilder.setCFlag(false);
srEroBuilder.setMFlag(false);
srEroBuilder.setSidType(SidType.Ipv4NodeId);
srEroBuilder.setSid(123456L);
* Segment Routing error: Both SID and NAI are absent in RRO subobject.
*/
SID_AND_NAI_ABSENT_IN_RRO(10, 7),
+ /**
+ * Segment Routing error: Non-identical RRO subobjects.
+ */
+ SID_NON_IDENTICAL_RRO_SUBOBJECTS(10, 8),
/**
* Invalid traffic engineering path setup type: Unsupported path setup type
*/