blob: ee5e2a434e162bc7566eea45dd7670065ea591ff [file] [log] [blame]
Carmelo Cascone44448a52018-06-25 23:36:57 +02001/*
2 * Copyright 2018-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 */
16
17package org.onosproject.p4runtime.ctl;
18
19import com.google.common.base.MoreObjects;
20import org.onosproject.net.DeviceId;
21
22import java.util.Objects;
23
24/**
25 * Key the uniquely identifies a P4Runtime client.
26 */
27final class ClientKey {
28
29 private final DeviceId deviceId;
30 private final String serverAddr;
31 private final int serverPort;
32 private final long p4DeviceId;
33
34 /**
35 * Creates a new client key.
36 *
37 * @param deviceId ONOS device ID
38 * @param serverAddr P4Runtime server address
39 * @param serverPort P4Runtime server port
40 * @param p4DeviceId P4Runtime server-internal device ID
41 */
42 ClientKey(DeviceId deviceId, String serverAddr, int serverPort, long p4DeviceId) {
43 this.deviceId = deviceId;
44 this.serverAddr = serverAddr;
45 this.serverPort = serverPort;
46 this.p4DeviceId = p4DeviceId;
47 }
48
49 /**
50 * Returns the device ID.
51 *
52 * @return device ID.
53 */
54 public DeviceId deviceId() {
55 return deviceId;
56 }
57
58 /**
59 * Returns the P4Runtime server address.
60 *
61 * @return P4Runtime server address
62 */
63 public String serverAddr() {
64 return serverAddr;
65 }
66
67 /**
68 * Returns the P4Runtime server port.
69 *
70 * @return P4Runtime server port
71 */
72 public int serverPort() {
73 return serverPort;
74 }
75
76 /**
77 * Returns the P4Runtime server-internal device ID.
78 *
79 * @return P4Runtime server-internal device ID
80 */
81 public long p4DeviceId() {
82 return p4DeviceId;
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(serverAddr, serverPort, p4DeviceId);
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
94 }
95 if (obj == null || getClass() != obj.getClass()) {
96 return false;
97 }
98 final ClientKey other = (ClientKey) obj;
99 return Objects.equals(this.serverAddr, other.serverAddr)
100 && Objects.equals(this.serverPort, other.serverPort)
101 && Objects.equals(this.p4DeviceId, other.p4DeviceId);
102 }
103
104 @Override
105 public String toString() {
106 return MoreObjects.toStringHelper(this)
107 .add("deviceId", deviceId)
108 .add("serverAddr", serverAddr)
109 .add("serverPort", serverPort)
110 .add("p4DeviceId", p4DeviceId)
111 .toString();
112 }
113}