import java.util.List;
import java.util.Optional;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
+import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
+import org.opendaylight.openflowplugin.impl.util.GroupUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
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.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectLiveness;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdatedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdatedBuilder;
protected static final Logger logger = LoggerFactory
.getLogger(SinglePurposeMultipartReplyTranslator.class);
+ private final ConvertorExecutor convertorExecutor;
- private static FlowStatsResponseConvertor flowStatsConvertor = new FlowStatsResponseConvertor();
- private static GroupStatsResponseConvertor groupStatsConvertor = new GroupStatsResponseConvertor();
-
+ public SinglePurposeMultipartReplyTranslator(ConvertorExecutor convertorExecutor) {
+ this.convertorExecutor = convertorExecutor;
+ }
public List<DataObject> translate(final BigInteger datapathId, final short version, final OfHeader msg) {
MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
OpenflowVersion ofVersion = OpenflowVersion.get(version);
NodeId node = nodeIdFromDatapathId(datapathId);
+ VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(version);
+ data.setDatapathId(datapathId);
- translateFlow(listDataObject, mpReply, node, ofVersion, datapathId);
+ translateFlow(listDataObject, mpReply, node, data);
translateAggregate(listDataObject, mpReply, node);
translatePortStats(listDataObject, mpReply, node, ofVersion, datapathId);
- translateGroup(listDataObject, mpReply, node);
- translateGroupDesc(listDataObject, mpReply, node, ofVersion);
+ translateGroup(listDataObject, mpReply, node, data);
+ translateGroupDesc(listDataObject, mpReply, node, data);
translateGroupFeatures(listDataObject, mpReply, node);
- translateMeter(listDataObject, mpReply, node);
- translateMeterConfig(listDataObject, mpReply, node);
+ translateMeter(listDataObject, mpReply, node, data);
+ translateMeterConfig(listDataObject, mpReply, node, data);
translateMeterFeatures(listDataObject, mpReply, node);
translateTable(listDataObject, mpReply, node);
translateQueue(listDataObject, mpReply, node, ofVersion, datapathId);
return listDataObject;
}
- private static void translateFlow(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node,
- final OpenflowVersion ofVersion,
- final BigInteger datapathId) {
+ private void translateFlow(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node, VersionDatapathIdConvertorData data) {
if (!MultipartType.OFPMPFLOW.equals(mpReply.getType())) {
return;
}
+ FlowStatsResponseConvertorData flowData = new FlowStatsResponseConvertorData(data.getVersion());
+ flowData.setDatapathId(data.getDatapathId());
+ flowData.setMatchPath(MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
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(), datapathId, ofVersion));
+ final Optional<List<FlowAndStatisticsMapList>> flowAndStatisticsMapLists =
+ convertorExecutor.convert(replyBody.getFlowStats(), flowData);
+
+ message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
- private static void translateAggregate(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node) {
+ private void translateAggregate(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node) {
if (!MultipartType.OFPMPAGGREGATE.equals(mpReply.getType())) {
return;
}
listDataObject.add(message.build());
}
- private static void translatePortStats(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node,
- final OpenflowVersion ofVersion,
- final BigInteger datapathId) {
+ private void translatePortStats(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node,
+ final OpenflowVersion ofVersion,
+ final BigInteger datapathId) {
if (!MultipartType.OFPMPPORTSTATS.equals(mpReply.getType())) {
return;
}
listDataObject.add(message.build());
}
- private static void translateGroup(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node) {
+ private void translateGroup(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node,
+ final VersionDatapathIdConvertorData data) {
if (!MultipartType.OFPMPGROUP.equals(mpReply.getType())) {
return;
}
message.setTransactionId(generateTransactionId(mpReply.getXid()));
MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody();
MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup();
- message.setGroupStats(groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats()));
+ final Optional<List<GroupStats>> groupStatsList = convertorExecutor.convert(
+ replyBody.getGroupStats(), data);
+
+ message.setGroupStats(groupStatsList.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
- private static void translateGroupDesc(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node,
- final OpenflowVersion ofVersion) {
+ private void translateGroupDesc(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node,
+ final VersionDatapathIdConvertorData data) {
if (!MultipartType.OFPMPGROUPDESC.equals(mpReply.getType())) {
return;
}
MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase) mpReply.getMultipartReplyBody();
MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc();
- message.setGroupDescStats(groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion));
+ final Optional<List<GroupDescStats>> groupDescStatsList = convertorExecutor.convert(
+ replyBody.getGroupDesc(), data);
+
+ message.setGroupDescStats(groupDescStatsList.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
- private static void translateGroupFeatures(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node) {
+ private void translateGroupFeatures(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node) {
if (!MultipartType.OFPMPGROUPFEATURES.equals(mpReply.getType())) {
return;
}
message.setGroupCapabilitiesSupported(supportedCapabilities);
- message.setActions(getGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
+ message.setActions(GroupUtil.extractGroupActionsSupportBitmap(replyBody.getActionsBitmap()));
listDataObject.add(message.build());
}
- private static void translateMeter(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node) {
+ private void translateMeter(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node,
+ final VersionDatapathIdConvertorData data) {
if (!MultipartType.OFPMPMETER.equals(mpReply.getType())) {
return;
}
MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody();
MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter();
final Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats>> meterStatsList =
- ConvertorManager.getInstance().convert(replyBody.getMeterStats());
+ convertorExecutor.convert(replyBody.getMeterStats(), data);
message.setMeterStats(meterStatsList.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
- private static void translateMeterConfig(final List<DataObject> listDataObject,
- final MultipartReplyMessage mpReply,
- final NodeId node) {
+ private void translateMeterConfig(final List<DataObject> listDataObject,
+ final MultipartReplyMessage mpReply,
+ final NodeId node,
+ final VersionDatapathIdConvertorData data) {
if (!MultipartType.OFPMPMETERCONFIG.equals(mpReply.getType())) {
return;
}
MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase) mpReply.getMultipartReplyBody();
MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig();
- final Optional<List<MeterConfigStats>> meterConfigStatsList = ConvertorManager.getInstance().convert(replyBody.getMeterConfig());
+ final Optional<List<MeterConfigStats>> meterConfigStatsList = convertorExecutor.convert(replyBody.getMeterConfig(), data);
message.setMeterConfigStats(meterConfigStatsList.orElse(Collections.emptyList()));
listDataObject.add(message.build());
}
- private static void translateMeterFeatures(final List<DataObject> listDataObject,
+ private void translateMeterFeatures(final List<DataObject> listDataObject,
final MultipartReplyMessage mpReply,
final NodeId node) {
if (!MultipartType.OFPMPMETERFEATURES.equals(mpReply.getType())) {
listDataObject.add(message.build());
}
- private static void translateTable(final List<DataObject> listDataObject,
+ private void translateTable(final List<DataObject> listDataObject,
final MultipartReplyMessage mpReply,
final NodeId node) {
if (!MultipartType.OFPMPTABLE.equals(mpReply.getType())) {
listDataObject.add(message.build());
}
- private static void translateQueue(final List<DataObject> listDataObject,
+ private void translateQueue(final List<DataObject> listDataObject,
final MultipartReplyMessage mpReply,
final NodeId node,
final OpenflowVersion ofVersion,
BigInteger bigIntXid = BigInteger.valueOf(xid);
return new TransactionId(bigIntXid);
}
-
- /*
- * Method returns the bitmap of actions supported by each group.
- *
- * @param actionsSupported
- * @return
- */
- 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;
- supportActionBitmap |= supportedActions.isOFPATOUTPUT() ? (1 << 0) : 0;
- supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT() ? (1 << 11) : 0;
- supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN() ? (1 << 12) : 0;
- supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL() ? (1 << 15) : 0;
- supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL() ? (1 << 16) : 0;
- supportActionBitmap |= supportedActions.isOFPATPUSHVLAN() ? (1 << 17) : 0;
- supportActionBitmap |= supportedActions.isOFPATPOPVLAN() ? (1 << 18) : 0;
- supportActionBitmap |= supportedActions.isOFPATPUSHMPLS() ? (1 << 19) : 0;
- supportActionBitmap |= supportedActions.isOFPATPOPMPLS() ? (1 << 20) : 0;
- supportActionBitmap |= supportedActions.isOFPATSETQUEUE() ? (1 << 21) : 0;
- supportActionBitmap |= supportedActions.isOFPATGROUP() ? (1 << 22) : 0;
- supportActionBitmap |= supportedActions.isOFPATSETNWTTL() ? (1 << 23) : 0;
- supportActionBitmap |= supportedActions.isOFPATDECNWTTL() ? (1 << 24) : 0;
- supportActionBitmap |= supportedActions.isOFPATSETFIELD() ? (1 << 25) : 0;
- supportActionBitmap |= supportedActions.isOFPATPUSHPBB() ? (1 << 26) : 0;
- supportActionBitmap |= supportedActions.isOFPATPOPPBB() ? (1 << 27) : 0;
- supportActionByGroups.add(Long.valueOf(supportActionBitmap));
- }
- return supportActionByGroups;
- }
-
}