BUG-4827: Introduce Avertise All Paths Selecetion Mode 30/35930/16
authorClaudio D. Gasparini <cgaspari@cisco.com>
Tue, 8 Mar 2016 13:15:38 +0000 (14:15 +0100)
committerMilos Fabian <milfabia@cisco.com>
Thu, 31 Mar 2016 11:28:59 +0000 (11:28 +0000)
Introduce Avertise All Paths Selecetion Mode

Change-Id: I744cf2722828234203fe3830a753ec1e0259c9ee
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/controller-config/src/main/resources/initial/41-bgp-example.xml
bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModule.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModuleFactory.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AllPathSelection.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java [new file with mode: 0644]
bgp/path-selection-mode/src/main/yang/bgp-path-selection-mode.yang

index 66cc0c820bab554a989ff4423fa47b2e22e4dea8..2b213b1e276eed5ee687d7721474d42472f80100 100755 (executable)
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:path:selection:mode">prefix:advertise-n-paths</type>
                     <name>n-paths</name>
                     <n-best-paths>2</n-best-paths>
-                </module>
-                <module>
+                </module>-->
+                <!--<module>
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:path:selection:mode">prefix:advertise-all-paths</type>
+                    <name>all-paths</name>
+                </module>-->
+                <!--<module>
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:rib:impl">prefix:bgp-psm-impl</type>
                     <name>ipv4-unicast-path-selection-mode</name>
                     <path-address-family>
@@ -77,6 +81,7 @@
                     </path-selection-mode>
                 </module>-->
 
+
                 <!--
                      A single BGP peer. Note this section is deactivated because a misconfigured peer
                      tends to log rather nasty error messages.
                         <name>n-paths</name>
                         <provider>/config/modules/module[name='advertise-n-paths']/instance[name='n-paths']</provider>
                     </instance>
