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 java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
23 * Class is an utility class for converting flow related statistics messages coming from openflow
24 * switch to MD-SAL messages.
25 * @author avishnoi@in.ibm.com
28 public class FlowStatsResponseConvertor {
31 * Method returns the list of MD-SAL format flow statistics, converted flow Openflow
32 * specific flow statistics.
36 public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats){
38 List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
40 for(FlowStats flowStats : allFlowStats){
41 convertedSALFlowStats.add(toSALFlowStats(flowStats));
44 return convertedSALFlowStats;
48 * Method convert Openflow switch specific flow statistics to the MD-SAL format
53 public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats){
54 FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
55 salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
56 salFlowStatsBuilder.setCookie(flowStats.getCookie());
58 DurationBuilder time = new DurationBuilder();
59 time.setSecond(new Counter32(flowStats.getDurationSec()));
60 time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
61 salFlowStatsBuilder.setDuration(time.build());
63 salFlowStatsBuilder.setFlags(
64 new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
65 flowStats.getFlags().isOFPFFRESETCOUNTS(),
66 flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
67 flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
68 flowStats.getFlags().isOFPFFSENDFLOWREM()));
70 salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
71 salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
72 salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
73 salFlowStatsBuilder.setPriority(flowStats.getPriority());
74 salFlowStatsBuilder.setTableId(flowStats.getTableId());
75 if(flowStats.getMatchV10() != null){
76 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10()));
78 if(flowStats.getMatch() != null){
79 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchToSALMatch(flowStats.getMatch()));
81 if(flowStats.getInstructions()!= null){
82 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstructions()));
85 return salFlowStatsBuilder.build();