--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.rsvp.parser.impl.subobject.AsNumberCaseParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for {@link AsNumberCase}
+ */
+public class EROAsNumberSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 32;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ return new SubobjectContainerBuilder().setLoose(loose).setSubobjectType(AsNumberCaseParser.parseSubobject
+ (buffer)).build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof AsNumberCase, "Unknown subobject instance. Passed %s. Needed AsNumberCase.", subobject.getSubobjectType().getClass());
+ final ByteBuf body = AsNumberCaseParser.serializeSubobject((AsNumberCase) subobject.getSubobjectType());
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectRegistry;
+import org.opendaylight.protocol.util.Values;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.ExrsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.ExrsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.Exrs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.ExrsBuilder;
+
+public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 33;
+
+ private static final int HEADER_LENGTH = 2;
+
+ private final XROSubobjectRegistry registry;
+
+ public EROExplicitExclusionRouteSubobjectParser(final XROSubobjectRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer> list = parseSubobject(buffer);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs> exrss = Lists.newArrayList();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer s : list) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
+ .subobjects.subobject.type.exrs._case.exrs.ExrsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
+ .subobjects.subobject.type.exrs._case.exrs.ExrsBuilder();
+ b.setAttribute(s.getAttribute());
+ b.setMandatory(s.isMandatory());
+ b.setSubobjectType(s.getSubobjectType());
+ exrss.add(b.build());
+ }
+ builder.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(exrss).build()).build());
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof ExrsCase, "Unknown subobject instance. Passed %s. Needed Exrs.", subobject.getSubobjectType().getClass());
+ final Exrs e = ((ExrsCase) subobject.getSubobjectType()).getExrs();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route
+ .object.exclude.route.object.SubobjectContainer> list = new ArrayList<>();
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs ex : e.getExrs()) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder();
+ b.setAttribute(ex.getAttribute());
+ b.setMandatory(ex.isMandatory());
+ b.setSubobjectType(ex.getSubobjectType());
+ list.add(b.build());
+ }
+ final ByteBuf body = Unpooled.buffer();
+ serializeSubobject(list, body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+
+ private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer> parseSubobject(
+ final ByteBuf buffer) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer> subs = new ArrayList<>();
+ while (buffer.isReadable()) {
+ final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false;
+ final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET);
+ final int length = buffer.readUnsignedByte() - HEADER_LENGTH;
+ if (length > buffer.readableBytes()) {
+ throw new RSVPParsingException("Wrong length specified. Passed: " + length + "; Expected: <= "
+ + buffer.readableBytes());
+ }
+ subs.add(this.registry.parseSubobject(type, buffer.readSlice(length), mandatory));
+ }
+ return subs;
+ }
+
+ private void serializeSubobject(
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer> subobjects, final ByteBuf body) {
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer subobject : subobjects) {
+ this.registry.serializeSubobject(subobject, body);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for {@link IpPrefixCase}
+ */
+public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 1;
+
+ private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
+
+ private static final int RESERVED = 1;
+
+ private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + RESERVED + 1;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ if (buffer.readableBytes() != CONTENT4_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
+ }
+ final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
+ final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer,
+ Ipv4Util.IP4_LENGTH), length)));
+ builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
+ final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
+ final IpPrefix prefix = specObj.getIpPrefix();
+ Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
+ if (prefix.getIpv6Prefix() != null) {
+ new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
+ } else {
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ body.writeZero(RESERVED);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for {@link IpPrefixCase}
+ */
+public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 2;
+
+ private static final int PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
+
+ private static final int RESERVED = 1;
+
+ private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + RESERVED + 1;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ if (buffer.readableBytes() != CONTENT_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
+ }
+ final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET);
+ final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer,
+ Ipv6Util.IPV6_LENGTH), length)));
+ builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
+ final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
+ final IpPrefix prefix = specObj.getIpPrefix();
+ final ByteBuf body = Unpooled.buffer();
+ Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+ writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+ body.writeZero(RESERVED);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.LabelRegistry;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.label._case.Label;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.label._case.LabelBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
+
+public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 3;
+
+ private static final int FLAGS_SIZE = 8;
+
+ private static final int C_TYPE_F_LENGTH = 1;
+
+ private static final int C_TYPE_F_OFFSET = FLAGS_SIZE / Byte.SIZE;
+
+ private static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
+
+ private static final int U_FLAG_OFFSET = 0;
+
+ private final LabelRegistry registry;
+
+ public EROLabelSubobjectParser(final LabelRegistry labelReg) {
+ this.registry = Preconditions.checkNotNull(labelReg);
+ }
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ if (buffer.readableBytes() < HEADER_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
+ + HEADER_LENGTH + ".");
+ }
+ final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
+ final short cType = buffer.readUnsignedByte();
+
+ final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
+ if (labelType == null) {
+ throw new RSVPParsingException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
+ }
+ final LabelBuilder builder = new LabelBuilder();
+ builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
+ builder.setLabelType(labelType);
+ return new SubobjectContainerBuilder().setLoose(loose).setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof LabelCase, "Unknown subobject instance. Passed %s. Needed LabelCase.", subobject.getSubobjectType().getClass());
+ final Label label = ((LabelCase) subobject.getSubobjectType()).getLabel();
+ final ByteBuf body = Unpooled.buffer();
+ this.registry.serializeLabel(label.isUniDirectional(), false, label.getLabelType(), body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonPathKeyParser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for { PathKey}
+ */
+public class EROPathKey128SubobjectParser extends CommonPathKeyParser implements EROSubobjectParser{
+
+ public static final int TYPE = 65;
+
+ protected static final int PCE128_ID_F_LENGTH = 16;
+
+ private static final int CONTENT128_LENGTH = 2 + PCE128_ID_F_LENGTH;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ if (buffer.readableBytes() != CONTENT128_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
+ + CONTENT128_LENGTH + ".");
+ }
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(parsePathKey(PCE128_ID_F_LENGTH, buffer)).build());
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonPathKeyParser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for {PathKey}
+ */
+public class EROPathKey32SubobjectParser extends CommonPathKeyParser implements EROSubobjectParser,
+ EROSubobjectSerializer {
+
+ public static final int TYPE = 64;
+
+ private static final int PCE_ID_F_LENGTH = 4;
+
+ private static final int CONTENT_LENGTH = 2 + PCE_ID_F_LENGTH;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ if (buffer.readableBytes() != CONTENT_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
+ + CONTENT_LENGTH + ".");
+ }
+
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(parsePathKey(PCE_ID_F_LENGTH, buffer)).build());
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
+ final ByteBuf body = serializePathKey(pk);
+ if (pk.getPceId().getBinary().length == PCE_ID_F_LENGTH) {
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ } else if (pk.getPceId().getBinary().length == EROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
+ EROSubobjectUtil.formatSubobject(EROPathKey128SubobjectParser.TYPE, subobject.isLoose(), body, buffer);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+
+/**
+ * Parser for {@link UnnumberedCase}
+ */
+public class EROUnnumberedInterfaceSubobjectParser extends CommonUnnumberedInterfaceSubobjectParser implements
+ EROSubobjectParser, EROSubobjectSerializer {
+
+ public static final int TYPE = 4;
+
+ private static final int RESERVED = 2;
+
+ private static final int CONTENT_LENGTH = 10;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ if (buffer.readableBytes() != CONTENT_LENGTH) {
+ throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
+ + CONTENT_LENGTH + ".");
+ }
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ buffer.skipBytes(RESERVED);
+ builder.setSubobjectType(parseUnnumeredInterface(buffer));
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
+ final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+ body.writeZero(RESERVED);
+ serializeUnnumeredInterface(((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(), body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.protection.subobject.ProtectionSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.BasicProtectionCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.BasicProtectionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.DynamicControlProtectionCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.basic.protection._case.BasicProtectionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.dynamic.control.protection._case.DynamicControlProtectionBuilder;
+
+public class SEROBasicProtectionSubobjectParser extends ProtectionCommonParser implements EROSubobjectParser, EROSubobjectSerializer {
+ public static final int TYPE = 37;
+ public static final Short CTYPE = 1;
+
+ @Override
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) throws RSVPParsingException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
+ builder.setLoose(loose);
+ //skip reserved
+ buffer.readByte();
+ final short cType = buffer.readUnsignedByte();
+ final ProtectionSubobject prot = parseCommonProtectionBody(cType, buffer);
+ if (cType == CTYPE) {
+ builder.setSubobjectType(new BasicProtectionCaseBuilder().setBasicProtection(new BasicProtectionBuilder()
+ .setProtectionSubobject(prot).build()).build());
+
+ } else if (cType == SERODynamicProtectionSubobjectParser.CTYPE) {
+ builder.setSubobjectType(new DynamicControlProtectionCaseBuilder().setDynamicControlProtection(
+ new DynamicControlProtectionBuilder().setProtectionSubobject(prot).build()).build());
+ }
+ return builder.build();
+ }
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof BasicProtectionCase, "Unknown " +
+ "subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType());
+ final ProtectionSubobject protObj = ((BasicProtectionCase) subobject.getSubobjectType()).getBasicProtection()
+ .getProtectionSubobject();
+ final ByteBuf body = Unpooled.buffer();
+ serializeBody(CTYPE, protObj, body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.rsvp.parser.impl.subobject.ero;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.protection.subobject.ProtectionSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.secondary.explicit.route.object.secondary.explicit.route.object.subobject.container.subobject.type.DynamicControlProtectionCase;
+
+/**
+ * Parser for {@link DynamicControlProtectionCase}
+ */
+public class SERODynamicProtectionSubobjectParser extends ProtectionCommonParser implements EROSubobjectSerializer {
+
+ public static final int TYPE = 37;
+ public static final Short CTYPE = 2;
+
+ @Override
+ public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof DynamicControlProtectionCase, "Unknown " +
+ "subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType());
+ final ProtectionSubobject protObj = ((DynamicControlProtectionCase) subobject.getSubobjectType())
+ .getDynamicControlProtection().getProtectionSubobject();
+ final ByteBuf body = Unpooled.buffer();
+ serializeBody(CTYPE, protObj, body);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ }
+
+}
\ No newline at end of file