*/
package org.opendaylight.protocol.pcep.lsp.setup.type01;
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
+import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
// http://tools.ietf.org/html/draft-sivabalan-pce-segment-routing-01#section-9.3
public static final int TYPE = 27;
+ private static final int CONTENT_LENGTH = 4;
private static final int PST_LENGTH = 1;
- private static final int OFFSET = 4 - PST_LENGTH;
+ private static final int OFFSET = CONTENT_LENGTH - PST_LENGTH;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkNotNull(tlv, "PathSetupType is mandatory.");
+ Preconditions.checkArgument(tlv != null && tlv instanceof PathSetupType, "PathSetupType is mandatory.");
final PathSetupType pstTlv = (PathSetupType) tlv;
- ByteBuf body = Unpooled.buffer();
+ ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(OFFSET);
- body.writeBoolean((pstTlv.isPst() != null) ? pstTlv.isPst() : false);
+ writeBoolean(pstTlv.isPst(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
package org.opendaylight.protocol.pcep.segment.routing02;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+
import com.google.common.base.Preconditions;
-import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.BitSet;
import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@Override
public void serializeSubobject(Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrEroSubobject, "Unknown subobject instance. Passed %s. Needed SrEroSubobject.", subobject.getSubobjectType().getClass());
+ Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrEroSubobject,
+ "Unknown subobject instance. Passed %s. Needed SrEroSubobject.", subobject.getSubobjectType()
+ .getClass());
final SrEroSubobject srEroSubobject = (SrEroSubobject) subobject.getSubobjectType();
final ByteBuf body = Unpooled.buffer(MINIMAL_LENGTH);
- body.writeByte(UnsignedBytes.checkedCast(srEroSubobject.getSidType().getIntValue()) << 4);
+ writeUnsignedByte((short)(srEroSubobject.getSidType().getIntValue() << 4), body);
final Flags flags = srEroSubobject.getFlags();
final BitSet bits = new BitSet();
- bits.set(M_FLAG_POSITION, flags.isM());
- bits.set(C_FLAG_POSITION, flags.isC());
- bits.set(S_FLAG_POSITION, flags.isS());
- bits.set(F_FLAG_POSITION, flags.isF());
- body.writeByte(ByteArray.bitSetToBytes(bits, FLAGS_OFFSET)[0]);
-
- if(srEroSubobject.getSid() != null) {
- body.writeInt(srEroSubobject.getSid().intValue());
+ if (flags != null) {
+ bits.set(M_FLAG_POSITION, flags.isM());
+ bits.set(C_FLAG_POSITION, flags.isC());
+ bits.set(S_FLAG_POSITION, flags.isS());
+ bits.set(F_FLAG_POSITION, flags.isF());
}
+ writeBitSet(bits, FLAGS_OFFSET, body);
+
+ writeUnsignedInt(srEroSubobject.getSid(), body);
final Nai nai = srEroSubobject.getNai();
- if(nai != null) {
+ if (nai != null) {
switch (srEroSubobject.getSidType()) {
case Ipv4NodeId:
- body.writeBytes(Ipv4Util.bytesForAddress(((IpNodeId)nai).getIpAddress().getIpv4Address()));
+ writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4Address(), body);
break;
case Ipv6NodeId:
- body.writeBytes(Ipv6Util.bytesForAddress(((IpNodeId)nai).getIpAddress().getIpv6Address()));
+ writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6Address(), body);
break;
case Ipv4Adjacency:
- body.writeBytes(Ipv4Util.bytesForAddress(((IpAdjacency)nai).getLocalIpAddress().getIpv4Address()));
- body.writeBytes(Ipv4Util.bytesForAddress(((IpAdjacency)nai).getRemoteIpAddress().getIpv4Address()));
+ writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4Address(), body);
+ writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4Address(), body);
break;
case Ipv6Adjacency:
- body.writeBytes(Ipv6Util.bytesForAddress(((IpAdjacency)nai).getLocalIpAddress().getIpv6Address()));
- body.writeBytes(Ipv6Util.bytesForAddress(((IpAdjacency)nai).getRemoteIpAddress().getIpv6Address()));
+ writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6Address(), body);
+ writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6Address(), body);
break;
case Unnumbered:
- final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency)nai;
- body.writeInt(unnumbered.getLocalNodeId().intValue());
- body.writeInt(unnumbered.getLocalInterfaceId().intValue());
- body.writeInt(unnumbered.getRemoteNodeId().intValue());
- body.writeInt(unnumbered.getRemoteInterfaceId().intValue());
+ final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalNodeId(), body);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getLocalInterfaceId(), body);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteNodeId(), body);
+ ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRemoteInterfaceId(), body);
break;
}
}
final long sid = buffer.readUnsignedInt();
srEroSubobjectBuilder.setSid(sid);
- if(sidType != null) {
+ if (sidType != null) {
switch (sidType) {
case Ipv4NodeId:
- srEroSubobjectBuilder.setNai(new IpNodeIdBuilder()
- .setIpAddress(new IpAddress(new Ipv4Address(Ipv4Util.addressForByteBuf(buffer)))).build());
+ srEroSubobjectBuilder.setNai(new IpNodeIdBuilder().setIpAddress(
+ new IpAddress(new Ipv4Address(Ipv4Util.addressForByteBuf(buffer)))).build());
break;
case Ipv6NodeId:
- srEroSubobjectBuilder.setNai(new IpNodeIdBuilder().setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build());
+ srEroSubobjectBuilder.setNai(new IpNodeIdBuilder().setIpAddress(
+ new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build());
break;
case Ipv4Adjacency:
- srEroSubobjectBuilder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)))
+ srEroSubobjectBuilder.setNai(new IpAdjacencyBuilder()
+ .setLocalIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer)))
.setRemoteIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build());
break;
case Ipv6Adjacency:
- srEroSubobjectBuilder.setNai(new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)))
+ srEroSubobjectBuilder.setNai(new IpAdjacencyBuilder()
+ .setLocalIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer)))
.setRemoteIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build());
break;
case Unnumbered:
*/
package org.opendaylight.protocol.pcep.segment.routing02;
-import com.google.common.base.Preconditions;
+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.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
public static final int TYPE = 26;
private static final int MSD_LENGTH = 1;
- private static final int OFFSET = 4 - MSD_LENGTH;
+ private static final int CONTENT_LENGTH = 4;
+ private static final int OFFSET = CONTENT_LENGTH - MSD_LENGTH;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkNotNull(tlv, "SrPceCapability is mandatory.");
- TlvUtil.formatTlv(TYPE, Unpooled.copyInt(((SrPceCapability) tlv).getMsd()), buffer);
+ Preconditions.checkArgument(tlv != null && tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
+ final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+ body.writerIndex(OFFSET);
+ writeUnsignedByte(((SrPceCapability) tlv).getMsd(), body);
+ TlvUtil.formatTlv(TYPE, body, buffer);
}
@Override