Bump versions by x.y.(z+1)
[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 com.google.common.base.Preconditions;
11 import javax.annotation.concurrent.NotThreadSafe;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
14 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * A context for a single RIB table instance. It is always bound to a particular {@link AdjRibInWriter}.
22  *
23  * FIXME: need a better name once we local-rib and rib-out contexts
24  */
25 @NotThreadSafe
26 final class TableContext {
27     private final YangInstanceIdentifier tableId;
28     private final RIBSupportContext tableSupport;
29
30     TableContext(final RIBSupportContext tableSupport, final YangInstanceIdentifier tableId) {
31         this.tableSupport = Preconditions.checkNotNull(tableSupport);
32         this.tableId = Preconditions.checkNotNull(tableId);
33     }
34
35     YangInstanceIdentifier getTableId() {
36         return this.tableId;
37     }
38
39
40     void createEmptyTableStructure(final DOMDataWriteTransaction tx) {
41         this.tableSupport.createEmptyTableStructure(tx, this.tableId);
42     }
43
44     void removeTable(final DOMDataWriteTransaction tx) {
45         tx.delete(LogicalDatastoreType.OPERATIONAL, this.tableId);
46     }
47
48     void writeRoutes(final DOMDataWriteTransaction tx, final MpReachNlri nlri, final Attributes attributes) {
49         this.tableSupport.writeRoutes(tx, this.tableId, nlri, attributes);
50     }
51
52     void removeRoutes(final DOMDataWriteTransaction tx, final MpUnreachNlri nlri) {
53         this.tableSupport.deleteRoutes(tx, this.tableId, nlri);
54     }
55 }