Merge "BUG-113: introduce Activator and use it"
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 14 Oct 2013 19:18:26 +0000 (19:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 14 Oct 2013 19:18:26 +0000 (19:18 +0000)
37 files changed:
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/ActivatorImpl.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SimpleAddressFamilyRegistry.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SimpleBGPMessageFactory.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SimpleSubsequentAddressFamilyRegistry.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SingletonProviderContext.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/MultiProtocolCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/SimpleCapabilityRegistry.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/SimpleParameterRegistry.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AS4AggregatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AS4PathAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AggregatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AtomicAggregateAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv4NlriParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/Ipv6NlriParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LinkstateNlriParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/LocalPreferenceAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MPReachAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MPUnreachAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/MultiExitDiscriminatorAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/NextHopAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/SimpleAttributeRegistry.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/SimpleNlriRegistry.java
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/PathAttributeParserTest.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderActivator.java [new file with mode: 0644]
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderContext.java [new file with mode: 0644]

diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/ActivatorImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/ActivatorImpl.java
new file mode 100644 (file)
index 0000000..ea81712
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.protocol.bgp.linkstate.LinkstateAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4AggregatorAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4PathAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.LinkstateNlriParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscriminatorAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ProviderActivator;
+import org.opendaylight.protocol.bgp.parser.spi.ProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+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.Keepalive;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
+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.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4Bytes;
+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.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.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class ActivatorImpl implements ProviderActivator {
+       private static final Logger logger = LoggerFactory.getLogger(ActivatorImpl.class);
+       private List<AutoCloseable> registrations;
+
+       @Override
+       public synchronized void start(final ProviderContext context) {
+               Preconditions.checkState(registrations == null);
+               final List<AutoCloseable> regs = new ArrayList<>();
+
+               final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
+               regs.add(afiReg.registerAddressFamily(Ipv4AddressFamily.class, 1));
+               regs.add(afiReg.registerAddressFamily(Ipv6AddressFamily.class, 2));
+               regs.add(afiReg.registerAddressFamily(LinkstateAddressFamily.class, 16388));
+
+               final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
+               regs.add(safiReg.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
+               regs.add(safiReg.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, 71));
+               regs.add(safiReg.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
+
+               final NlriRegistry nlriReg = context.getNlriRegistry();
+               regs.add(nlriReg.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
+                               new Ipv4NlriParser()));
+               regs.add(nlriReg.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
+                               new Ipv6NlriParser()));
+               regs.add(nlriReg.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class,
+                               new LinkstateNlriParser(false)));
+               regs.add(nlriReg.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class,
+                               new LinkstateNlriParser(true)));
+
+               final AttributeRegistry attrReg = context.getAttributeRegistry();
+               regs.add(attrReg.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE,
+                               new MultiExitDiscriminatorAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(CommunitiesAttributeParser.TYPE, new CommunitiesAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(OriginatorIdAttributeParser.TYPE, new OriginatorIdAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(ClusterIdAttributeParser.TYPE, new ClusterIdAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(nlriReg)));
+               regs.add(attrReg.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(nlriReg)));
+               regs.add(attrReg.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, new ExtendedCommunitiesAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
+               regs.add(attrReg.registerAttributeParser(LinkstateAttributeParser.TYPE, new LinkstateAttributeParser()));
+
+               final CapabilityRegistry capReg = context.getCapabilityRegistry();
+               final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
+               regs.add(capReg.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
+               regs.add(capReg.registerCapabilitySerializer(CMultiprotocol.class, multi));
+
+               final As4CapabilityHandler as4 = new As4CapabilityHandler();
+               regs.add(capReg.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
+               regs.add(capReg.registerCapabilitySerializer(CAs4Bytes.class, as4));
+
+               final ParameterRegistry paramReg = context.getParameterRegistry();
+               final CapabilityParameterParser cpp = new CapabilityParameterParser(capReg);
+               regs.add(paramReg.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
+               regs.add(paramReg.registerParameterSerializer(BgpParameters.class, cpp));
+
+               final MessageRegistry msgReg = context.getMessageRegistry();
+               final BGPOpenMessageParser omp = new BGPOpenMessageParser(paramReg);
+               regs.add(msgReg.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
+               regs.add(msgReg.registerMessageSerializer(Open.class, omp));
+
+               final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
+               regs.add(msgReg.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
+               // Serialization of Update message is not supported
+               // regs.add(msgReg.registerMessageSerializer(Update.class, ump));
+
+               final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
+               regs.add(msgReg.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
+               regs.add(msgReg.registerMessageSerializer(Notify.class, nmp));
+
+               final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
+               regs.add(msgReg.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
+               regs.add(msgReg.registerMessageSerializer(Keepalive.class, kamp));
+
+               registrations = regs;
+       }
+
+       @Override
+       public synchronized void stop() {
+               Preconditions.checkState(registrations != null);
+
+               for (AutoCloseable r : registrations) {
+                       try {
+                               r.close();
+                       } catch (Exception e) {
+                               logger.warn("Failed to close registration", e);
+                       }
+               }
+
+               registrations = null;
+       }
+}
index 09cd971551bf79168435fb5bdd08a18a0dd354ea..c7b5601f4888ec43c8fb835b0c1cae64f7f91ef9 100644 (file)
@@ -8,26 +8,13 @@
 package org.opendaylight.protocol.bgp.parser.impl;
 
 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
-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.types.rev130919.AddressFamily;
-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 com.google.common.base.Preconditions;
 
 public final class SimpleAddressFamilyRegistry implements AddressFamilyRegistry {
        private static final class Holder {
-               private static final AddressFamilyRegistry INSTANCE;
-
-               static {
-                       final AddressFamilyRegistry reg = new SimpleAddressFamilyRegistry();
-
-                       reg.registerAddressFamily(Ipv4AddressFamily.class, 1);
-                       reg.registerAddressFamily(Ipv6AddressFamily.class, 2);
-                       reg.registerAddressFamily(LinkstateAddressFamily.class, 16388);
-
-                       INSTANCE = reg;
-               }
+               private static final AddressFamilyRegistry INSTANCE = new SimpleAddressFamilyRegistry();
        }
 
        private final SimpleFamilyRegistry<AddressFamily, Integer> registry = new SimpleFamilyRegistry<>();
index 6a49e33eb3f0b2811445b0174aa44168cc6ed96f..7aaf328abe351c9c049f6368496156fdd351ed7a 100644 (file)
@@ -8,16 +8,9 @@
 package org.opendaylight.protocol.bgp.parser.impl;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
@@ -26,18 +19,15 @@ public final class SimpleBGPMessageFactory extends AbstractMessageRegistry {
                private static final SimpleBGPMessageFactory INSTANCE;
 
                static {
-                       final SimpleBGPMessageFactory reg = new SimpleBGPMessageFactory();
+                       final SimpleBGPMessageFactory f = new SimpleBGPMessageFactory();
 
-                       reg.registerMessageParser(BGPOpenMessageParser.TYPE, BGPOpenMessageParser.PARSER);
-                       reg.registerMessageSerializer(Open.class, BGPOpenMessageParser.SERIALIZER);
-                       reg.registerMessageParser(BGPUpdateMessageParser.TYPE, BGPUpdateMessageParser.PARSER);
-                       // Serialization of Update message is not supported
-                       reg.registerMessageParser(BGPNotificationMessageParser.TYPE, BGPNotificationMessageParser.PARSER);
-                       reg.registerMessageSerializer(Notify.class, BGPNotificationMessageParser.SERIALIZER);
-                       reg.registerMessageParser(BGPKeepAliveMessageParser.TYPE, BGPKeepAliveMessageParser.PARSER);
-                       reg.registerMessageSerializer(Keepalive.class, BGPKeepAliveMessageParser.SERIALIZER);
-
-                       INSTANCE = reg;
+                       // Wrong order, but needed for circular dep.
+                       INSTANCE = f;
+                       try {
+                               new ActivatorImpl().start(SingletonProviderContext.getInstance());
+                       } catch (Exception e) {
+                               throw new ExceptionInInitializerError(e);
+                       }
                }
        }
 
index 949f83809134e133e05b225d45fad56324b7d881..df212da5e089897fc21bb7dd1867a08951be57e0 100644 (file)
@@ -8,26 +8,14 @@
 package org.opendaylight.protocol.bgp.parser.impl;
 
 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
 import com.google.common.base.Preconditions;
 
 public final class SimpleSubsequentAddressFamilyRegistry implements SubsequentAddressFamilyRegistry {
        private static final class Holder {
-               private static final SubsequentAddressFamilyRegistry INSTANCE;
-
-               static {
-                       final SimpleSubsequentAddressFamilyRegistry reg = new SimpleSubsequentAddressFamilyRegistry();
-
-                       reg.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1);
-                       reg.registerSubsequentAddressFamily(LinkstateSubsequentAddressFamily.class, 71);
-                       reg.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128);
-
-                       INSTANCE = reg;
-               }
+               private static final SubsequentAddressFamilyRegistry INSTANCE =
+                               new SimpleSubsequentAddressFamilyRegistry();
        }
 
        private final SimpleFamilyRegistry<SubsequentAddressFamily, Integer> registry = new SimpleFamilyRegistry<>();
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SingletonProviderContext.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/SingletonProviderContext.java
new file mode 100644 (file)
index 0000000..5d8b5b8
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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 org.opendaylight.protocol.bgp.parser.impl.message.open.SimpleCapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.impl.message.open.SimpleParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleAttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleNlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+
+public final class SingletonProviderContext implements ProviderContext {
+       private static final class Holder {
+               private static final ProviderContext INSTANCE = new SingletonProviderContext();
+       }
+
+       private SingletonProviderContext() {
+
+       }
+
+       public static ProviderContext getInstance() {
+               return Holder.INSTANCE;
+       }
+
+       @Override
+       public AddressFamilyRegistry getAddressFamilyRegistry() {
+               return SimpleAddressFamilyRegistry.getInstance();
+       }
+
+       @Override
+       public AttributeRegistry getAttributeRegistry() {
+               return SimpleAttributeRegistry.getInstance();
+       }
+
+       @Override
+       public CapabilityRegistry getCapabilityRegistry() {
+               return SimpleCapabilityRegistry.getInstance();
+       }
+
+       @Override
+       public MessageRegistry getMessageRegistry() {
+               return SimpleBGPMessageFactory.getInstance();
+       }
+
+       @Override
+       public NlriRegistry getNlriRegistry() {
+               return SimpleNlriRegistry.getInstance();
+       }
+
+       @Override
+       public ParameterRegistry getParameterRegistry() {
+               return SimpleParameterRegistry.getInstance();
+       }
+
+       @Override
+       public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+               return SimpleSubsequentAddressFamilyRegistry.getInstance();
+       }
+}
index 94220ec9089dc11cb6c63c29099b3bf153f421b9..efc9adc4da4248e4c4aca07a5b688b313e0c4930 100644 (file)
@@ -12,23 +12,10 @@ import com.google.common.base.Preconditions;
 
 public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
        public static final int TYPE = 4;
-       public static final MessageParser PARSER;
-       public static final MessageSerializer SERIALIZER;
 
        private static final Keepalive msg = new KeepaliveBuilder().build();
        private static final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
 
-
-       static {
-               final BGPKeepAliveMessageParser p = new BGPKeepAliveMessageParser();
-               PARSER = p;
-               SERIALIZER = p;
-       }
-
-       private BGPKeepAliveMessageParser() {
-
-       }
-
        @Override
        public Keepalive parseMessageBody(final byte[] body, final int messageLength) throws BGPDocumentedException {
                if (body.length != 0) {
index e5bd8dc3d93cf10b8f376b3b74eb256098e1db76..123c4e060241a94ebec33dfdf5f63043dd3578b8 100644 (file)
@@ -28,23 +28,11 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public final class BGPNotificationMessageParser implements MessageParser, MessageSerializer {
        public static final int TYPE = 3;
-       public static final MessageParser PARSER;
-       public static final MessageSerializer SERIALIZER;
-
-       static {
-               final BGPNotificationMessageParser p = new BGPNotificationMessageParser();
-               PARSER = p;
-               SERIALIZER = p;
-       }
 
        private static final Logger logger = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
 
        private static final int ERROR_SIZE = 2; // bytes
 
-       private BGPNotificationMessageParser() {
-
-       }
-
        /**
         * Serializes BGP Notification message.
         * 
index a94c3cf746f09ac72128fd7f48eca37ed291c78e..d9218eff1c7c1ced130733b2f5d00bcde2337c8b 100644 (file)
@@ -15,7 +15,6 @@ import java.util.Map.Entry;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.message.open.SimpleParameterRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
@@ -41,14 +40,6 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public final class BGPOpenMessageParser implements MessageParser, MessageSerializer {
        public static final int TYPE = 1;
-       public static final MessageParser PARSER;
-       public static final MessageSerializer SERIALIZER;
-
-       static {
-               final BGPOpenMessageParser p = new BGPOpenMessageParser(SimpleParameterRegistry.getInstance());
-               PARSER = p;
-               SERIALIZER = p;
-       }
 
        private static final Logger logger = LoggerFactory.getLogger(BGPOpenMessageParser.class);
 
@@ -64,7 +55,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
        private final ParameterRegistry reg;
 
-       private BGPOpenMessageParser(final ParameterRegistry reg) {
+       public BGPOpenMessageParser(final ParameterRegistry reg) {
                this.reg = Preconditions.checkNotNull(reg);
        }
 
index a995ca36f69e635a77124554be1f5dae9f27b402..bc2f5f324f6ce370fa5014e57546263cb650052f 100644 (file)
@@ -14,7 +14,6 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleAttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
 import org.opendaylight.protocol.concepts.Ipv4Util;
@@ -38,7 +37,6 @@ import com.google.common.base.Preconditions;
  */
 public class BGPUpdateMessageParser implements MessageParser {
        public static final int TYPE = 2;
-       public static final BGPUpdateMessageParser PARSER = new BGPUpdateMessageParser(SimpleAttributeRegistry.getInstance());
 
        private static Logger logger = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
 
index 660c10063a8b67bb16613c343f95f6784a5f3aab..9b9d431ccc05a0bc5be771d8b20264943a86df83 100644 (file)
@@ -19,8 +19,8 @@ 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.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;
 
-final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
-       static final int CODE = 65;
+public final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
+       public static final int CODE = 65;
 
        @Override
        public CParameters parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
index 42957226e0cbd54696eba48b487191cdc381b4f7..8d218d3afad737f1e26d6ba1bd172113103f60ae 100644 (file)
@@ -25,8 +25,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 
-final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
-       static final int CODE = 1;
+public final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
+       public static final int CODE = 1;
 
        private static final int AFI_SIZE = 2; // bytes
        private static final int SAFI_SIZE = 1; // bytes
@@ -34,7 +34,7 @@ final class MultiProtocolCapabilityHandler implements CapabilityParser, Capabili
        private final AddressFamilyRegistry afiReg;
        private final SubsequentAddressFamilyRegistry safiReg;
 
-       MultiProtocolCapabilityHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
+       public MultiProtocolCapabilityHandler(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
                this.afiReg = Preconditions.checkNotNull(afiReg);
                this.safiReg = Preconditions.checkNotNull(safiReg);
        }
index 85c8055291655a952903593c8bad820e21ba8dba..fa4900dd4c27ed54e6575616e7babc27123e770d 100644 (file)
@@ -9,38 +9,18 @@ package org.opendaylight.protocol.bgp.parser.impl.message.open;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.SimpleAddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.impl.SimpleSubsequentAddressFamilyRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
 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.message.rev130918.open.bgp.parameters.c.parameters.CAs4Bytes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 import com.google.common.base.Preconditions;
 
 public final class SimpleCapabilityRegistry implements CapabilityRegistry {
        private static final class Holder {
-               private static final CapabilityRegistry INSTANCE;
-
-               static {
-                       final CapabilityRegistry reg = new SimpleCapabilityRegistry();
-
-                       final MultiProtocolCapabilityHandler multi =
-                                       new MultiProtocolCapabilityHandler(SimpleAddressFamilyRegistry.getInstance(),
-                                                       SimpleSubsequentAddressFamilyRegistry.getInstance());
-                       reg.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi);
-                       reg.registerCapabilitySerializer(CMultiprotocol.class, multi);
-
-                       final As4CapabilityHandler as4 = new As4CapabilityHandler();
-                       reg.registerCapabilityParser(As4CapabilityHandler.CODE, as4);
-                       reg.registerCapabilitySerializer(CAs4Bytes.class, as4);
-
-                       INSTANCE = reg;
-               }
+               private static final CapabilityRegistry INSTANCE = new SimpleCapabilityRegistry();
        }
 
        private final HandlerRegistry<DataContainer, CapabilityParser, CapabilitySerializer> handlers = new HandlerRegistry<>();
index 33a749ae539720f33a72ed863e1b90b92e0ec56e..3f1e49a81867b614198c930e5f9fc113b48755e1 100644 (file)
@@ -20,17 +20,7 @@ import com.google.common.base.Preconditions;
 
 public final class SimpleParameterRegistry implements ParameterRegistry {
        private static final class Holder {
-               private static final ParameterRegistry INSTANCE;
-
-               static {
-                       final ParameterRegistry reg = new SimpleParameterRegistry();
-
-                       final CapabilityParameterParser cpp = new CapabilityParameterParser(SimpleCapabilityRegistry.getInstance());
-                       reg.registerParameterParser(CapabilityParameterParser.TYPE, cpp);
-                       reg.registerParameterSerializer(BgpParameters.class, cpp);
-
-                       INSTANCE = reg;
-               }
+               private static final ParameterRegistry INSTANCE = new SimpleParameterRegistry();
        }
 
        private final HandlerRegistry<DataContainer, ParameterParser, ParameterSerializer> handlers = new HandlerRegistry<>();
index c768b49e20f0738172fe66864c350e78f3f7a0c0..a9039c441ecce6f8a5346d8bece15c7d0cbdcce3 100644 (file)
@@ -1,10 +1,17 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class AS4AggregatorAttributeParser implements AttributeParser {
-       static final int TYPE = 17;
+public final class AS4AggregatorAttributeParser implements AttributeParser {
+       public static final int TYPE = 17;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index aeebf2459dc1f493add02aa592628ade3c522a36..3e8c622dd06ed4567db834b6589419729f3209a7 100644 (file)
@@ -1,10 +1,17 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class AS4PathAttributeParser implements AttributeParser {
-       static final int TYPE = 18;
+public final class AS4PathAttributeParser implements AttributeParser {
+       public static final int TYPE = 18;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 92dda87efd1e6d72b5961891a4fb92966ef715b0..7279c6ed310bacba2f3a4e15ba5a4728c970dc37 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
@@ -9,8 +16,8 @@ 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.path.attributes.AggregatorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class AggregatorAttributeParser implements AttributeParser {
-       static final int TYPE = 7;
+public final class AggregatorAttributeParser implements AttributeParser {
+       public static final int TYPE = 7;
 
        /**
         * Parse AGGREGATOR from bytes
index e4f8037167681e7e5b1fa02f2c1e1a2bb668e790..538b3fe90c1f227083d981fa96132e8325beee3c 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import java.util.List;
@@ -21,8 +28,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 
-final class AsPathAttributeParser implements AttributeParser {
-       static final int TYPE = 2;
+public final class AsPathAttributeParser implements AttributeParser {
+       public static final int TYPE = 2;
 
        /**
         * Parses AS_PATH from bytes.
index 67f67071fbf508145b0fece7fea2c622c5aba38b..2666c728e9e4be54a510b3745e63fd7e289a8555 100644 (file)
@@ -1,11 +1,18 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.AtomicAggregateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class AtomicAggregateAttributeParser implements AttributeParser {
-       static final int TYPE = 6;
+public final class AtomicAggregateAttributeParser implements AttributeParser {
+       public static final int TYPE = 6;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 62e3baa39db409dc3cf211e82a3782fa121d22bc..0e568b19d11f471fba382a9b8cce8e0481e625aa 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import java.util.List;
@@ -9,8 +16,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 
 import com.google.common.collect.Lists;
 
-final class ClusterIdAttributeParser implements AttributeParser {
-       static final int TYPE = 10;
+public final class ClusterIdAttributeParser implements AttributeParser {
+       public static final int TYPE = 10;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 3ed49eb3d220de6899ef9464cc9e5e891eb70059..96491a3e02514a4f04067aed723275598631232e 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import java.util.List;
@@ -10,8 +17,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 
 import com.google.common.collect.Lists;
 
-final class CommunitiesAttributeParser implements AttributeParser {
-       static final int TYPE = 8;
+public final class CommunitiesAttributeParser implements AttributeParser {
+       public static final int TYPE = 8;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
index e928c5c6a3f84540a6e6ed60dca2d527b5c1ba94..c094ed021ec8ea989d8510d2bd369b9c4156009f 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import java.util.List;
@@ -10,8 +17,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 
 import com.google.common.collect.Lists;
 
-final class ExtendedCommunitiesAttributeParser implements AttributeParser {
-       static final int TYPE = 16;
+public final class ExtendedCommunitiesAttributeParser implements AttributeParser {
+       public static final int TYPE = 16;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
index aa9e8cfbb88c21aa3d8e2801600a6a4f5bde2e68..9b3bf66fffca1af77209b00157e49a15e00fa761 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4Builder;
 
-final class Ipv4NlriParser extends IpNlriParser {
+public final class Ipv4NlriParser extends IpNlriParser {
        @Override
        protected DestinationIpv4 parseNlri(final byte[] nlri) {
                return new DestinationIpv4Builder().setIpv4Prefixes(Ipv4Util.prefixListForBytes(nlri)).build();
index 9fa6697f2b3aa4b9e018eff4278c405f2ccda0d8..e3451db87d94fd0c7dbb2b8395f748e01fd5164d 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
 
-final class Ipv6NlriParser extends IpNlriParser {
+public final class Ipv6NlriParser extends IpNlriParser {
        @Override
        protected DestinationIpv6 parseNlri(final byte[] nlri) {
                return new DestinationIpv6Builder().setIpv6Prefixes(Ipv6Util.prefixListForBytes(nlri)).build();
index e9fc35139cf85067b6a685f087c68c122706f524..8ed35445d4b40ca74f85c9665559f69e49501f64 100644 (file)
@@ -62,7 +62,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.primitives.UnsignedBytes;
 
-final class LinkstateNlriParser implements NlriParser {
+public final class LinkstateNlriParser implements NlriParser {
        private static final Logger logger = LoggerFactory.getLogger(LinkstateNlriParser.class);
        private static final int ROUTE_DISTINGUISHER_LENGTH = 8;
        private static final int PROTOCOL_ID_LENGTH = 1;
index fe9454f0706f7700f43878aeece0f503db7be78f..c66ff1adf07b151d8a2e63f73f76d1c13c9b6d04 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
@@ -5,8 +12,8 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.LocalPrefBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class LocalPreferenceAttributeParser implements AttributeParser {
-       static final int TYPE = 5;
+public final class LocalPreferenceAttributeParser implements AttributeParser {
+       public static final int TYPE = 5;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 602a22a405412f72556ddf64aac31c95be2466a8..a3dad945d521e9edecc8785d94c24a92248a5d07 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -11,12 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 
 import com.google.common.base.Preconditions;
 
-final class MPReachAttributeParser implements AttributeParser {
-       static final int TYPE = 14;
+public final class MPReachAttributeParser implements AttributeParser {
+       public static final int TYPE = 14;
 
        private final NlriRegistry reg;
 
-       MPReachAttributeParser(final NlriRegistry reg) {
+       public MPReachAttributeParser(final NlriRegistry reg) {
                this.reg = Preconditions.checkNotNull(reg);
        }
 
index ae87110d64f1fd8ef2695a17f9ec1d59f658492c..631bd87ea09f95e3b465e3391f317659d94bfb05 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -11,12 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 
 import com.google.common.base.Preconditions;
 
-final class MPUnreachAttributeParser implements AttributeParser {
-       static final int TYPE = 15;
+public final class MPUnreachAttributeParser implements AttributeParser {
+       public static final int TYPE = 15;
 
        private final NlriRegistry reg;
 
-       MPUnreachAttributeParser(final NlriRegistry reg) {
+       public MPUnreachAttributeParser(final NlriRegistry reg) {
                this.reg = Preconditions.checkNotNull(reg);
        }
 
index 8dd9bc6da17a7d2666b327ef721b71c6bd937000..5a409ba34b69ecf5e3e042eeb056bb8c57b1ea20 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
@@ -5,8 +12,8 @@ import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.MultiExitDiscBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class MultiExitDiscriminatorAttributeParser implements AttributeParser {
-       static final int TYPE = 4;
+public final class MultiExitDiscriminatorAttributeParser implements AttributeParser {
+       public static final int TYPE = 4;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index d97870f55dbbdbbcbade62523a368e4d3cc75f65..8bda1b88b36919f161c77dd16ac39fe0b27712ea 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
@@ -6,8 +13,8 @@ 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.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
 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;
 
-final class NextHopAttributeParser implements AttributeParser {
-       static final int TYPE = 3;
+public final class NextHopAttributeParser implements AttributeParser {
+       public static final int TYPE = 3;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 9d478a8e439eb4a2e273354402ac7689c4eb1c5f..7fcbb63e407f96cdeacf72222be2f43ae443392d 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
@@ -9,8 +16,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 
 import com.google.common.primitives.UnsignedBytes;
 
-final class OriginAttributeParser implements AttributeParser {
-       static final int TYPE = 1;
+public final class OriginAttributeParser implements AttributeParser {
+       public static final int TYPE = 1;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
index 54fe62ed356a0c50733d39d60a64b2146d347056..d031ce6aa44cf8029b5a52015281e45e6d9d73df 100644 (file)
@@ -1,10 +1,17 @@
+/*
+ * 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.message.update;
 
 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
 
-final class OriginatorIdAttributeParser implements AttributeParser {
-       static final int TYPE = 9;
+public final class OriginatorIdAttributeParser implements AttributeParser {
+       public static final int TYPE = 9;
 
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
index 851a6e9c8b9654515e50d78647158e44f77de223..9b8bb50f17eb69a2a2d824a7702e0d6003616ac1 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.bgp.parser.impl.message.update;
 
-import org.opendaylight.protocol.bgp.linkstate.LinkstateAttributeParser;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
@@ -26,30 +25,7 @@ import com.google.common.primitives.UnsignedBytes;
 
 public final class SimpleAttributeRegistry implements AttributeRegistry {
        private static final class Holder {
-               private static final AttributeRegistry INSTANCE;
-
-               static {
-                       final AttributeRegistry reg = new SimpleAttributeRegistry();
-
-                       reg.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser());
-                       reg.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser());
-                       reg.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser());
-                       reg.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser());
-                       reg.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser());
-                       reg.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser());
-                       reg.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser());
-                       reg.registerAttributeParser(CommunitiesAttributeParser.TYPE, new CommunitiesAttributeParser());
-                       reg.registerAttributeParser(OriginatorIdAttributeParser.TYPE, new OriginatorIdAttributeParser());
-                       reg.registerAttributeParser(ClusterIdAttributeParser.TYPE, new ClusterIdAttributeParser());
-                       reg.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(SimpleNlriRegistry.getInstance()));
-                       reg.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(SimpleNlriRegistry.getInstance()));
-                       reg.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, new ExtendedCommunitiesAttributeParser());
-                       reg.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser());
-                       reg.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser());
-                       reg.registerAttributeParser(LinkstateAttributeParser.TYPE, new LinkstateAttributeParser());
-
-                       INSTANCE = reg;
-               }
+               private static final AttributeRegistry INSTANCE = new SimpleAttributeRegistry();
        }
 
        private SimpleAttributeRegistry() {
index 2d8012c3e72f4342e052652ac3af2a0729f12c8b..380d38afda1663d22c5e0b2f3748a775583db554 100644 (file)
@@ -20,42 +20,22 @@ import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
 import org.opendaylight.protocol.concepts.AbstractRegistration;
 import org.opendaylight.protocol.util.ByteArray;
-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.multiprotocol.rev130918.BgpTableType;
 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.MpUnreachNlri;
 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.types.rev130919.AddressFamily;
-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.MplsLabeledVpnSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 
 public final class SimpleNlriRegistry implements NlriRegistry {
        private static final class Holder {
-               private static final NlriRegistry INSTANCE;
-
-               static {
-                       final NlriRegistry reg = new SimpleNlriRegistry(SimpleAddressFamilyRegistry.getInstance(),
-                                       SimpleSubsequentAddressFamilyRegistry.getInstance());
-
-                       final NlriParser ipv4 = new Ipv4NlriParser();
-                       reg.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, ipv4);
-
-                       final NlriParser ipv6 = new Ipv6NlriParser();
-                       reg.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, ipv6);
-
-                       reg.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateNlriParser(false));
-                       reg.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class, new LinkstateNlriParser(true));
-
-                       INSTANCE = reg;
-               }
+               private static final NlriRegistry INSTANCE =
+                               new SimpleNlriRegistry(SimpleAddressFamilyRegistry.getInstance(),
+                                               SimpleSubsequentAddressFamilyRegistry.getInstance());
        }
 
        private final ConcurrentMap<BgpTableType, NlriParser> handlers = new ConcurrentHashMap<>();
@@ -126,7 +106,6 @@ public final class SimpleNlriRegistry implements NlriRegistry {
                final NlriParser parser = handlers.get(createKey(builder.getAfi(), builder.getSafi()));
                parser.parseNlri(ByteArray.subByte(bytes, 3, bytes.length - 3), builder);
 
-               //              builder.setWithdrawnRoutes(routes);
                return builder.build();
        }
 
index 90d742f7d60d492edf7ce8031d081eac3cc24f04..44e070f7644c9e7258651a5fae3c67c141099f02 100644 (file)
@@ -25,6 +25,8 @@ import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleAttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
 import org.opendaylight.protocol.concepts.IGPMetric;
 import org.opendaylight.protocol.concepts.IPv4;
@@ -85,10 +87,14 @@ public class BGPParserTest {
 
        private static int MAX_SIZE = 300;
 
-       private final BGPUpdateMessageParser updateParser = BGPUpdateMessageParser.PARSER;
+       private static MessageRegistry reg;
+
+       private static BGPUpdateMessageParser updateParser;
 
        @BeforeClass
        public static void setUp() throws Exception {
+               reg = SimpleBGPMessageFactory.getInstance();
+               updateParser = new BGPUpdateMessageParser(SimpleAttributeRegistry.getInstance());
 
                for (int i = 1; i <= COUNTER; i++) {
                        final String name = "/up" + i + ".bin";
index 78549254f8252095c05931ff57fa8f2174af6b44..206e4492a6d58927bfe0bfd177a939efaca44553 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
@@ -21,6 +22,12 @@ import org.opendaylight.protocol.bgp.parser.impl.message.update.SimpleAttributeR
  */
 public class PathAttributeParserTest {
 
+       @Before
+       public void setUp() {
+               // Activates everything
+               SimpleBGPMessageFactory.getInstance();
+       }
+
        @Test
        public void testOriginParser() {
                try {
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderActivator.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderActivator.java
new file mode 100644 (file)
index 0000000..6b0912c
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * 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.spi;
+
+public interface ProviderActivator {
+       public void start(ProviderContext context);
+       public void stop();
+}
\ No newline at end of file
diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderContext.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/ProviderContext.java
new file mode 100644 (file)
index 0000000..4df2143
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.spi;
+
+public interface ProviderContext {
+       public AddressFamilyRegistry getAddressFamilyRegistry();
+       public AttributeRegistry getAttributeRegistry();
+       public CapabilityRegistry getCapabilityRegistry();
+       public MessageRegistry getMessageRegistry();
+       public NlriRegistry getNlriRegistry();
+       public ParameterRegistry getParameterRegistry();
+       public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry();
+}