blob: aa85d9bd3b1edc4dba85767b53a2bf892c1020da [file] [log] [blame]
karthik197739b84a02024-03-02 18:25:10 +05301/*
2 * Copyright 2024-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.sflow;
17
18import com.google.common.base.MoreObjects;
karthik1977f1065972024-03-16 15:21:57 +053019import java.nio.ByteBuffer;
20import org.onlab.packet.BasePacket;
21import org.onlab.packet.Deserializer;
22
23import java.util.function.BiPredicate;
karthik197739b84a02024-03-02 18:25:10 +053024
25/**
26 * Represents VG counters for network interfaces.
27 */
karthik1977f1065972024-03-16 15:21:57 +053028public final class VgCounter extends BasePacket {
29
30 public static final int VG_COUNTER_LENGTH = 80;
karthik197739b84a02024-03-02 18:25:10 +053031
32 private InterfaceCounter generic;
33 private int dot12InHighPriorityFrames;
34 private long dot12InHighPriorityOctets;
35 private int dot12InNormPriorityFrames;
36 private long dot12InNormPriorityOctets;
37 private int dot12InIpmErrors;
38 private int dot12InOversizeFrameErrors;
39 private int dot12InDataErrors;
40 private int dot12InNullAddressedFrames;
41 private int dot12OutHighPriorityFrames;
42 private long dot12OutHighPriorityOctets;
43 private int dot12TransitionIntoTrainings;
44 private long dot12HCInHighPriorityOctets;
45 private long dot12HCInNormPriorityOctets;
46 private long dot12HCOutHighPriorityOctets;
47
48 private VgCounter(Builder builder) {
49 this.generic = builder.generic;
50 this.dot12InHighPriorityFrames = builder.dot12InHighPriorityFrames;
51 this.dot12InHighPriorityOctets = builder.dot12InHighPriorityOctets;
52 this.dot12InNormPriorityFrames = builder.dot12InNormPriorityFrames;
53 this.dot12InNormPriorityOctets = builder.dot12InNormPriorityOctets;
54 this.dot12InIpmErrors = builder.dot12InIpmErrors;
55 this.dot12InOversizeFrameErrors = builder.dot12InOversizeFrameErrors;
56 this.dot12InDataErrors = builder.dot12InDataErrors;
57 this.dot12InNullAddressedFrames = builder.dot12InNullAddressedFrames;
58 this.dot12OutHighPriorityFrames = builder.dot12OutHighPriorityFrames;
59 this.dot12OutHighPriorityOctets = builder.dot12OutHighPriorityOctets;
60 this.dot12TransitionIntoTrainings = builder.dot12TransitionIntoTrainings;
61 this.dot12HCInHighPriorityOctets = builder.dot12HCInHighPriorityOctets;
62 this.dot12HCInNormPriorityOctets = builder.dot12HCInNormPriorityOctets;
63 this.dot12HCOutHighPriorityOctets = builder.dot12HCOutHighPriorityOctets;
64
65 }
66
67 /**
68 * Gets the generic interface counter.
69 *
70 * @return generic interface counter.
71 */
72 public InterfaceCounter getGeneric() {
73 return generic;
74 }
75
76 /**
77 * Gets the count of high priority frames.
78 *
79 * @return count of high priority frames.
80 */
81 public int getDot12InHighPriorityFrames() {
82 return dot12InHighPriorityFrames;
83 }
84
85 /**
86 * Gets the count of high priority octets.
87 *
88 * @return high priority octets.
89 */
90 public long getDot12InHighPriorityOctets() {
91 return dot12InHighPriorityOctets;
92 }
93
94 /**
95 * Gets the count of normal priority frames.
96 *
97 * @return count of normal priority frames.
98 */
99 public int getDot12InNormPriorityFrames() {
100 return dot12InNormPriorityFrames;
101 }
102
103 /**
104 * Gets the count of normal priority octets.
105 *
106 * @return count of normal priority octets.
107 */
108 public long getDot12InNormPriorityOctets() {
109 return dot12InNormPriorityOctets;
110 }
111
112 /**
113 * Gets the count of ipm errors.
114 *
115 * @return count of ipm errors.
116 */
117 public int getDot12InIpmErrors() {
118 return dot12InIpmErrors;
119 }
120
121 /**
122 * Gets the count of over size frame errors.
123 *
124 * @return count of over size frame errors.
125 */
126 public int getDot12InOversizeFrameErrors() {
127 return dot12InOversizeFrameErrors;
128 }
129
130 /**
131 * Gets the count of in data errors.
132 *
133 * @return count of in data errors.
134 */
135 public int getDot12InDataErrors() {
136 return dot12InDataErrors;
137 }
138
139 /**
140 * Gets the count of in null addressed frames.
141 *
142 * @return count of in null addressed frames.
143 */
144 public int getDot12InNullAddressedFrames() {
145 return dot12InNullAddressedFrames;
146 }
147
148 /**
149 * Gets the count of out high priority frames.
150 *
151 * @return count of out high priority frames.
152 */
153 public int getDot12OutHighPriorityFrames() {
154 return dot12OutHighPriorityFrames;
155 }
156
157 /**
158 * Gets the count of out high priority octets.
159 *
160 * @return count of out high priority octets.
161 */
162 public long getDot12OutHighPriorityOctets() {
163 return dot12OutHighPriorityOctets;
164 }
165
166 /**
167 * Gets the count of transition.
168 *
169 * @return count of transition.
170 */
171 public int getDot12TransitionIntoTrainings() {
172 return dot12TransitionIntoTrainings;
173 }
174
175 /**
176 * Gets the count of high priority octets.
177 *
178 * @return count of high priority octets.
179 */
180 public long getDot12HCInHighPriorityOctets() {
181 return dot12HCInHighPriorityOctets;
182 }
183
184 /**
185 * Gets the count of in normal priority octets.
186 *
187 * @return count of in normal priority octets.
188 */
189 public long getDot12HCInNormPriorityOctets() {
190 return dot12HCInNormPriorityOctets;
191 }
192
193 /**
194 * Gets the count of out high priority octets.
195 *
196 * @return count of out high priority octets.
197 */
198 public long getDot12HCOutHighPriorityOctets() {
199 return dot12HCOutHighPriorityOctets;
200 }
201
202 @Override
203 public String toString() {
204 return MoreObjects.toStringHelper(getClass())
205 .add("generic", generic)
206 .add("dot12InHighPriorityFrames", dot12InHighPriorityFrames)
207 .add("dot12InHighPriorityOctets", dot12InHighPriorityOctets)
208 .add("dot12InNormPriorityFrames", dot12InNormPriorityFrames)
209 .add("dot12InNormPriorityOctets", dot12InNormPriorityOctets)
210 .add("dot12InIPMErrors", dot12InIpmErrors)
211 .add("dot12InOversizeFrameErrors", dot12InOversizeFrameErrors)
212 .add("dot12InDataErrors", dot12InDataErrors)
213 .add("dot12InNullAddressedFrames", dot12InNullAddressedFrames)
214 .add("dot12OutHighPriorityFrames", dot12OutHighPriorityFrames)
215 .add("dot12OutHighPriorityOctets", dot12OutHighPriorityOctets)
216 .add("dot12TransitionIntoTrainings", dot12TransitionIntoTrainings)
217 .add("dot12HCInHighPriorityOctets", dot12HCInHighPriorityOctets)
218 .add("dot12HCInNormPriorityOctets", dot12HCInNormPriorityOctets)
219 .add("dot12HCOutHighPriorityOctets", dot12HCOutHighPriorityOctets)
220 .toString();
221 }
222
223 /**
karthik1977f1065972024-03-16 15:21:57 +0530224 * Deserializer function for sFlow interface vg counter.
225 *
226 * @return deserializer function
227 */
228 public static Deserializer<VgCounter> deserializer() {
229 return (data, offset, length) -> {
230
231 BiPredicate<ByteBuffer, Integer> isValidBuffer = (b, l)
232 -> b.hasRemaining() && b.remaining() >= l;
233
234 ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
235 byte[] ifCounterBytes;
236 if (!isValidBuffer.test(bb, InterfaceCounter.INTERFACE_COUNTER_LENGTH)) {
237 throw new IllegalStateException("Invalid interface vg counter buffer size.");
238 }
239
240 ifCounterBytes = new byte[InterfaceCounter.INTERFACE_COUNTER_LENGTH];
241 bb.get(ifCounterBytes);
242
243 InterfaceCounter interfaceCounter = InterfaceCounter.deserializer().deserialize(ifCounterBytes,
244 0, InterfaceCounter.INTERFACE_COUNTER_LENGTH);
245 if (!isValidBuffer.test(bb, VG_COUNTER_LENGTH)) {
246 throw new IllegalStateException("Invalid interface vg counter buffer size.");
247 }
248
249 Builder builder = new Builder();
250 return builder.generic(interfaceCounter)
251 .dot12InHighPriorityFrames(bb.getInt())
252 .dot12InHighPriorityOctets(bb.getLong())
253 .dot12InNormPriorityFrames(bb.getInt())
254 .dot12InNormPriorityOctets(bb.getLong())
255 .dot12InIpmErrors(bb.getInt())
256 .dot12InOversizeFrameErrors(bb.getInt())
257 .dot12InDataErrors(bb.getInt())
258 .dot12InNullAddressedFrames(bb.getInt())
259 .dot12OutHighPriorityFrames(bb.getInt())
260 .dot12OutHighPriorityOctets(bb.getLong())
261 .dot12TransitionIntoTrainings(bb.getInt())
262 .dot12HCInHighPriorityOctets(bb.getLong())
263 .dot12HCInNormPriorityOctets(bb.getLong())
264 .dot12HCOutHighPriorityOctets(bb.getLong())
265 .build();
266
267 };
268 }
269
270 @Override
271 public byte[] serialize() {
272 throw new UnsupportedOperationException("Not supported yet.");
273 }
274
275 /**
karthik197739b84a02024-03-02 18:25:10 +0530276 * Builder pattern to create an instance of InterfaceCounter.
277 */
278 private static class Builder {
279 private InterfaceCounter generic;
280 private int dot12InHighPriorityFrames;
281 private long dot12InHighPriorityOctets;
282 private int dot12InNormPriorityFrames;
283 private long dot12InNormPriorityOctets;
284 private int dot12InIpmErrors;
285 private int dot12InOversizeFrameErrors;
286 private int dot12InDataErrors;
287 private int dot12InNullAddressedFrames;
288 private int dot12OutHighPriorityFrames;
289 private long dot12OutHighPriorityOctets;
290 private int dot12TransitionIntoTrainings;
291 private long dot12HCInHighPriorityOctets;
292 private long dot12HCInNormPriorityOctets;
293 private long dot12HCOutHighPriorityOctets;
294
295 /**
296 * Sets the generic interface counter.
297 *
298 * @param generic the generic interface counter.
299 * @return this builder instance.
300 */
301 public Builder generic(InterfaceCounter generic) {
302 this.generic = generic;
303 return this;
304 }
305
306 /**
307 * Sets the count of high priority frames.
308 *
309 * @param dot12InHighPriorityFrames the count of high priority frames.
310 * @return this builder instance.
311 */
312 public Builder dot12InHighPriorityFrames(int dot12InHighPriorityFrames) {
313 this.dot12InHighPriorityFrames = dot12InHighPriorityFrames;
314 return this;
315 }
316
317 /**
318 * Sets the count of high priority octets.
319 *
320 * @param dot12InHighPriorityOctets the high priority octets.
321 * @return this builder instance.
322 */
323 public Builder dot12InHighPriorityOctets(long dot12InHighPriorityOctets) {
324 this.dot12InHighPriorityOctets = dot12InHighPriorityOctets;
325 return this;
326 }
327
328 /**
329 * Sets the count of normal priority frames.
330 *
331 * @param dot12InNormPriorityFrames the count of normal priority frames.
332 * @return this builder instance.
333 */
334 public Builder dot12InNormPriorityFrames(int dot12InNormPriorityFrames) {
335 this.dot12InNormPriorityFrames = dot12InNormPriorityFrames;
336 return this;
337 }
338
339 /**
340 * Sets the count of normal priority octets.
341 *
342 * @param dot12InNormPriorityOctets the count of normal priority octets.
343 * @return this builder instance.
344 */
345 public Builder dot12InNormPriorityOctets(long dot12InNormPriorityOctets) {
346 this.dot12InNormPriorityOctets = dot12InNormPriorityOctets;
347 return this;
348 }
349
350 /**
351 * Sets the count of ipm errors.
352 *
353 * @param dot12InIPMErrors the count of ipm errors.
354 * @return this builder instance.
355 */
356 public Builder dot12InIpmErrors(int dot12InIpmErrors) {
357 this.dot12InIpmErrors = dot12InIpmErrors;
358 return this;
359 }
360
361 /**
362 * Sets the count of over size frame errors.
363 *
364 * @param dot12InOversizeFrameErrors the count of over size frame errors.
365 * @return this builder instance.
366 */
367 public Builder dot12InOversizeFrameErrors(int dot12InOversizeFrameErrors) {
368 this.dot12InOversizeFrameErrors = dot12InOversizeFrameErrors;
369 return this;
370 }
371
372 /**
373 * Sets the count of in data errors.
374 *
375 * @param dot12InDataErrors the count of in data errors.
376 * @return this builder instance.
377 */
378 public Builder dot12InDataErrors(int dot12InDataErrors) {
379 this.dot12InDataErrors = dot12InDataErrors;
380 return this;
381 }
382
383 /**
384 * Sets the count of in null addressed frames.
385 *
386 * @param dot12InNullAddressedFrames the count of in null addressed frames.
387 * @return this builder instance.
388 */
389 public Builder dot12InNullAddressedFrames(int dot12InNullAddressedFrames) {
390 this.dot12InNullAddressedFrames = dot12InNullAddressedFrames;
391 return this;
392 }
393
394 /**
395 * Sets the count of out high priority frames.
396 *
397 * @param dot12OutHighPriorityFrames the count of out high priority frames.
398 * @return this builder instance.
399 */
400 public Builder dot12OutHighPriorityFrames(int dot12OutHighPriorityFrames) {
401 this.dot12OutHighPriorityFrames = dot12OutHighPriorityFrames;
402 return this;
403 }
404
405 /**
406 * Sets the count of out high priority octets.
407 *
408 * @param dot12OutHighPriorityOctets the count of out high priority octets.
409 * @return this builder instance.
410 */
411 public Builder dot12OutHighPriorityOctets(long dot12OutHighPriorityOctets) {
412 this.dot12OutHighPriorityOctets = dot12OutHighPriorityOctets;
413 return this;
414 }
415
416 /**
417 * Sets the count of transition.
418 *
419 * @param dot12TransitionIntoTrainings the count of transition.
420 * @return this builder instance.
421 */
422 public Builder dot12TransitionIntoTrainings(int dot12TransitionIntoTrainings) {
423 this.dot12TransitionIntoTrainings = dot12TransitionIntoTrainings;
424 return this;
425 }
426
427 /**
428 * Sets the count of high priority octets.
429 *
430 * @param dot12HCInHighPriorityOctets the count of high priority octets.
431 * @return this builder instance.
432 */
433 public Builder dot12HCInHighPriorityOctets(long dot12HCInHighPriorityOctets) {
434 this.dot12HCInHighPriorityOctets = dot12HCInHighPriorityOctets;
435 return this;
436 }
437
438 /**
439 * Sets the count of in normal priority octets.
440 *
441 * @param dot12HCInNormPriorityOctets the count of in normal priority octets.
442 * @return this builder instance.
443 */
444 public Builder dot12HCInNormPriorityOctets(long dot12HCInNormPriorityOctets) {
445 this.dot12HCInNormPriorityOctets = dot12HCInNormPriorityOctets;
446 return this;
447 }
448
449 /**
450 * Sets the count of out high priority octets.
451 *
452 * @param dot12HCOutHighPriorityOctets the count of out high priority octets.
453 * @return this builder instance.
454 */
455 public Builder dot12HCOutHighPriorityOctets(long dot12HCOutHighPriorityOctets) {
456 this.dot12HCOutHighPriorityOctets = dot12HCOutHighPriorityOctets;
457 return this;
458 }
459
460 /**
461 * Builds an instance of VgCounter based on the configured parameters.
462 *
463 * @return an instance of VgCounter.
464 */
465 public VgCounter build() {
466 return new VgCounter(this);
467 }
468
469 }
470}