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 com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Optional;
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.openflow.md.core.sal.convertor.ConvertorExecutor;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.XidConvertorData;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacket;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketOutput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
26 public final class TransmitPacketImpl extends AbstractSimpleService<TransmitPacketInput, TransmitPacketOutput>
27 implements TransmitPacket {
28 private final ConvertorExecutor convertorExecutor;
30 public TransmitPacketImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
31 final ConvertorExecutor convertorExecutor) {
32 super(requestContextStack, deviceContext, TransmitPacketOutput.class);
33 this.convertorExecutor = convertorExecutor;
37 public ListenableFuture<RpcResult<TransmitPacketOutput>> invoke(final TransmitPacketInput input) {
38 return handleServiceCall(input);
42 protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) {
43 final XidConvertorData data = new XidConvertorData(getVersion());
44 data.setDatapathId(getDatapathId());
45 data.setXid(xid.getValue());
47 final Optional<PacketOutInput> result = convertorExecutor.convert(input, data);
48 return result.orElse(PacketOutConvertor.defaultResult(getVersion()));