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.CLUSTER;
14 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.IPV4;
15 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.LOCAL_AS;
17 import com.google.common.collect.ImmutableMap;
18 import java.util.List;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
23 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
24 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
32 public class ImportDefaultStatementTest extends AbstractStatementRegistryConsumerTest {
33 private static final NodeIdentifierWithPredicates ROUTE_ID_PA
34 = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
35 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "1.2.3.4/32"));
37 private BGPRouteEntryImportParameters importParameters;
38 private List<Statement> defaultImportStatements;
39 private PolicyRIBBaseParametersImpl baseAttributes;
44 public void setUp() throws Exception {
46 this.defaultImportStatements = loadStatement("default-odl-import-policy");
47 doReturn(ROUTE_ID_PA).when(this.importParameters).getRouteId();
48 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
55 public void testFromEbgp() {
56 final Statement statement = getStatement("from-external");
58 final RouteAttributeContainer attributeContainer
59 = routeAttributeContainerFalse(ImportAttributeTestUtil.createInput());
61 assertApplyImportStatement(statement, PeerRole.Ebgp, attributeContainer,
62 ImportAttributeTestUtil.createOutput());
69 public void testFromNonExternal() {
70 final Statement statement = getStatement("from-non-external");
72 final Attributes expected = ImportAttributeTestUtil.createInput();
73 final RouteAttributeContainer attributeContainer
74 = routeAttributeContainerFalse(expected);
76 assertApplyImportStatement(statement, PeerRole.Ibgp, attributeContainer, expected);
77 assertApplyImportStatement(statement, PeerRole.RrClient, attributeContainer, expected);
78 assertApplyImportStatement(statement, PeerRole.Internal, attributeContainer, expected);
81 private Statement getStatement(final String statementName) {
82 return this.defaultImportStatements.stream()
83 .filter(st -> st.getName().equals(statementName)).findFirst().get();
86 private void assertApplyImportStatement(
87 final Statement statement,
88 final PeerRole fromPeerRole,
89 final RouteAttributeContainer attInput,
90 final Attributes attExpected) {
92 doReturn(fromPeerRole).when(this.importParameters).getFromPeerRole();
94 RouteAttributeContainer result = this.statementRegistry.applyImportStatement(
96 this.importParameters,
99 assertEquals(attExpected, result.getAttributes());