import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOriginIpv4EcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetAsTwoOctetEcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetIpv4EcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.SourceASHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.VrfRouteImportHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.Generic4OctASEcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.SourceAS4OctectHandler;
import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
regs.add(context.registerExtendedCommunityParser(encapsulationECHandler.getType(true), encapsulationECHandler.getSubType(),
encapsulationECHandler));
regs.add(context.registerExtendedCommunitySerializer(EncapsulationCase.class, encapsulationECHandler));
+
+
+ final SourceAS4OctectHandler source4ASHandler = new SourceAS4OctectHandler();
+ regs.add(context.registerExtendedCommunityParser(source4ASHandler.getType(true),
+ source4ASHandler.getSubType(), source4ASHandler));
+ regs.add(context.registerExtendedCommunitySerializer(SourceAs4ExtendedCommunityCase.class, source4ASHandler));
+
+ final SourceASHandler sourceASHandler = new SourceASHandler();
+ regs.add(context.registerExtendedCommunityParser(sourceASHandler.getType(true),
+ sourceASHandler.getSubType(), sourceASHandler));
+ regs.add(context.registerExtendedCommunitySerializer(SourceAsExtendedCommunityCase.class, sourceASHandler));
+
+ final VrfRouteImportHandler vrfRouteImportHandler = new VrfRouteImportHandler();
+ regs.add(context.registerExtendedCommunityParser(vrfRouteImportHandler.getType(true),
+ vrfRouteImportHandler.getSubType(), vrfRouteImportHandler));
+ regs.add(context.registerExtendedCommunitySerializer(SourceAsExtendedCommunityCase.class,
+ vrfRouteImportHandler));
}
}
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+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.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity;
-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.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.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunity;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
+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
- public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
- new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(
- Ipv4Util.addressForByteBuf(buffer)).setLocalAdministrator(
- ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH)).build()).build();
+ new Inet4SpecificExtendedCommunityBuilder()
+ .setInet4SpecificExtendedCommunityCommon(parseCommon(buffer))
+ .build()).build();
}
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
Preconditions.checkArgument(extendedCommunity instanceof Inet4SpecificExtendedCommunityCase,
- "The extended community %s is not Inet4SpecificExtendedCommunityCase type.", extendedCommunity);
- final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity = ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
- ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
- byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
+ "The extended community %s is not Inet4SpecificExtendedCommunityCase type.",
+ extendedCommunity);
+ final Inet4SpecificExtendedCommunity inet4SpecificExtendedCommunity
+ = ((Inet4SpecificExtendedCommunityCase) extendedCommunity).getInet4SpecificExtendedCommunity();
+
+ final Inet4SpecificExtendedCommunityCommon common
+ = inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon();
+ if (common != null) {
+ serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
+ } else {
+ ByteBufWriteUtil.writeIpv4Address(inet4SpecificExtendedCommunity.getGlobalAdministrator(), byteAggregator);
+ byteAggregator.writeBytes(inet4SpecificExtendedCommunity.getLocalAdministrator());
+ }
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Ints;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractTwoOctetAsExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunityBuilder;
+
+public final class SourceASHandler extends AbstractTwoOctetAsExtendedCommunity {
+ private static final short SUBTYPE = 9;
+ private static final int LOCAL_ADMIN = 0;
+
+ @Override
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
+ final SourceAsExtendedCommunityBuilder builder = new SourceAsExtendedCommunityBuilder();
+ builder.setGlobalAdministrator(new ShortAsNumber((long) buffer.readUnsignedShort()));
+ buffer.skipBytes(AS_LOCAL_ADMIN_LENGTH);
+ return new SourceAsExtendedCommunityCaseBuilder().setSourceAsExtendedCommunity(builder.build()).build();
+ }
+
+ @Override
+ public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+ Preconditions.checkArgument(extendedCommunity instanceof SourceAsExtendedCommunityCase,
+ "The extended community %s is not SourceAsExtendedCommunityCase type.",
+ extendedCommunity);
+ final SourceAsExtendedCommunity excomm = ((SourceAsExtendedCommunityCase) extendedCommunity)
+ .getSourceAsExtendedCommunity();
+ ByteBufWriteUtil.writeUnsignedShort(Ints.checkedCast(excomm.getGlobalAdministrator().getValue()), body);
+ ByteBufWriteUtil.writeInt(LOCAL_ADMIN, body);
+ }
+
+ @Override
+ public int getSubType() {
+ return SUBTYPE;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities;
+
+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.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.VrfRouteImportExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
+
+public final class VrfRouteImportHandler extends AbstractIpv4ExtendedCommunity {
+ private static final short SUBTYPE = 11;
+
+ @Override
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) {
+ return new VrfRouteImportExtendedCommunityCaseBuilder().setVrfRouteImportExtendedCommunity(
+ new VrfRouteImportExtendedCommunityBuilder()
+ .setInet4SpecificExtendedCommunityCommon(parseCommon(buffer))
+ .build()).build();
+ }
+
+ @Override
+ public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(extendedCommunity instanceof VrfRouteImportExtendedCommunityCase,
+ "The extended community %s is not VrfRouteImportExtendedCommunityCase type.",
+ extendedCommunity);
+ final VrfRouteImportExtendedCommunity inet4SpecificExtendedCommunity
+ = ((VrfRouteImportExtendedCommunityCase) extendedCommunity).getVrfRouteImportExtendedCommunity();
+ serializeCommon(inet4SpecificExtendedCommunity.getInet4SpecificExtendedCommunityCommon(), byteAggregator);
+ }
+
+ @Override
+ public int getSubType() {
+ return SUBTYPE;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.Abstract4OctetAsExtendedCommunity;
+import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as._4.extended.community._case.SourceAs4ExtendedCommunityBuilder;
+
+public final class SourceAS4OctectHandler extends Abstract4OctetAsExtendedCommunity {
+ private static final short SUBTYPE = 209;
+ private static final int LOCAL_ADMIN = 0;
+ private static final short LOCAL_LENGTH = 2;
+
+ @Override
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) {
+ final SourceAs4ExtendedCommunityBuilder builder = new SourceAs4ExtendedCommunityBuilder();
+ builder.setAsNumber(new AsNumber(body.readUnsignedInt()));
+ body.skipBytes(LOCAL_LENGTH);
+ return new SourceAs4ExtendedCommunityCaseBuilder().setSourceAs4ExtendedCommunity(
+ builder.build()).build();
+ }
+
+ @Override
+ public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+ Preconditions.checkArgument(extendedCommunity instanceof SourceAs4ExtendedCommunityCase,
+ "The extended community %s is not SourceAs4ExtendedCommunityCase type.",
+ extendedCommunity);
+
+ body.writeInt(((SourceAs4ExtendedCommunityCase) extendedCommunity).getSourceAs4ExtendedCommunity()
+ .getAsNumber().getValue().intValue());
+ ByteBufWriteUtil.writeUnsignedShort(LOCAL_ADMIN, body);
+ }
+
+ @Override
+ public int getSubType() {
+ return SUBTYPE;
+ }
+}
package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+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.Assert;
import org.junit.Test;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
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.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.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
public class Ipv4SpecificEcHandlerTest {
private static final byte[] INPUT = {
- 12, 51, 2, 5, 21, 45
+ 12, 51, 2, 5, 21, 45
};
@Test
- public void testHandler() throws BGPDocumentedException, BGPParsingException {
+ public void testHandlerDeprecated() {
+ final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
+ final Inet4SpecificExtendedCommunityCase input
+ = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder()
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(new byte[]{21, 45}).build()).build();
+
+ final Inet4SpecificExtendedCommunityCase expected
+ = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder()
+ .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(new byte[]{21, 45}).build()).build())
+ .build();
+ final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ assertEquals(expected, exComm);
+
+ final ByteBuf output = Unpooled.buffer(INPUT.length);
+ handler.serializeExtendedCommunity(input, output);
+ assertArrayEquals(INPUT, output.array());
+ }
+
+ @Test
+ public void testHandle() {
final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler();
- final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
- new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(new Ipv4Address("12.51.2.5")).setLocalAdministrator(
- new byte[] { 21, 45 }).build()).build();
+ final Inet4SpecificExtendedCommunityCase expected
+ = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder()
+ .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(new byte[]{21, 45}).build()).build())
+ .build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
- Assert.assertEquals(expected, exComm);
+ assertEquals(expected, exComm);
final ByteBuf output = Unpooled.buffer(INPUT.length);
handler.serializeExtendedCommunity(expected, output);
- Assert.assertArrayEquals(INPUT, output.array());
+ assertArrayEquals(INPUT, output.array());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.SourceAS4OctectHandler;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAs4ExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as._4.extended.community._case.SourceAs4ExtendedCommunityBuilder;
+
+public class SourceAS4OctectASHandlerTest {
+ private static final byte[] INPUT = {
+ 0, 0, 0, 20, 0, 0
+ };
+ private final SourceAS4OctectHandler handler = new SourceAS4OctectHandler();
+
+
+ @Test
+ public void testHandler() {
+ final SourceAs4ExtendedCommunityCase expected = new SourceAs4ExtendedCommunityCaseBuilder()
+ .setSourceAs4ExtendedCommunity(new SourceAs4ExtendedCommunityBuilder()
+ .setAsNumber(new AsNumber(20L)).build()).build();
+
+ final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ assertEquals(expected, exComm);
+
+ final ByteBuf output = Unpooled.buffer(INPUT.length);
+ this.handler.serializeExtendedCommunity(expected, output);
+ Assert.assertArrayEquals(INPUT, output.array());
+
+ assertEquals(209, this.handler.getSubType());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testHandlerError() {
+ this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.SourceAsExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.source.as.extended.community._case.SourceAsExtendedCommunityBuilder;
+
+public class SourceASHandlerTest {
+ private static final byte[] INPUT = {
+ 0, 1, 0, 0, 0, 0
+ };
+
+ private final SourceASHandler handler = new SourceASHandler();
+
+ @Test
+ public void testHandler() {
+ final SourceAsExtendedCommunityCase expected = new SourceAsExtendedCommunityCaseBuilder()
+ .setSourceAsExtendedCommunity(new SourceAsExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber(1L))
+ .build()).build();
+
+ final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ Assert.assertEquals(expected, exComm);
+
+ final ByteBuf output = Unpooled.buffer(INPUT.length);
+ handler.serializeExtendedCommunity(expected, output);
+ Assert.assertArrayEquals(INPUT, output.array());
+
+ assertEquals(9, this.handler.getSubType());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testHandlerError() {
+ this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(),
+ null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.impl.message.update.extended.communities;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+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.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.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.VrfRouteImportExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.vrf.route._import.extended.community._case.VrfRouteImportExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.inet4.specific.extended.community.common.Inet4SpecificExtendedCommunityCommonBuilder;
+
+public class VrfRouteImportHandlerTest {
+
+ private static final byte[] INPUT = {
+ 12, 51, 2, 5, 21, 45
+ };
+ private final VrfRouteImportHandler handler = new VrfRouteImportHandler();
+
+ @Test
+ public void testHandler() {
+ final VrfRouteImportExtendedCommunityCase expected = new VrfRouteImportExtendedCommunityCaseBuilder()
+ .setVrfRouteImportExtendedCommunity(new VrfRouteImportExtendedCommunityBuilder()
+ .setInet4SpecificExtendedCommunityCommon(new Inet4SpecificExtendedCommunityCommonBuilder()
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(new byte[]{21, 45}).build())
+ .build())
+ .build();
+
+ final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
+ Assert.assertEquals(expected, exComm);
+
+ final ByteBuf output = Unpooled.buffer(INPUT.length);
+ handler.serializeExtendedCommunity(expected, output);
+ Assert.assertArrayEquals(INPUT, output.array());
+
+ assertEquals(11, this.handler.getSubType());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testHandlerError() {
+ this.handler.serializeExtendedCommunity(new As4GenericSpecExtendedCommunityCaseBuilder().build(), null);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.spi.extended.community;
+
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractIpv4ExtendedCommunity.INET_LOCAL_ADMIN_LENGTH;
+
+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 final class Inet4SpecificExtendedCommunityCommonUtil {
+ private Inet4SpecificExtendedCommunityCommonUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ public static Inet4SpecificExtendedCommunityCommon parseCommon(final ByteBuf buffer) {
+ return new Inet4SpecificExtendedCommunityCommonBuilder()
+ .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
+ .setLocalAdministrator(ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH))
+ .build();
+ }
+
+ public static void serializeCommon(
+ final Inet4SpecificExtendedCommunityCommon extComm,
+ final ByteBuf byteAggregator) {
+ ByteBufWriteUtil.writeIpv4Address(extComm.getGlobalAdministrator(), byteAggregator);
+ byteAggregator.writeBytes(extComm.getLocalAdministrator());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.bgp.parser.spi.extended.community;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Assert;
+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.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 class Inet4SpecificExtendedCommunityCommonUtilTest {
+ private static final byte[] INPUT = {
+ 12, 51, 2, 5, 21, 45
+ };
+
+ @Test
+ public void testHandle() {
+ final Inet4SpecificExtendedCommunityCommon expected
+ = new Inet4SpecificExtendedCommunityCommonBuilder()
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(new byte[]{21, 45}).build();
+
+ final Inet4SpecificExtendedCommunityCommon exComm = Inet4SpecificExtendedCommunityCommonUtil
+ .parseCommon(Unpooled.copiedBuffer(INPUT));
+ Assert.assertEquals(expected, exComm);
+
+ final ByteBuf output = Unpooled.buffer(INPUT.length);
+ Inet4SpecificExtendedCommunityCommonUtil.serializeCommon(expected, output);
+ Assert.assertArrayEquals(INPUT, output.array());
+ }
+
+}
\ No newline at end of file