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.mode.impl.base;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.mockito.Mockito.doReturn;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 public class BaseRouteEntryTest extends AbstractRouteEntryTest {
23 private BaseSimpleRouteEntry testBARE;
31 public void testBaseSimpleRouteEntry() throws Exception {
32 this.testBARE = new BaseSimpleRouteEntry();
33 testWriteEmptyBestPath();
34 testAddRouteSelectBestAndWriteOnDS();
35 testRewriteSameRoute();
36 testInitializePeerWithExistentRoute();
40 private void testRemoveRoute() {
41 Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
42 assertEquals(8, yiiCount.size());
43 assertEquals(1, (long) yiiCount.get(this.routePaYii));
44 this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID);
45 this.testBARE.selectBest(AS);
46 this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx);
47 yiiCount = collectInfo();
48 assertFalse(yiiCount.containsKey(this.routePaYii));
49 assertFalse(yiiCount.containsKey(this.routeAddRiboutAttYii));
52 private void testInitializePeerWithExistentRoute() {
53 doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId();
54 this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
55 assertEquals(8, this.yiichanges.size());
56 Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
57 assertEquals(1, (long) yiiCount.get(this.routeRiboutYiiPeer2));
58 assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYiiPeer2));
61 private void testRewriteSameRoute() {
62 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
63 assertEquals(1, this.testBARE.getOffsets().size());
64 assertFalse(this.testBARE.selectBest(AS));
67 private void testAddRouteSelectBestAndWriteOnDS() {
68 this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
69 assertFalse(this.testBARE.getOffsets().isEmpty());
70 this.testBARE.selectBest(AS);
71 this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx);
72 Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
73 assertEquals(3, yiiCount.size());
74 assertEquals(1, (long) yiiCount.get(this.routePaYii));
75 assertEquals(1, (long) yiiCount.get(this.routeRiboutYii));
76 assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYii));
77 this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx);
78 yiiCount = collectInfo();
79 assertEquals(6, yiiCount.size());
80 assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
81 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
82 assertEquals(1, (long) yiiCount.get(this.routeAddRiboutAttYii));
85 private void testWriteEmptyBestPath() {
86 doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId();
87 this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx);
88 assertEquals(0, this.yiichanges.size());