import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.AreaIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
@Override
public void serializeTlvBody(final AreaIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+ ByteBufUtils.write(body, tlv.getValue());
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
@Override
public void serializeTlvBody(final AsNumber tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+ ByteBufUtils.write(body, tlv.getValue());
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.DomainIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
@Override
public void serializeTlvBody(final DomainIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+ ByteBufUtils.write(body, tlv.getValue());
}
@Override
*/
package org.opendaylight.protocol.bgp.linkstate.impl.tlvs;
+import static java.util.Objects.requireNonNull;
+
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkLrIdentifiers;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
public final class LinkIdTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer<LinkLrIdentifiers>,
LinkstateTlvParser<LinkLrIdentifiers> {
-
private static final int LINK_LR_IDENTIFIERS = 258;
@Override
public void serializeTlvBody(final LinkLrIdentifiers tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedInt(tlv.getLinkLocalIdentifier(), body);
- ByteBufWriteUtil.writeUnsignedInt(tlv.getLinkRemoteIdentifier(), body);
+ ByteBufUtils.writeOrZero(body, tlv.getLinkLocalIdentifier());
+ ByteBufUtils.writeOrZero(body, tlv.getLinkRemoteIdentifier());
}
@Override
public LinkLrIdentifiers parseTlvBody(final ByteBuf value) {
- final Uint32 localId = Uint32.valueOf(value.readUnsignedInt());
- final Uint32 remoteId = Uint32.valueOf(value.readUnsignedInt());
- return new LinkLrIdentifiers() {
- @Override
- public Class<LinkLrIdentifiers> implementedInterface() {
- return LinkLrIdentifiers.class;
- }
-
- @Override
- public Uint32 getLinkRemoteIdentifier() {
- return remoteId;
- }
-
- @Override
- public Uint32 getLinkLocalIdentifier() {
- return localId;
- }
- };
+ final Uint32 localId = ByteBufUtils.readUint32(value);
+ final Uint32 remoteId = ByteBufUtils.readUint32(value);
+ return new AnonymousLinkLrIdentifiers(localId, remoteId);
}
@Override
public int getType() {
return LINK_LR_IDENTIFIERS;
}
+
+ private static final class AnonymousLinkLrIdentifiers implements LinkLrIdentifiers {
+ private final Uint32 localId;
+ private final Uint32 remoteId;
+
+ AnonymousLinkLrIdentifiers(final Uint32 localId, final Uint32 remoteId) {
+ this.localId = requireNonNull(localId);
+ this.remoteId = requireNonNull(remoteId);
+ }
+
+ @Override
+ public Class<LinkLrIdentifiers> implementedInterface() {
+ return LinkLrIdentifiers.class;
+ }
+
+ @Override
+ public Uint32 getLinkRemoteIdentifier() {
+ return remoteId;
+ }
+
+ @Override
+ public Uint32 getLinkLocalIdentifier() {
+ return localId;
+ }
+ }
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
@Override
public void serializeTlvBody(final AsNumber tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedInt(tlv.getValue(), body);
+ ByteBufUtils.write(body, tlv.getValue());
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
public final class MultiTopoIdTlvParser implements LinkstateTlvParser<TopologyIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<TopologyIdentifier> {
-
public static final QName MULTI_TOPOLOGY_ID_QNAME = QName.create(LinkDescriptors.QNAME, "multi-topology-id")
.intern();
@Override
public void serializeTlvBody(final TopologyIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedShort(tlv.getValue(), body);
+ ByteBufUtils.write(body, tlv.getValue());
}
@Override
}
public static TopologyIdentifier serializeModel(final ContainerNode prefixDesc) {
- if (prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
- return new TopologyIdentifier((Uint16) prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue());
- }
- return null;
+ return prefixDesc.getChild(TlvUtil.MULTI_TOPOLOGY_NID)
+ .map(child -> new TopologyIdentifier((Uint16) child.getValue()))
+ .orElse(null);
}
}
-
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfRouteType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors;
import org.opendaylight.yangtools.yang.common.QName;
public final class OspfRouteTlvParser implements LinkstateTlvParser<OspfRouteType>,
LinkstateTlvParser.LinkstateTlvSerializer<OspfRouteType> {
+ public static final QName OSPF_ROUTE_TYPE_QNAME = QName.create(PrefixDescriptors.QNAME, "ospf-route-type").intern();
+ public static final NodeIdentifier OSPF_ROUTE_NID = NodeIdentifier.create(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
- public static final QName OSPF_ROUTE_TYPE_QNAME =
- QName.create(PrefixDescriptors.QNAME.getModule(), "ospf-route-type");
- public static final NodeIdentifier OSPF_ROUTE_NID = new NodeIdentifier(OspfRouteTlvParser.OSPF_ROUTE_TYPE_QNAME);
private static final int OSPF_ROUTE_TYPE = 264;
@Override
public void serializeTlvBody(final OspfRouteType tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeUnsignedByte((short) tlv.getIntValue(), body);
+ body.writeByte(tlv.getIntValue());
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfInterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.isis.lan.identifier.IsIsRouterIdentifierBuilder;
public final class RouterIdTlvParser implements LinkstateTlvParser<CRouterIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<CRouterIdentifier> {
-
private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8;
private static final int OSPF_ROUTER_ID_LENGTH = 4;
private static final int ISO_SYSTEM_ID_LENGTH = 6;
} else if (tlv instanceof IsisPseudonodeCase) {
final IsisPseudonode isis = ((IsisPseudonodeCase) tlv).getIsisPseudonode();
body.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
- ByteBufWriteUtil.writeUnsignedByte(isis.getPsn(), body);
+ ByteBufUtils.writeOrZero(body, isis.getPsn());
} else if (tlv instanceof OspfNodeCase) {
- ByteBufWriteUtil.writeUnsignedInt(((OspfNodeCase) tlv).getOspfNode().getOspfRouterId(), body);
+ ByteBufUtils.writeOrZero(body, ((OspfNodeCase) tlv).getOspfNode().getOspfRouterId());
} else if (tlv instanceof OspfPseudonodeCase) {
final OspfPseudonode node = ((OspfPseudonodeCase) tlv).getOspfPseudonode();
- ByteBufWriteUtil.writeUnsignedInt(node.getOspfRouterId(), body);
- ByteBufWriteUtil.writeUnsignedInt(node.getLanInterface().getValue(), body);
+ ByteBufUtils.writeOrZero(body, node.getOspfRouterId());
+ ByteBufUtils.write(body, node.getLanInterface().getValue());
}
}
package org.opendaylight.protocol.bgp.linkstate.spi;
import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Identifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
public abstract class AbstractNlriTypeCodec implements NlriTypeCaseParser, NlriTypeCaseSerializer {
@Override
public final CLinkstateDestination parseTypeNlri(final ByteBuf nlri) {
- final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
- builder.setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte()));
- builder.setIdentifier(new Identifier(ByteBufUtils.readUint64(nlri)));
- builder.setObjectType(parseObjectType(nlri));
- return builder.build();
+ return new CLinkstateDestinationBuilder()
+ .setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte()))
+ .setIdentifier(new Identifier(ByteBufUtils.readUint64(nlri)))
+ .setObjectType(parseObjectType(nlri))
+ .build();
}
@Override
public final void serializeTypeNlri(final CLinkstateDestination nlriType, final ByteBuf byteAggregator) {
- ByteBufWriteUtil.writeUnsignedByte((short) nlriType.getProtocolId().getIntValue(), byteAggregator);
- ByteBufWriteUtil.writeUnsignedLong(nlriType.getIdentifier().getValue(), byteAggregator);
+ byteAggregator.writeByte(nlriType.getProtocolId().getIntValue());
+ ByteBufUtils.write(byteAggregator, nlriType.getIdentifier().getValue());
serializeObjectType(nlriType.getObjectType(), byteAggregator);
}
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
}
public static TeLspCase serializeTeLsp(final ChoiceNode objectType) {
- final TeLspCaseBuilder teLsp = new TeLspCaseBuilder();
- teLsp.setLspId(new LspId((Uint32) objectType.getChild(LSP_ID).get().getValue()));
- teLsp.setTunnelId(new TunnelId((Uint16) objectType.getChild(TUNNEL_ID).get().getValue()));
final ChoiceNode addressFamily = (ChoiceNode) objectType.getChild(ADDRESS_FAMILY).get();
- teLsp.setAddressFamily(serializeAddressFamily(addressFamily,
- addressFamily.getChild(IPV4_TUNNEL_SENDER_ADDRESS).isPresent()));
-
- return teLsp.build();
+ return new TeLspCaseBuilder()
+ .setLspId(new LspId((Uint32) objectType.getChild(LSP_ID).get().getValue()))
+ .setTunnelId(new TunnelId((Uint16) objectType.getChild(TUNNEL_ID).get().getValue()))
+ .setAddressFamily(serializeAddressFamily(addressFamily,
+ addressFamily.getChild(IPV4_TUNNEL_SENDER_ADDRESS).isPresent()))
+ .build();
}
private static AddressFamily serializeAddressFamily(final ChoiceNode addressFamily, final boolean ipv4Case) {
}
private static void serializeTunnelIdAndLspId(final ByteBuf buffer, final TeLspCase teLSP) {
- ByteBufWriteUtil.writeUnsignedShort(teLSP.getTunnelId().getValue(), buffer);
- ByteBufWriteUtil.writeUnsignedShort(teLSP.getLspId().getValue().intValue(), buffer);
+ ByteBufUtils.write(buffer, teLSP.getTunnelId().getValue());
+ buffer.writeShort(teLSP.getLspId().getValue().intValue());
}
}