private static final Logger log = LoggerFactory.getLogger(ForwardingRulesManager.class);
private static final Logger logsync = LoggerFactory.getLogger("FRMsync");
- private static final String PORTREMOVED = "Port removed";
- private static final String NODEDOWN = "Node is Down";
+ private static final String PORT_REMOVED = "Port removed";
+ private static final String NODE_DOWN = "Node is Down";
private static final String INVALID_FLOW_ENTRY = "Invalid FlowEntry";
private String frmFileName;
private String portGroupFileName;
*/
static final String WORK_ORDER_CACHE = "frm.workOrder";
static final String WORK_STATUS_CACHE = "frm.workStatus";
+ static final String ORIGINAL_SW_VIEW_CACHE = "frm.originalSwView";
+ static final String INSTALLED_SW_VIEW_CACHE = "frm.installedSwView";
/*
* Data structure responsible for distributing the FlowEntryInstall requests
// Update DB
newEntries.setRequestId(status.getRequestId());
- updateLocalDatabase(currentEntries, false);
- updateLocalDatabase(newEntries, true);
+ updateSwViews(currentEntries, false);
+ updateSwViews(newEntries, true);
return status;
}
log.trace("Removed {}", entry.getInstall());
// Update DB
- updateLocalDatabase(entry, false);
+ updateSwViews(entry, false);
return status;
}
// Update DB
entry.setRequestId(status.getRequestId());
- updateLocalDatabase(entry, true);
+ updateSwViews(entry, true);
return status;
}
return null;
}
- private void updateLocalDatabase(FlowEntryInstall entry, boolean add) {
- // Update the software view
- updateSwViewes(entry, add);
-
+ private void updateIndexDatabase(FlowEntryInstall entry, boolean add) {
// Update node indexed flow database
updateNodeFlowsDB(entry, add);
/*
* Update the node mapped flows database
*/
- private void updateSwViewes(FlowEntryInstall flowEntries, boolean add) {
+ private void updateSwViews(FlowEntryInstall flowEntries, boolean add) {
if (add) {
originalSwView.put(flowEntries.getOriginal(), flowEntries.getOriginal());
installedSwView.put(flowEntries, flowEntries);
// Update DB
if (status.isSuccess()) {
- updateLocalDatabase(target, false);
+ updateSwViews(target, false);
} else {
// log the error
log.trace("SDN Plugin failed to remove the flow: {}. The failure is: {}", target.getInstall(),
private void nonClusterObjectCreate() {
originalSwView = new ConcurrentHashMap<FlowEntry, FlowEntry>();
installedSwView = new ConcurrentHashMap<FlowEntryInstall, FlowEntryInstall>();
- nodeFlows = new ConcurrentHashMap<Node, List<FlowEntryInstall>>();
- groupFlows = new ConcurrentHashMap<String, List<FlowEntryInstall>>();
TSPolicies = new ConcurrentHashMap<String, Object>();
staticFlowsOrdinal = new ConcurrentHashMap<Integer, Integer>();
portGroupConfigs = new ConcurrentHashMap<String, PortGroupConfig>();
log.debug("Allocating caches for Container {}", container.getName());
try {
- clusterContainerService.createCache("frm.originalSwView",
+ clusterContainerService.createCache(ORIGINAL_SW_VIEW_CACHE,
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
- clusterContainerService.createCache("frm.installedSwView",
+ clusterContainerService.createCache(INSTALLED_SW_VIEW_CACHE,
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache("frm.inactiveFlows",
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
- clusterContainerService.createCache("frm.nodeFlows",
- EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
- clusterContainerService.createCache("frm.groupFlows",
- EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-
clusterContainerService.createCache("frm.staticFlows",
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
log.debug("Retrieving Caches for Container {}", container.getName());
- map = clusterContainerService.getCache("frm.originalSwView");
+ map = clusterContainerService.getCache(ORIGINAL_SW_VIEW_CACHE);
if (map != null) {
originalSwView = (ConcurrentMap<FlowEntry, FlowEntry>) map;
} else {
log.error("Retrieval of frm.originalSwView cache failed for Container {}", container.getName());
}
- map = clusterContainerService.getCache("frm.installedSwView");
+ map = clusterContainerService.getCache(INSTALLED_SW_VIEW_CACHE);
if (map != null) {
installedSwView = (ConcurrentMap<FlowEntryInstall, FlowEntryInstall>) map;
} else {
log.error("Retrieval of frm.inactiveFlows cache failed for Container {}", container.getName());
}
- map = clusterContainerService.getCache("frm.nodeFlows");
- if (map != null) {
- nodeFlows = (ConcurrentMap<Node, List<FlowEntryInstall>>) map;
- } else {
- log.error("Retrieval of cache failed for Container {}", container.getName());
- }
-
- map = clusterContainerService.getCache("frm.groupFlows");
- if (map != null) {
- groupFlows = (ConcurrentMap<String, List<FlowEntryInstall>>) map;
- } else {
- log.error("Retrieval of frm.groupFlows cache failed for Container {}", container.getName());
- }
-
map = clusterContainerService.getCache("frm.staticFlows");
if (map != null) {
staticFlows = (ConcurrentMap<Integer, FlowConfig>) map;
// Take note of this controller generated static flow
toRemove.add(entry.getKey());
} else {
- config.setStatus(NODEDOWN);
+ config.setStatus(NODE_DOWN);
}
}
}
List<FlowEntryInstall> toRemove = new ArrayList<FlowEntryInstall>(nodeFlows.get(node));
for (FlowEntryInstall entry : toRemove) {
- updateLocalDatabase(entry, false);
+ updateSwViews(entry, false);
}
}
}
if (fei.getGroupName().equals(FlowConfig.STATICFLOWGROUP)) {
FlowConfig flowConfig = getStaticFlow(fei.getFlowName(), fei.getNode());
if (flowConfig != null) {
- flowConfig.setStatus(PORTREMOVED);
+ flowConfig.setStatus(PORT_REMOVED);
updated = true;
}
}
portGroupProvider.registerPortGroupChange(this);
}
+ nodeFlows = new ConcurrentHashMap<Node, List<FlowEntryInstall>>();
+ groupFlows = new ConcurrentHashMap<String, List<FlowEntryInstall>>();
+
cacheStartup();
registerWithOSGIConsole();
* flow merging is not an injective function
*/
updateFlowsContainerFlow();
+ } else if (event instanceof UpdateIndexDBs) {
+ UpdateIndexDBs update = (UpdateIndexDBs)event;
+ updateIndexDatabase(update.getFei(), update.isAddition());
} else {
- log.warn("Dequeued unknown event {}", event.getClass()
- .getSimpleName());
+ log.warn("Dequeued unknown event {}", event.getClass().getSimpleName());
}
} catch (InterruptedException e) {
// clear pending events
}
}
+ private class UpdateIndexDBs extends FRMEvent {
+ private FlowEntryInstall fei;
+ private boolean add;
+
+ /**
+ *
+ * @param fei the flow entry which was installed/removed on the netwrok node
+ * @param update
+ */
+ UpdateIndexDBs(FlowEntryInstall fei, boolean add) {
+ this.fei = fei;
+ this.add = add;
+ }
+
+
+ /**
+ * @return the flowEntryInstall object which was added/removed
+ * to/from the installed software view cache
+ */
+ public FlowEntryInstall getFei() {
+ return fei;
+ }
+
+ /**
+ *
+ * @return whether this was an flow addition or removal
+ */
+ public boolean isAddition() {
+ return add;
+ }
+ }
+
/*
* OSGI COMMANDS
*/
}
// Update software views
- this.updateLocalDatabase(installedEntry, false);
+ this.updateSwViews(installedEntry, false);
}
@Override
}
if (target != null) {
// This was a flow install, update database
- this.updateLocalDatabase(target, false);
+ this.updateSwViews(target, false);
// also update the config
if(FlowConfig.STATICFLOWGROUP.equals(target.getGroupName())) {
ConcurrentMap.Entry<Integer, FlowConfig> staticFlowEntry = getStaticFlowEntry(target.getFlowName(),target.getNode());
@Override
public void entryUpdated(Object key, Object new_value, String cacheName, boolean originLocal) {
+ /*
+ * Streamline the updates for the per node and per group index databases
+ */
+ if (cacheName.equals(INSTALLED_SW_VIEW_CACHE)) {
+ pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)key, true));
+ }
+
if (originLocal) {
/*
* Local updates are of no interest
@Override
public void entryDeleted(Object key, String cacheName, boolean originLocal) {
/*
- * Do nothing
+ * Streamline the updates for the per node and per group index databases
*/
+ if (cacheName.equals(INSTALLED_SW_VIEW_CACHE)) {
+ pendingEvents.offer(new UpdateIndexDBs((FlowEntryInstall)key, false));
+ }
}
/**