Skip to content
Snippets Groups Projects
Commit 465857a9 authored by Mandeep Dhami's avatar Mandeep Dhami
Browse files

Fixes some static hashmaps/return values to be ConcurrentHashMap

Updates corresponding interface definitions to use Map
parent 91607e22
No related branches found
No related tags found
No related merge requests found
......@@ -19,10 +19,8 @@ package net.floodlightcontroller.core;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Future;
import net.floodlightcontroller.core.types.MacVlanPair;
......@@ -139,7 +137,7 @@ public interface IOFSwitch {
* Get the portmap
* @return
*/
public HashMap<Short, OFPhysicalPort> getPorts();
public Map<Short, OFPhysicalPort> getPorts();
/**
* @param portNumber
......@@ -171,7 +169,7 @@ public interface IOFSwitch {
* Retrieves attributes of this switch
* @return
*/
public ConcurrentMap<Object, Object> getAttributes();
public Map<Object, Object> getAttributes();
/**
* Retrieves the date the switch connected to this controller
......
......@@ -20,9 +20,9 @@ package net.floodlightcontroller.core;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
......@@ -78,7 +78,7 @@ public class OFMessageFilterManager implements IOFMessageListener {
protected IFloodlightProvider floodlightProvider = null;
// filter List is a key value pair. Key is the session id, value is the filter rules.
protected ConcurrentHashMap<String, HashMap<String,String>> filterMap = null;
protected ConcurrentHashMap<String, ConcurrentHashMap<String,String>> filterMap = null;
protected ConcurrentHashMap<String, Long> filterTimeoutMap = null;
protected Timer timer = null;
......@@ -104,12 +104,12 @@ public class OFMessageFilterManager implements IOFMessageListener {
public void init (IFloodlightProvider bp) {
floodlightProvider = bp;
filterMap = new ConcurrentHashMap<String, HashMap<String,String>>();
filterMap = new ConcurrentHashMap<String, ConcurrentHashMap<String,String>>();
filterTimeoutMap = new ConcurrentHashMap<String, Long>();
serverPort = Integer.parseInt(System.getProperty("net.floodlightcontroller.packetstreamer.port", "9090"));
}
protected String addFilter(HashMap<String,String> f, long delta) {
protected String addFilter(ConcurrentHashMap<String,String> f, long delta) {
// Create unique session ID.
int prime = 33791;
......@@ -143,7 +143,7 @@ public class OFMessageFilterManager implements IOFMessageListener {
return s; // the return string is the session ID.
}
public String setupFilter(String sid, HashMap<String,String> f, int deltaInSecond) {
public String setupFilter(String sid, ConcurrentHashMap<String,String> f, int deltaInSecond) {
if (sid == null) {
// Delta in filter needs to be milliseconds
......@@ -230,7 +230,7 @@ public class OFMessageFilterManager implements IOFMessageListener {
while (filterIt.hasNext()) { // for every filter
boolean filterMatch = false;
String filterSessionId = filterIt.next();
HashMap<String,String> filter = filterMap.get(filterSessionId);
Map<String,String> filter = filterMap.get(filterSessionId);
// If the filter has empty fields, then it is not considered as a match.
if (filter == null || filter.isEmpty()) continue;
......
......@@ -20,7 +20,6 @@ package net.floodlightcontroller.core.internal;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
......@@ -66,7 +65,7 @@ public class OFSwitchImpl implements IOFSwitch {
protected String stringId;
protected Channel channel;
protected AtomicInteger transactionIdSource;
protected HashMap<Short, OFPhysicalPort> ports;
protected Map<Short, OFPhysicalPort> ports;
protected Long switchClusterId;
protected Map<MacVlanPair,Short> macVlanToPortMap;
protected Map<Integer,OFStatisticsFuture> statsFutureMap;
......@@ -81,10 +80,10 @@ public class OFSwitchImpl implements IOFSwitch {
this.attributes = new ConcurrentHashMap<Object, Object>();
this.connectedSince = new Date();
this.transactionIdSource = new AtomicInteger();
this.ports = new HashMap<Short, OFPhysicalPort>();
this.ports = new ConcurrentHashMap<Short, OFPhysicalPort>();
this.switchClusterId = null;
this.connected = true;
this.statsFutureMap = new HashMap<Integer,OFStatisticsFuture>();
this.statsFutureMap = new ConcurrentHashMap<Integer,OFStatisticsFuture>();
// Defaults properties for an ideal switch
this.setAttribute(PROP_FASTWILDCARDS, (Integer) OFMatch.OFPFW_ALL);
......@@ -179,7 +178,7 @@ public class OFSwitchImpl implements IOFSwitch {
ports.put(port.getPortNumber(), port);
}
public HashMap<Short, OFPhysicalPort> getPorts() {
public Map<Short, OFPhysicalPort> getPorts() {
return ports;
}
......@@ -315,7 +314,7 @@ public class OFSwitchImpl implements IOFSwitch {
public synchronized Map<MacVlanPair, Short> getMacVlanToPortMap() {
// Note that this function intentionally returns a copy
if (macVlanToPortMap != null)
return new HashMap<MacVlanPair, Short>(macVlanToPortMap);
return new ConcurrentHashMap<MacVlanPair, Short>(macVlanToPortMap);
else
return null;
}
......
......@@ -20,9 +20,9 @@ package net.floodlightcontroller.core.internal;
import static org.easymock.EasyMock.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
......@@ -284,19 +284,19 @@ public class ControllerTest extends FloodlightTestCase {
mfm.init(mbp);
mfm.startUp();
HashMap <String, String> filter;
ConcurrentHashMap <String, String> filter;
int i;
//Adding the filter works -- adds up to the maximum filter size.
for(i=mfm.getMaxFilterSize(); i > 0; --i) {
filter = new HashMap<String,String>();
filter = new ConcurrentHashMap<String,String>();
filter.put("mac", String.format("00:11:22:33:44:%d%d", i,i));
sid = mfm.setupFilter(null, filter, 6);
assertTrue(mfm.getNumberOfFilters() == mfm.getMaxFilterSize() - i +1);
}
// Add one more to see if you can't
filter = new HashMap<String,String>();
filter = new ConcurrentHashMap<String,String>();
filter.put("mac", "mac2");
mfm.setupFilter(null, filter, 10);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment