BGPCEP-589: BGP Neighbor match 24/69524/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 15 Mar 2018 08:06:48 +0000 (09:06 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Thu, 15 Mar 2018 12:22:09 +0000 (12:22 +0000)
match Peer-Id generated from neighbor address,
it can be used as replacement for generate similar
policy than removed simple-routing-policy.

Change-Id: I347a77cb40c72ff110b5088682f8edd375cecca1
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/openconfig-api/src/main/yang/odl-bgp-default-policy.yang
bgp/openconfig-rp-spi/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/registry/ConditionsRegistryImpl.java
bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/StatementActivator.java
bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/conditions/MatchBgpNeighborSetHandler.java [new file with mode: 0644]
bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java [new file with mode: 0644]
bgp/openconfig-rp-statement/src/test/resources/initial/routing-policy-config.xml

index 9fa1745cd82606436ed05e4fa9f9bcd6a78414d8..b027f997a7a8e305fc1fb65c2c8bd97e21c4e816 100644 (file)
@@ -64,6 +64,37 @@ module odl-bgp-policy {
         }
     }
 
+    grouping bgp-neighbor {
+        leaf neighbor-set {
+          type leafref {
+            path "/rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/rpol:neighbor-set/rpol:neighbor-set-name";
+            require-instance true;
+          }
+          description "References a defined neighbor set";
+        }
+        uses rpol:match-set-options-restricted-group;
+    }
+
+    grouping match-bgp-neighbor-grouping {
+        container match-bgp-neighbor-set {
+            presence
+                "The presence of this container indicates that the routes
+                should match the neighbour address of set referenced";
+
+            description
+                "Match a referenced neighbor set according to the logic
+                defined in the match-set-options-leaf";
+
+            container from-neighbor {
+                uses bgp-neighbor;
+            }
+
+            container to-neighbor {
+                uses bgp-neighbor;
+            }
+        }
+    }
+
     grouping match-originator-id-set-condition-grouping {
         description
             "Match a list of referenced originator-id-set according to the logic
@@ -200,6 +231,11 @@ module odl-bgp-policy {
         }
     }
 
