blob: 70bf33cafb37e3ef374b7735c83ebcfe9368c60b [file] [log] [blame]
Yi Tseng2a340f72018-11-02 16:52:47 -07001/*
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.api;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.grpc.api.GrpcClientKey;
21import org.onosproject.net.DeviceId;
22
23import java.util.Objects;
24
25/**
26 * Key that uniquely identifies a P4Runtime client.
27 */
28@Beta
29public final class P4RuntimeClientKey extends GrpcClientKey {
30 private static final String P4R_SERVICE_NAME = "p4runtime";
31 private final long p4DeviceId;
32
33 /**
34 * Creates a new client key.
35 *
36 * @param deviceId ONOS device ID
37 * @param serverAddr P4Runtime server address
38 * @param serverPort P4Runtime server port
39 * @param p4DeviceId P4Runtime server-internal device ID
40 */
41 public P4RuntimeClientKey(DeviceId deviceId, String serverAddr,
42 int serverPort, long p4DeviceId) {
43 super(P4R_SERVICE_NAME, deviceId, serverAddr, serverPort);
44 this.p4DeviceId = p4DeviceId;
45 }
46
47 /**
48 * Returns the P4Runtime server-internal device ID.
49 *
50 * @return P4Runtime server-internal device ID
51 */
52 public long p4DeviceId() {
53 return p4DeviceId;
54 }
55
56 @Override
57 public boolean equals(Object o) {
58 if (this == o) {
59 return true;
60 }
61 if (o == null || getClass() != o.getClass()) {
62 return false;
63 }
64 if (!super.equals(o)) {
65 return false;
66 }
67 P4RuntimeClientKey that = (P4RuntimeClientKey) o;
68 return p4DeviceId == that.p4DeviceId;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(super.hashCode(), p4DeviceId);
74 }
75
76 @Override
77 public String toString() {
78 return super.toStringHelper()
79 .add("p4DeviceId", p4DeviceId)
80 .toString();
81 }
82}