<groupId>org.opendaylight.openflowplugin</groupId>
<artifactId>openflowplugin-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>infrautils-util</artifactId>
+ <version>${infrautils.version}</version>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
package org.opendaylight.openflowplugin.learningswitch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public interface LearningSwitchHandler {
* @param tablePath the table path
*/
void onSwitchAppeared(InstanceIdentifier<Table> tablePath);
-
- /**
- * Sets the PacketProcessingService.
- *
- * @param packetProcessingService the packetProcessingService to set
- */
- void setPacketProcessingService(PacketProcessingService packetProcessingService);
-
- /**
- * Sets the data store accessor.
- *
- * @param dataStoreAccessor the dataStoreAccessor to set
- */
- void setDataStoreAccessor(FlowCommitWrapper dataStoreAccessor);
-
- /**
- * Sets the DataTreeChangeListener registration publisher.
- *
- * @param registrationPublisher the registrationPublisher to set
- */
- void setRegistrationPublisher(DataTreeChangeListenerRegistrationHolder registrationPublisher);
}
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
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;
private static final byte[] ETH_TYPE_IPV4 = new byte[] { 0x08, 0x00 };
private static final int DIRECT_FLOW_PRIORITY = 512;
- private DataTreeChangeListenerRegistrationHolder registrationPublisher;
- private FlowCommitWrapper dataStoreAccessor;
- private PacketProcessingService packetProcessingService;
+ private final DataTreeChangeListenerRegistrationHolder registrationPublisher;
+ private final FlowCommitWrapper dataStoreAccessor;
+ private final PacketProcessingService packetProcessingService;
- private boolean isLearning = false;
+ private volatile boolean isLearning = false;
private NodeId nodeId;
private final AtomicLong flowIdInc = new AtomicLong();
private final AtomicLong flowCookieInc = new AtomicLong(0x2a00000000000000L);
private InstanceIdentifier<Node> nodePath;
- private InstanceIdentifier<Table> tablePath;
+ private volatile InstanceIdentifier<Table> tablePath;
private Map<MacAddress, NodeConnectorRef> mac2portMapping;
- private Set<String> coveredMacPaths;
+ private final Set<String> coveredMacPaths = new HashSet<>();
+
+ public LearningSwitchHandlerSimpleImpl(@Nonnull FlowCommitWrapper dataStoreAccessor,
+ @Nonnull PacketProcessingService packetProcessingService,
+ @Nullable DataTreeChangeListenerRegistrationHolder registrationPublisher) {
+ this.dataStoreAccessor = Objects.requireNonNull(dataStoreAccessor);
+ this.packetProcessingService = Objects.requireNonNull(packetProcessingService);
+ this.registrationPublisher = registrationPublisher;
+ }
@Override
public synchronized void onSwitchAppeared(InstanceIdentifier<Table> appearedTablePath) {
nodePath = tablePath.firstIdentifierOf(Node.class);
nodeId = nodePath.firstKeyOf(Node.class, NodeKey.class).getId();
mac2portMapping = new HashMap<>();
- coveredMacPaths = new HashSet<>();
// start forwarding all packages to controller
FlowId flowId = new FlowId(String.valueOf(flowIdInc.getAndIncrement()));
dataStoreAccessor.writeFlowToConfig(flowPath, allToCtrlFlow.build());
}
- @Override
- public void setRegistrationPublisher(DataTreeChangeListenerRegistrationHolder registrationPublisher) {
- this.registrationPublisher = registrationPublisher;
- }
-
- @Override
- public void setDataStoreAccessor(FlowCommitWrapper dataStoreAccessor) {
- this.dataStoreAccessor = dataStoreAccessor;
- }
-
- @Override
- public void setPacketProcessingService(PacketProcessingService packetProcessingService) {
- this.packetProcessingService = packetProcessingService;
- }
-
@Override
public void onPacketReceived(PacketReceived notification) {
if (!isLearning) {
.setEgress(egress)
.setIngress(ingress)
.build();
- packetProcessingService.transmitPacket(input);
+ JdkFutures.addErrorLogging(packetProcessingService.transmitPacket(input), LOG, "transmitPacket");
}
}
LOG.debug("start() -->");
FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
- LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl();
- learningSwitchHandler.setRegistrationPublisher(this);
- learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
- learningSwitchHandler.setPacketProcessingService(packetProcessingService);
+ LearningSwitchHandlerSimpleImpl learningSwitchHandler = new LearningSwitchHandlerSimpleImpl(dataStoreAccessor,
+ packetProcessingService, this);
packetInRegistration = notificationService.registerNotificationListener(learningSwitchHandler);
WakeupOnNode wakeupListener = new WakeupOnNode();
FlowCommitWrapper dataStoreAccessor = new FlowCommitWrapperImpl(data);
PacketInDispatcherImpl packetInDispatcher = new PacketInDispatcherImpl();
- MultipleLearningSwitchHandlerFacadeImpl learningSwitchHandler = new MultipleLearningSwitchHandlerFacadeImpl();
- learningSwitchHandler.setRegistrationPublisher(this);
- learningSwitchHandler.setDataStoreAccessor(dataStoreAccessor);
- learningSwitchHandler.setPacketProcessingService(packetProcessingService);
- learningSwitchHandler.setPacketInDispatcher(packetInDispatcher);
+ MultipleLearningSwitchHandlerFacadeImpl learningSwitchHandler = new MultipleLearningSwitchHandlerFacadeImpl(
+ dataStoreAccessor, packetProcessingService, packetInDispatcher);
packetInRegistration = notificationService.registerNotificationListener(packetInDispatcher);
WakeupOnNode wakeupListener = new WakeupOnNode();
package org.opendaylight.openflowplugin.learningswitch.multi;
-import org.opendaylight.openflowplugin.learningswitch.DataTreeChangeListenerRegistrationHolder;
+import java.util.Objects;
+import javax.annotation.Nonnull;
import org.opendaylight.openflowplugin.learningswitch.FlowCommitWrapper;
import org.opendaylight.openflowplugin.learningswitch.InstanceIdentifierUtils;
import org.opendaylight.openflowplugin.learningswitch.LearningSwitchHandler;
public class MultipleLearningSwitchHandlerFacadeImpl implements LearningSwitchHandler {
private static final Logger LOG = LoggerFactory.getLogger(MultipleLearningSwitchHandlerFacadeImpl.class);
- private FlowCommitWrapper dataStoreAccessor;
- private PacketProcessingService packetProcessingService;
- private PacketInDispatcherImpl packetInDispatcher;
+ private final FlowCommitWrapper dataStoreAccessor;
+ private final PacketProcessingService packetProcessingService;
+ private final PacketInDispatcherImpl packetInDispatcher;
+
+ public MultipleLearningSwitchHandlerFacadeImpl(@Nonnull FlowCommitWrapper dataStoreAccessor,
+ @Nonnull PacketProcessingService packetProcessingService,
+ @Nonnull PacketInDispatcherImpl packetInDispatcher) {
+ this.dataStoreAccessor = Objects.requireNonNull(dataStoreAccessor);
+ this.packetProcessingService = Objects.requireNonNull(packetProcessingService);
+ this.packetInDispatcher = Objects.requireNonNull(packetInDispatcher);
+ }
+
@Override
public synchronized void onSwitchAppeared(InstanceIdentifier<Table> appearedTablePath) {
*/
if (!packetInDispatcher.getHandlerMapping().containsKey(nodePath)) {
// delegate this node (owning appearedTable) to SimpleLearningSwitchHandler
- LearningSwitchHandlerSimpleImpl simpleLearningSwitch = new LearningSwitchHandlerSimpleImpl();
- /**
- * We set runtime dependencies
- */
- simpleLearningSwitch.setDataStoreAccessor(dataStoreAccessor);
- simpleLearningSwitch.setPacketProcessingService(packetProcessingService);
+ LearningSwitchHandlerSimpleImpl simpleLearningSwitch = new LearningSwitchHandlerSimpleImpl(
+ dataStoreAccessor, packetProcessingService, null);
/**
* We propagate table event to newly instantiated instance of learning switch
packetInDispatcher.getHandlerMapping().put(nodePath, simpleLearningSwitch);
}
}
-
- @Override
- public void setRegistrationPublisher(
- DataTreeChangeListenerRegistrationHolder registrationPublisher) {
- //NOOP
- }
-
- @Override
- public void setDataStoreAccessor(FlowCommitWrapper dataStoreAccessor) {
- this.dataStoreAccessor = dataStoreAccessor;
- }
-
- @Override
- public void setPacketProcessingService(
- PacketProcessingService packetProcessingService) {
- this.packetProcessingService = packetProcessingService;
- }
-
- public void setPacketInDispatcher(PacketInDispatcherImpl packetInDispatcher) {
- this.packetInDispatcher = packetInDispatcher;
- }
}
import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.osgi.framework.BundleContext;
public class Activator extends AbstractBindingAwareConsumer {
- SimpleDropFirewall service;
- private SalFlowService flowService;
- private SimpleDropFirewallCli cliAdapter;
-
- @Override
- protected void startImpl(BundleContext context) {
- service = new SimpleDropFirewall();
-
- cliAdapter.setService(service);
- }
-
@Override
public void onSessionInitialized(ConsumerContext session) {
- service.setContext(session);
- flowService = session.getRpcService(SalFlowService.class);
-
- service.setFlowService(flowService);
- service.start();
+ SalFlowService flowService = session.getRpcService(SalFlowService.class);
+ new SimpleDropFirewall(flowService).start();
}
-
}
*/
package org.opendaylight.openflowplugin.openflow.samples.consumer;
-import java.util.Collection;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
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.inventory.rev130819.NodeConnectorRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yangtools.yang.common.RpcResult;
public class SimpleDropFirewall {
- private ConsumerContext context;
- private SalFlowService flowService;
- private DataTreeChangeListener listener = new NodeListener();
+ private final SalFlowService flowService;
- public void setContext(ConsumerContext session) {
- this.context = session;
- }
-
- public void setFlowService(SalFlowService flowService) {
+ public SimpleDropFirewall(SalFlowService flowService) {
this.flowService = flowService;
}
public void start() {
- NotificationService notificationService = context.getSALService(NotificationService.class);
}
public boolean addFlow(AddFlowInput flow) throws InterruptedException,
return result.get(5, TimeUnit.SECONDS).isSuccessful();
}
-
- private class NodeListener implements DataTreeChangeListener<Node> {
- @Override
- public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> modifications) {
- for (DataTreeModification modification : modifications) {
- if (modification.getRootNode().getModificationType() == ModificationType.SUBTREE_MODIFIED) {
- // node updated
- }
- }
- }
- }
-
- private class InventoryListener implements OpendaylightInventoryListener {
-
- @Override
- public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
-
- }
-
- @Override
- public void onNodeRemoved(NodeRemoved notification) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onNodeUpdated(NodeUpdated notification) {
- // TODO Auto-generated method stub
-
- }
-
- }
}
public class SimpleDropFirewallCli {
- private SimpleDropFirewall service;
-
- public void setService(final SimpleDropFirewall service) {
- this.service = service;
- }
-
/**
* Form of input is: node name node-connector number source ip-address destinatinon ip-address.
*
private final BlockingQueue<byte[]> ofMsg;
private ChannelHandlerContext ctx;
private int eventNumber;
- private boolean scenarioFinished = false;
+ private volatile boolean scenarioFinished = false;
private int freeze = 2;
private long sleepBetweenTries = 100L;
private boolean finishedOK = true;
LOG.debug("Scenario finished");
synchronized (this) {
scenarioFinished = true;
- this.notify();
+ this.notifyAll();
}
}