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
9 package org.opendaylight.openflowplugin.applications.frm.impl;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import java.util.Collections;
14 import java.util.concurrent.Future;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
19 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
20 import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
40 private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
41 private ListenerRegistration<TableForwarder> listenerRegistration;
43 @SuppressWarnings("IllegalCatch")
44 public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) {
46 Preconditions.checkNotNull(db, "DataBroker can not be null!");
47 final DataTreeIdentifier<TableFeatures> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
51 SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
52 ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
53 listenerRegistration = looper
54 .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, TableForwarder.this));
55 } catch (final Exception e) {
56 LOG.warn("FRM Table DataTreeChangeListener registration fail!");
57 LOG.debug("FRM Table DataTreeChangeListener registration fail ..", e);
58 throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e);
64 if (listenerRegistration != null) {
65 listenerRegistration.close();
66 listenerRegistration = null;
71 protected InstanceIdentifier<TableFeatures> getWildCardPath() {
72 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
73 .child(TableFeatures.class);
77 public void remove(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures removeDataObj,
78 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
83 public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original,
84 final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
85 LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" + " " + identifier + " "
86 + nodeIdent + " " + original + " " + update);
88 final TableFeatures originalTableFeatures = original;
89 TableFeatures updatedTableFeatures;
91 updatedTableFeatures = original;
93 updatedTableFeatures = update;
95 final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
97 builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
99 // TODO: reconsider model - this particular field is not used in service
101 builder.setTableRef(new TableRef(identifier));
103 builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
105 builder.setUpdatedTable(
106 new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(updatedTableFeatures)).build());
108 builder.setOriginalTable(
109 new OriginalTableBuilder().setTableFeatures(Collections.singletonList(originalTableFeatures)).build());
110 LOG.debug("Invoking SalTableService ");
112 if (this.provider.getSalTableService() != null) {
113 LOG.debug(" Handle to SalTableServices" + this.provider.getSalTableService());
116 final Future<RpcResult<UpdateTableOutput>> resultFuture =
117 this.provider.getSalTableService().updateTable(builder.build());
118 JdkFutures.addErrorLogging(resultFuture, LOG, "updateTable");
123 public Future<? extends RpcResult<?>> add(final InstanceIdentifier<TableFeatures> identifier,
124 final TableFeatures addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
125 return Futures.immediateFuture(null);
129 public void createStaleMarkEntity(InstanceIdentifier<TableFeatures> identifier, TableFeatures del,
130 InstanceIdentifier<FlowCapableNode> nodeIdent) {
135 public Future<? extends RpcResult<?>> removeWithResult(InstanceIdentifier<TableFeatures> identifier,
136 TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {