blob: 7eeb7f68f1068c6118a6a63ea707c6de5b7c3a68 [file] [log] [blame]
Carmelo Cascone326ad2d2017-11-28 18:09:13 -08001/*
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 */
16
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.DeviceId;
23
24/**
25 * Global identifier of a PI table entry applied on a device, uniquely defined
26 * by a device ID, table ID and match key.
27 */
28@Beta
29public final class PiTableEntryHandle extends PiHandle<PiTableEntry> {
30
31 private PiTableEntryHandle(DeviceId deviceId, PiTableEntry entry) {
32 super(deviceId, entry);
33 }
34
35 /**
36 * Creates a new handle for the given PI table entry and device ID.
37 *
38 * @param deviceId device ID
39 * @param entry PI table entry
40 * @return PI table entry handle
41 */
42 public static PiTableEntryHandle of(DeviceId deviceId, PiTableEntry entry) {
43 return new PiTableEntryHandle(deviceId, entry);
44 }
45
46 @Override
47 public int hashCode() {
48 return Objects.hashCode(deviceId(),
49 piEntity().table(),
50 piEntity().matchKey());
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (this == obj) {
56 return true;
57 }
58 if (obj == null || getClass() != obj.getClass()) {
59 return false;
60 }
61 final PiTableEntryHandle other = (PiTableEntryHandle) obj;
62 return Objects.equal(this.deviceId(), other.deviceId())
63 && Objects.equal(this.piEntity().table(),
64 other.piEntity().table())
65 && Objects.equal(this.piEntity().matchKey(),
66 other.piEntity().matchKey());
67 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(this)
72 .add("deviceId", deviceId())
73 .add("tableId", piEntity().table())
74 .add("matchKey", piEntity().matchKey())
75 .toString();
76 }
77}