blob: dfea3901dbd16745da467def46a15ba6430d2e21 [file] [log] [blame]
Cem Türker3baff672017-10-12 15:09:01 +03001/*
2 * Copyright 2014-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.provider.of.flow.util;
17
18import org.projectfloodlight.openflow.protocol.stat.Stat;
19import org.projectfloodlight.openflow.protocol.stat.StatField;
20import org.projectfloodlight.openflow.types.U32;
21import org.projectfloodlight.openflow.types.U64;
22
23/**
24 * FlowStatParser helps to parse OXS which is added in OPF 1.5.
25 */
26public final class FlowStatParser {
27 private final Stat stat;
28
29
30 private long duration;
31 private long idleTime;
32 private long flowCount;
33 private long packetCount;
34 private long byteCount;
35 private boolean isDurationReceived;
36
37 public FlowStatParser(Stat stat) {
38 this.stat = stat;
39 parseStats();
40 }
41
42 public Stat getStat() {
43 return stat;
44 }
45
46 private void parseStats() {
47 U64 durationOfValue = this.stat.get(StatField.DURATION);
48 U64 byteCountOfValue = this.stat.get(StatField.BYTE_COUNT);
49 U32 flowCountOfValue = this.stat.get(StatField.FLOW_COUNT);
50 U64 idleTimeOfValue = this.stat.get(StatField.IDLE_TIME);
51 U64 packetCountOfValue = this.stat.get(StatField.PACKET_COUNT);
52
53 isDurationReceived = durationOfValue != null;
54 duration = durationOfValue != null ? durationOfValue.getValue() : 0;
55 byteCount = byteCountOfValue != null ? byteCountOfValue.getValue() : 0;
56 idleTime = idleTimeOfValue != null ? idleTimeOfValue.getValue() : 0;
57 flowCount = flowCountOfValue != null ? flowCountOfValue.getValue() : 0;
58 packetCount = packetCountOfValue != null ? packetCountOfValue.getValue() : 0;
59 }
60
61
62 public long getByteCount() {
63 return byteCount;
64 }
65
66 public long getDuration() {
67 return duration;
68 }
69
70 public long getFlowCount() {
71 return flowCount;
72 }
73
74 public long getPacketCount() {
75 return packetCount;
76 }
77
78 public long getIdleTime() {
79 return idleTime;
80 }
81
82 public boolean isDurationReceived() {
83 return isDurationReceived;
84 }
85}