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
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.mockito.Mockito.doReturn;
14 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
15 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.CLUSTER;
16 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.IPV4;
17 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.statement.ExportAttributeTestUtil.LOCAL_AS;
19 import com.google.common.collect.ImmutableMap;
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
27 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
28 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
29 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
35 import org.opendaylight.yangtools.yang.common.QName;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
38 public class MatchAsPathSetTest extends AbstractStatementRegistryConsumerTest {
40 private BGPRouteEntryExportParameters exportParameters;
41 private List<Statement> basicStatements;
42 private PolicyRIBBaseParametersImpl baseAttributes;
46 public void setUp() throws Exception {
48 this.basicStatements = loadStatement("match-as-path-set-test");
49 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
54 public void testMatchAsPathAny() {
55 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
56 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
57 .when(this.exportParameters).getRouteId();
58 Statement statement = this.basicStatements.stream()
59 .filter(st -> st.getName().equals("reject-match-as-path-any-set")).findFirst().get();
60 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
61 new AttributesBuilder().build());
62 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
64 this.exportParameters,
67 assertNotNull(result.getAttributes());
70 attributeContainer = routeAttributeContainerFalse(
71 new AttributesBuilder()
72 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
73 new SegmentsBuilder().setAsSequence(Collections.singletonList(
74 AsNumber.getDefaultInstance("65"))).build())).build()).build());
75 result = this.statementRegistry.applyExportStatement(
77 this.exportParameters,
80 assertNull(result.getAttributes());
84 public void testMatchAsPathAll() {
85 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
86 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
87 .when(this.exportParameters).getRouteId();
88 Statement statement = this.basicStatements.stream()
89 .filter(st -> st.getName().equals("reject-match-as-path-all-set")).findFirst().get();
90 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
91 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
92 new SegmentsBuilder().setAsSequence(Collections.singletonList(
93 AsNumber.getDefaultInstance("65"))).build())).build()).build());
94 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
96 this.exportParameters,
99 assertNotNull(result.getAttributes());
102 attributeContainer = routeAttributeContainerFalse(
103 new AttributesBuilder()
104 .setAsPath(new AsPathBuilder().setSegments(Arrays.asList(
105 new SegmentsBuilder().setAsSet(Arrays.asList(
106 AsNumber.getDefaultInstance("65"),
107 AsNumber.getDefaultInstance("64")
109 new SegmentsBuilder().setAsSet(Collections.singletonList(
110 AsNumber.getDefaultInstance("63")
112 )).build()).build());
113 result = this.statementRegistry.applyExportStatement(
115 this.exportParameters,
118 assertNull(result.getAttributes());
122 public void testMatchAsPathInverse() {
123 doReturn(new YangInstanceIdentifier.NodeIdentifierWithPredicates(Ipv4Route.QNAME,
124 ImmutableMap.of(QName.create(Ipv4Route.QNAME, "prefix").intern(), "10.3.191.0/22")))
125 .when(this.exportParameters).getRouteId();
126 Statement statement = this.basicStatements.stream()
127 .filter(st -> st.getName().equals("reject-match-as-path-inverse-set")).findFirst().get();
128 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
129 new AttributesBuilder()
130 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
131 new SegmentsBuilder().setAsSequence(Collections.singletonList(
132 AsNumber.getDefaultInstance("65"))).build())).build()).build());
133 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
135 this.exportParameters,
138 assertNotNull(result.getAttributes());
141 attributeContainer = routeAttributeContainerFalse(
142 new AttributesBuilder()
143 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
144 new SegmentsBuilder().setAsSequence(Collections.singletonList(
145 AsNumber.getDefaultInstance("200"))).build())).build()).build());
146 result = this.statementRegistry.applyExportStatement(
148 this.exportParameters,
151 assertNull(result.getAttributes());