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 java.util.concurrent.Future;
12 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
13 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
15 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
16 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
24 import org.opendaylight.yangtools.yang.common.RpcError;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
28 public class NodeConfigServiceImpl extends CommonService implements NodeConfigService {
29 public NodeConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
30 super(requestContextStack, deviceContext);
34 public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
35 final RequestContext<SetConfigOutput> requestContext = createRequestContext();
36 if (requestContext == null) {
37 return failedFuture();
40 SetConfigInputBuilder builder = new SetConfigInputBuilder();
41 SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
43 final Xid xid = requestContext.getXid();
44 builder.setXid(xid.getValue());
45 builder.setFlags(flag);
46 builder.setMissSendLen(input.getMissSearchLength());
47 builder.setVersion(getVersion());
48 final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput setConfigInput = builder.build();
50 final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
51 outboundQueue.commitEntry(xid.getValue(), setConfigInput, new FutureCallback<OfHeader>() {
53 public void onSuccess(final OfHeader ofHeader) {
54 RpcResultBuilder<SetConfigOutput> rpcResultBuilder = RpcResultBuilder.success((SetConfigOutput)ofHeader);
55 requestContext.setResult(rpcResultBuilder.build());
56 RequestContextUtil.closeRequstContext(requestContext);
58 getMessageSpy().spyMessage(setConfigInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
62 public void onFailure(final Throwable throwable) {
63 RpcResultBuilder<SetConfigOutput> rpcResultBuilder = RpcResultBuilder.<SetConfigOutput>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
64 requestContext.setResult(rpcResultBuilder.build());
65 RequestContextUtil.closeRequstContext(requestContext);
67 getMessageSpy().spyMessage(setConfigInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
70 return requestContext.getFuture();