Update MRI projects for Aluminium
[bgpcep.git] / bgp / topology-provider / src / main / java / org / opendaylight / bgpcep / bgp / topology / provider / LinkstateGraphBuilder.java
index cc268d40344fc7d38c0088479ddb1142d395e25a..807528fe6213e411d560b1a0416beb423cde4b8b 100644 (file)
@@ -80,7 +80,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.graph.topology.graph.VertexKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.vertex.SrgbBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.bgp.linkstate.topology.type.BgpLinkstateTopologyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
@@ -105,7 +104,6 @@ import org.slf4j.LoggerFactory;
 
 public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
     private static final TopologyTypes LINKSTATE_TOPOLOGY_TYPE = new TopologyTypesBuilder().addAugmentation(
-            TopologyTypes1.class,
             new TopologyTypes1Builder().setBgpLinkstateTopology(new BgpLinkstateTopologyBuilder().build()).build())
             .build();
 
@@ -113,11 +111,11 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
 
     private static final Logger LOG = LoggerFactory.getLogger(LinkstateGraphBuilder.class);
 
-    private ConnectedGraphProvider graphProvider;
-    private ConnectedGraph cgraph;
+    private final ConnectedGraphProvider graphProvider;
+    private final ConnectedGraph cgraph;
 
     public LinkstateGraphBuilder(final DataBroker dataProvider, final RibReference locRibReference,
-            final TopologyId topologyId, ConnectedGraphProvider provider) {
+            final TopologyId topologyId, final ConnectedGraphProvider provider) {
         super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class,
                 LinkstateSubsequentAddressFamily.class);
         this.graphProvider = requireNonNull(provider);
