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.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createClusterInput;
14 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createInputWithOriginator;
15 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createPathInput;
16 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createPathInputWithAs;
17 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ImportAttributeTestUtil.AS;
19 import java.util.Collections;
20 import java.util.List;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mock;
24 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
25 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
26 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
27 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
31 public class ExportDefaultStatementTest extends AbstractStatementRegistryConsumerTest {
33 private BGPRouteEntryExportParameters exportParameters;
34 private List<Statement> defaultExportStatements;
35 private PolicyRIBBaseParametersImpl baseAttributes;
39 public void setUp() throws Exception {
41 this.defaultExportStatements = loadStatement("default-odl-export-policy");
42 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
46 public void testToEbgp() {
47 final Statement statement = getStatementAndSetToRole("to-external", PeerRole.Ebgp);
49 final Attributes expectedOutput = createPathInputWithAs();
50 final RouteAttributeContainer attributeContainer
51 = routeAttributeContainerFalse(createPathInput(Collections.emptyList()));
53 assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, expectedOutput);
54 assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, expectedOutput);
55 assertApplyExportStatement(statement, PeerRole.Internal, attributeContainer, expectedOutput);
56 assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, expectedOutput);
60 public void testFromInternalToInternal() {
61 final Statement statement = getStatementAndSetToRole("from-internal-to-internal", PeerRole.Ibgp);
62 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
63 assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, null);
67 public void testFromExternalToInternal() {
68 final Statement statement = getStatementAndSetToRole("from-external-to-internal", PeerRole.Ibgp);
69 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
70 assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, attributeContainer.getAttributes());
74 public void testFromOdlInternalToInternal() {
75 final Statement statement = getStatementAndSetToRole("from-odl-internal-to-internal-or-rr-client",
77 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
78 assertApplyExportStatement(statement, PeerRole.Internal, attributeContainer, createClusterInput());
82 public void testFromRRclientToInternal() {
83 final Statement statement = getStatementAndSetToRole("from-rr-client-to-internal", PeerRole.Ibgp);
84 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
85 assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, createInputWithOriginator());
89 public void testOdlInternal() {
90 final Statement statement = getStatementAndSetToRole("to-odl-internal", PeerRole.Internal);
91 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
93 assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, null);
94 assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, null);
95 assertApplyExportStatement(statement, PeerRole.Internal, attributeContainer, null);
96 assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, null);
100 public void testFromExternalToRRClient() {
101 final Statement statement = getStatementAndSetToRole("from-external-to-route-reflector", PeerRole.RrClient);
102 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
103 assertApplyExportStatement(statement, PeerRole.Ebgp, attributeContainer, attributeContainer.getAttributes());
107 public void testFromInternalOrRRClientToRRClient() {
108 final Statement statement = getStatementAndSetToRole("from-internal-or-rr-client-to-route-reflector",
110 final Attributes expectedOutput = createInputWithOriginator();
111 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
113 assertApplyExportStatement(statement, PeerRole.Ibgp, attributeContainer, expectedOutput);
114 assertApplyExportStatement(statement, PeerRole.RrClient, attributeContainer, expectedOutput);
118 public void testFromOdlInternalToRRClient() {
119 final Statement statement = getStatementAndSetToRole("from-odl-internal-to-internal-or-rr-client",
121 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
122 assertApplyExportStatement(statement, PeerRole.Internal, attributeContainer, createClusterInput());
125 private Statement getStatementAndSetToRole(final String statementName, final PeerRole toPeerRole) {
126 doReturn(toPeerRole).when(this.exportParameters).getToPeerRole();
127 doReturn(AS).when(this.exportParameters).getToPeerLocalAs();
128 return this.defaultExportStatements.stream()
129 .filter(st -> st.getName().equals(statementName)).findFirst().get();
132 private void assertApplyExportStatement(
133 final Statement statement, final PeerRole fromPeerRole,
134 final RouteAttributeContainer attInput,
135 final Attributes attExpected) {
136 doReturn(fromPeerRole).when(this.exportParameters).getFromPeerRole();
138 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
140 this.exportParameters,
143 assertEquals(attExpected, result.getAttributes());