Updated MatchActionComponent to start pushing FlowMods
Change-Id: I8ef34135ecd9eb8a1d100932174c2539e4500aff
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
index 52e7dd9..83ad467 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
@@ -1,7 +1,6 @@
package net.onrc.onos.core.matchaction;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.EventListener;
import java.util.HashMap;
import java.util.HashSet;
@@ -57,6 +56,7 @@
// TODO Single instance for now, should be a work queue of some sort eventually
private Thread coordinator;
private Thread installer;
+ private Installer installerListener;
private final IDatagridService datagrid;
private IControllerRegistryService registryService;
@@ -93,6 +93,9 @@
installer = new InstallerWorker();
installer.start();
+
+ installerListener = new Installer();
+ installerListener.start();
}
public MatchActionOperationsId installMatchActionOperations(MatchActionOperations matchSet) {
@@ -101,6 +104,10 @@
} else {
matchSet.setState(MatchActionOperationsState.INIT);
}
+ log.trace("MatchActionsOperations set added: {} {} {}",
+ matchSet.getOperationsId(),
+ matchSet.getState(),
+ matchSet.toString());
matchSetMap.put(matchSet.getOperationsId(), matchSet);
if (matchSet.getState() == MatchActionOperationsState.RESOLVED) {
resolvedQueue.add(matchSet.getOperationsId());
@@ -128,7 +135,7 @@
class Coordinator extends Thread
implements IEventChannelListener<String, SwitchResultList> {
- private Map<MatchActionOperationsId, Map<Dpid, SwitchResult>> pendingMatchActionOperationss = new HashMap<>();
+ private Map<MatchActionOperationsId, Map<Dpid, SwitchResult>> pendingMatchActionOperations = new HashMap<>();
protected Coordinator() {
installSetReplyChannel.addListener(this);
@@ -166,17 +173,19 @@
matchActionMap.put(matchAction.getId(), matchAction);
break;
case REMOVE:
- //TODO
+ // TODO we may want to be more careful when removing MatchActions
+ matchActionMap.remove(matchAction.getId());
+ break;
default:
throw new UnsupportedOperationException(
"Unsupported MatchAction operation" +
matchActionOp.getOperator().toString());
}
}
- pendingMatchActionOperationss.put(setId, switches);
+ pendingMatchActionOperations.put(setId, switches);
// distribute apply/undo sets to cluster
- //installSetChannel.addTransientEntry(setId.toString(), matchSet);
+ installSetChannel.addTransientEntry(setId.toString(), matchSet);
}
@Override
@@ -201,7 +210,7 @@
MatchActionOperationsId matchSetId = results.get(0).getMatchActionOperationsId();
// apply updates from results list
- Map<Dpid, SwitchResult> resultMap = pendingMatchActionOperationss.get(matchSetId);
+ Map<Dpid, SwitchResult> resultMap = pendingMatchActionOperations.get(matchSetId);
for (SwitchResult result : results) {
SwitchResult resultToUpdate = resultMap.get(result.getSwitch());
if (resultToUpdate != null) {
@@ -230,7 +239,7 @@
MatchActionOperations matchSet = matchSetMap.get(matchSetId);
matchSet.setState(MatchActionOperationsState.INSTALLED);
matchSetMap.replace(matchSetId, matchSet);
- pendingMatchActionOperationss.remove(matchSetId);
+ pendingMatchActionOperations.remove(matchSetId);
// TODO update dependent sets as needed
break;
@@ -241,16 +250,18 @@
matchSetMap.replace(matchSetId, matchSet);
// TODO instruct installers to install Undo set
+ // TODO the pendingMatchActionOperations state needs to be cleaned-up
break;
case UNKNOWN:
+ // FALLTHROUGH
default:
// noop, still waiting for results
// TODO: check to see if installers are dead after timeout
+ break;
}
}
}
-
class InstallerWorker extends Thread {
// Note: we should consider using an alternative representation for
@@ -324,14 +335,19 @@
class Installer
implements IEventChannelListener<String, MatchActionOperations> {
- protected Installer() {
+ protected void start() {
installSetChannel.addListener(this);
}
@Override
public void entryAdded(MatchActionOperations value) {
- installationWorkQueue.add(value);
+ try {
+ installationWorkQueue.put(value);
+ } catch (InterruptedException e) {
+ log.warn("Error adding to installer work queue: {}",
+ e.getMessage());
+ }
}
@Override
@@ -341,7 +357,12 @@
@Override
public void entryUpdated(MatchActionOperations value) {
- installationWorkQueue.add(value);
+ try {
+ installationWorkQueue.put(value);
+ } catch (InterruptedException e) {
+ log.warn("Error adding to installer work queue: {}",
+ e.getMessage());
+ }
}
}
@@ -365,7 +386,8 @@
@Override
public Set<MatchAction> getMatchActions() {
- return Collections.unmodifiableSet(currentOperations);
+ // return Collections.unmodifiableSet(currentOperations);
+ return new HashSet<MatchAction>(matchActionMap.values());
}
@Override
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
index 72fd717..4970cf1 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
@@ -65,11 +65,6 @@
@Override
public void init(FloodlightModuleContext context) throws FloodlightModuleException {
-
- }
-
- @Override
- public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
final IDatagridService datagrid = context.getServiceImpl(IDatagridService.class);
final IFlowPusherService pusher = context.getServiceImpl(IFlowPusherService.class);
final IFloodlightProviderService provider = context.getServiceImpl(IFloodlightProviderService.class);
@@ -79,7 +74,10 @@
restApi.addRestletRoutable(new MatchActionWebRoutable());
matchActionComponent = new MatchActionComponent(datagrid, pusher, provider, registry);
- log.info("match action component created");
+ }
+
+ @Override
+ public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
matchActionComponent.start();
}
@@ -90,12 +88,13 @@
@Override
public Set<MatchAction> getMatchActions() {
- return null;
+ return matchActionComponent.getMatchActions();
}
@Override
public boolean executeOperations(MatchActionOperations operations) {
- return false;
+ matchActionComponent.installMatchActionOperations(operations);
+ return false; // TODO define return value semantics
}
@Override