blob: bf34437d3d3b9231aa63039d043e3f87bfa00b5a [file] [log] [blame]
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -07003 *
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.net.flow;
17
18import org.onosproject.net.DeviceId;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21/**
22 * Default implementation of table statistics entry interface.
23 */
24public final class DefaultTableStatisticsEntry implements TableStatisticsEntry {
25
26 private final DeviceId deviceId;
hjtsao1a4333c2018-10-22 11:02:00 -070027 private final TableId tableId;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070028 private final long activeFlowEntries;
29 private final long packetsLookedupCount;
30 private final long packetsMatchedCount;
hjtsao1a4333c2018-10-22 11:02:00 -070031 private final long maxSize;
32 private static final Long NOT_PRESENT = (long) -1;
33
34 /**
35 * Default table statistics constructor.
36 *
37 * @param deviceId device identifier
38 * @param tableId index table identifier
39 * @param activeFlowEntries number of active flow entries in the table
40 * @param packetsLookedupCount number of packets looked up in table
41 * @param packetsMatchedCount number of packets that hit table
42 * @deprecated since 1.15, suggest using the Builder class.
43 */
44 @Deprecated
45 public DefaultTableStatisticsEntry(DeviceId deviceId,
46 int tableId,
47 long activeFlowEntries,
48 long packetsLookedupCount,
49 long packetsMatchedCount) {
50 this.deviceId = checkNotNull(deviceId);
51 this.tableId = IndexTableId.of(tableId);
52 this.activeFlowEntries = activeFlowEntries;
53 this.packetsLookedupCount = packetsLookedupCount;
54 this.packetsMatchedCount = packetsMatchedCount;
55 this.maxSize = NOT_PRESENT;
56 }
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070057
58 /**
59 * Default table statistics constructor.
60 *
61 * @param deviceId device identifier
62 * @param tableId table identifier
63 * @param activeFlowEntries number of active flow entries in the table
64 * @param packetsLookedupCount number of packets looked up in table
65 * @param packetsMatchedCount number of packets that hit table
hjtsao1a4333c2018-10-22 11:02:00 -070066 * @param maxSize maximum size of this table
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070067 */
hjtsao1a4333c2018-10-22 11:02:00 -070068 private DefaultTableStatisticsEntry(DeviceId deviceId,
69 TableId tableId,
70 long activeFlowEntries,
71 long packetsLookedupCount,
72 long packetsMatchedCount,
73 long maxSize) {
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070074 this.deviceId = checkNotNull(deviceId);
75 this.tableId = tableId;
76 this.activeFlowEntries = activeFlowEntries;
77 this.packetsLookedupCount = packetsLookedupCount;
78 this.packetsMatchedCount = packetsMatchedCount;
hjtsao1a4333c2018-10-22 11:02:00 -070079 this.maxSize = maxSize;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070080 }
81
82 @Override
83 public String toString() {
Sho SHIMIZU8d50c8d2016-08-12 17:29:02 -070084 return "device: " + deviceId + ", " +
85 "tableId: " + this.tableId + ", " +
86 "activeEntries: " + this.activeFlowEntries + ", " +
87 "packetsLookedUp: " + this.packetsLookedupCount + ", " +
88 "packetsMatched: " + this.packetsMatchedCount;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070089 }
90
91 @Override
92 public int tableId() {
hjtsao1a4333c2018-10-22 11:02:00 -070093 return tableId.type() == TableId.Type.INDEX ? ((IndexTableId) tableId).id() : tableId.hashCode();
94 }
95
96 @Override
97 public TableId table() {
98 //TODO: this is a temporary method, should implement tableId() like this method.
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070099 return tableId;
100 }
101
102 @Override
103 public long activeFlowEntries() {
104 return activeFlowEntries;
105 }
106
107 @Override
108 public long packetsLookedup() {
109 return packetsLookedupCount;
110 }
111
112 @Override
113 public long packetsMatched() {
114 return packetsMatchedCount;
115 }
116
117 @Override
118 public DeviceId deviceId() {
119 return deviceId;
120 }
hjtsao1a4333c2018-10-22 11:02:00 -0700121
122 @Override
123 public long maxSize() {
124 return maxSize;
125 }
126
127 @Override
128 public boolean hasPacketsLookedup() {
129 return packetsLookedupCount == NOT_PRESENT ? false : true;
130 }
131
132 @Override
133 public boolean hasMaxSize() {
134 return maxSize == NOT_PRESENT ? false : true;
135 }
136
137 public static Builder builder() {
138 return new Builder();
139 }
140
141 public static final class Builder {
142 private DeviceId deviceId;
143 private TableId tableId;
144 private Long activeFlowEntries;
145 private Long packetsMatchedCount;
146 private Long packetsLookedUpCount = NOT_PRESENT;
147 private Long maxSize = NOT_PRESENT;
148
149 public Builder withDeviceId(DeviceId deviceId) {
150 this.deviceId = deviceId;
151 return this;
152 }
153
154 public Builder withTableId(TableId tableId) {
155 this.tableId = tableId;
156 return this;
157 }
158
159 public Builder withActiveFlowEntries(long activeFlowEntries) {
160 this.activeFlowEntries = activeFlowEntries;
161 return this;
162 }
163
164 public Builder withPacketsLookedUpCount(long packetsLookedUpCount) {
165 this.packetsLookedUpCount = packetsLookedUpCount;
166 return this;
167 }
168
169 public Builder withPacketsMatchedCount(long packetsMatchedCount) {
170 this.packetsMatchedCount = packetsMatchedCount;
171 return this;
172 }
173
174 public Builder withMaxSize(long maxSize) {
175 this.maxSize = maxSize;
176 return this;
177 }
178
179 public TableStatisticsEntry build() {
180 checkNotNull(deviceId, "DeviceId cannot be null");
181 checkNotNull(tableId, "TableId cannot be null");
182 checkNotNull(activeFlowEntries, "ActiveFlowEntries cannot be null");
183 checkNotNull(packetsMatchedCount, "PacketsMatchedCount cannot be null");
184
185 return new DefaultTableStatisticsEntry(deviceId, tableId, activeFlowEntries, packetsLookedUpCount,
186 packetsMatchedCount, maxSize);
187 }
188 }
189
190}