BUG-49 : updated the rest of ignored tests and fixed more warnings. 10/2110/1
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 23 Oct 2013 15:38:48 +0000 (17:38 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 23 Oct 2013 15:38:48 +0000 (17:38 +0200)
Change-Id: I02bc04b0c66ee5458ea9d60a40a6569b4ebd72ef
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
21 files changed:
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
bgp/linkstate/src/main/yang/bgp-linkstate.yang
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java [new file with mode: 0644]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRIBsInFactoryRegistryImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPMessageHeaderDecoder.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionProposalImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPDispatcher.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/BinaryBGPDumpFileParser.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/HexDumpBGPFileParser.java
concepts/src/main/java/org/opendaylight/protocol/concepts/Ipv4Util.java

index 339e85a8227df70859961b1f99eaf3a888e0c3d2..91dcac7b5f5455d123a7601f529242891377cadc 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.linkstate;
 
 import java.math.BigInteger;
 import java.util.Arrays;
+import java.util.List;
 
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
@@ -41,6 +42,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
@@ -59,6 +61,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.conc
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 
 public final class LinkstateNlriParser implements NlriParser {
@@ -84,7 +87,8 @@ public final class LinkstateNlriParser implements NlriParser {
                byteOffset += LENGTH_SIZE;
                final NodeIdentifier remote = null;
                if (type == 257) {
-                       builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
+                       builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length),
+                                       false));
                        byteOffset += length;
                }
                builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
@@ -100,49 +104,49 @@ public final class LinkstateNlriParser implements NlriParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
+                       logger.trace("Parsing Link Descriptor: {}", Arrays.toString(value));
                        switch (type) {
                        case 258:
                                builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
                                builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
-                               logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+                               logger.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
                                                builder.getLinkRemoteIdentifier());
                                break;
                        case 259:
                                final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
                                builder.setIpv4InterfaceAddress(lipv4);
-                               logger.trace("Parsed IPv4 interface address {}.", lipv4);
+                               logger.debug("Parsed IPv4 interface address {}.", lipv4);
                                break;
                        case 260:
                                final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
                                builder.setIpv4NeighborAddress(ripv4);
-                               logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
+                               logger.debug("Parsed IPv4 neighbor address {}.", ripv4);
                                break;
                        case 261:
                                final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
                                builder.setIpv6InterfaceAddress(lipv6);
-                               logger.trace("Parsed IPv6 interface address {}.", lipv6);
+                               logger.debug("Parsed IPv6 interface address {}.", lipv6);
                                break;
                        case 262:
                                final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
                                builder.setIpv6NeighborAddress(ripv6);
-                               logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
+                               logger.debug("Parsed IPv6 neighbor address {}.", ripv6);
                                break;
                        case 263:
                                final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
                                builder.setMultiTopologyId(topId);
-                               logger.trace("Parsed topology identifier {}.", topId);
+                               logger.debug("Parsed topology identifier {}.", topId);
                                break;
                        default:
                                throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
                        }
                        byteOffset += length;
                }
-               logger.debug("Finished parsing Link descriptors.");
+               logger.trace("Finished parsing Link descriptors.");
                return builder.build();
        }
 
-       private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
+       private static NodeIdentifier parseNodeDescriptors(final byte[] bytes, final boolean local) throws BGPParsingException {
                int byteOffset = 0;
                AsNumber asnumber = null;
                DomainIdentifier bgpId = null;
@@ -154,31 +158,33 @@ public final class LinkstateNlriParser implements NlriParser {
                        final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
-                       logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
+                       logger.trace("Parsing Node Descriptor: {}", Arrays.toString(value));
                        switch (type) {
                        case 512:
                                asnumber = new AsNumber(ByteArray.bytesToLong(value));
-                               logger.trace("Parsed AS number {}", asnumber);
+                               logger.debug("Parsed {}", asnumber);
                                break;
                        case 513:
                                bgpId = new DomainIdentifier(value);
-                               logger.trace("Parsed bgpId {}", bgpId);
+                               logger.debug("Parsed {}", bgpId);
                                break;
                        case 514:
                                ai = new AreaIdentifier(value);
-                               logger.trace("Parsed area identifier {}", ai);
+                               logger.debug("Parsed area identifier {}", ai);
                                break;
                        case 515:
                                routerId = parseRouterId(value);
-                               logger.trace("Parsed Router Identifier {}", routerId);
+                               logger.debug("Parsed Router Identifier {}", routerId);
                                break;
                        default:
                                throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
                        }
                        byteOffset += length;
                }
-               logger.debug("Finished parsing Node descriptors.");
-               return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+               logger.trace("Finished parsing Node descriptors.");
+               return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
+                               routerId).build()
+                               : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
        }
 
        private static CRouterIdentifier parseRouterId(final byte[] value) throws BGPParsingException {
@@ -267,15 +273,18 @@ public final class LinkstateNlriParser implements NlriParser {
         * @return BGPLinkMP or BGPNodeMP
         * @throws BGPParsingException
         */
-       private CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+       private List<CLinkstateDestination> parseNlri(final byte[] nlri) throws BGPParsingException {
                if (nlri.length == 0) {
                        return null;
                }
                int byteOffset = 0;
 
-               final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+               final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+               CLinkstateDestinationBuilder builder = null;
 
                while (byteOffset != nlri.length) {
+                       builder = new CLinkstateDestinationBuilder();
                        final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH)));
                        builder.setNlriType(type);
 
@@ -310,13 +319,13 @@ public final class LinkstateNlriParser implements NlriParser {
                        locallength = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
                        byteOffset += LENGTH_SIZE;
                        if (localtype == 256) {
-                               localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength));
+                               localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength), true);
                        }
                        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;
-                       logger.debug("Restlength {}", restLength);
+                       final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+                                       - TYPE_LENGTH - LENGTH_SIZE - locallength;
+                       logger.trace("Restlength {}", restLength);
                        switch (type) {
                        case Link:
                                parseLink(builder, ByteArray.subByte(nlri, byteOffset, restLength));
@@ -330,15 +339,17 @@ public final class LinkstateNlriParser implements NlriParser {
                                break;
                        }
                        byteOffset += restLength;
+                       dests.add(builder.build());
                }
