blob: e84b34300f9fb6e1b0a25e2721e1d4110cda7abc [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
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070038 * @param tableId 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
hjtsao1a4333c2018-10-22 11:02:00 -070042 * @param maxSize maximum size of this table
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070043 */
hjtsao1a4333c2018-10-22 11:02:00 -070044 private DefaultTableStatisticsEntry(DeviceId deviceId,
45 TableId tableId,
46 long activeFlowEntries,
47 long packetsLookedupCount,
48 long packetsMatchedCount,
49 long maxSize) {
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070050 this.deviceId = checkNotNull(deviceId);
51 this.tableId = tableId;
52 this.activeFlowEntries = activeFlowEntries;
53 this.packetsLookedupCount = packetsLookedupCount;
54 this.packetsMatchedCount = packetsMatchedCount;
hjtsao1a4333c2018-10-22 11:02:00 -070055 this.maxSize = maxSize;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070056 }
57
58 @Override
59 public String toString() {
Sho SHIMIZU8d50c8d2016-08-12 17:29:02 -070060 return "device: " + deviceId + ", " +
61 "tableId: " + this.tableId + ", " +
62 "activeEntries: " + this.activeFlowEntries + ", " +
63 "packetsLookedUp: " + this.packetsLookedupCount + ", " +
64 "packetsMatched: " + this.packetsMatchedCount;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070065 }
66
67 @Override
68 public int tableId() {
hjtsao1a4333c2018-10-22 11:02:00 -070069 return tableId.type() == TableId.Type.INDEX ? ((IndexTableId) tableId).id() : tableId.hashCode();
70 }
71
72 @Override
73 public TableId table() {
74 //TODO: this is a temporary method, should implement tableId() like this method.
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070075 return tableId;
76 }
77
78 @Override
79 public long activeFlowEntries() {
80 return activeFlowEntries;
81 }
82
83 @Override
84 public long packetsLookedup() {
85 return packetsLookedupCount;
86 }
87
88 @Override
89 public long packetsMatched() {
90 return packetsMatchedCount;
91 }
92
93 @Override
94 public DeviceId deviceId() {
95 return deviceId;
96 }
hjtsao1a4333c2018-10-22 11:02:00 -070097
98 @Override
99 public long maxSize() {
100 return maxSize;
101 }
102
103 @Override
104 public boolean hasPacketsLookedup() {
105 return packetsLookedupCount == NOT_PRESENT ? false : true;
106 }
107
108 @Override
109 public boolean hasMaxSize() {
110 return maxSize == NOT_PRESENT ? false : true;
111 }
112
113 public static Builder builder() {
114 return new Builder();
115 }
116
117 public static final class Builder {
118 private DeviceId deviceId;
119 private TableId tableId;
120 private Long activeFlowEntries;
121 private Long packetsMatchedCount;
122 private Long packetsLookedUpCount = NOT_PRESENT;
123 private Long maxSize = NOT_PRESENT;
124
125 public Builder withDeviceId(DeviceId deviceId) {
126 this.deviceId = deviceId;
127 return this;
128 }
129
130 public Builder withTableId(TableId tableId) {
131 this.tableId = tableId;
132 return this;
133 }
134
135 public Builder withActiveFlowEntries(long activeFlowEntries) {
136 this.activeFlowEntries = activeFlowEntries;
137 return this;
138 }
139
140 public Builder withPacketsLookedUpCount(long packetsLookedUpCount) {
141 this.packetsLookedUpCount = packetsLookedUpCount;
142 return this;
143 }
144
145 public Builder withPacketsMatchedCount(long packetsMatchedCount) {
146 this.packetsMatchedCount = packetsMatchedCount;
147 return this;
148 }
149
150 public Builder withMaxSize(long maxSize) {
151 this.maxSize = maxSize;
152 return this;
153 }
154
155 public TableStatisticsEntry build() {
156 checkNotNull(deviceId, "DeviceId cannot be null");
157 checkNotNull(tableId, "TableId cannot be null");
158 checkNotNull(activeFlowEntries, "ActiveFlowEntries cannot be null");
159 checkNotNull(packetsMatchedCount, "PacketsMatchedCount cannot be null");
160
161 return new DefaultTableStatisticsEntry(deviceId, tableId, activeFlowEntries, packetsLookedUpCount,
162 packetsMatchedCount, maxSize);
163 }
164 }
165
166}