2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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
9 package org.opendaylight.protocol.bgp.rib.impl;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
13 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
15 import com.google.common.collect.ImmutableMap;
16 import io.netty.channel.Channel;
17 import io.netty.channel.ChannelFuture;
18 import java.net.InetSocketAddress;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
24 import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
33 public class AddPathNPathsTest extends AbstractAddPathTest {
34 private RIBImpl ribImpl;
35 private Channel serverChannel;
39 public void setUp() throws Exception {
41 final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
42 final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2));
44 this.ribImpl = new RIBImpl(this.tableRegistry, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID),
46 this.serverDispatcher, this.codecsRegistry, getDomBroker(), getDataBroker(), this.policies,
47 TABLES_TYPE, pathTables);
49 this.ribImpl.instantiateServiceInstance();
50 this.ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext());
51 final ChannelFuture channelFuture = this.serverDispatcher.createServer(
52 new InetSocketAddress(RIB_ID, PORT.toJava()));
53 waitFutureSuccess(channelFuture);
54 this.serverChannel = channelFuture.channel();
59 public void tearDown() throws Exception {
60 waitFutureSuccess(this.serverChannel.close());
67 * | ODL BGP 127.0.0.1 |
68 * [peer://127.0.0.2; p1, lp100] --(iBGP)--> | | --(RR-client, non add-path) -->
69 * [peer://127.0.0.3; p1, lp200] --(iBGP)--> | | [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
70 * [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(RR-client, add-path) -->
71 * [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________| [Peer://127.0.0.6; (p1, path-id1, lp100),
72 * p1 = 1.1.1.1/32 (p1, path-id2, pl50), (p1, path-id3, pl200)]
75 public void testUseCase1() throws Exception {
76 final BgpParameters nonAddPathParams = createParameter(false);
77 final BgpParameters addPathParams = createParameter(true);
79 configurePeer(this.tableRegistry, PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
80 final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
82 configurePeer(this.tableRegistry, PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
83 final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
85 configurePeer(this.tableRegistry, PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
86 final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
88 final SimpleSessionListener listener4 = new SimpleSessionListener();
89 configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
91 final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
93 final SimpleSessionListener listener5 = new SimpleSessionListener();
94 configurePeer(this.tableRegistry, PEER5, this.ribImpl, addPathParams, PeerRole.RrClient, this.serverRegistry);
95 final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
96 checkPeersPresentOnDataStore(5);
98 //new best route so far
99 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
100 checkReceivedMessages(listener4, 2);
101 checkReceivedMessages(listener5, 2);
102 assertEquals(UPD_100, listener5.getListMsg().get(1));
104 final SimpleSessionListener listener6 = new SimpleSessionListener();
105 configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
106 this.serverRegistry);
107 final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
108 checkPeersPresentOnDataStore(6);
109 checkReceivedMessages(listener6, 2);
110 assertEquals(UPD_NA_100, listener6.getListMsg().get(1));
112 checkPeersPresentOnDataStore(5);
114 //the second best route
115 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
116 checkReceivedMessages(listener4, 2);
117 checkReceivedMessages(listener5, 3);
118 assertEquals(UPD_50, listener5.getListMsg().get(2));
121 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
122 checkReceivedMessages(listener4, 3);
123 checkReceivedMessages(listener5, 4);
124 assertEquals(UPD_200, listener5.getListMsg().get(3));
126 //the worst prefix, no changes
127 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 20, 2);
128 checkReceivedMessages(listener4, 3);
129 checkReceivedMessages(listener5, 4);
131 //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, none for non add path
132 sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
133 checkReceivedMessages(listener4, 3);
134 checkReceivedMessages(listener5, 6);
136 //we advertise again to try new test
137 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
138 checkReceivedMessages(listener4, 3);
139 checkReceivedMessages(listener5, 7);
141 //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported,
142 // 1 withdrawal for non add path
143 sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
144 checkReceivedMessages(listener4, 4);
145 checkReceivedMessages(listener5, 9);