* @author Claudio D. Gasparini
*/
public final class IpAddressUtil {
- private static final int ZERO_BYTE = 1;
-
private IpAddressUtil() {
throw new UnsupportedOperationException();
}
body.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
body.writeBytes(Ipv6Util.bytesForAddress(address.getIpv6Address()));
} else {
- body.writeZero(ZERO_BYTE);
+ body.writeByte(0);
}
return body;
}
} else if (address.getIpv6Address() != null) {
body.writeBytes(Ipv6Util.bytesForAddress(address.getIpv6Address()));
} else {
- body.writeZero(ZERO_BYTE);
+ body.writeByte(0);
}
return body;
}
final AsGenerated asGen = ((AsGeneratedCase) esi).getAsGenerated();
writeUnsignedInt(asGen.getAs().getValue(), body);
writeUnsignedInt(asGen.getLocalDiscriminator(), body);
- return body.writeZero(ZERO_BYTE);
+ return body.writeByte(0);
}
@Override
abstract class AbstractEsiType implements EsiParser, EsiSerializer {
private static final int BODY_LENGTH = 9;
- static final int ZERO_BYTE = 1;
static final int MAC_ADDRESS_LENGTH = 6;
@Override
final LacpAutoGenerated lacp = ((LacpAutoGeneratedCase) esi).getLacpAutoGenerated();
body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lacp.getCeLacpMacAddress()));
ByteBufWriteUtil.writeUnsignedShort(lacp.getCeLacpPortKey(), body);
- return body.writeZero(ZERO_BYTE);
+ return body.writeByte(0);
}
@Override
final LanAutoGenerated lan = ((LanAutoGeneratedCase) esi).getLanAutoGenerated();
body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lan.getRootBridgeMacAddress()));
ByteBufWriteUtil.writeUnsignedShort(lan.getRootBridgePriority(), body);
- return body.writeZero(ZERO_BYTE);
+ return body.writeByte(0);
}
@Override
final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
ByteBufWriteUtil.writeIpv4Address(routerID.getRouterId(), body);
ByteBufWriteUtil.writeUnsignedInt(routerID.getLocalDiscriminator(), body);
- return body.writeZero(ZERO_BYTE);
+ return body.writeByte(0);
}
@Override
static final int MAC_ADDRESS_LENGTH = 6;
static final int ESI_SIZE = 10;
private static final NodeIdentifier ESI_NID = NodeIdentifier.create(Esi.QNAME);
- static final int ZERO_BYTE = 1;
@Override
public final ByteBuf serializeEvpn(final EvpnChoice evpn, final ByteBuf common) {
body.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
body.writeBytes(Ipv6Util.bytesForAddress(ipAddress.getIpv6Address()));
} else {
- body.writeZero(ZERO_BYTE);
+ body.writeByte(0);
}
} else {
- body.writeZero(ZERO_BYTE);
+ body.writeByte(0);
}
return body;
}
output.writeByte(IPV6_BITS_LENGTH);
ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), prefixBuf);
}
+ // FIXME: remove this funky loop
while (prefixBuf.readableBytes() % 8 != 0) {
- prefixBuf.writeZero(1);
+ prefixBuf.writeByte(0);
}
output.writeBytes(prefixBuf);
}
public static final int TYPE = 2;
- private static final int WITHDRAWN_ROUTES_LENGTH_SIZE = 2;
-
- private static final int TOTAL_PATH_ATTR_LENGTH_SIZE = 2;
-
private final AttributeRegistry attrReg;
private final NlriRegistry nlriReg;
messageBody.writeShort(withdrawnRoutesBuf.writerIndex());
messageBody.writeBytes(withdrawnRoutesBuf);
} else {
- messageBody.writeZero(WITHDRAWN_ROUTES_LENGTH_SIZE);
+ messageBody.writeShort(0);
}
if (update.getAttributes() != null) {
final ByteBuf pathAttributesBuf = Unpooled.buffer();
messageBody.writeShort(pathAttributesBuf.writerIndex());
messageBody.writeBytes(pathAttributesBuf);
} else {
- messageBody.writeZero(TOTAL_PATH_ATTR_LENGTH_SIZE);
+ messageBody.writeShort(0);
}
final List<Nlri> nlris = update.getNlri();
if (nlris != null) {
if (t.getAfiFlags() != null && t.getAfiFlags().isForwardingState()) {
bytes.writeByte(AFI_FLAG_FORWARDING_STATE);
} else {
- bytes.writeZero(1);
+ bytes.writeByte(0);
}
}
}
if (table.getAfiFlags() != null && table.getAfiFlags().isForwardingState()) {
buffer.writeByte(AFI_FLAG_FORWARDING_STATE);
} else {
- buffer.writeZero(1);
+ buffer.writeByte(0);
}
final Uint24 staleTime = table.getLongLivedStaleTime();
final int timeval = staleTime != null ? staleTime.getValue().intValue() : 0;
final class SimpleNlriRegistry implements NlriRegistry {
private static final int RESERVED = 1;
- private static final int NEXT_HOP_LENGHT = 1;
private static final String PARSER_NOT_FOUND = "Nlri parser not found for table type {}";
private static final Logger LOG = LoggerFactory.getLogger(SimpleNlriRegistry.class);
byteAggregator.writeBytes(nextHopBuffer);
} else {
- byteAggregator.writeZero(NEXT_HOP_LENGHT);
+ byteAggregator.writeByte(0);
}
byteAggregator.writeZero(RESERVED);
}
if (peerHeader.getTimestampSec() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampSec().getValue(), output);
} else {
- output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ output.writeInt(0);
}
if (peerHeader.getTimestampMicro() != null) {
ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampMicro().getValue(), output);
} else {
- output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
+ output.writeInt(0);
}
}
public static final int TYPE = 6;
private static final int CONTENT_LENGTH = 2;
@VisibleForTesting
- static P2mpPceCapability P2MP_CAPABILITY = new P2mpPceCapabilityBuilder().build();
+ static final P2mpPceCapability P2MP_CAPABILITY = new P2mpPceCapabilityBuilder().build();
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof P2mpPceCapability, "P2mpPceCapability is mandatory.");
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- body.writeZero(2);
+ body.writeShort(0);
TlvUtil.formatTlv(TYPE, body, buffer);
}
final BitArray reflect = new BitArray(FLAGS_SIZE);
reflect.set(REFLECT, addObject.isReflect());
reflect.toByteBuf(output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(TESTING, addObject.isTesting());
flags.set(DOWN, addObject.isAdministrativelyDown());
final int sHeader = flowObj.getServiceHeader().getIntValue();
if (sHeader == 2) {
serializeAttributeHeader(BODY_SIZE_REQUESTING, CLASS_NUM, CTYPE, output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
output.writeShort(REQUESTING_OVERALL_LENGTH);
} else {
serializeAttributeHeader(BODY_SIZE_CONTROLLED, CLASS_NUM, CTYPE, output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
output.writeShort(CONTROLLER_OVERALL_LENGHT);
}
output.writeByte(sHeader);
- output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ output.writeByte(0);
if (sHeader == 2) {
output.writeShort(SERVICE_LENGHT);
} else {
}
output.writeByte(TOKEN_BUCKET_TSPEC);
- output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ output.writeByte(0);
output.writeShort(PARAMETER_127_LENGTH);
final TspecObject tSpec = flowObj.getTspecObject();
writeFloat32(tSpec.getTokenBucketRate(), output);
return;
}
output.writeByte(GUARANTEED_SERVICE_RSPEC);
- output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ output.writeByte(0);
output.writeShort(PARAMETER_130_LENGTH);
writeFloat32(flowObj.getRate(), output);
writeUnsignedInt(flowObj.getSlackTerm(), output);
byteAggregator.writeByte(fastRerouteObject.getSetupPriority().toJava());
byteAggregator.writeByte(fastRerouteObject.getHoldPriority().toJava());
byteAggregator.writeByte(fastRerouteObject.getHopLimit().toJava());
- byteAggregator.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ byteAggregator.writeByte(0);
byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
writeAttributeFilter(fastRerouteObject.getExcludeAny(), byteAggregator);
checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory.");
final MetricObject metric = (MetricObject) teLspObject;
serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
final BitArray reflect = new BitArray(FLAGS_SIZE);
reflect.set(BOUND, metric.isBound());
reflect.set(COMPUTED, metric.isComputed());
public class ProtectionCommonParser {
- protected static final int BYTE_SIZE = 1;
protected static final short PROTECTION_SUBOBJECT_TYPE_1 = 1;
protected static final short PROTECTION_SUBOBJECT_TYPE_2 = 2;
protected static final int CONTENT_LENGTH_C2 = 8;
final BitArray flagBitArray = new BitArray(FLAGS_SIZE);
flagBitArray.set(SECONDARY, protObj.isSecondary());
flagBitArray.toByteBuf(output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
output.writeByte(protObj.getLinkFlags().getIntValue());
}
flagBitArray.set(OPERATIONAL, protObj.isOperational());
flagBitArray.toByteBuf(output);
output.writeByte(protObj.getLspFlag().getIntValue());
- output.writeZero(BYTE_SIZE);
+ output.writeByte(0);
output.writeByte(protObj.getLinkFlags().getIntValue());
final BitArray flagInPlaceBitArray = new BitArray(FLAGS_SIZE);
flagInPlaceBitArray.set(IN_PLACE, protObj.isInPlace());
flagInPlaceBitArray.set(REQUIRED, protObj.isRequired());
flagInPlaceBitArray.toByteBuf(output);
output.writeByte(protObj.getSegFlag().getIntValue());
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
}
protected static ProtectionSubobject parseCommonProtectionBodyType2(final ByteBuf byteBuf) throws
protected static void serializeBody(final short ctype, final ProtectionSubobject protObj,
final ByteBuf output) {
- output.writeZero(BYTE_SIZE);
+ output.writeByte(0);
output.writeByte(ctype);
switch (ctype) {
case PROTECTION_SUBOBJECT_TYPE_1:
public static final short CLASS_NUM = 12;
public static final short CTYPE = 2;
private static final int BODY_SIZE = 32;
- private static final int SERVICE_LENGHT = 6;
+ private static final int SERVICE_LENGTH = 6;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
checkArgument(teLspObject instanceof TspecObject, "SenderTspecObject is mandatory.");
final TspecObject tspecObj = (TspecObject) teLspObject;
serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
- output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
+ output.writeShort(0);
output.writeShort(OVERALL_LENGTH);
+ // FIXME: this is weird. Use explicit 1?
output.writeByte(ByteBufWriteUtil.ONE_BYTE_LENGTH);
- output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
- output.writeShort(SERVICE_LENGHT);
+ output.writeByte(0);
+ output.writeShort(SERVICE_LENGTH);
output.writeByte(TOKEN_BUCKET_TSPEC);
- output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
+ output.writeByte(0);
output.writeShort(PARAMETER_127_LENGTH);
writeFloat32(tspecObj.getTokenBucketRate(), output);
writeFloat32(tspecObj.getTokenBucketSize(), output);
public static final int SHORT_BYTES_LENGTH = Short.SIZE / Byte.SIZE;
- public static final int MEDIUM_BYTES_LENGTH = 3;
-
public static final int INT_BYTES_LENGTH = Integer.SIZE / Byte.SIZE;
public static final int LONG_BYTES_LENGTH = Long.SIZE / Byte.SIZE;
* ByteBuf, where value or zeros are written.
*/
public static void writeInt(final Integer value, final ByteBuf output) {
- if (value != null) {
- output.writeInt(value);
- } else {
- output.writeZero(INT_BYTES_LENGTH);
- }
+ output.writeInt(value != null ? value : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeMedium(final Integer value, final ByteBuf output) {
- if (value != null) {
- output.writeMedium(value);
- } else {
- output.writeZero(MEDIUM_BYTES_LENGTH);
- }
+ output.writeMedium(value != null ? value : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeShort(final Short value, final ByteBuf output) {
- if (value != null) {
- output.writeShort(value);
- } else {
- output.writeZero(SHORT_BYTES_LENGTH);
- }
+ output.writeShort(value != null ? value : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeLong(final Long value, final ByteBuf output) {
- if (value != null) {
- output.writeLong(value);
- } else {
- output.writeZero(LONG_BYTES_LENGTH);
- }
+ output.writeLong(value != null ? value : 0L);
}
/**
if (value != null) {
output.writeBoolean(value);
} else {
- output.writeZero(ONE_BYTE_LENGTH);
+ output.writeByte(0);
}
}
*/
@Deprecated(forRemoval = true)
public static void writeUnsignedByte(final Short value, final ByteBuf output) {
- if (value != null) {
- output.writeByte(value);
- } else {
- output.writeZero(ONE_BYTE_LENGTH);
- }
+ output.writeByte(value != null ? value : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeUnsignedByte(final Uint8 value, final ByteBuf output) {
- if (value != null) {
- output.writeByte(value.byteValue());
- } else {
- output.writeZero(ONE_BYTE_LENGTH);
- }
+ output.writeByte(value != null ? value.byteValue() : 0);
}
/**
*/
@Deprecated(forRemoval = true)
public static void writeUnsignedShort(final Integer value, final ByteBuf output) {
- if (value != null) {
- output.writeShort(value.shortValue());
- } else {
- output.writeZero(SHORT_BYTES_LENGTH);
- }
+ output.writeShort(value != null ? value.shortValue() : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeUnsignedShort(final Uint16 value, final ByteBuf output) {
- if (value != null) {
- output.writeShort(value.shortValue());
- } else {
- output.writeZero(SHORT_BYTES_LENGTH);
- }
+ output.writeShort(value != null ? value.shortValue() : 0);
}
/**
*/
@Deprecated(forRemoval = true)
public static void writeUnsignedInt(final Long value, final ByteBuf output) {
- if (value != null) {
- output.writeInt(value.intValue());
- } else {
- output.writeZero(INT_BYTES_LENGTH);
- }
+ output.writeInt(value != null ? value.intValue() : 0);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeUnsignedInt(final Uint32 value, final ByteBuf output) {
- if (value != null) {
- output.writeInt(value.intValue());
- } else {
- output.writeZero(INT_BYTES_LENGTH);
- }
+ output.writeInt(value != null ? value.intValue() : 0);
}
/**
*/
@Deprecated(forRemoval = true)
public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) {
- if (value != null) {
- output.writeLong(value.longValue());
- } else {
- output.writeZero(LONG_BYTES_LENGTH);
- }
+ output.writeLong(value != null ? value.longValue() : 0L);
}
/**
* ByteBuf, where value or zeros are written.
*/
public static void writeUnsignedLong(final Uint64 value, final ByteBuf output) {
- if (value != null) {
- output.writeLong(value.longValue());
- } else {
- output.writeZero(LONG_BYTES_LENGTH);
- }
+ output.writeLong(value != null ? value.longValue() : 0L);
}
/**
if (ipv4Address != null) {
output.writeBytes(Ipv4Util.bytesForAddress(ipv4Address));
} else {
- output.writeZero(Ipv4Util.IP4_LENGTH);
+ output.writeInt(0);
}
}
if (ipv4Address != null) {
output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
} else {
- output.writeZero(Ipv4Util.IP4_LENGTH);
+ output.writeInt(0);
}
}
if (value != null) {
output.writeBytes(value.getValue());
} else {
- output.writeZero(FLOAT32_BYTES_LENGTH);
+ output.writeInt(0);
}
}
}
@Test
public void testWriteMediumValue() {
final byte[] result = { 0, 0, 5 };
- final ByteBuf output = Unpooled.buffer(ByteBufWriteUtil.MEDIUM_BYTES_LENGTH);
+ final ByteBuf output = Unpooled.buffer(3);
writeMedium(5, output);
assertArrayEquals(result, output.array());