e21a9720d8a048ef0110787cbaa9a1605a8cbc1f
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalMeterServiceImpl.java
1 /**
2  * Copyright (c) 2015 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 package org.opendaylight.openflowplugin.impl.services;
9
10 import com.google.common.base.Function;
11 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.slf4j.Logger;
23 import java.math.BigInteger;
24 import java.util.concurrent.Future;
25
26 public class SalMeterServiceImpl extends CommonService implements SalMeterService {
27
28     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalMeterServiceImpl.class);
29
30     @Override
31     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
32         return ServiceCallProcessingUtil.<AddMeterOutput, Void>handleServiceCall(rpcContext, PRIMARY_CONNECTION,
33                 deviceContext, new Function<BigInteger,Future<RpcResult<Void>>>() {
34                     @Override
35                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
36                         return convertAndSend(input, IDConnection);
37                     }
38                 });
39     }
40
41     @Override
42     public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
43         return ServiceCallProcessingUtil.<UpdateMeterOutput, Void>handleServiceCall(rpcContext, PRIMARY_CONNECTION,
44                 deviceContext, new Function<BigInteger,Future<RpcResult<Void>>>() {
45                     @Override
46                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
47                         return convertAndSend(input.getUpdatedMeter(), IDConnection);
48                     }
49                 });
50     }
51
52     @Override
53     public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
54         return ServiceCallProcessingUtil.<RemoveMeterOutput, Void>handleServiceCall(rpcContext, PRIMARY_CONNECTION,
55                 deviceContext, new Function<BigInteger,Future<RpcResult<Void>>>() {
56                     @Override
57                     public Future<RpcResult<Void>> apply(final BigInteger IDConnection) {
58                         return convertAndSend(input, IDConnection);
59                     }
60                 });
61     }
62
63     Future<RpcResult<Void>> convertAndSend(final Meter iputMeter, final BigInteger IDConnection) {
64         final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(iputMeter, version);
65         ofMeterModInput.setXid(deviceContext.getNextXid().getValue());
66         return provideConnectionAdapter(IDConnection).meterMod(ofMeterModInput.build());
67     }
68 }