2 * Copyright (c) 2015 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.Callable;
15 import java.util.concurrent.Future;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
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.table.update.OriginalTableBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
39 private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
41 private ListenerRegistration<TableForwarder> listenerRegistration;
43 public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) {
44 super(manager, TableFeatures.class);
45 Preconditions.checkNotNull(db, "DataBroker can not be null!");
46 final DataTreeIdentifier<TableFeatures> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath());
49 SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
50 ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
51 listenerRegistration = looper.loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, TableForwarder.this));
52 } catch (final Exception e) {
53 LOG.warn("FRM Table DataChange listener registration fail!");
54 LOG.debug("FRM Table DataChange listener registration fail ..", e);
55 throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e);
61 if (listenerRegistration != null) {
63 listenerRegistration.close();
64 } catch (Exception e) {
65 LOG.warn("Error by stop FRM TableChangeListener: {}", e.getMessage());
66 LOG.debug("Error by stop FRM TableChangeListener..", e);
68 listenerRegistration = null;
73 protected InstanceIdentifier<TableFeatures> getWildCardPath() {
74 return InstanceIdentifier.create(Nodes.class).child(Node.class)
75 .augmentation(FlowCapableNode.class).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,
86 final TableFeatures original, final TableFeatures update,
87 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
88 LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" +
89 " " + identifier + " " + nodeIdent + " " + original + " " + update);
91 final TableFeatures originalTableFeatures = original;
92 TableFeatures updatedTableFeatures;
94 updatedTableFeatures = original;
97 updatedTableFeatures = update;
99 final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
101 builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
103 // TODO: reconsider model - this particular field is not used in service implementation
104 builder.setTableRef(new TableRef(identifier));
106 builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
108 builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(
109 Collections.singletonList(updatedTableFeatures)).build());
111 builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(
112 Collections.singletonList(originalTableFeatures)).build());
113 LOG.debug("Invoking SalTableService ");
115 if (this.provider.getSalTableService() != null)
116 LOG.debug(" Handle to SalTableServices" + this.provider.getSalTableService());
117 this.provider.getSalTableService().updateTable(builder.build());
122 public Future<? extends RpcResult> add(
123 final InstanceIdentifier<TableFeatures> identifier,
124 final TableFeatures addDataObj,
125 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
126 return Futures.immediateFuture(null);
130 public void createStaleMarkEntity(InstanceIdentifier<TableFeatures> identifier, TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {
136 public Future<? extends RpcResult> removeWithResult(InstanceIdentifier<TableFeatures> identifier, TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {