Update MRI projects for Aluminium
[bgpcep.git] / bgp / cli / src / main / java / org / opendaylight / protocol / bgp / cli / utils / PeerGroupStateCliUtils.java
1 /*
2  * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.cli.utils;
9
10 import static org.opendaylight.protocol.bgp.cli.utils.NeighborStateCliUtils.addHeader;
11
12 import java.io.PrintStream;
13 import java.util.Collection;
14 import org.apache.karaf.shell.support.table.ShellTable;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State;
17 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroup;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.PeerGroupStateAugmentation;
19
20 // PeerGroupStateCliUtils sends Peer Group Operational State to PrintStream
21 final class PeerGroupStateCliUtils {
22     private PeerGroupStateCliUtils() {
23         // Hidden on purpose
24     }
25
26     static void displayPeerOperationalState(@NonNull final Collection<PeerGroup> peerGroupList,
27             @NonNull final PrintStream stream) {
28         final ShellTable table = new ShellTable();
29         table.column("Attribute").alignLeft();
30         table.column("Value").alignLeft();
31
32         peerGroupList.forEach(group -> displayState(group, table));
33         table.print(stream);
34     }
35
36     private static void displayState(final PeerGroup group, final ShellTable table) {
37         addHeader(table, "Peer Group state");
38         table.addRow().addContent("Peer Group Name", group.getPeerGroupName());
39         final State state = group.getState();
40         if (state == null) {
41             return;
42         }
43         final PeerGroupStateAugmentation aug = state.augmentation(PeerGroupStateAugmentation.class);
44         table.addRow().addContent("Total Prefixes", aug.getTotalPrefixes());
45     }
46 }