Change-Id: I763bdd6178047e3de43158176c29a8bd6f478b25
Signed-off-by: Alessandro Boch <aboch@cisco.com>
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply;
import java.util.List;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply;
private List<FlowOnNode> flowOnNodeList;
public FlowStatisticsConverter(List<OFStatistics> statsList) {
private List<FlowOnNode> flowOnNodeList;
public FlowStatisticsConverter(List<OFStatistics> statsList) {
- if (statsList == null) {// || statsList.isEmpty()) {
- this.ofStatsList = new ArrayList<OFStatistics>(1); // dummy list
+ if (statsList == null) {
+ this.ofStatsList = Collections.emptyList();
- this.ofStatsList = statsList; // new
- // ArrayList<OFStatistics>(statsList);
+ this.ofStatsList = statsList;
}
this.flowOnNodeList = null;
}
}
this.flowOnNodeList = null;
}
private ConcurrentMap<Long, List<OFStatistics>> descStatistics;
private ConcurrentMap<Long, List<OFStatistics>> portStatistics;
private ConcurrentMap<Long, List<OFStatistics>> tableStatistics;
private ConcurrentMap<Long, List<OFStatistics>> descStatistics;
private ConcurrentMap<Long, List<OFStatistics>> portStatistics;
private ConcurrentMap<Long, List<OFStatistics>> tableStatistics;
- private List<OFStatistics> dummyList;
private ConcurrentMap<Long, StatisticsTicks> statisticsTimerTicks;
protected BlockingQueue<StatsRequest> pendingStatsRequests;
protected BlockingQueue<Long> switchPortStatsUpdated;
private ConcurrentMap<Long, StatisticsTicks> statisticsTimerTicks;
protected BlockingQueue<StatsRequest> pendingStatsRequests;
protected BlockingQueue<Long> switchPortStatsUpdated;
descStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
portStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
tableStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
descStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
portStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
tableStatistics = new ConcurrentHashMap<Long, List<OFStatistics>>();
- dummyList = new ArrayList<OFStatistics>(1);
pendingStatsRequests = new LinkedBlockingQueue<StatsRequest>(getStatsQueueSize());
statisticsTimerTicks = new ConcurrentHashMap<Long, StatisticsTicks>(INITIAL_SIZE);
switchPortStatsUpdated = new LinkedBlockingQueue<Long>(INITIAL_SIZE);
pendingStatsRequests = new LinkedBlockingQueue<StatsRequest>(getStatsQueueSize());
statisticsTimerTicks = new ConcurrentHashMap<Long, StatisticsTicks>(INITIAL_SIZE);
switchPortStatsUpdated = new LinkedBlockingQueue<Long>(INITIAL_SIZE);
List<OFStatistics> values = this.fetchStatisticsFromSwitch(switchId, statType, null);
// If got a valid response update local cache and notify listeners
List<OFStatistics> values = this.fetchStatisticsFromSwitch(switchId, statType, null);
// If got a valid response update local cache and notify listeners
- if (values != null && !values.isEmpty()) {
+ if (!values.isEmpty()) {
switch (statType) {
case FLOW:
case VENDOR:
switch (statType) {
case FLOW:
case VENDOR:
@SuppressWarnings("unchecked")
private List<OFStatistics> fetchStatisticsFromSwitch(Long switchId,
OFStatisticsType statsType, Object target) {
@SuppressWarnings("unchecked")
private List<OFStatistics> fetchStatisticsFromSwitch(Long switchId,
OFStatisticsType statsType, Object target) {
- List<OFStatistics> values = null;
+ List<OFStatistics> values = Collections.emptyList();
String type = null;
ISwitch sw = controller.getSwitch(switchId);
String type = null;
ISwitch sw = controller.getSwitch(switchId);
// Malformed request
log.warn("Invalid target type for Flow stats request: {}",
target.getClass());
// Malformed request
log.warn("Invalid target type for Flow stats request: {}",
target.getClass());
+ return Collections.emptyList();
} else {
// Specific flow request
match = (OFMatch) target;
} else {
// Specific flow request
match = (OFMatch) target;
// Malformed request
log.warn("Invalid target type for Port stats request: {}",
target.getClass());
// Malformed request
log.warn("Invalid target type for Port stats request: {}",
target.getClass());
+ return Collections.emptyList();
} else {
// Specific port request
targetPort = (Short) target;
} else {
// Specific port request
targetPort = (Short) target;
// Malformed request
log.warn("Invalid table id for table stats request: {}",
target.getClass());
// Malformed request
log.warn("Invalid table id for table stats request: {}",
target.getClass());
+ return Collections.emptyList();
}
byte targetTable = (Byte) target;
OFTableStatistics specificReq = new OFTableStatistics();
}
byte targetTable = (Byte) target;
OFTableStatistics specificReq = new OFTableStatistics();
* Check on emptiness as interference between add and get is still
* possible on the inner list (the concurrentMap entry's value)
*/
* Check on emptiness as interference between add and get is still
* possible on the inner list (the concurrentMap entry's value)
*/
- return (list == null || list.isEmpty()) ? this.dummyList
+ return (list == null || list.isEmpty()) ? Collections.<OFStatistics>emptyList()
: (list.get(0) instanceof OFVendorStatistics) ? this
.v6StatsListToOFStatsList(list) : list;
}
: (list.get(0) instanceof OFVendorStatistics) ? this
.v6StatsListToOFStatsList(list) : list;
}
* possible on the inner list (the concurrentMap entry's value)
*/
if (statsList == null || statsList.isEmpty()) {
* possible on the inner list (the concurrentMap entry's value)
*/
if (statsList == null || statsList.isEmpty()) {
+ return Collections.emptyList();
}
if (statsList.get(0) instanceof OFVendorStatistics) {
}
if (statsList.get(0) instanceof OFVendorStatistics) {
+ return Collections.emptyList();
}
/*
* Converts the v6 vendor statistics to the OFStatistics
*/
}
/*
* Converts the v6 vendor statistics to the OFStatistics
*/
- private List<OFStatistics> v6StatsListToOFStatsList(
- List<OFStatistics> statistics) {
+ private List<OFStatistics> v6StatsListToOFStatsList(List<OFStatistics> statistics) {
+ if (statistics == null || statistics.isEmpty()) {
+ return Collections.emptyList();
+ }
List<OFStatistics> v6statistics = new ArrayList<OFStatistics>();
List<OFStatistics> v6statistics = new ArrayList<OFStatistics>();
- if (statistics != null && !statistics.isEmpty()) {
- for (OFStatistics stats : statistics) {
- if (stats instanceof OFVendorStatistics) {
- List<OFStatistics> r = getV6ReplyStatistics((OFVendorStatistics) stats);
- if (r != null) {
- v6statistics.addAll(r);
- }
+ for (OFStatistics stats : statistics) {
+ if (stats instanceof OFVendorStatistics) {
+ List<OFStatistics> r = getV6ReplyStatistics((OFVendorStatistics) stats);
+ if (r != null) {
+ v6statistics.addAll(r);
OFVendorStatistics stat) {
int length = stat.getLength();
List<OFStatistics> results = new ArrayList<OFStatistics>();
OFVendorStatistics stat) {
int length = stat.getLength();
List<OFStatistics> results = new ArrayList<OFStatistics>();
- if (length < 12)
- return null; // Nicira Hdr is 12 bytes. We need atleast that much
+ if (length < 12) {
+ // Nicira Hdr is 12 bytes. We need at least that much
+ return Collections.emptyList();
+ }
ByteBuffer data = ByteBuffer.allocate(length);
stat.writeTo(data);
data.rewind();
ByteBuffer data = ByteBuffer.allocate(length);
stat.writeTo(data);
data.rewind();
int vendor = data.getInt(); // first 4 bytes is vendor id.
if (vendor != V6StatsRequest.NICIRA_VENDOR_ID) {
log.warn("Unexpected vendor id: 0x{}", Integer.toHexString(vendor));
int vendor = data.getInt(); // first 4 bytes is vendor id.
if (vendor != V6StatsRequest.NICIRA_VENDOR_ID) {
log.warn("Unexpected vendor id: 0x{}", Integer.toHexString(vendor));
+ return Collections.emptyList();
} else {
// go ahead by 8 bytes which is 8 bytes of 0
data.getLong(); // should be all 0's
} else {
// go ahead by 8 bytes which is 8 bytes of 0
data.getLong(); // should be all 0's
while (length > 0) {
v6statsreply = new V6StatsReply();
min_len = v6statsreply.getLength();
while (length > 0) {
v6statsreply = new V6StatsReply();
min_len = v6statsreply.getLength();
- if (length < v6statsreply.getLength())
+ if (length < v6statsreply.getLength()) {
v6statsreply.setActionFactory(stat.getActionFactory());
v6statsreply.readFrom(data);
v6statsreply.setActionFactory(stat.getActionFactory());
v6statsreply.readFrom(data);
- if (v6statsreply.getLength() < min_len)
+ if (v6statsreply.getLength() < min_len) {
v6statsreply.setVendorId(vendor);
log.trace("V6StatsReply: {}", v6statsreply);
length -= v6statsreply.getLength();
v6statsreply.setVendorId(vendor);
log.trace("V6StatsReply: {}", v6statsreply);
length -= v6statsreply.getLength();
- List<OFStatistics> list = this.fetchStatisticsFromSwitch(switchId, statType,
- target);
+ List<OFStatistics> list = this.fetchStatisticsFromSwitch(switchId, statType, target);
- return (list == null) ? null :
- (statType == OFStatisticsType.VENDOR) ? v6StatsListToOFStatsList(list) : list;
+ return (statType == OFStatisticsType.VENDOR) ? v6StatsListToOFStatsList(list) : list;
}
@Override
public List<OFStatistics> getOFDescStatistics(Long switchId) {
}
@Override
public List<OFStatistics> getOFDescStatistics(Long switchId) {
- if (!descStatistics.containsKey(switchId))
- return this.dummyList;
+ if (!descStatistics.containsKey(switchId)) {
+ return Collections.emptyList();
+ }
return descStatistics.get(switchId);
}
return descStatistics.get(switchId);
}
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId) {
if (!portStatistics.containsKey(switchId)) {
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId) {
if (!portStatistics.containsKey(switchId)) {
+ return Collections.emptyList();
}
return portStatistics.get(switchId);
}
return portStatistics.get(switchId);
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId, short portId) {
if (!portStatistics.containsKey(switchId)) {
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId, short portId) {
if (!portStatistics.containsKey(switchId)) {
+ return Collections.emptyList();
}
List<OFStatistics> list = new ArrayList<OFStatistics>(1);
for (OFStatistics stats : portStatistics.get(switchId)) {
}
List<OFStatistics> list = new ArrayList<OFStatistics>(1);
for (OFStatistics stats : portStatistics.get(switchId)) {
@Override
public List<OFStatistics> getOFTableStatistics(Long switchId) {
if (!tableStatistics.containsKey(switchId)) {
@Override
public List<OFStatistics> getOFTableStatistics(Long switchId) {
if (!tableStatistics.containsKey(switchId)) {
+ return Collections.emptyList();
}
return tableStatistics.get(switchId);
}
return tableStatistics.get(switchId);
@Override
public List<OFStatistics> getOFTableStatistics(Long switchId, Byte tableId) {
if (!tableStatistics.containsKey(switchId)) {
@Override
public List<OFStatistics> getOFTableStatistics(Long switchId, Byte tableId) {
if (!tableStatistics.containsKey(switchId)) {
+ return Collections.emptyList();
}
List<OFStatistics> list = new ArrayList<OFStatistics>(1);
}
List<OFStatistics> list = new ArrayList<OFStatistics>(1);
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.opendaylight.controller.sal.core.Node;
import java.util.List;
import org.opendaylight.controller.sal.core.Node;
public PortStatisticsConverter(long switchId, List<OFStatistics> statsList) {
this.switchId = switchId;
if (statsList == null || statsList.isEmpty()) {
public PortStatisticsConverter(long switchId, List<OFStatistics> statsList) {
this.switchId = switchId;
if (statsList == null || statsList.isEmpty()) {
- this.ofStatsList = new ArrayList<OFStatistics>(1); // dummy list
+ this.ofStatsList = Collections.emptyList();
} else {
this.ofStatsList = new ArrayList<OFStatistics>(statsList);
}
} else {
this.ofStatsList = new ArrayList<OFStatistics>(statsList);
}
package org.opendaylight.controller.protocol_plugin.openflow.internal;
package org.opendaylight.controller.protocol_plugin.openflow.internal;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.List;
import java.util.Set;
import java.util.Dictionary;
import java.util.List;
import java.util.Set;
public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
+ return Collections.emptyList();
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for the node : " + node);
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for the node : " + node);
+ return Collections.emptyList();
}
return filter.readAllFlow(containerName, node, cached);
}
return filter.readAllFlow(containerName, node, cached);
boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
+ return Collections.emptyList();
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for node : " + node);
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for node : " + node);
+ return Collections.emptyList();
}
return filter.readAllNodeConnector(containerName, node, cached);
}
return filter.readAllNodeConnector(containerName, node, cached);
public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
if (!node.getType().equals(NodeIDType.OPENFLOW)) {
logger.error("Invalid node type");
+ return Collections.emptyList();
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for node : " + node);
}
if (!connectionOutService.isLocal(node)) {
logger.debug("This Controller is not the master for node : " + node);
+ return Collections.emptyList();
}
return filter.readAllNodeTable(containerName, node, cached);
}
return filter.readAllNodeTable(containerName, node, cached);
List<FlowOnNode> flowOnNodeList = new FlowStatisticsConverter(ofList).getFlowOnNodeList(node);
List<FlowOnNode> filteredList = filterFlowListPerContainer(container, node, flowOnNodeList);
List<FlowOnNode> flowOnNodeList = new FlowStatisticsConverter(ofList).getFlowOnNodeList(node);
List<FlowOnNode> filteredList = filterFlowListPerContainer(container, node, flowOnNodeList);
- return (filteredList == null || filteredList.isEmpty()) ? null : filteredList.get(0);
+ return (filteredList.isEmpty()) ? null : filteredList.get(0);
// Convert and filter the statistics per container
List<FlowOnNode> flowOnNodeList = new FlowStatisticsConverter(ofList).getFlowOnNodeList(node);
// Convert and filter the statistics per container
List<FlowOnNode> flowOnNodeList = new FlowStatisticsConverter(ofList).getFlowOnNodeList(node);
- List<FlowOnNode> filteredList = filterFlowListPerContainer(container, node, flowOnNodeList);
-
- return (filteredList == null) ? null : filteredList;
+ return filterFlowListPerContainer(container, node, flowOnNodeList);
* @param list
* @return
*/
* @param list
* @return
*/
- public List<FlowOnNode> filterFlowListPerContainer(String container,
+ private List<FlowOnNode> filterFlowListPerContainer(String container,
Node nodeId, List<FlowOnNode> list) {
if (list == null) {
Node nodeId, List<FlowOnNode> list) {
if (list == null) {
+ return Collections.emptyList();
}
// Create new filtered list of flows
}
// Create new filtered list of flows
* @param list
* @return
*/
* @param list
* @return
*/
- public List<OFStatistics> filterPortListPerContainer(String container, long switchId, List<OFStatistics> list) {
+ private List<OFStatistics> filterPortListPerContainer(String container, long switchId, List<OFStatistics> list) {
+ return Collections.emptyList();
}
// Create new filtered list of flows
}
// Create new filtered list of flows
- public List<OFStatistics> filterTableListPerContainer(
+ private List<OFStatistics> filterTableListPerContainer(
String container, long switchId, List<OFStatistics> list) {
if (list == null) {
String container, long switchId, List<OFStatistics> list) {
if (list == null) {
+ return Collections.emptyList();
}
// Create new filtered list of node tables
}
// Create new filtered list of node tables
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
package org.opendaylight.controller.protocol_plugin.openflow.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.opendaylight.controller.sal.core.Node;
import java.util.List;
import org.opendaylight.controller.sal.core.Node;
public TableStatisticsConverter(long switchId, List<OFStatistics> statsList) {
this.switchId = switchId;
if (statsList == null || statsList.isEmpty()) {
public TableStatisticsConverter(long switchId, List<OFStatistics> statsList) {
this.switchId = switchId;
if (statsList == null || statsList.isEmpty()) {
- this.ofStatsList = new ArrayList<OFStatistics>(1); // dummy list
+ this.ofStatsList = Collections.emptyList();
} else {
this.ofStatsList = new ArrayList<OFStatistics>(statsList);
}
} else {
this.ofStatsList = new ArrayList<OFStatistics>(statsList);
}
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Map;
import java.util.Set;
}
}
logger.warn("Plugin {} unavailable", node.getType());
}
}
logger.warn("Plugin {} unavailable", node.getType());
+ return Collections.emptyList();
}
}
logger.warn("Plugin {} unavailable", node.getType());
}
}
logger.warn("Plugin {} unavailable", node.getType());
+ return Collections.emptyList();
}
}
logger.warn("Plugin {} unavailable", node.getType());
}
}
logger.warn("Plugin {} unavailable", node.getType());
+ return Collections.emptyList();
}
}
logger.warn("Plugin {} unavailable", node.getType());
}
}
logger.warn("Plugin {} unavailable", node.getType());
+ return Collections.emptyList();
}
}
logger.warn("Plugin {} unavailable", node.getType());
}
}
logger.warn("Plugin {} unavailable", node.getType());
+ return Collections.emptyList();
triggers = new ConcurrentHashMap<Integer, Node>();
}
triggers = new ConcurrentHashMap<Integer, Node>();
}
- @SuppressWarnings("deprecation")
private void allocateCaches() {
if (clusterContainerService == null) {
nonClusterObjectCreate();
private void allocateCaches() {
if (clusterContainerService == null) {
nonClusterObjectCreate();
log.debug("Skipping statistics cache creation - already present");
}
}
log.debug("Skipping statistics cache creation - already present");
}
}
- @SuppressWarnings({ "unchecked", "deprecation" })
+ @SuppressWarnings({ "unchecked" })
private void retrieveCaches() {
ConcurrentMap<?, ?> map;
private void retrieveCaches() {
ConcurrentMap<?, ?> map;
@Override
public List<NodeConnectorStatistics> getNodeConnectorStatistics(Node node) {
if (node == null){
@Override
public List<NodeConnectorStatistics> getNodeConnectorStatistics(Node node) {
if (node == null){
+ return Collections.emptyList();
}
List<NodeConnectorStatistics> statList = new ArrayList<NodeConnectorStatistics>();
}
List<NodeConnectorStatistics> statList = new ArrayList<NodeConnectorStatistics>();
@Override
public List<NodeTableStatistics> getNodeTableStatistics(Node node){
if (node == null){
@Override
public List<NodeTableStatistics> getNodeTableStatistics(Node node){
if (node == null){
+ return Collections.emptyList();
}
List<NodeTableStatistics> statList = new ArrayList<NodeTableStatistics>();
List<NodeTableStatistics> cachedList = tableStatistics.get(node);
}
List<NodeTableStatistics> statList = new ArrayList<NodeTableStatistics>();
List<NodeTableStatistics> cachedList = tableStatistics.get(node);