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
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.mockito.Mockito.doReturn;
14 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
21 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
22 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
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.rev171207.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 this.basicStatements = loadStatement("bgp-neighbor-statements-test");
38 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
43 public void testMatchFromBgpNeighborAny() {
44 Statement statement = this.basicStatements.stream()
45 .filter(st -> st.getName().equals("reject-from-neighbor-test")).findFirst().get();
46 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
47 new AttributesBuilder().build());
49 doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
51 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
53 this.exportParameters,
56 assertNotNull(result.getAttributes());
59 doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
60 result = this.statementRegistry.applyExportStatement(
62 this.exportParameters,
65 assertNull(result.getAttributes());
69 public void testMatchFromBgpNeighborInvert() {
70 Statement statement = this.basicStatements.stream()
71 .filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().get();
72 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
73 new AttributesBuilder().build());
75 doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getFromPeerId();
77 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
79 this.exportParameters,
82 assertNull(result.getAttributes());
84 doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getFromPeerId();
85 result = this.statementRegistry.applyExportStatement(
87 this.exportParameters,
90 assertNotNull(result.getAttributes());
94 public void testMatchToBgpNeighborAny() {
95 Statement statement = this.basicStatements.stream()
96 .filter(st -> st.getName().equals("reject-to-neighbor-test")).findFirst().get();
97 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
98 new AttributesBuilder().build());
100 doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
101 doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
103 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
105 this.exportParameters,
108 assertNotNull(result.getAttributes());
111 doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
112 result = this.statementRegistry.applyExportStatement(
114 this.exportParameters,
117 assertNull(result.getAttributes());
121 public void testMatchToBgpNeighborInvert() {
122 Statement statement = this.basicStatements.stream()
123 .filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().get();
124 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
125 new AttributesBuilder().build());
127 doReturn(new PeerId("bgp://127.0.0.2")).when(this.exportParameters).getFromPeerId();
128 doReturn(new PeerId("bgp://42.42.42.42")).when(this.exportParameters).getToPeerId();
130 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
132 this.exportParameters,
135 assertNull(result.getAttributes());
137 doReturn(new PeerId("bgp://127.0.0.1")).when(this.exportParameters).getToPeerId();
138 result = this.statementRegistry.applyExportStatement(
140 this.exportParameters,
143 assertNotNull(result.getAttributes());