Route Constrain policies
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / MatchAfiSafiNotInTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14
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.bgp.types.rev151009.IPV6UNICAST;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
32
33 public class MatchAfiSafiNotInTest extends AbstractStatementRegistryConsumerTest {
34     @Mock
35     private BGPRouteEntryExportParameters exportParameters;
36     private List<Statement> basicStatements;
37     private PolicyRIBBaseParametersImpl baseAttributes;
38
39     @Before
40     @Override
41     public void setUp() throws Exception {
42         super.setUp();
43         this.basicStatements = loadStatement("match-afi-safi-not-in-test");
44         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
45     }
46
47     @Test
48     public void testExtComAny() {
49         Statement statement = this.basicStatements.stream()
50                 .filter(st -> st.getName().equals("match-afi-safi-not-in-test")).findFirst().get();
51         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
52                 new AttributesBuilder().build());
53         RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
54                 this.baseAttributes,
55                 IPV4UNICAST.class,
56                 this.exportParameters,
57                 attributeContainer,
58                 statement);
59         assertNotNull(result.getAttributes());
60
61
62         attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
63                 .setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder()
64                         .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder()
65                                 .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
66                                         .setAs4SpecificCommon(new As4SpecificCommonBuilder()
67                                                 .setAsNumber(AsNumber.getDefaultInstance("65000"))
68                                                 .setLocalAdministrator(123)
69                                                 .build()).build()).build()).build())).build());
70
71         result = this.statementRegistry.applyExportStatement(
72                 this.baseAttributes,
73                 IPV6UNICAST.class,
74                 this.exportParameters,
75                 attributeContainer,
76                 statement);
77         assertNull(result.getAttributes());
78     }
79 }