2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.services.sal;
10 import java.util.Optional;
11 import java.util.concurrent.Future;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
16 import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerPortService;
17 import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
30 public final class SalPortServiceImpl
31 extends AbstractSimpleService<UpdatePortInput, UpdatePortOutput> implements SalPortService {
32 private final ConvertorExecutor convertorExecutor;
33 private final VersionConvertorData data;
34 private final SingleLayerPortService<UpdatePortOutput> portMessage;
36 public SalPortServiceImpl(final RequestContextStack requestContextStack,
37 final DeviceContext deviceContext,
38 final ConvertorExecutor convertorExecutor) {
39 super(requestContextStack, deviceContext, UpdatePortOutput.class);
40 this.convertorExecutor = convertorExecutor;
41 data = new VersionConvertorData(getVersion());
42 portMessage = new SingleLayerPortService<>(requestContextStack, deviceContext, UpdatePortOutput.class);
46 public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
47 return portMessage.canUseSingleLayerSerialization()
48 ? portMessage.handleServiceCall(getPortFromInput(input))
49 : handleServiceCall(input);
53 protected OfHeader buildRequest(final Xid xid, final UpdatePortInput input) throws ServiceException {
54 final Optional<PortModInput> ofPortModInput = convertorExecutor
55 .convert(getPortFromInput(input), data);
57 final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput
58 .orElse(PortConvertor.defaultResult(getVersion())))
59 .setXid(xid.getValue());
61 return mdInput.build();
64 private Port getPortFromInput(final UpdatePortInput input) {
65 return input.getUpdatedPort().getPort().getPort().get(0);