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.stats.rib.impl;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.doReturn;
15 import java.util.Collections;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.config.api.IdentityAttributeRef;
22 import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
23 import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
24 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
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 BGPRenderStatsImplTest {
35 private static final BgpId BGP_ID = new BgpId("127.0.0.1");
36 private static final RibId RIB_ID = new RibId("test-rib");
37 private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("192.168.1.2");
38 private static final AsNumber AS = new AsNumber(0x10L);
39 private static final ZeroBasedCounter32 COUTER = new ZeroBasedCounter32(0L);
40 private static final ZeroBasedCounter32 COUTER_ONE_ROUTE = new ZeroBasedCounter32(1L);
41 private final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
44 private BGPRIBState bgpGlobalState;
48 MockitoAnnotations.initMocks(this);
51 public void getBgpRenderState() throws Exception {
52 final BGPRenderStatsImpl render = new BGPRenderStatsImpl(BGP_ID, RIB_ID, AS, CLUSTER_ID, this.bgpGlobalState,
53 Collections.singleton(this.tk));
55 final BgpRenderState renderStateExpected = new BgpRenderState();
56 renderStateExpected.setRibId(RIB_ID);
57 renderStateExpected.setBgpRibId(BGP_ID);
58 renderStateExpected.setClusterId(CLUSTER_ID);
59 renderStateExpected.setLocalAs(AS);
60 renderStateExpected.setConfiguredPeerCount(COUTER);
61 renderStateExpected.setConnectedPeerCount(COUTER);
62 final LocRibRouteTable locRibTable = new LocRibRouteTable();
63 locRibTable.setAfi(new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()));
64 locRibTable.setSafi(new IdentityAttributeRef(UnicastSubsequentAddressFamily.QNAME.toString()));
65 locRibTable.setRoutesCount(COUTER);
66 final List<LocRibRouteTable> locRibRouteTableList = Collections.singletonList(locRibTable);
67 renderStateExpected.setLocRibRouteTable(locRibRouteTableList);
68 renderStateExpected.setLocRibRoutesCount(COUTER);
69 doReturn(0L).when(this.bgpGlobalState).getPathCount(eq(this.tk));
71 assertEquals(renderStateExpected, render.getBgpRenderState());
72 doReturn(1L).when(this.bgpGlobalState).getPathCount(eq(this.tk));
73 locRibTable.setRoutesCount(COUTER_ONE_ROUTE);
74 renderStateExpected.setLocRibRoutesCount(COUTER_ONE_ROUTE);
75 assertEquals(renderStateExpected, render.getBgpRenderState());
76 render.getConfiguredPeerCounter().increment();
77 assertEquals(1L, render.getConfiguredPeerCounter().longValue());
78 render.getConnectedPeerCounter().increment();
79 assertEquals(1L, render.getConnectedPeerCounter().longValue());