2 * Copyright (c) 2015 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
8 package org.opendaylight.protocol.bgp.mode.impl.base;
10 import com.google.common.primitives.UnsignedInteger;
11 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
12 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
15 final class ComplexRouteEntry extends BaseAbstractRouteEntry {
16 private static final Route[] EMPTY_VALUES = new Route[0];
17 private Route[] values = EMPTY_VALUES;
19 ComplexRouteEntry(final BGPPeerTracker peerTracker) {
24 public int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
25 final OffsetMap oldMap = getOffsets();
26 final int offset = super.addRoute(routerId, remotePathId, route);
27 final OffsetMap newMap = getOffsets();
29 if (!newMap.equals(oldMap)) {
30 this.values = newMap.expand(oldMap, this.values, offset);
33 newMap.setValue(this.values, offset, route);
38 public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
39 final OffsetMap map = getOffsets();
40 final int offset = map.offsetOf(routerId);
41 this.values = map.removeValue(this.values, offset);
42 return removeRoute(routerId, offset);
46 public Route createRoute(final RIBSupport ribSup, String routeKey, final long pathId,
47 final BaseBestPath path) {
48 final OffsetMap map = getOffsets();
49 final Route route = map.getValue(this.values, map.offsetOf(path.getRouterId()));
50 return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());