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;
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.Attributes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.CommunitiesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
28 import org.opendaylight.yangtools.yang.common.Uint16;
30 public class SetCommunityTest extends AbstractStatementRegistryConsumerTest {
31 private final Attributes multipleCom = new AttributesBuilder().setCommunities(List.of(
32 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("65")).setSemantics(Uint16.valueOf(10))
34 new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("66")).setSemantics(Uint16.valueOf(11))
37 private final Attributes emptyCom = new AttributesBuilder().setCommunities(List.of()).build();
39 private BGPRouteEntryExportParameters exportParameters;
40 private List<Statement> basicStatements;
41 private PolicyRIBBaseParametersImpl baseAttributes;
45 public void setUp() throws Exception {
47 basicStatements = loadStatement("set-community-statements-test");
48 baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
49 doReturn(PeerRole.Ibgp).when(exportParameters).getFromPeerRole();
53 public void testInlineAdd() {
54 Statement statement = basicStatements.stream()
55 .filter(st -> st.getName().equals("set-community-inline-add-test")).findFirst().orElseThrow();
56 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
57 new AttributesBuilder().build());
58 RouteAttributeContainer result = statementRegistry.applyExportStatement(
59 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
61 assertEquals(multipleCom, result.getAttributes());
65 public void testInlineReplace() {
66 Statement statement = basicStatements.stream()
67 .filter(st -> st.getName().equals("set-community-inline-replace-test")).findFirst().orElseThrow();
68 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
69 new AttributesBuilder().build());
70 RouteAttributeContainer result = statementRegistry.applyExportStatement(
71 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
73 assertEquals(multipleCom, result.getAttributes());
77 public void testInlineRemove() {
78 Statement statement = basicStatements.stream()
79 .filter(st -> st.getName().equals("set-community-inline-remove-test")).findFirst().orElseThrow();
81 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleCom);
82 RouteAttributeContainer result = statementRegistry.applyExportStatement(
83 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
85 assertEquals(emptyCom, result.getAttributes());
89 public void testReferenceAdd() {
90 Statement statement = basicStatements.stream()
91 .filter(st -> st.getName().equals("set-community-reference-add-test")).findFirst().orElseThrow();
92 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
93 new AttributesBuilder().build());
94 RouteAttributeContainer result = statementRegistry.applyExportStatement(
95 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
97 assertEquals(multipleCom, result.getAttributes());
101 public void testReferenceReplace() {
102 Statement statement = basicStatements.stream()
103 .filter(st -> st.getName().equals("set-community-reference-replace-test")).findFirst().orElseThrow();
104 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
105 new AttributesBuilder().build());
106 RouteAttributeContainer result = statementRegistry.applyExportStatement(
107 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
109 assertEquals(multipleCom, result.getAttributes());
113 public void testReferenceRemove() {
114 Statement statement = basicStatements.stream()
115 .filter(st -> st.getName().equals("set-community-reference-remove-test")).findFirst().orElseThrow();
117 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleCom);
118 RouteAttributeContainer result = statementRegistry.applyExportStatement(
119 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
121 assertEquals(emptyCom, result.getAttributes());