+    augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:conditions/bgppol:bgp-conditions {
+        ext:augment-identifier match-bgp-neighbor-condition;
+        uses match-bgp-neighbor-grouping;
+    }
+
     augment /rpol:routing-policy/rpol:policy-definitions/rpol:policy-definition/rpol:statements/rpol:statement/rpol:conditions/bgppol:bgp-conditions {
         ext:augment-identifier match-role-set-condition;
         uses match-role-set-condition-grouping;
index 4fd46514a2e063fecd93c753ae8504f84661d703..875c5a056840a179dad2020f01b023ce1fc1c300 100644 (file)
@@ -79,10 +79,6 @@ final class ConditionsRegistryImpl {
             final BGPRouteEntryExportParameters routeEntryExportParameters,
             final Attributes attributes,
             final Conditions conditions) {
-      /*  if (!this.genericConditionHandler
-                .matchExportCondition(routeEntryExportParameters, conditions)) {
-            return false;
-        }*/
 
         if (!this.bgpConditionsRegistry
                 .matchExportConditions(entryInfo, routeEntryExportParameters, attributes, conditions)) {
index 9cf14be0ed656e4989520fd9fa3604c9ebf8e514..4c6fb2b9d1363fac84b90a7266878ea750e5ad1e 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetExtCommunityHandler;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.actions.SetOriginatorIdPrependHandler;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchAsPathSetHandler;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchBgpNeighborSetHandler;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchClusterIdSetHandler;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchCommunitySetHandler;
 import org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.conditions.MatchExtCommunitySetHandler;
@@ -33,6 +34,7 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev15100
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetAsPathPrepend;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetCommunity;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.routing.policy.policy.definitions.policy.definition.statements.statement.actions.bgp.actions.SetExtCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchBgpNeighborCondition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchClusterIdSetCondition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchOriginatorIdSetCondition;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchRoleSetCondition;
@@ -49,7 +51,7 @@ public final class StatementActivator extends AbstractBGPStatementProviderActiva
 
     @Override
     protected synchronized List<AutoCloseable> startImpl(final StatementRegistryProvider provider) {
-        final List<AutoCloseable> registration = new ArrayList<>(12);
+        final List<AutoCloseable> registration = new ArrayList<>(13);
         registerActions(provider, registration);
         registerConditions(provider, registration);
         return registration;
@@ -73,6 +75,9 @@ public final class StatementActivator extends AbstractBGPStatementProviderActiva
 
         registration.add(provider.registerBgpConditionsPolicy(MatchCommunitySet.class,
                 new MatchCommunitySetHandler(this.dataBroker)));
+
+        registration.add(provider.registerBgpConditionsAugmentationPolicy(MatchBgpNeighborCondition.class,
+                new MatchBgpNeighborSetHandler(this.dataBroker)));
     }
 
     private void registerActions(final StatementRegistryProvider provider, final List<AutoCloseable> registration) {
diff --git a/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/conditions/MatchBgpNeighborSetHandler.java b/bgp/openconfig-rp-statement/src/main/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/conditions/MatchBgpNeighborSetHandler.java
new file mode 100644 (file)
index 0000000..97fe3ae
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.openconfig.routing.policy.statement.conditions;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.base.Optional;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringUtils;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.policy.condition.BgpConditionsAugmentationPolicy;
+import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.MatchSetOptionsRestrictedType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.generic.defined.sets.NeighborSets;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSet;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.neighbor.set.NeighborSetKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.RoutingPolicy;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.DefinedSets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.BgpNeighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.MatchBgpNeighborCondition;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp._default.policy.rev180109.match.bgp.neighbor.grouping.MatchBgpNeighborSet;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Match a set of Neighbors(ip address) (ANY, INVERT).
+ */
+public final class MatchBgpNeighborSetHandler
+        implements BgpConditionsAugmentationPolicy<MatchBgpNeighborCondition, Void> {
+    private static final InstanceIdentifier<NeighborSets> NEIGHBOR_SET_IID
+            = InstanceIdentifier.create(RoutingPolicy.class)
+            .child(DefinedSets.class)
+            .child(NeighborSets.class);
+    private final DataBroker dataBroker;
+    private final LoadingCache<String, List<PeerId>> peerSets = CacheBuilder.newBuilder()
+            .build(new CacheLoader<String, List<PeerId>>() {
+                @Override
+                public List<PeerId> load(final String key) throws ExecutionException, InterruptedException {
+                    return loadRoleSets(key);
+                }
+            });
+
+    public MatchBgpNeighborSetHandler(final DataBroker dataBroker) {
+        this.dataBroker = requireNonNull(dataBroker);
+    }
+
+    private List<PeerId> loadRoleSets(final String key) throws ExecutionException, InterruptedException {
+        final ReadOnlyTransaction tr = this.dataBroker.newReadOnlyTransaction();
+        final Optional<NeighborSet> result = tr.read(LogicalDatastoreType.CONFIGURATION,
+                NEIGHBOR_SET_IID.child(NeighborSet.class, new NeighborSetKey(key))).get();
+        if (!result.isPresent()) {
+            return Collections.emptyList();
+        }
+        return result.get().getNeighbor().stream()
+                .map(nei -> RouterIds.createPeerId(nei.getAddress()))
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public boolean matchImportCondition(
+            final RouteEntryBaseAttributes routeEntryInfo,
+            final BGPRouteEntryImportParameters importParameters,
+            final Void nonAttributres,
+            final MatchBgpNeighborCondition conditions) {
+        return matchBgpNeighborSetCondition(importParameters.getFromPeerId(), null,
+                conditions.getMatchBgpNeighborSet());
+    }
+
+    @Override
+    public boolean matchExportCondition(
+            final RouteEntryBaseAttributes routeEntryInfo,
+            final BGPRouteEntryExportParameters exportParameters,
+            final Void nonAttributres,
+            final MatchBgpNeighborCondition conditions) {
+        return matchBgpNeighborSetCondition(exportParameters.getFromPeerId(), exportParameters.getToPeerId(),
+                conditions.getMatchBgpNeighborSet());
+    }
+
+    private boolean matchBgpNeighborSetCondition(
+            @Nonnull final PeerId fromPeerId,
+            @Nullable final PeerId toPeerId,
+            final MatchBgpNeighborSet matchBgpNeighborSet) {
+
+        final BgpNeighbor from = matchBgpNeighborSet.getFromNeighbor();
+        Boolean match = null;
+        if (from != null) {
+            match = checkMatch(from.getNeighborSet(), fromPeerId, from.getMatchSetOptions());
+        }
+
+        if (match != null && !match) {
+            return false;
+        }
+
+        final BgpNeighbor to = matchBgpNeighborSet.getToNeighbor();
+        if (to != null) {
+            match = checkMatch(to.getNeighborSet(), toPeerId, to.getMatchSetOptions());
+        }
+
+        return match;
+    }
+
+    private boolean checkMatch(
+            final String neighborSetName,
+            final PeerId peerId,
+            final MatchSetOptionsRestrictedType matchSetOptions) {
+        final List<PeerId> roles = this.peerSets.getUnchecked(StringUtils
+                .substringBetween(neighborSetName, "=\"", "\""));
+
+        final boolean found = roles.contains(peerId);
+        if (MatchSetOptionsRestrictedType.ANY.equals(matchSetOptions)) {
+            return found;
+        }
+        //INVERT
+        return !found;
+    }
+
+    @Override
+    public Void getConditionParameter(final Attributes attributes) {
+        return null;
+    }
+}
diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java
new file mode 100644 (file)
index 0000000..f6b4131
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.openconfig.routing.policy.statement;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
+
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
+
+public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTest {
+    @Mock
+    private BGPRouteEntryExportParameters exportParameters;
+    private List<Statement> basicStatements;
+    private PolicyRIBBaseParametersImpl baseAttributes;
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        this.basicStatements = loadStatement("bgp-neighbor-statements-test");
+        this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
+    }
+
+
+    @Test
+    public void testMatchFromBgpNeighborAny() {
+        Statement statement = this.basicStatements.stream()
+                .filter(st -> st.getName().equals("reject-from-neighbor-test")).findFirst().get();
+        RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
+                new AttributesBuilder().build());
+
+        doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
+
+        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNotNull(result.getAttributes());
+
+
+        doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
+        result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNull(result.getAttributes());
+    }
+
+    @Test
+    public void testMatchFromBgpNeighborInvert() {
+        Statement statement = this.basicStatements.stream()
+                .filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().get();
+        RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
+                new AttributesBuilder().build());
+
+        doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
+
+        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNull(result.getAttributes());
+
+        doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
+        result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNotNull(result.getAttributes());
+    }
+
+    @Test
+    public void testMatchToBgpNeighborAny() {
+        Statement statement = this.basicStatements.stream()
+                .filter(st -> st.getName().equals("reject-to-neighbor-test")).findFirst().get();
+        RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
+                new AttributesBuilder().build());
+
+        doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
+        doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
+
+        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNotNull(result.getAttributes());
+
+
+        doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
+        result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNull(result.getAttributes());
+    }
+
+    @Test
+    public void testMatchToBgpNeighborInvert() {
+        Statement statement = this.basicStatements.stream()
+                .filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().get();
+        RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
+                new AttributesBuilder().build());
+
+        doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
+        doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
+
+        RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNull(result.getAttributes());
+
+        doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
+        result = this.statementRegistry.applyExportStatement(
+                this.baseAttributes,
+                this.exportParameters,
+                attributeContainer,
+                statement);
+        assertNotNull(result.getAttributes());
+    }
+}
index d35acdfd2bd668c42210a0ffe219043014872a80..d4ef5b550d5981c22afb136d066a3403ed8db251 100644 (file)
                 </statement>
             </statements>
         </policy-definition>
