package org.opendaylight.bgp.concepts;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
}
}
- /**
- * Returns byte array containing IpAddress.
- *
- * @param address containing ipv4 or ipv6 address
- * @return byte array
- */
- public static @NonNull ByteBuf bytesWOLengthFor(final IpAddressNoZone address) {
- final ByteBuf body = Unpooled.buffer();
- if (address.getIpv4AddressNoZone() != null) {
- body.writeBytes(Ipv4Util.bytesForAddress(address.getIpv4AddressNoZone()));
- } else if (address.getIpv6AddressNoZone() != null) {
- body.writeBytes(Ipv6Util.bytesForAddress(address.getIpv6AddressNoZone()));
- } else {
- body.writeByte(0);
- }
- return body;
- }
-
public static IpAddressNoZone extractIpAddress(final DataContainerNode route, final NodeIdentifier rdNid) {
final var rdNode = NormalizedNodes.findNode(route, rdNid).orElse(null);
if (rdNode == null) {
import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
import org.opendaylight.protocol.bgp.mvpn.spi.nlri.MvpnParser;
import org.opendaylight.protocol.bgp.mvpn.spi.nlri.MvpnSerializer;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.MulticastSourceRdGrouping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.mvpn.MvpnChoice;
RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), output);
IpAddressUtil.writeBytesFor(route.getMulticastSource(), output);
}
+
+ static final void serializeAddress(final IpAddressNoZone address, final ByteBuf output) {
+ final var ipv4 = address.getIpv4AddressNoZone();
+ output.writeBytes(ipv4 != null ? Ipv4Util.bytesForAddress(ipv4)
+ : Ipv6Util.bytesForAddress(address.getIpv6AddressNoZone()));
+ }
}
final IntraAsIPmsiAD route = mvpn.getIntraAsIPmsiAD();
final ByteBuf nlriByteBuf = Unpooled.buffer();
RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), nlriByteBuf);
- final ByteBuf orig = IpAddressUtil.bytesWOLengthFor(route.getOrigRouteIp());
- checkArgument(orig.readableBytes() > 0);
- nlriByteBuf.writeBytes(orig);
+ serializeAddress(route.getOrigRouteIp(), nlriByteBuf);
return nlriByteBuf;
}
}
*/
package org.opendaylight.protocol.bgp.mvpn.impl.nlri;
-import static com.google.common.base.Preconditions.checkArgument;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opendaylight.bgp.concepts.IpAddressUtil;
.mvpn.choice.SPmsiADCaseBuilder((SPmsiADCase) key).build();
}
nlriByteBuf.writeBytes(SimpleMvpnNlriRegistry.getInstance().serializeMvpn(keyCase));
- final ByteBuf orig = IpAddressUtil.bytesWOLengthFor(leaf.getOrigRouteIp());
- checkArgument(orig.readableBytes() > 0);
- nlriByteBuf.writeBytes(orig);
+ serializeAddress(leaf.getOrigRouteIp(), nlriByteBuf);
return nlriByteBuf;
}
}
final ByteBuf nlriByteBuf = Unpooled.buffer();
serializeRDMulticastSource(route, nlriByteBuf);
MulticastGroupOpaqueUtil.bytesForMulticastGroup(route.getMulticastGroup(), nlriByteBuf);
- nlriByteBuf.writeBytes(IpAddressUtil.bytesWOLengthFor(route.getOrigRouteIp()));
+ serializeAddress(route.getOrigRouteIp(), nlriByteBuf);
return nlriByteBuf;
}
}