import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsRequest;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsReply;
import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6StatsRequest;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
- * It periodically polls the different OF statistics from the OF switches and
- * caches them for quick retrieval for the above layers' modules It also
- * provides an API to directly query the switch about the statistics
+ * Periodically polls the different OF statistics from the OF switches, caches
+ * them, and publishes results towards SAL. It also provides an API to directly
+ * query the switch for any specific statistics.
-public class OFStatisticsManager implements IOFStatisticsManager,
-IInventoryShimExternalListener, CommandProvider {
+public class OFStatisticsManager implements IOFStatisticsManager, IInventoryShimExternalListener, CommandProvider {
private static final Logger log = LoggerFactory.getLogger(OFStatisticsManager.class);
private static final int INITIAL_SIZE = 64;
private static final long FLOW_STATS_PERIOD = 10000;
private static final Logger log = LoggerFactory.getLogger(OFStatisticsManager.class);
private static final int INITIAL_SIZE = 64;
private static final long FLOW_STATS_PERIOD = 10000;
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 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;
private ConcurrentMap<Long, Boolean> switchSupportsVendorExtStats;
// Per port sampled (every portStatsPeriod) transmit rate
private Map<Long, Map<Short, TxRates>> txRates;
private ConcurrentMap<Long, Boolean> switchSupportsVendorExtStats;
// Per port sampled (every portStatsPeriod) transmit rate
private Map<Long, Map<Short, TxRates>> txRates;
+
+ IPluginOutConnectionService connectionPluginOutService;
+ void setIPluginOutConnectionService(IPluginOutConnectionService s) {
+ connectionPluginOutService = s;
+ }
+
+ void unsetIPluginOutConnectionService(IPluginOutConnectionService s) {
+ if (connectionPluginOutService == s) {
+ connectionPluginOutService = null;
+ }
+ }
+
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>>();
pendingStatsRequests = new LinkedBlockingQueue<StatsRequest>(getStatsQueueSize());
statisticsTimerTicks = new ConcurrentHashMap<Long, StatisticsTicks>(INITIAL_SIZE);
switchPortStatsUpdated = new LinkedBlockingQueue<Long>(INITIAL_SIZE);
switchSupportsVendorExtStats = new ConcurrentHashMap<Long, Boolean>(INITIAL_SIZE);
txRates = new HashMap<Long, Map<Short, TxRates>>(INITIAL_SIZE);
pendingStatsRequests = new LinkedBlockingQueue<StatsRequest>(getStatsQueueSize());
statisticsTimerTicks = new ConcurrentHashMap<Long, StatisticsTicks>(INITIAL_SIZE);
switchPortStatsUpdated = new LinkedBlockingQueue<Long>(INITIAL_SIZE);
switchSupportsVendorExtStats = new ConcurrentHashMap<Long, Boolean>(INITIAL_SIZE);
txRates = new HashMap<Long, Map<Short, TxRates>>(INITIAL_SIZE);
updatePortsTxRate(switchId);
} catch (InterruptedException e) {
log.warn("TX Rate Updater thread interrupted", e);
updatePortsTxRate(switchId);
} catch (InterruptedException e) {
log.warn("TX Rate Updater thread interrupted", e);
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
@SuppressWarnings("unchecked")
private List<OFStatistics> fetchStatisticsFromSwitch(Long switchId,
OFStatisticsType statsType, Object target) {
@SuppressWarnings("unchecked")
private List<OFStatistics> fetchStatisticsFromSwitch(Long switchId,
OFStatisticsType statsType, Object target) {
* 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)
*/
* 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()) {
- private List<OFStatistics> v6StatsListToOFStatsList(
- List<OFStatistics> statistics) {
+ private List<OFStatistics> v6StatsListToOFStatsList(List<OFStatistics> statistics) {
+ if (statistics == null || statistics.isEmpty()) {
+ return Collections.emptyList();
+ }
- 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>();
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));
v6statsreply.setVendorId(vendor);
log.trace("V6StatsReply: {}", v6statsreply);
length -= v6statsreply.getLength();
v6statsreply.setVendorId(vendor);
log.trace("V6StatsReply: {}", v6statsreply);
length -= v6statsreply.getLength();
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId) {
if (!portStatistics.containsKey(switchId)) {
@Override
public List<OFStatistics> getOFPortStatistics(Long switchId) {
if (!portStatistics.containsKey(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)) {
}
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)) {
@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)) {