-                </service>
-                <service>
+                </service>-->
+                <!--<service>
+                    <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:path:selection:mode">prefix:path-selection-mode-factory</type>
+                    <instance>
+                        <name>all-paths</name>
+                        <provider>/config/modules/module[name='advertise-all-paths']/instance[name='all-paths']</provider>
+                    </instance>
+                </service>-->
+                <!--<service>
                     <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:bgp:rib:impl">prefix:bgp-path-selection-mode</type>
                     <instance>
                         <name>ipv4-unicast-path-selection-mode</name>
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModule.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModule.java
new file mode 100644 (file)
index 0000000..3aa8ce5
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.controller.config.yang.bgp.path.selection.mode;
+
+import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
+
+public class AdvertiseAllPathsModule extends org.opendaylight.controller.config.yang.bgp.path.selection.mode.AbstractAdvertiseAllPathsModule {
+    public AdvertiseAllPathsModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public AdvertiseAllPathsModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.bgp.path.selection.mode.AdvertiseAllPathsModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        return new AllPathSelection();
+    }
+
+}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModuleFactory.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/controller/config/yang/bgp/path/selection/mode/AdvertiseAllPathsModuleFactory.java
new file mode 100644 (file)
index 0000000..77ec629
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.controller.config.yang.bgp.path.selection.mode;
+public class AdvertiseAllPathsModuleFactory extends org.opendaylight.controller.config.yang.bgp.path.selection.mode.AbstractAdvertiseAllPathsModuleFactory {
+
+}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java
new file mode 100644 (file)
index 0000000..782ca55
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.mode.impl.add.all.paths;
+
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.bgp.mode.api.BestPathState;
+import org.opendaylight.protocol.bgp.mode.impl.BestPathStateImpl;
+import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
+import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
+import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractAllPathsRouteEntry.class);
+
+    @Override
+    public final boolean selectBest(final long localAs) {
+        final List<AddPathBestPath> newBestPathList = new ArrayList<>();
+        final List<RouteKey> keyList = this.offsets.getRouteKeysList();
+
+        if(!keyList.isEmpty()) {
+            /* we set the best path first on List for not supported Add path cases*/
+            final AddPathBestPath newBest = selectBest(localAs, keyList);
+            newBestPathList.add(newBest);
+            keyList.remove(newBest.getRouteKey());
+            /*we add the rest of path, regardless in what order they are, since this is all path case */
+            for (RouteKey key : keyList) {
+                final int offset = this.offsets.offsetOf(key);
+                final ContainerNode attributes = this.offsets.getValue(this.values, offset);
+                Preconditions.checkNotNull(key.getRouteId(), "Router ID may not be null");
+                if (attributes != null) {
+                    final BestPathState state = new BestPathStateImpl(attributes);
+                    final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset, this.offsets.getValue(this.pathsId, offset));
+                    newBestPathList.add(bestPath);
+                }
+            }
+        }
+
+        this.bestPathRemoved = new ArrayList<>(this.bestPath);
+        if (this.bestPathRemoved.removeAll(newBestPathList) || !this.bestPath.equals(newBestPathList)) {
+            this.bestPath = newBestPathList;
+            LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);
+            return true;
+        }
+        return false;
+    }
+
+
+}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AllPathSelection.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AllPathSelection.java
new file mode 100644 (file)
index 0000000..d4a92d8
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.mode.impl.add.all.paths;
+
+import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
+
+public class AllPathSelection implements PathSelectionMode {
+    @Override
+    public RouteEntry createRouteEntry(final boolean isComplexRoute) {
+        return isComplexRoute ? new ComplexRouteEntry() : new SimpleRouteEntry();
+    }
+
+    @Override
+    public void close() throws Exception {
+        //no-op
+    }
+}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java
new file mode 100644 (file)
index 0000000..58a1ba8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.mode.impl.add.all.paths;
+
+import com.google.common.primitives.UnsignedInteger;
+import org.opendaylight.protocol.bgp.mode.api.BestPath;
+import org.opendaylight.protocol.bgp.mode.impl.OffsetMap;
+import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
+import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+final class ComplexRouteEntry extends AbstractAllPathsRouteEntry {
+    private static final MapEntryNode[] EMPTY_VALUES = new MapEntryNode[0];
+    private MapEntryNode[] values = EMPTY_VALUES;
+
+    @Override
+    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
+        final RouteKey key = new RouteKey(routerId, remotePathId);
+        final OffsetMap<RouteKey> map = getOffsets();
+        final int offset = map.offsetOf(key);
+        final boolean ret = removeRoute(key, offset);
+        this.values = map.removeValue(this.values, offset);
+        return ret;
+    }
+
+    @Override
+    public MapEntryNode createValue(final YangInstanceIdentifier.PathArgument routeId, final BestPath path) {
+        final OffsetMap<RouteKey> map = getOffsets();
+        final int offset = map.offsetOf(((AddPathBestPath) path).getRouteKey());
+        return map.getValue(this.values, offset);
+    }
+
+    @Override
+    public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final YangInstanceIdentifier.NodeIdentifier attII, final NormalizedNode<?, ?> data) {
+        final OffsetMap<RouteKey> oldMap = getOffsets();
+        final int offset = addRoute(new RouteKey(routerId, remotePathId), attII, data);
+        final OffsetMap<RouteKey> newMap = getOffsets();
+
+        if (!newMap.equals(oldMap)) {
+            this.values = newMap.expand(oldMap, this.values, offset);
+        }
+
+        newMap.setValue(this.values, offset, data);
+        return offset;
+    }
+}
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java
new file mode 100644 (file)
index 0000000..f566fef
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.mode.impl.add.all.paths;
+
+import com.google.common.primitives.UnsignedInteger;
+import org.opendaylight.protocol.bgp.mode.api.BestPath;
+import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+
+final class SimpleRouteEntry extends AbstractAllPathsRouteEntry {
+    @Override
+    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
+        final RouteKey key = new RouteKey(routerId, remotePathId);
+        return removeRoute(key, getOffsets().offsetOf(key));
+    }
+
+    @Override
+    public MapEntryNode createValue(final YangInstanceIdentifier.PathArgument routeId, final BestPath path) {
+        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> b = Builders.mapEntryBuilder();
+        b.withNodeIdentifier((YangInstanceIdentifier.NodeIdentifierWithPredicates) routeId);
+        b.addChild(path.getAttributes());
+        return b.build();
+    }
+
+    @Override
+    public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attII,
+        final NormalizedNode<?, ?> data) {
+        return addRoute(new RouteKey(routerId, remotePathId), attII, data);
+    }
+}
index 6d6bdab0af63df6963e6347bee0b19d9492081ba..39a21dbebe57674bee0eba4b303d1c0bf5964eed 100644 (file)
@@ -50,4 +50,16 @@ module odl-bgp-path-selection-mode {
             }
         }
     }
+
+    identity advertise-all-paths {
+         base config:module-type;
+         config:provided-service path-selection-mode-factory;
+         config:java-name-prefix AdvertiseAllPaths;
+    }
+
+    augment "/config:modules/config:module/config:configuration" {
+        case advertise-all-paths {
+            when "/config:modules/config:module/config:type = 'advertise-all-paths'";
+        }
+    }
 }
\ No newline at end of file