*/
package org.opendaylight.openflowplugin.impl.statistics;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
/**
* Class converts multipart reply messages to the notification objects defined
private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
- public List<DataObject> translate(DeviceContext deviceContext, OfHeader msg) {
+ public List<DataObject> translate(final DeviceContext deviceContext, final OfHeader msg) {
- List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
+ List<DataObject> listDataObject = new ArrayList<>();
OpenflowVersion ofVersion = OpenflowVersion.get(deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
final FeaturesReply features = deviceContext.getPrimaryConnectionContext().getFeatures();
if (msg instanceof MultipartReplyMessage) {
MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
- NodeId node = this.nodeIdFromDatapathId(features.getDatapathId());
+ NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(features.getDatapathId());
switch (mpReply.getType()) {
case OFPMPFLOW: {
- logger.debug("Received flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
FlowsStatisticsUpdateBuilder message = new FlowsStatisticsUpdateBuilder();
message.setId(node);
message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), features.getDatapathId(), ofVersion));
- logger.debug("Converted flow statistics : {}", message.build().toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPAGGREGATE: {
- logger.debug("Received aggregate flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
AggregateFlowStatisticsUpdateBuilder message = new AggregateFlowStatisticsUpdateBuilder();
message.setId(node);
message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
message.setPacketCount(new Counter64(replyBody.getPacketCount()));
message.setFlowCount(new Counter32(replyBody.getFlowCount()));
- logger.debug("Converted aggregate flow statistics : {}", message.build().toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPPORTSTATS: {
- logger.debug("Received port statistics multipart response");
NodeConnectorStatisticsUpdateBuilder message = new NodeConnectorStatisticsUpdateBuilder();
message.setId(node);
statsBuilder.setPackets(packetsBuilder.build());
DurationBuilder durationBuilder = new DurationBuilder();
- if (portStats.getDurationSec() != null)
+ if (portStats.getDurationSec() != null) {
durationBuilder.setSecond(new Counter32(portStats.getDurationSec()));
- if (portStats.getDurationNsec() != null)
+ }
+ if (portStats.getDurationNsec() != null) {
durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec()));
+ }
statsBuilder.setDuration(durationBuilder.build());
statsBuilder.setCollisionCount(portStats.getCollisions());
statsBuilder.setKey(new NodeConnectorStatisticsAndPortNumberMapKey(statsBuilder.getNodeConnectorId()));
}
message.setNodeConnectorStatisticsAndPortNumberMap(statsMap);
- logger.debug("Converted ports statistics : {}", message.build().toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPGROUP: {
- logger.debug("Received group statistics multipart reponse");
GroupStatisticsUpdatedBuilder message = new GroupStatisticsUpdatedBuilder();
message.setId(node);
message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
message.setGroupStats(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
- logger.debug("Converted group statistics : {}", message.toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPGROUPDESC: {
- logger.debug("Received group description statistics multipart reponse");
GroupDescStatsUpdatedBuilder message = new GroupDescStatsUpdatedBuilder();
message.setId(node);
message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion));
- logger.debug("Converted group statistics : {}", message.toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPGROUPFEATURES: {
- logger.debug("Received group features multipart reponse");
GroupFeaturesUpdatedBuilder message = new GroupFeaturesUpdatedBuilder();
message.setId(node);
message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
return listDataObject;
}
case OFPMPMETER: {
- logger.debug("Received meter statistics multipart reponse");
MeterStatisticsUpdatedBuilder message = new MeterStatisticsUpdatedBuilder();
message.setId(node);
message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE());
return listDataObject;
}
case OFPMPMETERCONFIG: {
- logger.debug("Received meter config statistics multipart reponse");
MeterConfigStatsUpdatedBuilder message = new MeterConfigStatsUpdatedBuilder();
message.setId(node);
return listDataObject;
}
case OFPMPMETERFEATURES: {
- logger.debug("Received meter features multipart reponse");
//Convert OF message and send it to SAL listener
MeterFeaturesUpdatedBuilder message = new MeterFeaturesUpdatedBuilder();
message.setId(node);
return listDataObject;
}
case OFPMPTABLE: {
- logger.debug("Received flow table statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+");
FlowTableStatisticsUpdateBuilder message = new FlowTableStatisticsUpdateBuilder();
message.setId(node);
}
message.setFlowTableAndStatisticsMap(salFlowStats);
-
- logger.debug("Converted flow table statistics : {}", message.build().toString());
listDataObject.add(message.build());
return listDataObject;
}
case OFPMPQUEUE: {
- logger.debug("Received queue statistics multipart response");
QueueStatisticsUpdateBuilder message = new QueueStatisticsUpdateBuilder();
message.setId(node);
}
message.setQueueIdAndStatisticsMap(statsMap);
- logger.debug("Converted queue statistics : {}", message.build().toString());
listDataObject.add(message.build());
return listDataObject;
}
return listDataObject;
}
- private NodeId nodeIdFromDatapathId(BigInteger datapathId) {
+ private static NodeId nodeIdFromDatapathId(final BigInteger datapathId) {
String current = datapathId.toString();
return new NodeId("openflow:" + current);
}
- private TransactionId generateTransactionId(Long xid) {
- String stringXid = xid.toString();
- BigInteger bigIntXid = new BigInteger(stringXid);
+ private static TransactionId generateTransactionId(final Long xid) {
+ BigInteger bigIntXid = BigInteger.valueOf(xid);
return new TransactionId(bigIntXid);
-
}
- /*
+ /*
* Method returns the bitmap of actions supported by each group.
- * TODO: My recommendation would be, its good to have a respective model of
- * 'type bits', which will generate a class where all these flags will eventually
- * be stored as boolean. It will be convenient for application to check the
- * supported action, rather then doing bitmap operation.
+ *
* @param actionsSupported
* @return
*/
- private List<Long> getGroupActionsSupportBitmap(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
+ static List<Long> getGroupActionsSupportBitmap(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType> actionsSupported) {
List<Long> supportActionByGroups = new ArrayList<Long>();
for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported) {
long supportActionBitmap = 0;