+        <policy-definition>
+            <name>bgp-neighbor-statements-test</name>
+            <statements>
+                <statement>
+                    <name>reject-from-neighbor-test</name>
+                    <conditions>
+                        <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy">
+                            <match-bgp-neighbor-set xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy">
+                                <from-neighbor>
+                                    <neighbor-set>
+                                        /rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/neighbor-set[neighbor-set-name="test-bgp-neighbor-set"
+                                    </neighbor-set>
+                                </from-neighbor>
+                            </match-bgp-neighbor-set>
+                        </bgp-conditions>
+                    </conditions>
+                    <actions>
+                        <reject-route/>
+                    </actions>
+                </statement>
+                <statement>
+                    <name>reject-from-neighbor-invert-test</name>
+                    <conditions>
+                        <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy">
+                            <match-bgp-neighbor-set xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy">
+                                <from-neighbor>
+                                    <neighbor-set>
+                                        /rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/neighbor-set[neighbor-set-name="test-bgp-neighbor-set"
+                                    </neighbor-set>
+                                    <match-set-options>INVERT</match-set-options>
+                                </from-neighbor>
+                            </match-bgp-neighbor-set>
+                        </bgp-conditions>
+                    </conditions>
+                    <actions>
+                        <reject-route/>
+                    </actions>
+                </statement>
+                <statement>
+                    <name>reject-to-neighbor-test</name>
+                    <conditions>
+                        <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy">
+                            <match-bgp-neighbor-set xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy">
+                                <to-neighbor>
+                                    <neighbor-set>
+                                        /rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/neighbor-set[neighbor-set-name="test-bgp-neighbor-set"
+                                    </neighbor-set>
+                                </to-neighbor>
+                            </match-bgp-neighbor-set>
+                        </bgp-conditions>
+                    </conditions>
+                    <actions>
+                        <reject-route/>
+                    </actions>
+                </statement>
+                <statement>
+                    <name>reject-to-neighbor-invert-test</name>
+                    <conditions>
+                        <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy">
+                            <match-bgp-neighbor-set xmlns="urn:opendaylight:params:xml:ns:yang:odl:bgp:default:policy">
+                                <to-neighbor>
+                                    <neighbor-set>
+                                        /rpol:routing-policy/rpol:defined-sets/rpol:neighbor-sets/neighbor-set[neighbor-set-name="test-bgp-neighbor-set"
+                                    </neighbor-set>
+                                    <match-set-options>INVERT</match-set-options>
+                                </to-neighbor>
+                            </match-bgp-neighbor-set>
+                        </bgp-conditions>
+                    </conditions>
+                    <actions>
+                        <reject-route/>
+                    </actions>
+                </statement>
+            </statements>
+        </policy-definition>
     </policy-definitions>
     <defined-sets>
         <bgp-defined-sets xmlns="http://openconfig.net/yang/bgp-policy">
                 </prefix>
             </prefix-set>
         </prefix-sets>
+        <neighbor-sets>
+            <neighbor-set>
+                <neighbor-set-name>test-bgp-neighbor-set</neighbor-set-name>
+                <neighbor>
+                    <address>127.0.0.1</address>
+                </neighbor>
+                <neighbor>
+                    <address>127.0.0.2</address>
+                </neighbor>
+            </neighbor-set>
+        </neighbor-sets>
     </defined-sets>
 </routing-policy>
\ No newline at end of file