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.spi;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.doReturn;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
15 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.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.AttributesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.AsPathBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.as.path.SegmentsBuilder;
28 public class AsPathLengthTest extends AbstractStatementRegistryTest {
30 private BGPRouteEntryExportParameters exportParameters;
31 private List<Statement> basicStatements;
33 private RouteEntryBaseAttributes baseAttributes;
37 public void setUp() throws Exception {
39 basicStatements = loadStatement("basic-statements-test");
40 doReturn(CLUSTER).when(baseAttributes).getClusterId();
41 doReturn(LOCAL_AS).when(baseAttributes).getLocalAs();
42 doReturn(IPV4).when(baseAttributes).getOriginatorId();
46 public void testASPathLengthEq() {
47 final AsPathBuilder asPath = new AsPathBuilder();
48 asPath.setSegments(List.of(new SegmentsBuilder()
49 .setAsSequence(List.of(
50 AsNumber.getDefaultInstance("1"),
51 AsNumber.getDefaultInstance("2"),
52 AsNumber.getDefaultInstance("3")))
55 Statement statement = basicStatements.stream()
56 .filter(st -> st.getName().equals("as-path-eq-length-test")).findFirst().orElseThrow();
57 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
58 .setAsPath(asPath.build())
61 RouteAttributeContainer result = statementRegistry.applyExportStatement(
67 assertNotNull(result.getAttributes());
69 asPath.setSegments(List.of(new SegmentsBuilder()
70 .setAsSequence(List.of(
71 AsNumber.getDefaultInstance("1"),
72 AsNumber.getDefaultInstance("3")))
75 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build());
76 result = statementRegistry.applyExportStatement(
82 assertNull(result.getAttributes());
86 public void testASPathLengthGe() {
87 final AsPathBuilder asPath = new AsPathBuilder();
88 asPath.setSegments(List.of(new SegmentsBuilder()
89 .setAsSequence(List.of(
90 AsNumber.getDefaultInstance("1"),
91 AsNumber.getDefaultInstance("2"),
92 AsNumber.getDefaultInstance("3")))
95 Statement statement = basicStatements.stream()
96 .filter(st -> st.getName().equals("as-path-ge-length-test")).findFirst().orElseThrow();
97 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
98 .setAsPath(asPath.build())
101 RouteAttributeContainer result = statementRegistry.applyExportStatement(
107 assertNull(result.getAttributes());
109 asPath.setSegments(List.of(new SegmentsBuilder()
110 .setAsSequence(List.of(AsNumber.getDefaultInstance("3")))
113 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build());
114 result = statementRegistry.applyExportStatement(
120 assertNotNull(result.getAttributes());
124 public void testASPathLengthLe() {
125 final AsPathBuilder asPath = new AsPathBuilder();
126 asPath.setSegments(List.of(new SegmentsBuilder()
127 .setAsSequence(List.of(
128 AsNumber.getDefaultInstance("1"),
129 AsNumber.getDefaultInstance("2"),
130 AsNumber.getDefaultInstance("3")))
133 Statement statement = basicStatements.stream()
134 .filter(st -> st.getName().equals("as-path-le-length-test")).findFirst().orElseThrow();
135 RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
136 .setAsPath(asPath.build())
139 RouteAttributeContainer result = statementRegistry.applyExportStatement(
145 assertNotNull(result.getAttributes());
147 asPath.setSegments(List.of(new SegmentsBuilder()
148 .setAsSequence(List.of(AsNumber.getDefaultInstance("3"))).build()));
150 attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build());
151 result = statementRegistry.applyExportStatement(
157 assertNull(result.getAttributes());