2 * Copyright (c) 2015, 2017 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.openflowplugin.applications.frm.impl;
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.JdkFutures;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
37 private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
38 private ListenerRegistration<TableForwarder> listenerRegistration;
40 public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) {
44 @SuppressWarnings("IllegalCatch")
46 public void registerListener() {
47 final DataTreeIdentifier<TableFeatures> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
51 listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, TableForwarder.this);
52 } catch (final Exception e) {
53 LOG.warn("FRM Table DataTreeChangeListener registration fail!");
54 LOG.debug("FRM Table DataTreeChangeListener registration fail ..", e);
55 throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e);
60 public void deregisterListener() {
66 if (listenerRegistration != null) {
67 listenerRegistration.close();
68 listenerRegistration = null;
73 protected InstanceIdentifier<TableFeatures> getWildCardPath() {
74 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
75 .child(TableFeatures.class);
79 public void remove(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures removeDataObj,
80 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
85 public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original,
86 final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
87 LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd {} {} {} {}", identifier,
88 nodeIdent, original, update);
90 final TableFeatures originalTableFeatures = original;
91 TableFeatures updatedTableFeatures;
93 updatedTableFeatures = original;
95 updatedTableFeatures = update;
97 final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
99 builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
101 // TODO: reconsider model - this particular field is not used in service
103 builder.setTableRef(new TableRef(identifier));
105 builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
107 builder.setUpdatedTable(
108 new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(updatedTableFeatures)).build());
110 builder.setOriginalTable(
111 new OriginalTableBuilder().setTableFeatures(Collections.singletonList(originalTableFeatures)).build());
112 LOG.debug("Invoking SalTableService ");
114 if (this.provider.getSalTableService() != null) {
115 LOG.debug(" Handle to SalTableServices {}", this.provider.getSalTableService());
118 final Future<RpcResult<UpdateTableOutput>> resultFuture =
119 this.provider.getSalTableService().updateTable(builder.build());
120 JdkFutures.addErrorLogging(resultFuture, LOG, "updateTable");
125 public Future<? extends RpcResult<?>> add(final InstanceIdentifier<TableFeatures> identifier,
126 final TableFeatures addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
127 return Futures.immediateFuture(null);
131 public void createStaleMarkEntity(InstanceIdentifier<TableFeatures> identifier, TableFeatures del,
132 InstanceIdentifier<FlowCapableNode> nodeIdent) {
137 public Future<? extends RpcResult<?>> removeWithResult(InstanceIdentifier<TableFeatures> identifier,
138 TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {