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 com.google.common.util.concurrent.FutureCallback;
11 import com.google.common.util.concurrent.SettableFuture;
12 import java.util.concurrent.Future;
13 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
18 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
26 import org.opendaylight.yangtools.yang.common.RpcError;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
30 public class NodeConfigServiceImpl extends CommonService implements NodeConfigService {
33 public NodeConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
34 super(requestContextStack, deviceContext);
38 public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
39 final RequestContext<SetConfigOutput> requestContext = createRequestContext();
40 if (requestContext == null) {
41 return failedFuture();
44 SetConfigInputBuilder builder = new SetConfigInputBuilder();
45 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
47 final Xid xid = requestContext.getXid();
48 builder.setXid(xid.getValue());
49 builder.setFlags(flag);
50 builder.setMissSendLen(input.getMissSearchLength());
51 builder.setVersion(getVersion());
52 final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
54 final SettableFuture<RpcResult<SetConfigOutput>> settableFuture = SettableFuture.create();
55 outboundQueue.commitEntry(xid.getValue(), builder.build(), new FutureCallback<OfHeader>() {
57 public void onSuccess(final OfHeader ofHeader) {
58 RequestContextUtil.closeRequstContext(requestContext);
59 getDeviceContext().unhookRequestCtx(requestContext.getXid());
60 getMessageSpy().spyMessage(FlowModInput.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
62 settableFuture.set(RpcResultBuilder.<SetConfigOutput>success().build());
66 public void onFailure(final Throwable throwable) {
67 RpcResultBuilder rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
68 RequestContextUtil.closeRequstContext(requestContext);
69 getDeviceContext().unhookRequestCtx(requestContext.getXid());
70 settableFuture.set(rpcResultBuilder.build());
73 return settableFuture;