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.LoggingFutures;
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.table.update.OriginalTableBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
36 private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
37 private ListenerRegistration<TableForwarder> listenerRegistration;
39 public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) {
43 @SuppressWarnings("IllegalCatch")
45 public void registerListener() {
46 final DataTreeIdentifier<TableFeatures> treeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
50 listenerRegistration = dataBroker.registerDataTreeChangeListener(treeId, TableForwarder.this);
51 } catch (final Exception e) {
52 LOG.warn("FRM Table DataTreeChangeListener registration fail!");
53 LOG.debug("FRM Table DataTreeChangeListener registration fail ..", e);
54 throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e);
59 public void deregisterListener() {
65 if (listenerRegistration != null) {
66 listenerRegistration.close();
67 listenerRegistration = null;
72 protected InstanceIdentifier<TableFeatures> getWildCardPath() {
73 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
74 .child(TableFeatures.class);
78 public void remove(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures removeDataObj,
79 final InstanceIdentifier<FlowCapableNode> nodeIdent) {
84 public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original,
85 final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
86 LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd {} {} {} {}", identifier,
87 nodeIdent, original, update);
89 final TableFeatures originalTableFeatures = original;
90 TableFeatures updatedTableFeatures;
92 updatedTableFeatures = original;
94 updatedTableFeatures = update;
96 final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
98 builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
100 // TODO: reconsider model - this particular field is not used in service
102 builder.setTableRef(new TableRef(identifier));
104 builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
106 builder.setUpdatedTable(
107 new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(updatedTableFeatures)).build());
109 builder.setOriginalTable(
110 new OriginalTableBuilder().setTableFeatures(Collections.singletonList(originalTableFeatures)).build());
111 LOG.debug("Invoking SalTableService ");
113 if (this.provider.getSalTableService() != null) {
114 LOG.debug(" Handle to SalTableServices {}", this.provider.getSalTableService());
117 LoggingFutures.addErrorLogging(this.provider.getSalTableService().updateTable(builder.build()), LOG,
122 public Future<? extends RpcResult<?>> add(final InstanceIdentifier<TableFeatures> identifier,
123 final TableFeatures addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
124 return Futures.immediateFuture(null);
128 public void createStaleMarkEntity(InstanceIdentifier<TableFeatures> identifier, TableFeatures del,
129 InstanceIdentifier<FlowCapableNode> nodeIdent) {
134 public Future<? extends RpcResult<?>> removeWithResult(InstanceIdentifier<TableFeatures> identifier,
135 TableFeatures del, InstanceIdentifier<FlowCapableNode> nodeIdent) {