2 * Copyright IBM Corporation, 2013. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
10 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
11 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
12 import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
26 import java.math.BigInteger;
27 import java.util.ArrayList;
28 import java.util.List;
31 * Class is an utility class for converting flow related statistics messages coming from openflow
32 * switch to MD-SAL messages.
33 * @author avishnoi@in.ibm.com
36 public class FlowStatsResponseConvertor {
39 * Method returns the list of MD-SAL format flow statistics, converted flow Openflow
40 * specific flow statistics.
44 public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats, BigInteger datapathid, OpenflowVersion ofVersion){
46 List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
48 for(FlowStats flowStats : allFlowStats){
49 convertedSALFlowStats.add(toSALFlowStats(flowStats, datapathid, ofVersion));
52 return convertedSALFlowStats;
56 * Method convert Openflow switch specific flow statistics to the MD-SAL format
61 public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats, BigInteger datapathid, OpenflowVersion ofVersion){
62 FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
63 salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
64 if(flowStats.getCookie() != null) {
65 salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
67 DurationBuilder time = new DurationBuilder();
68 time.setSecond(new Counter32(flowStats.getDurationSec()));
69 time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
70 salFlowStatsBuilder.setDuration(time.build());
72 salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
73 salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
74 salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
75 salFlowStatsBuilder.setPriority(flowStats.getPriority());
76 salFlowStatsBuilder.setTableId(flowStats.getTableId());
77 if(flowStats.getMatchV10() != null){
78 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(),datapathid, OpenflowVersion.OF10));
79 if(flowStats.getAction() != null && flowStats.getAction().size()!=0){
80 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction(), ofVersion));
83 if(flowStats.getMatch() != null){
84 MatchBuilder matchBuilder = MatchConvertorImpl.fromOFMatchToSALMatch(flowStats.getMatch(),datapathid, ofVersion);
86 AugmentTuple<Match> matchExtensionWrap =
87 MatchExtensionHelper.processAllExtensions(
88 flowStats.getMatch().getMatchEntries(), ofVersion, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
89 if (matchExtensionWrap != null) {
90 matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
94 salFlowStatsBuilder.setMatch(matchBuilder.build());
95 salFlowStatsBuilder.setFlags(
96 new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
97 flowStats.getFlags().isOFPFFRESETCOUNTS(),
98 flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
99 flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
100 flowStats.getFlags().isOFPFFSENDFLOWREM()));
102 if(flowStats.getInstruction()!= null){
103 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstruction(), ofVersion));
106 return salFlowStatsBuilder.build();