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.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
11 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
21 import java.math.BigInteger;
22 import java.util.ArrayList;
23 import java.util.List;
26 * Class is an utility class for converting flow related statistics messages coming from openflow
27 * switch to MD-SAL messages.
28 * @author avishnoi@in.ibm.com
31 public class FlowStatsResponseConvertor {
34 * Method returns the list of MD-SAL format flow statistics, converted flow Openflow
35 * specific flow statistics.
39 public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats, BigInteger datapathid, OpenflowVersion ofVersion){
41 List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
43 for(FlowStats flowStats : allFlowStats){
44 convertedSALFlowStats.add(toSALFlowStats(flowStats, datapathid, ofVersion));
47 return convertedSALFlowStats;
51 * Method convert Openflow switch specific flow statistics to the MD-SAL format
56 public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats, BigInteger datapathid, OpenflowVersion ofVersion){
57 FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
58 salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
59 salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
61 DurationBuilder time = new DurationBuilder();
62 time.setSecond(new Counter32(flowStats.getDurationSec()));
63 time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
64 salFlowStatsBuilder.setDuration(time.build());
66 salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
67 salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
68 salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
69 salFlowStatsBuilder.setPriority(flowStats.getPriority());
70 salFlowStatsBuilder.setTableId(flowStats.getTableId());
71 if(flowStats.getMatchV10() != null){
72 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(),datapathid, OpenflowVersion.OF10));
73 if(flowStats.getAction().size()!=0){
74 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction(), ofVersion));
77 if(flowStats.getMatch() != null){
78 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchToSALMatch(flowStats.getMatch(),datapathid, ofVersion));
79 salFlowStatsBuilder.setFlags(
80 new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
81 flowStats.getFlags().isOFPFFRESETCOUNTS(),
82 flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
83 flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
84 flowStats.getFlags().isOFPFFSENDFLOWREM()));
86 if(flowStats.getInstruction()!= null){
87 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstruction(), ofVersion));
90 return salFlowStatsBuilder.build();