package org.opendaylight.protocol.rsvp.parser.impl.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final AsNumberSubobject asNumber = asCase.getAsNumber();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
- writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
+ body.writeShort(asNumber.getAsNumber().getValue().shortValue());
return body;
}
}
* 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.label;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
"Unknown Label Subobject instance. Passed %s. Needed Type1LabelCase.", subobject.getClass());
final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
- Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
- writeUnsignedInt(type1Label.getType1Label(), body);
+ checkArgument(type1Label != null, "Type1Label is mandatory.");
+ ByteBufUtils.writeOrZero(body, type1Label.getType1Label());
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.label;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
subobject.getClass());
final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
- writeUnsignedInt(obj.getWavebandId(), body);
- checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
- writeUnsignedInt(obj.getStartLabel(), body);
- checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
- writeUnsignedInt(obj.getEndLabel(), body);
+ ByteBufUtils.writeMandatory(body, obj.getWavebandId(), "WavebandId");
+ ByteBufUtils.writeMandatory(body, obj.getStartLabel(), "StartLabel");
+ ByteBufUtils.writeMandatory(body, obj.getEndLabel(), "EndLabel");
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
}
*/
package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class RROPathKey128SubobjectParser implements RROSubobjectParser {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
- body.writeBytes(pk.getPceId().getValue());
+
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
+ ByteBufUtils.write(body, pathKey.getValue());
+
+ final PceId pceId = pk.getPceId();
+ checkArgument(pceId != null, "PceId is mandatory.");
+ body.writeBytes(pceId.getValue());
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ 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 Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
- final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
- final PathKeyBuilder pBuilder = new PathKeyBuilder();
- pBuilder.setPceId(new PceId(pceId));
- pBuilder.setPathKey(new PathKey(pathKey));
- builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ return new SubobjectContainerBuilder()
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
-import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; " + "Expected: >" + CONTENT_LENGTH + ".");
}
- final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
- final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
- final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
- final PathKeyBuilder pBuilder = new PathKeyBuilder();
- pBuilder.setPceId(new PceId(pceId));
- pBuilder.setPathKey(new PathKey(pathKey));
- builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
- return builder.build();
+ return new SubobjectContainerBuilder()
+ .setSubobjectType(new PathKeyCaseBuilder()
+ .setPathKey(new PathKeyBuilder()
+ .setPathKey(new PathKey(ByteBufUtils.readUint16(buffer)))
+ .setPceId(new PceId(ByteArray.readBytes(buffer, PCE_ID_F_LENGTH)))
+ .build())
+ .build())
+ .build();
}
@Override
if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
}
- checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+
+ final PathKey pathKey = pk.getPathKey();
+ checkArgument(pathKey != null, "PathKey is mandatory.");
checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory.");
- writeUnsignedShort(pk.getPathKey().getValue(), body);
+ ByteBufUtils.write(body, pathKey.getValue());
body.writeBytes(pceId);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
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.UnnumberedSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.UnnumberedCase;
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
+ "Expected: " + CONTENT_LENGTH + ".");
}
- final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
- builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
- builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
- final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
buffer.skipBytes(RESERVED);
- ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
- ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
- builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
- return builder.build();
+ return new SubobjectContainerBuilder()
+ .setProtectionAvailable(flags.get(LPA_F_OFFSET))
+ .setProtectionInUse(flags.get(LPIU_F_OFFSET))
+ .setSubobjectType(new UnnumberedCaseBuilder()
+ .setUnnumbered(new UnnumberedBuilder()
+ .setRouterId(ByteBufUtils.readUint32(buffer))
+ .setInterfaceId(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build())
+ .build();
}
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
- "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
- subobject.getSubobjectType().getClass());
- final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
+ final SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
+ type.getClass());
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
flags.toByteBuf(body);
body.writeZero(RESERVED);
- checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
- writeUnsignedInt(specObj.getRouterId(), body);
- checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
- writeUnsignedInt(specObj.getInterfaceId(), body);
+
+ final UnnumberedSubobject specObj = ((UnnumberedCase) type).getUnnumbered();
+ ByteBufUtils.writeMandatory(body, specObj.getRouterId(), "RouterId");
+ ByteBufUtils.writeMandatory(body, specObj.getInterfaceId(), "InterfaceId");
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
* 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.xro;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
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.SubobjectType;
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;
public static final int TYPE = 1;
private static final int PREFIX_F_LENGTH = 1;
-
private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setMandatory(mandatory);
if (buffer.readableBytes() != CONTENT4_LENGTH) {
@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 SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
+ type.getClass());
+ final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
+ checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
"Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
if (prefix.getIpv6Prefix() != null) {
new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
} else {
final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
+ checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+ body.writeByte(subobject.getAttribute().getIntValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
* 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.xro;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
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.SubobjectType;
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;
* Parser for {@link IpPrefixCase}.
*/
public class XROIpv6PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
-
public static final int TYPE = 2;
private static final int PREFIX_F_LENGTH = 1;
-
private static final int PREFIX6_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
private static final int CONTENT6_LENGTH = PREFIX6_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setMandatory(mandatory);
if (buffer.readableBytes() != CONTENT6_LENGTH) {
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ final SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof IpPrefixCase,
"Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
- subobject.getSubobjectType().getClass());
- final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
+ type.getClass());
+ final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
+ checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
writeIpv6Prefix(prefix.getIpv6Prefix(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
+ checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+ body.writeByte(subobject.getAttribute().getIntValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.xro;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.SrlgCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.srlg._case.SrlgBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
-import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
/**
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- checkArgument(subobject.getSubobjectType() instanceof SrlgCase,
- "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
- final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
+ final SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.",
+ type.getClass());
+ final SrlgSubobject specObj = ((SrlgCase) type).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
- writeUnsignedInt(specObj.getSrlgId().getValue(), body);
- checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- writeUnsignedByte((Uint8) null, body);
- writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
+
+ final SrlgId srlgId = specObj.getSrlgId();
+ checkArgument(srlgId != null, "SrlgId is mandatory.");
+ ByteBufUtils.write(body, srlgId.getValue());
+
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(0);
+ body.writeByte(attribute.getIntValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
* 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.xro;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.CommonUnnumberedInterfaceSubobjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
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.exclude.route.object.exclude.route.object.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder;
* Parser for {@link UnnumberedCase}.
*/
public class XROUnnumberedInterfaceSubobjectParser extends CommonUnnumberedInterfaceSubobjectParser
- implements XROSubobjectParser, XROSubobjectSerializer {
+ implements XROSubobjectParser, XROSubobjectSerializer {
public static final int TYPE = 4;
private static final int RESERVED = 1;
-
private static final int CONTENT_LENGTH = 10;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ 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 + ".");
}
buffer.readerIndex(buffer.readerIndex() + RESERVED);
- final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
- builder.setMandatory(mandatory);
- builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
- builder.setSubobjectType(parseUnnumeredInterface(buffer));
- return builder.build();
+ return new SubobjectContainerBuilder()
+ .setMandatory(mandatory)
+ .setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()))
+ .setSubobjectType(parseUnnumeredInterface(buffer))
+ .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 SubobjectType type = subobject.getSubobjectType();
+ checkArgument(type instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
+ type.getClass());
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(RESERVED);
- writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null,
- body);
- serializeUnnumeredInterface(((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(), body);
+
+ final Attribute attribute = subobject.getAttribute();
+ body.writeByte(attribute != null ? attribute.getIntValue() : 0);
+ serializeUnnumeredInterface(((UnnumberedCase) type).getUnnumbered(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
*/
package org.opendaylight.protocol.rsvp.parser.impl.te;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof FlowSpecObject, "SenderTspecObject is mandatory.");
+ checkArgument(teLspObject instanceof FlowSpecObject, "SenderTspecObject is mandatory.");
final FlowSpecObject flowObj = (FlowSpecObject) teLspObject;
final int sHeader = flowObj.getServiceHeader().getIntValue();
if (sHeader == 2) {
writeFloat32(tSpec.getTokenBucketRate(), output);
writeFloat32(tSpec.getTokenBucketSize(), output);
writeFloat32(tSpec.getPeakDataRate(), output);
- writeUnsignedInt(tSpec.getMinimumPolicedUnit(), output);
- writeUnsignedInt(tSpec.getMaximumPacketSize(), output);
+ ByteBufUtils.writeOrZero(output, tSpec.getMinimumPolicedUnit());
+ ByteBufUtils.writeOrZero(output, tSpec.getMaximumPacketSize());
if (sHeader != 2) {
return;
output.writeByte(0);
output.writeShort(PARAMETER_130_LENGTH);
writeFloat32(flowObj.getRate(), output);
- writeUnsignedInt(flowObj.getSlackTerm(), output);
+ ByteBufUtils.writeOrZero(output, flowObj.getSlackTerm());
}
}
import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
writeFloat32(tspecObj.getTokenBucketRate(), output);
writeFloat32(tspecObj.getTokenBucketSize(), output);
writeFloat32(tspecObj.getPeakDataRate(), output);
- writeUnsignedInt(tspecObj.getMinimumPolicedUnit(), output);
- writeUnsignedInt(tspecObj.getMaximumPacketSize(), output);
+ ByteBufUtils.writeOrZero(output, tspecObj.getMinimumPolicedUnit());
+ ByteBufUtils.writeOrZero(output, tspecObj.getMaximumPacketSize());
}
}