2 * Copyright (c) 2015 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.mode.impl.add.n.paths;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 public final class SimpleRouteEntryTest extends AbstractRouteEntryTest {
21 private static final long N_PATHS = 2;
22 private SimpleRouteEntry testBARE;
30 public void testSimpleRouteEntry() throws Exception {
31 this.testBARE = (SimpleRouteEntry) new AddPathBestNPathSelection(N_PATHS).createRouteEntry(false);
32 testWriteEmptyBestPath();
33 testAddRouteSelectBestAndWriteOnDS();
34 testRewriteSameRoute();
35 testInitializePeerWithExistentRoute();
39 @Test(expected = NullPointerException.class)
40 public void testAddRouteSelectBestAndWriteOnDSs() {
41 /** Add non Add Path Route **/
42 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
45 private void testWriteEmptyBestPath() {
46 this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport,
48 assertEquals(0, this.yiichanges.size());
51 private void testAddRouteSelectBestAndWriteOnDS() {
52 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(),
54 assertFalse(this.testBARE.isEmpty());
55 assertTrue(this.testBARE.selectBest(AS));
56 /** Add AddPath Route **/
57 this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx,
58 ROUTE_ID_PA_ADD_PATH);
59 final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
60 assertEquals(3, yiiCount.size());
61 assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
62 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
63 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutAttYii));
66 private void testRewriteSameRoute() {
67 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
68 assertFalse(this.testBARE.selectBest(AS));
71 private void testInitializePeerWithExistentRoute() {
72 assertEquals(3, this.yiichanges.size());
73 this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA_ADD_PATH, PEER_YII2, this.peg, TABLES_KEY, this.peerPT,
74 this.ribSupport, this.tx);
75 assertEquals(5, this.yiichanges.size());
76 final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
77 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
78 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
81 private void testRemoveRoute() {
82 Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
83 assertEquals(5, yiiCount.size());
84 assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
85 assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID));
86 assertTrue(this.testBARE.selectBest(AS));
87 this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx,
88 ROUTE_ID_PA_ADD_PATH);
89 yiiCount = collectInfo();
90 assertEquals(2, yiiCount.size());
91 assertFalse(yiiCount.containsKey(this.routePaAddPathYii));
92 assertFalse(yiiCount.containsKey(this.routeAddRiboutYii));