Merge "unifying statistics manager api packages"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalPortServiceImpl.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 org.opendaylight.openflowplugin.api.openflow.device.Xid;
11
12 import com.google.common.base.Function;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21 import org.slf4j.Logger;
22 import java.util.concurrent.Future;
23
24 public class SalPortServiceImpl extends CommonService implements SalPortService {
25     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalPortServiceImpl.class);
26
27     @Override
28     public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
29         return this.<UpdatePortOutput, Void> handleServiceCall(PRIMARY_CONNECTION,
30                 new Function<DataCrate<UpdatePortOutput>, Future<RpcResult<Void>>>() {
31                     @Override
32                     public Future<RpcResult<Void>> apply(final DataCrate<UpdatePortOutput> data) {
33                         final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
34                         final PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, version);
35                         final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
36                         Xid xid = deviceContext.getNextXid();
37                         mdInput.setXid(xid.getValue());
38                         data.getRequestContext().setXid(xid);
39                         return provideConnectionAdapter(data.getiDConnection()).portMod(mdInput.build());
40                     }
41                 });
42     }
43
44 }