2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.doReturn;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
15 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
21 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
27 public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTest {
29 private BGPRouteEntryExportParameters exportParameters;
30 private List<Statement> basicStatements;
31 private PolicyRIBBaseParametersImpl baseAttributes;
35 public void setUp() throws Exception {
37 basicStatements = loadStatement("bgp-neighbor-statements-test");
38 baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
42 public void testMatchFromBgpNeighborAny() {
43 Statement statement = basicStatements.stream()
44 .filter(st -> st.getName().equals("reject-from-neighbor-test")).findFirst().orElseThrow();
45 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
46 new AttributesBuilder().build());
48 doReturn(new PeerId("bgp://42.42.42.42")).when(exportParameters).getFromPeerId();
50 RouteAttributeContainer result = statementRegistry.applyExportStatement(
51 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
52 assertNotNull(result.getAttributes());
55 doReturn(new PeerId("bgp://127.0.0.1")).when(exportParameters).getFromPeerId();
56 result = statementRegistry.applyExportStatement(
57 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
58 assertNull(result.getAttributes());
62 public void testMatchFromBgpNeighborInvert() {
63 Statement statement = basicStatements.stream()
64 .filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().orElseThrow();
65 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
66 new AttributesBuilder().build());
68 doReturn(new PeerId("bgp://42.42.42.42")).when(exportParameters).getFromPeerId();
70 RouteAttributeContainer result = statementRegistry.applyExportStatement(
71 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
72 assertNull(result.getAttributes());
74 doReturn(new PeerId("bgp://127.0.0.1")).when(exportParameters).getFromPeerId();
75 result = statementRegistry.applyExportStatement(
76 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
77 assertNotNull(result.getAttributes());
81 public void testMatchToBgpNeighborAny() {
82 Statement statement = basicStatements.stream()
83 .filter(st -> st.getName().equals("reject-to-neighbor-test")).findFirst().orElseThrow();
84 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
85 new AttributesBuilder().build());
87 doReturn(new PeerId("bgp://127.0.0.2")).when(exportParameters).getFromPeerId();
88 doReturn(new PeerId("bgp://42.42.42.42")).when(exportParameters).getToPeerId();
90 RouteAttributeContainer result = statementRegistry.applyExportStatement(
91 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
92 assertNotNull(result.getAttributes());
95 doReturn(new PeerId("bgp://127.0.0.1")).when(exportParameters).getToPeerId();
96 result = statementRegistry.applyExportStatement(
97 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
98 assertNull(result.getAttributes());
102 public void testMatchToBgpNeighborInvert() {
103 Statement statement = basicStatements.stream()
104 .filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().orElseThrow();
105 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
106 new AttributesBuilder().build());
108 doReturn(new PeerId("bgp://127.0.0.2")).when(exportParameters).getFromPeerId();
109 doReturn(new PeerId("bgp://42.42.42.42")).when(exportParameters).getToPeerId();
111 RouteAttributeContainer result = statementRegistry.applyExportStatement(
112 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
113 assertNull(result.getAttributes());
115 doReturn(new PeerId("bgp://127.0.0.1")).when(exportParameters).getToPeerId();
116 result = statementRegistry.applyExportStatement(
117 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
118 assertNotNull(result.getAttributes());