Revert "WIP: Bump upstreams"
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / TableForwarder.java
1 /*
2  * Copyright (c) 2015, 2017 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.openflowplugin.applications.frm.impl;
9
10 import com.google.common.util.concurrent.Futures;
11 import java.util.Collections;
12 import java.util.concurrent.Future;
13 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
32
33     private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
34
35     public TableForwarder(final ForwardingRulesManager manager, final DataBroker db,
36                           final ListenerRegistrationHelper registrationHelper) {
37         super(manager, db, registrationHelper);
38     }
39
40     @Override
41     public  void deregisterListener() {
42         close();
43     }
44
45     @Override
46     public void close() {
47         if (listenerRegistration != null) {
48             listenerRegistration.close();
49             listenerRegistration = null;
50         }
51     }
52
53     @Override
54     protected InstanceIdentifier<TableFeatures> getWildCardPath() {
55         return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
56                 .child(TableFeatures.class);
57     }
58
59     @Override
60     public void remove(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures removeDataObj,
61             final InstanceIdentifier<FlowCapableNode> nodeIdent) {
62         // DO Nothing
63     }
64
65     @Override
66     public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original,
67             final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
68         LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd {} {} {} {}", identifier,
69                 nodeIdent, original, update);
70
71         final TableFeatures originalTableFeatures = original;
72         TableFeatures updatedTableFeatures;
73         if (null == update) {
74             updatedTableFeatures = original;
75         } else {
76             updatedTableFeatures = update;
77         }
78         final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
79
80         builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
81
82         // TODO: reconsider model - this particular field is not used in service
83         // implementation
84         builder.setTableRef(new TableRef(identifier));
85
86         builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
87
88         builder.setUpdatedTable(new UpdatedTableBuilder()
89             .setTableFeatures(Collections.singletonMap(updatedTableFeatures.key(), updatedTableFeatures))
90             .build());
91
92         builder.setOriginalTable(new OriginalTableBuilder()
93             .setTableFeatures(Collections.singletonMap(originalTableFeatures.key(), originalTableFeatures))
94             .build());
95         LOG.debug("Invoking SalTableService ");
96
97         if (this.provider.getSalTableService() != null) {
98             LOG.debug(" Handle to SalTableServices {}", this.provider.getSalTableService());
99         }
100
101         LoggingFutures.addErrorLogging(this.provider.getSalTableService().updateTable(builder.build()), LOG,
102             "updateTable");
103     }
104
105     @Override
106     public Future<? extends RpcResult<?>> add(final InstanceIdentifier<TableFeatures> identifier,
107             final TableFeatures addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
108         return Futures.immediateFuture(null);
109     }
110
111     @Override
112     public void createStaleMarkEntity(InstanceIdentifier<TableFeatures> identifier, TableFeatures del,
113             InstanceIdentifier<FlowCapableNode> nodeIdent) {
114         LOG.debug("NO-OP");
115     }
116
117     @Override
118     public Future<? extends RpcResult<?>> removeWithResult(InstanceIdentifier<TableFeatures> identifier,
119             TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {
120         return null;
121     }
122 }