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.Arrays;
15 import java.util.Collections;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
21 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
22 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.CommunitiesBuilder;
28 import org.opendaylight.yangtools.yang.common.Uint16;
30 public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest {
32 private BGPRouteEntryExportParameters exportParameters;
33 private List<Statement> basicStatements;
34 private PolicyRIBBaseParametersImpl baseAttributes;
38 public void setUp() throws Exception {
40 this.basicStatements = loadStatement("community-statements-test");
41 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
45 public void testComAny() {
46 Statement statement = this.basicStatements.stream()
47 .filter(st -> st.getName().equals("community-any-test")).findFirst().get();
48 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
49 new AttributesBuilder().build());
50 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
53 this.exportParameters,
56 assertNotNull(result.getAttributes());
58 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
59 Collections.singletonList(new CommunitiesBuilder()
60 .setAsNumber(AsNumber.getDefaultInstance("65"))
61 .setSemantics(Uint16.valueOf(10))
64 result = this.statementRegistry.applyExportStatement(
67 this.exportParameters,
70 assertNull(result.getAttributes());
74 public void testComInvert() {
75 Statement statement = this.basicStatements.stream()
76 .filter(st -> st.getName().equals("community-invert-test")).findFirst().get();
77 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
78 new AttributesBuilder().build());
79 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
82 this.exportParameters,
85 assertNull(result.getAttributes());
87 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(
88 Collections.singletonList(new CommunitiesBuilder()
89 .setAsNumber(AsNumber.getDefaultInstance("65"))
90 .setSemantics(Uint16.valueOf(10))
93 result = this.statementRegistry.applyExportStatement(
96 this.exportParameters,
99 assertNotNull(result.getAttributes());
103 public void testComAll() {
104 Statement statement = this.basicStatements.stream()
105 .filter(st -> st.getName().equals("community-all-test")).findFirst().get();
106 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
107 new AttributesBuilder().build());
108 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
111 this.exportParameters,
114 assertNotNull(result.getAttributes());
116 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setCommunities(Arrays.asList(
117 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("65"))
118 .setSemantics(Uint16.valueOf(10)).build(),
119 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("66"))
120 .setSemantics(Uint16.valueOf(11)).build())).build());
122 result = this.statementRegistry.applyExportStatement(
125 this.exportParameters,
128 assertNull(result.getAttributes());