blob: bcbaf74142dda8598f51eea0c7a205bbf731b4bc [file] [log] [blame]
Pier Ventref5d72362016-07-17 12:02:14 +02001/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16
17package org.onosproject.net.behaviour;
18
19import com.google.common.base.MoreObjects;
20
21import java.util.Map;
22import java.util.Objects;
23
24/**
25 * Represents statistics associated to a mirroring.
26 */
27public final class MirroringStatistics {
28
29 private MirroringName mirroringName;
30 private int txBytes;
31 private int txPackets;
32
33 /**
34 * Statistics associated to a named mirroring.
35 *
36 * @param name the name of the mirroring
37 * @param bytes transmitted bytes
38 * @param packets transmitted packets
39 */
40 private MirroringStatistics(String name, int bytes, int packets) {
41 this.mirroringName = MirroringName.mirroringName(name);
42 this.txBytes = bytes;
43 this.txPackets = packets;
44 }
45
46 /**
47 *
48 * Creates a MirroringStatistics using the supplied information.
49 *
50 * @param name the name of the mirroring
51 * @param statistics the associated statistics
52 * @return the MirroringStatistics object
53 */
54 public static MirroringStatistics mirroringStatistics(String name, Map<String, Integer> statistics) {
55 return new MirroringStatistics(name, statistics.get("tx_bytes"), statistics.get("tx_packets"));
56 }
57
58 /**
59 * Returns the mirroring name string.
60 *
61 * @return name string
62 */
63 public MirroringName name() {
64 return mirroringName;
65 }
66
67 /**
68 * Returns the transmitted bytes.
69 *
70 * @return the bytes
71 */
72 public long bytes() {
73 return txBytes;
74 }
75
76 /**
77 * Returns the transmitted packtes.
78 *
79 * @return the packets
80 */
81 public long packtes() {
82 return txPackets;
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(name().name(), txBytes, txPackets);
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
94 }
95 if (obj instanceof MirroringStatistics) {
96 final MirroringStatistics that = (MirroringStatistics) obj;
97 return this.getClass() == that.getClass() &&
98 Objects.equals(this.mirroringName, that.mirroringName) &&
99 Objects.equals(this.txBytes, that.txBytes) &&
100 Objects.equals(this.txPackets, that.txPackets);
101 }
102 return false;
103 }
104
105 @Override
106 public String toString() {
107 return MoreObjects.toStringHelper(getClass())
108 .add("name", name())
109 .add("tx_bytes", bytes())
110 .add("tx_packets", packtes())
111 .toString();
112 }
113
114}