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.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
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.model.statistics.types.rev130925.duration.DurationBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
25 * Class is an utility class for converting flow related statistics messages coming from openflow
26 * switch to MD-SAL messages.
27 * @author avishnoi@in.ibm.com
30 public class FlowStatsResponseConvertor {
33 * Method returns the list of MD-SAL format flow statistics, converted flow Openflow
34 * specific flow statistics.
38 public List<FlowAndStatisticsMapList> toSALFlowStatsList(List<FlowStats> allFlowStats,BigInteger datapathid){
40 List<FlowAndStatisticsMapList> convertedSALFlowStats = new ArrayList<FlowAndStatisticsMapList>();
42 for(FlowStats flowStats : allFlowStats){
43 convertedSALFlowStats.add(toSALFlowStats(flowStats, datapathid));
46 return convertedSALFlowStats;
50 * Method convert Openflow switch specific flow statistics to the MD-SAL format
55 public FlowAndStatisticsMapList toSALFlowStats(FlowStats flowStats,BigInteger datapathid){
56 FlowAndStatisticsMapListBuilder salFlowStatsBuilder = new FlowAndStatisticsMapListBuilder();
57 salFlowStatsBuilder.setByteCount(new Counter64(flowStats.getByteCount()));
58 salFlowStatsBuilder.setCookie(new FlowCookie(flowStats.getCookie()));
60 DurationBuilder time = new DurationBuilder();
61 time.setSecond(new Counter32(flowStats.getDurationSec()));
62 time.setNanosecond(new Counter32(flowStats.getDurationNsec()));
63 salFlowStatsBuilder.setDuration(time.build());
65 salFlowStatsBuilder.setHardTimeout(flowStats.getHardTimeout());
66 salFlowStatsBuilder.setIdleTimeout(flowStats.getIdleTimeout());
67 salFlowStatsBuilder.setPacketCount(new Counter64(flowStats.getPacketCount()));
68 salFlowStatsBuilder.setPriority(flowStats.getPriority());
69 salFlowStatsBuilder.setTableId(flowStats.getTableId());
70 if(flowStats.getMatchV10() != null){
71 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(),datapathid));
72 if(flowStats.getAction().size()!=0){
73 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction()));
76 if(flowStats.getMatch() != null){
77 salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchToSALMatch(flowStats.getMatch(),datapathid));
78 salFlowStatsBuilder.setFlags(
79 new FlowModFlags(flowStats.getFlags().isOFPFFCHECKOVERLAP(),
80 flowStats.getFlags().isOFPFFRESETCOUNTS(),
81 flowStats.getFlags().isOFPFFNOPKTCOUNTS(),
82 flowStats.getFlags().isOFPFFNOBYTCOUNTS(),
83 flowStats.getFlags().isOFPFFSENDFLOWREM()));
85 if(flowStats.getInstruction()!= null){
86 salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.toSALInstruction(flowStats.getInstruction()));
89 return salFlowStatsBuilder.build();