-               return builder.build();
+               return dests;
        }
 
        @Override
        public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
-               if (nlri.length == 0)
+               if (nlri.length == 0) {
                        return;
-               final CLinkstateDestination dst = parseNlri(nlri);
+               }
+               final List<CLinkstateDestination> dst = parseNlri(nlri);
 
                builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
                                new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
@@ -346,7 +357,7 @@ public final class LinkstateNlriParser implements NlriParser {
 
        @Override
        public void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
-               final CLinkstateDestination dst = parseNlri(nlri);
+               final List<CLinkstateDestination> dst = parseNlri(nlri);
 
                builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
                                new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build());
index 7307901a45d8c06db555b12f28a5a9f358240cd7..81c424f8293acfe9cea0ff82245b9e5a18ce5137 100644 (file)
@@ -261,7 +261,7 @@ module bgp-linkstate {
        }
 
        grouping linkstate-destination {
-               container c-linkstate-destination {
+               list c-linkstate-destination {
                        leaf nlri-type {
                                type nlri-type;
                        }
diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
new file mode 100644 (file)
index 0000000..f545743
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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 java.math.BigInteger;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+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.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
+
+public class LinkstateNlriParserTest {
+
+       private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x27, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+                       (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+                       (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39 };
+
+       private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48,
+                       (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02,
+                       (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42,
+                       (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28,
+                       (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+                       (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0,
+                       (byte) 0x28 };
+
+       private final byte[] nextHop = new byte[] { (byte) 0x0a, (byte) 0x19, (byte) 0x02, (byte) 0x1b };
+
+       @Test
+       public void testNodeNlri() throws BGPParsingException {
+               final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+               final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+               parser.parseNlri(this.nodeNlri, this.nextHop, builder);
+
+               assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+               final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+               assertEquals(1, ls.getCLinkstateDestination().size());
+
+               final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+               assertEquals(NlriType.Node, dest.getNlriType());
+               assertNull(dest.getDistinguisher());
+               assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+               assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+               final LocalNodeDescriptors nodeD = dest.getLocalNodeDescriptors();
+               assertEquals(new AsNumber(72L), nodeD.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), nodeD.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x39 })).build()).build(), nodeD.getCRouterIdentifier());
+
+               assertNull(dest.getRemoteNodeDescriptors());
+       }
+
+       @Test
+       public void testLinkNlri() throws BGPParsingException {
+               final LinkstateNlriParser parser = new LinkstateNlriParser(false);
+               final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+               parser.parseNlri(this.linkNlri, this.nextHop, builder);
+
+               assertEquals("10.25.2.27", ((CIpv4NextHop) builder.getCNextHop()).getIpv4NextHop().getGlobal().getValue());
+
+               final DestinationLinkstate ls = (DestinationLinkstate) builder.getAdvertizedRoutes().getDestinationType();
+
+               assertEquals(1, ls.getCLinkstateDestination().size());
+
+               final CLinkstateDestination dest = ls.getCLinkstateDestination().get(0);
+
+               assertEquals(NlriType.Link, dest.getNlriType());
+               assertNull(dest.getDistinguisher());
+               assertEquals(ProtocolId.IsisLevel2, dest.getProtocolId());
+               assertEquals(BigInteger.ONE, dest.getIdentifier().getValue());
+
+               final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
+               assertEquals(new AsNumber(72L), local.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
+               final RemoteNodeDescriptors remote = dest.getRemoteNodeDescriptors();
+               assertEquals(new AsNumber(72L), remote.getAsNumber());
+               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), remote.getDomainId());
+               assertEquals(
+                               new CIsisNodeBuilder().setIsisNode(
+                                               new IsisNodeBuilder().setIsoSystemId(
+                                                               new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                                                               (byte) 0x40 })).build()).build(), remote.getCRouterIdentifier());
+               final LinkDescriptors ld = dest.getLinkDescriptors();
+               assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
+               assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
+       }
+}
index 3337a244b06974d67d45ee88a6e38e5599cc3b87..ea3831f1ad1f49b8dc09bb8bd55ec5146f60c151 100644 (file)
@@ -15,12 +15,12 @@ import static org.junit.Assert.assertNull;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
@@ -34,8 +34,28 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
@@ -64,6 +84,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
@@ -85,6 +106,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -203,12 +225,12 @@ public class BGPParserTest {
 
                // check nlri
 
-               List<Ipv4Prefix> prefs = Lists.newArrayList();
+               final List<Ipv4Prefix> prefs = Lists.newArrayList();
                prefs.add(new Ipv4Prefix("172.17.2.0/24"));
                prefs.add(new Ipv4Prefix("172.17.1.0/24"));
                prefs.add(new Ipv4Prefix("172.17.0.0/24"));
 
-               Nlri nlri = new NlriBuilder().setNlri(prefs).build();
+               final Nlri nlri = new NlriBuilder().setNlri(prefs).build();
 
                assertEquals(nlri, message.getNlri());
 
@@ -216,9 +238,9 @@ public class BGPParserTest {
 
                // check path attributes
 
-               PathAttributes attrs = message.getPathAttributes();
+               final PathAttributes attrs = message.getPathAttributes();
 
-               PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
                paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
                assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
@@ -304,7 +326,7 @@ public class BGPParserTest {
 
                // check NLRI
 
-               List<Ipv6Prefix> prefs = Lists.newArrayList();
+               final List<Ipv6Prefix> prefs = Lists.newArrayList();
                prefs.add(new Ipv6Prefix("2001:db8:1:2::/64"));
                prefs.add(new Ipv6Prefix("2001:db8:1:1::/64"));
                prefs.add(new Ipv6Prefix("2001:db8:1::/64"));
@@ -325,9 +347,9 @@ public class BGPParserTest {
 
                // check path attributes
 
-               PathAttributes attrs = message.getPathAttributes();
+               final PathAttributes attrs = message.getPathAttributes();
 
-               PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
                paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
                assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
@@ -344,7 +366,7 @@ public class BGPParserTest {
                paBuilder.setClusterId(clusters);
                assertEquals(paBuilder.getClusterId(), attrs.getClusterId());
 
-               MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
                mpBuilder.setAfi(Ipv6AddressFamily.class);
                mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
                mpBuilder.setCNextHop(nextHop);
@@ -432,9 +454,9 @@ public class BGPParserTest {
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
 
                // check path attributes
-               PathAttributes attrs = message.getPathAttributes();
+               final PathAttributes attrs = message.getPathAttributes();
 
-               PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
                paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
                assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
@@ -529,9 +551,9 @@ public class BGPParserTest {
                final List<Segments> asPath = Lists.newArrayList();
 
                // check path attributes
-               PathAttributes attrs = message.getPathAttributes();
+               final PathAttributes attrs = message.getPathAttributes();
 
-               PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
 
                paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
                assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
@@ -808,58 +830,123 @@ public class BGPParserTest {
                00 00 01 <- value
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testBGPLink() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(8), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
-               // network object state
-               // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-
-               // network link state
-               // final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
-               // container.setDefaultEntry(new IGPMetric(1));
-               // final NetworkLinkState linkState = new NetworkLinkState(objState, container, null,
-               // LinkProtectionType.UNPROTECTED, null, null, null);
-
-               // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
-               // DomainIdentifier(new byte[] { 25, 25,
-               // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-               //
-               // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
-               // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-               // 0x0b, 0x0b, 0x0b, 0x03 })));
-               // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-               //
-               // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+                               new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
 
-               // check API message
+               final List<Segments> asPath = Lists.newArrayList();
+
+               final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+               clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+               clBuilder.setNlriType(NlriType.Link);
+               clBuilder.setProtocolId(ProtocolId.Ospf);
+
+               final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(LinkstateAddressFamily.class);
+               mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+               mpBuilder.setCNextHop(nextHop);
+
+               final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
+                               new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
+               linkstates.add(clBuilder.build());
+
+               lsBuilder.setMpReachNlri(mpBuilder.build());
+
+               // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
+
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
 
-               // final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
-               // final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
-               // final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new
-               // IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
-               //
-               // final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
-               // final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
-               // final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
-               //
-               // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1,
-               // (BGPObject) link2,
-               // (BGPObject) link3), Collections.<Identifier> emptySet());
-               //
-               // assertEquals(expectedMessage, message);
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+               paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+               assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+               final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+               assertEquals(mpBuilder.getAfi(), mp.getAfi());
+               assertEquals(mpBuilder.getSafi(), mp.getSafi());
+               assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+               final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+               dBuilder.setCLinkstateDestination(linkstates);
+
+               mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+               lsBuilder.setMpReachNlri(mpBuilder.build());
+
+               paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder();
+
+               lsAttrBuilder.setLinkstatePathAttribute(new LinkstatePathAttributeBuilder().setLinkStateAttribute(
+                               new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
+               paBuilder.addAugmentation(
+                               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class,
+                               lsAttrBuilder.build());
+
+               assertEquals(
+                               lsAttrBuilder.build().getLinkstatePathAttribute(),
+                               attrs.getAugmentation(
+                                               org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1.class).getLinkstatePathAttribute());
+
+               final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+               assertEquals(linkstates.size(), dests.size());
+
+               assertEquals(linkstates, dests);
+               // check API message
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
@@ -875,11 +962,11 @@ public class BGPParserTest {
                04 <- next hop length
                19 19 19 01 - nexthop (25.25.25.1)
                00 <- reserved
+               
                00 01 <- NLRI type (1 - nodeNLRI)
                00 31 <- NLRI length (49)
                03 <- ProtocolID - OSPF
                00 00 00 00 00 00 00 01 <- identifier
-
                01 00 <- local node descriptor type (256)
                00 24 <- length (36)
                02 00 <- node descriptor type (member AS - 512)
@@ -899,7 +986,6 @@ public class BGPParserTest {
                00 2d <- NLRI length (45)
                03 <- ProtocolID - OSPF
                00 00 00 00 00 00 00 01 <- identifier
-
                01 00 <- local node descriptor type (256)
                00 20 <- length (32)
                02 00 <- node descriptor type (member AS - 512)
@@ -947,50 +1033,91 @@ public class BGPParserTest {
                00 00 00 64 <- value
         */
        @Test
-       @Ignore
-       // FIXME: to be fixed in testing phase
        public void testBGPNode() throws Exception {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(9), MessageUtil.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), MessageUtil.MARKER_LENGTH,
                                MessageUtil.LENGTH_FIELD_LENGTH));
                final Update message = BGPParserTest.updateParser.parseMessageBody(body, messageLength);
 
+               final UpdateBuilder builder = new UpdateBuilder();
+
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
-               // network object state
-               // final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(),
-               // Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               // final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-               // final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(),
-               // Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier>
-               // emptySet(), null);
-
-               // network link state
-
-               // final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new
-               // DomainIdentifier(new byte[] { 25, 25,
-               // 25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-               //
-               // final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new
-               // byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-               // 0x0b, 0x0b, 0x0b, 0x03 })));
-               // final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-               //
-               // final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               // attributes
 
-               // check API message
+               final CIpv4NextHop nextHop = new CIpv4NextHopBuilder().setIpv4NextHop(
+                               new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
+
+               final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
+                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
+                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+
+               final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
+               clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
+               clBuilder.setNlriType(NlriType.Node);
+               clBuilder.setProtocolId(ProtocolId.Ospf);
+
+               final List<CLinkstateDestination> linkstates = Lists.newArrayList();
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfPseudonodeBuilder().setOspfPseudonode(
+                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
+                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
+                               new COspfNodeBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+               linkstates.add(clBuilder.build());
+
+               final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(LinkstateAddressFamily.class);
+               mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+               mpBuilder.setCNextHop(nextHop);
 
-               // final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
-               // final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
-               // final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
-               //
-               // final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1,
-               // (BGPObject) node2,
-               // (BGPObject) node3), Collections.<Identifier> emptySet());
-               //
-               // assertEquals(expectedMessage, message);
+               final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
+               dBuilder.setCLinkstateDestination(linkstates);
+
+               mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(dBuilder.build()).build());
+               lsBuilder.setMpReachNlri(mpBuilder.build());
+
+               final List<Segments> asPath = Lists.newArrayList();
+
+               // check path attributes
+               final PathAttributes attrs = message.getPathAttributes();
+
+               final PathAttributesBuilder paBuilder = new PathAttributesBuilder();
+
+               paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
+               assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
+
+               paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
+               assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
+
+               paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+               assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
+
+               paBuilder.addAugmentation(PathAttributes1.class, lsBuilder.build());
+
+               final MpReachNlri mp = attrs.getAugmentation(PathAttributes1.class).getMpReachNlri();
+               assertEquals(mpBuilder.getAfi(), mp.getAfi());
+               assertEquals(mpBuilder.getSafi(), mp.getSafi());
+               assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
+
+               final List<CLinkstateDestination> dests = ((DestinationLinkstate) mp.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+
+               assertEquals(linkstates.size(), dests.size());
+
+               assertEquals(linkstates, dests);
+
+               // check API message
+               builder.setPathAttributes(paBuilder.build());
+               assertEquals(builder.build(), message);
        }
 
        /*
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/OpenTest.java
new file mode 100644 (file)
index 0000000..60414e0
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.parser.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+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.message.rev130918.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4BytesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
+
+import com.google.common.collect.Lists;
+
+public class OpenTest {
+
+       private final byte[] result = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0x00, (byte) 0x25, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x1e, (byte) 0x00, (byte) 0x03, (byte) 0x7f,
+                       (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x02, (byte) 0x06, (byte) 0x41, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x00, (byte) 0x03, (byte) 0xe8 };
+
+       @Test
+       public void testSerializeOpen() throws Exception {
+               final List<BgpParameters> tlvs = Lists.newArrayList();
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).build()).build());
+               final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(
+                               new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
+               final byte[] msg = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getParameterRegistry()).serializeMessage(open);
+               assertArrayEquals(this.result, msg);
+       }
+}
index d574fcdb1b53a800b092579ff36e8e04e48736bd..81df32f3386920dc0114fe25c2095217e81c099a 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.concepts.AbstractRegistration;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 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.LinkstateDestination;
 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.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
@@ -53,8 +54,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final Ipv4Prefix key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv4Prefix key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv4Routes.class);
@@ -65,7 +65,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
@@ -77,15 +77,14 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                                }
                        };
 
-                       for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
+                       for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
                                super.add(trans, peer, id, data);
                        }
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4)nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       for (final Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4) nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
                                super.remove(trans, peer, id);
                        }
                }
@@ -97,8 +96,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final Ipv6Prefix key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final Ipv6Prefix key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        builder.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.routes.Ipv6Routes.class);
@@ -109,7 +107,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
@@ -121,15 +119,14 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                                }
                        };
 
-                       for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
+                       for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
                                super.add(trans, peer, id, data);
                        }
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6)nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       for (final Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6) nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
                                super.remove(trans, peer, id);
                        }
                }
@@ -141,8 +138,7 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath,
-                               final CLinkstateDestination key) {
+               public InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final CLinkstateDestination key) {
                        final InstanceIdentifierBuilder<?> builder = InstanceIdentifier.builder(basePath);
 
                        switch (key.getNlriType()) {
@@ -165,13 +161,11 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
 
                @Override
                public void addRoutes(
-                               final DataModificationTransaction   trans,
+                               final DataModificationTransaction trans,
                                final Peer peer,
                                final MpReachNlri nlri,
                                final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
-                       final CLinkstateDestination key =
-                                       ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
-                                                       update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
+                       final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
 
                        RIBEntryData data = null;
                        switch (key.getNlriType()) {
@@ -220,11 +214,8 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                }
 
                @Override
-               public void removeRoutes(final DataModificationTransaction   trans, final Peer peer,
-                               final MpUnreachNlri nlri) {
-                       final CLinkstateDestination key =
-                                       ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
-                                                       update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstate) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
+               public void removeRoutes(final DataModificationTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
+                       final CLinkstateDestination key = (CLinkstateDestination) ((LinkstateDestination) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
 
                        super.remove(trans, peer, key);
                }
@@ -233,22 +224,19 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
        static {
                final AdjRIBsInFactoryRegistry reg = new AdjRIBsInFactoryRegistryImpl();
 
-               reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new Ipv4AdjRIBsIn(comparator, key);
                        }
                });
-               reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new Ipv6AdjRIBsIn(comparator, key);
                        }
                });
-               reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
-                               new AdjRIBsInFactory() {
+               reg.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new AdjRIBsInFactory() {
                        @Override
                        public AdjRIBsIn createAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
                                return new LinkstateAdjRIBsIn(comparator, key);
@@ -267,25 +255,26 @@ public final class AdjRIBsInFactoryRegistryImpl implements AdjRIBsInFactoryRegis
                        final Class<? extends SubsequentAddressFamily> safi, final AdjRIBsInFactory factory) {
                final TablesKey key = new TablesKey(afi, safi);
 
-               if (factories.containsKey(key)) {
+               if (this.factories.containsKey(key)) {
                        throw new RuntimeException("Specified AFI/SAFI combination is already registered");
                }
 
-               factories.put(key, factory);
+               this.factories.put(key, factory);
 
                final Object lock = this;
                return new AbstractRegistration() {
                        @Override
                        protected void removeRegistration() {
                                synchronized (lock) {
-                                       factories.remove(key);
+                                       AdjRIBsInFactoryRegistryImpl.this.factories.remove(key);
                                }
                        }
                };
        }
 
        @Override
-       public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
-               return factories.get(new TablesKey(afi, safi));
+       public synchronized AdjRIBsInFactory getAdjRIBsInFactory(final Class<? extends AddressFamily> afi,
+                       final Class<? extends SubsequentAddressFamily> safi) {
+               return this.factories.get(new TablesKey(afi, safi));
        }
 }
index dd65579f625dfeb291f5704de73eef02a143a6ad..e71b445bce8fdca0aaeb88bb48a7e00066ea406a 100644 (file)
@@ -14,12 +14,14 @@ import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
  */
 public final class BGPMessageHeaderDecoder extends LengthFieldBasedFrameDecoder {
 
-       private static final int MAX_FRAME_SIZE = 4096; // min 19, max 4096
+       private static final int MAX_FRAME_SIZE = 4096;
 
        private static final int MARKER_SIZE = 16;
 
-       private static final int LENGTH_SIZE = 2; // the length field represents the length of the whole message including
-                                                                                               // the header
+       /*
+        * the length field represents the length of the whole message including the header
+        */
+       private static final int LENGTH_SIZE = 2;
 
        /*
                
index 42a8db6d4a906867b7f30f79db785cb00229c19a..10d3ab5965f94a012f361e6a2b29999d7ffea072 100644 (file)
@@ -42,7 +42,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        @Override
        public void onMessage(final BGPSession session, final Notification message) {
                if (message instanceof Update) {
-                       this.rib.updateTables(this, (Update)message);
+                       this.rib.updateTables(this, (Update) message);
                } else {
                        logger.info("Ignoring unhandled message class " + message.getClass());
                }
@@ -52,8 +52,8 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        public void onSessionUp(final BGPSession session) {
                logger.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
 
-               for (BgpTableType t : session.getAdvertisedTableTypes()) {
-                       tables.add(new TablesKey(t.getAfi(), t.getSafi()));
+               for (final BgpTableType t : session.getAdvertisedTableTypes()) {
+                       this.tables.add(new TablesKey(t.getAfi(), t.getSafi()));
                }
        }
 
@@ -64,7 +64,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
                        this.rib.clearTable(this, key);
                }
 
-               tables.clear();
+               this.tables.clear();
        }
 
        @Override
@@ -73,7 +73,7 @@ public final class BGPPeer implements BGPSessionListener, Peer {
        }
 
        @Override
-       public final String toString() {
+       public String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index 9dd80cf7ce24d583f8ca5cd1dd27369aabd370a7..032cea380d7856c8d2ff310f5fefacb9439e4c5e 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,11 +50,14 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
 
+       /*
+        * 240
+        */
        private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
 
        private static final Notification keepalive = new KeepaliveBuilder().build();
 
-       private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE; // 240
+       private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
 
        /**
         * Internal session state.
@@ -113,19 +117,21 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                this.keepAlive = remoteOpen.getHoldTimer() / 3;
                holdTimerValue = remoteOpen.getHoldTimer();
 
-               final Set<BgpTableType> tts = Sets.newHashSet();
+               final Set<TablesKey> tts = Sets.newHashSet();
+               final Set<BgpTableType> tats = Sets.newHashSet();
                if (remoteOpen.getBgpParameters() != null) {
                        for (final BgpParameters param : remoteOpen.getBgpParameters()) {
                                if (param instanceof CParameters) {
                                        final CParameters cp = (CParameters) param;
-                                       final BgpTableType tt = new BgpTableTypeImpl(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+                                       final TablesKey tt = new TablesKey(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
                                        tts.add(tt);
+                                       tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
                                }
                        }
                }
 
                this.sync = new BGPSynchronization(this, this.listener, tts);
-               this.tableTypes = tts;
+               this.tableTypes = tats;
 
                if (remoteOpen.getHoldTimer() != 0) {
                        this.stateTimer.newTimeout(new TimerTask() {
@@ -278,7 +284,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        }
 
        @Override
-       final public String toString() {
+       public final String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index e849e19e139b56acf980c8280adf20351a27f1f6..e536ba54f7e18157fc43767ae62a982063c34681 100644 (file)
@@ -134,30 +134,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                case OpenSent:
                        if (msg instanceof Open) {
                                final Open openObj = (Open) msg;
-
-                               final List<BgpParameters> prefs = openObj.getBgpParameters();
-                               if (prefs != null && !prefs.isEmpty()) {
-                                       for (final BgpParameters param : openObj.getBgpParameters()) {
-                                               final CParameters cap = param.getCParameters();
-                                               if (cap instanceof CMultiprotocol) {
-                                                       if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
-                                                                       && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
-                                                               this.remotePref = openObj;
-                                                               this.channel.writeAndFlush(new KeepaliveBuilder().build());
-                                                               this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
-                                                               this.state = State.OpenConfirm;
-                                                               logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
-                                                               return;
-                                                       }
-                                               }
-                                       }
-                               }
-                               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
-                                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
-                               this.channel.writeAndFlush(ntf);
-                               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
-                                               ntf.getErrorCode(), ntf.getErrorSubcode())));
-                               this.state = State.Finished;
+                               handleOpen(openObj);
                                return;
                        }
                        break;
@@ -171,6 +148,31 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                this.state = State.Finished;
        }
 
+       private void handleOpen(final Open openObj) {
+               final List<BgpParameters> prefs = openObj.getBgpParameters();
+               if (prefs != null && !prefs.isEmpty()) {
+                       for (final BgpParameters param : openObj.getBgpParameters()) {
+                               final CParameters cap = param.getCParameters();
+                               if (cap instanceof CMultiprotocol
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+                                       this.remotePref = openObj;
+                                       this.channel.writeAndFlush(new KeepaliveBuilder().build());
+                                       this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+                                       this.state = State.OpenConfirm;
+                                       logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+                                       return;
+                               }
+                       }
+               }
+               final Notify ntf = new NotifyBuilder().setErrorCode(BGPError.UNSPECIFIC_OPEN_ERROR.getCode()).setErrorSubcode(
+                               BGPError.UNSPECIFIC_OPEN_ERROR.getSubcode()).build();
+               this.channel.writeAndFlush(ntf);
+               negotiationFailed(new BGPDocumentedException("Linkstate capability is not configured on router. Check the configuration of BGP speaker.", BGPError.forValue(
+                               ntf.getErrorCode(), ntf.getErrorSubcode())));
+               this.state = State.Finished;
+       }
+
        public synchronized State getState() {
                return this.state;
        }
index 0140ebe58e1a332be0c1c043754e1de0bc0309b2..1b9fbd4677b85b6b15e6f7e825ea29dd8f3a4aba 100644 (file)
@@ -52,10 +52,6 @@ public final class BGPSessionProposalImpl implements BGPSessionProposal {
                                new CMultiprotocolBuilder().setMultiprotocolCapability(
                                                new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
                                                                LinkstateSubsequentAddressFamily.class).build()).build()).build());
-               // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
-               // tableTypes.put(ipv4, true);
-               // tableTypes.put(linkstate,true);
-               // tlvs.add(new GracefulCapability(true, 0, tableTypes));
                tlvs.add(new BgpParametersBuilder().setCParameters(
                                new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
                this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
index 65d6676db60d372bfdba5e588b365c58148de6e1..b372c2f85ce4e035443b4a053f659e9d07d234a0 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
@@ -61,17 +60,17 @@ public class BGPSynchronization {
                }
        }
 
-       private final Map<BgpTableType, SyncVariables> syncStorage = Maps.newHashMap();
+       private final Map<TablesKey, SyncVariables> syncStorage = Maps.newHashMap();
 
        private final BGPSessionListener listener;
 
        private final BGPSession session;
 
-       public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<BgpTableType> types) {
+       public BGPSynchronization(final BGPSession bgpSession, final BGPSessionListener listener, final Set<TablesKey> types) {
                this.listener = Preconditions.checkNotNull(listener);
                this.session = Preconditions.checkNotNull(bgpSession);
 
-               for (final BgpTableType type : types) {
+               for (final TablesKey type : types) {
                        this.syncStorage.put(type, new SyncVariables());
                }
        }
@@ -89,12 +88,12 @@ public class BGPSynchronization {
                if (msg.getNlri() != null || msg.getWithdrawnRoutes() != null) {
                        type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
                } else if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
-                       PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
+                       final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
                        if (pa.getMpReachNlri() != null) {
                                type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
                        }
                } else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
-                       PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
+                       final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
                        if (pa.getMpUnreachNlri() != null) {
                                type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
                        }
@@ -113,7 +112,7 @@ public class BGPSynchronization {
         * session.
         */
        public void kaReceived() {
-               for (final Entry<BgpTableType, SyncVariables> entry : this.syncStorage.entrySet()) {
+               for (final Entry<TablesKey, SyncVariables> entry : this.syncStorage.entrySet()) {
                        final SyncVariables s = entry.getValue();
                        if (!s.getEor()) {
                                if (!s.getUpd()) {
@@ -127,10 +126,14 @@ public class BGPSynchronization {
                }
        }
 
-       private Update generateEOR(final BgpTableType type) {
+       private Update generateEOR(final TablesKey type) {
                if (type.getAfi().equals(Ipv4AddressFamily.class) && type.getSafi().equals(UnicastSubsequentAddressFamily.class)) {
                        return new UpdateBuilder().build();
                }
-               return new UpdateBuilder().setPathAttributes(new PathAttributesBuilder().addAugmentation(PathAttributes1.class, new PathAttributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
+               return new UpdateBuilder().setPathAttributes(
+                               new PathAttributesBuilder().addAugmentation(
+                                               PathAttributes1.class,
+                                               new PathAttributes1Builder().setMpReachNlri(
+                                                               new MpReachNlriBuilder().setAfi(type.getAfi()).setSafi(type.getSafi()).build()).build()).build()).build();
        }
 }
index b06b2a0045f1ae8f80e1f0006c417399845fbebf..b3e754d9ad1458de73b40d67998fcf96389d33fe 100644 (file)
@@ -11,8 +11,6 @@ import java.util.concurrent.Future;
 
 import javax.annotation.concurrent.ThreadSafe;
 
-
-
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
@@ -44,19 +42,19 @@ final class RIBImpl {
        }
 
        synchronized void updateTables(final BGPPeer peer, final Update message) {
-               final DataModificationTransaction trans = dps.beginTransaction();
+               final DataModificationTransaction trans = this.dps.beginTransaction();
 
                // FIXME: detect and handle end-of-RIB markers
 
-               //remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-               //              trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
+               // remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+               // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
 
                final PathAttributes attrs = message.getPathAttributes();
                final PathAttributes2 mpu = attrs.getAugmentation(PathAttributes2.class);
                if (mpu != null) {
                        final MpUnreachNlri nlri = mpu.getMpUnreachNlri();
 
-                       AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+                       final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
                        if (ari != null) {
                                ari.removeRoutes(trans, peer, nlri);
                        } else {
@@ -64,14 +62,14 @@ final class RIBImpl {
                        }
                }
 
-               //add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
-               //              trans, peer, message.getNlri().getNlri().iterator(), attrs);
+               // add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+               // trans, peer, message.getNlri().getNlri().iterator(), attrs);
 
                final PathAttributes1 mpr = message.getPathAttributes().getAugmentation(PathAttributes1.class);
                if (mpr != null) {
                        final MpReachNlri nlri = mpr.getMpReachNlri();
 
-                       final AdjRIBsIn ari = tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
+                       final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
                        if (ari != null) {
                                ari.addRoutes(trans, peer, nlri, attrs);
                        } else {
@@ -80,22 +78,22 @@ final class RIBImpl {
                }
 
                // FIXME: we need to attach to this future for failures
-               Future<RpcResult<TransactionStatus>> f = trans.commit();
+               final Future<RpcResult<TransactionStatus>> f = trans.commit();
        }
 
        synchronized void clearTable(final BGPPeer peer, final TablesKey key) {
-               final AdjRIBsIn ari = tables.get(key);
+               final AdjRIBsIn ari = this.tables.get(key);
                if (ari != null) {
-                       final DataModificationTransaction trans = dps.beginTransaction();
+                       final DataModificationTransaction trans = this.dps.beginTransaction();
                        ari.clear(trans, peer);
 
                        // FIXME: we need to attach to this future for failures
-                       Future<RpcResult<TransactionStatus>> f = trans.commit();
+                       final Future<RpcResult<TransactionStatus>> f = trans.commit();
                }
        }
 
        @Override
-       public final String toString() {
+       public String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
index 99a6fb68e03b947a4f3051b14d99a3e716744a5d..17e6b3fde757510c244d013bba66b7c6f92f0d5b 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.rib.impl.spi;
 
 import io.netty.util.concurrent.Future;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
@@ -27,7 +26,7 @@ public interface BGPDispatcher {
         * @param connection attributes required for connection
         * @param parser BGP message parser
         * @return client session
-        * @throws IOException
         */
-       Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener, final ReconnectStrategy strategy);
+       Future<BGPSessionImpl> createClient(InetSocketAddress address, BGPSessionPreferences preferences, BGPSessionListener listener,
+                       final ReconnectStrategy strategy);
 }
index aff25f329b9244730c7b591fb11947c94f48c0a8..3a0331866d1214afcb15d349b83979d0995e6b77 100644 (file)
@@ -8,24 +8,33 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
 
-import java.util.Collections;
 import java.util.Set;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.NlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 public class SynchronizationTest {
@@ -43,15 +52,29 @@ public class SynchronizationTest {
        @Before
        public void setUp() {
                this.listener = new SimpleSessionListener();
-//             final BGPIPv4RouteImpl i4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("1.1.1.1/32"), new BaseBGPObjectState(null, null), null);
-//             this.ipv4m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i4), Collections.EMPTY_SET);
-//             final BGPIPv6RouteImpl i6 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("::1/32"), new BaseBGPObjectState(null, null), null);
-//             this.ipv6m = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(i6), Collections.EMPTY_SET);
-//             this.lsm = new BGPUpdateMessageImpl(Sets.<BGPObject> newHashSet(mock(BGPLink.class)), Collections.EMPTY_SET);
+               this.ipv4m = new UpdateBuilder().setNlri(new NlriBuilder().setNlri(Lists.newArrayList(new Ipv4Prefix("1.1.1.1/32"))).build()).build();
 
-               final Set<BgpTableType> types = Sets.newHashSet();
-               types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-               types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+               final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+               mpBuilder.setAfi(Ipv6AddressFamily.class);
+               mpBuilder.setSafi(UnicastSubsequentAddressFamily.class);
+
+               PathAttributesBuilder paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes1.class,
+                               new PathAttributes1Builder().setMpReachNlri(mpBuilder.build()).build());
+
+               this.ipv6m = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+               final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
+               mpUBuilder.setAfi(LinkstateAddressFamily.class);
+               mpUBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
+
+               paBuilder = new PathAttributesBuilder().addAugmentation(PathAttributes2.class,
+                               new PathAttributes2Builder().setMpUnreachNlri(mpUBuilder.build()).build());
+
+               this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
+
+               final Set<TablesKey> types = Sets.newHashSet();
+               types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+               types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
 
                this.bs = new BGPSynchronization(new BGPSession() {
 
@@ -61,27 +84,28 @@ public class SynchronizationTest {
 
                        @Override
                        public Set<BgpTableType> getAdvertisedTableTypes() {
+                               final Set<BgpTableType> types = Sets.newHashSet();
+                               types.add(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
+                               types.add(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
                                return types;
                        }
                }, this.listener, types);
        }
 
        @Test
-       @Ignore
-       //FIXME: to be fixed in testing phase
        public void testSynchronize() {
                // simulate sync
-//             this.bs.updReceived(this.ipv6m);
-//
-//             this.bs.updReceived(this.ipv4m);
-//             this.bs.updReceived(this.lsm);
-//             this.bs.kaReceived(); // nothing yet
-//             this.bs.updReceived(this.ipv4m);
+               this.bs.updReceived(this.ipv6m);
+               this.bs.updReceived(this.ipv4m);
+               this.bs.updReceived(this.lsm);
+               this.bs.kaReceived(); // nothing yet
+               this.bs.updReceived(this.ipv4m);
                this.bs.kaReceived(); // linkstate
                assertEquals(1, this.listener.getListMsg().size());
+               assertEquals(
+                               LinkstateAddressFamily.class,
+                               ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
                this.bs.kaReceived(); // ipv4 sync
                assertEquals(2, this.listener.getListMsg().size());
-               assertEquals(Ipv4AddressFamily.class,
-                               ((Update) this.listener.getListMsg().get(1)).getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi());
        }
 }
index cb5bf7f8da371693977ae402d2dac8f0a961445b..1b77f841d11c733444d83b3c6547792866c7134c 100644 (file)
@@ -42,9 +42,9 @@ import com.google.common.eventbus.EventBus;
 @ThreadSafe
 public final class BGPMock implements BGP, Closeable {
 
-       private final static Logger logger = LoggerFactory.getLogger(BGPMock.class);
+       private static final Logger logger = LoggerFactory.getLogger(BGPMock.class);
 
-       static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
+       static final Notification CONNECTION_LOST_MAGIC_MSG = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
 
        @GuardedBy("this")
        private final List<byte[]> allPreviousByteMessages;
@@ -89,7 +89,7 @@ public final class BGPMock implements BGP, Closeable {
        }
 
        public synchronized void insertConnectionLostEvent() {
-               this.insertMessage(connectionLostMagicMessage);
+               this.insertMessage(CONNECTION_LOST_MAGIC_MSG);
        }
 
        public synchronized void insertMessages(final List<Notification> messages) {
index 814c6c2c38725414cda85e32c2ddcb83fa3000f9..be015d95c2c860a8fb5005972d331cc1a0fb3b50 100644 (file)
@@ -59,7 +59,7 @@ final class EventBusRegistration extends ListenerRegistration<BGPSessionListener
        }
 
        private static void sendMessage(final BGPSessionListener listener, final Notification message) {
-               if (BGPMock.connectionLostMagicMessage.equals(message)) {
+               if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
                        listener.onSessionTerminated(null, null);
                } else if (message instanceof Open) {
                        final Set<BgpTableType> tts = Sets.newHashSet();
@@ -84,9 +84,7 @@ final class EventBusRegistration extends ListenerRegistration<BGPSessionListener
                                        return tts;
                                }
                        });
-               } else if (message instanceof Keepalive) {
-                       // do nothing
-               } else {
+               } else if (!(message instanceof Keepalive)) {
                        listener.onMessage(null, message);
                }
        }
index 5d419a28de8bd2b32ea52765f17a21357e781964..348ae034c63e82d44b57eae12f172afed9be558c 100644 (file)
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
  */
 public class Main {
 
-       private final static Logger logger = LoggerFactory.getLogger(Main.class);
+       private static final Logger logger = LoggerFactory.getLogger(Main.class);
 
        private static String usage = "DESCRIPTION:\n"
                        + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
@@ -49,7 +49,11 @@ public class Main {
 
        private final BGPDispatcherImpl dispatcher;
 
-       public Main() throws Exception {
+       private static final int INITIAL_HOLD_TIME = 90;
+
+       private static final int RECONNECT_MILLIS = 5000;
+
+       Main() throws Exception {
                this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
        }
 
@@ -60,7 +64,7 @@ public class Main {
                }
 
                InetSocketAddress address = null;
-               short holdTimerValue = 90;
+               short holdTimerValue = INITIAL_HOLD_TIME;
                AsNumber as = null;
 
                int i = 0;
@@ -92,6 +96,7 @@ public class Main {
                logger.debug("{} {} {}", address, sessionListener, proposal);
 
                final InetSocketAddress addr = address;
-               m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
+               m.dispatcher.createClient(addr, proposal, sessionListener,
+                               new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
        }
 }
index b44a5dae5310f0ea9881d541d773b7443c741144..8f0ee1d93acd3bfadfac71ee5e8935a84bd5cefe 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.bgp.util;
 
-import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -28,10 +27,11 @@ import com.google.common.primitives.UnsignedBytes;
 @Immutable
 public final class BinaryBGPDumpFileParser {
 
-       private static final byte ff = (byte) 255;
        private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
        private static final int MINIMAL_LENGTH = 19;
 
+       private static final int MARKER_LENGTH = 16;
+
        private BinaryBGPDumpFileParser() {
 
        }
@@ -41,7 +41,6 @@ public final class BinaryBGPDumpFileParser {
         * 
         * @param file file with BGP messages in binary form.
         * @return list with byte arrays representing extracted messages.
-        * @throws IOException
         */
        public static List<byte[]> parseMessages(final byte[] byteArray) {
 
@@ -51,15 +50,15 @@ public final class BinaryBGPDumpFileParser {
                        final byte b = byteArray[i];
 
                        // Marker start
-                       if (b == ff) {
+                       if (b == UnsignedBytes.MAX_VALUE) {
                                final int start = i;
                                int ffCount = 0;
                                for (int j = i; j < i + (17); j++) {
                                        // Check marker
-                                       if (byteArray[j] == ff) {
+                                       if (byteArray[j] == UnsignedBytes.MAX_VALUE) {
                                                ffCount++;
-                                       } else if (ffCount == 16) {
-                                               if (j == (i + 16)) {
+                                       } else if (ffCount == MARKER_LENGTH) {
+                                               if (j == (i + MARKER_LENGTH)) {
                                                        // Parse length
                                                        final int length = UnsignedBytes.toInt(byteArray[j]) * 256 + UnsignedBytes.toInt(byteArray[j + 1]);
 
@@ -68,7 +67,7 @@ public final class BinaryBGPDumpFileParser {
 
                                                        final byte[] message = Arrays.copyOfRange(byteArray, start, start + length);
                                                        messages.add(message);
-                                                       j += length - 16;
+                                                       j += length - MARKER_LENGTH;
                                                }
                                                i = j;
                                                break;
index 02cd0f68db0ffe0e385a4d785d19f2a14c9f464f..9ea256ba6b79ccb8c7e78e24369826356e68e805 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.util;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -35,16 +34,16 @@ import com.google.common.io.CharStreams;
  * this format.
  */
 @Immutable
-public class HexDumpBGPFileParser {
+public final class HexDumpBGPFileParser {
        private static final int MINIMAL_LENGTH = 19;
        private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
-       private static final String ff_16 = Strings.repeat("FF", 16);
+       private static final String FF_16 = Strings.repeat("FF", 16);
 
        private HexDumpBGPFileParser() {
 
        }
 
-       public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
+       public static List<byte[]> parseMessages(final File file) throws IOException {
                Preconditions.checkArgument(file != null, "Filename cannot be null");
                return parseMessages(new FileInputStream(file));
        }
@@ -58,13 +57,13 @@ public class HexDumpBGPFileParser {
                }
        }
 
-       public static List<byte[]> parseMessages(String content) {
-               content = clearWhiteSpaceToUpper(content);
+       public static List<byte[]> parseMessages(final String c) {
+               final String content = clearWhiteSpaceToUpper(c);
                // search for 16 FFs
 
                final List<byte[]> messages = Lists.newLinkedList();
                int idx = 0;
-               while ((idx = content.indexOf(ff_16, idx)) > -1) {
+               while ((idx = content.indexOf(FF_16, idx)) > -1) {
                        // next 2 bytes are length
                        final int lengthIdx = idx + 16 * 2;
                        final int messageIdx = lengthIdx + 4;
index 83e4c921802a64b8fc39599bdeeffee2cc44ed78..0ab9bab3ddec8004ab02ecf64edb95a730bbe7ad 100644 (file)
@@ -51,23 +51,23 @@ public final class Ipv4Util {
        }
 
        public static byte[] bytesForPrefix(final Ipv4Prefix prefix) {
-               String p = prefix.getValue();
+               final String p = prefix.getValue();
                final int sep = p.indexOf("/");
                try {
-                       byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
+                       final byte[] bytes = Inet4Address.getByName(p.substring(0, sep)).getAddress();
                        return Bytes.concat(bytes, new byte[] { Byte.valueOf(p.substring(sep + 1, p.length() - 1)) });
-               } catch (UnknownHostException e) {
+               } catch (final UnknownHostException e) {
                        throw new IllegalArgumentException(e.getMessage());
                }
        }
 
        public static Ipv4Prefix prefixForBytes(final byte[] bytes, final int length) {
                Preconditions.checkArgument(length <= bytes.length * 8);
-               byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
+               final byte[] tmp = Arrays.copyOfRange(bytes, 0, 4);
                InetAddress a = null;
                try {
                        a = InetAddress.getByAddress(tmp);
-               } catch (UnknownHostException e) {
+               } catch (final UnknownHostException e) {
                        throw new IllegalArgumentException(e.getMessage());
                }
                return new Ipv4Prefix(InetAddresses.toAddrString(a) + "/" + length);