Merge "Bug 6176 - Decrease logging level in Sal-F/G/M-Service and use synchronized...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / PacketProcessingServiceImpl.java
index fa636f41eb63192b5977ba2c1a6c70d49063fab0..e32dbb5337d5fcb67703c41b073860740f2d1959 100644 (file)
@@ -7,40 +7,41 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
-import com.google.common.base.Function;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import java.math.BigInteger;
+import java.util.Optional;
 import java.util.concurrent.Future;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
-public class PacketProcessingServiceImpl extends CommonService implements PacketProcessingService {
-
-    @Override
-    public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
+public final class PacketProcessingServiceImpl extends AbstractVoidService<TransmitPacketInput> implements PacketProcessingService {
 
-        return handleServiceCall(PRIMARY_CONNECTION, new Function<DataCrate<Void>, Future<RpcResult<Void>>>() {
+    private final ConvertorExecutor convertorExecutor;
 
-            @Override
-            public Future<RpcResult<Void>> apply(DataCrate<Void> data) {
-                final Xid xid = deviceContext.getNextXid();
-                data.getRequestContext().setXid(xid);
-                final PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, xid.getValue(),
-                        datapathId);
+    public PacketProcessingServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final ConvertorExecutor convertorExecutor) {
+        super(requestContextStack, deviceContext);
+        this.convertorExecutor = convertorExecutor;
+    }
 
-                BigInteger connectionID = PRIMARY_CONNECTION;
-                final ConnectionCookie connectionCookie = input.getConnectionCookie();
-                if (connectionCookie != null && connectionCookie.getValue() != null) {
-                    connectionID = BigInteger.valueOf(connectionCookie.getValue());
-                }
+    @Override
+    public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
+        return handleServiceCall(input);
+    }
 
-                return provideConnectionAdapter(connectionID).packetOut(message);
-            }
-        });
+    @Override
+    protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) throws ServiceException {
+        final PacketOutConvertorData data = new PacketOutConvertorData(getVersion());
+        data.setDatapathId(getDatapathId());
+        data.setXid(xid.getValue());
 
+        final Optional<PacketOutInput> result = convertorExecutor.convert(input, data);
+        return result.orElse(PacketOutConvertor.defaultResult(getVersion()));
     }
 }