--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.parser.spi;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Serve as an entry gate for providers of {@link PeerSpecificParserConstraint} services.
+ *
+ */
+public interface PeerSpecificParserConstraintProvider extends PeerSpecificParserConstraint {
+
+ /**
+ * Register new {@link PeerConstraint} service.
+ * @param classType Class type of the service to be added.
+ * @param peerConstraint Peer constraint service to be added.
+ * @return True if service was added, false if not (such service is already registered).
+ */
+ <T extends PeerConstraint> boolean addPeerConstraint(@Nonnull Class<T> classType, @Nonnull T peerConstraint);
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.parser.spi.pojo;
+
+import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.protocol.bgp.parser.spi.PeerConstraint;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraintProvider;
+
+public class PeerSpecificParserConstraintImpl implements PeerSpecificParserConstraintProvider {
+
+ @GuardedBy("this")
+ private final Map<Class<? extends PeerConstraint>, PeerConstraint> constraints = new HashMap<>();
+
+ @Override
+ public synchronized <T extends PeerConstraint> Optional<T> getPeerConstraint(final Class<T> peerConstraintType) {
+ return (Optional<T>) Optional.ofNullable(this.constraints.get(peerConstraintType));
+ }
+
+ @Override
+ public synchronized <T extends PeerConstraint> boolean addPeerConstraint(final Class<T> classType, final T peerConstraint) {
+ Preconditions.checkNotNull(classType);
+ Preconditions.checkNotNull(peerConstraint);
+ final PeerConstraint previous = this.constraints.putIfAbsent(classType, peerConstraint);
+ return previous == null;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.parser.spi.pojo;
+
+import java.util.Collections;
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraintProvider;
+
+public class PeerSpecificParserConstraintImplTest {
+
+ private static final MultiPathSupport ADD_PATH_CONSTRAINT = MultiPathSupportImpl.createParserMultiPathSupport(Collections.emptyList());
+
+ private PeerSpecificParserConstraintProvider constraints;
+
+ @Before
+ public void setUp() {
+ this.constraints = new PeerSpecificParserConstraintImpl();
+ }
+
+ @Test
+ public void testProviderSucess() {
+ Assert.assertTrue(this.constraints.addPeerConstraint(MultiPathSupport.class, ADD_PATH_CONSTRAINT));
+ }
+
+ @Test
+ public void testProviderAlreadyPresent() {
+ this.constraints.addPeerConstraint(MultiPathSupport.class, ADD_PATH_CONSTRAINT);
+ Assert.assertFalse(this.constraints.addPeerConstraint(MultiPathSupport.class, ADD_PATH_CONSTRAINT));
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testProviderNullInput() {
+ this.constraints.addPeerConstraint(MultiPathSupport.class, null);
+ }
+
+ @Test
+ public void testGetPeerConstraintSuccess() {
+ this.constraints.addPeerConstraint(MultiPathSupport.class, ADD_PATH_CONSTRAINT);
+ final Optional<MultiPathSupport> peerConstraint = this.constraints.getPeerConstraint(MultiPathSupport.class);
+ Assert.assertTrue(peerConstraint.isPresent());
+ }
+
+ @Test
+ public void testGetPeerConstraintNonExisting() {
+ final Optional<MultiPathSupport> peerConstraint = this.constraints.getPeerConstraint(MultiPathSupport.class);
+ Assert.assertFalse(peerConstraint.isPresent());
+ }
+
+}