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.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14 import java.util.List;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
19 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
20 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.CommunitiesBuilder;
26 import org.opendaylight.yangtools.yang.common.Uint16;
28 public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest {
30 private BGPRouteEntryExportParameters exportParameters;
31 private List<Statement> basicStatements;
32 private PolicyRIBBaseParametersImpl baseAttributes;
36 public void setUp() throws Exception {
38 basicStatements = loadStatement("community-statements-test");
39 baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
43 public void testComAny() {
44 Statement statement = basicStatements.stream()
45 .filter(st -> st.getName().equals("community-any-test")).findFirst().orElseThrow();
46 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
47 new AttributesBuilder().build());
48 RouteAttributeContainer result = statementRegistry.applyExportStatement(
49 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
50 assertNotNull(result.getAttributes());
52 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
53 List.of(new CommunitiesBuilder()
54 .setAsNumber(AsNumber.getDefaultInstance("65"))
55 .setSemantics(Uint16.TEN)
58 result = statementRegistry.applyExportStatement(
59 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
60 assertNull(result.getAttributes());
64 public void testComInvert() {
65 Statement statement = basicStatements.stream()
66 .filter(st -> st.getName().equals("community-invert-test")).findFirst().orElseThrow();
67 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
68 new AttributesBuilder().build());
69 RouteAttributeContainer result = statementRegistry.applyExportStatement(
70 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
71 assertNull(result.getAttributes());
73 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
74 List.of(new CommunitiesBuilder()
75 .setAsNumber(AsNumber.getDefaultInstance("65"))
76 .setSemantics(Uint16.TEN)
79 result = statementRegistry.applyExportStatement(
80 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
81 assertNotNull(result.getAttributes());
85 public void testComAll() {
86 Statement statement = basicStatements.stream()
87 .filter(st -> st.getName().equals("community-all-test")).findFirst().orElseThrow();
88 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
89 new AttributesBuilder().build());
90 RouteAttributeContainer result = statementRegistry.applyExportStatement(
91 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
92 assertNotNull(result.getAttributes());
94 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(List.of(
95 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("65"))
96 .setSemantics(Uint16.TEN).build(),
97 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("66"))
98 .setSemantics(Uint16.valueOf(11)).build())).build());
100 result = statementRegistry.applyExportStatement(
101 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
102 assertNull(result.getAttributes());