blob: d6c7ef909042c55c0a63924c2fd9a455eedb2af7 [file] [log] [blame]
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -03001/*
2 * Copyright 2017-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.opencord.dhcpl2relay.impl;
17
18import org.opencord.dhcpl2relay.DhcpL2RelayEvent;
19
20import java.util.Objects;
21
22/**
23 * Represents DHCP relay counters identifier.
24 */
25public final class DhcpL2RelayCountersIdentifier {
26 final String counterClassKey;
Jonathan Hart77ca3152020-02-21 14:31:21 -080027 final Enum<DhcpL2RelayCounterNames> counterTypeKey;
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030028
29 /**
30 * Creates a default global counter identifier for a given counterType.
31 *
32 * @param counterTypeKey Identifies the supported type of DHCP relay counters
33 */
Jonathan Hart77ca3152020-02-21 14:31:21 -080034 public DhcpL2RelayCountersIdentifier(DhcpL2RelayCounterNames counterTypeKey) {
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030035 this.counterClassKey = DhcpL2RelayEvent.GLOBAL_COUNTER;
36 this.counterTypeKey = counterTypeKey;
37 }
38
39 /**
40 * Creates a counter identifier. A counter is defined by the key pair &lt;counterClass, counterType&gt;,
41 * where counterClass can be maybe global or the subscriber ID and counterType is the supported DHCP message type.
42 *
43 * @param counterClassKey Identifies which class the counter is assigned (global or per subscriber)
44 * @param counterTypeKey Identifies the supported type of DHCP relay counters
45 */
Jonathan Hart77ca3152020-02-21 14:31:21 -080046 public DhcpL2RelayCountersIdentifier(String counterClassKey, DhcpL2RelayCounterNames counterTypeKey) {
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030047 this.counterClassKey = counterClassKey;
48 this.counterTypeKey = counterTypeKey;
49 }
50
51 @Override
52 public boolean equals(Object obj) {
53 if (this == obj) {
54 return true;
55 }
56 if (obj instanceof DhcpL2RelayCountersIdentifier) {
57 final DhcpL2RelayCountersIdentifier other = (DhcpL2RelayCountersIdentifier) obj;
58 return Objects.equals(this.counterClassKey, other.counterClassKey)
59 && Objects.equals(this.counterTypeKey, other.counterTypeKey);
60 }
61
62 return false;
63 }
64
65 @Override
66 public int hashCode() {
67 return Objects.hash(counterClassKey, counterTypeKey);
68 }
Jonathan Hart77ca3152020-02-21 14:31:21 -080069
70 public String toString() {
71 return this.counterClassKey + "/" + this.counterTypeKey;
72 }
Marcos Aurelio Carreroeaf02b82019-11-25 13:34:25 -030073}