BUG-6647 Increase code coverage and clean up II
[bgpcep.git] / bgp / bmp-impl / src / main / java / org / opendaylight / protocol / bmp / impl / app / BmpRouterPeerImpl.java
index f94e3034e0fe054b501aead3b1fd75042772aaad..89f30d943b4314fc757847a524b4aab30af167d9 100644 (file)
@@ -16,6 +16,8 @@ import java.util.Set;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -52,8 +54,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.moni
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev150512.peers.peer.PrePolicyRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev150512.peers.peer.Stats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev150512.routers.Router;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTree;
-import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeNode;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -166,14 +166,14 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
         if (this.up) {
             final AdjRibInType ribType = routeMonitoring.getPeerHeader().getAdjRibInType();
             switch (ribType) {
-            case PrePolicy:
-                this.prePolicyWriter.onMessage(routeMonitoring.getUpdate());
-                break;
-            case PostPolicy:
-                this.postPolicyWriter.onMessage(routeMonitoring.getUpdate());
-                break;
-            default:
-                break;
+                case PrePolicy:
+                    this.prePolicyWriter.onMessage(routeMonitoring.getUpdate());
+                    break;
+                case PostPolicy:
+                    this.postPolicyWriter.onMessage(routeMonitoring.getUpdate());
+                    break;
+                default:
+                    break;
             }
         }
     }
@@ -202,11 +202,6 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
         close();
     }
 
-    @Override
-    public PeerId getPeerId() {
-        return this.peerId;
-    }
-
     @Override
     public void close() {
         Preconditions.checkState(this.up, "Already closed.");
@@ -238,16 +233,16 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
                 .withChild(
                         ImmutableNodes.leafNode(PEER_LOCAL_ADDRESS_QNAME,
                                 getStringIpAddress(peerUp.getLocalAddress())))
-                .withChild(
-                        ImmutableNodes.leafNode(PEER_LOCAL_PORT_QNAME, peerUp
-                                .getLocalPort().getValue()))
-                .withChild(
-                        ImmutableNodes.leafNode(PEER_REMOTE_PORT_QNAME, peerUp
-                                .getRemotePort().getValue()))
-                .withChild(ImmutableNodes.leafNode(PEER_STATUS_QNAME, "up"))
-                .withChild(
-                        ImmutableNodes.leafNode(PEER_UP_TIMESTAMP_QNAME,
-                                timestamp.getValue()));
+                                .withChild(
+                                        ImmutableNodes.leafNode(PEER_LOCAL_PORT_QNAME, peerUp
+                                                .getLocalPort().getValue()))
+                                                .withChild(
+                                                        ImmutableNodes.leafNode(PEER_REMOTE_PORT_QNAME, peerUp
+                                                                .getRemotePort().getValue()))
+                                                                .withChild(ImmutableNodes.leafNode(PEER_STATUS_QNAME, "up"))
+                                                                .withChild(
+                                                                        ImmutableNodes.leafNode(PEER_UP_TIMESTAMP_QNAME,
+                                                                                timestamp.getValue()));
         if (this.receivedOpenCodec != null) {
             builder.withChild((ContainerNode) this.receivedOpenCodec.serialize(peerUp.getReceivedOpen()));
         }
@@ -270,9 +265,9 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
                 .withChild(
                         Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PrePolicyRib.QNAME))
                         .withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build())
-                .withChild(
-                        Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PostPolicyRib.QNAME))
-                        .withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build());
+                        .withChild(
+                                Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(PostPolicyRib.QNAME))
+                                .withChild(ImmutableNodes.mapNodeBuilder(BMP_TABLES_QNAME).build()).build());
         if (peerHeader.getDistinguisher() != null) {
             mapEntryBuilder.withChild(ImmutableNodes.leafNode(PEER_DISTINGUISHER_QNAME, peerHeader.getDistinguisher().getDistinguisher()));
         }
@@ -320,19 +315,19 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
         }
         if (tlvs.getPerAfiSafiAdjRibInTlv() != null) {
             builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT9_QNAME))
-                .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME)
-                    .withChild(Builders.mapEntryBuilder()
-                        .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiAdjRibInTlv().getCount().getValue()))
-                        .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))
-                        .build()).build()).build());
+                    .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME)
+                            .withChild(Builders.mapEntryBuilder()
+                                    .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiAdjRibInTlv().getCount().getValue()))
+                                    .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))
+                                    .build()).build()).build());
         }
         if (tlvs.getPerAfiSafiLocRibTlv() != null) {
             builder.withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(STAT10_QNAME))
-                .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME)
-                    .withChild(Builders.mapEntryBuilder()
-                        .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiLocRibTlv().getCount().getValue()))
-                        .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))
-                        .build()).build()).build());
+                    .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME)
+                            .withChild(Builders.mapEntryBuilder()
+                                    .withChild(ImmutableNodes.leafNode(COUNT_QNAME, tlvs.getPerAfiSafiLocRibTlv().getCount().getValue()))
+                                    .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))
+                                    .build()).build()).build());
         }
         if (tlvs.getUpdatesTreatedAsWithdrawTlv() != null) {
             builder.withChild(ImmutableNodes.leafNode(STAT11_QNAME, tlvs.getUpdatesTreatedAsWithdrawTlv().getCount().getValue()));
@@ -348,11 +343,23 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
     private ContainerNode createMirrors(final Mirror mirror, final Timestamp timestamp) {
         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder =
                 Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(Mirrors.QNAME));
-        builder.withChild(ImmutableNodes.leafNode(PEER_MIRROR_INFORMATION_QNAME, MirrorInformationCode.forValue(mirror.getTlvs().getMirrorInformationTlv().getCode().getIntValue())));
+        builder.withChild(ImmutableNodes.leafNode(PEER_MIRROR_INFORMATION_QNAME, toDom(MirrorInformationCode.forValue(
+                mirror.getTlvs().getMirrorInformationTlv().getCode().getIntValue()))));
         builder.withChild(ImmutableNodes.leafNode(PEER_MIRROR_TIMESTAMP_QNAME, timestamp.getValue()));
         return builder.build();
     }
 
+    private static String toDom(final MirrorInformationCode informationCode) {
+        switch (informationCode) {
+            case ErroredPdu:
+                return "errored-pdu";
+            case MessageLost:
+                return "message-lost";
+            default:
+                return null;
+        }
+    }
+
 
     private static String getStringIpAddress(final IpAddress ipAddress) {
         if (ipAddress.getIpv4Address() != null) {