X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=test-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Ftestcommon%2FDropTestRpcSender.java;h=e8922da432a8636ffa33c8d698d88da2e92743b3;hb=89246202a625302ae22911da3dd47f2929d1630d;hp=fac568b683802cb7fa32f504ba4b6a76d72c0579;hpb=0b595be684db641f3cb25f1995de1f1660c07edb;p=openflowplugin.git diff --git a/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java b/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java index fac568b683..e8922da432 100644 --- a/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java +++ b/test-common/src/main/java/org/opendaylight/openflowplugin/testcommon/DropTestRpcSender.java @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. +/* + * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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, @@ -7,130 +7,6 @@ */ package org.opendaylight.openflowplugin.testcommon; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.JdkFutureAdapters; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import java.math.BigInteger; -import org.opendaylight.mdsal.binding.api.NotificationService; -import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public interface DropTestRpcSender extends DropTest { -/** - * Provides cbench responder behavior: upon packetIn arrival addFlow action is sent out to - * device using {@link SalFlowService} strategy. - */ -public class DropTestRpcSender extends AbstractDropTest { - private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcSender.class); - - private SalFlowService flowService; - - public void setFlowService(final SalFlowService flowService) { - this.flowService = flowService; - } - - private static final ThreadLocal BUILDER = ThreadLocal.withInitial(() -> { - final AddFlowInputBuilder fb = new AddFlowInputBuilder(); - - fb.setPriority(PRIORITY); - fb.setBufferId(BUFFER_ID); - - final FlowCookie cookie = new FlowCookie(BigInteger.TEN); - fb.setCookie(cookie); - fb.setCookieMask(cookie); - fb.setTableId(TABLE_ID); - fb.setHardTimeout(HARD_TIMEOUT); - fb.setIdleTimeout(IDLE_TIMEOUT); - fb.setFlags(new FlowModFlags(false, false, false, false, false)); - - return fb; - }); - - private NotificationService notificationService; - - private ListenerRegistration notificationRegistration; - - /** - * Start listening on packetIn. - */ - @SuppressWarnings("checkstyle:IllegalCatch") - public void start() { - final SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, - STARTUP_LOOP_MAX_RETRIES); - try { - notificationRegistration = looper.loopUntilNoException( - () -> notificationService.registerNotificationListener(DropTestRpcSender.this)); - } catch (Exception e) { - LOG.warn("DropTest sender notification listener registration fail!"); - LOG.debug("DropTest sender notification listener registration fail! ..", e); - throw new IllegalStateException("DropTest startup fail! Try again later.", e); - } - } - - @Override - protected void processPacket(final InstanceIdentifier node, final Match match, - final Instructions instructions) { - final AddFlowInputBuilder fb = BUILDER.get(); - - // Finally build our flow - fb.setMatch(match); - fb.setInstructions(instructions); - - // Construct the flow instance id - - fb.setNode(new NodeRef(node)); - - // Add flow - final AddFlowInput flow = fb.build(); - if (LOG.isDebugEnabled()) { - LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow); - } - ListenableFuture> result = - JdkFutureAdapters.listenInPoolThread(flowService.addFlow(flow)); - Futures.addCallback(result, new FutureCallback>() { - @Override - public void onSuccess(final RpcResult result) { - countFutureSuccess(); - } - - @Override - public void onFailure(final Throwable throwable) { - countFutureError(); - } - }, MoreExecutors.directExecutor()); - } - - public void setNotificationService(final NotificationService notificationService) { - this.notificationService = notificationService; - } - - @Override - @SuppressWarnings("checkstyle:IllegalCatch") - public void close() { - super.close(); - try { - LOG.debug("DropTestProvider stopped."); - if (notificationRegistration != null) { - notificationRegistration.close(); - } - } catch (RuntimeException e) { - LOG.warn("unregistration of notification listener failed: {}", e.getMessage()); - LOG.debug("unregistration of notification listener failed.. ", e); - } - } }