*/
package org.opendaylight.protocol.pcep.ietf.initiated00;
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+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 java.util.BitSet;
-
import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
if (srp.getAugmentation(Srp1.class) != null && srp.getAugmentation(Srp1.class).isRemove()) {
flags.set(REMOVE_FLAG, srp.getAugmentation(Srp1.class).isRemove());
}
- body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_SIZE));
- body.writeInt(srp.getOperationId().getValue().intValue());
+ writeBitSet(flags, FLAGS_SIZE, body);
+ Preconditions.checkArgument(srp.getOperationId() != null, "OperationId is mandatory.");
+ writeUnsignedInt(srp.getOperationId().getValue(), body);
serializeTlvs(srp.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.ietf.initiated00;
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+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.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "StatefulCapabilityTlv is mandatory.");
+ Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
final Stateful sct = (Stateful) tlv;
final ByteBuf body = Unpooled.buffer();
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
if (sct.isLspUpdateCapability() != null) {
flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
}
- body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+ writeBitSet(flags, FLAGS_F_LENGTH, body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "LspIdentifiersTlv is mandatory.");
+ Preconditions.checkArgument(tlv != null && tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
final LspIdentifiers lsp = (LspIdentifiers) tlv;
final AddressFamily afi = lsp.getAddressFamily();
final ByteBuf body = Unpooled.buffer();
new Stateful07LSPIdentifierIpv6TlvParser().serializeTlv(tlv, buffer);
}
final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
- body.writeBytes(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()));
- body.writeShort(lsp.getLspId().getValue().shortValue());
- body.writeShort(lsp.getTunnelId().getValue().shortValue());
- body.writeBytes(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()));
- body.writeBytes(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelEndpointAddress()));
+ Preconditions.checkArgument(ipv4.getIpv4TunnelSenderAddress() != null, "Ipv4TunnelSenderAddress is mandatory.");
+ writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
+ Preconditions.checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
+ writeShort(lsp.getLspId().getValue().shortValue(), body);
+ Preconditions.checkArgument(lsp.getTunnelId() != null, "TunnelId is mandatory.");
+ writeUnsignedShort(lsp.getTunnelId().getValue(), body);
+ Preconditions.checkArgument(ipv4.getIpv4ExtendedTunnelId() != null, "Ipv4ExtendedTunnelId is mandatory.");
+ writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
+ Preconditions.checkArgument(ipv4.getIpv4TunnelEndpointAddress() != null, "Ipv4TunnelEndpointAddress is mandatory.");
+ writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "LspIdentifiersTlv is mandatory.");
+ Preconditions.checkArgument(tlv != null && tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
final LspIdentifiers lsp = (LspIdentifiers) tlv;
final ByteBuf body = Unpooled.buffer();
final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
- body.writeBytes(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()));
- body.writeShort(lsp.getLspId().getValue().shortValue());
- body.writeShort(lsp.getTunnelId().getValue().shortValue());
- body.writeBytes(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()));
- body.writeBytes(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelEndpointAddress()));
+ Preconditions.checkArgument(ipv6.getIpv6TunnelSenderAddress() != null, "Ipv6TunnelSenderAddress is mandatory.");
+ writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
+ Preconditions.checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
+ writeShort(lsp.getLspId().getValue().shortValue(), body);
+ Preconditions.checkArgument(lsp.getTunnelId() != null, "TunnelId is mandatory.");
+ writeUnsignedShort(lsp.getTunnelId().getValue(), body);
+ Preconditions.checkArgument(ipv6.getIpv6ExtendedTunnelId() != null, "Ipv6ExtendedTunnelId is mandatory.");
+ writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
+ Preconditions.checkArgument(ipv6.getIpv6TunnelEndpointAddress() != null, "Ipv6TunnelEndpointAddress is mandatory.");
+ writeIpv6Address(ipv6.getIpv6TunnelEndpointAddress(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
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;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "SymbolicPathNameTlv is mandatory.");
- TlvUtil.formatTlv(TYPE, Unpooled.copiedBuffer(((SymbolicPathName) tlv).getPathName().getValue()), buffer);
+ Preconditions.checkArgument(tlv != null && tlv instanceof SymbolicPathName, "SymbolicPathNameTlv is mandatory.");
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName spn = ((SymbolicPathName) tlv).getPathName();
+ Preconditions.checkArgument(spn != null, "SymbolicPathName is mandatory");
+ TlvUtil.formatTlv(TYPE, Unpooled.copiedBuffer(spn.getValue()), buffer);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
-import com.google.common.base.Preconditions;
+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.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
public static final int TYPE = 20;
+ private static final int CONTENT_LENGTH = Integer.SIZE / Byte.SIZE;
+
@Override
public LspErrorCode parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "LspErrorCodeTlv is mandatory.");
- TlvUtil.formatTlv(TYPE, Unpooled.copyInt(((LspErrorCode) tlv).getErrorCode().intValue()), buffer);
+ Preconditions.checkArgument(tlv != null && tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
+ final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
+ writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body);
+ TlvUtil.formatTlv(TYPE, body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+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 static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
+
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
body.writeByte(USER_ERROR_CLASS_NUM);
body.writeByte(USER_ERROR_CLASS_TYPE);
- body.writeInt(ue.getEnterprise().getValue().intValue());
- body.writeByte(ue.getSubOrg());
+ Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory");
+ writeUnsignedInt(ue.getEnterprise().getValue(), body);
+ writeUnsignedByte(ue.getSubOrg(), body);
body.writeByte(desc.length);
- body.writeShort(ue.getValue().shortValue());
+ Preconditions.checkArgument(ue.getValue() != null, "Value is mandatory.");
+ writeUnsignedShort(ue.getValue(), body);
body.writeBytes(desc);
}
flags.set(IN_PLACE_FLAG_OFFSET, rsvp.getFlags().isInPlace());
flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
final IpAddress node = rsvp.getNode();
+ Preconditions.checkArgument(node != null, "Node is mandatory.");
if (node.getIpv4Address() != null) {
body.writeByte(RSVP_ERROR_CLASS_NUM);
body.writeByte(RSVP_IPV4_ERROR_CLASS_TYPE);
- body.writeBytes(Ipv4Util.bytesForAddress(node.getIpv4Address()));
+ writeIpv4Address(node.getIpv4Address(), body);
} else {
body.writeByte(RSVP_ERROR_CLASS_NUM);
body.writeByte(RSVP_IPV6_ERROR_CLASS_TYPE);
- body.writeBytes(Ipv6Util.bytesForAddress(node.getIpv6Address()));
+ writeIpv6Address(node.getIpv6Address(), body);
}
- body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
- body.writeByte(rsvp.getCode());
- body.writeShort(rsvp.getValue().shortValue());
+ writeBitSet(flags, FLAGS_F_LENGTH, body);
+ Preconditions.checkArgument(rsvp.getCode() != null, "Code is mandatory.");
+ writeUnsignedByte(rsvp.getCode(), body);
+ Preconditions.checkArgument(rsvp.getValue() != null, "Value is mandatory.");
+ writeUnsignedShort(rsvp.getValue(), body);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
-import com.google.common.base.Preconditions;
+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.pcep.spi.AbstractObjectWithTlvsParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
final Srp srp = (Srp) object;
final ByteBuf body = Unpooled.buffer();
body.writerIndex(body.writerIndex() + FLAGS_SIZE);
- final Long id = srp.getOperationId().getValue();
- body.writeInt(id.intValue());
+ final SrpIdNumber srpId = srp.getOperationId();
+ Preconditions.checkArgument(srpId != null, "SrpId is mandatory.");
+ writeUnsignedInt(srpId.getValue(), body);
serializeTlvs(srp.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
-import com.google.common.base.Preconditions;
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
+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.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv != null, "StatefulCapabilityTlv is mandatory.");
+ Preconditions.checkArgument(tlv != null && tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
final Stateful sct = (Stateful) tlv;
final ByteBuf body = Unpooled.buffer();
final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
if (sct.isLspUpdateCapability() != null) {
flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
}
- body.writeBytes(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH));
+ writeBitSet(flags, FLAGS_F_LENGTH, body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}