Route Constrain policies
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / SetLocalAddressAsNextHopHandlerTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.doReturn;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14
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.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.Ipv4Address;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
30
31 public class SetLocalAddressAsNextHopHandlerTest extends AbstractStatementRegistryConsumerTest {
32     private final Attributes multipleCom = new AttributesBuilder()
33             .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
34                     .setGlobal(new Ipv4Address("1.2.3.4")).build()).build())
35             .build();
36     @Mock
37     private BGPRouteEntryExportParameters exportParameters;
38     private List<Statement> basicStatements;
39     private PolicyRIBBaseParametersImpl baseAttributes;
40
41     @Before
42     @Override
43     public void setUp() throws Exception {
44         super.setUp();
45         this.basicStatements = loadStatement("set-local-address-as-next-hop");
46         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
47         doReturn(PeerRole.Ibgp).when(this.exportParameters).getFromPeerRole();
48     }
49
50     @Test
51     public void testInlineAdd() {
52         Statement statement = this.basicStatements.stream()
53                 .filter(st -> st.getName().equals("set-local-address-as-next-hop")).findFirst().get();
54         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
55                 new AttributesBuilder().build());
56         RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
57                 this.baseAttributes,
58                 IPV4UNICAST.class,
59                 this.exportParameters,
60                 attributeContainer,
61                 statement);
62
63         assertEquals(this.multipleCom, result.getAttributes());
64     }
65 }