final ApplyRoute function) {
if (destination != null) {
final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination
- .getChild(nlriRoutesList);
+ .getChild(this.nlriRoutesList);
if (maybeRoutes.isPresent()) {
final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
if (routes instanceof UnkeyedListNode) {
final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
for (final UnkeyedListEntryNode mvpnDest : ((UnkeyedListNode) routes).getValue()) {
- final YangInstanceIdentifier.NodeIdentifierWithPredicates routeKey = createRouteKey(mvpnDest);
+ final NodeIdentifierWithPredicates routeKey = createRouteKey(mvpnDest);
function.apply(tx, base, routeKey, mvpnDest, attributes);
}
} else {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.MulticastSourceRdGrouping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.MvpnChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.s.pmsi.a.d.grouping.SPmsiADBuilder;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
/**
* Abstract Mvpn Nlri.
* @author Claudio D. Gasparini
*/
abstract class AbstractMvpnNlri<T extends MvpnChoice> implements MvpnSerializer<T>, MvpnParser<T> {
- static final NodeIdentifier RD_NID = NodeIdentifier.create(QName.create(MvpnChoice.QNAME,
- "route-distinguisher").intern());
- static final NodeIdentifier ORI_NID = NodeIdentifier.create(QName.create(MvpnChoice.QNAME,
- "orig-route-ip").intern());
- static final NodeIdentifier SOURCE_AS_NID = NodeIdentifier.create(QName.create(MvpnChoice.QNAME,
- "source-as").intern());
- static final NodeIdentifier MULTICAST_SOURCE_NID = NodeIdentifier.create(QName.create(MvpnChoice.QNAME,
- "multicast-source").intern());
- static final NodeIdentifier MULTICAST_GROUP_NID = NodeIdentifier.create(QName.create(MvpnChoice.QNAME,
- "multicast-group").intern());
-
- @Override
- public final ByteBuf serializeMvpn(final T mvpn, final ByteBuf common) {
- final ByteBuf output = Unpooled.buffer();
- final ByteBuf body = serializeBody(mvpn);
- output.writeByte(getType());
- output.writeByte(body.readableBytes() + common.readableBytes());
- output.writeBytes(common);
- output.writeBytes(body);
- return output;
- }
-
- protected abstract ByteBuf serializeBody(T mvpn);
-
-
- static final MulticastSourceRdGrouping parseRDMulticastSource(final ByteBuf buffer) {
+ static MulticastSourceRdGrouping parseRDMulticastSource(final ByteBuf buffer) {
final SPmsiADBuilder builder = new SPmsiADBuilder();
builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(buffer));
final IpAddress address = IpAddressUtil.addressForByteBuf(buffer);
return builder.build();
}
- static final void serializeRDMulticastSource(final MulticastSourceRdGrouping route, final ByteBuf output) {
+ static void serializeRDMulticastSource(final MulticastSourceRdGrouping route, final ByteBuf output) {
RouteDistinguisherUtil.serializeRouteDistinquisher(route.getRouteDistinguisher(), output);
output.writeBytes(IpAddressUtil.bytesFor(route.getMulticastSource()));
}
+
+ @Override
+ public final ByteBuf serializeMvpn(final T mvpn) {
+ final ByteBuf output = Unpooled.buffer();
+ final ByteBuf body = serializeBody(mvpn);
+ output.writeByte(getType());
+ output.writeByte(body.readableBytes());
+ output.writeBytes(body);
+ return output;
+ }
+
+ protected abstract ByteBuf serializeBody(T mvpn);
}
package org.opendaylight.protocol.bgp.mvpn.impl.nlri;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.bgp.mvpn.spi.pojo.nlri.SimpleMvpnNlriRegistry;
}
static DestinationMvpnIpv4AdvertizedCase parseIpv4ReachNlri(
- final ByteBuf nlri,
- final boolean addPathSupported) {
- List<MvpnDestination> dests = new ArrayList<>();
+ final ByteBuf nlri,
+ final boolean addPathSupported) {
+ final List<MvpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final MvpnDestinationBuilder builder = new MvpnDestinationBuilder();
}
return new DestinationMvpnIpv4AdvertizedCaseBuilder()
- .setDestinationMvpn(new DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
+ .setDestinationMvpn(new DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
}
static DestinationMvpnIpv4WithdrawnCase parseIpv4UnreachNlri(
- final ByteBuf nlri,
- final boolean addPathSupported) {
- List<MvpnDestination> dests = new ArrayList<>();
+ final ByteBuf nlri,
+ final boolean addPathSupported) {
+ final List<MvpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final MvpnDestinationBuilder builder = new MvpnDestinationBuilder();
}
return new DestinationMvpnIpv4WithdrawnCaseBuilder().setDestinationMvpn(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv4.rev180417.update
- .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.mvpn.ipv4
- .withdrawn._case.DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv4.rev180417.update
+ .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.mvpn.ipv4
+ .withdrawn._case.DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
}
public static void serializeNlri(final List<MvpnDestination> destinationList, final ByteBuf output) {
- ByteBuf nlriOutput = null;
for (final MvpnDestination dest : destinationList) {
- final ByteBuf nlriCommon = Unpooled.buffer();
- nlriOutput = SimpleMvpnNlriRegistry.getInstance().serializeMvpn(dest.getMvpnChoice(), nlriCommon);
+ output.writeBytes(SimpleMvpnNlriRegistry.getInstance().serializeMvpn(dest.getMvpnChoice()));
}
- output.writeBytes(nlriOutput);
}
}
package org.opendaylight.protocol.bgp.mvpn.impl.nlri;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.bgp.mvpn.spi.pojo.nlri.SimpleMvpnNlriRegistry;
}
static DestinationMvpnIpv6AdvertizedCase parseIpv6ReachNlri(
- final ByteBuf nlri,
- final boolean addPathSupported) {
- List<MvpnDestination> dests = new ArrayList<>();
+ final ByteBuf nlri,
+ final boolean addPathSupported) {
+ final List<MvpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final MvpnDestinationBuilder builder = new MvpnDestinationBuilder();
}
return new DestinationMvpnIpv6AdvertizedCaseBuilder().setDestinationMvpn(
- new DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
+ new DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
}
static DestinationMvpnIpv6WithdrawnCase parseIpv6UnreachNlri(
- final ByteBuf nlri,
- final boolean addPathSupported) {
- List<MvpnDestination> dests = new ArrayList<>();
+ final ByteBuf nlri,
+ final boolean addPathSupported) {
+ final List<MvpnDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final MvpnDestinationBuilder builder = new MvpnDestinationBuilder();
}
return new DestinationMvpnIpv6WithdrawnCaseBuilder().setDestinationMvpn(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv6.rev180417.update
- .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.mvpn.ipv6.withdrawn
- ._case.DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv6.rev180417.update
+ .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.mvpn.ipv6.withdrawn
+ ._case.DestinationMvpnBuilder().setMvpnDestination(dests).build()).build();
}
public static void serializeNlri(final List<MvpnDestination> destinationList, final ByteBuf output) {
- ByteBuf nlriOutput = null;
for (final MvpnDestination dest : destinationList) {
- final ByteBuf nlriCommon = Unpooled.buffer();
- nlriOutput = SimpleMvpnNlriRegistry.getInstance().serializeMvpn(dest.getMvpnChoice(), nlriCommon);
+ output.writeBytes(SimpleMvpnNlriRegistry.getInstance().serializeMvpn(dest.getMvpnChoice()));
}
- output.writeBytes(nlriOutput);
}
}
keyCase = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn
.mvpn.choice.SPmsiADCaseBuilder((SPmsiADCase) key).build();
}
- nlriByteBuf.writeBytes(SimpleMvpnNlriRegistry.getInstance().serializeMvpn(keyCase, nlriByteBuf));
+ nlriByteBuf.writeBytes(SimpleMvpnNlriRegistry.getInstance().serializeMvpn(keyCase));
final ByteBuf orig = IpAddressUtil.bytesWOLengthFor(leaf.getOrigRouteIp());
Preconditions.checkArgument(orig.readableBytes() > 0);
nlriByteBuf.writeBytes(orig);
static MulticastGroup multicastGroupForByteBuf(final ByteBuf buffer) {
final short multicastGroupLength = buffer.readUnsignedByte();
- if (multicastGroupLength == Ipv4Util.IP4_BITS_LENGTH) {
- return new CGAddressCaseBuilder().setCGAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build();
- } else if (multicastGroupLength == Ipv6Util.IPV6_BITS_LENGTH) {
- return new CGAddressCaseBuilder().setCGAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
- } else {
- return new LdpMpOpaqueValueCaseBuilder()
+ switch (multicastGroupLength) {
+ case Ipv4Util.IP4_BITS_LENGTH:
+ return new CGAddressCaseBuilder()
+ .setCGAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build();
+ case Ipv6Util.IPV6_BITS_LENGTH:
+ return new CGAddressCaseBuilder()
+ .setCGAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build();
+ default:
+ return new LdpMpOpaqueValueCaseBuilder()
.setLdpMpOpaqueValue(new LdpMpOpaqueValueBuilder(OpaqueUtil.parseOpaque(buffer)).build()).build();
}
}
* Encode input BGP mvpn to output buffer.
*
* @param mvpn MvpnChoice
- * @param common encoded common mvpn
* @return encoded MvpnChoice body in Bytebuf
*/
@Nonnull
- ByteBuf serializeMvpn(@Nonnull MvpnChoice mvpn, @Nonnull ByteBuf common);
+ ByteBuf serializeMvpn(@Nonnull MvpnChoice mvpn);
}
* Serialize mvpn.
*
* @param mvpn mvpn
- * @param buffer Encode common mvpn parts to output buffer
* @return Encode mvpn to output buffer
*/
@Nonnull
- ByteBuf serializeMvpn(@Nonnull T mvpn, @Nonnull ByteBuf buffer);
+ ByteBuf serializeMvpn(@Nonnull T mvpn);
/**
* returns class of MvpnChoice handled by serializer.
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.opendaylight.protocol.bgp.mvpn.spi.nlri.MvpnParser;
import org.opendaylight.protocol.bgp.mvpn.spi.nlri.MvpnRegistry;
import org.opendaylight.protocol.bgp.mvpn.spi.nlri.MvpnSerializer;
return parser.parseMvpn(nlriBuf);
}
- public ByteBuf serializeMvpn(final MvpnChoice mvpn, final ByteBuf nlriBuf) {
+ public ByteBuf serializeMvpn(final MvpnChoice mvpn) {
final MvpnSerializer serializer = this.handlers.getSerializer(mvpn.getImplementedInterface());
if (serializer == null) {
- return nlriBuf;
+ return Unpooled.buffer();
}
- return serializer.serializeMvpn(mvpn, nlriBuf);
+ return serializer.serializeMvpn(mvpn);
}
}
@Override
public void setUp() throws Exception {
super.setUp();
- ribSupport = MvpnIpv4RIBSupport.getInstance(this.mappingService);
- setUpTestCustomizer(ribSupport);
+ this.ribSupport = MvpnIpv4RIBSupport.getInstance(this.mappingService);
+ setUpTestCustomizer(this.ribSupport);
NlriActivator.registerNlriParsers(new ArrayList<>());
}
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableSet;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.junit.Test;
@Override
public void setUp() throws Exception {
super.setUp();
- ribSupport = MvpnIpv6RIBSupport.getInstance(this.mappingService);
- setUpTestCustomizer(ribSupport);
+ this.ribSupport = MvpnIpv6RIBSupport.getInstance(this.mappingService);
+ setUpTestCustomizer(this.ribSupport);
+ NlriActivator.registerNlriParsers(new ArrayList<>());
}
@Test
.setGlobalAdministrator(new ShortAsNumber(1L))
.build()).build();
- final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
final ByteBuf output = Unpooled.buffer(INPUT.length);
- handler.serializeExtendedCommunity(expected, output);
+ this.handler.serializeExtendedCommunity(expected, output);
Assert.assertArrayEquals(INPUT, output.array());
assertEquals(9, this.handler.getSubType());
.build())
.build();
- final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
- Assert.assertEquals(expected, exComm);
+ final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ assertEquals(expected, exComm);
final ByteBuf output = Unpooled.buffer(INPUT.length);
- handler.serializeExtendedCommunity(expected, output);
+ this.handler.serializeExtendedCommunity(expected, output);
Assert.assertArrayEquals(INPUT, output.array());
assertEquals(11, this.handler.getSubType());
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testInterASIPmsiADSerializer() {
- final ByteBuf buff = Unpooled.buffer(INTER_AS_TYPE_LENGTH.length);
- assertArrayEquals(INTER_AS_TYPE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buff)));
+ assertArrayEquals(INTER_AS_TYPE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testIntraASIPmsiADSerializer() {
- final ByteBuf buff = Unpooled.buffer(INTRA_AS_TYPE_LENGTH.length);
- assertArrayEquals(INTRA_AS_TYPE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buff)));
+ assertArrayEquals(INTRA_AS_TYPE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import org.junit.Before;
@Test
public void testSerializer() {
- final ByteBuf buffer = Unpooled.buffer(LEAF_AD_LENGTH.length);
- assertArrayEquals(LEAF_AD_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buffer)));
+ assertArrayEquals(LEAF_AD_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testIntraASIPmsiADSerializer() {
- final ByteBuf buffer = Unpooled.buffer(SP_MSI_AD_LENGTH.length);
- assertArrayEquals(SP_MSI_AD_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buffer)));
+ assertArrayEquals(SP_MSI_AD_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testSerializer() {
- final ByteBuf buffer = Unpooled.buffer(SHARED_TREE_LENGTH.length);
- assertArrayEquals(SHARED_TREE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buffer)));
+ assertArrayEquals(SHARED_TREE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testSerializer() {
- final ByteBuf buff = Unpooled.buffer(SOURCE_ACTIVE_LENGTH.length);
- assertArrayEquals(SOURCE_ACTIVE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buff)));
+ assertArrayEquals(SOURCE_ACTIVE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
@Test
public void testSerializer() {
- final ByteBuf buffer = Unpooled.buffer(SHARED_TREE_LENGTH.length);
- assertArrayEquals(SHARED_TREE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected, buffer)));
+ assertArrayEquals(SHARED_TREE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
}
@Test
@Test
public void registryNullTest() {
final ByteBuf body = Unpooled.buffer();
- SimpleMvpnNlriRegistry.getInstance().serializeMvpn(new NotRegistered(), body);
+ SimpleMvpnNlriRegistry.getInstance().serializeMvpn(new NotRegistered());
assertEquals(0, body.readableBytes());
}