30e18e47bfe02a31fba26677aae590507d58d79c
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / TableContext.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.rib.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
15 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22
23 /**
24  * A context for a single RIB table instance. It is always bound to a particular {@link AdjRibInWriter}.
25  *
26  * <p>
27  * This class is NOT thread-safe.
28  */
29 // FIXME: need a better name once we local-rib and rib-out contexts
30 final class TableContext {
31     private final YangInstanceIdentifier tableId;
32     private final RIBSupportContext tableSupport;
33
34     TableContext(final RIBSupportContext tableSupport, final YangInstanceIdentifier tableId) {
35         this.tableSupport = requireNonNull(tableSupport);
36         this.tableId = requireNonNull(tableId);
37     }
38
39     YangInstanceIdentifier getTableId() {
40         return this.tableId;
41     }
42
43
44     void createEmptyTableStructure(final DOMDataTreeWriteTransaction tx) {
45         this.tableSupport.createEmptyTableStructure(tx, this.tableId);
46     }
47
48     void removeTable(final DOMDataTreeWriteTransaction tx) {
49         tx.delete(LogicalDatastoreType.OPERATIONAL, this.tableId);
50     }
51
52     Collection<NodeIdentifierWithPredicates> writeRoutes(final DOMDataTreeWriteTransaction tx, final MpReachNlri nlri,
53                                                          final Attributes attributes) {
54         return this.tableSupport.writeRoutes(tx, this.tableId, nlri, attributes);
55     }
56
57     void removeRoutes(final DOMDataTreeWriteTransaction tx, final MpUnreachNlri nlri) {
58         this.tableSupport.deleteRoutes(tx, this.tableId, nlri);
59     }
60
61     YangInstanceIdentifier routesPath() {
62         return tableSupport.getRibSupport().routesPath(this.tableId);
63     }
64
65     YangInstanceIdentifier routePath(final PathArgument routeId) {
66         return tableSupport.getRibSupport().routePath(this.tableId, routeId);
67     }
68 }