Merge "Bug 2895: Fix for FRM ClassNotFoundException"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / PacketProcessingServiceImpl.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 com.google.common.base.Function;
11 import com.google.common.util.concurrent.JdkFutureAdapters;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.math.BigInteger;
14 import java.util.concurrent.Future;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22
23 public class PacketProcessingServiceImpl extends CommonService implements PacketProcessingService {
24
25     @Override
26     public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
27
28         return handleServiceCall(PRIMARY_CONNECTION, new Function<DataCrate<Void>, ListenableFuture<RpcResult<Void>>>() {
29
30             @Override
31             public ListenableFuture<RpcResult<Void>> apply(DataCrate<Void> data) {
32                 final Xid xid = deviceContext.getNextXid();
33                 data.getRequestContext().setXid(xid);
34                 final PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, version, xid.getValue(),
35                         datapathId);
36
37                 BigInteger connectionID = PRIMARY_CONNECTION;
38                 final ConnectionCookie connectionCookie = input.getConnectionCookie();
39                 if (connectionCookie != null && connectionCookie.getValue() != null) {
40                     connectionID = BigInteger.valueOf(connectionCookie.getValue());
41                 }
42
43                 return JdkFutureAdapters.listenInPoolThread(provideConnectionAdapter(connectionID).packetOut(message));
44             }
45         });
46
47     }
48 }