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;
10 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
13 import com.google.common.base.Function;
14 import com.google.common.util.concurrent.JdkFutureAdapters;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.math.BigInteger;
17 import java.util.concurrent.Future;
18 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
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.ConnectionCookie;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
26 public class PacketProcessingServiceImpl extends CommonService implements PacketProcessingService {
28 public PacketProcessingServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
29 super(requestContextStack, deviceContext);
33 public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
35 return handleServiceCall(PRIMARY_CONNECTION, new Function<DataCrate<Void>, ListenableFuture<RpcResult<Void>>>() {
38 public ListenableFuture<RpcResult<Void>> apply(DataCrate<Void> data) {
39 final Xid xid = deviceContext.getNextXid();
40 data.getRequestContext().setXid(xid);
41 final PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, xid.getValue(),
44 BigInteger connectionID = PRIMARY_CONNECTION;
45 final ConnectionCookie connectionCookie = input.getConnectionCookie();
46 if (connectionCookie != null && connectionCookie.getValue() != null) {
47 connectionID = BigInteger.valueOf(connectionCookie.getValue());
50 return JdkFutureAdapters.listenInPoolThread(provideConnectionAdapter(connectionID).packetOut(message));