2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.mode.impl.add.all.paths;
11 import com.google.common.primitives.UnsignedInteger;
12 import org.opendaylight.protocol.bgp.mode.api.BestPath;
13 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
14 import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap;
15 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
16 import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 final class ComplexRouteEntry extends AbstractAllPathsRouteEntry {
23 private static final MapEntryNode[] EMPTY_VALUES = new MapEntryNode[0];
24 private MapEntryNode[] values = EMPTY_VALUES;
27 public boolean removeRoute(final UnsignedInteger routerId, final Long remotePathId) {
28 final RouteKey key = new RouteKey(routerId, remotePathId);
29 final OffsetMap map = getOffsets();
30 final int offset = map.offsetOf(key);
31 this.values = map.removeValue(this.values, offset);
32 return removeRoute(key, offset);
36 public MapEntryNode createValue(final PathArgument routeId, final BestPath path) {
37 final OffsetMap map = getOffsets();
38 final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(((AddPathBestPath) path).getRouteKey()));
39 return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues);
43 public int addRoute(final UnsignedInteger routerId, final Long remotePathId,
44 final NodeIdentifier attII, final NormalizedNode<?, ?> data) {
45 final OffsetMap oldMap = getOffsets();
46 final int offset = addRoute(new RouteKey(routerId, remotePathId), attII, data);
47 final OffsetMap newMap = getOffsets();
49 if (!newMap.equals(oldMap)) {
50 this.values = newMap.expand(oldMap, this.values, offset);
53 newMap.setValue(this.values, offset, data);