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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
12 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
14 import com.google.common.collect.ImmutableMap;
15 import io.netty.channel.Channel;
16 import io.netty.channel.ChannelFuture;
17 import java.net.InetSocketAddress;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
23 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.BgpId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
32 public class AddPathBasePathsTest extends AbstractAddPathTest {
33 private RIBImpl ribImpl;
34 private Channel serverChannel;
38 public void setUp() throws Exception {
40 final TablesKey tk = new TablesKey(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE);
41 final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk,
42 BasePathSelectionModeFactory.createBestPathSelectionStrategy());
44 ribImpl = new RIBImpl(tableRegistry, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), ribExtension,
45 serverDispatcher, codecsRegistry, getDomBroker(), policies, TABLES_TYPE, pathTables);
46 ribImpl.instantiateServiceInstance();
47 final ChannelFuture channelFuture = serverDispatcher.createServer(
48 new InetSocketAddress(RIB_ID, PORT.toJava()));
49 waitFutureSuccess(channelFuture);
50 serverChannel = channelFuture.channel();
55 public void tearDown() throws Exception {
56 waitFutureSuccess(serverChannel.close());
63 * | ODL BGP 127.0.0.1 |
64 * [peer://127.0.0.2; p1, lp100] --(iBGP)--> | | --(RR-client, non add-path) -->
65 * [peer://127.0.0.3; p1, lp200] --(iBGP)--> | | [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
66 * [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(eBgp, non add-path) -->
67 * [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________| [Peer://127.0.0.6; (p1, path-id1, lp100),
68 * p1 = 1.1.1.1/32 (p1, path-id2, pl50), (p1, path-id3, pl200)]
71 public void testUseCase1() throws Exception {
72 final BgpParameters nonAddPathParams = createParameter(false);
74 configurePeer(tableRegistry, PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp, serverRegistry);
75 final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
77 configurePeer(tableRegistry, PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp, serverRegistry);
78 final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
80 configurePeer(tableRegistry, PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp, serverRegistry);
81 final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
83 final SimpleSessionListener listener4 = new SimpleSessionListener();
84 configurePeer(tableRegistry, PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient,
86 final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
88 final SimpleSessionListener listener5 = new SimpleSessionListener();
89 configurePeer(tableRegistry, PEER5, ribImpl, nonAddPathParams, PeerRole.Ebgp, serverRegistry);
90 final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
91 checkPeersPresentOnDataStore(5);
93 //new best route so far
94 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
95 checkReceivedMessages(listener4, 2);
96 checkReceivedMessages(listener5, 1);
97 assertEquals(UPD_NA_100, listener4.getListMsg().get(1));
99 //the second best route
100 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 100, 1);
101 checkReceivedMessages(listener4, 2);
102 checkReceivedMessages(listener5, 1);
105 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 1);
106 checkReceivedMessages(listener4, 3);
107 checkReceivedMessages(listener5, 1);
108 assertEquals(UPD_NA_200, listener4.getListMsg().get(2));
110 final SimpleSessionListener listener6 = new SimpleSessionListener();
111 configurePeer(tableRegistry, PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient,
113 final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
115 checkPeersPresentOnDataStore(6);
116 checkReceivedMessages(listener6, 2);
117 assertEquals(UPD_NA_200, listener6.getListMsg().get(1));
119 checkPeersPresentOnDataStore(5);
121 //best route updated to be the worse one
122 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 1);
123 checkReceivedMessages(listener4, 4);
124 checkReceivedMessages(listener5, 1);
125 assertEquals(UPD_NA_100, listener4.getListMsg().get(3));
127 //Remove second best, no advertisement should be done
128 sendWithdrawalRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 1);
129 checkReceivedMessages(listener4, 4);
130 checkReceivedMessages(listener5, 1);
132 //Remove best, 1 advertisement
133 sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
134 checkReceivedMessages(listener4, 5);
135 checkReceivedMessages(listener5, 1);
137 //Remove best, 1 withdrawal
138 sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 0);
139 checkReceivedMessages(listener4, 6);
140 checkReceivedMessages(listener5, 1);