MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / openconfig-rp-spi / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / spi / AppendActionTest.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 package org.opendaylight.protocol.bgp.openconfig.routing.policy.spi;
9
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;
13
14 import java.util.List;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
19 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
20 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpOrigin;
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 AppendActionTest extends AbstractStatementRegistryTest {
32     @Mock
33     private BGPRouteEntryExportParameters exportParameters;
34     private List<Statement> basicStatements;
35     @Mock
36     private RouteEntryBaseAttributes baseAttributes;
37
38     @Before
39     @Override
40     public void setUp() throws Exception {
41         super.setUp();
42         this.basicStatements = loadStatement("basic-statements-test");
43         doReturn(CLUSTER).when(this.baseAttributes).getClusterId();
44         doReturn(LOCAL_AS).when(this.baseAttributes).getLocalAs();
45         doReturn(IPV4).when(this.baseAttributes).getOriginatorId();
46     }
47
48
49     @Test
50     public void testAppend() {
51         Statement statement = this.basicStatements.stream()
52                 .filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
53         final RouteAttributeContainer attributeContainer
54                 = routeAttributeContainerFalse(new AttributesBuilder().build());
55         RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
56                 this.baseAttributes,
57                 this.exportParameters,
58                 attributeContainer,
59                 statement);
60
61         final Attributes expected = new AttributesBuilder()
62                 .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
63                 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
64                         .setGlobal(new Ipv4Address("4.5.6.7")).build()).build())
65                 .setLocalPref(new LocalPrefBuilder().setPref(100L).build())
66                 .setMultiExitDisc(new MultiExitDiscBuilder().setMed(15L).build())
67                 .build();
68         assertEquals(expected, result.getAttributes());
69     }
70 }