import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.extractRD;
import io.netty.buffer.ByteBuf;
-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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
checkArgument(esi instanceof RouterIdGeneratedCase,
"Unknown esi instance. Passed %s. Needed RouterIdGeneratedCase.", esi);
final RouterIdGenerated routerID = ((RouterIdGeneratedCase) esi).getRouterIdGenerated();
- ByteBufWriteUtil.writeIpv4Address(routerID.getRouterId(), body);
+ Ipv4Util.writeIpv4Address(routerID.getRouterId(), body);
ByteBufUtils.writeOrZero(body, routerID.getLocalDiscriminator());
return body.writeByte(0);
}
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.ByteBufWriteUtil;
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;
.getRedirectIpNhExtendedCommunity();
final IpAddress nextHopAddress = redirect.getNextHopAddress();
if (nextHopAddress.getIpv4Address() != null) {
- ByteBufWriteUtil.writeIpv4Address(nextHopAddress.getIpv4Address(), byteAggregator);
+ Ipv4Util.writeIpv4Address(nextHopAddress.getIpv4Address(), byteAggregator);
} else {
- ByteBufWriteUtil.writeIpv6Address(nextHopAddress.getIpv6Address(), byteAggregator);
+ Ipv6Util.writeIpv6Address(nextHopAddress.getIpv6Address(), byteAggregator);
}
byteAggregator.writeShort(Boolean.TRUE.equals(redirect.isCopy()) ? 1 : 0);
}
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.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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4Builder;
"The extended community %s is not RedirectIpv4ExtendedCommunityCase type.", extendedCommunity);
final RedirectIpv4 redirect = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec
.rev180329.RedirectIpv4ExtendedCommunity) extendedCommunity).getRedirectIpv4();
- ByteBufWriteUtil.writeIpv4Address(redirect.getGlobalAdministrator(), byteAggregator);
+ Ipv4Util.writeIpv4Address(redirect.getGlobalAdministrator(), byteAggregator);
ByteBufUtils.writeOrZero(byteAggregator, redirect.getLocalAdministrator());
}
import static java.util.Objects.requireNonNull;
import io.netty.buffer.ByteBuf;
-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.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.DestinationPrefixCase;
public void serializeType(final FlowspecType value, final ByteBuf output) {
checkArgument(value instanceof DestinationPrefixCase, "DestinationPrefixCase class is mandatory!");
output.writeByte(DESTINATION_PREFIX_VALUE);
- ByteBufWriteUtil.writeMinimalPrefix(((DestinationPrefixCase) value).getDestinationPrefix(), output);
+ Ipv4Util.writeMinimalPrefix(((DestinationPrefixCase) value).getDestinationPrefix(), output);
}
@Override
*/
package org.opendaylight.protocol.bgp.flowspec.handlers;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
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.SourcePrefixCase;
@Override
public void serializeType(final FlowspecType value, final ByteBuf output) {
- Preconditions.checkArgument(value instanceof SourcePrefixCase, "SourcePrefixCase class is mandatory!");
+ checkArgument(value instanceof SourcePrefixCase, "SourcePrefixCase class is mandatory!");
output.writeByte(SOURCE_PREFIX_VALUE);
- ByteBufWriteUtil.writeMinimalPrefix(((SourcePrefixCase) value).getSourcePrefix(), output);
+ Ipv4Util.writeMinimalPrefix(((SourcePrefixCase) value).getSourcePrefix(), output);
}
@Override
* 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.inet.codec;
import io.netty.buffer.ByteBuf;
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.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
(DestinationIpv4Case) advertizedRoutes.getDestinationType();
for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator);
- ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
+ Ipv4Util.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
}
}
} else if (pathAttributes2 != null) {
.destination.type.DestinationIpv4Case) withdrawnRoutes.getDestinationType();
for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
PathIdUtil.writePathId(ipv4Prefix.getPathId(), byteAggregator);
- ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix.getPrefix(), byteAggregator);
+ Ipv4Util.writeMinimalPrefix(ipv4Prefix.getPrefix(), 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.bgp.inet.codec;
import io.netty.buffer.ByteBuf;
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.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder;
(DestinationIpv6Case) advertizedRoutes.getDestinationType();
for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator);
- ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
+ Ipv6Util.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
}
}
} else if (pathAttributes2 != null) {
.DestinationIpv6Case) withdrawnRoutes.getDestinationType();
for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
PathIdUtil.writePathId(ipv6Prefix.getPathId(), byteAggregator);
- ByteBufWriteUtil.writeMinimalPrefix(ipv6Prefix.getPrefix(), byteAggregator);
+ Ipv6Util.writeMinimalPrefix(ipv6Prefix.getPrefix(), 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.bgp.inet.codec;
import static org.junit.Assert.assertEquals;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
.setIpv4Prefixes(fakePrefixes).build()).build();
final ByteBuf buffer1 = Unpooled.buffer(5);
- ByteBufWriteUtil.writeMinimalPrefix(prefix1, buffer1);
+ Ipv4Util.writeMinimalPrefix(prefix1, buffer1);
this.inputBytes.writeBytes(buffer1.array());
final ByteBuf buffer2 = Unpooled.buffer(5);
- ByteBufWriteUtil.writeMinimalPrefix(prefix2, buffer2);
+ Ipv4Util.writeMinimalPrefix(prefix2, buffer2);
this.inputBytes.writeBytes(buffer2.array());
Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any());
*/
package org.opendaylight.protocol.bgp.l3vpn.mcast.nlri;
-import static org.opendaylight.protocol.util.Ipv6Util.IPV6_BITS_LENGTH;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
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.IpPrefix;
final int initialLength = nlri.readableBytes();
builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri));
- if (length == IPV6_BITS_LENGTH) {
+ if (length == Ipv6Util.IPV6_BITS_LENGTH) {
builder.setPrefix(new IpPrefix(Ipv6Util.prefixForByteBuf(nlri)));
} else {
builder.setPrefix(new IpPrefix(Ipv4Util.prefixForByteBuf(nlri)));
final IpPrefix prefix = dest.getPrefix();
if (prefix.getIpv4Prefix() != null) {
output.writeByte(Ipv4Util.IP4_BITS_LENGTH);
- ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv4Prefix(), prefixBuf);
+ Ipv4Util.writeMinimalPrefix(prefix.getIpv4Prefix(), prefixBuf);
} else {
- output.writeByte(IPV6_BITS_LENGTH);
- ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), prefixBuf);
+ output.writeByte(Ipv6Util.IPV6_BITS_LENGTH);
+ Ipv6Util.writeMinimalPrefix(prefix.getIpv6Prefix(), prefixBuf);
}
// FIXME: remove this funky loop
while (prefixBuf.readableBytes() % 8 != 0) {
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.protocol.util.MplsLabelUtil;
final ByteBuf buffer = Unpooled.buffer();
if (prefix.getIpv4Prefix() != null) {
- ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv4Prefix(), buffer);
+ Ipv4Util.writeMinimalPrefix(prefix.getIpv4Prefix(), buffer);
} else {
- ByteBufWriteUtil.writeMinimalPrefix(prefix.getIpv6Prefix(), buffer);
+ Ipv6Util.writeMinimalPrefix(prefix.getIpv6Prefix(), buffer);
}
return ByteArray.readAllBytes(buffer);
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
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.epe.rev150622.EpeNodeDescriptors;
public final class BgpRouterIdTlvParser implements LinkstateTlvParser<Ipv4Address>,
LinkstateTlvParser.LinkstateTlvSerializer<Ipv4Address> {
-
private static final int BGP_ROUTER_ID = 516;
public static final QName BGP_ROUTER_ID_QNAME = QName.create(EpeNodeDescriptors.QNAME, "bgp-router-id").intern();
@Override
public void serializeTlvBody(final Ipv4Address tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeIpv4Address(tlv, body);
+ Ipv4Util.writeIpv4Address(tlv, body);
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv4InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
-
private static final int IPV4_IFACE_ADDRESS = 259;
public static final QName IPV4_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-interface-address")
@Override
public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeIpv4Address(tlv, body);
+ Ipv4Util.writeIpv4Address(tlv, body);
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv4InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
public final class Ipv4NeighborTlvParser implements LinkstateTlvParser<Ipv4InterfaceIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<Ipv4InterfaceIdentifier> {
-
- private static final int IPV4_NEIGHBOR_ADDRESS = 260;
-
public static final QName IPV4_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address")
.intern();
+ private static final int IPV4_NEIGHBOR_ADDRESS = 260;
+
@Override
public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeIpv4Address(tlv, body);
+ Ipv4Util.writeIpv4Address(tlv, body);
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv6InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
-
private static final int IPV6_IFACE_ADDRESS = 261;
public static final QName IPV6_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-interface-address")
@Override
public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeIpv6Address(tlv, body);
+ Ipv6Util.writeIpv6Address(tlv, body);
}
@Override
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-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.linkstate.rev180329.Ipv6InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptors;
public final class Ipv6NeighborTlvParser implements LinkstateTlvParser<Ipv6InterfaceIdentifier>,
LinkstateTlvParser.LinkstateTlvSerializer<Ipv6InterfaceIdentifier> {
-
private static final int IPV6_NEIGHBOR_ADDRESS = 262;
public static final QName IPV6_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address")
@Override
public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) {
- ByteBufWriteUtil.writeIpv6Address(tlv, body);
+ Ipv6Util.writeIpv6Address(tlv, body);
}
@Override
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
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.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
@Override
public void serializeTlvBody(final IpPrefix tlv, final ByteBuf body) {
if (tlv.getIpv4Prefix() != null) {
- ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv4Prefix(), body);
+ Ipv4Util.writeMinimalPrefix(tlv.getIpv4Prefix(), body);
} else if (tlv.getIpv6Prefix() != null) {
- ByteBufWriteUtil.writeMinimalPrefix(tlv.getIpv6Prefix(), body);
+ Ipv6Util.writeMinimalPrefix(tlv.getIpv6Prefix(), body);
}
}
}
public static IpPrefix serializeModel(final ContainerNode prefixDesc) {
- if (prefixDesc.getChild(IP_REACH_NID).isPresent()) {
- final String prefix = (String) prefixDesc.getChild(IP_REACH_NID).get().getValue();
- try {
- final ByteBuf buffer = Unpooled.buffer(5);
- ByteBufWriteUtil.writeMinimalPrefix(new Ipv4Prefix(prefix), buffer);
- return new IpPrefix(new Ipv4Prefix(prefix));
- } catch (final IllegalArgumentException e) {
- LOG.debug("Creating Ipv6 prefix because", e);
- return new IpPrefix(new Ipv6Prefix(prefix));
- }
- }
- return null;
+ return prefixDesc.getChild(IP_REACH_NID)
+ .map(child -> {
+ final String prefix = (String) child.getValue();
+ try {
+ final ByteBuf buffer = Unpooled.buffer(5);
+ Ipv4Util.writeMinimalPrefix(new Ipv4Prefix(prefix), buffer);
+ return new IpPrefix(new Ipv4Prefix(prefix));
+ } catch (final IllegalArgumentException e) {
+ LOG.debug("Creating Ipv6 prefix because", e);
+ return new IpPrefix(new Ipv6Prefix(prefix));
+ }
+ })
+ .orElse(null);
}
}
*/
package org.opendaylight.protocol.bgp.linkstate.spi;
+import static com.google.common.base.Preconditions.checkArgument;
+
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.ObjectType;
@Override
protected final void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) {
- Preconditions.checkArgument(objectType instanceof TeLspCase);
+ checkArgument(objectType instanceof TeLspCase);
final TeLspCase teLSP = (TeLspCase) objectType;
final AddressFamily addressFamily = teLSP.getAddressFamily();
if (addressFamily instanceof Ipv4Case) {
}
private static void serializeIpv4Case(final TeLspCase teLSP, final Ipv4Case ipv4Case, final ByteBuf buffer) {
- ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelSenderAddress(), buffer);
+ Ipv4Util.writeIpv4Address(ipv4Case.getIpv4TunnelSenderAddress(), buffer);
serializeTunnelIdAndLspId(buffer, teLSP);
- ByteBufWriteUtil.writeIpv4Address(ipv4Case.getIpv4TunnelEndpointAddress(), buffer);
+ Ipv4Util.writeIpv4Address(ipv4Case.getIpv4TunnelEndpointAddress(), buffer);
}
private static void serializeIpv6Case(final TeLspCase teLSP, final Ipv6Case ipv6Case, final ByteBuf buffer) {
- ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelSenderAddress(), buffer);
+ Ipv6Util.writeIpv6Address(ipv6Case.getIpv6TunnelSenderAddress(), buffer);
serializeTunnelIdAndLspId(buffer, teLSP);
- ByteBufWriteUtil.writeIpv6Address(ipv6Case.getIpv6TunnelEndpointAddress(), buffer);
+ Ipv6Util.writeIpv6Address(ipv6Case.getIpv6TunnelEndpointAddress(), buffer);
}
private static void serializeTunnelIdAndLspId(final ByteBuf buffer, final TeLspCase teLSP) {
*/
package org.opendaylight.protocol.bgp.parser.impl.message;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
* @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
*/
public final class BGPUpdateMessageParser implements MessageParser, MessageSerializer {
-
private static final Logger LOG = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
public static final int TYPE = 2;
private final AttributeRegistry attrReg;
-
private final NlriRegistry nlriReg;
public BGPUpdateMessageParser(final AttributeRegistry attrReg, final NlriRegistry nlriReg) {
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
- Preconditions.checkArgument(message instanceof Update, "Message needs to be of type Update");
+ checkArgument(message instanceof Update, "Message needs to be of type Update");
final Update update = (Update) message;
final ByteBuf messageBody = Unpooled.buffer();
private static void writePathIdPrefix(final ByteBuf byteBuf, final PathId pathId, final Ipv4Prefix ipv4Prefix) {
PathIdUtil.writePathId(pathId, byteBuf);
- ByteBufWriteUtil.writeMinimalPrefix(ipv4Prefix, byteBuf);
+ Ipv4Util.writeMinimalPrefix(ipv4Prefix, byteBuf);
}
/**
@Override
public Update parseMessageBody(final ByteBuf buffer, final int messageLength,
final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
- Preconditions.checkArgument(buffer != null && buffer.isReadable(),
- "Buffer cannot be null or empty.");
+ checkArgument(buffer != null && buffer.isReadable(),"Buffer cannot be null or empty.");
final UpdateBuilder builder = new UpdateBuilder();
final boolean isMultiPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint,
* 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.impl.message.update.extended.communities;
+import static com.google.common.base.Preconditions.checkArgument;
import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.parseCommon;
import static org.opendaylight.protocol.bgp.parser.spi.extended.community.Inet4SpecificExtendedCommunityCommonUtil.serializeCommon;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
-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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
public final class Ipv4SpecificEcHandler extends AbstractIpv4ExtendedCommunity {
-
private static final int SUBTYPE = 0;
@Override
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
- "The extended community %s is not Inet4SpecificExtendedCommunityCase type.",
- extendedCommunity);
+ checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
+ "The extended community %s is not Inet4SpecificExtendedCommunityCase type.", extendedCommunity);
final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity
= ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
if (common != null) {
serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
} else {
- ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
+ Ipv4Util.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
}
}
public int getSubType() {
return SUBTYPE;
}
-
}
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+
import io.netty.buffer.ByteBuf;
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.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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginIpv4Case;
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(extendedCommunity instanceof RouteOriginIpv4Case,
+ checkArgument(extendedCommunity instanceof RouteOriginIpv4Case,
"The extended community %s is not RouteOriginIpv4Case type.", extendedCommunity);
final RouteOriginIpv4 routeTarget = ((RouteOriginIpv4Case) extendedCommunity).getRouteOriginIpv4();
- ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
+ Ipv4Util.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
}
@Override
public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
throws BGPDocumentedException, BGPParsingException {
- final RouteOriginIpv4 routeTarget = new RouteOriginIpv4Builder()
- .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
- .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
- .build();
- return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(routeTarget).build();
+ return new RouteOriginIpv4CaseBuilder()
+ .setRouteOriginIpv4(new RouteOriginIpv4Builder()
+ .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
+ .setLocalAdministrator(ByteBufUtils.readUint16(buffer))
+ .build())
+ .build();
}
@Override
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import io.netty.buffer.ByteBuf;
-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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
}
public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
- ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
+ Ipv4Util.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
ByteBufUtils.writeOrZero(byteAggregator, routeTarget.getLocalAdministrator());
}
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.util.ByteArray;
-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.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommon;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
public static void serializeCommon(final Inet4SpecificExtendedCommunityCommon extComm,
final ByteBuf byteAggregator) {
- ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
+ Ipv4Util.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
byteAggregator.writeBytes(extComm.getLocalAdministrator());
}
}
*/
package org.opendaylight.protocol.bmp.parser.message;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
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.ByteBufWriteUtil;
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;
@Override
public void serializeMessageBody(final Notification message, final ByteBuf buffer) {
super.serializeMessageBody(message, buffer);
- Preconditions.checkArgument(message instanceof PeerUpNotification,
- "An instance of Peer Up notification is required");
+ checkArgument(message instanceof PeerUpNotification, "An instance of Peer Up notification is required");
final PeerUpNotification peerUp = (PeerUpNotification) message;
if (peerUp.getLocalAddress().getIpv4Address() != null) {
buffer.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
- ByteBufWriteUtil.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer);
+ Ipv4Util.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer);
} else {
- ByteBufWriteUtil.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
+ Ipv6Util.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer);
}
ByteBufUtils.write(buffer, peerUp.getLocalPort().getValue());
ByteBufUtils.write(buffer, peerUp.getRemotePort().getValue());
try {
final Notification opSent = this.msgRegistry
.parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
- requireNonNull(opSent,
- "Error on parse Sent OPEN Message, Sent OPEN Message is null");
- Preconditions.checkArgument(opSent instanceof OpenMessage,
- "An instance of OpenMessage notification is required");
+ requireNonNull(opSent, "Error on parse Sent OPEN Message, Sent OPEN Message is null");
+ checkArgument(opSent instanceof OpenMessage, "An instance of OpenMessage notification is required");
final OpenMessage sent = (OpenMessage) opSent;
final Notification opRec = this.msgRegistry
.parseMessage(bytes.readSlice(getBgpMessageLength(bytes)), null);
- requireNonNull(opRec,
- "Error on parse Received OPEN Message, Received OPEN Message is null");
- Preconditions.checkArgument(opRec instanceof OpenMessage,
- "An instance of OpenMessage notification is required");
+ requireNonNull(opRec, "Error on parse Received OPEN Message, Received OPEN Message is null");
+ checkArgument(opRec instanceof OpenMessage, "An instance of OpenMessage notification is required");
final OpenMessage received = (OpenMessage) opRec;
peerUpNot.setSentOpen(new SentOpenBuilder(sent).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.ByteBufWriteUtil;
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.AsNumber;
}
if (peerHeader.isIpv4()) {
output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
- ByteBufWriteUtil.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
+ Ipv4Util.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
} else {
- ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
+ Ipv6Util.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
}
ByteBufUtils.write(output, peerHeader.getAs().getValue());
- ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
+ Ipv4Util.writeIpv4Address(peerHeader.getBgpId(), output);
final Timestamp stampSec = peerHeader.getTimestampSec();
if (stampSec != 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.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 org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof PccIdReq,
- "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+ checkArgument(object instanceof PccIdReq, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.",
+ object.getClass());
final PccIdReq pccIdReq = (PccIdReq) object;
if (pccIdReq.getIpAddress().getIpv4AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
- ByteBufWriteUtil.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
+ Ipv4Util.writeIpv4Address(pccIdReq.getIpAddress().getIpv4AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
body, buffer);
} else if (pccIdReq.getIpAddress().getIpv6AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
- ByteBufWriteUtil.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
+ Ipv6Util.writeIpv6Address(pccIdReq.getIpAddress().getIpv6AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), 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 org.opendaylight.protocol.pcep.spi.CommonObjectParser;
import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.pcep.spi.ObjectUtil;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
- Preconditions.checkArgument(object instanceof PceId,
- "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.", object.getClass());
+ checkArgument(object instanceof PceId, "Wrong instance of PCEPObject. Passed %s. Needed PccIdReqObject.",
+ object.getClass());
final PceId pceId = (PceId) object;
if (pceId.getIpAddress().getIpv4AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
- ByteBufWriteUtil.writeIpv4Address(pceId.getIpAddress().getIpv4AddressNoZone(), body);
+ Ipv4Util.writeIpv4Address(pceId.getIpAddress().getIpv4AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
body, buffer);
} else if (pceId.getIpAddress().getIpv6AddressNoZone() != null) {
final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
- ByteBufWriteUtil.writeIpv6Address(pceId.getIpAddress().getIpv6AddressNoZone(), body);
+ Ipv6Util.writeIpv6Address(pceId.getIpAddress().getIpv6AddressNoZone(), body);
ObjectUtil.formatSubobject(getObjectType(), getObjectClass(), object.isProcessingRule(), object.isIgnore(),
body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.object.end.points;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
final Ipv4 ipv4,
final ByteBuf buffer) {
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH);
- Preconditions.checkArgument(ipv4.getSourceIpv4Address() != null,
- "SourceIpv4Address is mandatory.");
- writeIpv4Address(ipv4.getSourceIpv4Address(), body);
- Preconditions.checkArgument(ipv4.getDestinationIpv4Address() != null,
- "DestinationIpv4Address is mandatory.");
- writeIpv4Address(ipv4.getDestinationIpv4Address(), body);
+ checkArgument(ipv4.getSourceIpv4Address() != null, "SourceIpv4Address is mandatory.");
+ Ipv4Util.writeIpv4Address(ipv4.getSourceIpv4Address(), body);
+ checkArgument(ipv4.getDestinationIpv4Address() != null, "DestinationIpv4Address is mandatory.");
+ Ipv4Util.writeIpv4Address(ipv4.getDestinationIpv4Address(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@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. Can't be null or empty.");
final EndpointsObjBuilder builder = new EndpointsObjBuilder();
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
*/
package org.opendaylight.protocol.pcep.parser.object.end.points;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
final Ipv6 ipv6,
final ByteBuf buffer) {
final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH);
- Preconditions.checkArgument(ipv6.getSourceIpv6Address() != null,
- "SourceIpv6Address is mandatory.");
- writeIpv6Address(ipv6.getSourceIpv6Address(), body);
- Preconditions.checkArgument(ipv6.getDestinationIpv6Address() != null,
- "DestinationIpv6Address is mandatory.");
- writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
+ checkArgument(ipv6.getSourceIpv6Address() != null, "SourceIpv6Address is mandatory.");
+ Ipv6Util.writeIpv6Address(ipv6.getSourceIpv6Address(), body);
+ checkArgument(ipv6.getDestinationIpv6Address() != null, "DestinationIpv6Address is mandatory.");
+ Ipv6Util.writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@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. Can't be null or empty.");
final EndpointsObjBuilder builder = new EndpointsObjBuilder();
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
*/
package org.opendaylight.protocol.pcep.parser.object.end.points;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
final P2mpIpv4 p2mpIpv4,
final ByteBuf buffer) {
final List<Ipv4AddressNoZone> dest = p2mpIpv4.getDestinationIpv4Address();
- Preconditions.checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
+ checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
final ByteBuf body = Unpooled.buffer(LEAF_TYPE_SIZE + Ipv4Util.IP4_LENGTH + Ipv4Util.IP4_LENGTH * dest.size());
- Preconditions.checkArgument(p2mpIpv4.getSourceIpv4Address() != null,
- "SourceIpv4Address is mandatory.");
+ checkArgument(p2mpIpv4.getSourceIpv4Address() != null, "SourceIpv4Address is mandatory.");
body.writeInt(p2mpIpv4.getP2mpLeaves().getIntValue());
- writeIpv4Address(p2mpIpv4.getSourceIpv4Address(), body);
- dest.forEach(ipv4 -> writeIpv4Address(ipv4, body));
+ Ipv4Util.writeIpv4Address(p2mpIpv4.getSourceIpv4Address(), body);
+ dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@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. Can't be null or empty.");
final EndpointsObjBuilder builder = new EndpointsObjBuilder();
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
*/
package org.opendaylight.protocol.pcep.parser.object.end.points;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
final P2mpIpv6 p2mpIpv6,
final ByteBuf buffer) {
final List<Ipv6AddressNoZone> dest = p2mpIpv6.getDestinationIpv6Address();
- Preconditions.checkArgument(dest != null, "DestinationIpv6Address is mandatory.");
+ checkArgument(dest != null, "DestinationIpv6Address is mandatory.");
final ByteBuf body =
Unpooled.buffer(LEAF_TYPE_SIZE + Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH * dest.size());
- Preconditions.checkArgument(p2mpIpv6.getSourceIpv6Address() != null,
- "SourceIpv6Address is mandatory.");
+ checkArgument(p2mpIpv6.getSourceIpv6Address() != null, "SourceIpv6Address is mandatory.");
body.writeInt(p2mpIpv6.getP2mpLeaves().getIntValue());
- writeIpv6Address(p2mpIpv6.getSourceIpv6Address(), body);
- dest.forEach(ipv6 -> writeIpv6Address(ipv6, body));
+ Ipv6Util.writeIpv6Address(p2mpIpv6.getSourceIpv6Address(), body);
+ dest.forEach(ipv6 -> Ipv6Util.writeIpv6Address(ipv6, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@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. Can't be null or empty.");
if (!header.isProcessingRule()) {
LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, new EndpointsObjBuilder().build());
*/
package org.opendaylight.protocol.pcep.parser.object.unreach;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
final Ipv4DestinationCase ipv4Case,
final ByteBuf buffer) {
final List<Ipv4AddressNoZone> dest = ipv4Case.getDestinationIpv4Address();
- Preconditions.checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
+ checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH * dest.size());
- dest.forEach(ipv4 -> writeIpv4Address(ipv4, body));
+ dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@Override
public UnreachDestinationObj 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. Can't be null or empty.");
final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
if (bytes.readableBytes() % Ipv4Util.IP4_LENGTH != 0) {
throw new PCEPDeserializerException("Wrong length of array of bytes.");
*/
package org.opendaylight.protocol.pcep.parser.object.unreach;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
final Ipv6DestinationCase ipv6Case,
final ByteBuf buffer) {
final List<Ipv6AddressNoZone> dest = ipv6Case.getDestinationIpv6Address();
- Preconditions.checkArgument(dest != null, "Destinationipv6Address is mandatory.");
+ checkArgument(dest != null, "Destinationipv6Address is mandatory.");
final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH * dest.size());
- dest.forEach(ipv6 -> writeIpv6Address(ipv6, body));
+ dest.forEach(ipv6 -> Ipv6Util.writeIpv6Address(ipv6, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
@Override
public UnreachDestinationObj 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. Can't be null or empty.");
final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
if (bytes.readableBytes() % Ipv6Util.IPV6_LENGTH != 0) {
throw new PCEPDeserializerException("Wrong length of array of bytes.");
*/
package org.opendaylight.protocol.pcep.parser.subobject;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.IpPrefixSubobject;
* Parser for {@link IpPrefixCase}.
*/
public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
public static final int TYPE = 1;
private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
private static final int RESERVED = 1;
-
private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + RESERVED + 1;
@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. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new PCEPDeserializerException(
"Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ 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());
- if (prefix.getIpv6Prefix() != null) {
- new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- body.writeZero(RESERVED);
- EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ final Ipv6Prefix ipv6prefix = prefix.getIpv6Prefix();
+ if (ipv6prefix != null) {
+ EROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6prefix);
+ return;
}
+
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ body.writeZero(RESERVED);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.IpPrefixSubobject;
* Parser for {@link IpPrefixCase}.
*/
public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
public static final int TYPE = 2;
private static final int PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
private static final int RESERVED = 1;
-
private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + RESERVED + 1;
@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. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new PCEPDeserializerException(
"Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ 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();
+ final Ipv6Prefix ipv6prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6prefix) {
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+ Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
body.writeZero(RESERVED);
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.IpPrefixSubobject;
@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. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new PCEPDeserializerException(
"Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ 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());
- if (prefix.getIpv6Prefix() != null) {
- new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final BitArray flags = new BitArray(FLAGS_SIZE);
- flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
- flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- flags.toByteBuf(body);
- RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
+ final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+ if (ipv6Prefix != null) {
+ RROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+ return;
}
+
+ final BitArray flags = new BitArray(FLAGS_SIZE);
+ flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+ flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ flags.toByteBuf(body);
+ RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}
*/
package org.opendaylight.protocol.pcep.parser.subobject;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.IpPrefixSubobject;
@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. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new PCEPDeserializerException(
"Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ 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();
+ final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6Prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6prefix) {
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+ Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
flags.toByteBuf(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.writeIpv4Prefix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
* Parser for {@link IpPrefixCase}.
*/
public class XROIpv4PrefixSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
-
public static final int TYPE = 1;
private static final int PREFIX_F_LENGTH = 1;
-
private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
checkArgument(ipv4Prefix != null, "Ipv4Prefix is mandatory.");
final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- writeIpv4Prefix(ipv4Prefix, body);
+ Ipv4Util.writeIpv4Prefix(ipv4Prefix, body);
final Attribute attribute = subobject.getAttribute();
checkArgument(attribute != null, "Attribute is mandatory.");
body.writeByte(attribute.getIntValue());
package org.opendaylight.protocol.pcep.parser.subobject;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
static void serializeSubobject(final ByteBuf buffer, final Subobject subobject, final Ipv6Prefix ipv6Prefix) {
final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
- writeIpv6Prefix(ipv6Prefix, body);
+ Ipv6Util.writeIpv6Prefix(ipv6Prefix, body);
final Attribute attribute = subobject.getAttribute();
checkArgument(attribute != null, "Attribute is mandatory.");
body.writeByte(attribute.getIntValue());
package org.opendaylight.protocol.pcep.ietf.stateful07;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
}
final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
checkArgument(ipv4.getIpv4TunnelSenderAddress() != null, "Ipv4TunnelSenderAddress is mandatory.");
- writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
+ Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
body.writeShort(lsp.getLspId().getValue().shortValue());
final TunnelId tunnelId = lsp.getTunnelId();
checkArgument(tunnelId != null, "TunnelId is mandatory.");
ByteBufUtils.write(body, tunnelId.getValue());
checkArgument(ipv4.getIpv4ExtendedTunnelId() != null, "Ipv4ExtendedTunnelId is mandatory.");
- writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
+ Ipv4Util.writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
checkArgument(ipv4.getIpv4TunnelEndpointAddress() != null, "Ipv4TunnelEndpointAddress is mandatory.");
- writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
+ Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
final ByteBuf body = Unpooled.buffer();
final Ipv6 ipv6 = ((Ipv6Case) lsp.getAddressFamily()).getIpv6();
checkArgument(ipv6.getIpv6TunnelSenderAddress() != null, "Ipv6TunnelSenderAddress is mandatory.");
- writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
+ Ipv6Util.writeIpv6Address(ipv6.getIpv6TunnelSenderAddress(), body);
final LspId lspId = lsp.getLspId();
checkArgument(lspId != null, "LspId is mandatory.");
checkArgument(tunnelId != null, "TunnelId is mandatory.");
ByteBufUtils.write(body, tunnelId.getValue());
checkArgument(ipv6.getIpv6ExtendedTunnelId() != null, "Ipv6ExtendedTunnelId is mandatory.");
- writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
+ Ipv6Util.writeIpv6Address(ipv6.getIpv6ExtendedTunnelId(), body);
checkArgument(ipv6.getIpv6TunnelEndpointAddress() != null, "Ipv6TunnelEndpointAddress is mandatory.");
- writeIpv6Address(ipv6.getIpv6TunnelEndpointAddress(), body);
+ Ipv6Util.writeIpv6Address(ipv6.getIpv6TunnelEndpointAddress(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
package org.opendaylight.protocol.pcep.ietf.stateful07;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
int type = 0;
if (node.getIpv4AddressNoZone() != null) {
type = RSVP_IPV4_ERROR_CLASS_TYPE;
- writeIpv4Address(node.getIpv4AddressNoZone(), rsvpObjBuf);
+ Ipv4Util.writeIpv4Address(node.getIpv4AddressNoZone(), rsvpObjBuf);
} else {
type = RSVP_IPV6_ERROR_CLASS_TYPE;
- writeIpv6Address(node.getIpv6AddressNoZone(), rsvpObjBuf);
+ Ipv6Util.writeIpv6Address(node.getIpv6AddressNoZone(), rsvpObjBuf);
}
flags.toByteBuf(rsvpObjBuf);
ByteBufUtils.writeMandatory(rsvpObjBuf, rsvp.getCode(), "Code");
package org.opendaylight.protocol.pcep.segment.routing;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
private static void serializeNai(final Nai nai, final SidType sidType, final ByteBuf buffer) {
switch (sidType) {
case Ipv4NodeId:
- writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4AddressNoZone(), buffer);
+ Ipv4Util.writeIpv4Address(((IpNodeId) nai).getIpAddress().getIpv4AddressNoZone(), buffer);
break;
case Ipv6NodeId:
- writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6AddressNoZone(), buffer);
+ Ipv6Util.writeIpv6Address(((IpNodeId) nai).getIpAddress().getIpv6AddressNoZone(), buffer);
break;
case Ipv4Adjacency:
- writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4AddressNoZone(), buffer);
- writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4AddressNoZone(), buffer);
+ Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getLocalIpAddress().getIpv4AddressNoZone(), buffer);
+ Ipv4Util.writeIpv4Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv4AddressNoZone(), buffer);
break;
case Ipv6Adjacency:
- writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6AddressNoZone(), buffer);
- writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6AddressNoZone(), buffer);
+ Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getLocalIpAddress().getIpv6AddressNoZone(), buffer);
+ Ipv6Util.writeIpv6Address(((IpAdjacency) nai).getRemoteIpAddress().getIpv6AddressNoZone(), buffer);
break;
case Unnumbered:
final UnnumberedAdjacency unnumbered = (UnnumberedAdjacency) nai;
*/
package org.opendaylight.protocol.rsvp.parser.impl.subobject.ero;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
* Parser for {@link IpPrefixCase}.
*/
public class EROIpv4PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
public static final int TYPE = 1;
private static final int PREFIX4_F_OFFSET = Ipv4Util.IP4_LENGTH;
-
private static final int RESERVED = 1;
-
private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + RESERVED + 1;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) 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. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setLoose(loose);
if (buffer.readableBytes() != CONTENT4_LENGTH) {
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
- Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase,
+ 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());
- if (prefix.getIpv6Prefix() != null) {
- new EROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- body.writeZero(RESERVED);
- EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
+ final Ipv6Prefix ipv6prefix = prefix.getIpv6Prefix();
+ if (ipv6prefix != null) {
+ EROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6prefix);
+ return;
}
+
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ body.writeZero(RESERVED);
+ EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
}
}
*/
package org.opendaylight.protocol.rsvp.parser.impl.subobject.ero;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
* Parser for {@link IpPrefixCase}.
*/
public class EROIpv6PrefixSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
-
public static final int TYPE = 2;
private static final int PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
-
private static final int RESERVED = 1;
-
private static final int CONTENT_LENGTH = PREFIX_F_OFFSET + RESERVED + 1;
@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean loose) 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. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setLoose(loose);
if (buffer.readableBytes() != CONTENT_LENGTH) {
@Override
public void serializeSubobject(final SubobjectContainer 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();
+ final Ipv6Prefix ipv6prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final SubobjectContainer subobject,
+ final Ipv6Prefix ipv6prefix) {
final ByteBuf body = Unpooled.buffer();
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+ Ipv6Util.writeIpv6Prefix(ipv6prefix, body);
body.writeZero(RESERVED);
EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), 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 org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
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. Can't be null or empty.");
if (buffer.readableBytes() != CONTENT4_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
}
@Override
public void serializeSubobject(final SubobjectContainer 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());
- if (prefix.getIpv6Prefix() != null) {
- new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final BitArray flags = new BitArray(FLAGS_SIZE);
- flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
- flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- flags.toByteBuf(body);
- RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
+ final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+ if (ipv6Prefix != null) {
+ RROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+ return;
}
+
+ final BitArray flags = new BitArray(FLAGS_SIZE);
+ flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+ flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ flags.toByteBuf(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.rro;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
+import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
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. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
if (buffer.readableBytes() != CONTENT_LENGTH) {
throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
@Override
public void serializeSubobject(final SubobjectContainer 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();
+ final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6Prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final SubobjectContainer subobject,
+ final Ipv6Prefix ipv6Prefix) {
final BitArray flags = new BitArray(FLAGS_SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
- Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
+ Ipv6Util.writeIpv6Prefix(ipv6Prefix, body);
flags.toByteBuf(body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.xro;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
private static final int CONTENT4_LENGTH = PREFIX4_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
- public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
- RSVPParsingException {
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
+ throws RSVPParsingException {
checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setMandatory(mandatory);
type.getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
final IpPrefix prefix = specObj.getIpPrefix();
- checkArgument(prefix.getIpv4Prefix() != null || prefix.getIpv6Prefix() != null,
- "Unknown AbstractPrefix instance. Passed %s.", prefix.getClass());
- if (prefix.getIpv6Prefix() != null) {
- new XROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
- } else {
- final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
- checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
- writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- body.writeByte(subobject.getAttribute().getIntValue());
- XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
+ final Ipv6Prefix ipv6Prefix = prefix.getIpv6Prefix();
+ if (ipv6Prefix != null) {
+ XROIpv6PrefixSubobjectParser.serializeSubobject(buffer, subobject, ipv6Prefix);
+ return;
}
+
+ final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
+ checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
+ Ipv4Util.writeIpv4Prefix(prefix.getIpv4Prefix(), body);
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(attribute.getIntValue());
+ XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}
}
package org.opendaylight.protocol.rsvp.parser.impl.subobject.xro;
import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv6Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
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.ExcludeRouteSubobjects.Attribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
private static final int CONTENT6_LENGTH = PREFIX6_F_OFFSET + PREFIX_F_LENGTH + 1;
@Override
- public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws
- RSVPParsingException {
+ public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory)
+ throws RSVPParsingException {
checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
builder.setMandatory(mandatory);
@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
final SubobjectType type = subobject.getSubobjectType();
- checkArgument(type instanceof IpPrefixCase,
- "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
+ checkArgument(type instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.",
type.getClass());
final IpPrefixSubobject specObj = ((IpPrefixCase) type).getIpPrefix();
- final IpPrefix prefix = specObj.getIpPrefix();
+ final Ipv6Prefix ipv6Prefix = specObj.getIpPrefix().getIpv6Prefix();
+ checkArgument(ipv6Prefix != null, "Ipv6Prefix is mandatory.");
+ serializeSubobject(buffer, subobject, ipv6Prefix);
+ }
+
+ static void serializeSubobject(final ByteBuf buffer, final SubobjectContainer subobject,
+ final Ipv6Prefix ipv6Prefix) {
final ByteBuf body = Unpooled.buffer(CONTENT6_LENGTH);
- checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
- writeIpv6Prefix(prefix.getIpv6Prefix(), body);
- checkArgument(subobject.getAttribute() != null, "Attribute is mandatory.");
- body.writeByte(subobject.getAttribute().getIntValue());
+ Ipv6Util.writeIpv6Prefix(ipv6Prefix, body);
+ final Attribute attribute = subobject.getAttribute();
+ checkArgument(attribute != null, "Attribute is mandatory.");
+ body.writeByte(attribute.getIntValue());
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 java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.rsvp.parser.spi.subobjects.AbstractRSVPObjectParser;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.Ipv4Util;
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.detour.object.detour.object.Ipv4DetourObject;
@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(teLspObject instanceof Ipv4DetourObject, "DetourObject is mandatory.");
+ checkArgument(teLspObject instanceof Ipv4DetourObject, "DetourObject is mandatory.");
final Ipv4DetourObject detourObject = (Ipv4DetourObject) teLspObject;
final List<Plr> list = detourObject.getPlr();
serializeAttributeHeader(list.size() * 2 * Ipv4Util.IP4_LENGTH, CLASS_NUM, CTYPE, byteAggregator);
for (final Plr plr : list) {
- ByteBufWriteUtil.writeIpv4Address(plr.getPlrId(), byteAggregator);
- ByteBufWriteUtil.writeIpv4Address(plr.getAvoidNode(), byteAggregator);
+ Ipv4Util.writeIpv4Address(plr.getPlrId(), byteAggregator);
+ Ipv4Util.writeIpv4Address(plr.getAvoidNode(), byteAggregator);
}
}
}
package org.opendaylight.protocol.util;
import io.netty.buffer.ByteBuf;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
/**
// Hidden on purpose
}
- /**
- * Writes IPv4 address if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
- *
- * @param ipv4Address
- * IPv4 address to be written to the output.
- * @param output
- * ByteBuf, where ipv4Address or zeros are written.
- */
- public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) {
- if (ipv4Address != null) {
- output.writeBytes(Ipv4Util.bytesForAddress(ipv4Address));
- } else {
- output.writeInt(0);
- }
- }
-
- /**
- * Writes IPv4 address if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
- *
- * @param ipv4Address
- * IPv4 address to be written to the output.
- * @param output
- * ByteBuf, where ipv4Address or zeros are written.
- */
- public static void writeIpv4Address(final Ipv4AddressNoZone ipv4Address, final ByteBuf output) {
- if (ipv4Address != null) {
- output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
- } else {
- output.writeInt(0);
- }
- }
-
- /**
- * Writes IPv4 prefix if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
- *
- * @param ipv4Prefix
- * IPv4 prefix value to be written to the output. Prefix is
- * written in the last byte.
- * @param output
- * ByteBuf, where ipv4Prefix or zeros are written.
- */
- public static void writeIpv4Prefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
- if (ipv4Prefix != null) {
- output.writeBytes(Ipv4Util.bytesForPrefix(ipv4Prefix));
- } else {
- output.writeZero(Ipv4Util.PREFIX_BYTE_LENGTH);
- }
- }
-
- /**
- * Writes IPv6 address if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
- *
- * @param ipv6Address
- * IPv6 address to be written to the output.
- * @param output
- * ByteBuf, where ipv6Address or zeros are written.
- */
- public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
- if (ipv6Address != null) {
- output.writeBytes(Ipv6Util.bytesForAddress(ipv6Address));
- } else {
- output.writeZero(Ipv6Util.IPV6_LENGTH);
- }
- }
-
- /**
- * Writes IPv6 address if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
- *
- * @param ipv6Address
- * IPv6 address to be written to the output.
- * @param output
- * ByteBuf, where ipv6Address or zeros are written.
- */
- public static void writeIpv6Address(final Ipv6AddressNoZone ipv6Address, final ByteBuf output) {
- if (ipv6Address != null) {
- output.writeBytes(IetfInetUtil.INSTANCE.ipv6AddressNoZoneBytes(ipv6Address));
- } else {
- output.writeZero(Ipv6Util.IPV6_LENGTH);
- }
- }
-
- /**
- * Writes IPv6 prefix if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.
- *
- * @param ipv6Prefix
- * IPv6 prefix to be written to the output. Prefix is written in
- * the last byte.
- * @param output
- * ByteBuf, where ipv6Prefix or zeros are written.
- */
- public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
- if (ipv6Prefix != null) {
- output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix));
- } else {
- output.writeZero(Ipv6Util.PREFIX_BYTE_LENGTH);
- }
- }
-
- public static void writeMinimalPrefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
- final byte[] bytes = IetfInetUtil.INSTANCE.ipv4PrefixToBytes(ipv4Prefix);
- writeMinimalPrefix(output, bytes, bytes[Ipv4Util.IP4_LENGTH]);
- }
-
- public static void writeMinimalPrefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
- final byte[] bytes = IetfInetUtil.INSTANCE.ipv6PrefixToBytes(ipv6Prefix);
- writeMinimalPrefix(output, bytes, bytes[Ipv6Util.IPV6_LENGTH]);
- }
-
- private static void writeMinimalPrefix(final ByteBuf output, final byte[] bytes, final byte prefixBits) {
- output.writeByte(prefixBits);
- output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits)));
- }
-
/**
* Writes Float32 <code>value</code> if not null, otherwise writes zeros to
* the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
* Returns number of minimum bytes needed to cover all bits of prefix.
*/
public static int getPrefixLengthBytes(final String prefix) {
- return prefixBitsToBytes(Ipv4Util.getPrefixLength(prefix));
+ return prefixBitsToBytes(getPrefixLength(prefix));
}
/**
}
return ipAddress.getIpv6Address().getValue();
}
+
+
+ /**
+ * Writes IPv4 address if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
+ *
+ * @param ipv4Address
+ * IPv4 address to be written to the output.
+ * @param output
+ * ByteBuf, where ipv4Address or zeros are written.
+ */
+ public static void writeIpv4Address(final Ipv4Address ipv4Address, final ByteBuf output) {
+ if (ipv4Address != null) {
+ output.writeBytes(bytesForAddress(ipv4Address));
+ } else {
+ output.writeInt(0);
+ }
+ }
+
+ /**
+ * Writes IPv4 address if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
+ *
+ * @param ipv4Address
+ * IPv4 address to be written to the output.
+ * @param output
+ * ByteBuf, where ipv4Address or zeros are written.
+ */
+ public static void writeIpv4Address(final Ipv4AddressNoZone ipv4Address, final ByteBuf output) {
+ if (ipv4Address != null) {
+ output.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressNoZoneBytes(ipv4Address));
+ } else {
+ output.writeInt(0);
+ }
+ }
+
+ /**
+ * Writes IPv4 prefix if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 5.
+ *
+ * @param ipv4Prefix
+ * IPv4 prefix value to be written to the output. Prefix is
+ * written in the last byte.
+ * @param output
+ * ByteBuf, where ipv4Prefix or zeros are written.
+ */
+ public static void writeIpv4Prefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
+ if (ipv4Prefix != null) {
+ output.writeBytes(bytesForPrefix(ipv4Prefix));
+ } else {
+ output.writeZero(PREFIX_BYTE_LENGTH);
+ }
+ }
+
+ public static void writeMinimalPrefix(final Ipv4Prefix ipv4Prefix, final ByteBuf output) {
+ final byte[] bytes = IetfInetUtil.INSTANCE.ipv4PrefixToBytes(ipv4Prefix);
+ writeMinimalPrefix(output, bytes, bytes[IP4_LENGTH]);
+ }
+
+ static void writeMinimalPrefix(final ByteBuf output, final byte[] bytes, final byte prefixBits) {
+ output.writeByte(prefixBits);
+ output.writeBytes(bytes, 0, prefixBitsToBytes(Byte.toUnsignedInt(prefixBits)));
+ }
}
}
return list;
}
+
+ /**
+ * Writes IPv6 address if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
+ *
+ * @param ipv6Address
+ * IPv6 address to be written to the output.
+ * @param output
+ * ByteBuf, where ipv6Address or zeros are written.
+ */
+ public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
+ if (ipv6Address != null) {
+ output.writeBytes(bytesForAddress(ipv6Address));
+ } else {
+ output.writeZero(IPV6_LENGTH);
+ }
+ }
+
+ /**
+ * Writes IPv6 address if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16.
+ *
+ * @param ipv6Address
+ * IPv6 address to be written to the output.
+ * @param output
+ * ByteBuf, where ipv6Address or zeros are written.
+ */
+ public static void writeIpv6Address(final Ipv6AddressNoZone ipv6Address, final ByteBuf output) {
+ if (ipv6Address != null) {
+ output.writeBytes(IetfInetUtil.INSTANCE.ipv6AddressNoZoneBytes(ipv6Address));
+ } else {
+ output.writeZero(IPV6_LENGTH);
+ }
+ }
+
+ /**
+ * Writes IPv6 prefix if not null, otherwise writes zeros to the
+ * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17.
+ *
+ * @param ipv6Prefix
+ * IPv6 prefix to be written to the output. Prefix is written in
+ * the last byte.
+ * @param output
+ * ByteBuf, where ipv6Prefix or zeros are written.
+ */
+ public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
+ if (ipv6Prefix != null) {
+ output.writeBytes(bytesForPrefix(ipv6Prefix));
+ } else {
+ output.writeZero(PREFIX_BYTE_LENGTH);
+ }
+ }
+
+ public static void writeMinimalPrefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
+ final byte[] bytes = IetfInetUtil.INSTANCE.ipv6PrefixToBytes(ipv6Prefix);
+ Ipv4Util.writeMinimalPrefix(output, bytes, bytes[IPV6_LENGTH]);
+ }
}
import static org.junit.Assert.assertArrayEquals;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
public class ByteBufWriteUtilTest {
private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
- @Test
- public void testWriteIpv4Address() {
- final byte[] result = { 127, 0, 0, 1 };
- final ByteBuf output = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
- writeIpv4Address(new Ipv4Address("127.0.0.1"), output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- writeIpv4Address(null, output);
- assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
- }
-
- @Test
- public void testWriteIpv4Prefix() {
- final byte[] result = { 123, 122, 4, 5, 8 };
- final ByteBuf output = Unpooled.buffer(Ipv4Util.PREFIX_BYTE_LENGTH);
- writeIpv4Prefix(new Ipv4Prefix("123.122.4.5/8"), output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- final byte[] zeroResult = { 0, 0, 0, 0, 0 };
- writeIpv4Prefix(null, output);
- assertArrayEquals(zeroResult, output.array());
- }
-
- @Test
- public void testWriteIpv6Address() {
- final byte[] result = { 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x01 };
- final ByteBuf output = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
- writeIpv6Address(new Ipv6Address("2001::1"), output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
- writeIpv6Address(null, output);
- assertArrayEquals(zeroResult, output.array());
- }
-
- @Test
- public void testWriteIpv6Prefix() {
- final byte[] result = { 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x40 };
- final ByteBuf output = Unpooled.buffer(Ipv6Util.PREFIX_BYTE_LENGTH);
- writeIpv6Prefix(new Ipv6Prefix("2001:db8:1:2::/64"), output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- writeIpv6Prefix(null, output);
- assertArrayEquals(zeroResult, output.array());
- }
-
@Test
public void testWriteFloat32() {
final byte[] result = { 0, 0, 0, 5 };
--- /dev/null
+/*
+ * Copyright (c) 2020 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.assertArrayEquals;
+import static org.opendaylight.protocol.util.Ipv4Util.writeIpv4Address;
+import static org.opendaylight.protocol.util.Ipv4Util.writeIpv4Prefix;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+
+public class Ipv4UtilTest {
+ private static final byte[] FOUR_BYTE_ZEROS = { 0, 0, 0, 0 };
+
+ @Test
+ public void testWriteIpv4Address() {
+ final byte[] result = { 127, 0, 0, 1 };
+ final ByteBuf output = Unpooled.buffer(Ipv4Util.IP4_LENGTH);
+ writeIpv4Address(new Ipv4Address("127.0.0.1"), output);
+ assertArrayEquals(result, output.array());
+
+ output.clear();
+ writeIpv4Address(null, output);
+ assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
+ }
+
+ @Test
+ public void testWriteIpv4Prefix() {
+ final byte[] result = { 123, 122, 4, 5, 8 };
+ final ByteBuf output = Unpooled.buffer(Ipv4Util.PREFIX_BYTE_LENGTH);
+ writeIpv4Prefix(new Ipv4Prefix("123.122.4.5/8"), output);
+ assertArrayEquals(result, output.array());
+
+ output.clear();
+ final byte[] zeroResult = { 0, 0, 0, 0, 0 };
+ writeIpv4Prefix(null, output);
+ assertArrayEquals(zeroResult, output.array());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 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.assertArrayEquals;
+import static org.opendaylight.protocol.util.Ipv6Util.writeIpv6Address;
+import static org.opendaylight.protocol.util.Ipv6Util.writeIpv6Prefix;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+
+public class Ipv6UtilTest {
+ @Test
+ public void testWriteIpv6Address() {
+ final byte[] result = { 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01 };
+ final ByteBuf output = Unpooled.buffer(Ipv6Util.IPV6_LENGTH);
+ writeIpv6Address(new Ipv6Address("2001::1"), output);
+ assertArrayEquals(result, output.array());
+
+ output.clear();
+ final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
+ writeIpv6Address(null, output);
+ assertArrayEquals(zeroResult, output.array());
+ }
+
+ @Test
+ public void testWriteIpv6Prefix() {
+ final byte[] result = { 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x40 };
+ final ByteBuf output = Unpooled.buffer(Ipv6Util.PREFIX_BYTE_LENGTH);
+ writeIpv6Prefix(new Ipv6Prefix("2001:db8:1:2::/64"), output);
+ assertArrayEquals(result, output.array());
+
+ output.clear();
+ final byte[] zeroResult = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ writeIpv6Prefix(null, output);
+ assertArrayEquals(zeroResult, output.array());
+ }
+}