BUG-4827: Replace extractPathId method from RibSupport
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / add / n / paths / SimpleRouteEntry.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.mode.impl.add.n.paths;
9
10 import com.google.common.primitives.UnsignedInteger;
11 import org.opendaylight.protocol.bgp.mode.api.BestPath;
12 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
20
21 final class SimpleRouteEntry extends AbstractNPathsRouteEntry {
22     public SimpleRouteEntry(final Long nBestPaths) {
23         super(nBestPaths);
24     }
25
26     @Override
27     public boolean removeRoute(final UnsignedInteger routerId, final Long remotePathId) {
28         final RouteKey key = new RouteKey(routerId, remotePathId);
29         return removeRoute(key, getOffsets().offsetOf(key));
30     }
31
32     @Override
33     public MapEntryNode createValue(final PathArgument routeId, final BestPath path) {
34         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = Builders.mapEntryBuilder();
35         b.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
36         b.addChild(path.getAttributes());
37         return b.build();
38     }
39
40     @Override
41     public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
42         return addRoute(new RouteKey(routerId, remotePathId), attributesIdentifier, data);
43     }
44 }