}
}
+ typedef node-identifier {
+ type binary {
+ length 1..65535;
+ }
+ }
+
grouping lsp-db-version-tlv {
description "LSP State Database Version TLV";
- reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.1.2";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.2.3";
container lsp-db-version {
uses pcep:tlv;
}
}
- grouping lsp-identifiers-tlv {
- description "LSP Identifiers TLV";
- reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.2.2";
- container lsp-identifiers {
- uses pcep:tlv;
- leaf lsp-id {
- type rsvp:lsp-id;
- mandatory true;
- }
-
- leaf tunnel-id {
- type rsvp:tunnel-id;
- mandatory true;
- }
+ grouping node-identifier-tlv {
+ description "Node Identifier TLV";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.1.3";
- choice address-family {
- case ipv4-case {
- container ipv4 {
- leaf ipv4-tunnel-sender-address {
- type inet:ipv4-address;
- mandatory true;
- }
- leaf ipv4-extended-tunnel-id {
- type rsvp:ipv4-extended-tunnel-id;
- mandatory true;
- }
- }
- }
- case ipv6-case {
- container ipv6 {
- leaf ipv6-tunnel-sender-address {
- type inet:ipv6-address;
- mandatory true;
- }
- leaf ipv6-extended-tunnel-id {
- type rsvp:ipv6-extended-tunnel-id;
- mandatory true;
- }
- }
- }
- }
- }
- }
-
- grouping lsp-error-code-tlv {
- description "LSP Error Code TLV";
- reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.2.3";
- container lsp-error-code {
+ container node-identifier {
uses pcep:tlv;
- leaf error-code {
- type uint32;
+ leaf node-id {
+ type node-identifier;
mandatory true;
}
}
grouping rsvp-error-spec-tlv {
description "RSVP Error Spec TLV";
- reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.2.4";
+ reference "http://tools.ietf.org/html/draft-ietf-pce-stateful-pce-02#section-7.2.2";
container rsvp-error-spec {
uses pcep:tlv;
choice error-type {
container "tlvs" {
uses lsp-db-version-tlv;
- uses lsp-error-code-tlv;
-
- uses lsp-identifiers-tlv;
-
uses rsvp-error-spec-tlv;
uses symbolic-path-name-tlv;
augment "/msg:open/msg:open-message/msg:open/msg:tlvs" {
uses stateful-capability-tlv;
- uses lsp-db-version-tlv;
+ uses node-identifier-tlv;
}
augment "/msg:pcerr/msg:pcerr-message/msg:error-type/msg:session-case/msg:session/msg:open/msg:tlvs" {
uses stateful-capability-tlv;
- uses lsp-db-version-tlv;
+ uses node-identifier-tlv;
}
augment "/msg:pcreq/msg:pcreq-message/msg:requests/msg:segment-computation/msg:p2p" {
final Tlvs2Builder statefulBuilder = new Tlvs2Builder();
if (tbuilder.getAugmentation(Tlvs2.class) != null) {
final Tlvs2 t = tbuilder.getAugmentation(Tlvs2.class);
- if (t.getClass() != null) {
+ if (t.getStateful() != null) {
statefulBuilder.setStateful(t.getStateful());
}
}
+++ /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.impl.stateful02;
-
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiers;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv4Case;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv6Case;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiers}
- */
-public class LspIdentifierIpv4TlvParser implements TlvParser, TlvSerializer {
-
- public static final int TYPE = 18;
-
- private static final int IP4_F_LENGTH = 4;
- private static final int EX_TUNNEL_ID4_F_LENGTH = 4;
-
- private static final int LSP_ID_F_LENGTH = 2;
- private static final int TUNNEL_ID_F_LENGTH = 2;
-
- private static final int V4_LENGTH = 12;
-
- @Override
- public LspIdentifiers parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- if (valueBytes == null || valueBytes.length == 0) {
- throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
- }
- if (valueBytes.length != V4_LENGTH) {
- throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers Ipv4 tlv length.");
- }
- int position = 0;
- final Ipv4Builder builder = new Ipv4Builder();
- builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
- position = IP4_F_LENGTH;
- final LspId lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
- position += LSP_ID_F_LENGTH;
- final TunnelId tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
- position += TUNNEL_ID_F_LENGTH;
- builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position,
- EX_TUNNEL_ID4_F_LENGTH))));
- final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
- position += EX_TUNNEL_ID4_F_LENGTH;
- return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
- }
-
- @Override
- public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null) {
- throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
- }
- final LspIdentifiers lsp = (LspIdentifiers) tlv;
- final AddressFamily afi = lsp.getAddressFamily();
-
- if (afi.getImplementedInterface().equals(Ipv6Case.class)) {
- return new LspIdentifierIpv6TlvParser().serializeTlv(tlv);
- }
-
- final byte[] bytes = new byte[V4_LENGTH];
- int offset = 0;
- final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
- ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()), bytes, offset);
- offset += IP4_F_LENGTH;
- ByteArray.copyWhole(ByteArray.longToBytes(lsp.getLspId().getValue(), LSP_ID_F_LENGTH), bytes, offset);
- offset += LSP_ID_F_LENGTH;
- ByteArray.copyWhole(ByteArray.intToBytes(lsp.getTunnelId().getValue(), TUNNEL_ID_F_LENGTH), bytes, offset);
- offset += TUNNEL_ID_F_LENGTH;
- ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
- return bytes;
- }
-
- @Override
- public int getType() {
- return TYPE;
- }
-}
+++ /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.impl.stateful02;
-
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiers;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv6Case;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv6CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiers}
- */
-public class LspIdentifierIpv6TlvParser implements TlvParser, TlvSerializer {
-
- public static final int TYPE = 19;
-
- private static final int IP6_F_LENGTH = 16;
- private static final int EX_TUNNEL_ID6_F_LENGTH = 16;
-
- private static final int LSP_ID_F_LENGTH = 2;
- private static final int TUNNEL_ID_F_LENGTH = 2;
-
- private static final int V6_LENGTH = 36;
-
- @Override
- public LspIdentifiers parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
- if (valueBytes == null || valueBytes.length == 0) {
- throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
- }
- if (valueBytes.length != V6_LENGTH) {
- throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers Ipv6 tlv length.");
- }
- int position = 0;
- final Ipv6Builder builder = new Ipv6Builder();
- builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
- position += IP6_F_LENGTH;
- final LspId lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
- position += LSP_ID_F_LENGTH;
- final TunnelId tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
- position += TUNNEL_ID_F_LENGTH;
- builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position,
- EX_TUNNEL_ID6_F_LENGTH))));
- final AddressFamily afi = new Ipv6CaseBuilder().setIpv6(builder.build()).build();
- position += EX_TUNNEL_ID6_F_LENGTH;
- return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
- }
-
- @Override
- public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null) {
- throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
- }
- final byte[] bytes = new byte[V6_LENGTH];
- int offset = 0;
- final LspIdentifiers lsp = (LspIdentifiers) tlv;
- final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
- ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()), bytes, offset);
- offset += IP6_F_LENGTH;
- ByteArray.copyWhole(ByteArray.longToBytes(lsp.getLspId().getValue(), LSP_ID_F_LENGTH), bytes, offset);
- offset += LSP_ID_F_LENGTH;
- ByteArray.copyWhole(ByteArray.intToBytes(lsp.getTunnelId().getValue(), TUNNEL_ID_F_LENGTH), bytes, offset);
- offset += TUNNEL_ID_F_LENGTH;
- ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
- return bytes;
- }
-
- @Override
- public int getType() {
- return TYPE;
- }
-}
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.error.code.tlv.LspErrorCode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.error.code.tlv.LspErrorCodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifierBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-/**
- * Parser for {@link LspErrorCode}
- */
-public class LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
-
- public static final int TYPE = 20;
+public class NodeIdentifierTlvParser implements TlvParser, TlvSerializer {
- private static final int UPDATE_ERR_CODE_LENGTH = 4;
+ public static final int TYPE = 24;
@Override
- public LspErrorCode parseTlv(final byte[] buffer) throws PCEPDeserializerException {
- return new LspErrorCodeBuilder().setErrorCode(ByteArray.bytesToLong(buffer)).build();
+ public int getType() {
+ return TYPE;
}
@Override
public byte[] serializeTlv(final Tlv tlv) {
- if (tlv == null) {
- throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
- }
- final LspErrorCode lsp = (LspErrorCode) tlv;
- return ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH);
+ return ((NodeIdentifier) tlv).getValue();
}
@Override
- public int getType() {
- return TYPE;
+ public Tlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
+ return new NodeIdentifierBuilder().setNodeId(new NodeIdentifier(buffer)).build();
}
-}
+}
\ No newline at end of file
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.PlspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.db.version.tlv.LspDbVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.error.code.tlv.LspErrorCode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.LspBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.lsp.Tlvs;
@Override
public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
- if (tlv instanceof LspErrorCode) {
- builder.setLspErrorCode((LspErrorCode) tlv);
- } else if (tlv instanceof LspIdentifiers) {
- builder.setLspIdentifiers((LspIdentifiers) tlv);
- } else if (tlv instanceof RsvpErrorSpec) {
+ if (tlv instanceof RsvpErrorSpec) {
builder.setRsvpErrorSpec((RsvpErrorSpec) tlv);
} else if (tlv instanceof SymbolicPathName) {
builder.setSymbolicPathName((SymbolicPathName) tlv);
return new byte[0];
}
int finalLength = 0;
- byte[] lspErrBytes = null;
- byte[] lspIdBytes = null;
byte[] rsvpErrBytes = null;
byte[] symbBytes = null;
byte[] dbvBytes = null;
- if (tlvs.getLspErrorCode() != null) {
- lspErrBytes = serializeTlv(tlvs.getLspErrorCode());
- finalLength += lspErrBytes.length;
- }
- if (tlvs.getLspIdentifiers() != null) {
- lspIdBytes = serializeTlv(tlvs.getLspIdentifiers());
- finalLength += lspIdBytes.length;
- }
if (tlvs.getRsvpErrorSpec() != null) {
rsvpErrBytes = serializeTlv(tlvs.getRsvpErrorSpec());
finalLength += rsvpErrBytes.length;
}
int offset = 0;
final byte[] result = new byte[finalLength];
- if (lspErrBytes != null) {
- ByteArray.copyWhole(lspErrBytes, result, offset);
- offset += lspErrBytes.length;
- }
- if (lspIdBytes != null) {
- ByteArray.copyWhole(lspIdBytes, result, offset);
- offset += lspIdBytes.length;
- }
if (rsvpErrBytes != null) {
ByteArray.copyWhole(rsvpErrBytes, result, offset);
offset += rsvpErrBytes.length;
--- /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.impl.stateful02;
+
+import org.opendaylight.protocol.pcep.impl.object.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.pcep.impl.object.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.primitives.UnsignedBytes;
+
+/**
+ * Parser for {@link Open}
+ */
+public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
+ private static final Logger LOG = LoggerFactory.getLogger(PCEPOpenObjectParser.class);
+
+ public static final int CLASS = 1;
+
+ public static final int TYPE = 1;
+
+ /*
+ * lengths of fields in bytes
+ */
+ private static final int VER_FLAGS_MF_LENGTH = 1;
+ private static final int KEEPALIVE_F_LENGTH = 1;
+ private static final int DEAD_TIMER_LENGTH = 1;
+ private static final int SID_F_LENGTH = 1;
+
+ /*
+ * lengths of subfields inside multi-field in bits
+ */
+ private static final int VERSION_SF_LENGTH = 3;
+
+ /*
+ * offsets of field in bytes
+ */
+ private static final int VER_FLAGS_MF_OFFSET = 0;
+ private static final int KEEPALIVE_F_OFFSET = VER_FLAGS_MF_OFFSET + VER_FLAGS_MF_LENGTH;
+ private static final int DEAD_TIMER_OFFSET = KEEPALIVE_F_OFFSET + KEEPALIVE_F_LENGTH;
+ private static final int SID_F_OFFSET = DEAD_TIMER_OFFSET + DEAD_TIMER_LENGTH;
+ private static final int TLVS_OFFSET = SID_F_OFFSET + SID_F_LENGTH;
+
+ /*
+ * offsets of subfields inside multi-field in bits
+ */
+ private static final int VERSION_SF_OFFSET = 0;
+
+ private static final int PCEP_VERSION = 1;
+
+ public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+ super(tlvReg);
+ }
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException {
+ if (bytes == null || bytes.length == 0) {
+ throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
+ }
+ final int versionValue = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH);
+
+ final OpenBuilder builder = new OpenBuilder();
+ builder.setVersion(new ProtocolVersion((short) versionValue));
+ builder.setProcessingRule(header.isProcessingRule());
+ builder.setIgnore(header.isIgnore());
+ builder.setDeadTimer((short) UnsignedBytes.toInt(bytes[DEAD_TIMER_OFFSET]));
+ builder.setKeepalive((short) UnsignedBytes.toInt(bytes[KEEPALIVE_F_OFFSET]));
+ builder.setSessionId((short) UnsignedBytes.toInt(bytes[SID_F_OFFSET]));
+
+ final TlvsBuilder tbuilder = new TlvsBuilder();
+ parseTlvs(tbuilder, ByteArray.cutBytes(bytes, TLVS_OFFSET));
+ builder.setTlvs(tbuilder.build());
+
+ final Open obj = builder.build();
+ if (versionValue != PCEP_VERSION) {
+ // TODO: Should we move this check into the negotiator
+ LOG.debug("Unsupported PCEP version {}", versionValue);
+ return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj);
+ }
+
+ return obj;
+ }
+
+ @Override
+ public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
+ final Tlvs2Builder statefulBuilder = new Tlvs2Builder();
+ if (tbuilder.getAugmentation(Tlvs2.class) != null) {
+ final Tlvs2 t = tbuilder.getAugmentation(Tlvs2.class);
+ if (t.getStateful() != null) {
+ statefulBuilder.setStateful(t.getStateful());
+ }
+ if (t.getNodeIdentifier() != null) {
+ statefulBuilder.setNodeIdentifier(t.getNodeIdentifier());
+ }
+ }
+ if (tlv instanceof OfList) {
+ tbuilder.setOfList((OfList) tlv);
+ } else if (tlv instanceof Stateful) {
+ statefulBuilder.setStateful((Stateful) tlv);
+ } else if (tlv instanceof NodeIdentifier) {
+ statefulBuilder.setNodeIdentifier((NodeIdentifier) tlv);
+ }
+ tbuilder.addAugmentation(Tlvs2.class, statefulBuilder.build());
+ }
+
+ @Override
+ public byte[] serializeObject(final Object object) {
+ if (!(object instanceof Open)) {
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed OpenObject.");
+ }
+ final Open open = (Open) object;
+
+ final byte versionFlagMF = (byte) (PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH));
+
+ final byte[] tlvs = serializeTlvs(open.getTlvs());
+
+ final byte[] bytes = new byte[TLVS_OFFSET + tlvs.length + getPadding(TLVS_OFFSET + tlvs.length, PADDED_TO)];
+
+ bytes[VER_FLAGS_MF_OFFSET] = versionFlagMF;
+ bytes[KEEPALIVE_F_OFFSET] = UnsignedBytes.checkedCast(open.getKeepalive());
+ bytes[DEAD_TIMER_OFFSET] = UnsignedBytes.checkedCast(open.getDeadTimer());
+ bytes[SID_F_OFFSET] = UnsignedBytes.checkedCast(open.getSessionId());
+ if (tlvs.length != 0) {
+ ByteArray.copyWhole(tlvs, bytes, TLVS_OFFSET);
+ }
+ return ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), bytes);
+ }
+
+ public byte[] serializeTlvs(final Tlvs tlvs) {
+ if (tlvs == null) {
+ return new byte[0];
+ }
+ int finalLength = 0;
+ byte[] ofListBytes = null;
+ byte[] statefulBytes = null;
+ byte[] nodeIdBytes = null;
+ if (tlvs.getOfList() != null) {
+ ofListBytes = serializeTlv(tlvs.getOfList());
+ finalLength += ofListBytes.length;
+ }
+ if (tlvs.getAugmentation(Tlvs2.class) != null) {
+ final Tlvs2 statefulTlvs = tlvs.getAugmentation(Tlvs2.class);
+ if (statefulTlvs.getStateful() != null) {
+ statefulBytes = serializeTlv(statefulTlvs.getStateful());
+ finalLength += statefulBytes.length;
+ }
+ if (statefulTlvs.getNodeIdentifier() != null) {
+ nodeIdBytes = serializeTlv(statefulTlvs.getNodeIdentifier());
+ finalLength += nodeIdBytes.length;
+ }
+ }
+
+ int offset = 0;
+ final byte[] result = new byte[finalLength];
+ if (ofListBytes != null) {
+ ByteArray.copyWhole(ofListBytes, result, offset);
+ offset += ofListBytes.length;
+ }
+ if (statefulBytes != null) {
+ ByteArray.copyWhole(statefulBytes, result, offset);
+ offset += statefulBytes.length;
+ }
+ if (nodeIdBytes != null) {
+ ByteArray.copyWhole(nodeIdBytes, result, offset);
+ offset += nodeIdBytes.length;
+ }
+ return result;
+ }
+
+ @Override
+ public int getObjectType() {
+ return TYPE;
+ }
+
+ @Override
+ public int getObjectClass() {
+ return CLASS;
+ }
+}
--- /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.impl.stateful02;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.List;
+
+import org.opendaylight.protocol.pcep.impl.message.AbstractMessageParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Replies1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Replies1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
+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.include.route.object.Iro;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.RepliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.Result;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.FailureCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.FailureCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.SuccessCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.SuccessCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Parser for {@link Pcrep}
+ */
+public class PCEPReplyMessageParser extends AbstractMessageParser {
+
+ public static final int TYPE = 4;
+
+ public PCEPReplyMessageParser(final ObjectHandlerRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public void serializeMessage(final Message message, final ByteBuf buffer) {
+ if (!(message instanceof Pcrep)) {
+ throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
+ + ". Nedded PcrepMessage.");
+ }
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessage repMsg = ((Pcrep) message).getPcrepMessage();
+ if (repMsg.getReplies() == null || repMsg.getReplies().isEmpty()) {
+ throw new IllegalArgumentException("Replies cannot be null or empty.");
+ }
+ for (final Replies reply : repMsg.getReplies()) {
+ if (reply.getRp() == null) {
+ throw new IllegalArgumentException("Reply must contain RP object.");
+ }
+ buffer.writeBytes(serializeObject(reply.getRp()));
+ if (reply.getAugmentation(Replies1.class) != null && reply.getAugmentation(Replies1.class).getLsp() != null) {
+ buffer.writeBytes(serializeObject(reply.getAugmentation(Replies1.class).getLsp()));
+ }
+ if (reply.getResult() != null) {
+ if (reply.getResult() instanceof FailureCase) {
+ final FailureCase f = ((FailureCase) reply.getResult());
+ buffer.writeBytes(serializeObject(f.getNoPath()));
+ if (f.getLspa() != null) {
+ buffer.writeBytes(serializeObject(f.getLspa()));
+ }
+ if (f.getBandwidth() != null) {
+ buffer.writeBytes(serializeObject(f.getBandwidth()));
+ }
+ if (f.getMetrics() != null && !f.getMetrics().isEmpty()) {
+ for (final Metrics m : f.getMetrics()) {
+ buffer.writeBytes(serializeObject(m.getMetric()));
+ }
+ }
+ if (f.getIro() != null) {
+ buffer.writeBytes(serializeObject(f.getIro()));
+ }
+ } else {
+ final SuccessCase s = (SuccessCase) reply.getResult();
+ for (final Paths p : s.getSuccess().getPaths()) {
+ buffer.writeBytes(serializeObject(p.getEro()));
+ if (p.getLspa() != null) {
+ buffer.writeBytes(serializeObject(p.getLspa()));
+ }
+ if (p.getOf() != null) {
+ buffer.writeBytes(serializeObject(p.getOf()));
+ }
+ if (p.getBandwidth() != null) {
+ buffer.writeBytes(serializeObject(p.getBandwidth()));
+ }
+ if (p.getMetrics() != null && !p.getMetrics().isEmpty()) {
+ for (final Metrics m : p.getMetrics()) {
+ buffer.writeBytes(serializeObject(m.getMetric()));
+ }
+ }
+ if (p.getIro() != null) {
+ buffer.writeBytes(serializeObject(p.getIro()));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected Pcrep validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
+ if (objects == null) {
+ throw new IllegalArgumentException("Passed list can't be null.");
+ }
+ if (objects.isEmpty()) {
+ throw new PCEPDeserializerException("Pcrep message cannot be empty.");
+ }
+ final List<Replies> replies = Lists.newArrayList();
+ while (!objects.isEmpty()) {
+ final Replies r = this.getValidReply(objects, errors);
+ if (r != null) {
+ replies.add(r);
+ }
+ }
+ if (!objects.isEmpty()) {
+ throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
+ }
+ return new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(replies).build()).build();
+ }
+
+ private Replies getValidReply(final List<Object> objects, final List<Message> errors) {
+ if (!(objects.get(0) instanceof Rp)) {
+ errors.add(createErrorMsg(PCEPErrors.RP_MISSING));
+ return null;
+ }
+ final Rp rp = (Rp) objects.get(0);
+ objects.remove(0);
+ Result res = null;
+ Lsp lsp = null;
+ if (objects.get(0) instanceof Lsp) {
+ lsp = (Lsp) objects.get(0);
+ objects.remove(0);
+ }
+ if (!objects.isEmpty()) {
+ if (objects.get(0) instanceof NoPath) {
+ final NoPath noPath = (NoPath) objects.get(0);
+ objects.remove(0);
+ final FailureCaseBuilder builder = new FailureCaseBuilder();
+ builder.setNoPath(noPath);
+ while (!objects.isEmpty()) {
+ this.parseAttributes(builder, objects);
+ }
+ res = builder.build();
+ } else if (objects.get(0) instanceof Ero) {
+ final Ero ero = (Ero) objects.get(0);
+ objects.remove(0);
+ final SuccessBuilder builder = new SuccessBuilder();
+ final List<Paths> paths = Lists.newArrayList();
+ final PathsBuilder pBuilder = new PathsBuilder();
+ pBuilder.setEro(ero);
+ while (!objects.isEmpty()) {
+ this.parsePath(pBuilder, objects);
+ paths.add(pBuilder.build());
+ }
+ builder.setPaths(paths);
+ res = new SuccessCaseBuilder().setSuccess(builder.build()).build();
+ }
+ }
+ return new RepliesBuilder().setRp(rp).addAugmentation(Replies1.class, new Replies1Builder().setLsp(lsp).build()).setResult(res).build();
+ }
+
+ private void parseAttributes(final FailureCaseBuilder builder, final List<Object> objects) {
+ final List<Metrics> pathMetrics = Lists.newArrayList();
+
+ Object obj;
+ State state = State.Init;
+ while (!objects.isEmpty() && !state.equals(State.End)) {
+ obj = objects.get(0);
+
+ switch (state) {
+ case Init:
+ state = State.LspaIn;
+ if (obj instanceof Lspa) {
+ builder.setLspa((Lspa) obj);
+ break;
+ }
+ case LspaIn:
+ state = State.BandwidthIn;
+ if (obj instanceof Bandwidth) {
+ builder.setBandwidth((Bandwidth) obj);
+ break;
+ }
+ case BandwidthIn:
+ state = State.MetricIn;
+ if (obj instanceof Metric) {
+ pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
+ state = State.MetricIn;
+ break;
+ }
+ case MetricIn:
+ state = State.IroIn;
+ if (obj instanceof Iro) {
+ builder.setIro((Iro) obj);
+ break;
+ }
+ case IroIn:
+ state = State.End;
+ break;
+ case End:
+ break;
+ }
+ if (!state.equals(State.End)) {
+ objects.remove(0);
+ }
+ }
+ builder.setMetrics(pathMetrics);
+ }
+
+ private void parsePath(final PathsBuilder builder, final List<Object> objects) {
+ final List<Metrics> pathMetrics = Lists.newArrayList();
+
+ Object obj;
+ State state = State.Init;
+ while (!objects.isEmpty() && !state.equals(State.End)) {
+ obj = objects.get(0);
+
+ switch (state) {
+ case Init:
+ state = State.LspaIn;
+ if (obj instanceof Lspa) {
+ builder.setLspa((Lspa) obj);
+ break;
+ }
+ case LspaIn:
+ state = State.OfIn;
+ if (obj instanceof Of) {
+ builder.setOf((Of) obj);
+ break;
+ }
+ case OfIn:
+ state = State.BandwidthIn;
+ if (obj instanceof Bandwidth) {
+ builder.setBandwidth((Bandwidth) obj);
+ break;
+ }
+ case BandwidthIn:
+ state = State.MetricIn;
+ if (obj instanceof Metric) {
+ pathMetrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
+ state = State.BandwidthIn;
+ break;
+ }
+ case MetricIn:
+ state = State.IroIn;
+ if (obj instanceof Iro) {
+ builder.setIro((Iro) obj);
+ break;
+ }
+ case IroIn:
+ state = State.End;
+ break;
+ case End:
+ break;
+ }
+ if (!state.equals(State.End)) {
+ objects.remove(0);
+ }
+ }
+ builder.setMetrics(pathMetrics);
+ }
+
+ private enum State {
+ Init, LspaIn, OfIn, BandwidthIn, MetricIn, IroIn, End
+ }
+
+ @Override
+ public int getMessageType() {
+ return TYPE;
+ }
+}
--- /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.impl.stateful02;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.List;
+
+import org.opendaylight.protocol.pcep.impl.message.AbstractMessageParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.P2p1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.P2p1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcreqBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.bandwidth.object.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.classtype.object.ClassType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObj;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Xro;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.gc.object.Gc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.include.route.object.Iro;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancing;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.PathKeyExpansionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.P2p;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.P2pBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+
+import com.google.common.collect.Lists;
+
+/**
+ * Parser for {@link Pcreq}
+ */
+public class PCEPRequestMessageParser extends AbstractMessageParser {
+
+ public static final int TYPE = 3;
+
+ public PCEPRequestMessageParser(final ObjectHandlerRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public void serializeMessage(final Message message, final ByteBuf buffer) {
+ if (!(message instanceof Pcreq)) {
+ throw new IllegalArgumentException("Wrong instance of PCEPMessage. Passed instance of " + message.getClass()
+ + ". Needed PcrepMessage.");
+ }
+ final PcreqMessage msg = ((Pcreq) message).getPcreqMessage();
+ if (msg.getRequests() == null || msg.getRequests().isEmpty()) {
+ throw new IllegalArgumentException("Requests cannot be null or empty.");
+ }
+ for (final Requests req : msg.getRequests()) {
+ buffer.writeBytes(serializeObject(req.getRp()));
+ if (req.getPathKeyExpansion() != null) {
+ buffer.writeBytes(serializeObject(req.getPathKeyExpansion().getPathKey()));
+ }
+ if (req.getSegmentComputation() != null) {
+ final SegmentComputation sc = req.getSegmentComputation();
+ if (sc.getP2p() != null) {
+ serializeP2P(buffer, sc.getP2p());
+ }
+ }
+ }
+ if (msg.getSvec() != null) {
+ for (final Svec s : msg.getSvec()) {
+ buffer.writeBytes(serializeObject(s.getSvec()));
+ if (s.getOf() != null) {
+ buffer.writeBytes(serializeObject(s.getOf()));
+ }
+ if (s.getGc() != null) {
+ buffer.writeBytes(serializeObject(s.getGc()));
+ }
+ if (s.getXro() != null) {
+ buffer.writeBytes(serializeObject(s.getXro()));
+ }
+ if (s.getMetric() != null) {
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.Metric m : s.getMetric()) {
+ buffer.writeBytes(serializeObject(m.getMetric()));
+ }
+ }
+ }
+ }
+ }
+
+ private void serializeP2P(final ByteBuf buffer, final P2p p2p) {
+ if (p2p.getEndpointsObj() != null) {
+ buffer.writeBytes(serializeObject(p2p.getEndpointsObj()));
+ }
+ if (p2p.getAugmentation(P2p1.class) != null && p2p.getAugmentation(P2p1.class).getLsp() != null) {
+ buffer.writeBytes(serializeObject(p2p.getAugmentation(P2p1.class).getLsp()));
+ }
+ if (p2p.getReportedRoute() != null) {
+ final ReportedRoute rr = p2p.getReportedRoute();
+ if (rr.getRro() != null) {
+ buffer.writeBytes(serializeObject(rr.getRro()));
+ }
+ if (rr.getBandwidth() != null) {
+ buffer.writeBytes(serializeObject(rr.getBandwidth()));
+ }
+ }
+ if (p2p.getLoadBalancing() != null) {
+ buffer.writeBytes(serializeObject(p2p.getLoadBalancing()));
+ }
+ if (p2p.getLspa() != null) {
+ buffer.writeBytes(serializeObject(p2p.getLspa()));
+ }
+ if (p2p.getBandwidth() != null) {
+ buffer.writeBytes(serializeObject(p2p.getBandwidth()));
+ }
+ if (p2p.getMetrics() != null) {
+ for (final Metrics m : p2p.getMetrics()) {
+ buffer.writeBytes(serializeObject(m.getMetric()));
+ }
+ }
+ if (p2p.getIro() != null) {
+ buffer.writeBytes(serializeObject(p2p.getIro()));
+ }
+ if (p2p.getRro() != null) {
+ buffer.writeBytes(serializeObject(p2p.getRro()));
+ }
+ if (p2p.getXro() != null) {
+ buffer.writeBytes(serializeObject(p2p.getXro()));
+ }
+ if (p2p.getOf() != null) {
+ buffer.writeBytes(serializeObject(p2p.getOf()));
+ }
+ if (p2p.getClassType() != null) {
+ buffer.writeBytes(serializeObject(p2p.getClassType()));
+ }
+ }
+
+ @Override
+ protected Message validate(
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object> objects,
+ final List<Message> errors) throws PCEPDeserializerException {
+ if (objects == null) {
+ throw new IllegalArgumentException("Passed list can't be null.");
+ }
+
+ final List<Requests> requests = Lists.newArrayList();
+ final List<Svec> svecList = Lists.newArrayList();
+ while (!objects.isEmpty()) {
+ final RequestsBuilder rBuilder = new RequestsBuilder();
+ Rp rpObj = null;
+ if (objects.get(0) instanceof Rp) {
+ rpObj = (Rp) objects.get(0);
+ objects.remove(0);
+ if (!rpObj.isProcessingRule()) {
+ errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET));
+ } else {
+ rBuilder.setRp(rpObj);
+ }
+ } else {
+ // if RP obj is missing return error only
+ errors.add(createErrorMsg(PCEPErrors.RP_MISSING));
+ return null;
+ }
+
+ // expansion
+ if (rpObj.isPathKey()) {
+ if (objects.get(0) instanceof PathKey) {
+ rBuilder.setPathKeyExpansion(new PathKeyExpansionBuilder().setPathKey((PathKey) objects.get(0)).build());
+ }
+ continue;
+ }
+
+ final P2pBuilder p2pBuilder = new P2pBuilder();
+
+ if (objects.get(0) instanceof EndpointsObj) {
+ final EndpointsObj ep = (EndpointsObj) objects.get(0);
+ objects.remove(0);
+ if (!ep.isProcessingRule()) {
+ errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, rpObj));
+ } else {
+ p2pBuilder.setEndpointsObj(ep);
+ }
+ } else {
+ errors.add(createErrorMsg(PCEPErrors.END_POINTS_MISSING, rpObj));
+ return null;
+ }
+ // p2p
+ if (!rpObj.isP2mp()) {
+ final SegmentComputation segm = getSegmentComputation(p2pBuilder, objects, errors, rpObj);
+ if (segm != null) {
+ rBuilder.setSegmentComputation(segm);
+ }
+ }
+ while (!objects.isEmpty()) {
+ final SvecBuilder sBuilder = new SvecBuilder();
+ final Svec svecComp = getValidSvec(sBuilder, objects);
+ if (svecComp == null) {
+ break;
+ }
+ svecList.add(svecComp);
+ }
+ requests.add(rBuilder.build());
+ }
+
+ final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
+ mBuilder.setRequests(requests);
+ if (!svecList.isEmpty()) {
+ mBuilder.setSvec(svecList);
+ }
+ return new PcreqBuilder().setPcreqMessage(mBuilder.build()).build();
+ }
+
+ private SegmentComputation getSegmentComputation(final P2pBuilder builder, final List<Object> objects, final List<Message> errors,
+ final Rp rp) {
+ final List<Metrics> metrics = Lists.newArrayList();
+
+ State state = State.Init;
+ while (!objects.isEmpty() && state != State.End) {
+ Object obj = objects.get(0);
+
+ switch (state) {
+ case Init:
+ state = State.LspIn;
+ if (obj instanceof Lsp) {
+ builder.addAugmentation(P2p1.class, new P2p1Builder().setLsp((Lsp) obj).build());
+ break;
+ }
+ case LspIn:
+ state = State.ReportedIn;
+ if (obj instanceof Rro) {
+ final ReportedRouteBuilder rrBuilder = new ReportedRouteBuilder();
+ rrBuilder.setRro((Rro) obj);
+ objects.remove(0);
+ obj = objects.get(0);
+ if (obj instanceof Bandwidth) {
+ rrBuilder.setBandwidth((Bandwidth) obj);
+ }
+ break;
+ }
+ case ReportedIn:
+ state = State.LoadBIn;
+ if (obj instanceof LoadBalancing) {
+ builder.setLoadBalancing((LoadBalancing) obj);
+ break;
+ }
+ case LoadBIn:
+ state = State.LspaIn;
+ if (obj instanceof Lspa) {
+ builder.setLspa((Lspa) obj);
+ break;
+ }
+ case LspaIn:
+ state = State.BandwidthIn;
+ if (obj instanceof Bandwidth) {
+ builder.setBandwidth((Bandwidth) obj);
+ break;
+ }
+ case BandwidthIn:
+ state = State.MetricIn;
+ if (obj instanceof Metric) {
+ metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
+ state = State.BandwidthIn;
+ break;
+ }
+ case MetricIn:
+ state = State.IroIn;
+ if (obj instanceof Iro) {
+ builder.setIro((Iro) obj);
+ break;
+ }
+ case IroIn:
+ state = State.RroIn;
+ if (obj instanceof Rro) {
+ builder.setRro((Rro) obj);
+ break;
+ }
+ case RroIn:
+ state = State.XroIn;
+ if (obj instanceof Xro) {
+ builder.setXro((Xro) obj);
+ break;
+ }
+ case XroIn:
+ state = State.OfIn;
+ if (obj instanceof Of) {
+ builder.setOf((Of) obj);
+ break;
+ }
+ case OfIn:
+ state = State.CtIn;
+ if (obj instanceof ClassType) {
+ final ClassType classType = (ClassType) obj;
+ if (!classType.isProcessingRule()) {
+ errors.add(createErrorMsg(PCEPErrors.P_FLAG_NOT_SET, rp));
+ } else {
+ builder.setClassType(classType);
+ }
+ break;
+ }
+ case CtIn:
+ state = State.End;
+ break;
+ case End:
+ break;
+ }
+ if (!state.equals(State.End)) {
+ objects.remove(0);
+ }
+ }
+ if (!metrics.isEmpty()) {
+ builder.setMetrics(metrics);
+ }
+
+ if (rp.isReoptimization()
+ && builder.getBandwidth() != null
+ && builder.getReportedRoute().getBandwidth().getBandwidth() != new BandwidthBuilder().setBandwidth(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth(new byte[] { 0 })).build()
+ && builder.getReportedRoute().getRro() == null) {
+ errors.add(createErrorMsg(PCEPErrors.RRO_MISSING, rp));
+ return null;
+ }
+ return new SegmentComputationBuilder().setP2p(builder.build()).build();
+ }
+
+ private enum State {
+ Init, LspIn, ReportedIn, LoadBIn, LspaIn, BandwidthIn, MetricIn, IroIn, RroIn, XroIn, OfIn, CtIn, End
+ }
+
+ private Svec getValidSvec(final SvecBuilder builder, final List<Object> objects) {
+ if (objects == null || objects.isEmpty()) {
+ throw new IllegalArgumentException("List cannot be null or empty.");
+ }
+
+ if (objects.get(0) instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) {
+ builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) objects.get(0));
+ objects.remove(0);
+ } else {
+ return null;
+ }
+
+ final List<Metrics> metrics = Lists.newArrayList();
+
+ Object obj = null;
+ SvecState state = SvecState.Init;
+ while (!objects.isEmpty() && !state.equals(SvecState.End)) {
+ obj = objects.get(0);
+
+ switch (state) {
+ case Init:
+ state = SvecState.OfIn;
+ if (obj instanceof Of) {
+ builder.setOf((Of) obj);
+ break;
+ }
+ case OfIn:
+ state = SvecState.GcIn;
+ if (obj instanceof Gc) {
+ builder.setGc((Gc) obj);
+ break;
+ }
+ case GcIn:
+ state = SvecState.XroIn;
+ if (obj instanceof Xro) {
+ builder.setXro((Xro) obj);
+ break;
+ }
+ case XroIn:
+ state = SvecState.MetricIn;
+ if (obj instanceof Metric) {
+ metrics.add(new MetricsBuilder().setMetric((Metric) obj).build());
+ state = SvecState.XroIn;
+ break;
+ }
+ case MetricIn:
+ state = SvecState.End;
+ break;
+ case End:
+ break;
+ }
+ if (!state.equals(SvecState.End)) {
+ objects.remove(0);
+ }
+ }
+ return builder.build();
+ }
+
+ private enum SvecState {
+ Init, OfIn, GcIn, XroIn, MetricIn, End
+ }
+
+ @Override
+ public int getMessageType() {
+ return TYPE;
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Pcrpt;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Pcupd;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.db.version.tlv.LspDbVersion;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.error.code.tlv.LspErrorCode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.identifiers.tlv.LspIdentifiers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.lsp.object.Lsp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.node.identifier.tlv.NodeIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.RsvpErrorSpec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
public class StatefulActivator extends AbstractPCEPExtensionProviderActivator {
@Override
new PCEPReportMessageParser(context.getObjectHandlerRegistry())));
regs.add(context.registerMessageSerializer(Pcrpt.class, new PCEPReportMessageParser(context.getObjectHandlerRegistry())));
+ regs.add(context.registerMessageParser(PCEPReplyMessageParser.TYPE, new PCEPReplyMessageParser(context.getObjectHandlerRegistry())));
+ regs.add(context.registerMessageSerializer(Pcrep.class, new PCEPReplyMessageParser(context.getObjectHandlerRegistry())));
+
+ regs.add(context.registerMessageParser(PCEPRequestMessageParser.TYPE,
+ new PCEPRequestMessageParser(context.getObjectHandlerRegistry())));
+ regs.add(context.registerMessageSerializer(Pcreq.class, new PCEPRequestMessageParser(context.getObjectHandlerRegistry())));
+
regs.add(context.registerObjectParser(PCEPLspObjectParser.TYPE, PCEPLspObjectParser.CLASS,
new PCEPLspObjectParser(context.getTlvHandlerRegistry())));
regs.add(context.registerObjectSerializer(Lsp.class, new PCEPLspObjectParser(context.getTlvHandlerRegistry())));
+ regs.add(context.registerObjectParser(PCEPOpenObjectParser.TYPE, PCEPOpenObjectParser.CLASS,
+ new PCEPOpenObjectParser(context.getTlvHandlerRegistry())));
+ regs.add(context.registerObjectSerializer(Open.class, new PCEPOpenObjectParser(context.getTlvHandlerRegistry())));
+
regs.add(context.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser()));
regs.add(context.registerTlvSerializer(Stateful.class, new PCEStatefulCapabilityTlvParser()));
regs.add(context.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser()));
regs.add(context.registerTlvSerializer(LspDbVersion.class, new LspDbVersionTlvParser()));
- regs.add(context.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser()));
- regs.add(context.registerTlvSerializer(LspErrorCode.class, new LspUpdateErrorTlvParser()));
+ regs.add(context.registerTlvParser(NodeIdentifierTlvParser.TYPE, new NodeIdentifierTlvParser()));
+ regs.add(context.registerTlvSerializer(NodeIdentifier.class, new NodeIdentifierTlvParser()));
regs.add(context.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser()));
regs.add(context.registerTlvSerializer(SymbolicPathName.class, new LspSymbolicNameTlvParser()));
- regs.add(context.registerTlvParser(LspIdentifierIpv4TlvParser.TYPE, new LspIdentifierIpv4TlvParser()));
- regs.add(context.registerTlvSerializer(LspIdentifiers.class, new LspIdentifierIpv4TlvParser()));
-
- regs.add(context.registerTlvParser(LspIdentifierIpv6TlvParser.TYPE, new LspIdentifierIpv6TlvParser()));
-
regs.add(context.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser()));
regs.add(context.registerTlvSerializer(RsvpErrorSpec.class, new RSVPErrorSpecTlvParser()));