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.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
21 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
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.AsPathBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.SegmentsBuilder;
29 public class MatchAsPathSetTest extends AbstractStatementRegistryConsumerTest {
31 private BGPRouteEntryExportParameters exportParameters;
32 private List<Statement> basicStatements;
33 private PolicyRIBBaseParametersImpl baseAttributes;
37 public void setUp() throws Exception {
39 basicStatements = loadStatement("match-as-path-set-test");
40 baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
44 public void testMatchAsPathAny() {
45 Statement statement = basicStatements.stream()
46 .filter(st -> st.getName().equals("reject-match-as-path-any-set")).findFirst().orElseThrow();
47 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
48 new AttributesBuilder().build());
49 RouteAttributeContainer result = statementRegistry.applyExportStatement(
50 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
51 assertNotNull(result.getAttributes());
54 attributeContainer = routeAttributeContainerFalse(
55 new AttributesBuilder()
56 .setAsPath(new AsPathBuilder().setSegments(List.of(
57 new SegmentsBuilder().setAsSequence(List.of(
58 AsNumber.getDefaultInstance("65"))).build())).build()).build());
59 result = statementRegistry.applyExportStatement(
60 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
61 assertNull(result.getAttributes());
65 public void testMatchAsPathAll() {
66 Statement statement = basicStatements.stream()
67 .filter(st -> st.getName().equals("reject-match-as-path-all-set")).findFirst().orElseThrow();
68 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
69 .setAsPath(new AsPathBuilder().setSegments(List.of(
70 new SegmentsBuilder().setAsSequence(List.of(
71 AsNumber.getDefaultInstance("65"))).build())).build()).build());
72 RouteAttributeContainer result = statementRegistry.applyExportStatement(
73 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
74 assertNotNull(result.getAttributes());
76 attributeContainer = routeAttributeContainerFalse(
77 new AttributesBuilder()
78 .setAsPath(new AsPathBuilder().setSegments(List.of(
79 new SegmentsBuilder().setAsSet(Set.of(
80 AsNumber.getDefaultInstance("65"),
81 AsNumber.getDefaultInstance("64")
83 new SegmentsBuilder().setAsSet(Set.of(
84 AsNumber.getDefaultInstance("63")
87 result = statementRegistry.applyExportStatement(
88 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
89 assertNull(result.getAttributes());
93 public void testMatchAsPathInverse() {
94 Statement statement = basicStatements.stream()
95 .filter(st -> st.getName().equals("reject-match-as-path-inverse-set")).findFirst().orElseThrow();
96 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
97 new AttributesBuilder()
98 .setAsPath(new AsPathBuilder().setSegments(List.of(
99 new SegmentsBuilder().setAsSequence(List.of(
100 AsNumber.getDefaultInstance("65"))).build())).build()).build());
101 RouteAttributeContainer result = statementRegistry.applyExportStatement(
102 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
103 assertNotNull(result.getAttributes());
106 attributeContainer = routeAttributeContainerFalse(
107 new AttributesBuilder()
108 .setAsPath(new AsPathBuilder().setSegments(List.of(
109 new SegmentsBuilder().setAsSequence(List.of(
110 AsNumber.getDefaultInstance("200"))).build())).build()).build());
111 result = statementRegistry.applyExportStatement(
112 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
113 assertNull(result.getAttributes());