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.bgp.rib.impl.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 java.util.concurrent.ExecutionException;
21 import org.junit.After;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
25 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
34 public class AddPathBasePathsTest extends AbstractAddPathTest {
35 private RIBImpl ribImpl;
36 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,
43 BasePathSelectionModeFactory.createBestPathSelectionStrategy());
45 this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
46 AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
47 this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
48 this.ribExtension.getClassLoadingStrategy(), null);
49 this.ribImpl.instantiateServiceInstance();
50 this.ribImpl.onGlobalContextUpdated(this.schemaContext);
51 final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
52 new InetSocketAddress(RIB_ID, PORT));
53 waitFutureSuccess(channelFuture);
54 this.serverChannel = channelFuture.channel();
58 public void tearDown() throws ExecutionException, InterruptedException {
59 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) --> [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
67 * [peer://127.0.0.3; p1, lp200] --(iBGP)--> | |
68 * [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(eBgp, non add-path) --> [Peer://127.0.0.6; (p1, path-id1, lp100), (p1, path-id2, pl50), (p1, path-id3, pl200)]
69 * [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________|
73 public void testUseCase1() throws Exception {
74 final BgpParameters nonAddPathParams = createParameter(false);
76 configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
77 final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
79 configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
80 final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
82 configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
83 final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
85 final SimpleSessionListener listener4 = new SimpleSessionListener();
86 configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
87 final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
89 final SimpleSessionListener listener5 = new SimpleSessionListener();
90 configurePeer(PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp);
91 final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
92 checkPeersPresentOnDataStore(5);
94 //new best route so far
95 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
96 checkReceivedMessages(listener4, 1);
97 checkReceivedMessages(listener5, 1);
98 assertEquals(UPD_NA_100, listener4.getListMsg().get(0));
99 assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(0));
101 //the second best route
102 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 1);
103 checkReceivedMessages(listener4, 1);
104 checkReceivedMessages(listener5, 1);
107 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 1);
108 checkReceivedMessages(listener4, 2);
109 checkReceivedMessages(listener5, 2);
110 assertEquals(UPD_NA_200, listener4.getListMsg().get(1));
111 assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(1));
113 final SimpleSessionListener listener6 = new SimpleSessionListener();
114 configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
115 final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
117 checkPeersPresentOnDataStore(6);
118 checkReceivedMessages(listener6, 1);
119 assertEquals(UPD_NA_200, listener6.getListMsg().get(0));
121 checkPeersPresentOnDataStore(5);
123 //best route updated to be the worse one
124 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 1);
125 checkReceivedMessages(listener4, 3);
126 checkReceivedMessages(listener5, 3);
127 assertEquals(UPD_NA_100, listener4.getListMsg().get(2));
128 assertEquals(UPD_NA_100_EBGP, listener5.getListMsg().get(2));
130 //Remove second best, no advertisement should be done
131 sendWithdrawalRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 1);
132 checkReceivedMessages(listener4, 3);
133 checkReceivedMessages(listener5, 3);
135 //Remove best, 1 advertisement
136 sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
137 checkReceivedMessages(listener4, 4);
138 checkReceivedMessages(listener5, 4);
140 //Remove best, 1 withdrawal
141 sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 20, 0);
142 checkReceivedMessages(listener4, 5);
143 checkReceivedMessages(listener5, 5);