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.class, UnicastSubsequentAddressFamily.class);
41 final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk,
42 BasePathSelectionModeFactory.createBestPathSelectionStrategy());
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);
48 this.ribImpl.instantiateServiceInstance();
49 final ChannelFuture channelFuture = this.serverDispatcher.createServer(
50 new InetSocketAddress(RIB_ID, PORT.toJava()));
51 waitFutureSuccess(channelFuture);
52 this.serverChannel = channelFuture.channel();
57 public void tearDown() throws Exception {
58 waitFutureSuccess(this.serverChannel.close());
65 * | ODL BGP 127.0.0.1 |
66 * [peer://127.0.0.2; p1, lp100] --(iBGP)--> | | --(RR-client, non add-path) -->
67 * [peer://127.0.0.3; p1, lp200] --(iBGP)--> | | [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
68 * [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(eBgp, non add-path) -->
69 * [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________| [Peer://127.0.0.6; (p1, path-id1, lp100),
70 * p1 = 1.1.1.1/32 (p1, path-id2, pl50), (p1, path-id3, pl200)]
73 public void testUseCase1() throws Exception {
74 final BgpParameters nonAddPathParams = createParameter(false);
76 configurePeer(this.tableRegistry, PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
77 final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
79 configurePeer(this.tableRegistry, PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
80 final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
82 configurePeer(this.tableRegistry, PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp, this.serverRegistry);
83 final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
85 final SimpleSessionListener listener4 = new SimpleSessionListener();
86 configurePeer(this.tableRegistry, PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
88 final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
90 final SimpleSessionListener listener5 = new SimpleSessionListener();
91 configurePeer(this.tableRegistry, PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp, this.serverRegistry);
92 final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
93 checkPeersPresentOnDataStore(5);
95 //new best route so far
96 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
97 checkReceivedMessages(listener4, 2);
98 checkReceivedMessages(listener5, 2);
99 assertEquals(UPD_NA_100, listener4.getListMsg().get(1));
100 assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(1));
102 //the second best route
103 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 100, 1);
104 checkReceivedMessages(listener4, 2);
105 checkReceivedMessages(listener5, 2);
108 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 1);
109 checkReceivedMessages(listener4, 3);
110 checkReceivedMessages(listener5, 3);
111 assertEquals(UPD_NA_200, listener4.getListMsg().get(2));
112 assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(2));
114 final SimpleSessionListener listener6 = new SimpleSessionListener();
115 configurePeer(this.tableRegistry, PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient,
116 this.serverRegistry);
117 final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
119 checkPeersPresentOnDataStore(6);
120 checkReceivedMessages(listener6, 2);
121 assertEquals(UPD_NA_200, listener6.getListMsg().get(1));
123 checkPeersPresentOnDataStore(5);
125 //best route updated to be the worse one
126 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 1);
127 checkReceivedMessages(listener4, 4);
128 checkReceivedMessages(listener5, 4);
129 assertEquals(UPD_NA_100, listener4.getListMsg().get(3));
130 assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(3));
132 //Remove second best, no advertisement should be done
133 sendWithdrawalRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 1);
134 checkReceivedMessages(listener4, 4);
135 checkReceivedMessages(listener5, 4);
137 //Remove best, 1 advertisement
138 sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
139 checkReceivedMessages(listener4, 5);
140 checkReceivedMessages(listener5, 5);
142 //Remove best, 1 withdrawal
143 sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 0);
144 checkReceivedMessages(listener4, 6);
145 checkReceivedMessages(listener5, 6);