import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser;
import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.PeerDownNotification;
final PeerDownNotification peerDown = (PeerDownNotification) message;
if (peerDown.isLocalSystemClosed()) {
if (peerDown.getData() instanceof FsmEventCode) {
- ByteBufWriteUtil.writeUnsignedByte(REASON_TWO.getValue(), buffer);
- ByteBufWriteUtil.writeUnsignedShort(((FsmEventCode) peerDown.getData()).getFsmEventCode(), buffer);
+ buffer.writeByte(REASON_TWO.getValue());
+ ByteBufUtils.writeOrZero(buffer, ((FsmEventCode) peerDown.getData()).getFsmEventCode());
} else if (peerDown.getData()
instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329
.peer.down.data.Notification) {
- ByteBufWriteUtil.writeUnsignedByte(REASON_ONE.getValue(), buffer);
+ buffer.writeByte(REASON_ONE.getValue());
serializePDU(peerDown.getData(), buffer);
}
} else {
if (peerDown.getData()
instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329
.peer.down.data.Notification) {
- ByteBufWriteUtil.writeUnsignedByte(REASON_THREE.getValue(), buffer);
+ buffer.writeByte(REASON_THREE.getValue());
serializePDU(peerDown.getData(), buffer);
} else {
- ByteBufWriteUtil.writeUnsignedByte(REASON_FOUR.getValue(), buffer);
+ buffer.writeByte(REASON_FOUR.getValue());
}
}
}
} else {
ByteBufWriteUtil.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
}
- ByteBufWriteUtil.writeUnsignedShort(peerUp.getLocalPort().getValue(), buffer);
- ByteBufWriteUtil.writeUnsignedShort(peerUp.getRemotePort().getValue(), buffer);
+ ByteBufUtils.write(buffer, peerUp.getLocalPort().getValue());
+ ByteBufUtils.write(buffer, peerUp.getRemotePort().getValue());
this.msgRegistry.serializeMessage(new OpenBuilder(peerUp.getSentOpen()).build(), buffer);
this.msgRegistry.serializeMessage(new OpenBuilder(peerUp.getReceivedOpen()).build(), buffer);
}
private void serializeTlvs(final Information tlvs, final ByteBuf output) {
- if (tlvs != null && tlvs.getStringInformation() != null) {
- for (final StringInformation stringInfo : tlvs.getStringInformation()) {
+ if (tlvs != null) {
+ for (final StringInformation stringInfo : tlvs.nonnullStringInformation()) {
if (stringInfo.getStringTlv() != null) {
serializeTlv(stringInfo.getStringTlv(), output);
}
*/
package org.opendaylight.protocol.bmp.parser.message;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
serializeStatTlv(tlvs.getPrefixesTreatedAsWithdrawTlv(), tlvsBuffer, counter);
serializeStatTlv(tlvs.getDuplicateUpdatesTlv(), tlvsBuffer, counter);
- writeUnsignedInt(counter.longValue(), output);
+ output.writeInt(counter.get());
output.writeBytes(tlvsBuffer);
}
import org.opendaylight.protocol.bmp.spi.parser.BmpTlvParser;
import org.opendaylight.protocol.bmp.spi.parser.BmpTlvSerializer;
import org.opendaylight.protocol.bmp.spi.parser.TlvUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.stat.tlvs.PerAfiSafiAdjRibInTlv;
private final AddressFamilyRegistry afiRegistry;
private final SubsequentAddressFamilyRegistry safiRegistry;
- public StatType009TlvHandler(final AddressFamilyRegistry afiReg, SubsequentAddressFamilyRegistry safiReg) {
+ public StatType009TlvHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
this.afiRegistry = requireNonNull(afiReg, "AddressFamily cannot be null");
this.safiRegistry = requireNonNull(safiReg, "SubsequentAddressFamily cannot be null");
}
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf output) {
checkArgument(tlv instanceof PerAfiSafiAdjRibInTlv, "PerAfiSafiAdjRibInTlv is mandatory.");
+ final PerAfiSafiAdjRibInTlv perAfiSafi = (PerAfiSafiAdjRibInTlv) tlv;
+
final ByteBuf buffer = Unpooled.buffer();
- ByteBufWriteUtil.writeUnsignedShort(this.afiRegistry.numberForClass(((PerAfiSafiAdjRibInTlv) tlv)
- .getAfi()), buffer);
- ByteBufWriteUtil.writeUnsignedByte(this.safiRegistry.numberForClass(((PerAfiSafiAdjRibInTlv) tlv)
- .getSafi()).shortValue(), buffer);
- ByteBufWriteUtil.writeUnsignedLong(((PerAfiSafiAdjRibInTlv) tlv).getCount().getValue(), buffer);
+ final Integer afiInt = this.afiRegistry.numberForClass(perAfiSafi.getAfi());
+ buffer.writeShort(afiInt != null ? afiInt : 0);
+ buffer.writeByte(this.safiRegistry.numberForClass(perAfiSafi.getSafi()));
+ ByteBufUtils.write(buffer, perAfiSafi.getCount().getValue());
TlvUtil.formatTlv(TYPE, buffer, output);
}
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedLong;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
private final AddressFamilyRegistry afiRegistry;
private final SubsequentAddressFamilyRegistry safiRegistry;
- public StatType010TlvHandler(final AddressFamilyRegistry afiReg, SubsequentAddressFamilyRegistry safiReg) {
+ public StatType010TlvHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
this.afiRegistry = requireNonNull(afiReg, "AddressFamily cannot be null");
this.safiRegistry = requireNonNull(safiReg, "SubsequentAddressFamily cannot be null");
}
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf output) {
checkArgument(tlv instanceof PerAfiSafiLocRibTlv, "PerAfiSafiLocRibInTlv is mandatory.");
+ final PerAfiSafiLocRibTlv perAfiSafi = (PerAfiSafiLocRibTlv) tlv;
+
final ByteBuf buffer = Unpooled.buffer();
- writeUnsignedShort(this.afiRegistry.numberForClass(((PerAfiSafiLocRibTlv) tlv).getAfi()), buffer);
- writeUnsignedByte(this.safiRegistry.numberForClass(((PerAfiSafiLocRibTlv) tlv).getSafi()).shortValue(), buffer);
- writeUnsignedLong(((PerAfiSafiLocRibTlv) tlv).getCount().getValue(), buffer);
+ final Integer afiInt = this.afiRegistry.numberForClass(perAfiSafi.getAfi());
+ buffer.writeShort(afiInt != null ? afiInt : 0);
+ buffer.writeByte(this.safiRegistry.numberForClass(perAfiSafi.getSafi()));
+ ByteBufUtils.write(buffer, perAfiSafi.getCount().getValue());
TlvUtil.formatTlv(TYPE, buffer, output);
}
* 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.bmp.spi.parser;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public abstract class AbstractBmpPerPeerMessageParser<T extends Builder<?>> extends AbstractBmpMessageWithTlvParser<T> {
-
private static final int L_FLAG_POS = 1;
private static final int V_FLAG_POS = 0;
private static final int FLAGS_SIZE = 8;
}
protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
- Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
+ checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
final PeerType peerType = PeerType.forValue(bytes.readByte());
phBuilder.setType(peerType);
}
protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
- Preconditions.checkArgument(peerHeader != null, "Per-peer header cannot be null.");
+ checkArgument(peerHeader != null, "Per-peer header cannot be null.");
final PeerType peerType = peerHeader.getType();
output.writeByte(peerType.getIntValue());
final BitArray flags = new BitArray(FLAGS_SIZE);
} else {
ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
}
- ByteBufWriteUtil.writeUnsignedInt(peerHeader.getAs().getValue(), output);
+ ByteBufUtils.write(output, peerHeader.getAs().getValue());
ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
- if (peerHeader.getTimestampSec() != null) {
- ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampSec().getValue(), output);
+
+ final Timestamp stampSec = peerHeader.getTimestampSec();
+ if (stampSec != null) {
+ ByteBufUtils.write(output, stampSec.getValue());
} else {
output.writeInt(0);
}
- if (peerHeader.getTimestampMicro() != null) {
- ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampMicro().getValue(), output);
+ final Timestamp stampMicro = peerHeader.getTimestampMicro();
+ if (stampMicro != null) {
+ ByteBufUtils.write(output, stampMicro.getValue());
} else {
output.writeInt(0);
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Gauge64;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public final class TlvUtil {
private TlvUtil() {
public static void formatTlvShort16(final int type, final int value, final ByteBuf out) {
formatTlvHeader(type, Short.BYTES, out);
- ByteBufWriteUtil.writeUnsignedShort(value, out);
+ out.writeShort(value);
}
public static void formatTlvCounter32(final int type, final Counter32 value, final ByteBuf out) {
- if (value != null && value.getValue() != null) {
+ if (value != null) {
formatTlvHeader(type, Integer.BYTES, out);
- ByteBufWriteUtil.writeUnsignedInt(value.getValue(), out);
+ ByteBufUtils.write(out, value.getValue());
}
}
public static void formatTlvGauge64(final int type, final Gauge64 value, final ByteBuf out) {
- if (value != null && value.getValue() != null) {
+ if (value != null) {
formatTlvHeader(type, Long.BYTES, out);
- ByteBufWriteUtil.writeUnsignedLong(value.getValue(), out);
+ ByteBufUtils.write(out, value.getValue());
}
}
if (value != null) {
TlvUtil.formatTlv(type, Unpooled.copiedBuffer(value, StandardCharsets.US_ASCII), out);
}
-
}
private static void formatTlvHeader(final int type, final int length, final ByteBuf output) {
- ByteBufWriteUtil.writeUnsignedShort(type, output);
- ByteBufWriteUtil.writeUnsignedShort(length, output);
+ output.writeShort(type);
+ output.writeShort(length);
}
}
* 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.bmp.spi.registry;
import static org.junit.Assert.assertArrayEquals;
import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageParser;
import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yangtools.yang.binding.Notification;
public class SimpleBmpMessageRegistryTest {
}
private static final class BmpTestParser extends AbstractBmpMessageParser {
-
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
- ByteBufWriteUtil.writeUnsignedInt(((BmpTestMessage) message).getValue(), buffer);
+ buffer.writeInt((int) ((BmpTestMessage) message).getValue());
}
@Override
}
private static final class BmpTestMessage implements Notification {
-
private final long value;
BmpTestMessage(final long value) {
public String toString() {
return "BmpTestMessage [value=" + this.value + "]";
}
-
}
-
}