+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.as.specific.extended.community.AsSpecificExtendedCommunityBuilder;
-
-public class ASSpecificExtendedCommunityTest {
-
- private final boolean transitive = true;
- private final AsNumber globalAdmin = new AsNumber(429496729800L);
-
- @Test
- @Ignore
- // FIXME: length is not implemented
- public void testOverflows() {
- try {
- new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- new byte[] {}).build();
- fail("Local Administrator has illegal length!");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid Local Administrator", e.getMessage());
- }
- }
-
- @Test
- public void testGetters() {
- final AsSpecificExtendedCommunity asSpecExCom = new AsSpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(
- this.globalAdmin).setLocalAdministrator(new byte[] { 10, 0, 0, 1 }).build();
- assertEquals(new AsNumber(429496729800L), asSpecExCom.getGlobalAdministrator());
- assertArrayEquals(new byte[] { 10, 0, 0, 1 }, asSpecExCom.getLocalAdministrator());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
-
-public class ClusterIdentifierTest {
-
- @Test
- public void testClusterIdentifier() {
- final ClusterIdentifier id = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
- // FIXME: uncomment, once the generated code has length precondition
- // try {
- // new ClusterIdentifier(new byte[] { 5, 6 });
- // fail("Cluster ID is invalid!");
- // } catch (final IllegalArgumentException e) {
- // assertEquals("Invalid Cluster ID", e.getMessage());
- // }
-
- final ClusterIdentifier id1 = new ClusterIdentifier(new byte[] { 13, 14, 15, 16 });
-
- assertEquals(id1.toString(), id.toString());
-
- assertArrayEquals(id1.getValue(), new byte[] { 13, 14, 15, 16 });
- }
-
- @Test
- public void testOrigin() {
- final BgpOrigin or = BgpOrigin.Egp;
- assertEquals(or.name(), "Egp");
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.inet4.specific.extended.community.Inet4SpecificExtendedCommunityBuilder;
-
-public class Inet4SpecificExtendedCommunityTest {
-
- private boolean transitive;
- private Ipv4Address globalAdmin;
- private byte[] localAdmin;
-
- private Inet4SpecificExtendedCommunity community;
-
- @Before
- public void init() {
- this.transitive = true;
- this.globalAdmin = new Ipv4Address("10.0.0.1");
- this.localAdmin = new byte[] { 10, 1 };
- this.community = new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- this.localAdmin).build();
- }
-
- @Test
- @Ignore
- // FIXME: length is not implemented
- public void testOverflows() {
- try {
- new Inet4SpecificExtendedCommunityBuilder().setTransitive(this.transitive).setGlobalAdministrator(this.globalAdmin).setLocalAdministrator(
- new byte[] { 10, 0, 1 }).build();
- fail("Invalid length of local administrator!");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid Local Administrator", e.getMessage());
- }
- }
-
- @Test
- public void testGetGlobalAdmin() {
- final Ipv4Address globalAdmin = new Ipv4Address("10.0.0.1");
- assertEquals(globalAdmin, this.community.getGlobalAdministrator());
- }
-
- @Test
- public void testGetLocalAdmin() {
- final byte[] localAdmin = new byte[] { 10, 1 };
- assertArrayEquals(localAdmin, this.community.getLocalAdministrator());
- }
-
- @Test
- public void testIsTransitive() {
- assertTrue(this.community.isTransitive());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.concepts;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.c.opaque.extended.community.OpaqueExtendedCommunityBuilder;
-
-public class OpaqueExtendedCommunityTest {
-
- private boolean transitive;
- private byte[] value;
-
- private OpaqueExtendedCommunity community;
-
- @Before
- public void init() {
- this.transitive = true;
- this.value = new byte[] { 1, 5, 9, 3, 5, 7 };
- this.community = new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(this.value).build();
- }
-
- @Test
- @Ignore
- // FIXME: when length is implemented
- public void testOverflows() {
- try {
- new OpaqueExtendedCommunityBuilder().setTransitive(this.transitive).setValue(new byte[] { 0, 1, 2, 3, 4, 5, 6, }).build();
- fail("Constructor successful unexpectedly");
- } catch (final IllegalArgumentException e) {
- assertEquals("Invalid value", e.getMessage());
- }
- }
-
- @Test
- public void testGetValue() {
- assertArrayEquals(new byte[] { 1, 5, 9, 3, 5, 7 }, this.community.getValue());
- }
-
- @Test
- public void testIsTransitive() {
- assertTrue(this.community.isTransitive());
- }
-
- @Test
- public void testToString() {
- final OpaqueExtendedCommunity c = new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(this.value).build();
- assertNotSame(c.toString(), this.community.toString());
- }
-}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
-/**
- *
- */
public final class Activator implements BGPExtensionProviderActivator {
@Override
public void start(final BGPExtensionProviderContext context) throws Exception {
context.registerAddressFamily(LinkstateAddressFamily.class, 16388);
context.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, 71);
- context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
- new LinkstateNlriParser(false));
- context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class,
- new LinkstateNlriParser(true));
+ context.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateNlriParser(false));
+ context.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class, new LinkstateNlriParser(true));
context.registerAttributeParser(LinkstateAttributeParser.TYPE, new LinkstateAttributeParser());
}
/**
* Parser for Link State information.
*
- * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-01">BGP-LS draft</a>
+ * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-03">BGP-LS draft</a>
*/
public class LinkstateAttributeParser implements AttributeParser {
// FIXME: update to IANA number once it is known
private static final int LENGTH_SIZE = 2;
- private static final Set<Integer> nodeTlvs = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
+ private static final Set<Integer> NODE_TLVS = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
- private static final Set<Integer> linkTlvs = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
+ private static final Set<Integer> LINK_TLVS = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
1096, 1097, 1098);
- private static final Set<Integer> prefixTlvs = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
+ private static final Set<Integer> PREFIX_TLVS = Sets.newHashSet(1152, 1153, 1154, 1155, 1156, 1157);
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPParsingException {
builder.addAugmentation(PathAttributes1.class, a);
}
-
- public static boolean verifyLink(final Set<Integer> keys) {
+ private static boolean verifyLink(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!linkTlvs.contains(i)) {
+ if (!LINK_TLVS.contains(i)) {
logger.warn("Invalid link attribute {}", i);
return false;
}
return true;
}
- public static boolean verifyNode(final Set<Integer> keys) {
+ private static boolean verifyNode(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!nodeTlvs.contains(i)) {
+ if (!NODE_TLVS.contains(i)) {
logger.warn("Invalid node attribute {}", i);
return false;
}
return true;
}
- public static boolean verifyPrefix(final Set<Integer> keys) {
+ private static boolean verifyPrefix(final Set<Integer> keys) {
for (final Integer i : keys) {
- if (!prefixTlvs.contains(i)) {
+ if (!PREFIX_TLVS.contains(i)) {
logger.warn("Invalid prefix attribute {}", i);
return false;
}
return true;
}
- protected static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
+ private static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
final Map<Integer, ByteList> map = new HashMap<Integer, ByteList>();
int byteOffset = 0;
while (byteOffset != bytes.length) {
* @return {@link LinkAttributes}
* @throws BGPParsingException if a link attribute is not recognized
*/
- public static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static LinkAttributes parseLinkAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.debug("Link attribute TLV {}", entry.getKey());
+ logger.trace("Link attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
case 1028:
final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setLocalIpv4RouterId(lipv4);
- logger.trace("Parsed IPv4 Router-ID of local node: {}", lipv4);
+ logger.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
break;
case 1029:
final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setLocalIpv6RouterId(lipv6);
- logger.trace("Parsed IPv6 Router-ID of local node: {}", lipv6);
+ logger.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
break;
case 1030:
final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setRemoteIpv4RouterId(ripv4);
- logger.trace("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+ logger.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
break;
case 1031:
final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setRemoteIpv6RouterId(ripv6);
- logger.trace("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+ logger.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
break;
case 1088:
builder.setAdminGroup(new AdministrativeGroup(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Administrative Group {}", builder.getAdminGroup());
+ logger.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case 1089:
builder.setMaxLinkBandwidth(new Bandwidth(value));
- logger.trace("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+ logger.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case 1090:
builder.setMaxReservableBandwidth(new Bandwidth(value));
- logger.trace("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+ logger.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case 1091:
int index = 0;
index += 4;
}
builder.setUnreservedBandwidth(unreservedBandwidth);
- logger.trace("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+ logger.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
break;
case 1092:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Metric {}", builder.getTeMetric());
+ logger.debug("Parsed Metric {}", builder.getTeMetric());
break;
case 1093:
final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[0]));
throw new BGPParsingException("Link Protection Type not recognized: " + UnsignedBytes.toInt(value[0]));
}
builder.setLinkProtection(lpt);
- logger.trace("Parsed Link Protection Type {}", lpt);
+ logger.debug("Parsed Link Protection Type {}", lpt);
break;
case 1094:
final boolean[] bits = ByteArray.parseBits(value[0]);
builder.setMplsProtocol(new MplsProtocolMask(bits[0], bits[1]));
- logger.trace("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+ logger.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case 1095:
builder.setMetric(new Metric(ByteArray.bytesToLong(value)));
- logger.trace("Parsed Metric {}", builder.getMetric());
+ logger.debug("Parsed Metric {}", builder.getMetric());
break;
case 1096:
int i = 0;
i += 4;
}
builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
- logger.trace("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+ logger.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
break;
case 1097:
final byte[] opaque = value;
- logger.trace("Parsed Opaque value : {}", Arrays.toString(opaque));
+ logger.debug("Parsed Opaque value : {}", Arrays.toString(opaque));
break;
case 1098:
final String name = new String(value, Charsets.US_ASCII);
builder.setLinkName(name);
- logger.trace("Parsed Link Name : ", name);
+ logger.debug("Parsed Link Name : {}", name);
break;
default:
throw new BGPParsingException("Link Attribute not recognized, type: " + entry.getKey());
}
}
}
- logger.debug("Finished parsing Link Attributes.");
+ logger.trace("Finished parsing Link Attributes.");
return builder.build();
}
* @return {@link NodeAttributes}
* @throws BGPParsingException if a node attribute is not recognized
*/
- public static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static NodeAttributes parseNodeAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final List<TopologyIdentifier> topologyMembership = Lists.newArrayList();
final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
final NodeAttributesBuilder builder = new NodeAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.debug("Node attribute TLV {}", entry.getKey());
+ logger.trace("Node attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
switch (entry.getKey()) {
case 263:
while (i != value.length) {
final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(ByteArray.subByte(value, i, 2)) & 0x3fff);
topologyMembership.add(topId);
- logger.trace("Parsed Topology Identifier: {}", topId);
+ logger.debug("Parsed Topology Identifier: {}", topId);
i += 2;
}
break;
case 1024:
final boolean[] flags = ByteArray.parseBits(value[0]);
builder.setNodeFlags(new NodeFlagBits(flags[0], flags[1], flags[2], flags[3]));
- logger.trace("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
+ logger.debug("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
break;
case 1025:
logger.debug("Ignoring opaque value: {}.", Arrays.toString(value));
break;
case 1026:
builder.setDynamicHostname(new String(value, Charsets.US_ASCII));
- logger.trace("Parsed Node Name {}", builder.getDynamicHostname());
+ logger.debug("Parsed Node Name {}", builder.getDynamicHostname());
break;
case 1027:
final IsisAreaIdentifier ai = new IsisAreaIdentifier(value);
areaMembership.add(ai);
- logger.trace("Parsed AreaIdentifier {}", ai);
+ logger.debug("Parsed AreaIdentifier {}", ai);
break;
case 1028:
final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4RouterId(ip4);
- logger.trace("Parsed IPv4 Router Identifier {}", ip4);
+ logger.debug("Parsed IPv4 Router Identifier {}", ip4);
break;
case 1029:
final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6RouterId(ip6);
- logger.trace("Parsed IPv6 Router Identifier {}", ip6);
+ logger.debug("Parsed IPv6 Router Identifier {}", ip6);
break;
default:
throw new BGPParsingException("Node Attribute not recognized, type: " + entry.getKey());
}
builder.setTopologyIdentifier(topologyMembership);
builder.setIsisAreaId(areaMembership);
- logger.debug("Finished parsing Node Attributes.");
+ logger.trace("Finished parsing Node Attributes.");
return builder.build();
}
* @return {@link PrefixAttributes}
* @throws BGPParsingException if some prefix attributes is not recognized
*/
- public static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
+ private static PrefixAttributes parsePrefixAttributes(final Map<Integer, ByteList> attributes) throws BGPParsingException {
final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
final List<RouteTag> routeTags = Lists.newArrayList();
final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
logger.trace("Parsed area identifier {}", ai);
break;
case 515:
- if (value.length == 6) {
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- } else if (value.length == 7) {
- if (value[6] == 0) {
- logger.warn("PSN octet is 0. Ignoring System ID.");
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- break;
- } else {
- final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
- new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
- routerId = new CIsisPseudonodeBuilder().setIsisPseudonode(
- new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
- }
- } else if (value.length == 4) {
- routerId = new COspfNodeBuilder().setOspfNode(
- new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
- } else if (value.length == 8) {
- final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
- final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
- routerId = new COspfPseudonodeBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
- }
+ routerId = parseRouterId(value);
logger.trace("Parsed Router Identifier {}", routerId);
break;
default:
return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
}
- private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes) throws BGPParsingException {
+ private static CRouterIdentifier parseRouterId(final byte[] value) throws BGPParsingException {
+ if (value.length == 6) {
+ return new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ }
+ if (value.length == 7) {
+ if (value[6] == 0) {
+ logger.warn("PSN octet is 0. Ignoring System ID.");
+ return new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ } else {
+ final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
+ return new CIsisPseudonodeBuilder().setIsisPseudonode(
+ new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
+ }
+ }
+ if (value.length == 4) {
+ return new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
+ }
+ if (value.length == 8) {
+ final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
+ final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
+ return new COspfPseudonodeBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
+ }
+ throw new BGPParsingException("Router Id of invalid length " + value.length);
+ }
+
+ private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes)
+ throws BGPParsingException {
int byteOffset = 0;
final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
while (byteOffset != bytes.length) {
* @return BGPLinkMP or BGPNodeMP
* @throws BGPParsingException
*/
- private final CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+ private CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
if (nlri.length == 0) {
return null;
}
final int length = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
RouteDistinguisher distinguisher = null;
- if (isVpn) {
+ if (this.isVpn) {
// this parses route distinguisher
distinguisher = new RouteDistinguisher(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(nlri, byteOffset,
ROUTE_DISTINGUISHER_LENGTH))));
}
byteOffset += locallength;
builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0)
- - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+ - TYPE_LENGTH - LENGTH_SIZE - locallength;
logger.debug("Restlength {}", restLength);
switch (type) {
case Link:
}
@Override
- public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ public void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
final CLinkstateDestination dst = parseNlri(nlri);
// FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
- final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+ final DestinationType s = (DestinationType) new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(s).build());
}
@Override
- public final void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
+ public void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
final CLinkstateDestination dst = parseNlri(nlri);
// FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
- final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+ final DestinationType s = (DestinationType) new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(s).build());
NlriUtil.parseNextHop(nextHop, builder);
--- /dev/null
+/*
+ * Copyright (c) 2013 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.linkstate;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+
+public class ActivatorTest {
+
+ private final Activator act = new Activator();
+
+ @Test
+ public void testActivator() {
+ final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
+
+ assertNull(context.getAddressFamilyRegistry().classForFamily(16388));
+ assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+
+ try {
+ this.act.start(context);
+ } catch (final Exception e) {
+ fail("This exception should not occurr.");
+ }
+
+ assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388));
+ assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71));
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ this.act.stop();
+ } catch (final Exception e) {
+ fail("This exception should not occurr.");
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.linkstate;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
-
-public class AreaIdentifierTest {
-
- private AreaIdentifier identifier;
-
- @Before
- public void init() {
- final byte[] id = new byte[] {10,0,0,1};
- this.identifier = new AreaIdentifier(id);
- }
-
- @Test
- public void testGetBytes() {
- final byte[] id = new byte[] {10,0,0,1};
- assertArrayEquals(id, this.identifier.getValue());
- }
-
- @Test
- public void testToString(){
- final byte[] id1 = new byte[] {10,0,0,1};
- final AreaIdentifier l1 = new AreaIdentifier(id1);
- final String s1 = "AreaIdentifier [_value=[10, 0, 0, 1]]";
- assertEquals(s1, l1.toString());
- }
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 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.linkstate;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
+
+public class LinkstateAttributeParserTest {
+
+ private static final byte[] LINK_ATTR = new byte[] { (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2a, (byte) 0x2a,
+ (byte) 0x2a, (byte) 0x2a, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b,
+ (byte) 0x2b, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, (byte) 0x04,
+ (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x04, (byte) 0x43,
+ (byte) 0x00, (byte) 0x20, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x46, (byte) 0x43, (byte) 0x50,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44,
+ (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03,
+ (byte) 0x00, (byte) 0x00, (byte) 0x0a };
+
+ private static final byte[] NODE_ATTR = new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x05, (byte) 0x31, (byte) 0x32,
+ (byte) 0x4b, (byte) 0x2d, (byte) 0x32, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04,
+ (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x29 };
+
+ private final LinkstateAttributeParser parser = new LinkstateAttributeParser();
+
+ @Test
+ public void testPositiveLinks() {
+ final PathAttributesBuilder builder = new PathAttributesBuilder();
+ try {
+ this.parser.parseAttribute(LINK_ATTR, builder);
+ } catch (final BGPParsingException e) {
+ fail("No exception should occur.");
+ }
+ final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+ final LinkAttributes ls = (LinkAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+ assertNotNull(ls);
+
+ assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
+ assertEquals(new Long(10), ls.getMetric().getValue());
+ assertEquals(new Long(0), ls.getAdminGroup().getValue());
+ assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
+ assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue());
+ assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue());
+ assertNotNull(ls.getUnreservedBandwidth());
+ assertEquals(8, ls.getUnreservedBandwidth().size());
+ }
+
+ @Test
+ public void testPositiveNodes() {
+ final PathAttributesBuilder builder = new PathAttributesBuilder();
+ try {
+ this.parser.parseAttribute(NODE_ATTR, builder);
+ } catch (final BGPParsingException e) {
+ fail("No exception should occur.");
+ }
+ final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
+ final NodeAttributes ls = (NodeAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
+ assertNotNull(ls);
+
+ assertEquals("12K-2", ls.getDynamicHostname());
+ assertEquals(1, ls.getIsisAreaId().size());
+ assertArrayEquals(new byte[] { 114 }, ls.getIsisAreaId().get(0).getValue());
+ assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.linkstate;
-
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.TopologyIdentifier;
-
-public class TopologyIdentifierTest {
-
- private TopologyIdentifier identifier;
-
- @Before
- public void init() {
- this.identifier = new TopologyIdentifier(23);
- }
-
- @Test
- public void testLinkAreaIdentifier() {
- try {
- new TopologyIdentifier(4096);
- } catch (final Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
- try {
- new TopologyIdentifier(-2);
- } catch (final Exception e) {
- assertTrue(e instanceof IllegalArgumentException);
- }
-
- }
-
- @Test
- public void testGetId() {
- assertEquals(23, this.identifier.getValue().intValue());
- }
-
- @Test
- public void testEquals() {
- assertThat(this.identifier, not(new Object()));
-
- final TopologyIdentifier testIdentifier = new TopologyIdentifier(23);
- assertEquals(this.identifier, testIdentifier);
- }
-
- @Test
- public void testToString() {
- assertEquals("TopologyIdentifier [_value=23]", this.identifier.toString());
- final TopologyIdentifier id = new TopologyIdentifier(3);
- assertEquals("TopologyIdentifier [_value=3]", id.toString());
- }
-}