*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.PathBinding;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.PathBindingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.path.binding.BindingTypeValue;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof PathBinding,
- "The TLV must be PathBinding type, but was %s", tlv.getClass());
+ checkArgument(tlv instanceof PathBinding, "The TLV must be PathBinding type, but was %s", tlv.getClass());
final PathBinding pTlv = (PathBinding) tlv;
final BindingTypeValue bindingTypeValue = pTlv.getBindingTypeValue();
- Preconditions.checkArgument(bindingTypeValue != null,
- "Missing Binding Value in Path Bidning TLV: %s", pTlv);
+ checkArgument(bindingTypeValue != null, "Missing Binding Value in Path Bidning TLV: %s", pTlv);
final ByteBuf body = Unpooled.buffer(MPLS_BINDING_LENGTH);
final PathBindingTlvCodec codec = BT_SERIALIZERS.get(bindingTypeValue.implementedInterface());
- Preconditions.checkArgument(codec != null,
- "Unsupported Path Binding Type: %s", bindingTypeValue.implementedInterface());
+ checkArgument(codec != null, "Unsupported Path Binding Type: %s", bindingTypeValue.implementedInterface());
codec.writeBinding(body, bindingTypeValue);
TlvUtil.formatTlv(TYPE, body, buffer);
@Override
void writeEntry(final ByteBuf buf, final BindingTypeValue bindingValue) {
- Preconditions.checkArgument(bindingValue instanceof MplsLabel, "bindingValue is not MplsLabel");
+ checkArgument(bindingValue instanceof MplsLabel, "bindingValue is not MplsLabel");
final MplsLabel mplsLabel = (MplsLabel) bindingValue;
- ByteBufWriteUtil.writeUnsignedInt(Uint32.valueOf(getMplsStackEntry(mplsLabel.getMplsLabel())), buf);
+ ByteBufUtils.write(buf, Uint32.valueOf(getMplsStackEntry(mplsLabel.getMplsLabel())));
}
@Override
@Override
void writeEntry(final ByteBuf buf, final BindingTypeValue bindingValue) {
- Preconditions.checkArgument(bindingValue instanceof MplsLabelEntry,
- "bindingValue is not MplsLabelEntry");
+ checkArgument(bindingValue instanceof MplsLabelEntry, "bindingValue is not MplsLabelEntry");
final MplsLabelEntry mplsEntry = (MplsLabelEntry) bindingValue;
final long entry = getMplsStackEntry(mplsEntry.getLabel())
| mplsEntry.getTrafficClass().toJava() << TC_SHIFT
| (mplsEntry.isBottomOfStack() ? 1 : 0) << S_SHIFT
| mplsEntry.getTimeToLive().toJava();
- ByteBufWriteUtil.writeUnsignedInt(Uint32.valueOf(entry), buf);
+ ByteBufUtils.write(buf, Uint32.valueOf(entry));
}
@Override
import static com.google.common.base.Preconditions.checkArgument;
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
}
checkArgument(buffer.readableBytes() == V4_LENGTH, "Length %s does not match LSP Identifiers Ipv4 tlv length.",
buffer.readableBytes());
- final Ipv4Builder builder = new Ipv4Builder();
- builder.setIpv4TunnelSenderAddress(Ipv4Util.noZoneAddressForByteBuf(buffer));
+ final Ipv4Builder builder = new Ipv4Builder()
+ .setIpv4TunnelSenderAddress(Ipv4Util.noZoneAddressForByteBuf(buffer));
final LspId lspId = new LspId(Uint32.valueOf(buffer.readUnsignedShort()));
final TunnelId tunnelId = new TunnelId(ByteBufUtils.readUint16(buffer));
builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.noZoneAddressForByteBuf(buffer)));
builder.setIpv4TunnelEndpointAddress(Ipv4Util.noZoneAddressForByteBuf(buffer));
final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
- return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
+ return new LspIdentifiersBuilder()
+ .setAddressFamily(afi)
+ .setLspId(lspId)
+ .setTunnelId(tunnelId)
+ .build();
}
@Override
checkArgument(ipv4.getIpv4TunnelSenderAddress() != null, "Ipv4TunnelSenderAddress is mandatory.");
writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
- writeShort(lsp.getLspId().getValue().shortValue(), body);
- checkArgument(lsp.getTunnelId() != null, "TunnelId is mandatory.");
- writeUnsignedShort(lsp.getTunnelId().getValue(), body);
+ body.writeShort(lsp.getLspId().getValue().shortValue());
+ final TunnelId tunnelId = lsp.getTunnelId();
+ checkArgument(tunnelId != null, "TunnelId is mandatory.");
+ ByteBufUtils.write(body, tunnelId.getValue());
checkArgument(ipv4.getIpv4ExtendedTunnelId() != null, "Ipv4ExtendedTunnelId is mandatory.");
writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
checkArgument(ipv4.getIpv4TunnelEndpointAddress() != null, "Ipv4TunnelEndpointAddress is mandatory.");
import static com.google.common.base.Preconditions.checkArgument;
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
checkArgument(ipv6.getIpv6TunnelSenderAddress() != null, "Ipv6TunnelSenderAddress is mandatory.");
writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
- checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
- writeShort(lsp.getLspId().getValue().shortValue(), body);
- checkArgument(lsp.getTunnelId() != null, "TunnelId is mandatory.");
- writeUnsignedShort(lsp.getTunnelId().getValue(), body);
+
+ final LspId lspId = lsp.getLspId();
+ checkArgument(lspId != null, "LspId is mandatory.");
+ body.writeShort(lspId.getValue().shortValue());
+ final TunnelId tunnelId = lsp.getTunnelId();
+ checkArgument(tunnelId != null, "TunnelId is mandatory.");
+ ByteBufUtils.write(body, tunnelId.getValue());
checkArgument(ipv6.getIpv6ExtendedTunnelId() != null, "Ipv6ExtendedTunnelId is mandatory.");
writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
checkArgument(ipv6.getIpv6TunnelEndpointAddress() != null, "Ipv6TunnelEndpointAddress is mandatory.");
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
+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.pcep.spi.PCEPDeserializerException;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
+ checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body);
+ ByteBufUtils.writeOrZero(body, ((LspErrorCode) tlv).getErrorCode());
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.ietf.stateful07;
+import static com.google.common.base.Preconditions.checkArgument;
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 io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
+ checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
final RsvpErrorSpec rsvp = (RsvpErrorSpec) tlv;
final ByteBuf body = Unpooled.buffer();
if (rsvp.getErrorType().implementedInterface().equals(RsvpCase.class)) {
}
private static UserCase parseUserError(final ByteBuf buffer) {
- final UserErrorBuilder error = new UserErrorBuilder();
- error.setEnterprise(new EnterpriseNumber(ByteBufUtils.readUint32(buffer)));
+ final UserErrorBuilder error = new UserErrorBuilder()
+ .setEnterprise(new EnterpriseNumber(ByteBufUtils.readUint32(buffer)));
error.setSubOrg(ByteBufUtils.readUint8(buffer));
final int errDescrLength = buffer.readUnsignedByte();
error.setValue(ByteBufUtils.readUint16(buffer));
}
private static void serializerUserError(final UserError ue, final ByteBuf body) {
- final byte[] desc = ue.getDescription() == null ? new byte[0]
- : ue.getDescription().getBytes(StandardCharsets.UTF_8);
+ final String description = ue.getDescription();
+ final byte[] desc = description == null ? new byte[0] : description.getBytes(StandardCharsets.UTF_8);
final ByteBuf userErrorBuf = Unpooled.buffer();
- Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory");
- writeUnsignedInt(ue.getEnterprise().getValue(), userErrorBuf);
- writeUnsignedByte(ue.getSubOrg(), userErrorBuf);
+ final EnterpriseNumber enterprise = ue.getEnterprise();
+ checkArgument(enterprise != null, "EnterpriseNumber is mandatory");
+ ByteBufUtils.write(userErrorBuf, enterprise.getValue());
+ ByteBufUtils.writeOrZero(userErrorBuf, ue.getSubOrg());
userErrorBuf.writeByte(desc.length);
- Preconditions.checkArgument(ue.getValue() != null, "Value is mandatory.");
- writeUnsignedShort(ue.getValue(), userErrorBuf);
+ ByteBufUtils.writeMandatory(userErrorBuf, ue.getValue(), "Value");
userErrorBuf.writeBytes(desc);
userErrorBuf.writeZero(TlvUtil.getPadding(desc.length, TlvUtil.PADDED_TO));
formatRSVPObject(USER_ERROR_CLASS_NUM, USER_ERROR_CLASS_TYPE, userErrorBuf, body);
flags.set(IN_PLACE, rsvp.getFlags().isInPlace());
flags.set(NOT_GUILTY, rsvp.getFlags().isNotGuilty());
final IpAddressNoZone node = rsvp.getNode();
- Preconditions.checkArgument(node != null, "Node is mandatory.");
+ checkArgument(node != null, "Node is mandatory.");
final ByteBuf rsvpObjBuf = Unpooled.buffer();
int type = 0;
if (node.getIpv4AddressNoZone() != null) {
writeIpv6Address(node.getIpv6AddressNoZone(), rsvpObjBuf);
}
flags.toByteBuf(rsvpObjBuf);
- Preconditions.checkArgument(rsvp.getCode() != null, "Code is mandatory.");
- writeUnsignedByte(rsvp.getCode(), rsvpObjBuf);
- Preconditions.checkArgument(rsvp.getValue() != null, "Value is mandatory.");
- writeUnsignedShort(rsvp.getValue(), rsvpObjBuf);
+ ByteBufUtils.writeMandatory(rsvpObjBuf, rsvp.getCode(), "Code");
+ ByteBufUtils.writeMandatory(rsvpObjBuf, rsvp.getValue(), "Value");
formatRSVPObject(RSVP_ERROR_CLASS_NUM, type, rsvpObjBuf, body);
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
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;
serializeFlags(srp, body);
final SrpIdNumber srpId = srp.getOperationId();
checkArgument(srpId != null, "SrpId is mandatory.");
- writeUnsignedInt(srpId.getValue(), body);
+ ByteBufUtils.write(body, srpId.getValue());
serializeTlvs(srp.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
}
public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
- if (tlvs == null) {
- return;
- }
- if (tlvs.getSymbolicPathName() != null) {
- serializeTlv(tlvs.getSymbolicPathName(), body);
- }
- if (tlvs.getPathSetupType() != null) {
- serializeTlv(tlvs.getPathSetupType(), body);
+ if (tlvs != null) {
+ if (tlvs.getSymbolicPathName() != null) {
+ serializeTlv(tlvs.getSymbolicPathName(), body);
+ }
+ if (tlvs.getPathSetupType() != null) {
+ serializeTlv(tlvs.getPathSetupType(), body);
+ }
}
}