Merge "OPNFLWPLUG-997 Spec - Southbound cli implementation"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / AbstractTableMultipartService.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.impl.services;
10
11 import java.util.List;
12 import java.util.concurrent.Future;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
15 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.TableUpdatedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22
23 public abstract class AbstractTableMultipartService<T extends OfHeader>
24         extends AbstractMultipartService<UpdateTableInput, T> {
25
26     private final MultipartWriterProvider multipartWriterProvider;
27
28     protected AbstractTableMultipartService(final RequestContextStack requestContextStack,
29                                             final DeviceContext deviceContext,
30                                             final MultipartWriterProvider multipartWriterProvider) {
31         super(requestContextStack, deviceContext);
32         this.multipartWriterProvider = multipartWriterProvider;
33     }
34
35     /**
36      * Stores table features to operational datastore.
37      */
38     protected void storeStatistics(List<org.opendaylight.yang.gen.v1.urn
39             .opendaylight.table.types.rev131026.table.features.TableFeatures> result) {
40         multipartWriterProvider
41             .lookup(MultipartType.OFPMPTABLEFEATURES)
42             .ifPresent(writer -> {
43                 writer.write(
44                     new TableUpdatedBuilder()
45                         .setTableFeatures(result)
46                         .build(),
47                     false);
48
49                 getTxFacade().submitTransaction();
50             });
51     }
52
53     /**
54      * Process experimenter input and result experimenter output.
55      * @param input experimenter input
56      * @return experimenter output
57      */
58     public abstract Future<RpcResult<UpdateTableOutput>> handleAndReply(UpdateTableInput input);
59
60 }