<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>concepts</artifactId>
+ </dependency>
<!--
FIXME: these are IETF models which are pre-generated in SAL infra.
This should not be here, but rather should somehow be
prefix "bgp-t";
import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
+ import network-concepts { prefix netc; revision-date 2013-11-25; }
organization "Cisco Systems, Inc.";
contact "Dana Kutenicsova <dkutenic@cisco.com>";
}
}
+ grouping link-bandwidth-extended-community {
+ reference "https://tools.ietf.org/html/draft-ietf-idr-link-bandwidth-06#section-2";
+ description
+ "The Link Bandwidth extended community is optional non-transitive";
+
+ leaf bandwidth {
+ description "Bandwidth of the link";
+ mandatory true;
+ type netc:bandwidth;
+ units "bytes per second";
+ }
+ }
+
grouping extended-community {
leaf comm-type {
status deprecated;
uses route-ipv4-extended-community;
}
}
+ case link-bandwidth-case {
+ container link-bandwidth-extended-community {
+ uses link-bandwidth-extended-community;
+ }
+ }
}
}
import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.AsTwoOctetSpecificEcHandler;
import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.Ipv4SpecificEcHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.LinkBandwidthEC;
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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.AsSpecificExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginExtendedCommunityCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4Case;
regs.add(context.registerExtendedCommunityParser(routeTargetIpv4EcHandler.getType(false), routeTargetIpv4EcHandler.getSubType(),
routeTargetIpv4EcHandler));
regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, routeTargetIpv4EcHandler));
+
+ final LinkBandwidthEC linkBandwidthECHandler = new LinkBandwidthEC();
+ regs.add(context.registerExtendedCommunityParser(linkBandwidthECHandler.getType(false), linkBandwidthECHandler.getSubType(),
+ linkBandwidthECHandler));
+ regs.add(context.registerExtendedCommunitySerializer(LinkBandwidthCase.class, linkBandwidthECHandler));
}
}
private static final int BGP_VERSION = 4;
- private static final int AS_TRANS = 2345;
+ public static final int AS_TRANS = 23456;
private final ParameterRegistry reg;
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.bgp.parser.impl.message.update.extended.communities;
+
+import static org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser.AS_TRANS;
+
+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.ExtendedCommunityParser;
+import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunitySerializer;
+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.rev130919.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+
+public class LinkBandwidthEC implements ExtendedCommunityParser, ExtendedCommunitySerializer {
+ private static final int TYPE = 64;
+ private static final int SUBTYPE = 4;
+ private static final int BANDWIDTH_SIZE = 4;
+ private static final int AS_TRANS_LENGTH = 2;
+
+ @Override
+ public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
+ buffer.skipBytes(AS_TRANS_LENGTH);
+ final LinkBandwidthExtendedCommunity lb = new LinkBandwidthExtendedCommunityBuilder()
+ .setBandwidth(new Bandwidth(ByteArray.readBytes(buffer, BANDWIDTH_SIZE)))
+ .build();
+ return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(lb).build();
+ }
+
+ @Override
+ public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf body) {
+ Preconditions.checkArgument(extendedCommunity instanceof LinkBandwidthCase,
+ "The extended community %s is not LinkBandwidthCase type.", extendedCommunity);
+ final LinkBandwidthExtendedCommunity lb = ((LinkBandwidthCase) extendedCommunity).getLinkBandwidthExtendedCommunity();
+ body.writeShort(AS_TRANS);
+ ByteBufWriteUtil.writeFloat32(lb.getBandwidth(), body);
+ }
+
+ @Override
+ public int getType(final boolean isTransitive) {
+ return TYPE;
+ }
+
+ @Override
+ public int getSubType() {
+ return SUBTYPE;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.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.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+
+public class LinkBandwidthECTest {
+ private static final byte[] RESULT = {(byte) 0x5b, (byte) 0xa0, 0x00, 0x00, (byte) 0xff, (byte) 0xff};
+ private static final int COMMUNITY_VALUE_SIZE = 6;
+ private LinkBandwidthEC parser;
+
+ @Before
+ public void setUp() {
+ this.parser = new LinkBandwidthEC();
+ }
+
+ @Test
+ public void parserTest() throws BGPParsingException, BGPDocumentedException {
+ final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
+
+ final LinkBandwidthCase expected = new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
+ .setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff}))
+ .build()).build();
+ this.parser.serializeExtendedCommunity(expected, buff);
+ assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
+
+ final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
+ assertEquals(expected, result);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void wrongCaseTest() {
+ this.parser.serializeExtendedCommunity(new Inet4SpecificExtendedCommunityCaseBuilder().build(), null);
+ }
+
+ @Test
+ public void testSubtype() {
+ assertEquals(4, this.parser.getSubType());
+ }
+}
\ No newline at end of file