outside extendend communities cases.
Allowing to reuse the models.
Change-Id: I9faab101f4b5ed0613fe26646be9da2fad58b942
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
.checkstyle
.factorypath
.fbExcludeFilterFile
+!**/route/target
}
}
+ grouping route-target-extended-community-grouping {
+ container route-target-extended-community {
+ description "Type 0x00 / Subtype 0x02";
+ reference "http://tools.ietf.org/html/rfc4360#section-4";
+
+ leaf global-administrator {
+ type short-as-number;
+ }
+ leaf local-administrator {
+ type binary {
+ length "4";
+ }
+ }
+ }
+ }
+
+ grouping route-target-ipv4-grouping {
+ container route-target-ipv4 {
+ description "Type 0x01 / Subtype 0x02";
+ reference "http://tools.ietf.org/html/rfc4360#section-4";
+ uses route-ipv4-extended-community;
+ }
+ }
+
+ grouping as-4-route-target-extended-community-grouping {
+ container as-4-route-target-extended-community {
+ description "Type 0x02 / Subtype 0x02";
+ reference "https://tools.ietf.org/html/rfc5668";
+ uses as-4-spec-common;
+ }
+ }
+
grouping extended-community {
leaf transitive {
type boolean;
}
}
case route-target-extended-community-case {
- container route-target-extended-community {
- leaf global-administrator {
- type short-as-number;
- }
- leaf local-administrator {
- type binary {
- length "4";
- }
- }
- }
+ uses route-target-extended-community-grouping;
+ }
+ case route-target-ipv4-case {
+ uses route-target-ipv4-grouping;
+ }
+ case as-4-route-target-extended-community-case {
+ uses as-4-route-target-extended-community-grouping;
}
case route-origin-extended-community-case {
container route-origin-extended-community {
}
}
}
- case route-target-ipv4-case {
- container route-target-ipv4 {
- reference "http://tools.ietf.org/html/rfc4360#section-4";
- uses route-ipv4-extended-community;
- }
- }
case route-origin-ipv4-case {
container route-origin-ipv4 {
reference "http://tools.ietf.org/html/rfc4360#section-5";
uses as-4-spec-common;
}
}
- case as-4-route-target-extended-community-case {
- container as-4-route-target-extended-community {
- reference "https://tools.ietf.org/html/rfc5668";
- uses as-4-spec-common;
- }
- }
case as-4-route-origin-extended-community-case {
container as-4-route-origin-extended-community {
reference "https://tools.ietf.org/html/rfc5668";
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.OpaqueEcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOriginAsTwoOctetEcHandler;
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.four.octect.as.specific.SourceAS4OctectHandler;
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.route.target.RouteTarget4OctectASEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target.RouteTargetAsTwoOctetEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target.RouteTargetIpv4EcHandler;
import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
--- /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.route.target;
+
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunityBuilder;
+
+/**
+ * Route Target 4 Octet As Handler.
+ *
+ * @author Claudio D. Gasparini
+ */
+public final class As4RouteTargetExtendedHandler {
+ private As4RouteTargetExtendedHandler() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static As4RouteTargetExtendedCommunity parse(final ByteBuf body) {
+ return new As4RouteTargetExtendedCommunityBuilder()
+ .setAs4SpecificCommon(FourOctAsCommonECUtil.parseCommon(body)).build();
+ }
+
+ public static void serialize(final As4RouteTargetExtendedCommunity as4RouteTargetExtendedCommunity,
+ final ByteBuf body) {
+ FourOctAsCommonECUtil.serializeCommon(as4RouteTargetExtendedCommunity.getAs4SpecificCommon(), body);
+ }
+}
\ No newline at end of file
* 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;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
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.Abstract4OctetAsExtendedCommunity;
-import org.opendaylight.protocol.bgp.parser.spi.extended.community.FourOctAsCommonECUtil;
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.As4RouteTargetExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
public final class RouteTarget4OctectASEcHandler extends Abstract4OctetAsExtendedCommunity {
private static final int SUBTYPE = 2;
@Override
- public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException {
- return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
- .setAs4SpecificCommon(FourOctAsCommonECUtil.parseCommon(body)).build()).build();
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf body)
+ throws BGPDocumentedException, BGPParsingException {
+ return new As4RouteTargetExtendedCommunityCaseBuilder()
+ .setAs4RouteTargetExtendedCommunity(As4RouteTargetExtendedHandler.parse(body)).build();
}
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
Preconditions.checkArgument(extendedCommunity instanceof As4RouteTargetExtendedCommunityCase,
- "The extended community %s is not As4RouteTargetExtendedCommunityCase type.", extendedCommunity);
- FourOctAsCommonECUtil.serializeCommon(((As4RouteTargetExtendedCommunityCase) extendedCommunity).getAs4RouteTargetExtendedCommunity()
- .getAs4SpecificCommon(), body);
+ "The extended community %s is not As4RouteTargetExtendedCommunityCase type.",
+ extendedCommunity);
+ As4RouteTargetExtendedHandler.serialize(((As4RouteTargetExtendedCommunityCase) extendedCommunity)
+ .getAs4RouteTargetExtendedCommunity(), body);
}
@Override
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import com.google.common.base.Preconditions;
-import com.google.common.primitives.Ints;
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.AbstractTwoOctetAsExtendedCommunity;
-import org.opendaylight.protocol.util.ByteArray;
-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.RouteTargetExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunity;
public final class RouteTargetAsTwoOctetEcHandler extends AbstractTwoOctetAsExtendedCommunity {
private static final int SUBTYPE = 2;
@Override
- public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
- final RouteTargetExtendedCommunity targetTarget = new RouteTargetExtendedCommunityBuilder()
- .setGlobalAdministrator(new ShortAsNumber((long) buffer.readUnsignedShort()))
- .setLocalAdministrator(ByteArray.readBytes(buffer, AS_LOCAL_ADMIN_LENGTH))
- .build();
- return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(targetTarget).build();
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
+ throws BGPDocumentedException, BGPParsingException {
+ return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
+ RouteTargetExtendedCommunityHandler.parse(buffer)).build();
}
@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) {
Preconditions.checkArgument(extendedCommunity instanceof RouteTargetExtendedCommunityCase,
- "The extended community %s is not RouteTargetExtendedCommunityCase type.", extendedCommunity);
- final RouteTargetExtendedCommunity routeTarget = ((RouteTargetExtendedCommunityCase) extendedCommunity).getRouteTargetExtendedCommunity();
- ByteBufWriteUtil.writeUnsignedShort(Ints.checkedCast(routeTarget.getGlobalAdministrator().getValue()), byteAggregator);
- byteAggregator.writeBytes(routeTarget.getLocalAdministrator());
+ "The extended community %s is not RouteTargetExtendedCommunityCase type.",
+ extendedCommunity);
+ final RouteTargetExtendedCommunity routeTarget = ((RouteTargetExtendedCommunityCase) extendedCommunity)
+ .getRouteTargetExtendedCommunity();
+ RouteTargetExtendedCommunityHandler.serialize(routeTarget, byteAggregator);
}
@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.route.target;
+
+import static org.opendaylight.protocol.bgp.parser.spi.extended.community.AbstractTwoOctetAsExtendedCommunity.AS_LOCAL_ADMIN_LENGTH;
+
+import com.google.common.primitives.Ints;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.util.ByteArray;
+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.route.target.extended.community.grouping.RouteTargetExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunityBuilder;
+
+/**
+ * Route Target Extended Community Parser / Serializer.
+ *
+ * @author Claudio D. Gasparini
+ */
+public final class RouteTargetExtendedCommunityHandler {
+ private RouteTargetExtendedCommunityHandler() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static RouteTargetExtendedCommunity parse(final ByteBuf buffer) {
+ return new RouteTargetExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber((long) buffer.readUnsignedShort()))
+ .setLocalAdministrator(ByteArray.readBytes(buffer, AS_LOCAL_ADMIN_LENGTH))
+ .build();
+ }
+
+ public static void serialize(final RouteTargetExtendedCommunity routeTarget, final ByteBuf byteAggregator) {
+ ByteBufWriteUtil.writeUnsignedShort(Ints.checkedCast(routeTarget.getGlobalAdministrator().getValue()),
+ byteAggregator);
+ byteAggregator.writeBytes(routeTarget.getLocalAdministrator());
+ }
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
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.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.RouteTargetIpv4Case;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4;
public final class RouteTargetIpv4EcHandler extends AbstractIpv4ExtendedCommunity {
Preconditions.checkArgument(extendedCommunity instanceof RouteTargetIpv4Case,
"The extended community %s is not RouteTargetAsTwoOctetCase type.", extendedCommunity);
final RouteTargetIpv4 routeTarget = ((RouteTargetIpv4Case) extendedCommunity).getRouteTargetIpv4();
- ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
- ByteBufWriteUtil.writeUnsignedShort(routeTarget.getLocalAdministrator(), byteAggregator);
+ RouteTargetIpv4Handler.serialize(routeTarget, byteAggregator);
}
@Override
- public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
- final RouteTargetIpv4 routeTarget = new RouteTargetIpv4Builder()
- .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
- .setLocalAdministrator(buffer.readUnsignedShort())
- .build();
- return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(routeTarget).build();
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer)
+ throws BGPDocumentedException, BGPParsingException {
+ return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(RouteTargetIpv4Handler.parse(buffer)).build();
}
@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.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;
+
+/**
+ * Route Target Ipv4 Handler.
+ *
+ * @author Claudio D. Gasparini
+ */
+public final class RouteTargetIpv4Handler {
+ private RouteTargetIpv4Handler() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static void serialize(final RouteTargetIpv4 routeTarget, final ByteBuf byteAggregator) {
+ ByteBufWriteUtil.writeIpv4Address(routeTarget.getGlobalAdministrator(), byteAggregator);
+ ByteBufWriteUtil.writeUnsignedShort(routeTarget.getLocalAdministrator(), byteAggregator);
+ }
+
+ public static RouteTargetIpv4 parse(final ByteBuf buffer) {
+ return new RouteTargetIpv4Builder()
+ .setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer))
+ .setLocalAdministrator(buffer.readUnsignedShort())
+ .build();
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
public class BGPParserTest {
comms.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(
new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
new RouteTargetIpv4Builder().setGlobalAdministrator(
- new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660).build()).build()).build());
+ new Ipv4Address("192.168.1.0")).setLocalAdministrator(4660)
+ .build()).build()).build());
// check path attributes
final Attributes attrs = message.getAttributes();
public final class RouteOrigin4OctectASEcHandlerTest {
- static final byte[] INPUT = {
+ public static final byte[] INPUT = {
0, 0, 0, 20, 0, 100
};
- static final As4SpecificCommon AS_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L))
+ public static final As4SpecificCommon AS_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L))
.setLocalAdministrator(100).build();
RouteOrigin4OctectASEcHandler handler;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOrigin4OctectASEcHandlerTest.AS_COMMON;
import static org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOrigin4OctectASEcHandlerTest.INPUT;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunityBuilder;
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.As4RouteOriginExtendedCommunityCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
public class RouteTarget4OctectASEcHandlerTest {
- RouteTarget4OctectASEcHandler handler;
-
- @Before
- public void Setup() {
- this.handler = new RouteTarget4OctectASEcHandler();
- }
+ private final RouteTarget4OctectASEcHandler handler = new RouteTarget4OctectASEcHandler();
@Test
public void testHandler() throws BGPDocumentedException, BGPParsingException {
final As4RouteTargetExtendedCommunityCase expected = new As4RouteTargetExtendedCommunityCaseBuilder()
- .setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
- .setAs4SpecificCommon(AS_COMMON).build()).build();
+ .setAs4RouteTargetExtendedCommunity(new As4RouteTargetExtendedCommunityBuilder()
+ .setAs4SpecificCommon(AS_COMMON).build()).build();
final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
Assert.assertArrayEquals(INPUT, output.array());
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testHandlerError() throws BGPDocumentedException, BGPParsingException {
this.handler.serializeExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder().build(), null);
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
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.RouteTargetExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunityBuilder;
public class RouteTargetAsTwoOctetEcHandlerTest {
@Test
public void testHandler() throws BGPDocumentedException, BGPParsingException {
final RouteTargetAsTwoOctetEcHandler handler = new RouteTargetAsTwoOctetEcHandler();
- final RouteTargetExtendedCommunityCase expected = new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
- new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(35L)).setLocalAdministrator(
- new byte[] { 4, 2, 8, 7 }).build()).build();
+ final RouteTargetExtendedCommunityCase expected = new RouteTargetExtendedCommunityCaseBuilder()
+ .setRouteTargetExtendedCommunity(new RouteTargetExtendedCommunityBuilder()
+ .setGlobalAdministrator(new ShortAsNumber(35L))
+ .setLocalAdministrator(new byte[]{4, 2, 8, 7})
+ .build()).build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
+package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.route.target;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
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.RouteTargetIpv4Case;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
public class RouteTargetIpv4EcHandlerTest {
final RouteTargetIpv4EcHandler handler = new RouteTargetIpv4EcHandler();
final RouteTargetIpv4Case expected = new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
new RouteTargetIpv4Builder()
- .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
- .setLocalAdministrator(5421)
- .build()).build();
+ .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
+ .setLocalAdministrator(5421)
+ .build()).build();
final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
Assert.assertEquals(expected, exComm);
private static final int TYPE = 0;
- protected static final int AS_LOCAL_ADMIN_LENGTH = 4;
+ public static final int AS_LOCAL_ADMIN_LENGTH = 4;
@Override
public final int getType(final boolean isTransitive) {
package org.opendaylight.protocol.bgp.parser.spi.pojo;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteOriginIpv4CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4Case;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
public class SimpleExtendedCommunityRegistryTest {
private SimpleExtendedCommunityRegistry register;
- private final ExtendedCommunityParser parser = Mockito.mock(ExtendedCommunityParser.class);
- private final ExtendedCommunitySerializer serializer = Mockito.mock(ExtendedCommunitySerializer.class);
+ private final ExtendedCommunityParser parser = mock(ExtendedCommunityParser.class);
+ private final ExtendedCommunitySerializer serializer = mock(ExtendedCommunitySerializer.class);
@Before
public void setup() throws BGPDocumentedException, BGPParsingException {
this.register = new SimpleExtendedCommunityRegistry();
this.register.registerExtendedCommunityParser(0, 0, this.parser);
this.register.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.serializer);
- Mockito.doReturn(0).when(this.serializer).getType(Mockito.anyBoolean());
- Mockito.doReturn(0).when(this.serializer).getSubType();
- Mockito.doNothing().when(this.serializer).serializeExtendedCommunity(Mockito.any(ExtendedCommunity.class), Mockito.any(ByteBuf.class));
- Mockito.doReturn(null).when(this.parser).parseExtendedCommunity(Mockito.any(ByteBuf.class));
+ doReturn(0).when(this.serializer).getType(anyBoolean());
+ doReturn(0).when(this.serializer).getSubType();
+ doNothing().when(this.serializer).serializeExtendedCommunity(any(ExtendedCommunity.class), any(ByteBuf.class));
+ doReturn(null).when(this.parser).parseExtendedCommunity(any(ByteBuf.class));
}
public void testExtendedCommunityRegistry() throws BGPDocumentedException, BGPParsingException {
final ByteBuf output = Unpooled.buffer();
this.register.serializeExtendedCommunity(
- new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(new RouteTargetIpv4Builder().build()).build()).build(), output);
- Mockito.verify(this.serializer).serializeExtendedCommunity(Mockito.any(ExtendedCommunity.class), Mockito.any(ByteBuf.class));
+ new ExtendedCommunitiesBuilder().setTransitive(true)
+ .setExtendedCommunity(new RouteTargetIpv4CaseBuilder()
+ .setRouteTargetIpv4(new RouteTargetIpv4Builder().build()).build()).build(), output);
+ verify(this.serializer).serializeExtendedCommunity(any(ExtendedCommunity.class), any(ByteBuf.class));
//no value serialized, just header
Assert.assertEquals(2, output.readableBytes());
- final ExtendedCommunities parsedExtendedCommunity = this.register.parseExtendedCommunity(Unpooled.copiedBuffer(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}));
- Mockito.verify(this.parser).parseExtendedCommunity(Mockito.any(ByteBuf.class));
+ final ExtendedCommunities parsedExtendedCommunity =
+ this.register.parseExtendedCommunity(Unpooled.copiedBuffer(new byte[] {0, 0, 0, 0, 0, 0, 0, 0}));
+ verify(this.parser).parseExtendedCommunity(any(ByteBuf.class));
Assert.assertTrue(parsedExtendedCommunity.isTransitive());
//no value parser
- Assert.assertNull(parsedExtendedCommunity.getExtendedCommunity());
+ assertNull(parsedExtendedCommunity.getExtendedCommunity());
}
@Test
public void testExtendedCommunityRegistryUnknown() throws BGPDocumentedException, BGPParsingException {
final ByteBuf output = Unpooled.buffer();
this.register.serializeExtendedCommunity(
- new ExtendedCommunitiesBuilder().setTransitive(false).setExtendedCommunity(new RouteOriginIpv4CaseBuilder().build()).build(), output);
+ new ExtendedCommunitiesBuilder().setTransitive(false)
+ .setExtendedCommunity(new RouteOriginIpv4CaseBuilder().build()).build(), output);
//no ex. community was serialized
Assert.assertEquals(0, output.readableBytes());
- Mockito.verify(this.serializer, Mockito.never()).serializeExtendedCommunity(Mockito.any(ExtendedCommunity.class), Mockito.any(ByteBuf.class));
+ verify(this.serializer, never())
+ .serializeExtendedCommunity(any(ExtendedCommunity.class), any(ByteBuf.class));
- final ExtendedCommunities noExtCommunity = this.register.parseExtendedCommunity(Unpooled.copiedBuffer(new byte[] {0, 1, 0, 0, 0, 0, 0, 0}));
+ final ExtendedCommunities noExtCommunity = this.register
+ .parseExtendedCommunity(Unpooled.copiedBuffer(new byte[] {0, 1, 0, 0, 0, 0, 0, 0}));
//no ext. community was parsed
- Assert.assertNull(noExtCommunity);
- Mockito.verify(this.parser, Mockito.never()).parseExtendedCommunity(Mockito.any(ByteBuf.class));
+ assertNull(noExtCommunity);
+ verify(this.parser, never()).parseExtendedCommunity(any(ByteBuf.class));
}
@Test(expected=IllegalArgumentException.class)
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommon;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
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.RouteTargetIpv4CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder;
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.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.origin.ipv4._case.RouteOriginIpv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.extended.community.grouping.RouteTargetExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.route.target.ipv4.grouping.RouteTargetIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
import org.slf4j.Logger;