BUG:5888 - Changing FRM from clustered DCN to clustered DTCN
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / impl / 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;
10
11 import java.util.Collections;
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.openflowplugin.applications.frsync.ForwardingRulesUpdateCommitter;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * Implements {@link ForwardingRulesUpdateCommitter} methods for processing update of {@link TableFeatures}.
34  */
35 public class TableForwarder implements ForwardingRulesUpdateCommitter<TableFeatures, UpdateTableOutput> {
36
37     private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
38     private final SalTableService salTableService;
39
40     public TableForwarder(SalTableService salTableService) {
41         this.salTableService = salTableService;
42     }
43
44     @Override
45     public Future<RpcResult<UpdateTableOutput>> update(final InstanceIdentifier<TableFeatures> identifier,
46                                                        final TableFeatures original, final TableFeatures update,
47                                                        final InstanceIdentifier<FlowCapableNode> nodeIdent) {
48         LOG.debug("Forwarding Table Update request [Tbl id, node Id {} {}",
49                 identifier, nodeIdent);
50
51         final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
52
53         builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
54
55         final InstanceIdentifier<Table> iiToTable = nodeIdent.child(Table.class,
56                 new TableKey(identifier.firstKeyOf(TableFeatures.class).getTableId()));
57         builder.setTableRef(new TableRef(iiToTable));
58
59         builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(
60                 Collections.singletonList(update)).build());
61
62         builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(
63                 Collections.singletonList(original)).build());
64         LOG.debug("Invoking SalTableService {} ", nodeIdent);
65
66         return salTableService.updateTable(builder.build());
67     }
68
69 }