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.ImportAttributeTestUtil.AS;
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.BGPRouteEntryImportParameters;
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.Attributes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
27 public class ImportDefaultStatementTest extends AbstractStatementRegistryConsumerTest {
29 private BGPRouteEntryImportParameters importParameters;
30 private List<Statement> defaultImportStatements;
31 private PolicyRIBBaseParametersImpl baseAttributes;
35 public void setUp() throws Exception {
37 defaultImportStatements = loadStatement("default-odl-import-policy");
38 baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
42 public void testFromEbgp() {
43 final Statement statement = getStatement("from-external");
45 final RouteAttributeContainer attributeContainer
46 = routeAttributeContainerFalse(ImportAttributeTestUtil.createInput());
48 assertApplyImportStatement(statement, PeerRole.Ebgp, attributeContainer,
49 ImportAttributeTestUtil.createOutput());
53 public void testFromNonExternal() {
54 final Statement statement = getStatement("from-non-external");
56 final Attributes expected = ImportAttributeTestUtil.createInput();
57 final RouteAttributeContainer attributeContainer
58 = routeAttributeContainerFalse(expected);
60 assertApplyImportStatement(statement, PeerRole.Ibgp, attributeContainer, expected);
61 assertApplyImportStatement(statement, PeerRole.RrClient, attributeContainer, expected);
62 assertApplyImportStatement(statement, PeerRole.Internal, attributeContainer, expected);
65 private Statement getStatement(final String statementName) {
66 return defaultImportStatements.stream()
67 .filter(st -> st.getName().equals(statementName)).findFirst().get();
70 private void assertApplyImportStatement(
71 final Statement statement,
72 final PeerRole fromPeerRole,
73 final RouteAttributeContainer attInput,
74 final Attributes attExpected) {
76 doReturn(fromPeerRole).when(importParameters).getFromPeerRole();
77 doReturn(AS).when(importParameters).getFromPeerLocalAs();
79 RouteAttributeContainer result = statementRegistry.applyImportStatement(
80 baseAttributes, IPV4UNICAST.VALUE, importParameters, attInput, statement);
81 assertEquals(attExpected, result.getAttributes());