import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.evpn.rev180329.EsiType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
public Esi parseEsi(final ByteBuf buffer) {
return new AsGeneratedCaseBuilder()
.setAsGenerated(new AsGeneratedBuilder()
- .setAs(new AsNumber(buffer.readUnsignedInt()))
- .setLocalDiscriminator(buffer.readUnsignedInt())
+ .setAs(new AsNumber(ByteBufUtils.readUint32(buffer)))
+ .setLocalDiscriminator(ByteBufUtils.readUint32(buffer))
.build())
.build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
.setLacpAutoGenerated(new LacpAutoGeneratedBuilder()
.setCeLacpMacAddress(IetfYangUtil.INSTANCE.macAddressFor(
ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)))
- .setCeLacpPortKey(buffer.readUnsignedShort())
+ .setCeLacpPortKey(ByteBufUtils.readUint16(buffer))
.build())
.build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
.setLanAutoGenerated(new LanAutoGeneratedBuilder()
.setRootBridgeMacAddress(IetfYangUtil.INSTANCE.macAddressFor(
ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)))
- .setRootBridgePriority(buffer.readUnsignedShort())
+ .setRootBridgePriority(ByteBufUtils.readUint16(buffer))
.build())
.build();
}
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
.setMacAutoGenerated(new MacAutoGeneratedBuilder()
.setSystemMacAddress(IetfYangUtil.INSTANCE.macAddressFor(
ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)))
- .setLocalDiscriminator(new Uint24(Long.valueOf(buffer.readUnsignedMedium())))
+ .setLocalDiscriminator(new Uint24(ByteBufUtils.readUint24(buffer)))
.build())
.build();
}
import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractRD;
import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EsiType;
return new RouterIdGeneratedCaseBuilder()
.setRouterIdGenerated(new RouterIdGeneratedBuilder()
.setRouterId(Ipv4Util.addressForByteBuf(buffer))
- .setLocalDiscriminator(buffer.readUnsignedInt())
+ .setLocalDiscriminator(ByteBufUtils.readUint32(buffer))
.build())
.build();
}
* 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.bgp.evpn.impl.extended.communities;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NormalizationType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.OperationalMode;
builder.setModeOfOperation(OperationalMode.forValue(getFlagShort(flags, MODE_OF_OPERATION)));
builder.setOperatingPer(NormalizationType.forValue(getFlagShort(flags, NORMALIZATION_TYPE)));
- builder.setL2Mtu(body.readUnsignedShort());
+ builder.setL2Mtu(ByteBufUtils.readUint16(body));
body.skipBytes(RESERVED);
return new Layer2AttributesExtendedCommunityCaseBuilder()
.setLayer2AttributesExtendedCommunity(builder.build()).build();
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.mac.mobility.extended.community.MacMobilityExtendedCommunity;
throws BGPDocumentedException, BGPParsingException {
final boolean isStatic = buffer.readBoolean();
buffer.skipBytes(RESERVED);
- final long seqNumber = buffer.readUnsignedInt();
return new MacMobilityExtendedCommunityCaseBuilder()
.setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder()
- .setStatic(isStatic).setSeqNumber(seqNumber).build()).build();
+ .setStatic(isStatic)
+ .setSeqNumber(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build();
}
@Override
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH,
"Wrong length of array of bytes. Passed: %s ;", buffer);
final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
- final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
+ final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build();
final MplsLabel label = mplsLabelForByteBuf(buffer);
final EthernetADRouteBuilder builder = new EthernetADRouteBuilder()
.setEsi(esi).setEthernetTagId(eti).setMplsLabel(label);
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.bgp.concepts.IpAddressUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.NlriType;
|| buffer.readableBytes() == CONTENT_LENGTH2,
"Wrong length of array of bytes. Passed: %s ;", buffer);
- final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
+ final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build();
IpAddress ip = IpAddressUtil.addressForByteBuf(buffer);
final IncMultiEthernetTagResBuilder builder = new IncMultiEthernetTagResBuilder()
.setEthernetTagId(eti).setOrigRouteIp(ip);
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
@Override
public EvpnChoice parseEvpn(final ByteBuf buffer) {
final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE));
- final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build();
+ final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(ByteBufUtils.readUint32(buffer)).build();
buffer.skipBytes(1);
final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH));
final IpAddress ip = parseIp(buffer);
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.Util;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
// RFC does not specify operator
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
- builder.setValue(new Dscp(nlri.readUnsignedByte()));
+ builder.setValue(new Dscp(ByteBufUtils.readUint8(nlri)));
end = op.isEndOfList();
dscps.add(builder.build());
}
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
public static final int ICMP_CODE_VALUE = 8;
@Override
- public void serializeType(FlowspecType fsType, ByteBuf output) {
+ public void serializeType(final FlowspecType fsType, final ByteBuf output) {
Preconditions.checkArgument(fsType instanceof IcmpCodeCase, "IcmpCodeCase class is mandatory!");
output.writeByte(ICMP_CODE_VALUE);
NumericOneByteOperandParser.INSTANCE.serialize(((IcmpCodeCase) fsType).getCodes(), output);
}
@Override
- public FlowspecType parseType(ByteBuf buffer) {
+ public FlowspecType parseType(final ByteBuf buffer) {
requireNonNull(buffer, "input buffer is null, missing data to parse.");
return new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(buffer)).build();
}
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
- builder.setValue(nlri.readUnsignedByte());
+ builder.setValue(ByteBufUtils.readUint8(nlri));
end = op.isEndOfList();
codes.add(builder.build());
}
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
public static final int ICMP_TYPE_VALUE = 7;
@Override
- public void serializeType(FlowspecType fsType, ByteBuf output) {
+ public void serializeType(final FlowspecType fsType, final ByteBuf output) {
Preconditions.checkArgument(fsType instanceof IcmpTypeCase, "IcmpTypeCase class is mandatory!");
output.writeByte(ICMP_TYPE_VALUE);
NumericOneByteOperandParser.INSTANCE.serialize(((IcmpTypeCase) fsType).getTypes(), output);
}
@Override
- public FlowspecType parseType(ByteBuf buffer) {
+ public FlowspecType parseType(final ByteBuf buffer) {
requireNonNull(buffer, "input buffer is null, missing data to parse.");
return new IcmpTypeCaseBuilder().setTypes(parseIcmpType(buffer)).build();
}
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
- builder.setValue(nlri.readUnsignedByte());
+ builder.setValue(ByteBufUtils.readUint8(nlri));
end = op.isEndOfList();
icmps.add(builder.build());
}
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCase;
public static final int IP_PROTOCOL_VALUE = 3;
@Override
- public void serializeType(FlowspecType fsType, ByteBuf output) {
+ public void serializeType(final FlowspecType fsType, final ByteBuf output) {
Preconditions.checkArgument(fsType instanceof ProtocolIpCase, "ProtocolIpCase class is mandatory!");
output.writeByte(IP_PROTOCOL_VALUE);
NumericOneByteOperandParser.INSTANCE.serialize(((ProtocolIpCase) fsType).getProtocolIps(), output);
}
@Override
- public FlowspecType parseType(ByteBuf buffer) {
+ public FlowspecType parseType(final ByteBuf buffer) {
requireNonNull(buffer, "input buffer is null, missing data to parse.");
return new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(buffer)).build();
}
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
- builder.setValue(nlri.readUnsignedByte());
+ builder.setValue(ByteBufUtils.readUint8(nlri));
end = op.isEndOfList();
ips.add(builder.build());
}
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
public static final int NEXT_HEADER_VALUE = 3;
@Override
- public void serializeType(FlowspecType value, ByteBuf output) {
+ public void serializeType(final FlowspecType value, final ByteBuf output) {
Preconditions.checkArgument(value instanceof NextHeaderCase, "NextHeaderCase class is mandatory!");
output.writeByte(NEXT_HEADER_VALUE);
NumericOneByteOperandParser.INSTANCE.serialize(((NextHeaderCase) value).getNextHeaders(), output);
}
@Override
- public FlowspecType parseType(ByteBuf buffer) {
+ public FlowspecType parseType(final ByteBuf buffer) {
if (buffer == null) {
return null;
}
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
- builder.setValue(nlri.readUnsignedByte());
+ builder.setValue(ByteBufUtils.readUint8(nlri));
end = op.isEndOfList();
headers.add(builder.build());
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.flowspec.rev180329.redirect.as4.extended.community.RedirectAs4;
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
final RedirectAs4Builder builder = new RedirectAs4Builder();
- builder.setGlobalAdministrator(new AsNumber(buffer.readUnsignedInt()));
- builder.setLocalAdministrator(buffer.readUnsignedShort());
+ builder.setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(buffer)));
+ builder.setLocalAdministrator(ByteBufUtils.readUint16(buffer));
return new RedirectAs4ExtendedCommunityCaseBuilder().setRedirectAs4(builder.build()).build();
}
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.extended.community.RedirectExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.extended.community.RedirectExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yangtools.yang.common.Uint32;
public class RedirectAsTwoOctetEcHandler implements ExtendedCommunityParser, ExtendedCommunitySerializer {
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
- final ShortAsNumber as1 = new ShortAsNumber((long) buffer.readUnsignedShort());
+ final ShortAsNumber as1 = new ShortAsNumber(Uint32.valueOf(ByteBufUtils.readUint16(buffer)));
final byte[] byteValue = ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE);
return new RedirectExtendedCommunityCaseBuilder().setRedirectExtendedCommunity(
new RedirectExtendedCommunityBuilder()
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4;
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
final RedirectIpv4Builder builder = new RedirectIpv4Builder();
builder.setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer));
- builder.setLocalAdministrator(buffer.readUnsignedShort());
+ builder.setLocalAdministrator(ByteBufUtils.readUint16(buffer));
return new RedirectIpv4ExtendedCommunityCaseBuilder().setRedirectIpv4(builder.build()).build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.RedirectIpv6ExtendedCommunity;
return new RedirectIpv6ExtendedCommunityCaseBuilder().setRedirectIpv6(
new RedirectIpv6Builder()
.setGlobalAdministrator(Ipv6Util.addressForByteBuf(buffer))
- .setLocalAdministrator(buffer.readUnsignedShort())
+ .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
.build()).build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.traffic.marking.extended.community.TrafficMarkingExtendedCommunity;
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
buffer.skipBytes(RESERVED);
- final Dscp dscp = new Dscp(buffer.readUnsignedByte());
+ final Dscp dscp = new Dscp(ByteBufUtils.readUint8(buffer));
return new TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity(
new TrafficMarkingExtendedCommunityBuilder()
.setGlobalAdministrator(dscp).build()).build();
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yangtools.yang.common.Uint32;
public class TrafficRateEcHandler implements ExtendedCommunityParser, ExtendedCommunitySerializer {
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
- final ShortAsNumber as = new ShortAsNumber((long) buffer.readUnsignedShort());
+ final ShortAsNumber as = new ShortAsNumber(Uint32.valueOf(buffer.readUnsignedShort()));
final Bandwidth value = new Bandwidth(ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE));
return new TrafficRateExtendedCommunityCaseBuilder().setTrafficRateExtendedCommunity(
new TrafficRateExtendedCommunityBuilder()
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvParser;
import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvSerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.LuLabelIndexTlvBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
public LuLabelIndexTlv parseBgpPrefixSidTlv(final ByteBuf buffer) {
buffer.readBytes(RESERVED);
buffer.readBytes(LABEL_INDEX_FLAGS_BYTES);
- final Long value = buffer.readUnsignedInt();
- return new LuLabelIndexTlvBuilder().setLabelIndexTlv(value).build();
+ return new LuLabelIndexTlvBuilder().setLabelIndexTlv(ByteBufUtils.readUint32(buffer)).build();
}
@Override
import java.util.List;
import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvParser;
import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvSerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.Srgb;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.originator.srgb.tlv.SrgbValue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.originator.srgb.tlv.SrgbValueBuilder;
"Number of SRGBs does not fit available bytes.");
final List<SrgbValue> ret = new ArrayList<>();
while (buffer.isReadable()) {
- ret.add(new SrgbValueBuilder().setBase(new Srgb((long) buffer.readUnsignedMedium()))
- .setRange(new Srgb((long) buffer.readUnsignedMedium())).build());
+ ret.add(new SrgbValueBuilder().setBase(new Srgb(ByteBufUtils.readUint24(buffer)))
+ .setRange(new Srgb(ByteBufUtils.readUint24(buffer))).build());
}
return ret;
}
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
break;
case ADMIN_GROUP:
- builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
+ builder.setAdminGroup(new AdministrativeGroup(ByteBufUtils.readUint32(value)));
LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case MAX_BANDWIDTH:
break;
// Performance Metrics
case LINK_DELAY:
- builder.setLinkDelay(new Delay(value.readUnsignedInt()));
+ builder.setLinkDelay(new Delay(ByteBufUtils.readUint32(value)));
LOG.debug("Parsed Link Delay {}", builder.getLinkDelay());
break;
case LINK_MIN_MAX_DELAY:
builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder()
- .setMinDelay(new Delay(value.readUnsignedInt()))
- .setMaxDelay(new Delay(value.readUnsignedInt())).build());
+ .setMinDelay(new Delay(ByteBufUtils.readUint32(value)))
+ .setMaxDelay(new Delay(ByteBufUtils.readUint32(value)))
+ .build());
LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay());
break;
case DELAY_VARIATION:
- builder.setDelayVariation(new Delay(value.readUnsignedInt()));
+ builder.setDelayVariation(new Delay(ByteBufUtils.readUint32(value)));
LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation());
break;
case LINK_LOSS:
- builder.setLinkLoss(new Loss(value.readUnsignedInt()));
+ builder.setLinkLoss(new Loss(ByteBufUtils.readUint32(value)));
LOG.debug("Parsed Link Loss {}", builder.getLinkLoss());
break;
case RESIDUAL_BANDWIDTH:
for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH);
unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(
- new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
+ new Bandwidth(ByteArray.readAllBytes(v))).setPriority(Uint8.valueOf(i)).build());
}
builder.setUnreservedBandwidth(unreservedBandwidth);
LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
while (value.isReadable()) {
- sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
+ sharedRiskLinkGroups.add(new SrlgId(ByteBufUtils.readUint32(value)));
}
builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrAlgorithm;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrCapabilities;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static void parseTopologyId(final List<TopologyIdentifier> topologyMembership, final ByteBuf value) {
while (value.isReadable()) {
final TopologyIdentifier topId = new TopologyIdentifier(
- value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+ Uint16.valueOf(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET));
topologyMembership.add(topId);
LOG.debug("Parsed Topology Identifier: {}", topId);
}
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
parseExtendedRouteTags(exRouteTags, value);
break;
case PREFIX_METRIC:
- final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
+ final IgpMetric metric = new IgpMetric(ByteBufUtils.readUint32(value));
builder.setPrefixMetric(metric);
LOG.debug("Parsed Metric: {}", metric);
break;
import java.util.List;
import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleBindingSubTlvsRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.prefix.state.SrBindingSidLabels;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrBindingSidLabelsBuilder;
public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) {
final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder();
- bindingSid.setWeight(new Weight(buffer.readUnsignedByte()));
+ bindingSid.setWeight(new Weight(ByteBufUtils.readUint8(buffer)));
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
bindingSid.setFlags(parseBindingSidFlags(flags, protocolId));
buffer.skipBytes(RESERVED_BINDING_SID);
import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser.Size;
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.prefix.state.SrRange;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.SrRangeBuilder;
range.setInterArea(Boolean.FALSE);
}
buffer.skipBytes(RESERVED);
- range.setRangeSize(buffer.readUnsignedShort());
+ range.setRangeSize(ByteBufUtils.readUint16(buffer));
range.setSubTlvs(parseRangeSubTlvs(buffer, protocolId));
return range.build();
}
import io.netty.buffer.Unpooled;
import java.util.Map;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.SidLabelIndex;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.Ipv6AddressCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.sid.label.index.sid.label.index.SidCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
switch (length) {
case LABEL:
return new LocalLabelCaseBuilder()
- .setLocalLabel(new MplsLabel(Long.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build();
+ .setLocalLabel(new MplsLabel(Uint32.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build();
case SID:
- return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build();
+ return new SidCaseBuilder().setSid(ByteBufUtils.readUint32(buffer)).build();
case IPV6_ADD:
return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build();
default:
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
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.attribute.SrAdjIds;
if (buffer.isReadable()) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
adjFlags = parseFlags(flags, protocolId);
- weight = new Weight(buffer.readUnsignedByte());
+ weight = new Weight(ByteBufUtils.readUint8(buffer));
buffer.skipBytes(RESERVED);
sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer);
} else {
final SidLabelIndex sidValue;
if (buffer.isReadable()) {
buffer.skipBytes(FLAGS_BYTE_SIZE);
- weight = new Weight(buffer.readUnsignedByte());
+ weight = new Weight(ByteBufUtils.readUint8(buffer));
buffer.skipBytes(RESERVED);
sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer);
} else {
final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
- srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
+ srLanAdjIdBuilder.setWeight(new Weight(ByteBufUtils.readUint8(buffer)));
buffer.skipBytes(RESERVED);
switch (protocolId) {
case IsisLevel1:
import java.util.List;
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.node.state.SrAlgorithm;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.node.state.SrAlgorithmBuilder;
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
setFlags(flags, protocol, builder);
buffer.skipBytes(RESERVERED);
- builder.setRangeSize((long) buffer.readUnsignedMedium());
+ builder.setRangeSize(ByteBufUtils.readUint24(buffer));
builder.setSidLabelIndex(SidLabelIndexParser.parseSidSubTlv(buffer));
return builder.build();
}
import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser;
import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.EroMetricCase;
@Override
public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) {
- return new EroMetricCaseBuilder().setEroMetric(new TeMetric(slice.readUnsignedInt())).build();
+ return new EroMetricCaseBuilder().setEroMetric(new TeMetric(ByteBufUtils.readUint32(slice))).build();
}
@Override
import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer;
import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.segment.routing.ext.rev151014.binding.sub.tlvs.BindingSubTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sub.tlvs.binding.sub.tlv.UnnumberedInterfaceIdEroCase;
final BitArray flags = BitArray.valueOf(buffer, Ipv4EroParser.FLAGS_SIZE);
builder.setLoose(flags.get(Ipv4EroParser.LOOSE));
buffer.skipBytes(Ipv4EroParser.RESERVED_ERO);
- builder.setRouterId(buffer.readUnsignedInt());
- builder.setInterfaceId(buffer.readUnsignedInt());
+ builder.setRouterId(ByteBufUtils.readUint32(buffer));
+ builder.setInterfaceId(ByteBufUtils.readUint32(buffer));
return builder.build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv4CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+import org.opendaylight.yangtools.yang.common.Uint32;
public final class TeLspIpv4NlriParser extends AbstractTeLspNlriCodec {
@Override
final TeLspCaseBuilder builder = new TeLspCaseBuilder();
final Ipv4CaseBuilder ipv4CaseBuilder = new Ipv4CaseBuilder();
ipv4CaseBuilder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
- builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
- builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
+ builder.setTunnelId(new TunnelId(ByteBufUtils.readUint16(buffer)));
+ builder.setLspId(new LspId(Uint32.valueOf(buffer.readUnsignedShort())));
ipv4CaseBuilder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
return builder.setAddressFamily(ipv4CaseBuilder.build()).build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.te.lsp._case.address.family.Ipv6CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+import org.opendaylight.yangtools.yang.common.Uint32;
public final class TeLspIpv6NlriParser extends AbstractTeLspNlriCodec {
@Override
final TeLspCaseBuilder builder = new TeLspCaseBuilder();
final Ipv6CaseBuilder ipv6CaseBuilder = new Ipv6CaseBuilder();
ipv6CaseBuilder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer));
- builder.setTunnelId(new TunnelId(buffer.readUnsignedShort()));
- builder.setLspId(new LspId((long) buffer.readUnsignedShort()));
+ builder.setTunnelId(new TunnelId(ByteBufUtils.readUint16(buffer)));
+ builder.setLspId(new LspId(Uint32.valueOf(buffer.readUnsignedShort())));
ipv6CaseBuilder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(buffer));
return builder.setAddressFamily(ipv6CaseBuilder.build()).build();
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
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;
@Override
public AreaIdentifier parseTlvBody(final ByteBuf value) {
- return new AreaIdentifier(value.readUnsignedInt());
+ return new AreaIdentifier(ByteBufUtils.readUint32(value));
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
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;
@Override
public AsNumber parseTlvBody(final ByteBuf value) {
- return new AsNumber(value.readUnsignedInt());
+ return new AsNumber(ByteBufUtils.readUint32(value));
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
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;
@Override
public DomainIdentifier parseTlvBody(final ByteBuf value) {
- return new DomainIdentifier(value.readUnsignedInt());
+ return new DomainIdentifier(ByteBufUtils.readUint32(value));
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
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;
@Override
public AsNumber parseTlvBody(final ByteBuf value) {
- return new AsNumber(value.readUnsignedInt());
+ return new AsNumber(ByteBufUtils.readUint32(value));
}
@Override
@Override
public TopologyIdentifier parseTlvBody(final ByteBuf value) {
- return new TopologyIdentifier(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+ return new TopologyIdentifier(Uint16.valueOf(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET));
}
@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.ByteBufUtils;
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;
final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder()
- .setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build();
+ .setIsIsRouterIdentifier(iri).setPsn(ByteBufUtils.readUint8(value)).build()).build();
}
if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) {
return new OspfNodeCaseBuilder().setOspfNode(
- new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
+ new OspfNodeBuilder().setOspfRouterId(ByteBufUtils.readUint32(value)).build()).build();
}
if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt())
- .setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
+ new OspfPseudonodeBuilder().setOspfRouterId(ByteBufUtils.readUint32(value))
+ .setLanInterface(new OspfInterfaceIdentifier(ByteBufUtils.readUint32(value))).build()).build();
}
return null;
}
package org.opendaylight.protocol.bgp.linkstate.spi;
import io.netty.buffer.ByteBuf;
-import java.math.BigInteger;
+import org.opendaylight.protocol.util.ByteBufUtils;
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;
public final CLinkstateDestination parseTypeNlri(final ByteBuf nlri) {
final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
builder.setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte()));
- builder.setIdentifier(new Identifier(BigInteger.valueOf(nlri.readLong())));
+ builder.setIdentifier(new Identifier(ByteBufUtils.readUint64(nlri)));
builder.setObjectType(parseObjectType(nlri));
return builder.build();
}
import java.util.List;
import javax.xml.bind.DatatypeConverter;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.HexString;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.Opaque;
}
public static Opaque parseOpaque(final ByteBuf buffer) {
- final short type = buffer.readUnsignedByte();
+ final Uint8 type = ByteBufUtils.readUint8(buffer);
final OpaqueValueBuilder builder = new OpaqueValueBuilder();
- switch (type) {
+ switch (type.toJava()) {
case GENERIC_LSP_IDENTIFIER:
builder.setOpaque(buildOpaqueValue(buffer));
break;
}
private static void buildExtended(final OpaqueValueBuilder builder, final ByteBuf buffer) {
- final int extendedType = buffer.readUnsignedShort();
+ final Uint16 extendedType = ByteBufUtils.readUint16(buffer);
final HexString opaqueValue = buildOpaqueValue(buffer);
builder.setOpaqueExtendedType(extendedType).setOpaque(opaqueValue);
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.mvpn.spi.attributes.tunnel.identifier.AbstractTunnelIdentifier;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.PmsiTunnelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi.tunnel.pmsi.tunnel.TunnelIdentifier;
.pmsi.tunnel.tunnel.identifier.rsvp.te.p2mp.lsp.RsvpTeP2mpLspBuilder rsvpTeP2mpLps
= new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pmsi.tunnel.rev180329.pmsi
.tunnel.pmsi.tunnel.tunnel.identifier.rsvp.te.p2mp.lsp.RsvpTeP2mpLspBuilder();
- rsvpTeP2mpLps.setP2mpId(buffer.readUnsignedInt());
- buffer.skipBytes(2);
- rsvpTeP2mpLps.setTunnelId(buffer.readUnsignedShort());
+ rsvpTeP2mpLps.setP2mpId(ByteBufUtils.readUint32(buffer));
+ buffer.skipBytes(RESERVED);
+ rsvpTeP2mpLps.setTunnelId(ByteBufUtils.readUint16(buffer));
final int ipLength = buffer.readableBytes();
rsvpTeP2mpLps.setExtendedTunnelId(parseIpAddress(ipLength, buffer));
return new RsvpTeP2mpLspBuilder().setRsvpTeP2mpLsp(rsvpTeP2mpLps.build()).build();
* 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.bgp.mvpn.impl.nlri;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.bgp.concepts.IpAddressUtil;
import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.mvpn.rev180417.c.multicast.grouping.CMulticast;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.c.multicast.grouping.CMulticastBuilder;
static CMulticast parseCMulticastGrouping(final ByteBuf buffer) {
final CMulticastBuilder builder = new CMulticastBuilder();
builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer));
- builder.setSourceAs(new AsNumber(buffer.readUnsignedInt()));
+ builder.setSourceAs(new AsNumber(ByteBufUtils.readUint32(buffer)));
builder.setMulticastSource(IpAddressUtil.addressForByteBuf(buffer));
builder.setMulticastGroup(MulticastGroupOpaqueUtil.multicastGroupForByteBuf(buffer));
return builder.build();
* 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.bgp.mvpn.impl.nlri;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.mvpn.rev180417.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.inter.as.i.pmsi.a.d.grouping.InterAsIPmsiAD;
return new InterAsIPmsiADCaseBuilder()
.setInterAsIPmsiAD(new InterAsIPmsiADBuilder()
.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer))
- .setSourceAs(new AsNumber(buffer.readUnsignedInt()))
+ .setSourceAs(new AsNumber(ByteBufUtils.readUint32(buffer)))
.build())
.build();
}
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.message.rev180329.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
final ByteBuf nlriBuf = nlri.readSlice(length);
Integer type = null;
if (length != 0) {
- builder.setOriginAs(new AsNumber(nlriBuf.readUnsignedInt()));
+ builder.setOriginAs(new AsNumber(ByteBufUtils.readUint32(nlriBuf)));
type = (int) nlriBuf.readUnsignedByte();
//Skip Subtype
nlriBuf.skipBytes(1);
*
* @return RIB AS
*/
+ // FIXME: consider using Uint32 here
long getLocalAs();
/**
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend;
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.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Prepend local AS, one time(n times not supported yet).
final BGPRouteEntryExportParameters exportParameters,
final Attributes attributes,
final SetAsPathPrepend actions) {
- return prependAS(attributes, new AsNumber(routeEntryInfo.getLocalAs()));
+ return prependAS(attributes, new AsNumber(Uint32.valueOf(routeEntryInfo.getLocalAs())));
}
}
\ No newline at end of file
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.SentBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Util for create OpenConfig Neighbor with corresponding openConfig state.
.setReceived(neighbor.isGracefulRestartReceived(tablesKey))
.setLlAdvertised(neighbor.isLlGracefulRestartAdvertised(tablesKey))
.setLlReceived(neighbor.isLlGracefulRestartReceived(tablesKey))
- .setLlStaleTimer((long) neighbor.getLlGracefulRestartTimer(tablesKey)).build();
+ .setLlStaleTimer(Uint32.valueOf(neighbor.getLlGracefulRestartTimer(tablesKey))).build();
return new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi
.safi.list.afi.safi.GracefulRestartBuilder().setState(new org.opendaylight.yang.gen.v1.http.openconfig
.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.graceful.restart.StateBuilder()
}
}
// Fallback to whatever is in the header
- return new AsNumber(open.getMyAsNumber().longValue());
+ return new AsNumber(Uint32.valueOf(open.getMyAsNumber()));
}
/**
return e;
}
+ // FIXME: Use Uint8 for this
public short getCode() {
return this.errorId.code;
}
+ // FIXME: Use Uint8 for this
public short getSubcode() {
return this.errorId.subcode;
}
*/
private static class BGPErrorIdentifier implements Serializable {
private static final long serialVersionUID = 5722575354944165734L;
+
+ // FIXME: Use Uint8 for these
final short code;
final short subcode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.",
BGPError.VERSION_NOT_SUPPORTED);
}
- final AsNumber as = new AsNumber((long) body.readUnsignedShort());
+ final AsNumber as = new AsNumber(Uint32.valueOf(body.readUnsignedShort()));
final int holdTime = body.readUnsignedShort();
if (holdTime == 1 || holdTime == 2) {
throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
final List<BgpParameters> optParams = parseParameters(body.slice(), optLength);
LOG.debug("BGP Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as,
holdTime, bgpId, optParams);
- return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer(holdTime)
+ return new OpenBuilder().setMyAsNumber(Uint16.valueOf(as.getValue())).setHoldTimer(holdTime)
.setBgpIdentifier(bgpId).setBgpParameters(optParams).build();
}
import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
import org.opendaylight.protocol.bgp.parser.spi.CapabilityUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
@Override
public CParameters parseCapability(final ByteBuf buffer) {
return new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder()
- .setAsNumber(new AsNumber(buffer.readUnsignedInt())).build()).build();
+ .setAsNumber(new AsNumber(ByteBufUtils.readUint32(buffer))).build()).build();
}
@Override
.setAfi(afi)
.setSafi(safi)
.setAfiFlags(new Tables.AfiFlags(Boolean.valueOf(afiFlags == AFI_FLAG_FORWARDING_STATE)))
- .setLongLivedStaleTime(Long.valueOf(staleTime))
+ .setLongLivedStaleTime(Uint32.valueOf(staleTime))
.build();
tables.add(table);
}
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.ReferenceCache;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
builder.setAggregator(new AggregatorBuilder()
// FIXME: above check should be expanded, so we report at least underflow errors
- .setAsNumber(this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt())))
+ .setAsNumber(this.refCache.getSharedReference(new AsNumber(ByteBufUtils.readUint32(buffer))))
.setNetworkAddress(Ipv4Util.addressForByteBuf(buffer))
.build());
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import java.math.BigInteger;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.Aigp;
LOG.warn("AIGP attribute contains unknown TLV type {}.", tlvType);
return null;
}
- return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(BigInteger.valueOf(buffer.readLong()))).build();
+ return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(ByteBufUtils.readUint64(buffer))).build();
}
/**
import com.google.common.collect.ImmutableList.Builder;
import io.netty.buffer.ByteBuf;
import java.util.List;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ReferenceCache;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
final Builder<AsNumber> coll = ImmutableList.builderWithExpectedSize(count);
for (int i = 0; i < count; i++) {
- coll.add(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt())));
+ coll.add(refCache.getSharedReference(new AsNumber(ByteBufUtils.readUint32(buffer))));
}
return coll.build();
}
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.message.rev180329.path.attributes.attributes.CommunitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Community;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Object representation of a RFC1997 Community tag. Communities are a way for the advertising entity to attach semantic
* @param semantics int
* @return new Community
*/
+ // FIXME: consider using Uint32 for asn
+ // FIXME: consider using Uint16 for semantics
public static Community create(final ReferenceCache refCache, final long asn, final int semantics) {
final CommunitiesBuilder builder = new CommunitiesBuilder();
- builder.setAsNumber(refCache.getSharedReference(new AsNumber(asn)));
- builder.setSemantics(refCache.getSharedReference(semantics));
+ builder.setAsNumber(refCache.getSharedReference(new AsNumber(Uint32.valueOf(asn))));
+ builder.setSemantics(refCache.getSharedReference(Uint16.valueOf(semantics)));
return refCache.getSharedReference(builder.build());
}
public static Community valueOf(final ReferenceCache refCache, final String string) {
final String[] parts = string.split(":", 2);
final CommunitiesBuilder builder = new CommunitiesBuilder();
- builder.setAsNumber(refCache.getSharedReference(new AsNumber(Long.valueOf(parts[0]))));
- builder.setSemantics(refCache.getSharedReference(Integer.valueOf(parts[1])));
+ builder.setAsNumber(refCache.getSharedReference(new AsNumber(Uint32.valueOf(parts[0]))));
+ builder.setSemantics(refCache.getSharedReference(Uint16.valueOf(parts[1])));
return refCache.getSharedReference(builder.build());
}
}
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPref;
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR, "Expected 4 bytes, have %s", readable);
}
- builder.setLocalPref(new LocalPrefBuilder().setPref(buffer.readUnsignedInt()).build());
+ builder.setLocalPref(new LocalPrefBuilder().setPref(ByteBufUtils.readUint32(buffer)).build());
}
@Override
import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc;
throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR,
"MULTI_EXIT_DISC has to have length 4, but has %s", readable);
}
- builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(buffer.readUnsignedInt()).build());
+ builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(ByteBufUtils.readUint32(buffer)).build());
}
@Override
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
throws BGPDocumentedException, BGPParsingException {
final RouteOriginIpv4 routeTarget = new RouteOriginIpv4Builder()
.setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
- .setLocalAdministrator(buffer.readUnsignedShort())
+ .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
.build();
return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(routeTarget).build();
}
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.types.rev180329.extended.community.ExtendedCommunity;
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder();
- builder.setGlobalAdministrator(new AsNumber(body.readUnsignedInt()));
+ builder.setGlobalAdministrator(new AsNumber(ByteBufUtils.readUint32(body)));
body.skipBytes(LOCAL_LENGTH);
return new SourceAs4ExtendedCommunityCaseBuilder().setSourceAs4ExtendedCommunity(
builder.build()).build();
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4;
public static RouteTargetIpv4 parse(final ByteBuf buffer) {
return new RouteTargetIpv4Builder()
.setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
- .setLocalAdministrator(buffer.readUnsignedShort())
+ .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
.build();
}
}
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import java.util.Optional;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
*/
public static PathId readPathId(final ByteBuf buffer) {
Preconditions.checkArgument(buffer != null && buffer.isReadable(ByteBufWriteUtil.INT_BYTES_LENGTH));
- return new PathId(buffer.readUnsignedInt());
+ return new PathId(ByteBufUtils.readUint32(buffer));
}
/**
* 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.bgp.parser.spi.extended.community;
import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufUtils;
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.types.rev180329.as._4.spec.common.As4SpecificCommon;
}
public static As4SpecificCommon parseCommon(final ByteBuf body) {
- return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(body.readUnsignedInt()))
- .setLocalAdministrator(body.readUnsignedShort()).build();
+ return new As4SpecificCommonBuilder().setAsNumber(new AsNumber(ByteBufUtils.readUint32(body)))
+ .setLocalAdministrator(ByteBufUtils.readUint16(body)).build();
}
public static void serializeCommon(final As4SpecificCommon extComm, final ByteBuf body) {
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
throw new BGPDocumentedException("Well known attribute not recognized.",
BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
}
+
+ final Uint8 typeVal = Uint8.valueOf(type);
final UnrecognizedAttributes unrecognizedAttribute = new UnrecognizedAttributesBuilder()
- .withKey(new UnrecognizedAttributesKey((short) type))
+ .withKey(new UnrecognizedAttributesKey(typeVal))
.setPartial(flags.get(PARTIAL_BIT))
.setTransitive(flags.get(TRANSITIVE_BIT))
- .setType((short) type)
+ .setType(typeVal)
.setValue(ByteArray.readBytes(buffer, len)).build();
this.unrecognizedAttributes.add(unrecognizedAttribute);
LOG.debug("Unrecognized attribute were parsed: {}", unrecognizedAttribute);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.OpenBuilder;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// <a href="http://tools.ietf.org/html/rfc6793">BGP Support for 4-Octet AS Number Space</a>
@VisibleForTesting
- static final int AS_TRANS = 23456;
+ static final Uint16 AS_TRANS = Uint16.valueOf(23456).intern();
private static final Logger LOG = LoggerFactory.getLogger(AbstractBGPSessionNegotiator.class);
private final BGPPeerRegistry registry;
private final Promise<BGPSessionImpl> promise;
}
final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
- final int as = openASNumber(preferences.getMyAs().getValue().longValue());
+ final Uint16 as = openASNumber(preferences.getMyAs().getValue().longValue());
sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(preferences.getHoldTime()).setBgpIdentifier(
preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
if (this.state != State.FINISHED) {
}
@VisibleForTesting
- static int openASNumber(final long configuredASNumber) {
+ static Uint16 openASNumber(final long configuredASNumber) {
// Return AS_TRANS if the value is bigger than 2B.
- return configuredASNumber > Values.UNSIGNED_SHORT_MAX_VALUE ? AS_TRANS : (int) configuredASNumber;
+ return configuredASNumber > Values.UNSIGNED_SHORT_MAX_VALUE ? AS_TRANS : Uint16.valueOf(configuredASNumber);
}
}
.setAfi(dto.getTableKey().getAfi())
.setSafi(dto.getTableKey().getSafi())
.setAfiFlags(new AfiFlags(dto.isForwarding()))
- .setLongLivedStaleTime((long) dto.getStaleTime())
+ .setLongLivedStaleTime(Uint32.valueOf(dto.getStaleTime()))
.build())
.collect(Collectors.toList());
return new CParametersBuilder().addAugmentation(CParameters1.class,
import static org.opendaylight.protocol.bgp.rib.impl.AbstractBGPSessionNegotiator.openASNumber;
import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class AbstractBGPSessionNegotiatorTest {
@Test
public void testOpenASNumber() {
- assertEquals(0, openASNumber(0));
- assertEquals(65535, openASNumber(65535));
+ assertEquals(Uint16.ZERO, openASNumber(0));
+ assertEquals(Uint16.MAX_VALUE, openASNumber(65535));
assertEquals(AS_TRANS, openASNumber(65536));
assertEquals(AS_TRANS, openASNumber(Integer.MAX_VALUE));
assertEquals(AS_TRANS, openASNumber(2147483648L));
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
final class PeerUtil {
static Update createUpdate(final BgpOrigin bgpOrigin,
final List<Segments> pathSegments,
+ // FIXME: consider using Uint32
final long preference,
final MpReachNlri mpReach,
final MpUnreachNlri mpUnreach) {
final Origin origin = new OriginBuilder().setValue(bgpOrigin).build();
final AsPath asPath = new AsPathBuilder().setSegments(pathSegments).build();
- final LocalPref localPref = new LocalPrefBuilder().setPref(preference).build();
+ final LocalPref localPref = new LocalPrefBuilder().setPref(Uint32.valueOf(preference)).build();
final AttributesBuilder attributeBuilder = new AttributesBuilder()
.setOrigin(origin).setAsPath(asPath).setLocalPref(localPref);
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamilies;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
private static class MockBGPSession implements BGPSession {
- private static final long AS = 30L;
+ private static final Uint32 AS = Uint32.valueOf(30).intern();
private final List<AddressFamilies> addPathAfis;
private final Set<BgpTableType> tts;
<groupId>${project.groupId}</groupId>
<artifactId>testtool-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
import org.opendaylight.protocol.util.ArgumentsInput;
import org.opendaylight.protocol.util.InetSocketAddressUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yangtools.yang.common.Uint32;
final class Arguments implements ArgumentsInput {
private static final String PROGRAM_NAME = "BGP testing tool.";
}
private interface ArgumentTypeTool<T> extends ArgumentType<T> {
- default T convert(ArgumentParser var1, Argument var2, String input) throws ArgumentParserException {
+ @Override
+ default T convert(final ArgumentParser var1, final Argument var2, final String input)
+ throws ArgumentParserException {
return convert(input);
}
parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class)
.setDefault(false).help(MULTIPATH_PARAMETER_HELP);
parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER))
- .type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Long.valueOf(as)))
- .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP);
+ .type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Uint32.valueOf(as)))
+ .setDefault(new AsNumber(Uint32.valueOf(64496))).help(AS_PARAMETER_HELP);
parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER))
.type((ArgumentTypeTool<List<String>>) extComInput ->
Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList())
* 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.bgp.testtool;
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class CommunitiesBuilder {
private static final Logger LOG = LoggerFactory.getLogger(CommunitiesBuilder.class);
+ private static final ShortAsNumber SHORT_AS = new ShortAsNumber(Uint32.valueOf(20));
private static final As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder()
- .setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build();
+ .setAsNumber(SHORT_AS).setLocalAdministrator(Uint16.valueOf(100)).build();
private static final Ipv4Address IPV4 = new Ipv4Address("192.168.1.0");
private static final byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00};
- private static final int LA = 4660;
- private static final ShortAsNumber SHORT_AS = new ShortAsNumber(20L);
+ private static final Uint16 LA = Uint16.valueOf(4660).intern();
private CommunitiesBuilder() {
throw new UnsupportedOperationException();
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
final class PrefixesBuilder {
private static final Ipv4NextHopCase NEXT_HOP;
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
- attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
- attBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.ZERO).build());
+ attBuilder.setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100L)).build());
attBuilder.setExtendedCommunities(createExtComm(extCom));
attBuilder.setUnrecognizedAttributes(Collections.emptyList());
final Ipv4PrefixesBuilder prefixes = new Ipv4PrefixesBuilder().setPrefix(addressPrefix);
if (multiPathSupport) {
- prefixes.setPathId(new PathId(5L));
+ prefixes.setPathId(new PathId(Uint32.valueOf(5)));
}
attBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class)
final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
ilab.setTed(tb.build());
if (topologyIdentifier != null) {
- ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
+ ilab.setMultiTopologyId(Uint8.valueOf(topologyIdentifier.getValue()));
}
return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021
final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
ilab.setTed(tb.build());
if (topologyIdentifier != null) {
- ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
+ ilab.setMultiTopologyId(Uint8.valueOf(topologyIdentifier.getValue()));
}
return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.slf4j.Logger;
LOG.warn("No support for table type {}, skipping it", k);
continue;
}
- final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(yangTableRootIId);
- final NodeIdentifierWithPredicates key = TablesUtil.toYangTablesKey(k);
- idb.nodeWithKey(key.getNodeType(), key.asMap());
- final TableContext ctx = new TableContext(rs, idb.build(), tree);
+ final TableContext ctx = new TableContext(rs,
+ yangTableRootIId.node(TablesUtil.toYangTablesKey(k)).toOptimized(), tree);
ctx.createTable(tx);
tx.put(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(BMP_ATTRIBUTES_QNAME)
* 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.mock;
import java.net.InetAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.peer.up.SentOpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.route.monitoring.message.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.route.monitoring.message.UpdateBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
final class BmpMockUtil {
private static final String DESCRIPTION = "OpenDaylight";
private static final String NAME = "BMP mock";
private static final int HOLD_TIMER = 180;
- private static final AsNumber ASN = new AsNumber(65431L);
+ private static final AsNumber ASN = new AsNumber(Uint32.valueOf(65431));
private static final Ipv4Address NEXT_HOP = new Ipv4Address("1.2.3.4");
- private static final PortNumber PEER_PORT = new PortNumber(179);
- private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion((short) 4);
+ private static final PortNumber PEER_PORT = new PortNumber(Uint16.valueOf(179).intern());
+ private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion(Uint8.valueOf(4));
private static final Origin ORIGIN = new OriginBuilder().setValue(BgpOrigin.Igp).build();
private static final AsPath AS_PATH = new AsPathBuilder().setSegments(Collections.emptyList()).build();
final OpenBuilder msgBuilder = new OpenBuilder();
msgBuilder.setBgpIdentifier(address);
msgBuilder.setHoldTimer(HOLD_TIMER);
- msgBuilder.setMyAsNumber(ASN.getValue().intValue());
+ msgBuilder.setMyAsNumber(Uint16.valueOf(ASN.getValue()));
msgBuilder.setVersion(PROTOCOL_VERSION);
return msgBuilder.build();
}
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.ByteBufUtils;
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;
if (reason != null) {
switch (reason) {
case REASON_ONE:
- peerDown.setLocalSystemClosed(true);
+ peerDown.setLocalSystemClosed(Boolean.TRUE);
peerDown.setData(parseBgpNotificationMessage(bytes));
break;
case REASON_TWO:
- peerDown.setLocalSystemClosed(true);
- peerDown.setData(new FsmEventCodeBuilder().setFsmEventCode(bytes.readUnsignedShort()).build());
+ peerDown.setLocalSystemClosed(Boolean.TRUE);
+ peerDown.setData(new FsmEventCodeBuilder().setFsmEventCode(ByteBufUtils.readUint16(bytes)).build());
break;
case REASON_THREE:
case REASON_FOUR:
- peerDown.setLocalSystemClosed(false);
+ peerDown.setLocalSystemClosed(Boolean.FALSE);
peerDown.setData(parseBgpNotificationMessage(bytes));
break;
case REASON_FIVE:
- peerDown.setLocalSystemClosed(false);
+ peerDown.setLocalSystemClosed(Boolean.FALSE);
break;
default:
break;
import org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser;
import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
import org.opendaylight.protocol.bmp.spi.parser.BmpTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
} else {
peerUpNot.setLocalAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
}
- peerUpNot.setLocalPort(new PortNumber(bytes.readUnsignedShort()));
- peerUpNot.setRemotePort(new PortNumber(bytes.readUnsignedShort()));
+ peerUpNot.setLocalPort(new PortNumber(ByteBufUtils.readUint16(bytes)));
+ peerUpNot.setRemotePort(new PortNumber(ByteBufUtils.readUint16(bytes)));
try {
final Notification opSent = this.msgRegistry
.parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.RejectedPrefixesTlv;
if (buffer == null) {
return null;
}
- return new RejectedPrefixesTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new RejectedPrefixesTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
* 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.parser.tlv;
import com.google.common.base.Preconditions;
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.DuplicatePrefixAdvertisementsTlv;
if (buffer == null) {
return null;
}
- return new DuplicatePrefixAdvertisementsTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new DuplicatePrefixAdvertisementsTlvBuilder()
+ .setCount(new Counter32(ByteBufUtils.readUint32(buffer)))
+ .build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.DuplicateWithdrawsTlv;
if (buffer == null) {
return null;
}
- return new DuplicateWithdrawsTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new DuplicateWithdrawsTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.InvalidatedClusterListLoopTlv;
if (buffer == null) {
return null;
}
- return new InvalidatedClusterListLoopTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new InvalidatedClusterListLoopTlvBuilder()
+ .setCount(new Counter32(ByteBufUtils.readUint32(buffer)))
+ .build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.InvalidatedAsPathLoopTlv;
if (buffer == null) {
return null;
}
- return new InvalidatedAsPathLoopTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new InvalidatedAsPathLoopTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.InvalidatedOriginatorIdTlv;
if (buffer == null) {
return null;
}
- return new InvalidatedOriginatorIdTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new InvalidatedOriginatorIdTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.InvalidatedAsConfedLoopTlv;
if (buffer == null) {
return null;
}
- return new InvalidatedAsConfedLoopTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new InvalidatedAsConfedLoopTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.UpdatesTreatedAsWithdrawTlv;
if (buffer == null) {
return null;
}
- return new UpdatesTreatedAsWithdrawTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new UpdatesTreatedAsWithdrawTlvBuilder()
+ .setCount(new Counter32(ByteBufUtils.readUint32(buffer)))
+ .build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.PrefixesTreatedAsWithdrawTlv;
if (buffer == null) {
return null;
}
- return new PrefixesTreatedAsWithdrawTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new PrefixesTreatedAsWithdrawTlvBuilder()
+ .setCount(new Counter32(ByteBufUtils.readUint32(buffer)))
+ .build();
}
}
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
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.DuplicateUpdatesTlv;
if (buffer == null) {
return null;
}
- return new DuplicateUpdatesTlvBuilder().setCount(new Counter32(buffer.readUnsignedInt())).build();
+ return new DuplicateUpdatesTlvBuilder().setCount(new Counter32(ByteBufUtils.readUint32(buffer))).build();
}
}
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
} else {
phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
}
- phBuilder.setAs(new AsNumber(bytes.readUnsignedInt()));
+ phBuilder.setAs(new AsNumber(ByteBufUtils.readUint32(bytes)));
phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
- phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt()));
- phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt()));
+ phBuilder.setTimestampSec(new Timestamp(ByteBufUtils.readUint32(bytes)));
+ phBuilder.setTimestampMicro(new Timestamp(ByteBufUtils.readUint32(bytes)));
return phBuilder.build();
}
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private void putCount(final long totalCount) {
final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
- final Counter counter = new CounterBuilder().setId(this.counterId).setCount(totalCount).build();
+ final Counter counter = new CounterBuilder().setId(this.counterId).setCount(Uint32.valueOf(totalCount)).build();
wTx.put(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId, counter);
wTx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on CLASS TYPE OBJECT, ignoring it");
return null;
}
if (bytes.readableBytes() != SIZE) {
- throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE + "; Passed: "
- + bytes.readableBytes());
+ throw new PCEPDeserializerException("Size of byte array doesn't match defined size. Expected: " + SIZE
+ + "; Passed: " + bytes.readableBytes());
}
final ClassTypeBuilder builder = new ClassTypeBuilder();
builder.setIgnore(header.isIgnore());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass());
+ checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.",
+ object.getClass());
final ByteBuf body = Unpooled.buffer(SIZE);
body.writeZero(SIZE - 1);
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ClassType classType = ((ClassType) object).getClassType();
- Preconditions.checkArgument(classType != null, "ClassType is mandatory.");
+ checkArgument(classType != null, "ClassType is mandatory.");
writeUnsignedByte(classType.getValue(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CClose;
@Override
public CClose parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(),
+ "Array of bytes is mandatory. Cannot be null or empty.");
final CCloseBuilder builder = new CCloseBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
- builder.setReason(bytes.readUnsignedByte());
+ builder.setReason(ByteBufUtils.readUint8(bytes));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof CClose, "Wrong instance of PCEPObject. Passed %s. Needed CCloseObject.", object.getClass());
+ checkArgument(object instanceof CClose, "Wrong instance of PCEPObject. Passed %s. Needed CCloseObject.",
+ object.getClass());
final CClose obj = (CClose) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(RESERVED + FLAGS_F_LENGTH);
- Preconditions.checkArgument(obj.getReason() != null, "Reason is mandatory.");
+ checkArgument(obj.getReason() != null, "Reason is mandatory.");
writeUnsignedByte(obj.getReason(), body);
serializeTlvs(obj.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
@Override
- protected final void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
+ protected void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
if (!tlvs.isEmpty()) {
builder.setVendorInformationTlv(tlvs);
}
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(FLAGS_F_LENGTH + RESERVED);
- builder.setType(bytes.readUnsignedByte());
- builder.setValue(bytes.readUnsignedByte());
+ builder.setType(ByteBufUtils.readUint8(bytes));
+ builder.setValue(ByteBufUtils.readUint8(bytes));
parseTlvs(builder, bytes.slice());
return builder.build();
}
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.gc.object.Gc;
@Override
public Gc parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final GcBuilder builder = new GcBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setMaxHop(bytes.readUnsignedByte());
- builder.setMaxUtilization(bytes.readUnsignedByte());
- builder.setMinUtilization(bytes.readUnsignedByte());
- builder.setOverBookingFactor(bytes.readUnsignedByte());
+ builder.setMaxHop(ByteBufUtils.readUint8(bytes));
+ builder.setMaxUtilization(ByteBufUtils.readUint8(bytes));
+ builder.setMinUtilization(ByteBufUtils.readUint8(bytes));
+ builder.setOverBookingFactor(ByteBufUtils.readUint8(bytes));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Gc,
+ checkArgument(object instanceof Gc,
"Wrong instance of PCEPObject. Passed %s. Needed GcObject.", object.getClass());
final Gc specObj = (Gc) object;
final ByteBuf body = Unpooled.buffer();
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(RESERVED + FLAGS_F_LENGTH);
- builder.setMaxLsp(bytes.readUnsignedByte());
+ builder.setMaxLsp(ByteBufUtils.readUint8(bytes));
builder.setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes)));
return builder.build();
}
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
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.List;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.Lspa;
@Override
public Lspa parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final LspaBuilder builder = new LspaBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setExcludeAny(new AttributeFilter(bytes.readUnsignedInt()));
- builder.setIncludeAll(new AttributeFilter(bytes.readUnsignedInt()));
- builder.setIncludeAny(new AttributeFilter(bytes.readUnsignedInt()));
- builder.setSetupPriority(bytes.readUnsignedByte());
- builder.setHoldPriority(bytes.readUnsignedByte());
+ builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(bytes)));
+ builder.setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(bytes)));
+ builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(bytes)));
+ builder.setSetupPriority(ByteBufUtils.readUint8(bytes));
+ builder.setHoldPriority(ByteBufUtils.readUint8(bytes));
final BitArray flags = BitArray.valueOf(bytes.readByte());
builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET));
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Lspa, "Wrong instance of PCEPObject. Passed %s. Needed LspaObject.", object.getClass());
+ checkArgument(object instanceof Lspa,
+ "Wrong instance of PCEPObject. Passed %s. Needed LspaObject.", object.getClass());
final Lspa lspaObj = (Lspa) object;
final ByteBuf body = Unpooled.buffer();
writeAttributeFilter(lspaObj.getExcludeAny(), body);
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
@Override
public Metric parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (bytes.readableBytes() != SIZE) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + SIZE
- + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
+ + "; Expected: " + SIZE + ".");
}
bytes.skipBytes(RESERVED);
final BitArray flags = BitArray.valueOf(bytes.readByte());
builder.setProcessingRule(header.isProcessingRule());
builder.setBound(flags.get(B_FLAG_OFFSET));
builder.setComputed(flags.get(C_FLAG_OFFSET));
- builder.setMetricType(bytes.readUnsignedByte());
+ builder.setMetricType(ByteBufUtils.readUint8(bytes));
builder.setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH)));
return builder.build();
}
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.", object.getClass());
+ checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.",
+ object.getClass());
final Metric mObj = (Metric) object;
final ByteBuf body = Unpooled.buffer(SIZE);
body.writeZero(RESERVED);
flags.set(C_FLAG_OFFSET, mObj.isComputed());
flags.set(B_FLAG_OFFSET, mObj.isBound());
flags.toByteBuf(body);
- Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
+ checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
writeUnsignedByte(mObj.getMetricType(), body);
writeFloat32(mObj.getValue(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
* 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.pcep.parser.object;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final MonitoringBuilder builder = new MonitoringBuilder();
buffer.readBytes(RESERVED);
final BitArray flagBits = BitArray.valueOf(buffer, FLAGS_SIZE);
final Flags flags = new Flags(flagBits.get(G_FLAG_POS), flagBits.get(I_FLAG_POS), flagBits.get(L_FLAG_POS),
flagBits.get(C_FLAG_POS), flagBits.get(P_FLAG_POS));
builder.setFlags(flags);
- builder.setMonitoringId(buffer.readUnsignedInt());
+ builder.setMonitoringId(ByteBufUtils.readUint32(buffer));
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, buffer.slice());
builder.setTlvs(tbuilder.build());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Monitoring, "Wrong instance of PCEPObject. Passed %s. Needed MonitoringObject.", object.getClass());
+ checkArgument(object instanceof Monitoring, "Wrong instance of PCEPObject. Passed %s. Needed MonitoringObject.",
+ object.getClass());
final Monitoring monitoring = (Monitoring) object;
final ByteBuf body = Unpooled.buffer();
body.writeZero(RESERVED);
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
@Override
public NoPath parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final NoPathBuilder builder = new NoPathBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setNatureOfIssue(bytes.readUnsignedByte());
+ builder.setNatureOfIssue(ByteBufUtils.readUint8(bytes));
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET));
bytes.skipBytes(RESERVED_F_LENGTH);
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof NoPath, "Wrong instance of PCEPObject. Passed %s. Needed NoPathObject.", object.getClass());
+ checkArgument(object instanceof NoPath, "Wrong instance of PCEPObject. Passed %s. Needed NoPathObject.",
+ object.getClass());
final NoPath nPObj = (NoPath) object;
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
+ checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
writeUnsignedByte(nPObj.getNatureOfIssue(), body);
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
bytes.skipBytes(NT_F_OFFSET);
- builder.setType(bytes.readUnsignedByte());
- builder.setValue(bytes.readUnsignedByte());
+ builder.setType(ByteBufUtils.readUint8(bytes));
+ builder.setValue(ByteBufUtils.readUint8(bytes));
parseTlvs(builder, bytes.slice());
return builder.build();
}
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OfId;
final OfBuilder builder = new OfBuilder();
builder.setIgnore(header.isIgnore());
builder.setProcessingRule(header.isProcessingRule());
- builder.setCode(new OfId(bytes.readUnsignedShort()));
+ builder.setCode(new OfId(ByteBufUtils.readUint16(bytes)));
bytes.readBytes(RESERVED);
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
}
@Override
- protected final void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
+ protected void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
if (!tlvs.isEmpty()) {
builder.setVendorInformationTlv(tlvs);
}
* 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.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
import org.opendaylight.protocol.pcep.spi.UnknownObject;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.Tlvs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final int versionValue = ByteArray.copyBitsRange(bytes.readByte(), VERSION_SF_OFFSET, VERSION_SF_LENGTH);
final OpenBuilder builder = new OpenBuilder();
builder.setKeepalive(keepalive);
final short deadTimer = bytes.readUnsignedByte();
if (keepalive == 0) {
- builder.setDeadTimer((short) 0);
+ builder.setDeadTimer(Uint8.ZERO);
} else {
builder.setDeadTimer(deadTimer);
}
- builder.setSessionId(bytes.readUnsignedByte());
+ builder.setSessionId(ByteBufUtils.readUint8(bytes));
final TlvsBuilder tbuilder = new TlvsBuilder();
parseTlvs(tbuilder, bytes.slice());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Open, "Wrong instance of PCEPObject. Passed %s. Needed OpenObject.", object.getClass());
+ checkArgument(object instanceof Open, "Wrong instance of PCEPObject. Passed %s. Needed OpenObject.",
+ object.getClass());
final Open open = (Open) object;
final ByteBuf body = Unpooled.buffer();
- writeUnsignedByte((short) (PCEP_VERSION << (Byte.SIZE - VERSION_SF_LENGTH)), body);
+ writeUnsignedByte((short) (PCEP_VERSION << Byte.SIZE - VERSION_SF_LENGTH), body);
writeUnsignedByte(open.getKeepalive(), body);
writeUnsignedByte(open.getDeadTimer(), body);
- Preconditions.checkArgument(open.getSessionId() != null, "SessionId is mandatory.");
+ checkArgument(open.getSessionId() != null, "SessionId is mandatory.");
writeUnsignedByte(open.getSessionId(), body);
serializeTlvs(open.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
"Array of bytes is mandatory. Can't be null or empty.");
final OverloadBuilder builder = new OverloadBuilder();
buffer.readBytes(RESERVED + FLAGS);
- builder.setDuration(buffer.readUnsignedShort());
+ builder.setDuration(ByteBufUtils.readUint16(buffer));
return builder.build();
}
}
*/
package org.opendaylight.protocol.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof ProcTime,
+ checkArgument(object instanceof ProcTime,
"Wrong instance of PCEPObject. Passed %s. Needed ProcTimeObject.", object.getClass());
final ProcTime procTime = (ProcTime) object;
final ByteBuf body = Unpooled.buffer(BODY_SIZE);
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
+ checkArgument(buffer != null && buffer.isReadable(),
"Array of bytes is mandatory. Can't be null or empty.");
- final ProcTimeBuilder builder = new ProcTimeBuilder();
buffer.skipBytes(RESERVED);
final BitArray flagBits = BitArray.valueOf(buffer, FLAGS);
- builder.setEstimated(flagBits.get(E_FLAG_POSITION));
- builder.setCurrentProcTime(buffer.readUnsignedInt());
- builder.setMinProcTime(buffer.readUnsignedInt());
- builder.setMaxProcTime(buffer.readUnsignedInt());
- builder.setAverageProcTime(buffer.readUnsignedInt());
- builder.setVarianceProcTime(buffer.readUnsignedInt());
- return builder.build();
+
+ return new ProcTimeBuilder()
+ .setEstimated(flagBits.get(E_FLAG_POSITION))
+ .setCurrentProcTime(ByteBufUtils.readUint32(buffer))
+ .setMinProcTime(ByteBufUtils.readUint32(buffer))
+ .setMaxProcTime(ByteBufUtils.readUint32(buffer))
+ .setAverageProcTime(ByteBufUtils.readUint32(buffer))
+ .setVarianceProcTime(ByteBufUtils.readUint32(buffer))
+ .build();
}
}
* 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.pcep.parser.object;
+import static com.google.common.base.Preconditions.checkArgument;
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.List;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.Tlvs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.rp.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Parser for {@link Rp}
@Override
public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
- Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
final RpBuilder builder = new RpBuilder();
priority |= (flags.get(PRI_SF_OFFSET + 1) ? 1 : 0) << 1;
priority |= (flags.get(PRI_SF_OFFSET) ? 1 : 0) << 2;
if (priority != 0) {
- builder.setPriority(priority);
+ builder.setPriority(Uint8.valueOf(priority));
}
builder.setFragmentation(flags.get(F_FLAG_OFFSET));
builder.setP2mp(flags.get(N_FLAG_OFFSET));
builder.setBiDirectional(flags.get(B_FLAG_OFFSET));
builder.setReoptimization(flags.get(R_FLAG_OFFSET));
- builder.setRequestId(new RequestId(bytes.readUnsignedInt()));
+ builder.setRequestId(new RequestId(ByteBufUtils.readUint32(bytes)));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
builder.setTlvs(tlvsBuilder.build());
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof Rp, "Wrong instance of PCEPObject. Passed %s. Needed RPObject.", object.getClass());
+ checkArgument(object instanceof Rp, "Wrong instance of PCEPObject. Passed %s. Needed RPObject.",
+ object.getClass());
final ByteBuf body = Unpooled.buffer();
final Rp rpObj = (Rp) object;
final BitArray flags = new BitArray(FLAGS_SIZE);
res[res.length - 1] = (byte) (res[res.length - 1] | p);
}
body.writeBytes(res);
- Preconditions.checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
+ checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
writeUnsignedInt(rpObj.getRequestId().getValue(), body);
serializeTlvs(rpObj.getTlvs(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
final List<RequestId> requestIDs = new ArrayList<>();
while (bytes.isReadable()) {
- requestIDs.add(new RequestId(bytes.readUnsignedInt()));
+ requestIDs.add(new RequestId(ByteBufUtils.readUint32(bytes)));
}
if (requestIDs.isEmpty()) {
throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
flags.toByteBuf(body);
final List<RequestId> requestIDs = svecObj.getRequestsIds();
- assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
+ assert !requestIDs.isEmpty() : "Empty Svec Object - no request ids.";
for (final RequestId requestId : requestIDs) {
writeUnsignedInt(requestId.getValue(), body);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
-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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
final class AsNumberCaseParser {
private static final int CONTENT_LENGTH = 2;
static AsNumberCase parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
- return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer.readUnsignedShort())).build()).build();
+ return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(
+ new AsNumber(Uint32.valueOf(buffer.readUnsignedShort()))).build()).build();
}
static ByteBuf serializeSubobject(final AsNumberCase asCase) {
final AsNumberSubobject asNumber = asCase.getAsNumber();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
+ checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
return body;
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject;
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
final SubobjectBuilder builder = new SubobjectBuilder();
builder.setLoose(loose);
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
buffer.skipBytes(RESERVED);
- ubuilder.setRouterId(buffer.readUnsignedInt());
- ubuilder.setInterfaceId(buffer.readUnsignedInt());
+ ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
+ ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
return builder.build();
}
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
+ "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(RESERVED);
- Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+ checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
writeUnsignedInt(specObj.getRouterId(), body);
- Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory");
+ checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory");
writeUnsignedInt(specObj.getInterfaceId(), body);
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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 org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class RROPathKey128SubobjectParser implements RROSubobjectParser {
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT128_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
- + CONTENT128_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: >" + CONTENT128_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
final SubobjectBuilder builder = new SubobjectBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
body.writeBytes(pk.getPceId().getValue());
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import com.google.common.base.Preconditions;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(),
+ "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: >" + CONTENT_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
final SubobjectBuilder builder = new SubobjectBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
+ "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
final byte[] pceId = pk.getPceId().getValue();
if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
RROPathKey128SubobjectParser.serializeSubobject(subobject,buffer);
}
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
body.writeBytes(pceId);
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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.RROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject;
@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
final SubobjectBuilder builder = new SubobjectBuilder();
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
buffer.skipBytes(RESERVED);
- ubuilder.setRouterId(buffer.readUnsignedInt());
- ubuilder.setInterfaceId(buffer.readUnsignedInt());
+ ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
+ ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
return builder.build();
}
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
+ "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
flags.toByteBuf(body);
body.writeZero(RESERVED);
- Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+ checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
writeUnsignedInt(specObj.getRouterId(), body);
- Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
+ checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
writeUnsignedInt(specObj.getInterfaceId(), body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder;
@Override
public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != LABEL_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + LABEL_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + LABEL_LENGTH + ".");
}
- return new Type1LabelCaseBuilder().setType1Label(new Type1LabelBuilder().setType1Label(buffer.readUnsignedInt()).build()).build();
+ return new Type1LabelCaseBuilder()
+ .setType1Label(new Type1LabelBuilder().setType1Label(ByteBufUtils.readUint32(buffer)).build())
+ .build();
}
@Override
- public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject instanceof Type1LabelCase, "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
+ public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject,
+ final ByteBuf buffer) {
+ checkArgument(subobject instanceof Type1LabelCase,
+ "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
- Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
+ checkArgument(type1Label != null, "Type1Label is mandatory.");
writeUnsignedInt(type1Label.getType1Label(), body);
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder;
@Override
public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
- final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
- builder.setWavebandId(buffer.readUnsignedInt());
- builder.setStartLabel(buffer.readUnsignedInt());
- builder.setEndLabel(buffer.readUnsignedInt());
- return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
+ return new WavebandSwitchingLabelCaseBuilder()
+ .setWavebandSwitchingLabel(new WavebandSwitchingLabelBuilder()
+ .setWavebandId(ByteBufUtils.readUint32(buffer))
+ .setStartLabel(ByteBufUtils.readUint32(buffer))
+ .setEndLabel(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build();
}
@Override
public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject instanceof WavebandSwitchingLabelCase, "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass());
+ checkArgument(subobject instanceof WavebandSwitchingLabelCase,
+ "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.", subobject.getClass());
final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
+ checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
writeUnsignedInt(obj.getWavebandId(), body);
- Preconditions.checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
+ checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
writeUnsignedInt(obj.getStartLabel(), body);
- Preconditions.checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
+ checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
writeUnsignedInt(obj.getEndLabel(), body);
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
final SubobjectBuilder builder = new SubobjectBuilder();
builder.setMandatory(mandatory);
if (buffer.readableBytes() != CONTENT4_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + ";");
}
final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
- final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer,
- Ipv4Util.IP4_LENGTH), length)));
+ final IpPrefixBuilder prefix = new IpPrefixBuilder()
+ .setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH),
+ length)));
builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
buffer.skipBytes(PREFIX_F_LENGTH);
builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null, "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
+ checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
+ "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
if (prefix.getIpv6Prefix() != null) {
new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
} else {
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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 org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
/**
* Parser for {@link PathKey}
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT128_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
- + CONTENT128_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: >" + CONTENT128_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
final SubobjectBuilder builder = new SubobjectBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
}
public static void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
+ "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
- .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
+ .subobjects.subobject.type.path.key._case.PathKey pk =
+ ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
body.writeBytes(pk.getPceId().getValue());
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
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 org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
/**
* Parser for {@link PathKey}
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: >" + CONTENT_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
final SubobjectBuilder builder = new SubobjectBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase, "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
+ "Unknown subobject instance. Passed %s. Needed PathKey.", subobject.getSubobjectType().getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
- .subobjects.subobject.type.path.key._case.PathKey pk = ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
+ .subobjects.subobject.type.path.key._case.PathKey pk =
+ ((PathKeyCase) subobject.getSubobjectType()).getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
final byte[] pceId = pk.getPceId().getValue();
if (pceId.length == XROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
XROPathKey128SubobjectParser.serializeSubobject(subobject,buffer);
}
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
+ checkArgument(pceId.length == PCE_ID_F_LENGTH, "PceId 32 Bit required.");
body.writeBytes(pceId);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
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.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
- final SubobjectBuilder builder = new SubobjectBuilder();
- builder.setMandatory(mandatory);
-
- builder.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer.readUnsignedInt())).build()).build());
+ final SubobjectBuilder builder = new SubobjectBuilder()
+ .setMandatory(mandatory)
+ .setSubobjectType(new SrlgCaseBuilder()
+ .setSrlg(new SrlgBuilder()
+ .setSrlgId(new SrlgId(ByteBufUtils.readUint32(buffer)))
+ .build())
+ .build());
buffer.readByte();
- builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
- return builder.build();
+ return builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()))
+ .build();
}
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase, "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof SrlgCase,
+ "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
+ checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
writeUnsignedInt(specObj.getSrlgId().getValue(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+ checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
writeUnsignedByte((Uint8) null, body);
writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
*/
package org.opendaylight.protocol.pcep.parser.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
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.XROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.XROSubobjectUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects.Attribute;
@Override
public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
- + CONTENT_LENGTH + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + "; Expected: " + CONTENT_LENGTH + ".");
}
buffer.readerIndex(buffer.readerIndex() + RESERVED);
final SubobjectBuilder builder = new SubobjectBuilder();
builder.setMandatory(mandatory);
builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte()));
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
- ubuilder.setRouterId(buffer.readUnsignedInt());
- ubuilder.setInterfaceId(buffer.readUnsignedInt());
+ ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
+ ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
return builder.build();
}
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
+ "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writeZero(RESERVED);
- writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null, body);
- Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+ writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null,
+ body);
+ checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
writeUnsignedInt(specObj.getRouterId(), body);
- Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
+ checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
writeUnsignedInt(specObj.getInterfaceId(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.tlv;
+import static com.google.common.base.Preconditions.checkArgument;
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.util.ArrayList;
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OfId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfList;
return null;
}
if (buffer.readableBytes() % OF_CODE_ELEMENT_LENGTH != 0) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ".");
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ + ".");
}
final List<OfId> ofCodes = new ArrayList<>();
while (buffer.isReadable()) {
- ofCodes.add(new OfId(buffer.readUnsignedShort()));
+ ofCodes.add(new OfId(ByteBufUtils.readUint16(buffer)));
}
return new OfListBuilder().setCodes(ofCodes).build();
}
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof OfList, "OFListTlv is mandatory.");
+ checkArgument(tlv instanceof OfList, "OFListTlv is mandatory.");
final OfList oft = (OfList) tlv;
final ByteBuf body = Unpooled.buffer();
final List<OfId> ofCodes = oft.getCodes();
*/
package org.opendaylight.protocol.pcep.parser.tlv;
+import static com.google.common.base.Preconditions.checkArgument;
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;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.order.tlv.Order;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.order.tlv.OrderBuilder;
if (buffer == null) {
return null;
}
- return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build();
+ return new OrderBuilder()
+ .setDelete(ByteBufUtils.readUint32(buffer))
+ .setSetup(ByteBufUtils.readUint32(buffer))
+ .build();
}
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
+ checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
final Order otlv = (Order) tlv;
final ByteBuf body = Unpooled.buffer();
writeUnsignedInt(otlv.getDelete(), body);
*/
package org.opendaylight.protocol.pcep.parser.tlv;
+import static com.google.common.base.Preconditions.checkArgument;
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;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.duration.tlv.OverloadDuration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.overload.duration.tlv.OverloadDurationBuilder;
if (buffer == null) {
return null;
}
- return new OverloadDurationBuilder().setDuration(buffer.readUnsignedInt()).build();
+ return new OverloadDurationBuilder().setDuration(ByteBufUtils.readUint32(buffer)).build();
}
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
+ checkArgument(tlv instanceof OverloadDuration, "OverloadedTlv is mandatory.");
final ByteBuf body = Unpooled.buffer();
writeUnsignedInt(((OverloadDuration) tlv).getDuration(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissing;
if (buffer == null) {
return null;
}
- return new ReqMissingBuilder().setRequestId(new RequestId(buffer.readUnsignedInt())).build();
+ return new ReqMissingBuilder().setRequestId(new RequestId(ByteBufUtils.readUint32(buffer))).build();
}
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.path.binding.tlv.path.binding.binding.type.value.MplsLabelEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Parser for {@link PathBinding}.
final MplsLabelEntryBuilder builder = new MplsLabelEntryBuilder();
final long entry = buffer.readUnsignedInt();
builder.setLabel(getMplsLabel(entry));
- builder.setTrafficClass((short) (entry >> TC_SHIFT & TC_MASK));
+ builder.setTrafficClass(Uint8.valueOf(entry >> TC_SHIFT & TC_MASK));
builder.setBottomOfStack((entry >> S_SHIFT & S_MASK) == 1);
- builder.setTimeToLive((short) (entry & TTL_MASK));
+ builder.setTimeToLive(Uint8.valueOf(entry & TTL_MASK));
return builder.build();
}
private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel
getMplsLabel(final long mplsStackEntry) {
return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125
- .MplsLabel(mplsStackEntry >> LABEL_SHIFT & LABEL_MASK);
+ .MplsLabel(Uint32.valueOf(mplsStackEntry >> LABEL_SHIFT & LABEL_MASK));
}
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
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.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Parser for {@link LspIdentifiers}.
buffer.readableBytes());
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(Ipv4Util.noZoneAddressForByteBuf(buffer));
- final LspId lspId = new LspId((long) buffer.readUnsignedShort());
- final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
+ 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();
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.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv6ExtendedTunnelId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Parser for {@link LspIdentifiers}.
buffer.readableBytes());
final Ipv6Builder builder = new Ipv6Builder();
builder.setIpv6TunnelSenderAddress(Ipv6Util.noZoneAddressForByteBuf(buffer));
- final LspId lspId = new LspId((long) buffer.readUnsignedShort());
- final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
+ final LspId lspId = new LspId(Uint32.valueOf(buffer.readUnsignedShort()));
+ final TunnelId tunnelId = new TunnelId(ByteBufUtils.readUint16(buffer));
builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.noZoneAddressForByteBuf(buffer)));
builder.setIpv6TunnelEndpointAddress(Ipv6Util.noZoneAddressForByteBuf(buffer));
final AddressFamily afi = new Ipv6CaseBuilder().setIpv6(builder.build()).build();
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vs.tlv.VsTlv;
+import org.opendaylight.yangtools.yang.common.Uint32;
/**
* Parser for {@link Lsp}.
builder.setProcessingRule(header.isProcessingRule());
final int[] plspIdRaw
= new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), };
- builder.setPlspId(new PlspId((long) (plspIdRaw[0] << FLAGS_SIZE | plspIdRaw[1] << FOUR_BITS_SHIFT
+ builder.setPlspId(new PlspId(Uint32.valueOf(plspIdRaw[0] << FLAGS_SIZE | plspIdRaw[1] << FOUR_BITS_SHIFT
| plspIdRaw[2] >> FOUR_BITS_SHIFT)));
parseFlags(builder, bytes);
final TlvsBuilder b = new TlvsBuilder();
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.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.error.code.tlv.LspErrorCodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
if (buffer == null) {
return null;
}
- return new LspErrorCodeBuilder().setErrorCode(buffer.readUnsignedInt()).build();
+ return new LspErrorCodeBuilder().setErrorCode(ByteBufUtils.readUint32(buffer)).build();
}
@Override
import org.opendaylight.protocol.pcep.spi.TlvUtil;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
private static UserCase parseUserError(final ByteBuf buffer) {
final UserErrorBuilder error = new UserErrorBuilder();
- error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt()));
- error.setSubOrg(buffer.readUnsignedByte());
+ error.setEnterprise(new EnterpriseNumber(ByteBufUtils.readUint32(buffer)));
+ error.setSubOrg(ByteBufUtils.readUint8(buffer));
final int errDescrLength = buffer.readUnsignedByte();
- error.setValue(buffer.readUnsignedShort());
+ error.setValue(ByteBufUtils.readUint16(buffer));
error.setDescription(ByteArray.bytesToHRString(ByteArray.readBytes(buffer, errDescrLength)));
// if we have any subobjects, place the implementation here
return new UserCaseBuilder().setUserError(error.build()).build();
}
final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
builder.setFlags(new Flags(flags.get(IN_PLACE), flags.get(NOT_GUILTY)));
- final short errorCode = buffer.readUnsignedByte();
- builder.setCode(errorCode);
- final int errorValue = buffer.readUnsignedShort();
- builder.setValue(errorValue);
+ builder.setCode(ByteBufUtils.readUint8(buffer));
+ builder.setValue(ByteBufUtils.readUint16(buffer));
return new RsvpCaseBuilder().setRsvpError(builder.build()).build();
}
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.TlvRegistry;
import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SrpIdNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.Srp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.SrpBuilder;
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes()
+ "; Expected: >=" + MIN_SIZE + ".");
}
- final SrpBuilder builder = new SrpBuilder();
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
+ final SrpBuilder builder = new SrpBuilder()
+ .setIgnore(header.isIgnore())
+ .setProcessingRule(header.isProcessingRule());
parseFlags(builder, bytes);
- builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
+ builder.setOperationId(new SrpIdNumber(ByteBufUtils.readUint32(bytes)));
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
parseTlvs(tlvsBuilder, bytes.slice());
- builder.setTlvs(tlvsBuilder.build());
- return builder.build();
+ return builder.setTlvs(tlvsBuilder.build()).build();
}
protected void parseFlags(final SrpBuilder builder, final ByteBuf bytes) {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final List<PCEPCapability> capabilities) {
if (keepAlive != 0) {
Preconditions.checkArgument(keepAlive >= 1, "Minimum value for keep-alive-timer-value is 1");
- if (deadTimer != 0 && (deadTimer / keepAlive != KA_TO_DEADTIMER_RATIO)) {
+ if (deadTimer != 0 && deadTimer / keepAlive != KA_TO_DEADTIMER_RATIO) {
LOG.warn("dead-timer-value should be {} times greater than keep-alive-timer-value",
KA_TO_DEADTIMER_RATIO);
}
oBuilder.setSessionId((short) sessionId);
oBuilder.setKeepalive((short) BasePCEPSessionProposalFactory.this.keepAlive);
if (BasePCEPSessionProposalFactory.this.keepAlive == 0) {
- oBuilder.setDeadTimer((short) 0);
+ oBuilder.setDeadTimer(Uint8.ZERO);
} else {
oBuilder.setDeadTimer((short) BasePCEPSessionProposalFactory.this.deadTimer);
}
public final synchronized ChannelFuture createServer(final PCEPDispatcherDependencies dispatcherDependencies) {
this.keys = dispatcherDependencies.getKeys();
- @SuppressWarnings("unchecked") final ChannelPipelineInitializer initializer = (ch, promise) -> {
+ final ChannelPipelineInitializer initializer = (ch, promise) -> {
ch.pipeline().addLast(this.hf.getDecoders());
ch.pipeline().addLast("negotiator", this.snf
.getSessionNegotiator(dispatcherDependencies, ch, promise));
parser.parseLabel(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseLabel(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseLabel(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseLabel(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseObject(new ObjectHeaderImpl(true, true), null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseObject(new ObjectHeaderImpl(true, true), Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
}
package org.opendaylight.protocol.pcep.impl;
import io.netty.buffer.ByteBuf;
-
import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
import org.opendaylight.protocol.pcep.parser.object.AbstractVendorInformationObjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
+import org.opendaylight.yangtools.yang.common.Uint32;
public class TestVendorInformationObjectParser extends AbstractVendorInformationObjectParser {
- private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
+ private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(Uint32.ZERO);
public TestVendorInformationObjectParser() {
super(0, 0);
import org.opendaylight.protocol.pcep.parser.tlv.AbstractVendorInformationTlvParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
+import org.opendaylight.yangtools.yang.common.Uint32;
public class TestVendorInformationTlvParser extends AbstractVendorInformationTlvParser {
- private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
+ private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(Uint32.ZERO);
@Override
public void serializeEnterpriseSpecificInformation(
for (int i = 1; i <= lsps; i++) {
final PCCTunnel tunnel = new PCCTunnel(MsgBuilderUtil.getDefaultPathName(address, Uint32.valueOf(i)),
PCC_DELEGATION, LspType.PCC_LSP, createPath(Lists.newArrayList(DEFAULT_ENDPOINT_HOP)));
- tunnels.put(new PlspId((long) i), tunnel);
+ tunnels.put(new PlspId(Uint32.valueOf(i)), tunnel);
}
return tunnels;
}
}
protected void addTunnel(final Requests request, final PCCSession session) {
- final PlspId plspId = new PlspId(this.plspIDsCounter.incrementAndGet());
+ final PlspId plspId = new PlspId(Uint32.valueOf(this.plspIDsCounter.incrementAndGet()));
final PCCTunnel tunnel = new PCCTunnel(request.getLsp().getTlvs().getSymbolicPathName()
.getPathName().getValue(), session.getId(), LspType.PCE_LSP, reqToRptPath(request));
sendToAll(tunnel, plspId, request.getEro().getSubobject(),
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.Ipv4ExtendedTunnelId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
.setIpv4TunnelSenderAddress(new Ipv4AddressNoZone(tunnelSender))
.setIpv4ExtendedTunnelId(
new Ipv4ExtendedTunnelId(extendedTunnelAddress))
- .build()).build()).setTunnelId(new TunnelId(lspId.intValue())).build());
+ .build()).build()).setTunnelId(new TunnelId(Uint16.valueOf(lspId))).build());
if (symbolicPathName) {
if (symbolicName.isPresent()) {
tlvs.setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
.setLocalIpAddress(new IpAddressNoZone(Ipv6Util.noZoneAddressForByteBuf(buffer)))
.setRemoteIpAddress(new IpAddressNoZone(Ipv6Util.noZoneAddressForByteBuf(buffer))).build();
case Unnumbered:
- return new UnnumberedAdjacencyBuilder().setLocalNodeId(buffer.readUnsignedInt())
- .setLocalInterfaceId(buffer.readUnsignedInt()).setRemoteNodeId(buffer.readUnsignedInt())
- .setRemoteInterfaceId(buffer.readUnsignedInt()).build();
+ return new UnnumberedAdjacencyBuilder()
+ .setLocalNodeId(ByteBufUtils.readUint32(buffer))
+ .setLocalInterfaceId(ByteBufUtils.readUint32(buffer))
+ .setRemoteNodeId(ByteBufUtils.readUint32(buffer))
+ .setRemoteInterfaceId(ByteBufUtils.readUint32(buffer)).build();
default:
return null;
}
* 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.pcep.segment.routing;
import java.net.InetSocketAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.Tlvs1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
+import org.opendaylight.yangtools.yang.common.Uint8;
public class PCEPSegmentRoutingCapability implements PCEPCapability {
public void setCapabilityProposal(final InetSocketAddress address, final TlvsBuilder builder) {
if (this.isSegmentRoutingCapable) {
builder.addAugmentation(Tlvs1.class,
- new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd((short) 0).build())
+ new Tlvs1Builder().setSrPceCapability(new SrPceCapabilityBuilder().setMsd(Uint8.ZERO).build())
.build());
}
}
*/
package org.opendaylight.protocol.pcep.segment.routing;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
-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;
import org.opendaylight.protocol.pcep.spi.TlvUtil;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapability;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.pce.capability.tlv.SrPceCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
+ checkArgument(tlv instanceof SrPceCapability, "SrPceCapability is mandatory.");
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
body.writerIndex(OFFSET);
writeUnsignedByte(((SrPceCapability) tlv).getMsd(), body);
if (buffer == null) {
return null;
}
- final short msd = buffer.readerIndex(OFFSET).readUnsignedByte();
- return new SrPceCapabilityBuilder().setMsd(msd).build();
+ return new SrPceCapabilityBuilder()
+ .setMsd(ByteBufUtils.readUint8(buffer.readerIndex(OFFSET)))
+ .build();
}
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
/**
* Parser for {@link PathKey}.
checkArgument(buffer != null && buffer.isReadable(),
"Array of bytes is mandatory. Can't be null or empty.");
checkContentLength(buffer.readableBytes());
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = readPceId(buffer);
final PathKeyBuilder pBuilder = new PathKeyBuilder();
pBuilder.setPceId(new PceId(pceId));
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.PcerrBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
- final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt());
+ final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(bytesToPass));
final Optional<? extends Object> obj = this.registry.parseVendorInformationObject(enterpriseNumber,
header, bytesToPass);
if (obj.isPresent()) {
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
if (VendorInformationUtil.isVendorInformationTlv(type)) {
- final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt());
+ final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(ByteBufUtils.readUint32(tlvBytes));
final Optional<VendorInformationTlv> viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber,
tlvBytes);
if (viTlv.isPresent()) {
*/
final class PCEPErrorIdentifier implements Serializable {
private static final long serialVersionUID = 2434590156751699872L;
+
+ // FIXME: these should be Uint8s
private final short type;
private final short value;
return this.errorId;
}
+ // FIXME: these should be Uint8s
public short getErrorType() {
return this.errorId.getType();
}
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public abstract class AbstractTopologySessionListener<S, L> implements TopologySessionListener, TopologySessionStats {
static final MessageHeader MESSAGE_HEADER = new MessageHeader() {
- private final ProtocolVersion version = new ProtocolVersion((short) 1);
+ private final ProtocolVersion version = new ProtocolVersion(Uint8.ONE);
@Override
public Class<MessageHeader> implementedInterface() {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client.attributes.path.computation.client.reported.lsp.Path;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class Stateful07TopologySessionListener extends AbstractTopologySessionListener<SrpIdNumber, PlspId> {
private static final Logger LOG = LoggerFactory.getLogger(Stateful07TopologySessionListener.class);
+ private static final PlspId PLSPID_ZERO = new PlspId(Uint32.ZERO);
private final AtomicLong requestId = new AtomicLong(1L);
private SrpIdNumber createUpdateMessageSync(final PcupdMessageBuilder pcupdMessageBuilder) {
final UpdatesBuilder updBuilder = new UpdatesBuilder();
// LSP mandatory in Upd
- final Lsp lsp = new LspBuilder().setPlspId(new PlspId(0L)).setSync(Boolean.TRUE).build();
+ final Lsp lsp = new LspBuilder().setPlspId(PLSPID_ZERO).setSync(Boolean.TRUE).build();
// SRP Mandatory in Upd
final SrpBuilder srpBuilder = new SrpBuilder();
// not sue whether use 0 instead of nextRequest() or do not insert srp == SRP-ID-number = 0
return true;
}
- private Path buildPath(final Reports report, final Srp srp, final Lsp lsp) {
+ private static Path buildPath(final Reports report, final Srp srp, final Lsp lsp) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client
.attributes.path.computation.client.reported.lsp.PathBuilder pb = new org.opendaylight.yang.gen.v1
.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev181109.pcep.client.attributes.path.computation
}
private SrpIdNumber nextRequest() {
- return new SrpIdNumber(this.requestId.getAndIncrement());
+ return new SrpIdNumber(Uint32.valueOf(this.requestId.getAndIncrement()));
}
@Override
new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(this.input.getName()
.getBytes(StandardCharsets.UTF_8))).build());
- final SrpBuilder srpBuilder = new SrpBuilder();
- srpBuilder.setOperationId(nextRequest());
- srpBuilder.setProcessingRule(Boolean.TRUE);
+ final SrpBuilder srpBuilder = new SrpBuilder()
+ .setOperationId(nextRequest())
+ .setProcessingRule(Boolean.TRUE);
if (!PSTUtil.isDefaultPST(args.getPathSetupType())) {
srpBuilder.setTlvs(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf
}
rb.setSrp(srpBuilder.build());
- rb.setLsp(new LspBuilder().setAdministrative(inputLsp.isAdministrative()).setDelegate(
- inputLsp.isDelegate()).setPlspId(new PlspId(0L)).setTlvs(tlvsBuilder.build()).build());
-
- final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
- ib.setRequests(Collections.singletonList(rb.build()));
+ rb.setLsp(new LspBuilder()
+ .setAdministrative(inputLsp.isAdministrative())
+ .setDelegate(inputLsp.isDelegate())
+ .setPlspId(PLSPID_ZERO)
+ .setTlvs(tlvsBuilder.build())
+ .build());
// Send the message
- return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(),
- rb.getSrp().getOperationId(), this.input.getArguments().getMetadata());
+ return sendMessage(new PcinitiateBuilder()
+ .setPcinitiateMessage(new PcinitiateMessageBuilder(MESSAGE_HEADER)
+ .setRequests(Collections.singletonList(rb.build()))
+ .build())
+ .build(),
+ rb.getSrp().getOperationId(), this.input.getArguments().getMetadata());
}
}
*/
package org.opendaylight.bgpcep.programming;
-import java.math.BigInteger;
+import java.util.concurrent.TimeUnit;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public final class NanotimeUtil {
private static final Logger LOG = LoggerFactory.getLogger(NanotimeUtil.class);
- private static final BigInteger MILLION = BigInteger.valueOf(1000000);
- private static volatile BigInteger nanoTimeOffset = null;
+
+ private static volatile Long nanoTimeOffset = null;
private NanotimeUtil() {
throw new UnsupportedOperationException();
* @return Nanotime object filled with current time in nanoseconds.
*/
public static Nanotime currentTime() {
- return new Nanotime(BigInteger.valueOf(System.currentTimeMillis()).multiply(MILLION));
+ final long millis = Uint64.valueOf(System.currentTimeMillis()).longValue();
+ return new Nanotime(Uint64.fromLongBits(TimeUnit.MILLISECONDS.toNanos(millis)));
}
/**
if (nanoTimeOffset == null) {
calibrate();
}
- return new Nanotime(BigInteger.valueOf(System.nanoTime()).add(nanoTimeOffset));
+ return new Nanotime(Uint64.fromLongBits(System.nanoTime() + nanoTimeOffset.longValue()));
}
/**
LOG.debug("Calibrated currentTime and nanoTime to {}m <= {}n <= {}m <= {}n", tm1, nt1, tm2, nt2);
- final BigInteger tm = BigInteger.valueOf(tm1).add(BigInteger.valueOf(tm2)).divide(BigInteger.valueOf(2));
- final BigInteger nt = BigInteger.valueOf(nt1).add(BigInteger.valueOf(nt2)).divide(BigInteger.valueOf(2));
+ final long tm = (tm1 + tm2) / 2;
+ final long nt = (nt1 + nt2) / 2;
- nanoTimeOffset = tm.multiply(MILLION).subtract(nt);
+ nanoTimeOffset = Long.valueOf(TimeUnit.MILLISECONDS.toNanos(tm) - nt);
}
}
* 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.rsvp.parser.impl.subobject;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeShort;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
public final class AsNumberCaseParser {
private static final int CONTENT_LENGTH = 2;
}
public static AsNumberCase parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; " + "Expected: " + CONTENT_LENGTH + ".");
}
- return new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer
- .readUnsignedShort())).build()).build();
+ return new AsNumberCaseBuilder()
+ .setAsNumber(new AsNumberBuilder()
+ .setAsNumber(new AsNumber(Uint32.valueOf(buffer.readUnsignedShort())))
+ .build())
+ .build();
}
public static ByteBuf serializeSubobject(final AsNumberCase asCase) {
final AsNumberSubobject asNumber = asCase.getAsNumber();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
+ checkArgument(asNumber.getAsNumber() != null, "AsNumber is mandatory.");
writeShort(asNumber.getAsNumber().getValue().shortValue(), body);
return body;
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.label;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
import com.google.common.base.Preconditions;
import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder;
@Override
public LabelType parseLabel(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != LABEL_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
+ "Expected: " + LABEL_LENGTH + ".");
}
- return new Type1LabelCaseBuilder().setType1Label(new Type1LabelBuilder().setType1Label(
- buffer.readUnsignedInt()).build()).build();
+ return new Type1LabelCaseBuilder()
+ .setType1Label(new Type1LabelBuilder().setType1Label(ByteBufUtils.readUint32(buffer)).build())
+ .build();
}
@Override
public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject,
final ByteBuf buffer) {
- Preconditions.checkArgument(subobject instanceof Type1LabelCase,
- "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
+ checkArgument(subobject instanceof Type1LabelCase,
+ "Unknown Label Subobject instance. Passed %s. Needed Type1LabelCase.", subobject.getClass());
final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
* 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.rsvp.parser.impl.subobject.label;
+import static com.google.common.base.Preconditions.checkArgument;
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.rsvp.parser.spi.LabelParser;
import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.WavebandSwitchingLabelCaseBuilder;
@Override
public final LabelType parseLabel(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; Expected: " + CONTENT_LENGTH + ".");
}
- final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
- builder.setWavebandId(buffer.readUnsignedInt());
- builder.setStartLabel(buffer.readUnsignedInt());
- builder.setEndLabel(buffer.readUnsignedInt());
- return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
+ return new WavebandSwitchingLabelCaseBuilder()
+ .setWavebandSwitchingLabel(new WavebandSwitchingLabelBuilder()
+ .setWavebandId(ByteBufUtils.readUint32(buffer))
+ .setStartLabel(ByteBufUtils.readUint32(buffer))
+ .setEndLabel(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build();
}
@Override
public final void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject,
final ByteBuf buffer) {
- Preconditions.checkArgument(subobject instanceof WavebandSwitchingLabelCase,
- "Unknown Label Subobject instance. Passed {}. Needed WavebandSwitchingLabelCase.",
+ checkArgument(subobject instanceof WavebandSwitchingLabelCase,
+ "Unknown Label Subobject instance. Passed %s. Needed WavebandSwitchingLabelCase.",
subobject.getClass());
final WavebandSwitchingLabel obj = ((WavebandSwitchingLabelCase) subobject).getWavebandSwitchingLabel();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
+ checkArgument(obj.getWavebandId() != null, "WavebandId is mandatory.");
writeUnsignedInt(obj.getWavebandId(), body);
- Preconditions.checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
+ checkArgument(obj.getStartLabel() != null, "StartLabel is mandatory.");
writeUnsignedInt(obj.getStartLabel(), body);
- Preconditions.checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
+ checkArgument(obj.getEndLabel() != null, "EndLabel is mandatory.");
writeUnsignedInt(obj.getEndLabel(), body);
LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class RROPathKey128SubobjectParser implements RROSubobjectParser {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
+ "Expected: >" + CONTENT128_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE128_ID_F_LENGTH);
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
*/
package org.opendaylight.protocol.rsvp.parser.impl.subobject.rro;
+import static com.google.common.base.Preconditions.checkArgument;
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 org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.PathKeyCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class RROPathKey32SubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; " + "Expected: >" + CONTENT_LENGTH + ".");
}
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
final PathKeyBuilder pBuilder = new PathKeyBuilder();
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
+ checkArgument(subobject.getSubobjectType() instanceof PathKeyCase,
"Unknown subobject instance.Passed %s. Needed PathKey.",
subobject.getSubobjectType().getClass());
final PathKeyCase pkcase = (PathKeyCase) subobject.getSubobjectType();
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects
.subobject.type.path.key._case.PathKey pk = pkcase.getPathKey();
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
final byte[] pceId = pk.getPceId().getValue();
if (pceId.length == RROPathKey128SubobjectParser.PCE128_ID_F_LENGTH) {
RROPathKey128SubobjectParser.serializeSubobject(subobject, buffer);
}
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
- Preconditions.checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pceId.length == PCE_ID_F_LENGTH, "PathKey 32Bit is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
body.writeBytes(pceId);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
* 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.rsvp.parser.impl.subobject.rro;
+import static com.google.common.base.Preconditions.checkArgument;
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.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.UnnumberedSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; "
+ "Expected: " + CONTENT_LENGTH + ".");
builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
buffer.skipBytes(RESERVED);
- ubuilder.setRouterId(buffer.readUnsignedInt());
- ubuilder.setInterfaceId(buffer.readUnsignedInt());
+ ubuilder.setRouterId(ByteBufUtils.readUint32(buffer));
+ ubuilder.setInterfaceId(ByteBufUtils.readUint32(buffer));
builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build());
return builder.build();
}
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
+ checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
"Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
subobject.getSubobjectType().getClass());
final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
flags.toByteBuf(body);
body.writeZero(RESERVED);
- Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
+ checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
writeUnsignedInt(specObj.getRouterId(), body);
- Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
+ checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
writeUnsignedInt(specObj.getInterfaceId(), body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
* 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.rsvp.parser.impl.subobject.xro;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
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.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ExcludeRouteSubobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgSubobject;
private static final int CONTENT_LENGTH = 6;
@Override
- public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
- RSVPParsingException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Array of bytes is mandatory. Can't be null or empty.");
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
+ throws RSVPParsingException {
+ checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Cannot be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes()
+ "; " + "Expected: " + CONTENT_LENGTH + ".");
}
- final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
- builder.setMandatory(mandatory);
- builder.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer
- .readUnsignedInt())).build()).build());
+ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder()
+ .setMandatory(mandatory)
+ .setSubobjectType(new SrlgCaseBuilder()
+ .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(ByteBufUtils.readUint32(buffer))).build())
+ .build());
buffer.readByte();
- builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
- return builder.build();
+ return builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()))
+ .build();
}
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof SrlgCase,
- "Unknown subobject instance. Passed %s. Needed SrlgCase.",
- subobject.getSubobjectType().getClass());
+ checkArgument(subobject.getSubobjectType() instanceof SrlgCase,
+ "Unknown subobject instance. Passed %s. Needed SrlgCase.", subobject.getSubobjectType().getClass());
final SrlgSubobject specObj = ((SrlgCase) subobject.getSubobjectType()).getSrlg();
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
+ checkArgument(specObj.getSrlgId() != null, "SrlgId is mandatory.");
writeUnsignedInt(specObj.getSrlgId().getValue(), body);
- Preconditions.checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
+ checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
writeUnsignedByte((Uint8) null, body);
writeUnsignedByte((short) subobject.getAttribute().getIntValue(), body);
XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
* 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.rsvp.parser.impl.te;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
@Override
protected final void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof AssociationObject, "AssociationObject is mandatory.");
+ checkArgument(teLspObject instanceof AssociationObject, "AssociationObject is mandatory.");
final AssociationObject assObject = (AssociationObject) teLspObject;
if (assObject.getIpAddress().getIpv4AddressNoZone() != null) {
@Override
protected final RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final AssociationObjectBuilder asso = new AssociationObjectBuilder();
- asso.setAssociationType(AssociationType.forValue(byteBuf.readUnsignedShort()));
- asso.setAssociationId(byteBuf.readUnsignedShort());
- asso.setIpAddress(parseAssociationIpAddress(byteBuf));
- return asso.build();
+ return new AssociationObjectBuilder()
+ .setAssociationType(AssociationType.forValue(byteBuf.readUnsignedShort()))
+ .setAssociationId(ByteBufUtils.readUint16(byteBuf))
+ .setIpAddress(parseAssociationIpAddress(byteBuf))
+ .build();
}
}
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.FastRerouteFlags;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) {
- final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder();
- builder.setSetupPriority(byteBuf.readUnsignedByte());
- builder.setHoldPriority(byteBuf.readUnsignedByte());
- builder.setHopLimit(byteBuf.readUnsignedByte());
- builder.setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte()));
+ final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder()
+ .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHopLimit(ByteBufUtils.readUint8(byteBuf))
+ .setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte()));
final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
- builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
+ builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
+ builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
+ builder.setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
return builder.build();
}
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
//skip parameter ID 127 and 127 flags
byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
- final TspecObjectBuilder tBuilder = new TspecObjectBuilder();
- tBuilder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- tBuilder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- tBuilder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- tBuilder.setMinimumPolicedUnit(byteBuf.readUnsignedInt());
- tBuilder.setMaximumPacketSize(byteBuf.readUnsignedInt());
+ final TspecObjectBuilder tBuilder = new TspecObjectBuilder()
+ .setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setMinimumPolicedUnit(ByteBufUtils.readUint32(byteBuf))
+ .setMaximumPacketSize(ByteBufUtils.readUint32(byteBuf));
builder.setTspecObject(tBuilder.build());
if (builder.getServiceHeader().getIntValue() == 2) {
//skip parameter ID 130, flags, lenght
byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
builder.setRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- builder.setSlackTerm(byteBuf.readUnsignedInt());
+ builder.setSlackTerm(ByteBufUtils.readUint32(byteBuf));
}
return builder.build();
}
* 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.rsvp.parser.impl.te;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder();
- builder.setSetupPriority(byteBuf.readUnsignedByte());
- builder.setHoldPriority(byteBuf.readUnsignedByte());
- builder.setHopLimit(byteBuf.readUnsignedByte());
+ final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder()
+ .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHoldPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHopLimit(ByteBufUtils.readUint8(byteBuf));
+
//skip reserved
byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH);
final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH);
builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)));
- builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
+ builder.setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
+ builder.setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)));
return builder.build();
}
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory.");
+ checkArgument(teLspObject instanceof LegacyFastRerouteObject, "FastRerouteObject is mandatory.");
final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject;
serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator);
* 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.rsvp.parser.impl.te;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final MetricObjectBuilder builder = new MetricObjectBuilder();
byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
final BitArray flags = BitArray.valueOf(byteBuf.readByte());
- builder.setBound(flags.get(BOUND));
- builder.setComputed(flags.get(COMPUTED));
- builder.setMetricType(byteBuf.readUnsignedByte());
- builder.setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- return builder.build();
+
+ return new MetricObjectBuilder()
+ .setBound(flags.get(BOUND))
+ .setComputed(flags.get(COMPUTED))
+ .setMetricType(ByteBufUtils.readUint8(byteBuf))
+ .setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .build();
}
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory.");
+ 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);
*/
package org.opendaylight.protocol.rsvp.parser.impl.te;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final TspecObjectBuilder builder = new TspecObjectBuilder();
//skip version number, reserved, Overall length
byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
//skip Service header, reserved, Length of service
//skip Parameter ID, Parameter 127 flags, Parameter 127 length
byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH);
- builder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- builder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- builder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
- builder.setMinimumPolicedUnit(byteBuf.readUnsignedInt());
- builder.setMaximumPacketSize(byteBuf.readUnsignedInt());
- return builder.build();
+ return new TspecObjectBuilder()
+ .setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)))
+ .setMinimumPolicedUnit(ByteBufUtils.readUint32(byteBuf))
+ .setMaximumPacketSize(ByteBufUtils.readUint32(byteBuf))
+ .build();
}
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof TspecObject, "SenderTspecObject is mandatory.");
+ 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);
* 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.rsvp.parser.impl.te;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.BasicSessionAttributeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.BasicSessionAttributeObjectBuilder;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder();
- builder.setSetupPriority(byteBuf.readUnsignedByte());
- builder.setHoldPriority(byteBuf.readUnsignedByte());
+ final BasicSessionAttributeObjectBuilder builder = new BasicSessionAttributeObjectBuilder()
+ .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHoldPriority(ByteBufUtils.readUint8(byteBuf));
final BitArray bs = BitArray.valueOf(byteBuf.readByte());
builder.setLocalProtectionDesired(bs.get(LOCAL_PROTECTION));
builder.setLabelRecordingDesired(bs.get(LABEL_RECORDING));
builder.setSeStyleDesired(bs.get(SE_STYLE));
- final short nameLenght = byteBuf.readUnsignedByte();
- final ByteBuf auxBuf = byteBuf.readSlice(nameLenght);
+ final short nameLength = byteBuf.readUnsignedByte();
+ final ByteBuf auxBuf = byteBuf.readSlice(nameLength);
final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII);
builder.setSessionName(name);
return builder.build();
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof BasicSessionAttributeObject,
- "SessionAttributeObject is mandatory.");
+ checkArgument(teLspObject instanceof BasicSessionAttributeObject, "SessionAttributeObject is mandatory.");
final BasicSessionAttributeObject sessionObject = (BasicSessionAttributeObject) teLspObject;
final ByteBuf sessionName = Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject
*/
package org.opendaylight.protocol.rsvp.parser.impl.te;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.SessionAttributeObjectWithResourcesAffinities;
@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
- final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new
- SessionAttributeObjectWithResourcesAffinitiesBuilder();
- builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
- builder.setSetupPriority(byteBuf.readUnsignedByte());
- builder.setHoldPriority(byteBuf.readUnsignedByte());
+ final SessionAttributeObjectWithResourcesAffinitiesBuilder builder =
+ new SessionAttributeObjectWithResourcesAffinitiesBuilder()
+ .setIncludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
+ .setExcludeAny(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
+ .setIncludeAll(new AttributeFilter(ByteBufUtils.readUint32(byteBuf)))
+ .setSetupPriority(ByteBufUtils.readUint8(byteBuf))
+ .setHoldPriority(ByteBufUtils.readUint8(byteBuf));
+
final BitArray bs = BitArray.valueOf(byteBuf.readByte());
builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION));
builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING));
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
- Preconditions.checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities,
+ checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities,
"SessionAttributeObject is mandatory.");
final SessionAttributeObjectWithResourcesAffinities sessionObject =
parser.parseSubobject(null, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseLabel(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseLabel(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseLabel(null);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseLabel(Unpooled.EMPTY_BUFFER);
fail();
} catch (final IllegalArgumentException e) {
- assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
}
parser.parseSubobject(null);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
parser.parseSubobject(null, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
try {
parser.parseSubobject(Unpooled.EMPTY_BUFFER, true);
Assert.fail();
} catch (final IllegalArgumentException e) {
- Assert.assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ Assert.assertEquals("Array of bytes is mandatory. Cannot be null or empty.", e.getMessage());
}
}
* 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.rsvp.parser.spi.subobjects;
+import static com.google.common.base.Preconditions.checkArgument;
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 org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKeyBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
public class CommonPathKeyParser {
protected CommonPathKeyParser() {
public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route
.subobjects.subobject.type.path.key._case.PathKey parsePathKey(final int pceIdFLength, final ByteBuf buffer) {
- final int pathKey = buffer.readUnsignedShort();
+ final Uint16 pathKey = ByteBufUtils.readUint16(buffer);
final byte[] pceId = ByteArray.readBytes(buffer, pceIdFLength);
final PathKeyBuilder pBuilder = new PathKeyBuilder();
pBuilder.setPceId(new PceId(pceId));
public static ByteBuf serializePathKey(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
.rsvp.rev150820.explicit.route.subobjects.subobject.type.path.key._case.PathKey pk) {
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
+ checkArgument(pk.getPathKey() != null, "PathKey is mandatory.");
writeUnsignedShort(pk.getPathKey().getValue(), body);
- Preconditions.checkArgument(pk.getPceId() != null, "PceId is mandatory.");
+ checkArgument(pk.getPceId() != null, "PceId is mandatory.");
body.writeBytes(pk.getPceId().getValue());
return body;
}
* 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.rsvp.parser.spi.subobjects;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteBufUtils;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
}
protected static UnnumberedCase parseUnnumeredInterface(final ByteBuf buffer) {
- final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
- ubuilder.setRouterId(buffer.readUnsignedInt());
- ubuilder.setInterfaceId(buffer.readUnsignedInt());
- return new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build();
+ return new UnnumberedCaseBuilder()
+ .setUnnumbered(new UnnumberedBuilder()
+ .setRouterId(ByteBufUtils.readUint32(buffer))
+ .setInterfaceId(ByteBufUtils.readUint32(buffer))
+ .build())
+ .build();
}
protected static void serializeUnnumeredInterface(final Unnumbered unnumbered, final ByteBuf body) {
- Preconditions.checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory.");
+ checkArgument(unnumbered.getRouterId() != null, "RouterId is mandatory.");
ByteBufWriteUtil.writeUnsignedInt(unnumbered.getRouterId(), body);
- Preconditions.checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory.");
+ checkArgument(unnumbered.getInterfaceId() != null, "InterfaceId is mandatory.");
ByteBufWriteUtil.writeUnsignedInt(unnumbered.getInterfaceId(), body);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+/**
+ * Utility methods for interacting with {@link ByteBuf}s. These add a number of methods for reading and writing various
+ * data types from/to ByteBufs.
+ */
+public final class ByteBufUtils {
+ private ByteBufUtils() {
+
+ }
+
+ public static @NonNull Uint8 readUint8(final ByteBuf buf) {
+ return Uint8.fromByteBits(buf.readByte());
+ }
+
+ public static @NonNull Uint16 readUint16(final ByteBuf buf) {
+ return Uint16.fromShortBits(buf.readShort());
+ }
+
+ // TODO: this probably wants a dedicated concept
+ public static @NonNull Uint32 readUint24(final ByteBuf buf) {
+ return Uint32.fromIntBits(buf.readMedium());
+ }
+
+ public static @NonNull Uint32 readUint32(final ByteBuf buf) {
+ return Uint32.fromIntBits(buf.readInt());
+ }
+
+ public static @NonNull Uint64 readUint64(final ByteBuf buf) {
+ return Uint64.fromLongBits(buf.readLong());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Byte value, final String name) {
+ buf.writeByte(nonNullArgument(value, name).byteValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Short value, final String name) {
+ buf.writeShort(nonNullArgument(value, name).shortValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Integer value, final String name) {
+ buf.writeInt(nonNullArgument(value, name).intValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Long value, final String name) {
+ buf.writeLong(nonNullArgument(value, name).longValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Uint8 value, final String name) {
+ buf.writeByte(nonNullArgument(value, name).byteValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Uint16 value, final String name) {
+ buf.writeShort(nonNullArgument(value, name).shortValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Uint32 value, final String name) {
+ buf.writeInt(nonNullArgument(value, name).intValue());
+ }
+
+ public static void writeMandatory(final ByteBuf buf, final Uint64 value, final String name) {
+ buf.writeLong(nonNullArgument(value, name).longValue());
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Byte value) {
+ if (value != null) {
+ buf.writeByte(value.byteValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Short value) {
+ if (value != null) {
+ buf.writeShort(value.shortValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Integer value) {
+ if (value != null) {
+ buf.writeInt(value.intValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Long value) {
+ if (value != null) {
+ buf.writeLong(value.longValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Uint8 value) {
+ if (value != null) {
+ buf.writeByte(value.byteValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Uint16 value) {
+ if (value != null) {
+ buf.writeShort(value.shortValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Uint32 value) {
+ if (value != null) {
+ buf.writeInt(value.intValue());
+ }
+ }
+
+ public static void writeOptional(final ByteBuf buf, final @Nullable Uint64 value) {
+ if (value != null) {
+ buf.writeLong(value.longValue());
+ }
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Byte value) {
+ buf.writeByte(value != null ? value.byteValue() : 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Short value) {
+ buf.writeShort(value != null ? value.shortValue() : (short) 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Integer value) {
+ buf.writeInt(value != null ? value.intValue() : 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Long value) {
+ buf.writeLong(value != null ? value.longValue() : 0L);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Uint8 value) {
+ buf.writeByte(value != null ? value.byteValue() : 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Uint16 value) {
+ buf.writeShort(value != null ? value.shortValue() : (short) 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Uint32 value) {
+ buf.writeInt(value != null ? value.intValue() : 0);
+ }
+
+ public static void writeOrZero(final ByteBuf buf, final @Nullable Uint64 value) {
+ buf.writeLong(value != null ? value.longValue() : 0L);
+ }
+
+ private static <T> @NonNull T nonNullArgument(final @Nullable T obj, final String name) {
+ if (obj == null) {
+ throw new IllegalArgumentException(name + " is mandatory");
+ }
+ return obj;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
+
+public class ByteBufUtilsTest {
+
+ @Test
+ public void testByte() {
+ testWrite(Byte.valueOf((byte) 1), 1, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero,
+ ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testShort() {
+ testWrite(Short.valueOf((short) 1), 2, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero,
+ ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testInteger() {
+ testWrite(Integer.valueOf(1), 4, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero,
+ ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testLong() {
+ testWrite(Long.valueOf(1L), 8, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero,
+ ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testUint8() {
+ testRead(Uint8.ONE, ByteBufUtils::readUint8, (byte) 1);
+ testWrite(Uint8.ONE, 1, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testUint16() {
+ testRead(Uint16.ONE, ByteBufUtils::readUint16, (byte) 0, (byte) 1);
+ testWrite(Uint16.ONE, 2, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testUint32() {
+ testRead(Uint32.ONE, ByteBufUtils::readUint32, (byte) 0, (byte) 0, (byte) 0, (byte) 1);
+ testWrite(Uint32.ONE, 4, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory);
+ }
+
+ @Test
+ public void testUint64() {
+ testRead(Uint64.ONE, ByteBufUtils::readUint64,
+ (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1);
+ testWrite(Uint64.ONE, 8, ByteBufUtils::writeOptional, ByteBufUtils::writeOrZero, ByteBufUtils::writeMandatory);
+ }
+
+ private static <T> void testRead(final T expected, final Function<ByteBuf, T> readFunc, final byte... bytes) {
+ final ByteBuf buf = Unpooled.wrappedBuffer(bytes);
+ assertEquals(expected, readFunc.apply(buf));
+ assertFalse(buf.isReadable());
+ }
+
+ private static <T> void testWrite(final T obj, final int size, final WriteNullable<T> writeOptional,
+ final WriteNullable<T> writeOrZero, final WriteMandatory<T> writeMandatory) {
+ final ByteBuf buf = Unpooled.buffer(size);
+
+ writeOptional.accept(buf, null);
+ assertEquals(0, buf.writerIndex());
+ writeOptional.accept(buf, obj);
+ assertEquals(size, buf.writerIndex());
+
+ writeOrZero.accept(buf, null);
+ assertEquals(2 * size, buf.writerIndex());
+ writeOrZero.accept(buf, obj);
+ assertEquals(3 * size, buf.writerIndex());
+
+ buf.clear();
+ try {
+ writeMandatory.accept(buf, null, "name");
+ fail("IAE should have been thrown");
+ } catch (IllegalArgumentException e) {
+ assertEquals("name is mandatory", e.getMessage());
+ }
+ assertEquals(0, buf.writerIndex());
+
+ writeMandatory.accept(buf, obj, null);
+ assertEquals(size, buf.writerIndex());
+ }
+
+ @FunctionalInterface
+ interface WriteNullable<T> extends BiConsumer<ByteBuf, T> {
+
+ }
+
+ @FunctionalInterface
+ interface WriteMandatory<T> {
+ void accept(ByteBuf buf, T value, String name);
+ }
+}