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.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.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.bgp.types.rev151009.IPV4UNICAST;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.LocalPrefBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.OriginBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpOrigin;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
30 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;
31 import org.opendaylight.yangtools.yang.common.Uint32;
33 public class AppendActionTest extends AbstractStatementRegistryTest {
35 private BGPRouteEntryExportParameters exportParameters;
36 private List<Statement> basicStatements;
38 private RouteEntryBaseAttributes baseAttributes;
42 public void setUp() throws Exception {
44 this.basicStatements = loadStatement("basic-statements-test");
45 doReturn(CLUSTER).when(this.baseAttributes).getClusterId();
46 doReturn(LOCAL_AS).when(this.baseAttributes).getLocalAs();
47 doReturn(IPV4).when(this.baseAttributes).getOriginatorId();
52 public void testMultipleAppend() {
53 Statement statement = this.basicStatements.stream()
54 .filter(st -> st.getName().equals("multiple-append-test")).findFirst().get();
55 final RouteAttributeContainer attributeContainer
56 = routeAttributeContainerFalse(new AttributesBuilder().build());
57 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
60 this.exportParameters,
64 final Attributes expected = new AttributesBuilder()
65 .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
66 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
67 .setGlobal(new Ipv4Address("4.5.6.7")).build()).build())
68 .setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build())
69 .setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.valueOf(15)).build())
71 assertEquals(expected, result.getAttributes());
75 public void testNextHopSelf() {
76 Statement statement = this.basicStatements.stream()
77 .filter(st -> st.getName().equals("next-hop-self-append-test")).findFirst().get();
78 final RouteAttributeContainer attributeContainer
79 = routeAttributeContainerFalse(new AttributesBuilder().build());
80 RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
83 this.exportParameters,
87 final Attributes expected = new AttributesBuilder()
88 .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
89 .setGlobal(IPV4).build()).build())
91 assertEquals(expected, result.getAttributes());