import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.Callable;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
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.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
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.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
* Created by Martin Bobak mbobak@cisco.com on 8/27/14.
*/
public class LLDPPacketPuntEnforcer implements DataChangeListener {
-
+ private static final long STARTUP_LOOP_TICK = 500L;
+ private static final int STARTUP_LOOP_MAX_RETRIES = 8;
private static final short TABLE_ID = (short) 0;
private static final String LLDP_PUNT_WHOLE_PACKET_FLOW = "LLDP_PUNT_WHOLE_PACKET_FLOW";
private static final String DEFAULT_FLOW_ID = "42";
private final SalFlowService flowService;
+ private final DataBroker dataBroker;
+ private ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
- public LLDPPacketPuntEnforcer(SalFlowService flowService) {
+ public LLDPPacketPuntEnforcer(SalFlowService flowService, DataBroker dataBroker) {
this.flowService = flowService;
+ this.dataBroker = dataBroker;
+ }
+
+ public void start() {
+ final InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class).
+ augmentation(FlowCapableNode.class);
+ SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
+ try {
+ dataChangeListenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DataChangeListener>>() {
+ @Override
+ public ListenerRegistration<DataChangeListener> call() throws Exception {
+ return dataBroker.registerDataChangeListener(
+ LogicalDatastoreType.OPERATIONAL,
+ path, LLDPPacketPuntEnforcer.this, AsyncDataBroker.DataChangeScope.BASE);
+ }
+ });
+ } catch (Exception e) {
+ throw new IllegalStateException("registerDataChangeListener failed", e);
+ }
+ }
+
+ public void close() {
+ if(dataChangeListenerRegistration != null) {
+ dataChangeListenerRegistration.close();
+ }
}
@Override
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.table.miss.enforcer.rev140326;
-import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.applications.tableMissEnforcer.LLDPPacketPuntEnforcer;
-import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-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.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LLDPPacketPuntEnforcerModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.table.miss.enforcer.rev140326.AbstractLLDPPacketPuntEnforcerModule {
- private static final long STARTUP_LOOP_TICK = 500L;
- private static final int STARTUP_LOOP_MAX_RETRIES = 8;
- private static final Logger LOG = LoggerFactory.getLogger(LLDPPacketPuntEnforcerModule.class);
+import org.opendaylight.controller.sal.common.util.NoopAutoCloseable;
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class LLDPPacketPuntEnforcerModule extends AbstractLLDPPacketPuntEnforcerModule {
public LLDPPacketPuntEnforcerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
}
@Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- final InstanceIdentifier<FlowCapableNode> path = InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
- final SalFlowService salFlowService = getRpcRegistryDependency().getRpcService(SalFlowService.class);
-
- ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
- SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK, STARTUP_LOOP_MAX_RETRIES);
- try {
- dataChangeListenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<DataChangeListener>>() {
- @Override
- public ListenerRegistration<DataChangeListener> call() throws Exception {
- return getDataBrokerDependency().registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL,
- path,
- new LLDPPacketPuntEnforcer(salFlowService),
- AsyncDataBroker.DataChangeScope.BASE);
- }
- });
- } catch (Exception e) {
- LOG.warn("data listener registration failed: {}", e.getMessage());
- LOG.debug("data listener registration failed.. ", e);
- throw new IllegalStateException("LLDPPacketPuntEnforcer startup fail! System needs restart.", e);
- }
- return dataChangeListenerRegistration;
+ public AutoCloseable createInstance() {
+ // LLDPPacketPuntEnforcer instance is created via blueprint so this in a no-op.
+ return NoopAutoCloseable.INSTANCE;
}
-
}
* Do not modify this file unless it is present under src/main directory
*/
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.table.miss.enforcer.rev140326;
-public class LLDPPacketPuntEnforcerModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.table.miss.enforcer.rev140326.AbstractLLDPPacketPuntEnforcerModuleFactory {
+
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class LLDPPacketPuntEnforcerModuleFactory extends AbstractLLDPPacketPuntEnforcerModuleFactory {
}
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
+
+NOTE: This file is deprecated as wiring is now done via blueprint. This file is kept for
+ backwards compatibility. Runtime modifications are not honored.
-->
<snapshot>
<configuration>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+
+ <odl:rpc-service id="flowService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService"/>
+
+ <bean id="LLDPPacketPuntEnforcer" class="org.opendaylight.openflowplugin.applications.tableMissEnforcer.LLDPPacketPuntEnforcer"
+ init-method="start" destroy-method="close">
+ <argument ref="flowService"/>
+ <argument ref="dataBroker"/>
+ </bean>
+</blueprint>
\ No newline at end of file
identity table-miss-enforcer {
base "config:module-type";
config:java-name-prefix LLDPPacketPuntEnforcer;
+ status deprecated;
}
augment "/config:modules/config:module/config:configuration" {
*/
@Test
public void testCreateFlow() {
- LLDPPacketPuntEnforcer lldpDataChangeListener = new LLDPPacketPuntEnforcer(flowService);
+ LLDPPacketPuntEnforcer lldpDataChangeListener = new LLDPPacketPuntEnforcer(flowService, null);
evaluateFlow(lldpDataChangeListener.createFlow());
}