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;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableMap;
15 import io.netty.channel.Channel;
16 import java.net.InetSocketAddress;
17 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
21 import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
22 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
32 public class AddPathNPathsTest extends AbstractAddPathTest {
37 * | ODL BGP 127.0.0.1 |
38 * [peer://127.0.0.2; p1, lp100] --(iBGP)--> | | --(RR-client, non add-path) --> [Peer://127.0.0.5; (p1, lp100), (p1, lp1200)]
39 * [peer://127.0.0.3; p1, lp200] --(iBGP)--> | |
40 * [peer://127.0.0.4; p1, lp50] --(iBGP)--> | | --(RR-client, add-path) --> [Peer://127.0.0.6; (p1, path-id1, lp100), (p1, path-id2, pl50), (p1, path-id3, pl200)]
41 * [peer://127.0.0.2; p1, lp20] --(iBGP)--> |___________________|
45 public void testUseCase1() throws Exception {
47 final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
48 final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
49 final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
51 final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
52 this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
54 ribImpl.instantiateServiceInstance();
55 ribImpl.onGlobalContextUpdated(this.schemaContext);
57 this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)).sync();
60 final BGPHandlerFactory hf = new BGPHandlerFactory(this.context.getMessageRegistry());
61 final BgpParameters nonAddPathParams = createParameter(false);
62 final BgpParameters addPathParams = createParameter(true);
64 final Channel session1 = createPeerSession(PEER1, PeerRole.Ibgp, nonAddPathParams, ribImpl, hf, new SimpleSessionListener());
65 final Channel session2 = createPeerSession(PEER2, PeerRole.Ibgp, nonAddPathParams, ribImpl, hf, new SimpleSessionListener());
66 final Channel session3 = createPeerSession(PEER3, PeerRole.Ibgp, nonAddPathParams, ribImpl, hf, new SimpleSessionListener());
67 final SimpleSessionListener listener4 = new SimpleSessionListener();
68 final Channel session4 = createPeerSession(PEER4, PeerRole.RrClient, nonAddPathParams, ribImpl, hf, listener4);
69 final SimpleSessionListener listener5 = new SimpleSessionListener();
70 final Channel session5 = createPeerSession(PEER5, PeerRole.RrClient, addPathParams, ribImpl, hf, listener5);
72 checkPeersPresentOnDataStore(5);
74 //new best route so far
75 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 1);
76 assertEquals(1, listener4.getListMsg().size());
77 assertEquals(1, listener5.getListMsg().size());
78 assertEquals(UPD_100, listener5.getListMsg().get(0));
80 final SimpleSessionListener listener6 = new SimpleSessionListener();
81 final Channel session6 = createPeerSession(PEER6, PeerRole.RrClient, nonAddPathParams, ribImpl, hf, listener6);
83 checkPeersPresentOnDataStore(6);
84 assertEquals(1, listener6.getListMsg().size());
85 assertEquals(UPD_NA_100, listener6.getListMsg().get(0));
89 //the second best route
90 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 50, 2);
91 assertEquals(1, listener4.getListMsg().size());
92 assertEquals(2, listener5.getListMsg().size());
93 assertEquals(UPD_50, listener5.getListMsg().get(1));
96 sendRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
97 assertEquals(2, listener4.getListMsg().size());
98 assertEquals(3, listener5.getListMsg().size());
99 assertEquals(UPD_200, listener5.getListMsg().get(2));
101 //the worst prefix, no changes
102 sendRouteAndCheckIsOnLocRib(session2, PREFIX1, 20, 2);
103 assertEquals(2, listener4.getListMsg().size());
104 assertEquals(3, listener5.getListMsg().size());
106 //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, none for non add path
107 sendWithdrawalRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
108 assertEquals(2, listener4.getListMsg().size());
109 assertEquals(5, listener5.getListMsg().size());
111 //we advertise again to try new test
112 sendRouteAndCheckIsOnLocRib(session1, PREFIX1, 100, 2);
113 assertEquals(2, listener4.getListMsg().size());
114 assertEquals(6, listener5.getListMsg().size());
116 //withdraw second best route, 2 advertisement (1 withdrawal) for add-path supported, 1 withdrawal for non add path
117 sendWithdrawalRouteAndCheckIsOnLocRib(session3, PREFIX1, 200, 2);
118 assertEquals(3, listener4.getListMsg().size());
119 assertEquals(8, listener5.getListMsg().size());