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;
15 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.CLUSTER;
16 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.IPV4;
17 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.LOCAL_AS;
18 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.createClusterInput;
20 import com.google.common.collect.ImmutableMap;
21 import java.util.List;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mock;
25 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
26 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
27 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
28 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
30 import org.opendaylight.yangtools.yang.common.QName;
31 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
33 public class PrefixMatchTest extends AbstractStatementRegistryConsumerTest {
35 private BGPRouteEntryExportParameters exportParameters;
36 private List<Statement> basicStatements;
37 private PolicyRIBBaseParametersImpl baseAttributes;
41 public void setUp() throws Exception {
43 this.basicStatements = loadStatement("basic-statements-test");
44 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
48 public void testPrefixRange() {
50 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
51 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
52 .when(this.exportParameters).getRouteId();
53 Statement statement = this.basicStatements.stream()
54 .filter(st -> st.getName().equals("reject-prefix-test")).findFirst().get();
55 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
56 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
58 this.exportParameters,
61 assertNull(result.getAttributes());
63 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
64 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "14.3.191.0/22")))
65 .when(this.exportParameters).getRouteId();
66 result = this.statementRegistry.applyExportStatement(
68 this.exportParameters,
71 assertNotNull(result.getAttributes());
75 public void testPrefixExact() {
76 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
77 Statement statement = this.basicStatements.stream()
78 .filter(st -> st.getName().equals("reject-prefix-test")).findFirst().get();
80 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
81 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.192.0/21")))
82 .when(this.exportParameters).getRouteId();
83 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
85 this.exportParameters,
88 assertNull(result.getAttributes());
90 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
91 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "11.3.192.0/21")))
92 .when(this.exportParameters).getRouteId();
93 result = this.statementRegistry.applyExportStatement(
95 this.exportParameters,
98 assertNotNull(result.getAttributes());
102 public void testPrefixInverse() {
103 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(createClusterInput());
105 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
106 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.192.0/21")))
107 .when(this.exportParameters).getRouteId();
108 final Statement statement = this.basicStatements.stream()
109 .filter(st -> st.getName().equals("reject-prefix-inverse-test")).findFirst().get();
110 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
112 this.exportParameters,
115 assertNotNull(result.getAttributes());
117 doReturn(new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
118 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "11.3.192.0/21")))
119 .when(this.exportParameters).getRouteId();
120 result = this.statementRegistry.applyExportStatement(
122 this.exportParameters,
125 assertNull(result.getAttributes());