BGPCEP-702: Migrate Cli to Operational State 27/65027/3
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Fri, 20 Oct 2017 08:29:25 +0000 (10:29 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 6 Nov 2017 06:59:01 +0000 (07:59 +0100)
Old bgp stats are being removed, therefore
we use new operational state stats for cli
- Enforce checkstyle

Change-Id: Iabe50a392db7eacb70b0533c65ecee7e683aba4c
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
25 files changed:
bgp/cli/pom.xml
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/AbstractStatsCommandProvider.java [deleted file]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/OperationalStateCommandProvider.java [new file with mode: 0644]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ResetBGPStatsCommandProvider.java [deleted file]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ShowBGPStatsCommandProvider.java [deleted file]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtils.java [new file with mode: 0644]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtils.java [deleted file]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtils.java [new file with mode: 0644]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtils.java [new file with mode: 0644]
bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtils.java [new file with mode: 0644]
bgp/cli/src/main/resources/OSGI-INF/blueprint/commands.xml [deleted file]
bgp/cli/src/main/resources/org/opendaylight/blueprint/bgp-cli.xml [new file with mode: 0644]
bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtilsTest.java [new file with mode: 0644]
bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtilsTests.java [deleted file]
bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtilsTest.java [new file with mode: 0644]
bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtilsTest.java [new file with mode: 0644]
bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtilsTest.java [new file with mode: 0644]
bgp/cli/src/test/resources/empty-global.txt [new file with mode: 0644]
bgp/cli/src/test/resources/empty-neighbor.txt [new file with mode: 0644]
bgp/cli/src/test/resources/empty-peer-group.txt [new file with mode: 0644]
bgp/cli/src/test/resources/global.txt [new file with mode: 0644]
bgp/cli/src/test/resources/neighbor.txt [new file with mode: 0644]
bgp/cli/src/test/resources/peer-group.txt [new file with mode: 0644]
features/bgp/odl-bgpcep-bgp-cli/pom.xml
features/bgp/odl-bgpcep-bgp/pom.xml

index 1156cfddc02012301143126ee9c6483b8ad09d84..bda22cc8bea059c6e36fe229d529e96f63929a11 100644 (file)
@@ -8,7 +8,8 @@
  and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
     <parent>
     <dependencies>
         <dependency>
             <groupId>${project.groupId}</groupId>
-            <artifactId>bgp-parser-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>bgp-rib-impl</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>bgp-concepts</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>concepts</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>yang-binding</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-common</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>concepts</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>config-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.mdsal.model</groupId>
-            <artifactId>ietf-inet-types</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
+            <artifactId>bgp-openconfig-api</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.karaf.shell</groupId>
             <version>${karaf.version}</version>
             <scope>provided</scope>
         </dependency>
-
+        <!--Test dependencies-->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
-             <groupId>junit</groupId>
-             <artifactId>junit</artifactId>
-         </dependency>
-         <dependency>
-             <groupId>org.mockito</groupId>
-             <artifactId>mockito-core</artifactId>
-             <scope>test</scope>
-         </dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-broker-impl</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
     </dependencies>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/AbstractStatsCommandProvider.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/AbstractStatsCommandProvider.java
deleted file mode 100644 (file)
index f9fcc67..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.cli;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.lang.management.ManagementFactory;
-import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.management.JMX;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerModuleFactory;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
-
-public abstract class AbstractStatsCommandProvider extends OsgiCommandSupport {
-    private static final ObjectName BGP_PEER_MODULE_PATTERN = ObjectNameUtil.createRuntimeBeanPattern(BGPPeerModuleFactory.NAME, null);
-
-    private static final MBeanServer MBEAN_SERVER = ManagementFactory.getPlatformMBeanServer();
-
-    @Override
-    protected final Object doExecute() throws Exception {
-        final PrintStream out = this.session.getConsole();
-        getObjectNames().forEach(objectName -> onExecution(out, getRuntimeMXBean(objectName), objectName));
-        return null;
-    }
-
-    protected abstract void onExecution(@Nonnull PrintStream out, @Nonnull BGPPeerRuntimeMXBean peerRuntimeMXBean, @Nonnull ObjectName objectName);
-
-    private static Set<ObjectName> getObjectNames() throws IOException {
-        return MBEAN_SERVER.queryNames(BGP_PEER_MODULE_PATTERN, null);
-    }
-
-    private static BGPPeerRuntimeMXBean getRuntimeMXBean(final ObjectName objectName) {
-        return JMX.newMXBeanProxy(MBEAN_SERVER, objectName, BGPPeerRuntimeMXBean.class);
-    }
-}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/OperationalStateCommandProvider.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/OperationalStateCommandProvider.java
new file mode 100644 (file)
index 0000000..07e0b63
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli;
+
+import static java.util.Objects.requireNonNull;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.protocol.bgp.cli.utils.BGPOperationalStateUtils;
+
+@Command(scope = "bgp", name = "operational-state", description = "Shows BGP Operational State.")
+public final class OperationalStateCommandProvider extends OsgiCommandSupport {
+    private DataBroker dataBroker;
+    @Option(name = "-neighbor", aliases = {"--neighbor"}, description = "Neighbor address")
+    private String peer;
+    @Option(name = "-rib", aliases = {"--rib"}, description = "Name of RIB", required = true)
+    private String ribId;
+    @Option(name = "-peer-group", aliases = {"--peer-group"}, description = "Name of Peer Group")
+    private String group;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        BGPOperationalStateUtils.displayBgpOperationalState(this.dataBroker, this.session.getConsole(),
+                this.ribId, this.group, this.peer);
+        return null;
+    }
+
+    public void setDataBroker(final DataBroker dataBroker) {
+        this.dataBroker = requireNonNull(dataBroker);
+    }
+}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ResetBGPStatsCommandProvider.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ResetBGPStatsCommandProvider.java
deleted file mode 100644 (file)
index 2f3b90b..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.cli;
-
-import java.io.PrintStream;
-import javax.annotation.Nonnull;
-import javax.management.ObjectName;
-import org.apache.karaf.shell.commands.Command;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
-
-@Command(scope = "bgp", name = "reset-stats", description = "Reset BGP stats.")
-public class ResetBGPStatsCommandProvider extends AbstractStatsCommandProvider {
-
-    @Override
-    protected void onExecution(@Nonnull PrintStream out, @Nonnull BGPPeerRuntimeMXBean peerRuntimeMXBean,
-                               @Nonnull ObjectName objectName) {
-        peerRuntimeMXBean.resetSession();
-        out.println(String.format("BGP Statistics reset for [%s]!", objectName));
-    }
-}
-
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ShowBGPStatsCommandProvider.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/ShowBGPStatsCommandProvider.java
deleted file mode 100644 (file)
index 3134021..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.cli;
-
-import java.io.PrintStream;
-import javax.annotation.Nonnull;
-import javax.management.ObjectName;
-import org.apache.felix.gogo.commands.Command;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
-import org.opendaylight.protocol.bgp.cli.utils.BgpCliUtils;
-
-@Command(scope = "bgp", name = "show-stats", description = "Shows BGP stats.")
-public class ShowBGPStatsCommandProvider extends AbstractStatsCommandProvider {
-
-    @Override
-    protected void onExecution(@Nonnull PrintStream out, @Nonnull BGPPeerRuntimeMXBean peerRuntimeMXBean,
-                               @Nonnull ObjectName objectName) {
-        final BgpSessionState state = peerRuntimeMXBean.getBgpSessionState();
-        BgpCliUtils.displayAll(objectName, state, out);
-    }
-}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtils.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtils.java
new file mode 100644 (file)
index 0000000..ce7571f
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.opendaylight.protocol.bgp.cli.utils.GlobalStateCliUtils.displayRibOperationalState;
+import static org.opendaylight.protocol.bgp.cli.utils.NeighborStateCliUtils.displayNeighborOperationalState;
+import static org.opendaylight.protocol.bgp.cli.utils.PeerGroupStateCliUtils.displayPeerOperationalState;
+
+import java.io.PrintStream;
+import java.util.concurrent.ExecutionException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstanceKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * BGPOperationalStateUtils reads Operational state from DS and prints to stream.
+ */
+public final class BGPOperationalStateUtils {
+
+    static final InstanceIdentifier<Protocols> PROTOCOLS_IID;
+    private static final Logger LOG = LoggerFactory.getLogger(BGPOperationalStateUtils.class);
+
+    static {
+        PROTOCOLS_IID = InstanceIdentifier.create(NetworkInstances.class)
+                .child(NetworkInstance.class, new NetworkInstanceKey("global-bgp")).child(Protocols.class);
+    }
+
+    @SuppressWarnings("checkstyle:HideUtilityClassConstructor")
+    private BGPOperationalStateUtils() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Display to stream operational state, rib Id is mandatory.
+     *
+     * @param dataBroker data broker
+     * @param stream     where to print
+     * @param ribId      mandatory, Operational State per given RIB Group will be printed
+     *                   if no other parameter is passed
+     * @param group      if provided, Operational State per given Neighbor Group will be printed
+     * @param neighbor   if provided, Operational State per given Neighbor will be printed
+     */
+    public static void displayBgpOperationalState(@NonNull final DataBroker dataBroker,
+            @NonNull final PrintStream stream, @NonNull final String ribId, @Nullable final String group,
+            @Nullable final String neighbor) {
+        final Bgp globalBgp = readGlobalFromDataStore(dataBroker, ribId);
+        if (globalBgp == null) {
+            stream.println(String.format("RIB not found for [%s]", ribId));
+            return;
+        }
+        if (neighbor == null && group == null) {
+            displayRibOperationalState(ribId, globalBgp.getGlobal(), stream);
+        } else {
+            if (neighbor != null) {
+                globalBgp.getNeighbors().getNeighbor().stream()
+                        .filter(neig -> Ipv4Util.toStringIP(neig.getKey().getNeighborAddress()).matches(neighbor))
+                        .findFirst()
+                        .ifPresent(neighbor1 -> displayNeighborOperationalState(neighbor, neighbor1, stream));
+            } else {
+                displayPeerOperationalState(globalBgp.getPeerGroups().getPeerGroup(), stream);
+            }
+        }
+
+    }
+
+    private static Bgp readGlobalFromDataStore(final DataBroker dataBroker, final String ribId) {
+        final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID
+                .child(Protocol.class, new ProtocolKey(BGP.class, ribId))
+                .augmentation(Protocol1.class).child(Bgp.class);
+
+        final ReadOnlyTransaction rot = dataBroker.newReadOnlyTransaction();
+
+        try {
+            return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orNull();
+        } catch (final InterruptedException | ExecutionException e) {
+            LOG.warn("Failed to read rib {}", ribId, e);
+        }
+        return null;
+    }
+}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtils.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtils.java
deleted file mode 100644 (file)
index 4db67c7..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.cli.utils;
-
-import java.io.PrintStream;
-import javax.management.ObjectName;
-import org.apache.karaf.shell.table.ShellTable;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.LocalPeerPreferences;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.MessagesStats;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.RemotePeerPreferences;
-
-public final class BgpCliUtils {
-    private static final String MESSAGE_STATS_LABEL = "MessagesStats.";
-    private static final String PEER_PREFERENCES_LABEL = "PeerPreferences.";
-    private static final String SPEAKER_PREFERENCES_LABEL = "SpeakerPreferences.";
-
-    private BgpCliUtils() {
-        throw new UnsupportedOperationException();
-    }
-    public static void displayAll(final ObjectName objectName, final BgpSessionState bgpSessionState, final PrintStream printStream) {
-        if (bgpSessionState == null) {
-            printStream.println(String.format("No BgpSessionState found for [%s]", objectName));
-            return;
-        }
-        final ShellTable table = new ShellTable();
-        table.column("Attribute").alignLeft();
-        table.column("Value").alignLeft();
-        table.addRow().addContent("Object Name", objectName.getCanonicalName());
-        table.addRow().addContent("HoldtimeCurrent", bgpSessionState.getHoldtimeCurrent());
-        table.addRow().addContent("KeepaliveCurrent", bgpSessionState.getKeepaliveCurrent());
-        table.addRow().addContent("SessionDuration", bgpSessionState.getSessionDuration());
-        table.addRow().addContent("SessionState", bgpSessionState.getSessionState());
-
-        //Messages Stats
-        final MessagesStats messageStats = bgpSessionState.getMessagesStats();
-        if (messageStats != null) {
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "ErrorMsgsSent", messageStats.getErrorMsgs().getErrorSent().size());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "ErrorMsgsReceived", messageStats.getErrorMsgs().getErrorReceived().size());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "KeepAliveMsgsSent", messageStats.getKeepAliveMsgs().getSent().getCount());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "KeepAliveMsgsReceived", messageStats.getKeepAliveMsgs().getReceived().getCount());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "TotalMsgsSent", messageStats.getTotalMsgs().getSent().getCount());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "TotalMsgsReceived", messageStats.getTotalMsgs().getReceived().getCount());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "UpdateMsgsSent", messageStats.getUpdateMsgs().getSent().getCount());
-            table.addRow().addContent(MESSAGE_STATS_LABEL + "UpdateMsgsReceived", messageStats.getUpdateMsgs().getReceived().getCount());
-        }
-
-        //Peer Preferences
-        final LocalPeerPreferences peerPreferences = bgpSessionState.getLocalPeerPreferences();
-        if (peerPreferences != null) {
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "AddPathCapability", peerPreferences.getAdvertisedAddPathTableTypes());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "AS", peerPreferences.getAs());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "BgpExtendedMessageCapability", peerPreferences.getBgpExtendedMessageCapability());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "BgpId", peerPreferences.getBgpId());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "FourOctetAsCapability", peerPreferences.getFourOctetAsCapability());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "GrCapability", peerPreferences.getGrCapability());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "Port", peerPreferences.getPort());
-            table.addRow().addContent(PEER_PREFERENCES_LABEL + "RouteRefreshCapability", peerPreferences.getRouteRefreshCapability());
-        }
-
-        //Speaker Preferences
-        final RemotePeerPreferences speakerPreferences = bgpSessionState.getRemotePeerPreferences();
-        if (speakerPreferences != null) {
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "AddPathCapability", speakerPreferences.getAdvertisedAddPathTableTypes());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "AS", speakerPreferences.getAs());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "BgpExtendedMessageCapability", speakerPreferences.getBgpExtendedMessageCapability());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "BgpId", speakerPreferences.getBgpId());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "FourOctetAsCapability", speakerPreferences.getFourOctetAsCapability());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "GrCapability", speakerPreferences.getGrCapability());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "Port", speakerPreferences.getPort());
-            table.addRow().addContent(SPEAKER_PREFERENCES_LABEL + "RouteRefreshCapability", speakerPreferences.getRouteRefreshCapability());
-        }
-
-        table.print(printStream);
-    }
-}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtils.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtils.java
new file mode 100644 (file)
index 0000000..62f74c7
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.opendaylight.protocol.bgp.cli.utils.NeighborStateCliUtils.addHeader;
+
+import java.io.PrintStream;
+import org.apache.karaf.shell.table.ShellTable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.GlobalAfiSafiStateAugmentation;
+
+//GlobalStateCliUtils sends Global Operational State to PrintStream
+final class GlobalStateCliUtils {
+
+    @SuppressWarnings("checkstyle:HideUtilityClassConstructor")
+    private GlobalStateCliUtils() {
+        throw new UnsupportedOperationException();
+    }
+
+
+    static void displayRibOperationalState(@NonNull final String ribId, @NonNull final Global global,
+            @NonNull final PrintStream stream) {
+        final State globalState = global.getState();
+
+        final ShellTable table = new ShellTable();
+        table.column("Attribute").alignLeft();
+        table.column("Value").alignLeft();
+
+        addHeader(table, "RIB state");
+        table.addRow().addContent("Router Id", ribId);
+        table.addRow().addContent("As", globalState.getAs());
+        table.addRow().addContent("Total Paths", globalState.getTotalPaths());
+        table.addRow().addContent("Total Prefixes", globalState.getTotalPrefixes());
+        global.getAfiSafis().getAfiSafi().forEach(afiSafi -> displayAfiSafi(afiSafi, table));
+        table.print(stream);
+    }
+
+    private static void displayAfiSafi(final AfiSafi afiSafi, final ShellTable table) {
+        final GlobalAfiSafiStateAugmentation state = afiSafi.getState()
+                .getAugmentation(GlobalAfiSafiStateAugmentation.class);
+        addHeader(table, "AFI/SAFI state");
+        table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
+        if (state == null) {
+            return;
+        }
+        table.addRow().addContent("Total Paths", state.getTotalPaths());
+        table.addRow().addContent("Total Prefixes", state.getTotalPrefixes());
+    }
+}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtils.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtils.java
new file mode 100644 (file)
index 0000000..0981bc3
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import java.io.PrintStream;
+import java.util.List;
+import org.apache.karaf.shell.table.ShellTable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.operational.rev151009.bgp.neighbor.prefix.counters_state.Prefixes;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Timers;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Transport;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.BgpCapability;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.BgpNeighborStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborAfiSafiStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTimersStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTransportStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.Messages;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent;
+
+//NeighborStateCliUtils sends Neighbor Operational State to PrintStream
+final class NeighborStateCliUtils {
+    @SuppressWarnings("checkstyle:HideUtilityClassConstructor")
+    private NeighborStateCliUtils() {
+        throw new UnsupportedOperationException();
+    }
+
+    static void displayNeighborOperationalState(@NonNull final String neighborId,
+            @NonNull final Neighbor neighbor, @NonNull final PrintStream stream) {
+        final State neighborState = neighbor.getState();
+        if (neighborState == null) {
+            stream.println(String.format("No BgpSessionState found for [%s]", neighborId));
+            return;
+        }
+
+        final ShellTable table = new ShellTable();
+        table.column("Attribute").alignLeft();
+        table.column("Value").alignLeft();
+        table.addRow().addContent("Neighbor Address", neighborId);
+
+        final NeighborStateAugmentation stateAug = neighborState.getAugmentation(NeighborStateAugmentation.class);
+        if (stateAug != null) {
+            table.addRow().addContent("Session State", stateAug.getSessionState());
+            printCapabilitiesState(stateAug.getSupportedCapabilities(), table);
+        }
+
+        printTimerState(neighbor.getTimers(), table);
+        printTransportState(neighbor.getTransport(), table);
+        printMessagesState(neighborState, table);
+        printAfiSafisState(neighbor.getAfiSafis().getAfiSafi(), table);
+
+        table.print(stream);
+    }
+
+    private static void printCapabilitiesState(final List<Class<? extends BgpCapability>> supportedCapabilities,
+            final ShellTable table) {
+        if (supportedCapabilities == null) {
+            return;
+        }
+        addHeader(table, "Supported Capabilities");
+        supportedCapabilities.forEach(capa -> table.addRow().addContent("", capa.getSimpleName()));
+    }
+
+    static void addHeader(final ShellTable table, final String header) {
+        table.addRow().addContent("                      ", "");
+        table.addRow().addContent(header, "");
+        table.addRow().addContent("======================", "");
+    }
+
+    private static void printAfiSafisState(final List<AfiSafi> afiSafis, final ShellTable table) {
+        afiSafis.forEach(afiSafi -> printAfiSafiState(afiSafi, table));
+
+    }
+
+    private static void printAfiSafiState(final AfiSafi afiSafi, final ShellTable table) {
+        final NeighborAfiSafiStateAugmentation state = afiSafi.getState()
+                .getAugmentation(NeighborAfiSafiStateAugmentation.class);
+        addHeader(table, "AFI state");
+        table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
+        table.addRow().addContent("Active", state.isActive());
+        final Prefixes prefixes = state.getPrefixes();
+        if (prefixes == null) {
+            return;
+        }
+        table.addRow().addContent("Prefixes", "");
+        table.addRow().addContent("Installed", prefixes.getInstalled());
+        table.addRow().addContent("Sent", prefixes.getSent());
+        table.addRow().addContent("Received", prefixes.getReceived());
+
+    }
+
+    private static void printMessagesState(final State neighborState, final ShellTable table) {
+        final BgpNeighborStateAugmentation state = neighborState.getAugmentation(BgpNeighborStateAugmentation.class);
+        if (state == null) {
+            return;
+        }
+        addHeader(table, "Messages state");
+        final Messages messages = state.getMessages();
+        table.addRow().addContent("Messages Received", "");
+
+        final Received received = messages.getReceived();
+        table.addRow().addContent("NOTIFICATION", received.getNOTIFICATION());
+        table.addRow().addContent("UPDATE", received.getUPDATE());
+
+        final Sent sent = messages.getSent();
+        table.addRow().addContent("Messages Sent", "");
+        table.addRow().addContent("NOTIFICATION", sent.getNOTIFICATION());
+        table.addRow().addContent("UPDATE", sent.getUPDATE());
+    }
+
+    private static void printTransportState(final Transport transport, final ShellTable table) {
+        if (transport == null) {
+            return;
+        }
+        final NeighborTransportStateAugmentation state = transport.getState()
+                .getAugmentation(NeighborTransportStateAugmentation.class);
+        if (state == null) {
+            return;
+        }
+        addHeader(table, "Transport state");
+
+        final IpAddress remoteAddress = state.getRemoteAddress();
+        final String stringRemoteAddress;
+        if (remoteAddress.getIpv4Address() == null) {
+            stringRemoteAddress = remoteAddress.getIpv6Address().getValue();
+        } else {
+            stringRemoteAddress = remoteAddress.getIpv4Address().getValue();
+        }
+        table.addRow().addContent("Remote Address", stringRemoteAddress);
+        table.addRow().addContent("Remote Port", state.getRemotePort().getValue());
+        table.addRow().addContent("Local Port", state.getLocalPort().getValue());
+    }
+
+    private static void printTimerState(final Timers timers, final ShellTable table) {
+        if (timers == null) {
+            return;
+        }
+
+        final NeighborTimersStateAugmentation state = timers.getState()
+                .getAugmentation(NeighborTimersStateAugmentation.class);
+        if (state == null) {
+            return;
+        }
+        addHeader(table, "Timer state");
+        table.addRow().addContent("Negotiated Hold Time", state.getNegotiatedHoldTime());
+        table.addRow().addContent("Uptime", state.getUptime().getValue());
+    }
+}
diff --git a/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtils.java b/bgp/cli/src/main/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtils.java
new file mode 100644 (file)
index 0000000..aa91a95
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.opendaylight.protocol.bgp.cli.utils.NeighborStateCliUtils.addHeader;
+
+import java.io.PrintStream;
+import java.util.List;
+import org.apache.karaf.shell.table.ShellTable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.PeerGroupStateAugmentation;
+
+//PeerGroupStateCliUtils sends Peer Group Operational State to PrintStream
+final class PeerGroupStateCliUtils {
+    @SuppressWarnings("checkstyle:HideUtilityClassConstructor")
+    private PeerGroupStateCliUtils() {
+        throw new UnsupportedOperationException();
+    }
+
+    static void displayPeerOperationalState(@NonNull final List<PeerGroup> peerGroupList,
+            @NonNull final PrintStream stream) {
+        final ShellTable table = new ShellTable();
+        table.column("Attribute").alignLeft();
+        table.column("Value").alignLeft();
+
+        peerGroupList.forEach(group -> displayState(group, table));
+        table.print(stream);
+    }
+
+    private static void displayState(final PeerGroup group, final ShellTable table) {
+        addHeader(table, "Peer Group state");
+        table.addRow().addContent("Peer Group Name", group.getPeerGroupName());
+        final State state = group.getState();
+        if (state == null) {
+            return;
+        }
+        final PeerGroupStateAugmentation aug = state.getAugmentation(PeerGroupStateAugmentation.class);
+        table.addRow().addContent("Total Prefixes", aug.getTotalPrefixes());
+    }
+}
diff --git a/bgp/cli/src/main/resources/OSGI-INF/blueprint/commands.xml b/bgp/cli/src/main/resources/OSGI-INF/blueprint/commands.xml
deleted file mode 100644 (file)
index 4163cc3..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-  -->
-
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
-        <command name="bgp/show-stats">
-            <action class="org.opendaylight.protocol.bgp.cli.ShowBGPStatsCommandProvider"/>
-        </command>
-        <command name="bgp/reset-stats">
-            <action class="org.opendaylight.protocol.bgp.cli.ResetBGPStatsCommandProvider"/>
-        </command>
-    </command-bundle>
-</blueprint>
diff --git a/bgp/cli/src/main/resources/org/opendaylight/blueprint/bgp-cli.xml b/bgp/cli/src/main/resources/org/opendaylight/blueprint/bgp-cli.xml
new file mode 100644 (file)
index 0000000..1ceb150
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
+
+    <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+               odl:type="pingpong"/>
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+        <command name="bgp/operational-state">
+            <action class="org.opendaylight.protocol.bgp.cli.OperationalStateCommandProvider">
+                <property name="dataBroker" ref="dataBroker"/>
+            </action>
+        </command>
+    </command-bundle>
+</blueprint>
\ No newline at end of file
diff --git a/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtilsTest.java b/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BGPOperationalStateUtilsTest.java
new file mode 100644 (file)
index 0000000..c5811ed
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.cli.utils.BGPOperationalStateUtils.PROTOCOLS_IID;
+import static org.opendaylight.protocol.bgp.cli.utils.NeighborStateCliUtilsTest.NEIGHBOR_ADDRESS;
+import static org.opendaylight.protocol.bgp.cli.utils.PeerGroupStateCliUtilsTest.UTF8;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.BgpBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.NeighborsBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class BGPOperationalStateUtilsTest extends AbstractConcurrentDataBrokerTest {
+    static final String RIB_ID = "test-rib";
+    private static final String RIB_NOT_FOUND = "RIB not found for [test-rib]\n";
+    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    private final PrintStream stream = new PrintStream(this.output);
+
+    @Test
+    public void testDisplayBgpOperationalStateNotFound() {
+        BGPOperationalStateUtils.displayBgpOperationalState(getDataBroker(), this.stream, RIB_ID, null, null);
+        assertEquals(RIB_NOT_FOUND, this.output.toString());
+    }
+
+    @Test
+    public void testDisplayBgpOperationalStateFound() throws IOException, ExecutionException, InterruptedException {
+        createDefaultProtocol();
+        BGPOperationalStateUtils.displayBgpOperationalState(getDataBroker(), this.stream, RIB_ID, null, null);
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("global.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+
+    private void createDefaultProtocol() throws ExecutionException, InterruptedException {
+        final WriteTransaction wt = getDataBroker().newWriteOnlyTransaction();
+        final Bgp bgp = new BgpBuilder()
+                .setGlobal(GlobalStateCliUtilsTest.buildGlobal(true).build())
+                .setNeighbors(new NeighborsBuilder().setNeighbor(
+                        Collections.singletonList(NeighborStateCliUtilsTest.createBasicNeighbor())).build())
+                .build();
+        GlobalStateCliUtilsTest.buildGlobal(true);
+        final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID
+                .child(Protocol.class, new ProtocolKey(BGP.class, RIB_ID))
+                .augmentation(Protocol1.class).child(Bgp.class);
+        wt.put(LogicalDatastoreType.OPERATIONAL, bgpIID, bgp, true);
+        wt.submit().get();
+    }
+
+    @Test
+    public void testDisplayNeighborOperationalState() throws IOException, ExecutionException, InterruptedException {
+        createDefaultProtocol();
+        BGPOperationalStateUtils.displayBgpOperationalState(getDataBroker(), this.stream, RIB_ID, null,
+                NEIGHBOR_ADDRESS);
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("empty-neighbor.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+}
\ No newline at end of file
diff --git a/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtilsTests.java b/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/BgpCliUtilsTests.java
deleted file mode 100644 (file)
index e621e7b..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright © 2016 Inocybe Technologies and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.protocol.bgp.cli.utils;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import javax.management.JMException;
-import javax.management.ObjectName;
-import org.junit.Test;
-import org.opendaylight.controller.config.api.IdentityAttributeRef;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.AdvertisedAddPathTableTypes;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.AdvertizedTableTypes;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.ErrorMsgs;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.ErrorReceived;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.LocalPeerPreferences;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.MessagesStats;
-import org.opendaylight.controller.config.yang.bgp.rib.impl.RemotePeerPreferences;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types
-    .rev130919.UnicastSubsequentAddressFamily;
-
-public final class BgpCliUtilsTests{
-
-    @Test
-    public void testDisplayAll() throws IOException, JMException {
-        //Arrange
-        ObjectName objectName = mock(ObjectName.class);
-        BgpSessionState bgpSessionState = mock(BgpSessionState.class);
-        PrintStream printStream = mock(PrintStream.class);
-        MessagesStats msgStats = mock(MessagesStats.class);
-        RemotePeerPreferences speakerPref = mock(RemotePeerPreferences.class);
-        LocalPeerPreferences peerPref = mock(LocalPeerPreferences.class);
-        ErrorMsgs errorMsgs = mock(ErrorMsgs.class);
-        ErrorReceived errorReceived = mock(ErrorReceived.class);
-        List<ErrorReceived> newlist = new ArrayList<>();
-        newlist.add(errorReceived);
-
-        when(bgpSessionState.getMessagesStats()).thenReturn(msgStats);
-        final AdvertisedAddPathTableTypes att = new AdvertisedAddPathTableTypes();
-        att.setAfi(new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()));
-        att.setSafi(new IdentityAttributeRef(UnicastSubsequentAddressFamily.QNAME.toString()));
-        att.setSendReceive(SendReceive.Both);
-        when(speakerPref.getAdvertisedAddPathTableTypes()).thenReturn(Collections.singletonList(att));
-
-        final AdvertizedTableTypes atp = new AdvertizedTableTypes();
-        atp.setAfi(new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()));
-        atp.setSafi(new IdentityAttributeRef(UnicastSubsequentAddressFamily.QNAME.toString()));
-        when(peerPref.getAdvertizedTableTypes()).thenReturn(Collections.singletonList(atp));
-        when(errorReceived.getCount()).thenReturn(new ZeroBasedCounter32(5L));
-
-        when(errorMsgs.getErrorReceived()).thenReturn(newlist);
-        when(msgStats.getErrorMsgs()).thenReturn(errorMsgs);
-        when(bgpSessionState.getRemotePeerPreferences()).thenReturn(speakerPref);
-        when(bgpSessionState.getLocalPeerPreferences()).thenReturn(peerPref);
-
-        //Act
-        BgpCliUtils.displayAll(objectName, bgpSessionState, printStream);
-
-        //Assert
-        verify(objectName, atLeastOnce()).getCanonicalName();
-        verify(bgpSessionState, atLeastOnce()).getMessagesStats().getErrorMsgs();
-        verify(bgpSessionState, atLeastOnce()).getMessagesStats().getKeepAliveMsgs();
-        verify(bgpSessionState, atLeastOnce()).getMessagesStats().getRouteRefreshMsgs();
-        verify(bgpSessionState, atLeastOnce()).getMessagesStats().getTotalMsgs();
-        verify(bgpSessionState, atLeastOnce()).getMessagesStats().getUpdateMsgs();
-        verify(bgpSessionState, atLeastOnce()).getLocalPeerPreferences();
-        verify(bgpSessionState, atLeastOnce()).getRemotePeerPreferences();
-    }
-}
diff --git a/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtilsTest.java b/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/GlobalStateCliUtilsTest.java
new file mode 100644 (file)
index 0000000..1137f00
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.cli.utils.BGPOperationalStateUtilsTest.RIB_ID;
+import static org.opendaylight.protocol.bgp.cli.utils.PeerGroupStateCliUtilsTest.UTF8;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Collections;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.AfiSafisBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.StateBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.GlobalBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.GlobalAfiSafiStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.GlobalAfiSafiStateAugmentationBuilder;
+
+public class GlobalStateCliUtilsTest {
+    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    private final PrintStream stream = new PrintStream(this.output);
+
+    @Test
+    public void testEmptyGlobalStateCliUtil() throws IOException {
+        final GlobalBuilder builder = buildGlobal(false);
+        GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("empty-global.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+
+    @Test
+    public void testGlobalStateCliUtil() throws IOException {
+        final GlobalBuilder builder = buildGlobal(true);
+        GlobalStateCliUtils.displayRibOperationalState(RIB_ID, builder.build(), this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("global.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+
+    static GlobalBuilder buildGlobal(final boolean withStateAug) {
+        final GlobalBuilder builder = new GlobalBuilder().setState(new StateBuilder()
+                .setAs(AsNumber.getDefaultInstance("100"))
+                .setTotalPaths(1L)
+                .setTotalPrefixes(2L)
+                .build());
+
+        final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
+                .common.afi.safi.list.afi.safi.StateBuilder stateBuilder =
+                new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp
+                        .common.afi.safi.list.afi.safi.StateBuilder();
+        if (withStateAug) {
+            stateBuilder.addAugmentation(GlobalAfiSafiStateAugmentation.class,
+                    new GlobalAfiSafiStateAugmentationBuilder().setTotalPaths(3L).setTotalPrefixes(4L).build());
+        }
+
+
+        builder.setAfiSafis(new AfiSafisBuilder()
+                .setAfiSafi(Collections.singletonList(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+                        .setState(stateBuilder.build()).build())).build());
+        return builder;
+    }
+}
\ No newline at end of file
diff --git a/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtilsTest.java b/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/NeighborStateCliUtilsTest.java
new file mode 100644 (file)
index 0000000..5817053
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.cli.utils.PeerGroupStateCliUtilsTest.UTF8;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Collections;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.operational.rev151009.BgpNeighborState;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.operational.rev151009.bgp.neighbor.prefix.counters_state.PrefixesBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.StateBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Timers;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TimersBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Transport;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.TransportBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.ADDPATHS;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timeticks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.BgpNeighborStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.BgpNeighborStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborAfiSafiStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborAfiSafiStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTimersStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTimersStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTransportStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.NeighborTransportStateAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.MessagesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.ReceivedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Sent;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.SentBuilder;
+
+public class NeighborStateCliUtilsTest {
+
+    static final String NEIGHBOR_ADDRESS = "127.0.0.2";
+    private static final IpAddress NEIGHBOR_IP_ADDRESS = new IpAddress(new Ipv4Address(NEIGHBOR_ADDRESS));
+    private static final String  NO_SESSION_FOUND = "No BgpSessionState found for [" + NEIGHBOR_ADDRESS + "]\n";
+    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    private final PrintStream stream = new PrintStream(this.output);
+
+    static Neighbor createBasicNeighbor() {
+        final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi
+                .list.afi.safi.StateBuilder builder = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+                .multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.StateBuilder();
+
+        builder.addAugmentation(NeighborAfiSafiStateAugmentation.class, new NeighborAfiSafiStateAugmentationBuilder()
+                .setActive(false).build());
+        final AfiSafi afiSafi = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+                .setState(builder.build()).build();
+
+        return new NeighborBuilder()
+                .setNeighborAddress(NEIGHBOR_IP_ADDRESS)
+                .setState(new StateBuilder().build())
+                .setAfiSafis(new AfiSafisBuilder().setAfiSafi(Collections.singletonList(afiSafi)).build())
+                .build();
+    }
+
+    @Test
+    public void testNeighborStateWO_StateCli() {
+        NeighborStateCliUtils.displayNeighborOperationalState(NEIGHBOR_ADDRESS,
+                new NeighborBuilder().build(), this.stream);
+        assertEquals(NO_SESSION_FOUND, this.output.toString());
+    }
+
+    @Test
+    public void testEmptyNeighborStateCli() throws IOException {
+        final Neighbor neighbor = createBasicNeighbor();
+        NeighborStateCliUtils.displayNeighborOperationalState(NEIGHBOR_ADDRESS,
+                neighbor, this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("empty-neighbor.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+
+    @Test
+    public void testFullNeighborStateCli() throws IOException {
+        final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi
+                .list.afi.safi.StateBuilder builder = new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp
+                .multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.StateBuilder();
+
+        builder.addAugmentation(NeighborAfiSafiStateAugmentation.class, new NeighborAfiSafiStateAugmentationBuilder()
+                .setActive(true)
+                .setPrefixes(new PrefixesBuilder().setInstalled(1L).setReceived(1L).setSent(2L).build())
+                .build());
+        final AfiSafi afiSafi = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
+                .setState(builder.build()).build();
+
+
+        final StateBuilder stateBuilder = new StateBuilder();
+        stateBuilder.addAugmentation(NeighborStateAugmentation.class,
+                new NeighborStateAugmentationBuilder()
+                        .setSupportedCapabilities(Collections.singletonList(ADDPATHS.class))
+                        .setSessionState(BgpNeighborState.SessionState.ACTIVE).build());
+
+        final Received received = new ReceivedBuilder()
+                .setNOTIFICATION(BigInteger.ONE)
+                .setUPDATE(BigInteger.TEN)
+                .build();
+
+        final Sent sent = new SentBuilder()
+                .setNOTIFICATION(BigInteger.TEN)
+                .setUPDATE(BigInteger.ONE)
+                .build();
+
+        stateBuilder.addAugmentation(BgpNeighborStateAugmentation.class,
+                new BgpNeighborStateAugmentationBuilder()
+                        .setMessages(new MessagesBuilder()
+                                .setReceived(received)
+                                .setSent(sent)
+                                .build())
+                        .build());
+
+        final Transport transport = new TransportBuilder().setState(new org.opendaylight.yang.gen.v1.http.openconfig.net
+                .yang.bgp.rev151009.bgp.neighbor.group.transport.StateBuilder()
+                .addAugmentation(NeighborTransportStateAugmentation.class,
+                        new NeighborTransportStateAugmentationBuilder()
+                                .setRemoteAddress(NEIGHBOR_IP_ADDRESS)
+                                .setLocalPort(new PortNumber(1234))
+                                .setRemotePort(new PortNumber(4321))
+                                .build())
+                .build()).build();
+        final Timers timers = new TimersBuilder().setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang
+                .bgp.rev151009.bgp.neighbor.group.timers.StateBuilder()
+                .addAugmentation(NeighborTimersStateAugmentation.class,
+                        new NeighborTimersStateAugmentationBuilder()
+                                .setNegotiatedHoldTime(BigDecimal.TEN)
+                                .setUptime(new Timeticks(600L))
+                                .build())
+                .build()).build();
+        final Neighbor neighbor = new NeighborBuilder()
+                .setState(stateBuilder.build())
+                .setAfiSafis(new AfiSafisBuilder().setAfiSafi(Collections.singletonList(afiSafi)).build())
+                .setTransport(transport)
+                .setTimers(timers)
+                .build();
+        NeighborStateCliUtils.displayNeighborOperationalState(NEIGHBOR_ADDRESS,
+                neighbor, this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("neighbor.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+}
\ No newline at end of file
diff --git a/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtilsTest.java b/bgp/cli/src/test/java/org/opendaylight/protocol/bgp/cli/utils/PeerGroupStateCliUtilsTest.java
new file mode 100644 (file)
index 0000000..4439e0d
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.cli.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Collections;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.PeerGroupStateAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.PeerGroupStateAugmentationBuilder;
+
+public final class PeerGroupStateCliUtilsTest {
+
+    private static final String TEST_GROUP = "test-group";
+    static final String UTF8 = "UTF-8";
+    private final ByteArrayOutputStream output = new ByteArrayOutputStream();
+    private final PrintStream stream = new PrintStream(this.output);
+
+    @Test
+    public void testEmptyPeerGroupStateCli() throws IOException {
+        final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
+        PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("empty-peer-group.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+
+    @Test
+    public void testPeerGroupStateCli() throws IOException {
+        final PeerGroupBuilder peerGroup = new PeerGroupBuilder().setPeerGroupName(TEST_GROUP);
+
+        final PeerGroupStateAugmentation groupState = new PeerGroupStateAugmentationBuilder()
+                .setTotalPrefixes(1L)
+                .setTotalPaths(2L)
+                .build();
+
+        peerGroup.setState(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
+                .StateBuilder().addAugmentation(PeerGroupStateAugmentation.class, groupState).build());
+        PeerGroupStateCliUtils.displayPeerOperationalState(Collections.singletonList(peerGroup.build()), this.stream);
+
+        final String expected = IOUtils.toString(
+                getClass().getClassLoader().getResourceAsStream("peer-group.txt"), UTF8);
+        assertEquals(expected, this.output.toString());
+    }
+}
\ No newline at end of file
diff --git a/bgp/cli/src/test/resources/empty-global.txt b/bgp/cli/src/test/resources/empty-global.txt
new file mode 100644 (file)
index 0000000..0e4d21a
--- /dev/null
@@ -0,0 +1,13 @@
+Attribute              | Value                
+----------------------------------------------
+                       |                      
+RIB state              |                      
+====================== |                      
+Router Id              | test-rib             
+As                     | AsNumber [_value=100]
+Total Paths            | 1                    
+Total Prefixes         | 2                    
+                       |                      
+AFI/SAFI state         |                      
+====================== |                      
+Family                 | IPV4UNICAST          
diff --git a/bgp/cli/src/test/resources/empty-neighbor.txt b/bgp/cli/src/test/resources/empty-neighbor.txt
new file mode 100644 (file)
index 0000000..a84a385
--- /dev/null
@@ -0,0 +1,8 @@
+Attribute              | Value      
+------------------------------------
+Neighbor Address       | 127.0.0.2  
+                       |            
+AFI state              |            
+====================== |            
+Family                 | IPV4UNICAST
+Active                 | false      
diff --git a/bgp/cli/src/test/resources/empty-peer-group.txt b/bgp/cli/src/test/resources/empty-peer-group.txt
new file mode 100644 (file)
index 0000000..baf419a
--- /dev/null
@@ -0,0 +1,6 @@
+Attribute              | Value     
+-----------------------------------
+                       |           
+Peer Group state       |           
+====================== |           
+Peer Group Name        | test-group
diff --git a/bgp/cli/src/test/resources/global.txt b/bgp/cli/src/test/resources/global.txt
new file mode 100644 (file)
index 0000000..d3fec82
--- /dev/null
@@ -0,0 +1,15 @@
+Attribute              | Value                
+----------------------------------------------
+                       |                      
+RIB state              |                      
+====================== |                      
+Router Id              | test-rib             
+As                     | AsNumber [_value=100]
+Total Paths            | 1                    
+Total Prefixes         | 2                    
+                       |                      
+AFI/SAFI state         |                      
+====================== |                      
+Family                 | IPV4UNICAST          
+Total Paths            | 3                    
+Total Prefixes         | 4                    
diff --git a/bgp/cli/src/test/resources/neighbor.txt b/bgp/cli/src/test/resources/neighbor.txt
new file mode 100644 (file)
index 0000000..449e078
--- /dev/null
@@ -0,0 +1,37 @@
+Attribute              | Value      
+------------------------------------
+Neighbor Address       | 127.0.0.2  
+Session State          | ACTIVE     
+                       |            
+Supported Capabilities |            
+====================== |            
+                       | ADDPATHS   
+                       |            
+Timer state            |            
+====================== |            
+Negotiated Hold Time   | 10         
+Uptime                 | 600        
+                       |            
+Transport state        |            
+====================== |            
+Remote Address         | 127.0.0.2  
+Remote Port            | 4321       
+Local Port             | 1234       
+                       |            
+Messages state         |            
+====================== |            
+Messages Received      |            
+NOTIFICATION           | 1          
+UPDATE                 | 10         
+Messages Sent          |            
+NOTIFICATION           | 10         
+UPDATE                 | 1          
+                       |            
+AFI state              |            
+====================== |            
+Family                 | IPV4UNICAST
+Active                 | true       
+Prefixes               |            
+Installed              | 1          
+Sent                   | 2          
+Received               | 1          
diff --git a/bgp/cli/src/test/resources/peer-group.txt b/bgp/cli/src/test/resources/peer-group.txt
new file mode 100644 (file)
index 0000000..26725a3
--- /dev/null
@@ -0,0 +1,7 @@
+Attribute              | Value     
+-----------------------------------
+                       |           
+Peer Group state       |           
+====================== |           
+Peer Group Name        | test-group
+Total Prefixes         | 1         
index a864c28aeaedf71d95318bff126dfe9a810be156..ca6d6e2e8b6b192ddabe3c294c8b7124aea22dfd 100644 (file)
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>org.opendaylight.bgpcep</groupId>
+                <artifactId>dependency-version-management</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
@@ -36,8 +43,8 @@
             <artifactId>bgp-cli</artifactId>
         </dependency>
         <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>odl-bgpcep-bgp-rib-impl</artifactId>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>odl-mdsal-broker</artifactId>
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
index b09c9544e2f854c754d5d4f4665d48d2b097f0fd..007d8dbbd3fd77dc8c44a4dd5dc10fc7bb22b23c 100644 (file)
             <classifier>features</classifier>
             <type>xml</type>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>odl-bgpcep-bgp-cli</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+        </dependency>
     </dependencies>
 
     <!--