Fix drop-test-karaf service injection
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestRpcSender.java
index 30089b69a18688d694648d85ffac5c17c0682167..e8922da432a8636ffa33c8d698d88da2e92743b3 100644 (file)
@@ -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,119 +7,6 @@
  */
 package org.opendaylight.openflowplugin.testcommon;
 
-import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.BUFFER_ID;
-import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.HARD_TIMEOUT;
-import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.IDLE_TIMEOUT;
-import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.PRIORITY;
-import static org.opendaylight.openflowplugin.testcommon.AbstractDropTest.TABLE_ID;
+public interface DropTestRpcSender extends DropTest {
 
-import java.math.BigInteger;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-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.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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 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;
-
-    /**
-     * @param flowService the flowService to set
-     */
-    public void setFlowService(SalFlowService flowService) {
-        this.flowService = flowService;
-    }
-
-    private static final ThreadLocal<AddFlowInputBuilder> BUILDER = new ThreadLocal<AddFlowInputBuilder>() {
-        @Override
-        protected AddFlowInputBuilder initialValue() {
-            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 NotificationProviderService notificationService;
-
-    private ListenerRegistration<NotificationListener> notificationRegistration;
-
-    /**
-     * start listening on packetIn
-     */
-    public void start() {
-        notificationRegistration = notificationService.registerNotificationListener(this);
-    }
-
-    @Override
-    protected void processPacket(final NodeKey node, final Match match, final Instructions instructions) {
-        final AddFlowInputBuilder fb = BUILDER.get();
-
-        // Finally build our flow
-        fb.setMatch(match);
-        fb.setInstructions(instructions);
-        //fb.setId(new FlowId(Long.toString(fb.hashCode)));
-
-        // Construct the flow instance id
-        final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier
-                // File under nodes
-                .builder(Nodes.class)
-                // A particular node identified by nodeKey
-                .child(Node.class, node).build();
-        fb.setNode(new NodeRef(flowInstanceId));
-
-        // Add flow
-        AddFlowInput flow = fb.build();
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
-        }
-        flowService.addFlow(flow);
-    }
-
-    /**
-     * @param notificationService
-     */
-    public void setNotificationService(NotificationProviderService notificationService) {
-        this.notificationService = notificationService;
-    }
-
-    @Override
-    public void close() {
-        try {
-            LOG.debug("DropTestProvider stopped.");
-            if (notificationRegistration != null) {
-                notificationRegistration.close();
-            }
-        } catch (Exception e) {
-            LOG.error("unregistration of notification listener failed", e);
-        }
-    }
 }