Merge ActualBestPathRoutes and AdvertizedRoute 84/78484/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Dec 2018 21:22:27 +0000 (22:22 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 7 Dec 2018 10:03:20 +0000 (10:03 +0000)
These two classes are almost identical, extract the common bits
to a common superclass, reducing complexity and allowing them
us to share codepaths.

Change-Id: Ib6bbf1e4285ed0f1376d932367c8cb0d3f6f2662
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/AbstractAdvertizedRoute.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/ActualBestPathRoutes.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/AdvertizedRoute.java

diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/AbstractAdvertizedRoute.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/AbstractAdvertizedRoute.java
new file mode 100644 (file)
index 0000000..9d1cc38
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 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.rib.spi.entry;
+
+import static com.google.common.base.Verify.verifyNotNull;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.ChoiceIn;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+
+/**
+ * Preexistent routes to be advertized before process any route advertized by the peer.
+ *
+ * @author Claudio D. Gasparini
+ */
+public abstract class AbstractAdvertizedRoute<C extends Routes & DataObject & ChoiceIn<Tables>,
+        S extends ChildOf<? super C>,
+        R extends Route & ChildOf<? super S> & Identifiable<I>,
+        I extends Identifier<R>> implements RouteKeyIdentifier<R,I> {
+    private final PeerId fromPeerId;
+    private final R route;
+    private final Attributes attributes;
+    private final I nonAddPathRouteKeyIdentifier;
+    private final I addPathRouteKeyIdentifier;
+
+    AbstractAdvertizedRoute(final RIBSupport<C, S, R, I> ribSupport, final R route, final PeerId fromPeerId,
+            final Attributes attributes) {
+        this.fromPeerId = fromPeerId;
+        this.route = route;
+        this.attributes = attributes;
+
+        final @NonNull String routeKey = verifyNotNull(route.getRouteKey());
+        this.nonAddPathRouteKeyIdentifier = ribSupport.createRouteListKey(NON_PATH_ID_VALUE, routeKey);
+        this.addPathRouteKeyIdentifier = ribSupport.createRouteListKey(route.getPathId().getValue(), routeKey);
+    }
+
+    public final PeerId getFromPeerId() {
+        return this.fromPeerId;
+    }
+
+    public final R getRoute() {
+        return route;
+    }
+
+    public final Attributes getAttributes() {
+        return attributes;
+    }
+
+    @Override
+    public final I getNonAddPathRouteKeyIdentifier() {
+        return this.nonAddPathRouteKeyIdentifier;
+    }
+
+    @Override
+    public final I getAddPathRouteKeyIdentifier() {
+        return this.addPathRouteKeyIdentifier;
+    }
+}
index 0ce354c089b6e465bb7d28b4e9ed12546983f65d..b24a41d43a048c077bcc4f5f0fce1a1f105929dd 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.protocol.bgp.rib.spi.entry;
 
-import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
-
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
@@ -28,43 +26,11 @@ import org.opendaylight.yangtools.yang.binding.Identifier;
  * @author Claudio D. Gasparini
  */
 public final class ActualBestPathRoutes<C extends Routes & DataObject & ChoiceIn<Tables>,
-        S extends ChildOf<? super C>,
-        R extends Route & ChildOf<? super S> & Identifiable<I>,
-        I extends Identifier<R>> implements RouteKeyIdentifier<R,I> {
-    private final PeerId fromPeerId;
-    private final R route;
-    private final Attributes attributes;
-    private final I nonAddPathRouteKeyIdentifier;
-    private final I addPathRouteKeyIdentifier;
+        S extends ChildOf<? super C>, R extends Route & ChildOf<? super S> & Identifiable<I>,
+        I extends Identifier<R>> extends AbstractAdvertizedRoute<C, S, R, I> {
 
     public ActualBestPathRoutes(final RIBSupport<C, S, R, I> ribSupport, final R route, final PeerId fromPeerId,
             final Attributes attributes) {
-        this.fromPeerId = fromPeerId;
-        this.route = route;
-        this.attributes = attributes;
-        this.nonAddPathRouteKeyIdentifier
-                = ribSupport.createRouteListKey(NON_PATH_ID_VALUE, route.getRouteKey());
-        this.addPathRouteKeyIdentifier
-                = ribSupport.createRouteListKey(route.getPathId().getValue(), route.getRouteKey());
-    }
-
-    public PeerId getFromPeerId() {
-        return this.fromPeerId;
-    }
-
-    public R getRoute() {
-        return route;
-    }
-
-    public Attributes getAttributes() {
-        return attributes;
-    }
-
-    public I getNonAddPathRouteKeyIdentifier() {
-        return this.nonAddPathRouteKeyIdentifier;
-    }
-
-    public I getAddPathRouteKeyIdentifier() {
-        return this.addPathRouteKeyIdentifier;
+        super(ribSupport, route, fromPeerId, attributes);
     }
 }
index ce612515f3eb1d9a04ffa0b770b905d1f5009806..71489d5a6eb50ceea6b4d2b712318ebeb798ceea 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.protocol.bgp.rib.spi.entry;
 
-import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
-
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
@@ -28,62 +26,22 @@ import org.opendaylight.yangtools.yang.binding.Identifier;
  * @author Claudio D. Gasparini
  */
 public final class AdvertizedRoute<C extends Routes & DataObject & ChoiceIn<Tables>,
-        S extends ChildOf<? super C>,
-        R extends Route & ChildOf<? super S> & Identifiable<I>,
-        I extends Identifier<R>> implements RouteKeyIdentifier<R,I> {
-    private final R route;
-    private final PeerId peerId;
-    private final Attributes attributes;
+        S extends ChildOf<? super C>, R extends Route & ChildOf<? super S> & Identifiable<I>,
+        I extends Identifier<R>> extends AbstractAdvertizedRoute<C, S, R, I> {
     private final boolean isFirstBestPath;
-    private final I nonAddPathRouteKeyIdentifier;
-    private final I addPathRouteKeyIdentifier;
 
-    public AdvertizedRoute(
-            final RIBSupport<C, S, R, I> ribSupport,
-            final R route,
-            final Attributes attributes,
-            final PeerId peerId) {
-        this(ribSupport, true, route, attributes, peerId);
+    public AdvertizedRoute(final RIBSupport<C, S, R, I> ribSupport, final R route, final Attributes attributes,
+            final PeerId fromPeerId) {
+        this(ribSupport, true, route, attributes, fromPeerId);
     }
 
-    public AdvertizedRoute(
-            final RIBSupport<C, S, R, I> ribSupport,
-            final boolean isFirstBestPath,
-            final R route,
-            final Attributes attributes,
-            final PeerId peerId) {
+    public AdvertizedRoute(final RIBSupport<C, S, R, I> ribSupport, final boolean isFirstBestPath,
+            final R route, final Attributes attributes, final PeerId fromPeerId) {
+        super(ribSupport, route, fromPeerId, attributes);
         this.isFirstBestPath = isFirstBestPath;
-        this.route = route;
-        this.peerId = peerId;
-        this.attributes = attributes;
-        this.nonAddPathRouteKeyIdentifier
-                = ribSupport.createRouteListKey(NON_PATH_ID_VALUE, route.getRouteKey());
-        this.addPathRouteKeyIdentifier
-                = ribSupport.createRouteListKey(route.getPathId().getValue(), route.getRouteKey());
-
-    }
-
-    public R getRoute() {
-        return this.route;
-    }
-
-    public PeerId getFromPeerId() {
-        return this.peerId;
-    }
-
-    public Attributes getAttributes() {
-        return this.attributes;
     }
 
     public boolean isFirstBestPath() {
         return this.isFirstBestPath;
     }
-
-    public I getNonAddPathRouteKeyIdentifier() {
-        return this.nonAddPathRouteKeyIdentifier;
-    }
-
-    public I getAddPathRouteKeyIdentifier() {
-        return this.addPathRouteKeyIdentifier;
-    }
 }