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.route.targetcontrain.impl.route.policy;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14 import java.util.Collections;
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.AbstractStatementRegistryTest;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.RouteEntryBaseAttributes;
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.protocol.bgp.route.targetcontrain.impl.activators.StatementActivator;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
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.Ipv4AddressNoZone;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRouteBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
34 import org.opendaylight.yangtools.yang.common.Uint32;
36 public class ClientAttributePrependHandlerTest extends AbstractStatementRegistryTest {
38 private BGPRouteEntryExportParameters exportParameters;
39 private List<Statement> basicStatements;
41 private RouteEntryBaseAttributes baseAttributes;
45 public void setUp() throws Exception {
47 final StatementActivator act = new StatementActivator();
48 act.start(statementRegistry);
49 basicStatements = loadStatement("basic-statements-test");
50 doReturn(CLUSTER).when(baseAttributes).getClusterId();
51 doReturn(LOCAL_AS).when(baseAttributes).getLocalAs();
52 doReturn(IPV4).when(baseAttributes).getOriginatorId();
57 public void testPreprendClientAttribute() {
58 Statement statement = basicStatements.stream()
59 .filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().orElseThrow();
60 final Attributes att = new AttributesBuilder()
61 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
62 .setGlobal(IPV4).build()).build())
64 final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(att);
65 doReturn(Collections.emptyList()).when(exportParameters).getClientRouteTargetContrainCache();
67 RouteAttributeContainer result = statementRegistry.applyExportStatement(
73 assertEquals(att, result.getAttributes());
75 final Attributes expected = new AttributesBuilder()
76 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
77 .setGlobal(new Ipv4AddressNoZone("2.2.2.2")).build()).build())
79 final String rk = "testRoute";
80 final Route rtRoute = new RouteTargetConstrainRouteBuilder()
82 .setPathId(new PathId(Uint32.ZERO))
83 .setAttributes(expected)
85 doReturn(Collections.singletonList(rtRoute)).when(exportParameters).getClientRouteTargetContrainCache();
86 doReturn(rk).when(exportParameters).getRouteKey();
88 result = statementRegistry.applyExportStatement(
94 assertEquals(expected, result.getAttributes());