--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.util.concurrent.FutureCallback;
+import java.util.List;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+
+public abstract class AbstractMultipartService<I> extends AbstractService<I, List<MultipartReply>> {
+ protected AbstractMultipartService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext);
+ }
+
+ @Override
+ protected final FutureCallback<OfHeader> createCallback(final RequestContext<List<MultipartReply>> context, final Class<?> requestType) {
+ return new MultipartRequestCallback(context, requestType, getDeviceContext());
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy.STATISTIC_GROUP;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+abstract class AbstractRequestCallback<T> implements FutureCallback<OfHeader> {
+ private final RequestContext<T> context;
+ private final Class<?> requestType;
+ private final MessageSpy spy;
+
+ protected AbstractRequestCallback(final RequestContext<T> context, final Class<?> requestType, final MessageSpy spy) {
+ this.context = Preconditions.checkNotNull(context);
+ this.requestType = Preconditions.checkNotNull(requestType);
+ this.spy = Preconditions.checkNotNull(spy);
+ }
+
+ protected final void setResult(@Nullable final RpcResult<T> result) {
+ context.setResult(result);
+ context.close();
+ }
+
+ protected final void spyMessage(@Nonnull final STATISTIC_GROUP group) {
+ spy.spyMessage(requestType, Preconditions.checkNotNull(group));
+ }
+
+ @Override
+ public final void onFailure(final Throwable t) {
+ final RpcResultBuilder<T> builder;
+ if (t instanceof DeviceRequestFailedException) {
+ final Error err = ((DeviceRequestFailedException) t).getError();
+ final String errorString = String.format("Device reported error type %s code %s", err.getTypeString(), err.getCodeString());
+
+ builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, errorString, t);
+ spyMessage(MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
+ } else {
+ builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, t.getMessage(), t);
+ spyMessage(MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_ERROR);
+ }
+
+ context.setResult(builder.build());
+ RequestContextUtil.closeRequstContext(context);
+ }
+}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
+import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
+import javax.annotation.Nonnull;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public abstract class CommonService {
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(CommonService.class);
+abstract class AbstractService<I, O> {
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractService.class);
private static final long WAIT_TIME = 2000;
private static final BigInteger PRIMARY_CONNECTION = BigInteger.ZERO;
private final ConnectionAdapter primaryConnectionAdapter;
private final MessageSpy messageSpy;
- public CommonService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ public AbstractService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
this.requestContextStack = requestContextStack;
this.deviceContext = deviceContext;
final FeaturesReply features = this.deviceContext.getPrimaryConnectionContext().getFeatures();
return messageSpy;
}
+ protected abstract OfHeader buildRequest(Xid xid, I input);
+ protected abstract FutureCallback<OfHeader> createCallback(RequestContext<O> context, Class<?> requestType);
- public final <T> ListenableFuture<RpcResult<T>> handleServiceCall(final Function<RequestContext<T>, ListenableFuture<RpcResult<T>>> function) {
+ public final ListenableFuture<RpcResult<O>> handleServiceCall(@Nonnull final I input) {
+ Preconditions.checkNotNull(input);
+
+ final Class<?> requestType;
+ if (input instanceof DataContainer) {
+ requestType = ((DataContainer) input).getImplementedInterface();
+ } else {
+ requestType = input.getClass();
+ }
+ getMessageSpy().spyMessage(requestType, MessageSpy.STATISTIC_GROUP.TO_SWITCH_ENTERED);
LOG.trace("Handling general service call");
- final RequestContext<T> requestContext = createRequestContext();
+ final RequestContext<O> requestContext = requestContextStack.createRequestContext();
if (requestContext == null) {
LOG.trace("Request context refused.");
- deviceContext.getMessageSpy().spyMessage(CommonService.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_DISREGARDED);
+ deviceContext.getMessageSpy().spyMessage(AbstractService.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_DISREGARDED);
return failedFuture();
}
}
messageSpy.spyMessage(requestContext.getClass(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_READY_FOR_SUBMIT);
- function.apply(requestContext);
-
- return requestContext.getFuture();
- }
+ final Xid xid = requestContext.getXid();
+ OfHeader request = null;
+ try {
+ request = buildRequest(xid, input);
+ Verify.verify(xid.getValue().equals(request.getXid()), "Expected XID %s got %s", xid.getValue(), request.getXid());
+ } catch (Exception e) {
+ LOG.error("Failed to build request for {}, forfeiting request {}", input, xid.getValue(), e);
+ // FIXME: complete the requestContext
+ } finally {
+ final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
+ outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType));
+ }
- protected final <T> RequestContext<T> createRequestContext() {
- return requestContextStack.createRequestContext();
+ return requestContext.getFuture();
}
protected static <T> ListenableFuture<RpcResult<T>> failedFuture() {
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public abstract class AbstractSimpleService<I, O extends DataObject> extends AbstractService<I, O> {
+ private final Class<O> clazz;
+
+ protected AbstractSimpleService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<O> clazz) {
+ super(requestContextStack, deviceContext);
+ this.clazz = Preconditions.checkNotNull(clazz);
+ }
+
+ @Override
+ protected final FutureCallback<OfHeader> createCallback(final RequestContext<O> context, final Class<?> requestType) {
+ return SimpleRequestCallback.create(context, requestType, getMessageSpy(), clazz);
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.util.concurrent.FutureCallback;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public abstract class AbstractVoidService<T extends DataObject> extends AbstractService<T, Void> {
+ protected AbstractVoidService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext);
+ }
+
+ @Override
+ protected final FutureCallback<OfHeader> createCallback(final RequestContext<Void> context, final Class<?> requestType) {
+ return new VoidRequestCallback(context, requestType, getMessageSpy());
+ }
+}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.util.concurrent.FutureCallback;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrierInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FlowCapableTransactionServiceImpl extends CommonService implements FlowCapableTransactionService {
- private static final RpcResult<Void> SUCCESS = RpcResultBuilder.<Void>success().build();
- private static final Logger LOG = LoggerFactory.getLogger(FlowCapableTransactionServiceImpl.class);
+public class FlowCapableTransactionServiceImpl extends AbstractVoidService<SendBarrierInput> implements FlowCapableTransactionService {
public FlowCapableTransactionServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
super(requestContextStack, deviceContext);
}
@Override
public Future<RpcResult<Void>> sendBarrier(final SendBarrierInput input) {
- final RequestContext<Void> requestContext = getRequestContextStack().createRequestContext();
- if (requestContext == null) {
- getMessageSpy().spyMessage(null, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- return failedFuture();
- }
-
+ return handleServiceCall(input);
+ }
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final SendBarrierInput input) {
final BarrierInputBuilder barrierInputOFJavaBuilder = new BarrierInputBuilder();
- final Xid xid = requestContext.getXid();
barrierInputOFJavaBuilder.setVersion(getVersion());
barrierInputOFJavaBuilder.setXid(xid.getValue());
- final BarrierInput barrierInput = barrierInputOFJavaBuilder.build();
-
- LOG.trace("Hooking xid {} to device context - precaution.", requestContext.getXid().getValue());
-
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
- outboundQueue.commitEntry(xid.getValue(), barrierInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- requestContext.setResult(SUCCESS);
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(barrierInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(barrierInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
+ return barrierInputOFJavaBuilder.build();
}
}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+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.FlowConvertor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+
+final class FlowRemoveService extends AbstractSimpleService<RemoveFlowInput, RemoveFlowOutput> {
+ FlowRemoveService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, RemoveFlowOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final RemoveFlowInput input) {
+ final FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, getVersion(),
+ getDatapathId());
+ ofFlowModInput.setXid(xid.getValue());
+ return ofFlowModInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import java.util.ArrayList;
+import java.util.List;
+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.FlowConvertor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+final class FlowService<O extends DataObject> extends AbstractSimpleService<FlowModInputBuilder, O> {
+
+ protected FlowService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<O> clazz) {
+ super(requestContextStack, deviceContext, clazz);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final FlowModInputBuilder input) {
+ input.setXid(xid.getValue());
+ return input.build();
+ }
+
+ List<FlowModInputBuilder> toFlowModInputs(final Flow input) {
+ return FlowConvertor.toFlowModInputs(input, getVersion(), getDatapathId());
+ }
+
+ ListenableFuture<RpcResult<O>> processFlowModInputBuilders(final List<FlowModInputBuilder> ofFlowModInputs) {
+ final List<ListenableFuture<RpcResult<O>>> partialFutures = new ArrayList<>(ofFlowModInputs.size());
+
+ for (final FlowModInputBuilder flowModInputBuilder : ofFlowModInputs) {
+ partialFutures.add(handleServiceCall(flowModInputBuilder));
+ }
+
+ final ListenableFuture<List<RpcResult<O>>> allFutures = Futures.successfulAsList(partialFutures);
+ final SettableFuture<RpcResult<O>> finalFuture = SettableFuture.create();
+ Futures.addCallback(allFutures, new FutureCallback<List<RpcResult<O>>>() {
+ @Override
+ public void onSuccess(final List<RpcResult<O>> results) {
+ RpcResultBuilder<O> rpcResultBuilder = RpcResultBuilder.success();
+ finalFuture.set(rpcResultBuilder.build());
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ RpcResultBuilder<O> rpcResultBuilder = RpcResultBuilder.failed();
+ finalFuture.set(rpcResultBuilder.build());
+ }
+ });
+
+ return finalFuture;
+ }
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+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.GroupConvertor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+final class GroupService<I extends Group, O extends DataObject> extends AbstractSimpleService<I, O> {
+ GroupService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<O> clazz) {
+ super(requestContextStack, deviceContext, clazz);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final I input) {
+ final GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(input, getVersion(), getDatapathId());
+ ofGroupModInput.setXid(xid.getValue());
+
+ return ofGroupModInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+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.MeterConvertor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+final class MeterService<I extends Meter, O extends DataObject> extends AbstractSimpleService<I, O> {
+
+ MeterService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<O> clazz) {
+ super(requestContextStack, deviceContext, clazz);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final I input) {
+ final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(input, getVersion());
+ ofMeterModInput.setXid(xid.getValue());
+ return ofMeterModInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import java.util.List;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class MultipartRequestCallback extends AbstractRequestCallback<List<MultipartReply>> {
+ private static final Logger LOG = LoggerFactory.getLogger(MultipartRequestCallback.class);
+ private final MultiMsgCollector collector;
+
+ public MultipartRequestCallback(final RequestContext<List<MultipartReply>> context, final Class<?> requestType, final DeviceContext deviceContext) {
+ super(context, requestType, deviceContext.getMessageSpy());
+ collector = deviceContext.getMultiMsgCollector(context);
+ }
+
+ @Override
+ public void onSuccess(final OfHeader result) {
+ if (result == null) {
+ LOG.info("Ofheader was null.");
+ collector.endCollecting();
+ return;
+ }
+
+ if (!(result instanceof MultipartReply)) {
+ LOG.info("Unexpected response type received {}.", result.getClass());
+ final RpcResultBuilder<List<MultipartReply>> rpcResultBuilder =
+ RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.APPLICATION,
+ String.format("Unexpected response type received %s.", result.getClass()));
+ setResult(rpcResultBuilder.build());
+ } else {
+ collector.addMultipartMsg((MultipartReply) result);
+ }
+ }
+
+}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.util.concurrent.FutureCallback;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInputBuilder;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-public class NodeConfigServiceImpl extends CommonService implements NodeConfigService {
+public final class NodeConfigServiceImpl extends AbstractSimpleService<SetConfigInput, SetConfigOutput> implements NodeConfigService {
public NodeConfigServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ super(requestContextStack, deviceContext, SetConfigOutput.class);
}
@Override
public Future<RpcResult<SetConfigOutput>> setConfig(final SetConfigInput input) {
- final RequestContext<SetConfigOutput> requestContext = createRequestContext();
- if (requestContext == null) {
- return failedFuture();
- }
+ return handleServiceCall(input);
+ }
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final SetConfigInput input) {
SetConfigInputBuilder builder = new SetConfigInputBuilder();
SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag());
- final Xid xid = requestContext.getXid();
builder.setXid(xid.getValue());
builder.setFlags(flag);
builder.setMissSendLen(input.getMissSearchLength());
builder.setVersion(getVersion());
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput setConfigInput = builder.build();
-
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
- outboundQueue.commitEntry(xid.getValue(), setConfigInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- RpcResultBuilder<SetConfigOutput> rpcResultBuilder = RpcResultBuilder.success((SetConfigOutput)ofHeader);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(setConfigInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- RpcResultBuilder<SetConfigOutput> rpcResultBuilder = RpcResultBuilder.<SetConfigOutput>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(setConfigInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
-
+ return builder.build();
}
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor;
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.PacketProcessingService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-public class PacketProcessingServiceImpl extends CommonService implements PacketProcessingService {
+public final class PacketProcessingServiceImpl extends AbstractVoidService<TransmitPacketInput> implements PacketProcessingService {
public PacketProcessingServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
super(requestContextStack, deviceContext);
@Override
public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) {
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_ENTERED);
-
- return handleServiceCall(new Function<RequestContext<Void>, ListenableFuture<RpcResult<Void>>>() {
- @Override
- public ListenableFuture<RpcResult<Void>> apply(final RequestContext<Void> requestContext) {
- final Xid xid = requestContext.getXid();
- final PacketOutInput message = PacketOutConvertor.toPacketOutInput(input, getVersion(), xid.getValue(),
- getDatapathId());
-
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
-
- outboundQueue.commitEntry(xid.getValue(), message, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- getMessageSpy().spyMessage(message.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- final RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.<Void>success();
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- getMessageSpy().spyMessage(message.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- final RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
- }
- });
- return requestContext.getFuture();
- }
- });
+ return handleServiceCall(input);
+ }
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final TransmitPacketInput input) {
+ return PacketOutConvertor.toPacketOutInput(input, getVersion(), xid.getValue(), getDatapathId());
}
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.util.concurrent.FutureCallback;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SendEchoOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SalEchoServiceImpl extends CommonService implements SalEchoService {
-
- private static final Logger LOG = LoggerFactory.getLogger(SalEchoServiceImpl.class);
+public final class SalEchoServiceImpl extends AbstractSimpleService<SendEchoInput, SendEchoOutput> implements SalEchoService {
public SalEchoServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ super(requestContextStack, deviceContext, SendEchoOutput.class);
}
@Override
public Future<RpcResult<SendEchoOutput>> sendEcho(final SendEchoInput sendEchoInput) {
- final RequestContext<SendEchoOutput> requestContext = getRequestContextStack().createRequestContext();
- if (requestContext == null) {
- getMessageSpy().spyMessage(null, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- return failedFuture();
- }
+ return handleServiceCall(sendEchoInput);
+ }
- LOG.trace("Hooking xid {} to device context - precaution.", requestContext.getXid().getValue());
- final Xid xid = requestContext.getXid();
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final SendEchoInput input) {
final EchoInputBuilder echoInputOFJavaBuilder = new EchoInputBuilder();
echoInputOFJavaBuilder.setVersion(getVersion());
- echoInputOFJavaBuilder.setXid(requestContext.getXid().getValue());
- echoInputOFJavaBuilder.setData(sendEchoInput.getData());
- final EchoInput echoInputOFJava = echoInputOFJavaBuilder.build();
-
- LOG.debug("Echo with xid {} was sent from controller", xid);
-
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
- outboundQueue.commitEntry(xid.getValue(), echoInputOFJava, new FutureCallback<OfHeader>() {
-
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- RpcResultBuilder<SendEchoOutput> rpcResultBuilder = RpcResultBuilder.success((SendEchoOutput)ofHeader);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(echoInputOFJava.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- RpcResultBuilder<SendEchoOutput> rpcResultBuilder = RpcResultBuilder.<SendEchoOutput>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(echoInputOFJava.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
+ echoInputOFJavaBuilder.setXid(xid.getValue());
+ echoInputOFJavaBuilder.setData(input.getData());
+ return echoInputOFJavaBuilder.build();
}
}
/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- * <p/>
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.util.FlowUtil;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowConvertor;
import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class SalFlowServiceImpl extends CommonService implements SalFlowService {
-
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalFlowServiceImpl.class);
+public class SalFlowServiceImpl implements SalFlowService {
+ private static final Logger LOG = LoggerFactory.getLogger(SalFlowServiceImpl.class);
+ private final FlowService<UpdateFlowOutput> flowUpdate;
+ private final FlowService<AddFlowOutput> flowAdd;
+ private final FlowRemoveService flowRemove;
public SalFlowServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ flowRemove = new FlowRemoveService(requestContextStack, deviceContext);
+ flowAdd = new FlowService<>(requestContextStack, deviceContext, AddFlowOutput.class);
+ flowUpdate = new FlowService<>(requestContextStack, deviceContext, UpdateFlowOutput.class);
}
@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_ENTERED);
-
- final List<FlowModInputBuilder> ofFlowModInputs = FlowConvertor.toFlowModInputs(input, getVersion(), getDatapathId());
- final ListenableFuture<RpcResult<AddFlowOutput>> future = processFlowModInputBuilders(ofFlowModInputs);
+ final ListenableFuture<RpcResult<AddFlowOutput>> future = flowAdd.processFlowModInputBuilders(flowAdd.toFlowModInputs(input));
final FlowId flowId;
if (null != input.getFlowRef()) {
flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
flowId = FlowUtil.createAlienFlowId(input.getTableId());
}
- final DeviceContext deviceContext = getDeviceContext();
+ final DeviceContext deviceContext = flowAdd.getDeviceContext();
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
Futures.addCallback(future, new FutureCallback<RpcResult<AddFlowOutput>>() {
-
-
@Override
public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
if (rpcResult.isSuccessful()) {
@Override
public Future<RpcResult<RemoveFlowOutput>> removeFlow(final RemoveFlowInput input) {
LOG.trace("Calling remove flow for flow with ID ={}.", input.getFlowRef());
- return handleServiceCall(new Function<RequestContext<RemoveFlowOutput>, ListenableFuture<RpcResult<RemoveFlowOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<RemoveFlowOutput>> apply(final RequestContext<RemoveFlowOutput> requestContext) {
- final FlowModInputBuilder ofFlowModInput = FlowConvertor.toFlowModInput(input, getVersion(),
- getDatapathId());
- final ListenableFuture<RpcResult<RemoveFlowOutput>> future = createResultForFlowMod(requestContext, ofFlowModInput);
- Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFlowOutput>>() {
- @Override
- public void onSuccess(final RpcResult<RemoveFlowOutput> o) {
- final DeviceContext deviceContext = getDeviceContext();
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
- deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
- }
- @Override
- public void onFailure(final Throwable throwable) {
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- LOG.trace("Flow modification failed..", throwable);
+ final ListenableFuture<RpcResult<RemoveFlowOutput>> future = flowRemove.handleServiceCall(input);
+ Futures.addCallback(future, new FutureCallback<RpcResult<RemoveFlowOutput>>() {
+ @Override
+ public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
+ if (result.isSuccessful()) {
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
+ flowRemove.getDeviceContext().getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
+ } else {
+ if (LOG.isTraceEnabled()) {
StringBuilder errors = new StringBuilder();
- try {
- RpcResult<RemoveFlowOutput> result = future.get();
- Collection<RpcError> rpcErrors = result.getErrors();
- if (null != rpcErrors && rpcErrors.size() > 0) {
- for (RpcError rpcError : rpcErrors) {
- errors.append(rpcError.getMessage());
- }
+ Collection<RpcError> rpcErrors = result.getErrors();
+ if (null != rpcErrors && rpcErrors.size() > 0) {
+ for (RpcError rpcError : rpcErrors) {
+ errors.append(rpcError.getMessage());
}
- } catch (InterruptedException | ExecutionException e) {
- LOG.trace("Flow modification failed. Can't read errors from RpcResult.");
- } finally {
- LOG.trace("Flow modification failed. Errors : {}", errors.toString());
}
+ LOG.trace("Flow modification failed. Errors : {}", errors.toString());
}
- });
- return future;
+ }
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.trace("Flow modification failed..", throwable);
}
});
+
+ return future;
}
@Override
final OriginalFlow original = in.getOriginalFlow();
final List<FlowModInputBuilder> allFlowMods = new ArrayList<>();
- List<FlowModInputBuilder> ofFlowModInputs;
+ final List<FlowModInputBuilder> ofFlowModInputs;
- if (!FlowCreatorUtil.canModifyFlow(original, updated, getVersion())) {
+ if (!FlowCreatorUtil.canModifyFlow(original, updated, flowUpdate.getVersion())) {
// We would need to remove original and add updated.
// remove flow
final RemoveFlowInputBuilder removeflow = new RemoveFlowInputBuilder(original);
- final List<FlowModInputBuilder> ofFlowRemoveInput = FlowConvertor.toFlowModInputs(removeflow.build(),
- getVersion(), getDatapathId());
+ final List<FlowModInputBuilder> ofFlowRemoveInput = flowUpdate.toFlowModInputs(removeflow.build());
// remove flow should be the first
allFlowMods.addAll(ofFlowRemoveInput);
final AddFlowInputBuilder addFlowInputBuilder = new AddFlowInputBuilder(updated);
- ofFlowModInputs = FlowConvertor.toFlowModInputs(addFlowInputBuilder.build(), getVersion(), getDatapathId());
+ ofFlowModInputs = flowUpdate.toFlowModInputs(addFlowInputBuilder.build());
} else {
- ofFlowModInputs = FlowConvertor.toFlowModInputs(updated, getVersion(), getDatapathId());
+ ofFlowModInputs = flowUpdate.toFlowModInputs(updated);
}
allFlowMods.addAll(ofFlowModInputs);
- ListenableFuture<RpcResult<UpdateFlowOutput>> future = processFlowModInputBuilders(allFlowMods);
+ ListenableFuture<RpcResult<UpdateFlowOutput>> future = flowUpdate.processFlowModInputBuilders(allFlowMods);
Futures.addCallback(future, new FutureCallback<RpcResult<UpdateFlowOutput>>() {
@Override
public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
- final DeviceContext deviceContext = getDeviceContext();
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
FlowId flowId = input.getFlowRef().getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
- final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+ final DeviceFlowRegistry deviceFlowRegistry = flowUpdate.getDeviceContext().getDeviceFlowRegistry();
deviceFlowRegistry.markToBeremoved(flowRegistryKey);
deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
}
@Override
public void onFailure(final Throwable throwable) {
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
+ LOG.debug("Flow update failed", throwable);
}
});
return future;
}
-
- private <T> ListenableFuture<RpcResult<T>> processFlowModInputBuilders(final List<FlowModInputBuilder> ofFlowModInputs) {
-
- final List<ListenableFuture<RpcResult<T>>> partialFutures = new ArrayList<>();
-
- for (final FlowModInputBuilder flowModInputBuilder : ofFlowModInputs) {
- ListenableFuture<RpcResult<T>> partialFuture = handleServiceCall(
- new Function<RequestContext<T>, ListenableFuture<RpcResult<T>>>() {
- @Override
- public ListenableFuture<RpcResult<T>> apply(final RequestContext<T> requestContext) {
- return createResultForFlowMod(requestContext, flowModInputBuilder);
- }
- });
- partialFutures.add(partialFuture);
- }
-
- final ListenableFuture<List<RpcResult<T>>> allFutures = Futures.successfulAsList(partialFutures);
- final SettableFuture<RpcResult<T>> finalFuture = SettableFuture.create();
- Futures.addCallback(allFutures, new FutureCallback<List<RpcResult<T>>>() {
- @Override
- public void onSuccess(final List<RpcResult<T>> results) {
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.success();
- finalFuture.set(rpcResultBuilder.build());
- }
-
- @Override
- public void onFailure(final Throwable t) {
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.failed();
- finalFuture.set(rpcResultBuilder.build());
- }
- });
-
- return finalFuture;
- }
-
- protected <T> ListenableFuture<RpcResult<T>> createResultForFlowMod(final RequestContext<T> requestContext, final FlowModInputBuilder flowModInputBuilder) {
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
- final long xid = requestContext.getXid().getValue();
- flowModInputBuilder.setXid(xid);
- final FlowModInput flowModInput = flowModInputBuilder.build();
-
- outboundQueue.commitEntry(xid, flowModInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- getMessageSpy().spyMessage(FlowModInput.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
-
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.<T>success();
- requestContext.setResult(rpcResultBuilder.build());
-
- RequestContextUtil.closeRequstContext(requestContext);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- getMessageSpy().spyMessage(FlowModInput.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
-
- RequestContextUtil.closeRequstContext(requestContext);
- }
- });
- return requestContext.getFuture();
- }
-
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-
-public class SalGroupServiceImpl extends CommonService implements SalGroupService {
+public class SalGroupServiceImpl implements SalGroupService {
+ private final GroupService<AddGroupInput, AddGroupOutput> addGroup;
+ private final GroupService<Group, UpdateGroupOutput> updateGroup;
+ private final GroupService<RemoveGroupInput, RemoveGroupOutput> removeGroup;
public SalGroupServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ addGroup = new GroupService<>(requestContextStack, deviceContext, AddGroupOutput.class);
+ updateGroup = new GroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class);
+ removeGroup = new GroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class);
}
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalGroupServiceImpl.class);
-
@Override
public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
- getDeviceContext().getDeviceGroupRegistry().store(input.getGroupId());
- return handleServiceCall(new Function<RequestContext<AddGroupOutput>,
- ListenableFuture<RpcResult<AddGroupOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<AddGroupOutput>> apply(final RequestContext<AddGroupOutput> requestContext) {
- return convertAndSend(input, requestContext);
- }
- });
+ addGroup.getDeviceContext().getDeviceGroupRegistry().store(input.getGroupId());
+ return addGroup.handleServiceCall(input);
}
@Override
public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
- return handleServiceCall(new Function<RequestContext<UpdateGroupOutput>,
- ListenableFuture<RpcResult<UpdateGroupOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<UpdateGroupOutput>> apply(final RequestContext<UpdateGroupOutput> requestContext) {
- return convertAndSend(input.getUpdatedGroup(), requestContext);
- }
- });
+ return updateGroup.handleServiceCall(input.getUpdatedGroup());
}
@Override
public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
- getDeviceContext().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
- return handleServiceCall(new Function<RequestContext<RemoveGroupOutput>,
- ListenableFuture<RpcResult<RemoveGroupOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<RemoveGroupOutput>> apply(final RequestContext<RemoveGroupOutput> requestContext) {
- return convertAndSend(input, requestContext);
- }
- });
- }
-
- <T> ListenableFuture<RpcResult<T>> convertAndSend(final Group iputGroup, final RequestContext<T> requestContext) {
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
- getMessageSpy().spyMessage(iputGroup.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- final GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(iputGroup, getVersion(), getDatapathId());
- final Xid xid = requestContext.getXid();
- ofGroupModInput.setXid(xid.getValue());
-
- final GroupModInput groupModInput = ofGroupModInput.build();
- outboundQueue.commitEntry(xid.getValue(), groupModInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.success((T)ofHeader);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(groupModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(groupModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
+ removeGroup.getDeviceContext().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
+ return removeGroup.handleServiceCall(input);
}
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-public class SalMeterServiceImpl extends CommonService implements SalMeterService {
-
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalMeterServiceImpl.class);
+public class SalMeterServiceImpl implements SalMeterService {
+ private final MeterService<AddMeterInput, AddMeterOutput> addMeter;
+ private final MeterService<Meter, UpdateMeterOutput> updateMeter;
+ private final MeterService<RemoveMeterInput, RemoveMeterOutput> removeMeter;
public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ addMeter = new MeterService<>(requestContextStack, deviceContext, AddMeterOutput.class);
+ updateMeter = new MeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class);
+ removeMeter = new MeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class);
}
@Override
public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
- getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId());
- return handleServiceCall(new Function<RequestContext<AddMeterOutput>,
- ListenableFuture<RpcResult<AddMeterOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<AddMeterOutput>> apply(final RequestContext<AddMeterOutput> requestContext) {
- return convertAndSend(input, requestContext);
- }
- });
+ addMeter.getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId());
+
+ return addMeter.handleServiceCall(input);
}
@Override
public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
- return handleServiceCall(new Function<RequestContext<UpdateMeterOutput>,
- ListenableFuture<RpcResult<UpdateMeterOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<UpdateMeterOutput>> apply(final RequestContext<UpdateMeterOutput> requestContext) {
- return convertAndSend(input.getUpdatedMeter(), requestContext);
- }
- });
+ return updateMeter.handleServiceCall(input.getUpdatedMeter());
}
@Override
public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
- getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
- return handleServiceCall(new Function<RequestContext<RemoveMeterOutput>,
- ListenableFuture<RpcResult<RemoveMeterOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<RemoveMeterOutput>> apply(final RequestContext<RemoveMeterOutput> requestContext) {
- return convertAndSend(input, requestContext);
- }
- });
- }
-
- <T> ListenableFuture<RpcResult<T>> convertAndSend(final Meter iputMeter, final RequestContext<T> requestContext) {
- getMessageSpy().spyMessage(iputMeter.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
-
- final MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(iputMeter, getVersion());
- final Xid xid = requestContext.getXid();
- ofMeterModInput.setXid(xid.getValue());
-
- final MeterModInput meterModInput = ofMeterModInput.build();
- outboundQueue.commitEntry(xid.getValue(), meterModInput, new FutureCallback<OfHeader>() {
-
- RpcResultBuilder<T> rpcResultBuilder;
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- rpcResultBuilder = RpcResultBuilder.<T>success();
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(meterModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- rpcResultBuilder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(meterModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
+ removeMeter.getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
+ return removeMeter.handleServiceCall(input);
}
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.SalPortService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-
-public class SalPortServiceImpl extends CommonService implements SalPortService {
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalPortServiceImpl.class);
+public final class SalPortServiceImpl extends AbstractSimpleService<UpdatePortInput, UpdatePortOutput> implements SalPortService {
public SalPortServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ super(requestContextStack, deviceContext, UpdatePortOutput.class);
}
@Override
public Future<RpcResult<UpdatePortOutput>> updatePort(final UpdatePortInput input) {
- return handleServiceCall(new Function<RequestContext<UpdatePortOutput>, ListenableFuture<RpcResult<UpdatePortOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<UpdatePortOutput>> apply(final RequestContext<UpdatePortOutput> requestContext) {
- getMessageSpy().spyMessage(input.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
-
- final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
- final PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, getVersion());
- final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
- final Xid xid = requestContext.getXid();
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
-
- mdInput.setXid(xid.getValue());
- final PortModInput portModInput = mdInput.build();
- outboundQueue.commitEntry(xid.getValue(), portModInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- RpcResultBuilder<UpdatePortOutput> rpcResultBuilder = RpcResultBuilder.success((UpdatePortOutput)ofHeader);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
-
- getMessageSpy().spyMessage(portModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
+ return handleServiceCall(input);
+ }
- @Override
- public void onFailure(final Throwable throwable) {
- RpcResultBuilder<UpdatePortOutput> rpcResultBuilder = RpcResultBuilder.<UpdatePortOutput>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final UpdatePortInput input) {
+ final Port inputPort = input.getUpdatedPort().getPort().getPort().get(0);
+ final PortModInput ofPortModInput = PortConvertor.toPortModInput(inputPort, getVersion());
+ final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput);
+ mdInput.setXid(xid.getValue());
- getMessageSpy().spyMessage(portModInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
- }
- });
+ return mdInput.build();
}
-
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import com.google.common.base.Function;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.MultipartReplyBody;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
-public class SalTableServiceImpl extends CommonService implements SalTableService {
-
+public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTableInput> implements SalTableService {
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalTableServiceImpl.class);
public SalTableServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
@Override
public Future<RpcResult<UpdateTableOutput>> updateTable(final UpdateTableInput input) {
- class FunctionImpl implements
- Function<RequestContext<List<MultipartReply>>, ListenableFuture<RpcResult<List<MultipartReply>>>> {
-
- @Override
- public ListenableFuture<RpcResult<List<MultipartReply>>> apply(final RequestContext<List<MultipartReply>> requestContext) {
- getMessageSpy().spyMessage(input.getImplementedInterface(),
- MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
-
- final SettableFuture<RpcResult<List<MultipartReply>>> result = SettableFuture.create();
-
- final MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
- final MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
- final List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input
- .getUpdatedTable());
- requestBuilder.setTableFeatures(ofTableFeatureList);
- caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
-
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLEFEATURES,
- xid.getValue());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
-
- final MultiMsgCollector multiMsgCollector = getDeviceContext().getMultiMsgCollector(requestContext);
- final MultipartRequestInput multipartRequestInput = mprInput.build();
- outboundQueue.commitEntry(xid.getValue(), multipartRequestInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- if (ofHeader instanceof MultipartReply) {
- final MultipartReply multipartReply = (MultipartReply) ofHeader;
- multiMsgCollector.addMultipartMsg(multipartReply);
- } else {
- if (null != ofHeader) {
- LOG.info("Unexpected response type received {}.", ofHeader.getClass());
- } else {
- LOG.info("Response received is null.");
- multiMsgCollector.endCollecting();
- }
- }
- getMessageSpy().spyMessage(multipartRequestInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- final RpcResultBuilder<List<MultipartReply>> rpcResultBuilder = RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
- RequestContextUtil.closeRequstContext(requestContext);
- getMessageSpy().spyMessage(multipartRequestInput.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE);
- }
- });
- return requestContext.getFuture();
- }
- }
-
- final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(new FunctionImpl());
+ final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(input);
final SettableFuture<RpcResult<UpdateTableOutput>> finalFuture = SettableFuture.create();
class CallBackImpl implements FutureCallback<RpcResult<List<MultipartReply>>> {
- private final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CallBackImpl.class);
-
@Override
public void onSuccess(final RpcResult<List<MultipartReply>> result) {
if (result.isSuccessful()) {
final List<MultipartReply> multipartReplies = result.getResult();
if (multipartReplies.isEmpty()) {
- LOGGER.debug("Multipart reply to table features request shouldn't be empty list.");
+ LOG.debug("Multipart reply to table features request shouldn't be empty list.");
finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed()
.withError(ErrorType.RPC, "Multipart reply list is empty.").build());
} else {
final Long xid = multipartReplies.get(0).getXid();
- LOGGER.debug(
+ LOG.debug(
"OnSuccess, rpc result successful, multipart response for rpc update-table with xid {} obtained.",
xid);
final UpdateTableOutputBuilder updateTableOutputBuilder = new UpdateTableOutputBuilder();
writeResponseToOperationalDatastore(multipartReplies);
}
} else {
- LOGGER.debug("OnSuccess, rpc result unsuccessful, multipart response for rpc update-table was unsuccessful.");
+ LOG.debug("OnSuccess, rpc result unsuccessful, multipart response for rpc update-table was unsuccessful.");
finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withRpcErrors(result.getErrors())
.build());
}
@Override
public void onFailure(final Throwable t) {
- LOGGER.debug("Failure multipart response for table features request. Exception: {}", t);
+ LOG.debug("Failure multipart response for table features request. Exception: {}", t);
finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed()
.withError(ErrorType.RPC, "Future error", t).build());
}
+ }
- /**
- * @param multipartReplies
- */
- private void writeResponseToOperationalDatastore(final List<MultipartReply> multipartReplies) {
-
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeatures = convertToSalTableFeatures(multipartReplies);
-
- final DeviceContext deviceContext = getDeviceContext();
- final NodeId nodeId = deviceContext.getPrimaryConnectionContext().getNodeId();
- final InstanceIdentifier<FlowCapableNode> flowCapableNodeII = InstanceIdentifier.create(Nodes.class)
- .child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class);
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures tableFeatureData : salTableFeatures) {
- final Short tableId = tableFeatureData.getTableId();
- final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures, TableFeaturesKey> tableFeaturesII = flowCapableNodeII
- .child(Table.class, new TableKey(tableId))
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures.class,
- new TableFeaturesKey(tableId));
- deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII,
- tableFeatureData);
- }
+ Futures.addCallback(multipartFuture, new CallBackImpl());
- }
+ return finalFuture;
+ }
- private List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> convertToSalTableFeatures(
- final List<MultipartReply> multipartReplies) {
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesAll = new ArrayList<>();
- for (final MultipartReply multipartReply : multipartReplies) {
- if (multipartReply.getType().equals(MultipartType.OFPMPTABLEFEATURES)) {
- final MultipartReplyBody multipartReplyBody = multipartReply.getMultipartReplyBody();
- if (multipartReplyBody instanceof MultipartReplyTableFeaturesCase) {
- final MultipartReplyTableFeaturesCase tableFeaturesCase = ((MultipartReplyTableFeaturesCase) multipartReplyBody);
- final MultipartReplyTableFeatures salTableFeatures = tableFeaturesCase
- .getMultipartReplyTableFeatures();
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesPartial = TableFeaturesReplyConvertor
- .toTableFeaturesReply(salTableFeatures);
- salTableFeaturesAll.addAll(salTableFeaturesPartial);
- LOGGER.debug("TableFeature {} for xid {}.", salTableFeatures, multipartReply.getXid());
- }
- }
+ /**
+ * @param multipartReplies
+ */
+ private void writeResponseToOperationalDatastore(final List<MultipartReply> multipartReplies) {
+
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeatures = convertToSalTableFeatures(multipartReplies);
+
+ final DeviceContext deviceContext = getDeviceContext();
+ final NodeId nodeId = deviceContext.getPrimaryConnectionContext().getNodeId();
+ final InstanceIdentifier<FlowCapableNode> flowCapableNodeII = InstanceIdentifier.create(Nodes.class)
+ .child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class);
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures tableFeatureData : salTableFeatures) {
+ final Short tableId = tableFeatureData.getTableId();
+ final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures, TableFeaturesKey> tableFeaturesII = flowCapableNodeII
+ .child(Table.class, new TableKey(tableId))
+ .child(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures.class,
+ new TableFeaturesKey(tableId));
+ deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII,
+ tableFeatureData);
+ }
+ }
+
+ protected static List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> convertToSalTableFeatures(
+ final List<MultipartReply> multipartReplies) {
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesAll = new ArrayList<>();
+ for (final MultipartReply multipartReply : multipartReplies) {
+ if (multipartReply.getType().equals(MultipartType.OFPMPTABLEFEATURES)) {
+ final MultipartReplyBody multipartReplyBody = multipartReply.getMultipartReplyBody();
+ if (multipartReplyBody instanceof MultipartReplyTableFeaturesCase) {
+ final MultipartReplyTableFeaturesCase tableFeaturesCase = ((MultipartReplyTableFeaturesCase) multipartReplyBody);
+ final MultipartReplyTableFeatures salTableFeatures = tableFeaturesCase
+ .getMultipartReplyTableFeatures();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeaturesPartial = TableFeaturesReplyConvertor
+ .toTableFeaturesReply(salTableFeatures);
+ salTableFeaturesAll.addAll(salTableFeaturesPartial);
+ LOG.debug("TableFeature {} for xid {}.", salTableFeatures, multipartReply.getXid());
}
- return salTableFeaturesAll;
}
-
}
-
- Futures.addCallback(multipartFuture, new CallBackImpl());
-
- return finalFuture;
+ return salTableFeaturesAll;
}
private MultipartRequestInputBuilder createMultipartHeader(final MultipartType multipart, final Long xid) {
return mprInput;
}
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) {
+ final MultipartRequestTableFeaturesCaseBuilder caseBuilder = new MultipartRequestTableFeaturesCaseBuilder();
+ final MultipartRequestTableFeaturesBuilder requestBuilder = new MultipartRequestTableFeaturesBuilder();
+ final List<TableFeatures> ofTableFeatureList = TableFeaturesConvertor.toTableFeaturesRequest(input
+ .getUpdatedTable());
+ requestBuilder.setTableFeatures(ofTableFeatureList);
+ caseBuilder.setMultipartRequestTableFeatures(requestBuilder.build());
+
+ // Set request body to main multipart request
+ final MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPTABLEFEATURES,
+ xid.getValue());
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+
+ return mprInput.build();
+ }
}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class SimpleRequestCallback<T extends DataObject> extends AbstractRequestCallback<T> {
+ private static final Logger LOG = LoggerFactory.getLogger(SimpleRequestCallback.class);
+ private final Class<T> clazz;
+
+ private SimpleRequestCallback(final RequestContext<T> context, final Class<?> requestType, final MessageSpy spy, final Class<T> clazz) {
+ super(context, requestType, spy);
+ this.clazz = Preconditions.checkNotNull(clazz);
+ }
+
+ static <T extends DataObject> FutureCallback<OfHeader> create(final RequestContext<T> context, final Class<?> requestType, final MessageSpy spy, final Class<T> clazz) {
+ return new SimpleRequestCallback<>(context, requestType, spy, clazz);
+ }
+
+ @Override
+ public final void onSuccess(final OfHeader result) {
+ spyMessage(MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS);
+
+ if (result == null) {
+ setResult(RpcResultBuilder.<T>success().build());
+ return;
+ }
+ if (!clazz.isInstance(result)) {
+ LOG.info("Expected response type {}, got {}, result is empty", clazz, result.getClass());
+ setResult(RpcResultBuilder.<T>success().build());
+ return;
+
+ }
+
+ setResult(RpcResultBuilder.success(clazz.cast(result)).build());
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.services;
+
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy.STATISTIC_GROUP;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+final class VoidRequestCallback extends AbstractRequestCallback<Void> {
+ private static final RpcResult<Void> SUCCESS = RpcResultBuilder.<Void>success().build();
+
+ VoidRequestCallback(final RequestContext<Void> context, final Class<?> requestType, final MessageSpy spy) {
+ super(context, requestType, spy);
+ }
+
+ @Override
+ public void onSuccess(final OfHeader result) {
+ spyMessage(STATISTIC_GROUP.TO_SWITCH_SUBMIT_SUCCESS_NO_RESPONSE);
+ setResult(SUCCESS);
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
+
+final class AggregateFlowsInTableService extends AbstractSimpleService<GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput, GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> {
+ public AggregateFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
+ // Create multipart request body for fetch all the group stats
+ final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
+ final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
+ mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
+ mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+ mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ final short version = getVersion();
+ FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
+
+ // Set request body to main multipart request
+ multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
+ .build());
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
+
+ mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+
+final class AllFlowsInAllTablesService extends AbstractSimpleService<GetAllFlowsStatisticsFromAllFlowTablesInput, GetAllFlowsStatisticsFromAllFlowTablesOutput> {
+ private final MultipartRequestFlowCase flowCase;
+
+ AllFlowsInAllTablesService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllFlowsStatisticsFromAllFlowTablesOutput.class);
+
+ final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+ final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+ mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
+ mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+ mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ FlowCreatorUtil.setWildcardedFlowMatch(getVersion(), mprFlowRequestBuilder);
+ multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+
+ flowCase = multipartRequestFlowCaseBuilder.build();
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(flowCase);
+
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+
+public class AllFlowsInTableService extends AbstractSimpleService<GetAllFlowStatisticsFromFlowTableInput, GetAllFlowStatisticsFromFlowTableOutput> {
+
+ public AllFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllFlowStatisticsFromFlowTableOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllFlowStatisticsFromFlowTableInput input) {
+ final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+ mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
+ mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+ mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+
+ final short version = getVersion();
+ FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
+
+ final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+ multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPFLOW, xid.getValue(), version);
+
+ mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowjava.protocol.api.util.BinContent;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
+
+final class AllGroupsStatsService extends AbstractSimpleService<GetAllGroupStatisticsInput, GetAllGroupStatisticsOutput> {
+ private static final MultipartRequestGroupCase GROUP_CASE;
+
+ static {
+ final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
+ final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
+ mprGroupBuild.setGroupId(new GroupId(BinContent.intToUnsignedLong(Group.OFPGALL.getIntValue())));
+ caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
+
+ GROUP_CASE = caseBuilder.build();
+ }
+
+ AllGroupsStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllGroupStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllGroupStatisticsInput input) {
+ // Create multipart request header
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPGROUP, xid.getValue(), getVersion());
+
+ // Set request body to main multipart request
+ mprInput.setMultipartRequestBody(GROUP_CASE);
+
+ // Send the request, no cookies associated, use any connection
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowjava.protocol.api.util.BinContent;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
+
+final class AllMeterConfigStatsService extends AbstractSimpleService<GetAllMeterConfigStatisticsInput, GetAllMeterConfigStatisticsOutput> {
+ private static final MultipartRequestMeterConfigCase METER_CONFIG_CASE;
+
+ static {
+ MultipartRequestMeterConfigCaseBuilder caseBuilder =
+ new MultipartRequestMeterConfigCaseBuilder();
+ MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
+ new MultipartRequestMeterConfigBuilder();
+ mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
+ caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
+
+ METER_CONFIG_CASE = caseBuilder.build();
+ }
+
+ AllMeterConfigStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllMeterConfigStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllMeterConfigStatisticsInput input) {
+ MultipartRequestInputBuilder mprInput = RequestInputUtils
+ .createMultipartHeader(MultipartType.OFPMPMETERCONFIG, xid.getValue(), getVersion());
+ return mprInput.setMultipartRequestBody(METER_CONFIG_CASE).build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowjava.protocol.api.util.BinContent;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
+
+final class AllMeterStatsService extends AbstractSimpleService<GetAllMeterStatisticsInput, GetAllMeterStatisticsOutput> {
+ private static final MultipartRequestMeterCase METER_CASE;
+
+ static {
+ MultipartRequestMeterCaseBuilder caseBuilder =
+ new MultipartRequestMeterCaseBuilder();
+ MultipartRequestMeterBuilder mprMeterBuild =
+ new MultipartRequestMeterBuilder();
+ mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(Meter.OFPMALL.getIntValue())));
+ caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
+
+ METER_CASE = caseBuilder.build();
+ }
+
+ AllMeterStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllMeterStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllMeterStatisticsInput input) {
+ MultipartRequestInputBuilder mprInput = RequestInputUtils
+ .createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), getVersion());
+ return mprInput.setMultipartRequestBody(METER_CASE).build();
+ }
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
+
+final class AllPortStatsService extends AbstractSimpleService<GetAllNodeConnectorsStatisticsInput, GetAllNodeConnectorsStatisticsOutput> {
+ private static final MultipartRequestPortStatsCase PORT_STATS_CASE;
+
+ static {
+ MultipartRequestPortStatsCaseBuilder caseBuilder =
+ new MultipartRequestPortStatsCaseBuilder();
+ MultipartRequestPortStatsBuilder mprPortStatsBuilder =
+ new MultipartRequestPortStatsBuilder();
+ // Select all ports
+ mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
+ caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
+
+ PORT_STATS_CASE = caseBuilder.build();
+ }
+
+ AllPortStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllNodeConnectorsStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllNodeConnectorsStatisticsInput input) {
+ MultipartRequestInputBuilder mprInput = RequestInputUtils
+ .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(PORT_STATS_CASE);
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
+
+final class AllQueuesAllPortsService extends AbstractSimpleService<GetAllQueuesStatisticsFromAllPortsInput, GetAllQueuesStatisticsFromAllPortsOutput> {
+ private static final MultipartRequestQueueCase QUEUE_CASE;
+
+ static {
+ MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
+ MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
+ // Select all ports
+ // Select all the ports
+ mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
+ mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
+ caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
+
+ QUEUE_CASE = caseBuilder.build();
+ }
+
+ AllQueuesAllPortsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllQueuesStatisticsFromAllPortsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromAllPortsInput input) {
+ // Set request body to main multipart request
+ MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(QUEUE_CASE);
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortOutput;
+
+final class AllQueuesOnePortService extends AbstractSimpleService<GetAllQueuesStatisticsFromGivenPortInput, GetAllQueuesStatisticsFromGivenPortOutput> {
+ AllQueuesOnePortService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetAllQueuesStatisticsFromGivenPortOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAllQueuesStatisticsFromGivenPortInput input) {
+ MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
+ MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
+ // Select all queues
+ // Select specific port
+ final short version = getVersion();
+ mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
+ OpenflowVersion.get(version), input.getNodeConnectorId()));
+
+ mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
+ caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
+
+ // Set request body to main multipart request
+ MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPQUEUE, xid.getValue(), version);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+
+ return mprInput.build();
+ }
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+
+final class FlowsInTableService extends AbstractSimpleService<GetFlowStatisticsFromFlowTableInput, GetFlowStatisticsFromFlowTableOutput> {
+ FlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetFlowStatisticsFromFlowTableOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetFlowStatisticsFromFlowTableInput input) {
+ final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
+ final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
+ mprFlowRequestBuilder.setTableId(input.getTableId());
+
+ if (input.getOutPort() != null) {
+ mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
+ } else {
+ mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
+ }
+
+ if (input.getOutGroup() != null) {
+ mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
+ } else {
+ mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ }
+
+ if (input.getCookie() != null) {
+ mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
+ } else {
+ mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ }
+
+ if (input.getCookieMask() != null) {
+ mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
+ } else {
+ mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ }
+
+ // convert and inject match
+ final short version = getVersion();
+ final DeviceContext deviceContext = getDeviceContext();
+ MatchReactor.getInstance().convert(input.getMatch(), version, mprFlowRequestBuilder,
+ deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
+
+ // Set request body to main multipart request
+ multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPFLOW, xid.getValue(), version);
+ mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
+
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
+
+final class GroupDescriptionService extends AbstractSimpleService<GetGroupDescriptionInput, GetGroupDescriptionOutput> {
+ private static final MultipartRequestGroupDescCase GROUP_DESC_CASE = new MultipartRequestGroupDescCaseBuilder().build();
+
+ GroupDescriptionService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetGroupDescriptionOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetGroupDescriptionInput input) {
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPGROUPDESC, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(GROUP_DESC_CASE);
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupFeaturesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
+
+final class GroupFeaturesService extends AbstractSimpleService<GetGroupFeaturesInput, GetGroupFeaturesOutput> {
+ private static final MultipartRequestGroupFeaturesCase GROUP_FEAT_CASE =
+ new MultipartRequestGroupFeaturesCaseBuilder().build();
+
+ GroupFeaturesService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetGroupFeaturesOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetGroupFeaturesInput input) {
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPGROUPFEATURES, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(GROUP_FEAT_CASE);
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
+
+final class GroupStatsService extends AbstractSimpleService<GetGroupStatisticsInput, GetGroupStatisticsOutput> {
+ GroupStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetGroupStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetGroupStatisticsInput input) {
+ final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
+ final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
+ mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
+ caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
+
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPGROUP, xid.getValue(), getVersion());
+
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+import com.google.common.base.MoreObjects;
+import org.opendaylight.openflowplugin.api.OFConstants;
+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.impl.services.AbstractMultipartService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
+import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
+
+final class MatchingFlowsInTableService extends AbstractMultipartService<GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput> {
+
+ public MatchingFlowsInTableService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+ final DeviceContext deviceContext = getDeviceContext();
+ final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
+ final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
+ final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL).shortValue();
+ mprAggregateRequestBuilder.setTableId(tableId);
+ long outputPortValue = MoreObjects.firstNonNull(input.getOutPort(), OFConstants.OFPP_ANY).longValue();
+ mprAggregateRequestBuilder.setOutPort(outputPortValue);
+ // TODO: repeating code
+
+ final short version = getVersion();
+ if (version == OFConstants.OFP_VERSION_1_3) {
+
+ if (input.getCookie() == null) {
+ mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ } else {
+ mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
+ }
+
+ if (input.getCookieMask() == null) {
+ mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ } else {
+ mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
+ }
+ long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY).longValue();
+ mprAggregateRequestBuilder.setOutGroup(outGroup);
+ } else {
+ mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
+ mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
+ mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
+ }
+
+ MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder,
+ deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
+
+ FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
+
+ // Set request body to main multipart request
+ multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
+ .build());
+
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
+
+ mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterFeaturesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
+
+final class MeterFeaturesService extends AbstractSimpleService<GetMeterFeaturesInput, GetMeterFeaturesOutput> {
+ private static final MultipartRequestMeterFeaturesCase METER_FEATURES_CASE = new MultipartRequestMeterFeaturesCaseBuilder().build();
+
+ protected MeterFeaturesService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetMeterFeaturesOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetMeterFeaturesInput input) {
+ MultipartRequestInputBuilder mprInput =
+ RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETERFEATURES, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(METER_FEATURES_CASE);
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
+
+final class MeterStatsService extends AbstractSimpleService<GetMeterStatisticsInput, GetMeterStatisticsOutput> {
+
+ MeterStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetMeterStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetMeterStatisticsInput input) {
+ MultipartRequestMeterCaseBuilder caseBuilder =
+ new MultipartRequestMeterCaseBuilder();
+ MultipartRequestMeterBuilder mprMeterBuild =
+ new MultipartRequestMeterBuilder();
+ mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
+ caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
+
+ MultipartRequestInputBuilder mprInput =
+ RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ return mprInput.build();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetQueueStatisticsFromGivenPortOutput;
+
+final class OneQueueOnePortService extends AbstractSimpleService<GetQueueStatisticsFromGivenPortInput, GetQueueStatisticsFromGivenPortOutput> {
+ OneQueueOnePortService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetQueueStatisticsFromGivenPortOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetQueueStatisticsFromGivenPortInput input) {
+ MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
+ MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
+ // Select specific queue
+ mprQueueBuilder.setQueueId(input.getQueueId().getValue());
+ // Select specific port
+ final short version = getVersion();
+ mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
+ OpenflowVersion.get(version), input.getNodeConnectorId()));
+ caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
+
+ // Set request body to main multipart request
+ MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPQUEUE, xid.getValue(), version);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+ return mprInput.build();
+ }
+}
package org.opendaylight.openflowplugin.impl.statistics.services;
import com.google.common.base.Function;
-import com.google.common.base.MoreObjects;
import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
-import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregateCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestFlowCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
/**
* @author joe
*/
-public class OpendaylightFlowStatisticsServiceImpl extends CommonService implements OpendaylightFlowStatisticsService {
-
+public class OpendaylightFlowStatisticsServiceImpl implements OpendaylightFlowStatisticsService {
private static final Logger LOG = LoggerFactory.getLogger(OpendaylightFlowStatisticsServiceImpl.class);
- public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
- }
-
- @Override
- public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
- final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
-
-
- return handleServiceCall(
- new Function<RequestContext<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>,
- ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>>>() {
+ private final Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> matchingConvertor =
+ new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
+ @Override
+ public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
+ final DeviceContext deviceContext = matchingFlowsInTable.getDeviceContext();
+ TranslatorLibrary translatorLibrary = deviceContext.oook();
+ RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
+ if (input.isSuccessful()) {
+ MultipartReply reply = input.getResult().get(0);
+ final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
+ final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
+ List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
+
+ for (MultipartReply multipartReply : input.getResult()) {
+ aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
+ }
- @Override
- public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> apply(final RequestContext<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput> requestContext) {
+ GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
+ new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
+ getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
- // Create multipart request body for fetch all the group stats
- final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
- final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
- mprAggregateRequestBuilder.setTableId(input.getTableId().getValue());
- mprAggregateRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
- mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
- mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- final short version = getVersion();
- FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
+ rpcResult = RpcResultBuilder
+ .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
+ .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
+ .build();
- // Set request body to main multipart request
- multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
- .build());
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
+ } else {
+ rpcResult = RpcResultBuilder
+ .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
+ .withRpcErrors(input.getErrors())
+ .build();
+ }
+ return rpcResult;
+ }
+ };
- mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
+ private final AggregateFlowsInTableService aggregateFlowsInTable;
+ private final MatchingFlowsInTableService matchingFlowsInTable;
+ private final AllFlowsInAllTablesService allFlowsInAllTables;
+ private final AllFlowsInTableService allFlowsInTable;
+ private final FlowsInTableService flowsInTable;
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
+ public OpendaylightFlowStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ aggregateFlowsInTable = new AggregateFlowsInTableService(requestContextStack, deviceContext);
+ allFlowsInAllTables = new AllFlowsInAllTablesService(requestContextStack, deviceContext);
+ allFlowsInTable = new AllFlowsInTableService(requestContextStack, deviceContext);
+ flowsInTable = new FlowsInTableService(requestContextStack, deviceContext);
+ matchingFlowsInTable = new MatchingFlowsInTableService(requestContextStack, deviceContext);
+ }
+ @Override
+ public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
+ final GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
+ return aggregateFlowsInTable.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
-
-
- ListenableFuture<RpcResult<List<MultipartReply>>> rpcResultListenableFuture = handleServiceCall(
- new Function<RequestContext<List<MultipartReply>>, ListenableFuture<RpcResult<List<MultipartReply>>>>() {
-
- @Override
- public ListenableFuture<RpcResult<List<MultipartReply>>> apply(final RequestContext<List<MultipartReply>> requestContext) {
- final Xid xid = requestContext.getXid();
- final DeviceContext deviceContext = getDeviceContext();
- final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
- final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
- final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL).shortValue();
- mprAggregateRequestBuilder.setTableId(tableId);
- long outputPortValue = MoreObjects.firstNonNull(input.getOutPort(), OFConstants.OFPP_ANY).longValue();
- mprAggregateRequestBuilder.setOutPort(outputPortValue);
- // TODO: repeating code
-
- final short version = getVersion();
- if (version == OFConstants.OFP_VERSION_1_3) {
-
- if (input.getCookie() == null) {
- mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- } else {
- mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
- }
-
- if (input.getCookieMask() == null) {
- mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- } else {
- mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
- }
- long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY).longValue();
- mprAggregateRequestBuilder.setOutGroup(outGroup);
- } else {
- mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
- mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- }
-
- MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder,
- deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
-
- FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
-
- // Set request body to main multipart request
- multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
- .build());
-
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
-
- mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
-
- return Futures.transform(rpcResultListenableFuture, new Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>() {
- @Nullable
- @Override
- public RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> apply(final RpcResult<List<MultipartReply>> input) {
- final DeviceContext deviceContext = getDeviceContext();
- TranslatorLibrary translatorLibrary = deviceContext.oook();
- RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput> rpcResult;
- if (input.isSuccessful()) {
- MultipartReply reply = input.getResult().get(0);
- final TranslatorKey translatorKey = new TranslatorKey(reply.getVersion(), MultipartReplyAggregateCase.class.getName());
- final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
- List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
-
- for (MultipartReply multipartReply : input.getResult()) {
- aggregStats.add(messageTranslator.translate(multipartReply, deviceContext, null));
- }
-
- GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
- new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder();
- getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.setAggregatedFlowStatistics(aggregStats);
-
- rpcResult = RpcResultBuilder
- .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>success()
- .withResult(getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder.build())
- .build();
-
- } else {
- rpcResult = RpcResultBuilder
- .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
- .withRpcErrors(input.getErrors())
- .build();
- }
- return rpcResult;
- }
- });
-
+ return Futures.transform(matchingFlowsInTable.handleServiceCall(input), matchingConvertor);
}
@Override
public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
final GetAllFlowStatisticsFromFlowTableInput input) {
-
- return handleServiceCall(new Function<RequestContext<GetAllFlowStatisticsFromFlowTableOutput>,
- ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> apply(final RequestContext<GetAllFlowStatisticsFromFlowTableOutput> requestContext) {
-
- final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
- mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
- mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
- mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
- mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
-
- final short version = getVersion();
- FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
-
- final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
- multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
-
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPFLOW, xid.getValue(), version);
-
- mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
+ return allFlowsInTable.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
final GetAllFlowsStatisticsFromAllFlowTablesInput input) {
-
-
- return handleServiceCall(new Function<RequestContext<GetAllFlowsStatisticsFromAllFlowTablesOutput>,
- ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> apply(final RequestContext<GetAllFlowsStatisticsFromAllFlowTablesOutput> requestContext) {
-
- final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
- final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
- mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
- mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
- mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
- mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- final short version = getVersion();
- FlowCreatorUtil.setWildcardedFlowMatch(version, mprFlowRequestBuilder);
-
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPFLOW, xid.getValue(), version);
-
- multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
- mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
+ return allFlowsInAllTables.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
final GetFlowStatisticsFromFlowTableInput input) {
-
-
- return handleServiceCall(new Function<RequestContext<GetFlowStatisticsFromFlowTableOutput>, ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> apply(final RequestContext<GetFlowStatisticsFromFlowTableOutput> requestContext) {
-
- final MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
- final MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
- mprFlowRequestBuilder.setTableId(input.getTableId());
-
- if (input.getOutPort() != null) {
- mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
- } else {
- mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
- }
-
- if (input.getOutGroup() != null) {
- mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
- } else {
- mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
- }
-
- if (input.getCookie() != null) {
- mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
- } else {
- mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
- }
-
- if (input.getCookieMask() != null) {
- mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
- } else {
- mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
- }
-
- // convert and inject match
- final short version = getVersion();
- final DeviceContext deviceContext = getDeviceContext();
- MatchReactor.getInstance().convert(input.getMatch(), version, mprFlowRequestBuilder,
- deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
-
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
- multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPFLOW, xid.getValue(), version);
- mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
+ return flowsInTable.handleServiceCall(input);
}
-
}
*/
package org.opendaylight.openflowplugin.impl.statistics.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
+import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestTableCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.table._case.MultipartRequestTableBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
-/**
- * @author joe
- */
-public class OpendaylightFlowTableStatisticsServiceImpl extends CommonService implements
+public final class OpendaylightFlowTableStatisticsServiceImpl extends AbstractSimpleService<GetFlowTablesStatisticsInput, GetFlowTablesStatisticsOutput> implements
OpendaylightFlowTableStatisticsService {
- public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ public OpendaylightFlowTableStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetFlowTablesStatisticsOutput.class);
}
@Override
public Future<RpcResult<GetFlowTablesStatisticsOutput>> getFlowTablesStatistics(
final GetFlowTablesStatisticsInput input) {
+ return handleServiceCall(input);
+ }
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetFlowTablesStatisticsInput input) {
+ // Create multipart request body for fetch all the group stats
+ final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
+ final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
+ multipartRequestTableBuilder.setEmpty(true);
+ multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
- return handleServiceCall(new Function<RequestContext<GetFlowTablesStatisticsOutput>,
- ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetFlowTablesStatisticsOutput>> apply(final RequestContext<GetFlowTablesStatisticsOutput> requestContext) {
-
- // Create multipart request body for fetch all the group stats
- final MultipartRequestTableCaseBuilder multipartRequestTableCaseBuilder = new MultipartRequestTableCaseBuilder();
- final MultipartRequestTableBuilder multipartRequestTableBuilder = new MultipartRequestTableBuilder();
- multipartRequestTableBuilder.setEmpty(true);
- multipartRequestTableCaseBuilder.setMultipartRequestTable(multipartRequestTableBuilder.build());
+ // Set request body to main multipart request
+ final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
+ MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPFLOW, xid.getValue(), getVersion());
+ mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
- mprInput.setMultipartRequestBody(multipartRequestTableCaseBuilder.build());
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, mprInput.build(), getDeviceContext());
- }
- });
+ return mprInput.build();
}
-
}
*/
package org.opendaylight.openflowplugin.impl.statistics.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.util.BinContent;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetAllGroupStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupDescriptionInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GetGroupStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupDescCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestGroupFeaturesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.group._case.MultipartRequestGroupBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
/**
* @author joe
*/
-public class OpendaylightGroupStatisticsServiceImpl extends CommonService implements OpendaylightGroupStatisticsService {
-
-
- public OpendaylightGroupStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+public class OpendaylightGroupStatisticsServiceImpl implements OpendaylightGroupStatisticsService {
+ private final AllGroupsStatsService allGroups;
+ private final GroupDescriptionService groupDesc;
+ private final GroupFeaturesService groupFeat;
+ private final GroupStatsService groupStats;
+
+ public OpendaylightGroupStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ allGroups = new AllGroupsStatsService(requestContextStack, deviceContext);
+ groupDesc = new GroupDescriptionService(requestContextStack, deviceContext);
+ groupFeat = new GroupFeaturesService(requestContextStack, deviceContext);
+ groupStats = new GroupStatsService(requestContextStack, deviceContext);
}
@Override
public Future<RpcResult<GetAllGroupStatisticsOutput>> getAllGroupStatistics(final GetAllGroupStatisticsInput input) {
-
-
- return handleServiceCall(new Function<RequestContext<GetAllGroupStatisticsOutput>,
- ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllGroupStatisticsOutput>> apply(final RequestContext<GetAllGroupStatisticsOutput> requestContext) {
-
- final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
- final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
- mprGroupBuild.setGroupId(new GroupId(
- BinContent
- .intToUnsignedLong(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Group.OFPGALL
- .getIntValue())));
- caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
-
- // Create multipart request header
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPGROUP, xid.getValue(), getVersion());
-
- // Set request body to main multipart request
- mprInput.setMultipartRequestBody(caseBuilder.build());
-
- // Send the request, no cookies associated, use any connection
-
- MultipartRequestInput multipartRequestInput = mprInput.build();
-
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return allGroups.handleServiceCall(input);
}
-
@Override
public Future<RpcResult<GetGroupDescriptionOutput>> getGroupDescription(final GetGroupDescriptionInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetGroupDescriptionOutput>,
- ListenableFuture<RpcResult<GetGroupDescriptionOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetGroupDescriptionOutput>> apply(final RequestContext<GetGroupDescriptionOutput> requestContext) {
- final MultipartRequestGroupDescCaseBuilder mprGroupDescCaseBuild = new MultipartRequestGroupDescCaseBuilder();
-
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPGROUPDESC, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(mprGroupDescCaseBuild.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return groupDesc.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetGroupFeaturesOutput>> getGroupFeatures(final GetGroupFeaturesInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetGroupFeaturesOutput>,
- ListenableFuture<RpcResult<GetGroupFeaturesOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetGroupFeaturesOutput>> apply(final RequestContext<GetGroupFeaturesOutput> requestContext) {
- final MultipartRequestGroupFeaturesCaseBuilder mprGroupFeaturesBuild = new MultipartRequestGroupFeaturesCaseBuilder();
-
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPGROUPFEATURES, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(mprGroupFeaturesBuild.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return groupFeat.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetGroupStatisticsOutput>> getGroupStatistics(final GetGroupStatisticsInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetGroupStatisticsOutput>, ListenableFuture<RpcResult<GetGroupStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> apply(final RequestContext<GetGroupStatisticsOutput> requestContext) {
-
- final MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
- final MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
- mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
- caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());
-
- final Xid xid = requestContext.getXid();
- final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPGROUP, xid.getValue(), getVersion());
-
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
+ return groupStats.handleServiceCall(input);
}
-
}
*/
package org.opendaylight.openflowplugin.impl.statistics.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.util.BinContent;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterConfigStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetAllMeterStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.GetMeterStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterConfigCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestMeterFeaturesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter._case.MultipartRequestMeterBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.meter.config._case.MultipartRequestMeterConfigBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
-/**
- * @author joe
- */
-public class OpendaylightMeterStatisticsServiceImpl extends CommonService implements OpendaylightMeterStatisticsService {
-
-
- public OpendaylightMeterStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+public class OpendaylightMeterStatisticsServiceImpl implements OpendaylightMeterStatisticsService {
+ private final AllMeterConfigStatsService allMeterConfig;
+ private final AllMeterStatsService allMeterStats;
+ private final MeterFeaturesService meterFeatures;
+ private final MeterStatsService meterStats;
+
+ public OpendaylightMeterStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ allMeterConfig = new AllMeterConfigStatsService(requestContextStack, deviceContext);
+ allMeterStats = new AllMeterStatsService(requestContextStack, deviceContext);
+ meterFeatures = new MeterFeaturesService(requestContextStack, deviceContext);
+ meterStats = new MeterStatsService(requestContextStack, deviceContext);
}
@Override
public Future<RpcResult<GetAllMeterConfigStatisticsOutput>> getAllMeterConfigStatistics(
final GetAllMeterConfigStatisticsInput input) {
- return handleServiceCall(new Function<RequestContext<GetAllMeterConfigStatisticsOutput>,
- ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> apply(final RequestContext<GetAllMeterConfigStatisticsOutput> requestContext) {
-
- MultipartRequestMeterConfigCaseBuilder caseBuilder =
- new MultipartRequestMeterConfigCaseBuilder();
- MultipartRequestMeterConfigBuilder mprMeterConfigBuild =
- new MultipartRequestMeterConfigBuilder();
- mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
- .types.rev130731.Meter.OFPMALL.getIntValue())));
- caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils
- .createMultipartHeader(MultipartType.OFPMPMETERCONFIG, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return allMeterConfig.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetAllMeterStatisticsOutput>> getAllMeterStatistics(final GetAllMeterStatisticsInput input) {
-
- return handleServiceCall(
- new Function<RequestContext<GetAllMeterStatisticsOutput>, ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> apply(final RequestContext<GetAllMeterStatisticsOutput> requestContext) {
-
- MultipartRequestMeterCaseBuilder caseBuilder =
- new MultipartRequestMeterCaseBuilder();
- MultipartRequestMeterBuilder mprMeterBuild =
- new MultipartRequestMeterBuilder();
- mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common
- .types.rev130731.Meter.OFPMALL.getIntValue())));
- caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils
- .createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- }
- );
-
+ return allMeterStats.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetMeterFeaturesOutput>> getMeterFeatures(final GetMeterFeaturesInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetMeterFeaturesOutput>, ListenableFuture<RpcResult<GetMeterFeaturesOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> apply(final RequestContext<GetMeterFeaturesOutput> requestContext) {
-
- MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild =
- new MultipartRequestMeterFeaturesCaseBuilder();
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput =
- RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETERFEATURES, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
+ return meterFeatures.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetMeterStatisticsOutput>> getMeterStatistics(final GetMeterStatisticsInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetMeterStatisticsOutput>, ListenableFuture<RpcResult<GetMeterStatisticsOutput>>>() {
- @Override
- public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> apply(final RequestContext<GetMeterStatisticsOutput> requestContext) {
- MultipartRequestMeterCaseBuilder caseBuilder =
- new MultipartRequestMeterCaseBuilder();
- MultipartRequestMeterBuilder mprMeterBuild =
- new MultipartRequestMeterBuilder();
- mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
- caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput =
- RequestInputUtils.createMultipartHeader(MultipartType.OFPMPMETER, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return meterStats.handleServiceCall(input);
}
-
}
*/
package org.opendaylight.openflowplugin.impl.statistics.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
-import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
import org.opendaylight.yangtools.yang.common.RpcResult;
-/**
- * @author joe
- */
-public class OpendaylightPortStatisticsServiceImpl extends CommonService implements OpendaylightPortStatisticsService {
+public class OpendaylightPortStatisticsServiceImpl implements OpendaylightPortStatisticsService {
+ private final AllPortStatsService allPortStats;
+ private final PortStatsService portStats;
- public OpendaylightPortStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ public OpendaylightPortStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ allPortStats = new AllPortStatsService(requestContextStack, deviceContext);
+ portStats = new PortStatsService(requestContextStack, deviceContext);
}
@Override
public Future<RpcResult<GetAllNodeConnectorsStatisticsOutput>> getAllNodeConnectorsStatistics(
final GetAllNodeConnectorsStatisticsInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetAllNodeConnectorsStatisticsOutput>,
- ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> apply(final RequestContext<GetAllNodeConnectorsStatisticsOutput> requestContext) {
-
- MultipartRequestPortStatsCaseBuilder caseBuilder =
- new MultipartRequestPortStatsCaseBuilder();
- MultipartRequestPortStatsBuilder mprPortStatsBuilder =
- new MultipartRequestPortStatsBuilder();
- // Select all ports
- mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
- caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils
- .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
+ return allPortStats.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetNodeConnectorStatisticsOutput>> getNodeConnectorStatistics(
final GetNodeConnectorStatisticsInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetNodeConnectorStatisticsOutput>,
- ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> apply(final RequestContext<GetNodeConnectorStatisticsOutput> requestContext) {
-
- MultipartRequestPortStatsCaseBuilder caseBuilder =
- new MultipartRequestPortStatsCaseBuilder();
- MultipartRequestPortStatsBuilder mprPortStatsBuilder =
- new MultipartRequestPortStatsBuilder();
- // Set specific port
- final short version = getVersion();
- mprPortStatsBuilder
- .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
- OpenflowVersion.get(version),
- input.getNodeConnectorId()));
- caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
-
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils
- .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), version);
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return portStats.handleServiceCall(input);
}
-
}
*/
package org.opendaylight.openflowplugin.impl.statistics.services;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.util.StatisticsServiceUtil;
-import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestQueueCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.queue._case.MultipartRequestQueueBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromAllPortsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.GetAllQueuesStatisticsFromGivenPortInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
import org.opendaylight.yangtools.yang.common.RpcResult;
-/**
- * @author joe
- */
-public class OpendaylightQueueStatisticsServiceImpl extends CommonService implements OpendaylightQueueStatisticsService {
+public class OpendaylightQueueStatisticsServiceImpl implements OpendaylightQueueStatisticsService {
+ private final AllQueuesAllPortsService allQueuesAllPorts;
+ private final AllQueuesOnePortService allQueuesOnePort;
+ private final OneQueueOnePortService oneQueueOnePort;
- public OpendaylightQueueStatisticsServiceImpl(final RequestContextStack requestContextStack, DeviceContext deviceContext) {
- super(requestContextStack, deviceContext);
+ public OpendaylightQueueStatisticsServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ allQueuesAllPorts = new AllQueuesAllPortsService(requestContextStack, deviceContext);
+ allQueuesOnePort = new AllQueuesOnePortService(requestContextStack, deviceContext);
+ oneQueueOnePort = new OneQueueOnePortService(requestContextStack, deviceContext);
}
@Override
public Future<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> getAllQueuesStatisticsFromAllPorts(
final GetAllQueuesStatisticsFromAllPortsInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetAllQueuesStatisticsFromAllPortsOutput>,
- ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromAllPortsOutput>> apply(final RequestContext<GetAllQueuesStatisticsFromAllPortsOutput> requestContext) {
-
-
- MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
- MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
- // Select all ports
- // Select all the ports
- mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
- mprQueueBuilder.setPortNo(OFConstants.OFPP_ANY);
- caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
-
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
-
- MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPQUEUE, xid.getValue(), getVersion());
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
-
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
-
+ return allQueuesAllPorts.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> getAllQueuesStatisticsFromGivenPort(
final GetAllQueuesStatisticsFromGivenPortInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetAllQueuesStatisticsFromGivenPortOutput>, ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetAllQueuesStatisticsFromGivenPortOutput>> apply(final RequestContext<GetAllQueuesStatisticsFromGivenPortOutput> requestContext) {
-
- MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
- MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
- // Select all queues
- // Select specific port
- final short version = getVersion();
- mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
- OpenflowVersion.get(version), input.getNodeConnectorId()));
-
- mprQueueBuilder.setQueueId(OFConstants.OFPQ_ALL);
- caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
-
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPQUEUE, xid.getValue(), version);
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
+ return allQueuesOnePort.handleServiceCall(input);
}
@Override
public Future<RpcResult<GetQueueStatisticsFromGivenPortOutput>> getQueueStatisticsFromGivenPort(
final GetQueueStatisticsFromGivenPortInput input) {
- return handleServiceCall(
- new Function<RequestContext<GetQueueStatisticsFromGivenPortOutput>, ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>>>() {
-
- @Override
- public ListenableFuture<RpcResult<GetQueueStatisticsFromGivenPortOutput>> apply(final RequestContext<GetQueueStatisticsFromGivenPortOutput> requestContext) {
-
- MultipartRequestQueueCaseBuilder caseBuilder = new MultipartRequestQueueCaseBuilder();
- MultipartRequestQueueBuilder mprQueueBuilder = new MultipartRequestQueueBuilder();
- // Select specific queue
- mprQueueBuilder.setQueueId(input.getQueueId().getValue());
- // Select specific port
- final short version = getVersion();
- mprQueueBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
- OpenflowVersion.get(version), input.getNodeConnectorId()));
- caseBuilder.setMultipartRequestQueue(mprQueueBuilder.build());
-
- // Set request body to main multipart request
- final Xid xid = requestContext.getXid();
- MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
- MultipartType.OFPMPQUEUE, xid.getValue(), version);
- mprInput.setMultipartRequestBody(caseBuilder.build());
- MultipartRequestInput multipartRequestInput = mprInput.build();
- return StatisticsServiceUtil.getRpcResultListenableFuture(xid, multipartRequestInput, getDeviceContext());
- }
- });
+ return oneQueueOnePort.handleServiceCall(input);
}
-
}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.statistics.services;
+
+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.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
+import org.opendaylight.openflowplugin.impl.services.RequestInputUtils;
+import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestPortStatsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.port.stats._case.MultipartRequestPortStatsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsOutput;
+
+final class PortStatsService extends AbstractSimpleService<GetNodeConnectorStatisticsInput, GetNodeConnectorStatisticsOutput> {
+
+ protected PortStatsService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ super(requestContextStack, deviceContext, GetNodeConnectorStatisticsOutput.class);
+ }
+
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final GetNodeConnectorStatisticsInput input) {
+ MultipartRequestPortStatsCaseBuilder caseBuilder =
+ new MultipartRequestPortStatsCaseBuilder();
+ MultipartRequestPortStatsBuilder mprPortStatsBuilder =
+ new MultipartRequestPortStatsBuilder();
+ // Set specific port
+ final short version = getVersion();
+ mprPortStatsBuilder
+ .setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
+ OpenflowVersion.get(version),
+ input.getNodeConnectorId()));
+ caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());
+
+ MultipartRequestInputBuilder mprInput = RequestInputUtils
+ .createMultipartHeader(MultipartType.OFPMPPORTSTATS, xid.getValue(), version);
+ mprInput.setMultipartRequestBody(caseBuilder.build());
+
+ return mprInput.build();
+ }
+}
package org.opendaylight.openflowplugin.impl.statistics.services.dedicated;
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.Future;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
import org.opendaylight.openflowplugin.impl.common.MultipartRequestInputFactory;
-import org.opendaylight.openflowplugin.impl.services.CommonService;
-import org.opendaylight.openflowplugin.impl.services.RequestContextUtil;
+import org.opendaylight.openflowplugin.impl.services.AbstractMultipartService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 4.4.2015.
*/
-public class StatisticsGatheringService extends CommonService {
-
- private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringService.class);
-
+public class StatisticsGatheringService extends AbstractMultipartService<MultipartType> {
public StatisticsGatheringService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
-
super(requestContextStack, deviceContext);
}
-
public Future<RpcResult<List<MultipartReply>>> getStatisticsOfType(final MultipartType type) {
- return handleServiceCall(new Function<RequestContext<List<MultipartReply>>, ListenableFuture<RpcResult<List<MultipartReply>>>>() {
- @Override
- public ListenableFuture<RpcResult<List<MultipartReply>>> apply(final RequestContext<List<MultipartReply>> requestContext) {
- final Xid xid = requestContext.getXid();
- final DeviceContext deviceContext = getDeviceContext();
- final MultiMsgCollector multiMsgCollector = deviceContext.getMultiMsgCollector(requestContext);
-
-
- final MultipartRequestInput multipartRequestInput = MultipartRequestInputFactory.
- makeMultipartRequestInput(xid.getValue(),
- getVersion(),
- type);
- final OutboundQueue outboundQueue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
- outboundQueue.commitEntry(xid.getValue(), multipartRequestInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- if (ofHeader instanceof MultipartReply) {
- final MultipartReply multipartReply = (MultipartReply) ofHeader;
- multiMsgCollector.addMultipartMsg(multipartReply);
- } else {
- if (null != ofHeader) {
- LOG.info("Unexpected response type received {}.", ofHeader.getClass());
- final RpcResultBuilder<List<MultipartReply>> rpcResultBuilder = RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.APPLICATION, String.format("Unexpected response type received %s.", ofHeader.getClass()));
- requestContext.setResult(rpcResultBuilder.build());
- } else {
- LOG.info("Ofheader was null.");
- multiMsgCollector.endCollecting();
- }
- }
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- final RpcResultBuilder<List<MultipartReply>> rpcResultBuilder = RpcResultBuilder.<List<MultipartReply>>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage());
- requestContext.setResult(rpcResultBuilder.build());
- RequestContextUtil.closeRequstContext(requestContext);
- }
- });
- return requestContext.getFuture();
- }
- }
-
- );
+ return handleServiceCall(type);
}
+ @Override
+ protected OfHeader buildRequest(final Xid xid, final MultipartType input) {
+ return MultipartRequestInputFactory.makeMultipartRequestInput(xid.getValue(), getVersion(), input);
+ }
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.impl.util;
-
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-/**
- * Created by Martin Bobak <mbobak@cisco.com> on 18.5.2015.
- */
-public class StatisticsServiceUtil {
-
- private StatisticsServiceUtil() {
- throw new IllegalStateException("This class should not be instantiated");
- }
-
- public static <T> ListenableFuture<RpcResult<T>> getRpcResultListenableFuture(final Xid xid,
- final MultipartRequestInput multipartRequestInput,
- final DeviceContext deviceContext) {
- final SettableFuture<RpcResult<T>> settableFuture = SettableFuture.create();
- final OutboundQueue outboundQueue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
- outboundQueue.commitEntry(xid.getValue(), multipartRequestInput, new FutureCallback<OfHeader>() {
- @Override
- public void onSuccess(final OfHeader ofHeader) {
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- }
- });
- return settableFuture;
- }
-
-}