2 * Copyright (c) 2013, 2015 IBM Corporation and others. 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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
16 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
17 import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
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.
41 * @param allFlowStats all flow stats
42 * @param datapathid datapath id
43 * @param ofVersion openflow version
44 * @return list of flow and statistics mapping
46 public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats, BigInteger datapathid, OpenflowVersion ofVersion){
48 List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
50 for(FlowStats flowStats : allFlowStats){
51 convertedSALFlowStats.add(toSALFlowStats(flowStats, datapathid, ofVersion));
54 return convertedSALFlowStats;
58 * Method convert Openflow switch specific flow statistics to the MD-SAL format
60 * @param flowStats flow statis
61 * @param datapathid datapath id
62 * @param ofVersion openflow version
63 * @return flow and statistics map
65 public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats, BigInteger datapathid, OpenflowVersion ofVersion){
66 FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
67 salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
68 if(flowStats.getCookie() != null) {
69 salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
71 DurationBuilder time = new DurationBuilder();
72 time.setSecond(new Counter32(flowStats.getDurationSec()));
73 time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
74 salFlowStatsBuilder.setDuration(time.build());
76 salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
77 salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
78 salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
79 salFlowStatsBuilder.setPriority(flowStats.getPriority());
80 salFlowStatsBuilder.setTableId(flowStats.getTableId());
81 if(flowStats.getMatchV10() != null){
82 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(), datapathid, OpenflowVersion.OF10).build());
83 if(flowStats.getAction() != null && flowStats.getAction().size()!=0){
84 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction(), ofVersion));
87 if(flowStats.getMatch() != null){
88 MatchBuilder matchBuilder = MatchConvertorImpl.fromOFMatchToSALMatch(flowStats.getMatch(),datapathid, ofVersion);
90 AugmentTuple<Match> matchExtensionWrap =
91 MatchExtensionHelper.processAllExtensions(
92 flowStats.getMatch().getMatchEntry(), ofVersion, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
93 if (matchExtensionWrap != null) {
94 matchBuilder.addAugmentation(matchExtensionWrap.getAugmentationClass(), matchExtensionWrap.getAugmentationObject());
98 salFlowStatsBuilder.setMatch(matchBuilder.build());
99 salFlowStatsBuilder.setFlags(
100 new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
101 flowStats.getFlags().isOFPFFRESETCOUNTS(),
102 flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
103 flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
104 flowStats.getFlags().isOFPFFSENDFLOWREM()));
106 if(flowStats.getInstruction()!= null){
107 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstruction(), ofVersion));
110 return salFlowStatsBuilder.build();