--- /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.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+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.pcc.id.req.object.PccIdReq;
+
+public abstract class AbstractPccIdReqObjectParser implements ObjectSerializer, ObjectParser {
+ public static final int CLASS = 20;
+
+ public static final int IPV4_TYPE = 1;
+ public static final int IPV6_TYPE = 2;
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof PccIdReq, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+ final PccIdReq pccIdReq = (PccIdReq) object;
+ if (pccIdReq.getIpAddress().getIpv4Address() != null) {
+ final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
+ ByteBufWriteUtil.writeIpv4Address(pccIdReq.getIpAddress().getIpv4Address(), body);
+ ObjectUtil.formatSubobject(IPV4_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ } else if (pccIdReq.getIpAddress().getIpv6Address() != null) {
+ final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
+ ByteBufWriteUtil.writeIpv6Address(pccIdReq.getIpAddress().getIpv6Address(), body);
+ ObjectUtil.formatSubobject(IPV6_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+ }
+}
--- /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.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+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.pce.id.object.PceId;
+
+public abstract class AbstractPceIdObjectParser implements ObjectParser, ObjectSerializer {
+
+ public static final int CLASS = 25;
+
+ public static final int IPV4_TYPE = 1;
+ public static final int IPV6_TYPE = 2;
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof PceId, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+ final PceId pceId = (PceId) object;
+ if (pceId.getIpAddress().getIpv4Address() != null) {
+ final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
+ ByteBufWriteUtil.writeIpv4Address(pceId.getIpAddress().getIpv4Address(), body);
+ ObjectUtil.formatSubobject(IPV4_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ } else if (pceId.getIpAddress().getIpv6Address() != null) {
+ final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
+ ByteBufWriteUtil.writeIpv6Address(pceId.getIpAddress().getIpv6Address(), body);
+ ObjectUtil.formatSubobject(IPV6_TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+ }
+
+}
--- /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.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.BitSet;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
+import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
+
+/**
+ * Parser for {@link Monitoring}
+ * @see https://tools.ietf.org/html/rfc5886#section-4.1
+ */
+public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<TlvsBuilder> {
+
+ public static final int CLASS = 19;
+
+ public static final int TYPE = 1;
+
+ private static final int FLAGS = 3;
+ private static final int RESERVED = 1;
+ private static final int L_FLAG_POS = 23;
+ private static final int G_FLAG_POS = 22;
+ private static final int P_FLAG_POS = 21;
+ private static final int C_FLAG_POS = 20;
+ private static final int I_FLAG_POS = 19;
+
+ public PCEPMonitoringObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
+ super(tlvReg, viTlvReg);
+ }
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final MonitoringBuilder builder = new MonitoringBuilder();
+ buffer.readBytes(RESERVED);
+ final BitSet flagBits = ByteArray.bytesToBitSet(buffer.readBytes(FLAGS).array());
+ final Flags flags = new Flags(flagBits.get(G_FLAG_POS), flagBits.get(I_FLAG_POS), flagBits.get(L_FLAG_POS),
+ flagBits.get(C_FLAG_POS), flagBits.get(P_FLAG_POS));
+ builder.setFlags(flags);
+ builder.setMonitoringId(buffer.readUnsignedInt());
+ final TlvsBuilder tbuilder = new TlvsBuilder();
+ parseTlvs(tbuilder, buffer.slice());
+ builder.setTlvs(tbuilder.build());
+ return builder.build();
+ }
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof Monitoring, "Wrong instance of PCEPObject. Passed %s. Needed MonitoringObject.", object.getClass());
+ final Monitoring monitoring = (Monitoring) object;
+ final ByteBuf body = Unpooled.buffer();
+ body.writeZero(RESERVED);
+ final Flags flags = monitoring.getFlags();
+ final BitSet flagBits = new BitSet(FLAGS);
+ flagBits.set(I_FLAG_POS, flags.isIncomplete());
+ flagBits.set(C_FLAG_POS, flags.isOverload());
+ flagBits.set(P_FLAG_POS, flags.isProcessingTime());
+ flagBits.set(G_FLAG_POS, flags.isGeneral());
+ flagBits.set(L_FLAG_POS, flags.isLiveness());
+ ByteBufWriteUtil.writeBitSet(flagBits, FLAGS, body);
+ ByteBufWriteUtil.writeUnsignedInt(monitoring.getMonitoringId(), body);
+ serializeTlvs(monitoring.getTlvs(), body);
+ ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+
+ @Override
+ protected void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
+ if (!tlvs.isEmpty()) {
+ builder.setVendorInformationTlv(tlvs);
+ }
+ }
+
+ public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
+ if (tlvs == null) {
+ return;
+ }
+ serializeVendorInformationTlvs(tlvs.getVendorInformationTlv(), body);
+ }
+
+}
--- /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.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
+
+public class PCEPOverloadObjectParser implements ObjectParser, ObjectSerializer {
+
+ public static final int CLASS = 27;
+
+ public static final int TYPE = 1;
+
+ private static final int RESERVED = 1;
+ private static final int FLAGS = RESERVED;
+ private static final int BODY_SIZE = RESERVED + FLAGS + ByteBufWriteUtil.SHORT_BYTES_LENGTH;
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof Overload, "Wrong instance of PCEPObject. Passed %s. Needed OverloadObject.", object.getClass());
+ final Overload overload = (Overload) object;
+ final ByteBuf body = Unpooled.buffer(BODY_SIZE);
+ body.writeZero(RESERVED + FLAGS);
+ ByteBufWriteUtil.writeUnsignedShort(overload.getDuration(), body);
+ ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final OverloadBuilder builder = new OverloadBuilder();
+ buffer.readBytes(RESERVED + FLAGS);
+ builder.setDuration(buffer.readUnsignedShort());
+ return 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.impl.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.pcc.id.req.object.PccIdReqBuilder;
+
+/**
+ * Parser for {@link PccId} with IPv4 address
+ * @see https://tools.ietf.org/html/rfc5886#section-4.2
+ */
+public class PCEPPccIdReqIPv4ObjectParser extends AbstractPccIdReqObjectParser {
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final PccIdReqBuilder builder = new PccIdReqBuilder();
+ builder.setIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)));
+ return 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.impl.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.pcc.id.req.object.PccIdReqBuilder;
+
+/**
+ * Parser for {@link PccId} with IPv6 address
+ * @see https://tools.ietf.org/html/rfc5886#section-4.2
+ */
+public class PCEPPccIdReqIPv6ObjectParser extends AbstractPccIdReqObjectParser {
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final PccIdReqBuilder builder = new PccIdReqBuilder();
+ builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)));
+ return 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.impl.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.pce.id.object.PceIdBuilder;
+
+/**
+ * Parser for {@link PceId} with IPv4 address
+ * @see https://tools.ietf.org/html/rfc5886#section-4.3
+ */
+public class PCEPPceIdIPv4ObjectParser extends AbstractPceIdObjectParser {
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final PceIdBuilder builder = new PceIdBuilder();
+ builder.setIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)));
+ return 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.impl.object;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+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.pce.id.object.PceIdBuilder;
+
+/**
+ * Parser for {@link PceId} with IPv6 address
+ * @see https://tools.ietf.org/html/rfc5886#section-4.3
+ */
+public class PCEPPceIdIPv6ObjectParser extends AbstractPceIdObjectParser {
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final PceIdBuilder builder = new PceIdBuilder();
+ builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)));
+ return 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.impl.object;
+
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.BitSet;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.proc.time.object.ProcTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
+
+/**
+ * Parser for {@link ProcTime}
+ * @see https://tools.ietf.org/html/rfc5886#section-4.4
+ */
+public class PCEPProcTimeObjectParser implements ObjectParser, ObjectSerializer {
+
+ public static final int CLASS = 26;
+
+ public static final int TYPE = 1;
+
+ private static final int RESERVED = 2;
+ private static final int FLAGS = RESERVED;
+ private static final int BODY_SIZE = RESERVED + FLAGS + 5 * INT_BYTES_LENGTH;
+ private static final int E_FLAG_POSITION = 15;
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof ProcTime, "Wrong instance of PCEPObject. Passed %s. Needed ProcTimeObject.", object.getClass());
+ final ProcTime procTime = (ProcTime) object;
+ final ByteBuf body = Unpooled.buffer(BODY_SIZE);
+ body.writeZero(RESERVED);
+ final BitSet flagBits = new BitSet(FLAGS * Byte.SIZE);
+ flagBits.set(E_FLAG_POSITION, procTime.isEstimated());
+ ByteBufWriteUtil.writeBitSet(flagBits, FLAGS, body);
+ ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
+ ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
+ ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
+ ByteBufWriteUtil.writeUnsignedInt(procTime.getAverageProcTime(), body);
+ ByteBufWriteUtil.writeUnsignedInt(procTime.getVarianceProcTime(), body);
+ ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+
+ @Override
+ public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final ProcTimeBuilder builder = new ProcTimeBuilder();
+ buffer.readBytes(RESERVED);
+ final BitSet flagBits = ByteArray.bytesToBitSet(buffer.readBytes(FLAGS).array());
+ builder.setEstimated(flagBits.get(E_FLAG_POSITION));
+ builder.setCurrentProcTime(buffer.readUnsignedInt());
+ builder.setMinProcTime(buffer.readUnsignedInt());
+ builder.setMaxProcTime(buffer.readUnsignedInt());
+ builder.setAverageProcTime(buffer.readUnsignedInt());
+ builder.setVarianceProcTime(buffer.readUnsignedInt());
+ return builder.build();
+ }
+
+}
import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMonitoringObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPOverloadObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPProcTimeObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
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.order.tlv.OrderBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKeyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeys;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.path.key.PathKeysBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.error.object.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPathBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.RroBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
parser.serializeObject(viObj, buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
+
+ @Test
+ public void testMonitoringObject() throws PCEPDeserializerException {
+ final byte[] monitoringBytes = {
+ /* object header */
+ 0x13, 0x10, 0x00, 0x0C,
+ /* flags */
+ 0x00, 0x00, 0x00, 0x01,
+ /* monitoring-id=16 */
+ 0x00, 0x00, 0x00, 0x10
+ };
+ final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry);
+ final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L).setFlags(new Flags(false, false, true, false, false)).setTlvs(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes);
+ assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(monitoringBytes.length);
+ parser.serializeObject(monitoring, buf);
+ assertArrayEquals(monitoringBytes, buf.array());
+ }
+
+ @Test
+ public void testPccIdReqIPv4Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x14, 0x10, 0x00, 0x08,
+ /* ipv4 address */
+ 0x7f, 0x00, 0x00, 0x01
+ };
+ final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser();
+ final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPccIdReqIPv6Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x14, 0x20, 0x00, 0x14,
+ /* ipv6 address */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01
+ };
+ final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser();
+ final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPceIdIPv4Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x19, 0x10, 0x00, 0x08,
+ /* ipv4 address */
+ 0x7f, 0x00, 0x00, 0x01
+ };
+ final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder().setIpAddress(new IpAddress(
+ new Ipv4Address("127.0.0.1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pceId, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testPceIdIPv6Object() throws PCEPDeserializerException {
+ final byte[] pccIdReqBytes = {
+ /* object header */
+ 0x19, 0x20, 0x00, 0x14,
+ /* ipv6 header */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01
+ };
+ final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder().setIpAddress(new IpAddress(
+ new Ipv6Address("::1"))).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes);
+ assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length);
+ parser.serializeObject(pccIdReq, buf);
+ assertArrayEquals(pccIdReqBytes, buf.array());
+ }
+
+ @Test
+ public void testProcTimeObject() throws PCEPDeserializerException {
+ final byte[] proctimeBytes = {
+ /* object header */
+ 0x1A, 0x10, 0x00, 0x1C,
+ /* E flag */
+ 0x00, 0x00, 0x00, 0x01,
+ /* current proc. time */
+ 0x00, 0x00, 0x00, 0x01,
+ /* min proc. time */
+ 0x00, 0x00, 0x00, 0x02,
+ /* max proc time */
+ 0x00, 0x00, 0x00, 0x03,
+ /* average proc time */
+ 0x00, 0x00, 0x00, 0x04,
+ /* variance proc time */
+ 0x00, 0x00, 0x00, 0x05,
+ };
+ final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser();
+ final ProcTime procTime = new ProcTimeBuilder()
+ .setEstimated(true)
+ .setAverageProcTime(4L)
+ .setCurrentProcTime(1L)
+ .setMaxProcTime(3L)
+ .setMinProcTime(2L)
+ .setVarianceProcTime(5L).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes);
+ assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(proctimeBytes.length);
+ parser.serializeObject(procTime, buf);
+ assertArrayEquals(proctimeBytes, buf.array());
+ }
+
+ @Test
+ public void testOverloadObject() throws PCEPDeserializerException {
+ final byte[] overloadBytes = {
+ /* object header */
+ 0x1B, 0x10, 0x00, 0x08,
+ /* overload duration */
+ 0x00, 0x00, 0x00, 0x78
+ };
+ final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser();
+ final Overload overload = new OverloadBuilder().setDuration(120).build();
+ final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes);
+ assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
+
+ final ByteBuf buf = Unpooled.buffer(overloadBytes.length);
+ parser.serializeObject(overload, buf);
+ assertArrayEquals(overloadBytes, buf.array());
+ }
}