Use SyncupEntry in syncup method (Bug 6170 cleaning)
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / strategy / TableForwarder.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
10
11 import java.util.Collections;
12 import java.util.concurrent.Future;
13 import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesUpdateCommitter;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
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 /**
32  * Implements {@link ForwardingRulesUpdateCommitter} methods for processing update of {@link TableFeatures}.
33  */
34 public class TableForwarder implements ForwardingRulesUpdateCommitter<TableFeatures, UpdateTableOutput> {
35
36     private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
37     private final SalTableService salTableService;
38
39     public TableForwarder(SalTableService salTableService) {
40         this.salTableService = salTableService;
41     }
42
43     @Override
44     public Future<RpcResult<UpdateTableOutput>> update(final InstanceIdentifier<TableFeatures> identifier,
45                                                        final TableFeatures original, final TableFeatures update,
46                                                        final InstanceIdentifier<FlowCapableNode> nodeIdent) {
47         LOG.debug("Forwarding Table Update request [Tbl id, node Id {} {}",
48                 identifier, nodeIdent);
49
50         final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
51
52         builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
53
54         final InstanceIdentifier<Table> iiToTable = nodeIdent.child(Table.class,
55                 new TableKey(identifier.firstKeyOf(TableFeatures.class).getTableId()));
56         builder.setTableRef(new TableRef(iiToTable));
57
58         builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(
59                 Collections.singletonList(update)).build());
60
61         builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(
62                 Collections.singletonList(original)).build());
63         LOG.debug("Invoking SalTableService {} ", nodeIdent);
64
65         return salTableService.updateTable(builder.build());
66     }
67
68 }