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;
18 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 final class ComplexRouteEntry extends AbstractAllPathsRouteEntry {
22 private static final MapEntryNode[] EMPTY_VALUES = new MapEntryNode[0];
23 private MapEntryNode[] values = EMPTY_VALUES;
26 public boolean removeRoute(final UnsignedInteger routerId, final Long remotePathId) {
27 final RouteKey key = new RouteKey(routerId, remotePathId);
28 final OffsetMap map = getOffsets();
29 final int offset = map.offsetOf(key);
30 this.values = map.removeValue(this.values, offset);
31 return removeRoute(key, offset);
35 public MapEntryNode createValue(final YangInstanceIdentifier.PathArgument routeId, final BestPath path) {
36 final OffsetMap map = getOffsets();
37 final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(((AddPathBestPath) path).getRouteKey()));
38 return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues);
42 public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final YangInstanceIdentifier.NodeIdentifier attII, final NormalizedNode<?, ?> data) {
43 final OffsetMap oldMap = getOffsets();
44 final int offset = addRoute(new RouteKey(routerId, remotePathId), attII, data);
45 final OffsetMap newMap = getOffsets();
47 if (!newMap.equals(oldMap)) {
48 this.values = newMap.expand(oldMap, this.values, offset);
51 newMap.setValue(this.values, offset, data);