<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>
</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>
--- /dev/null
+/*
+ * 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();
+ }
+
+}
--- /dev/null
+/*
+ * 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 {
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+
+}
--- /dev/null
+/*
+ * 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
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
}
}
}
+
+ 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