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.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.doReturn;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.CLUSTER;
15 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.IPV4;
16 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.LOCAL_AS;
18 import com.google.common.collect.ImmutableMap;
19 import java.util.Arrays;
20 import java.util.Collections;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.CommunitiesBuilder;
33 import org.opendaylight.yangtools.yang.common.QName;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
36 public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest {
38 private BGPRouteEntryExportParameters exportParameters;
39 private List<Statement> basicStatements;
40 private PolicyRIBBaseParametersImpl baseAttributes;
44 public void setUp() throws Exception {
46 this.basicStatements = loadStatement("community-statements-test");
47 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
51 public void testComAny() {
52 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
53 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
54 .when(this.exportParameters).getRouteId();
55 Statement statement = this.basicStatements.stream()
56 .filter(st -> st.getName().equals("community-any-test")).findFirst().get();
57 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
58 new AttributesBuilder().build());
59 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
61 this.exportParameters,
64 assertNotNull(result.getAttributes());
66 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
67 Collections.singletonList(new CommunitiesBuilder()
68 .setAsNumber(AsNumber.getDefaultInstance("65"))
72 result = this.statementRegistry.applyExportStatement(
74 this.exportParameters,
77 assertNull(result.getAttributes());
81 public void testComInvert() {
82 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
83 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
84 .when(this.exportParameters).getRouteId();
85 Statement statement = this.basicStatements.stream()
86 .filter(st -> st.getName().equals("community-invert-test")).findFirst().get();
87 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
88 new AttributesBuilder().build());
89 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
91 this.exportParameters,
94 assertNull(result.getAttributes());
96 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
97 Collections.singletonList(new CommunitiesBuilder()
98 .setAsNumber(AsNumber.getDefaultInstance("65"))
102 result = this.statementRegistry.applyExportStatement(
104 this.exportParameters,
107 assertNotNull(result.getAttributes());
111 public void testComAll() {
112 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
113 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
114 .when(this.exportParameters).getRouteId();
115 Statement statement = this.basicStatements.stream()
116 .filter(st -> st.getName().equals("community-all-test")).findFirst().get();
117 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
118 new AttributesBuilder().build());
119 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
121 this.exportParameters,
124 assertNotNull(result.getAttributes());
126 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(Arrays.asList(
127 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("65"))
128 .setSemantics(10).build(),
129 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("66"))
130 .setSemantics(11).build())).build());
132 result = this.statementRegistry.applyExportStatement(
134 this.exportParameters,
137 assertNull(result.getAttributes());