@@ -131,7 +129,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
 
     @VisibleForTesting
     LinkstateGraphBuilder(final DataBroker dataProvider, final RibReference locRibReference,
-            final TopologyId topologyId, ConnectedGraphProvider provider, final long listenerResetLimitInMillsec,
+            final TopologyId topologyId, final ConnectedGraphProvider provider, final long listenerResetLimitInMillsec,
             final int listenerResetEnforceCounter) {
         super(dataProvider, locRibReference, topologyId, LINKSTATE_TOPOLOGY_TYPE, LinkstateAddressFamily.class,
                 LinkstateSubsequentAddressFamily.class, listenerResetLimitInMillsec, listenerResetEnforceCounter);
@@ -169,7 +167,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return True if all information are present, false otherwise
      */
-    private boolean checkLinkState(final LinkCase linkCase) {
+    private static boolean checkLinkState(final LinkCase linkCase) {
         if (linkCase.getLocalNodeDescriptors() == null || linkCase.getRemoteNodeDescriptors() == null) {
             LOG.warn("Missing Local or Remote Node descriptor in link {}, skipping it", linkCase);
             return false;
@@ -188,7 +186,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return Link Attributes
      */
-    private LinkAttributes getLinkAttributes(final Attributes attributes) {
+    private static LinkAttributes getLinkAttributes(final Attributes attributes) {
         final LinkAttributes la;
         final Attributes1 attr = attributes.augmentation(Attributes1.class);
         if (attr != null) {
@@ -212,7 +210,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return Unique key
      */
-    private Uint64 getEdgeId(LinkCase linkCase) {
+    private static Uint64 getEdgeId(final LinkCase linkCase) {
         long key = 0;
         if (linkCase.getLinkDescriptors().getIpv4InterfaceAddress() != null) {
             key = ipv4ToKey(linkCase.getLinkDescriptors().getIpv4InterfaceAddress().getValue());
@@ -282,6 +280,8 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         cgraph.addPrefix(prefix);
     }
 
+    private static final int MAX_PRIORITY = 8;
+
     /**
      * Create Edge Attributes from Link attributes.
      *
@@ -290,9 +290,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return EdgeAttributes
      */
-    private static final int MAX_PRIORITY = 8;
-
-    private EdgeAttributes createEdgeAttributes(LinkAttributes la, final LinkDescriptors linkDesc) {
+    private static EdgeAttributes createEdgeAttributes(final LinkAttributes la, final LinkDescriptors linkDesc) {
         EdgeAttributesBuilder builder = new EdgeAttributesBuilder();
 
         if (linkDesc.getIpv4InterfaceAddress() != null) {
@@ -330,7 +328,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
             final List<UnreservedBandwidth> unRsvBw = new ArrayList<>(upperBound);
 
             for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120
-                    .UnreservedBandwidth bandwidth : la.getUnreservedBandwidth()) {
+                    .UnreservedBandwidth bandwidth : la.nonnullUnreservedBandwidth().values()) {
                 unRsvBw.add(new UnreservedBandwidthBuilder()
                         .setBandwidth(bandwithToDecimalBandwidth(bandwidth.getBandwidth()))
                         .withKey(new UnreservedBandwidthKey(bandwidth.getPriority())).build());
@@ -365,7 +363,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
             builder.setUtilizedBandwidth(bandwithToDecimalBandwidth(la.getUtilizedBandwidth()));
         }
         if (la.getSharedRiskLinkGroups() != null) {
-            List<Uint32> srlgs = new ArrayList<Uint32>();
+            List<Uint32> srlgs = new ArrayList<>();
             for (SrlgId srlg : la.getSharedRiskLinkGroups()) {
                 srlgs.add(srlg.getValue());
             }
@@ -399,7 +397,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return Node Attributes
      */
-    private NodeAttributes getNodeAttributes(final Attributes attributes) {
+    private static NodeAttributes getNodeAttributes(final Attributes attributes) {
         final NodeAttributes na;
         final Attributes1 attr = attributes.augmentation(Attributes1.class);
         if (attr != null) {
@@ -424,7 +422,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return New Vertex
      */
-    private Vertex getVertex(NodeAttributes na, Uint64 id, int as) {
+    private static Vertex getVertex(final NodeAttributes na, final Uint64 id, final int as) {
         VertexBuilder builder = new VertexBuilder().setVertexId(id).setAsn(Uint32.valueOf(as));
         if (na.getIpv4RouterId() != null) {
             builder.setRouterId(new IpAddress(new Ipv4Address(na.getIpv4RouterId().getValue())));
@@ -440,7 +438,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         } else {
             int key = id.intValue();
             builder.setName(
-                    ((key << 24) & 0xFF) + "." + ((key << 16) & 0xFF) + "." + ((key << 8) & 0xFF) + "." + (key & 0xFF));
+                    (key << 24 & 0xFF) + "." + (key << 16 & 0xFF) + "." + (key << 8 & 0xFF) + "." + (key & 0xFF));
         }
         if (na.getSrCapabilities() != null) {
             builder.setSrgb(new SrgbBuilder()
@@ -585,14 +583,14 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         }
     }
 
-    private void removeEdge(LinkCase linkCase) {
+    private void removeEdge(final LinkCase linkCase) {
         /* Get Source and Destination Connected Vertex */
         if (linkCase.getLinkDescriptors() == null) {
             LOG.warn("Missing Link descriptor in link {}, skipping it", linkCase);
             return;
         }
         EdgeKey edgeKey = new EdgeKey(getEdgeId(linkCase));
-        if ((edgeKey == null) || (edgeKey.getEdgeId() == Uint64.ZERO)) {
+        if (edgeKey == null || edgeKey.getEdgeId() == Uint64.ZERO) {
             LOG.warn("Unable to get the Edge Key from link {}, skipping it", linkCase);
             return;
         }
@@ -601,9 +599,9 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         cgraph.deleteEdge(edgeKey);
     }
 
-    private void removeVertex(NodeCase nodeCase) {
+    private void removeVertex(final NodeCase nodeCase) {
         VertexKey vertexKey = new VertexKey(getVertexId(nodeCase.getNodeDescriptors().getCRouterIdentifier()));
-        if ((vertexKey == null) || (vertexKey.getVertexId() == Uint64.ZERO)) {
+        if (vertexKey == null || vertexKey.getVertexId() == Uint64.ZERO) {
             LOG.warn("Unable to get Vertex Key from descriptor {}, skipping it", nodeCase.getNodeDescriptors());
             return;
         }
@@ -612,7 +610,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         cgraph.deleteVertex(vertexKey);
     }
 
-    private void removePrefix(PrefixCase prefixCase) {
+    private void removePrefix(final PrefixCase prefixCase) {
         final IpPrefix ippfx = prefixCase.getPrefixDescriptors().getIpReachabilityInformation();
         if (ippfx == null) {
             LOG.warn("IP reachability not present in prefix {}, skipping it", prefixCase);
@@ -630,7 +628,7 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
      *
      * @return Vertex in the Connected Graph that corresponds to this Router ID. Vertex is created if not found.
      */
-    private Uint64 getVertexId(CRouterIdentifier routerID) {
+    private static Uint64 getVertexId(final CRouterIdentifier routerID) {
         Long rid = 0L;
 
         if (routerID instanceof IsisNodeCase) {
@@ -646,21 +644,21 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
         return Uint64.valueOf(rid);
     }
 
-    private DecimalBandwidth bandwithToDecimalBandwidth(Bandwidth bw) {
+    private static DecimalBandwidth bandwithToDecimalBandwidth(final Bandwidth bw) {
         return new DecimalBandwidth(BigDecimal.valueOf(ByteBuffer.wrap(bw.getValue()).getFloat()));
     }
 
-    private long ipv4ToKey(String str) {
+    private static long ipv4ToKey(final String str) {
         byte[] ip;
         try {
             ip = ((Inet4Address) Inet4Address.getByName(str)).getAddress();
         } catch (UnknownHostException e) {
             return 0;
         }
-        return (((0xFF & ip[0]) << 24) | ((0xFF & ip[1]) << 16) | ((0xFF & ip[2]) << 8) | (0xFF & ip[3]));
+        return (0xFF & ip[0]) << 24 | (0xFF & ip[1]) << 16 | (0xFF & ip[2]) << 8 | 0xFF & ip[3];
     }
 
-    private Long ipv6ToKey(String str) {
+    private static Long ipv6ToKey(final String str) {
         byte[] ip;
         try {
             ip = ((Inet6Address) Inet6Address.getByName(str)).getAddress();
@@ -681,5 +679,4 @@ public class LinkstateGraphBuilder extends AbstractTopologyBuilder<LinkstateRout
     protected void clearTopology() {
         cgraph.clear();
     }
-
 }