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.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
22 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
23 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
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.rev171207.path.attributes.AttributesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder;
30 public class MatchAsPathSetTest 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("match-as-path-set-test");
41 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
46 public void testMatchAsPathAny() {
47 Statement statement = this.basicStatements.stream()
48 .filter(st -> st.getName().equals("reject-match-as-path-any-set")).findFirst().get();
49 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
50 new AttributesBuilder().build());
51 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
53 this.exportParameters,
56 assertNotNull(result.getAttributes());
59 attributeContainer = routeAttributeContainerFalse(
60 new AttributesBuilder()
61 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
62 new SegmentsBuilder().setAsSequence(Collections.singletonList(
63 AsNumber.getDefaultInstance("65"))).build())).build()).build());
64 result = this.statementRegistry.applyExportStatement(
66 this.exportParameters,
69 assertNull(result.getAttributes());
73 public void testMatchAsPathAll() {
74 Statement statement = this.basicStatements.stream()
75 .filter(st -> st.getName().equals("reject-match-as-path-all-set")).findFirst().get();
76 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
77 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
78 new SegmentsBuilder().setAsSequence(Collections.singletonList(
79 AsNumber.getDefaultInstance("65"))).build())).build()).build());
80 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
82 this.exportParameters,
85 assertNotNull(result.getAttributes());
88 attributeContainer = routeAttributeContainerFalse(
89 new AttributesBuilder()
90 .setAsPath(new AsPathBuilder().setSegments(Arrays.asList(
91 new SegmentsBuilder().setAsSet(Arrays.asList(
92 AsNumber.getDefaultInstance("65"),
93 AsNumber.getDefaultInstance("64")
95 new SegmentsBuilder().setAsSet(Collections.singletonList(
96 AsNumber.getDefaultInstance("63")
99 result = this.statementRegistry.applyExportStatement(
101 this.exportParameters,
104 assertNull(result.getAttributes());
108 public void testMatchAsPathInverse() {
109 Statement statement = this.basicStatements.stream()
110 .filter(st -> st.getName().equals("reject-match-as-path-inverse-set")).findFirst().get();
111 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
112 new AttributesBuilder()
113 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
114 new SegmentsBuilder().setAsSequence(Collections.singletonList(
115 AsNumber.getDefaultInstance("65"))).build())).build()).build());
116 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
118 this.exportParameters,
121 assertNotNull(result.getAttributes());
124 attributeContainer = routeAttributeContainerFalse(
125 new AttributesBuilder()
126 .setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
127 new SegmentsBuilder().setAsSequence(Collections.singletonList(
128 AsNumber.getDefaultInstance("200"))).build())).build()).build());
129 result = this.statementRegistry.applyExportStatement(
131 this.exportParameters,
134 assertNull(result.getAttributes());