*/
package org.opendaylight.openflowplugin.impl.statistics;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterStatsResponseConvertor;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.BytesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.PacketsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
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 BigInteger datapathId, final short version, final OfHeader msg) {
- List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>();
+ List<DataObject> listDataObject = new ArrayList<>();
- OpenflowVersion ofVersion = OpenflowVersion.get(deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+ OpenflowVersion ofVersion = OpenflowVersion.get(version);
- final FeaturesReply features = deviceContext.getPrimaryConnectionContext().getFeatures();
if (msg instanceof MultipartReplyMessage) {
MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
- NodeId node = this.nodeIdFromDatapathId(features.getDatapathId());
+ NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(datapathId);
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());
message.setTransactionId(generateTransactionId(mpReply.getXid()));
MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
- message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), features.getDatapathId(), ofVersion));
+ message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), datapathId, 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);
NodeConnectorStatisticsAndPortNumberMapBuilder statsBuilder =
new NodeConnectorStatisticsAndPortNumberMapBuilder();
statsBuilder.setNodeConnectorId(
- InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+ InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
portStats.getPortNo(), ofVersion));
BytesBuilder bytesBuilder = new BytesBuilder();
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);
QueueIdAndStatisticsMapBuilder statsBuilder =
new QueueIdAndStatisticsMapBuilder();
statsBuilder.setNodeConnectorId(
- InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+ InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
queueStats.getPortNo(), ofVersion));
statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors()));
statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes()));
statsBuilder.setDuration(durationBuilder.build());
statsBuilder.setQueueId(new QueueId(queueStats.getQueueId()));
- statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+ statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
queueStats.getPortNo(), ofVersion));
statsMap.add(statsBuilder.build());
}
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;