blob: 9b99faa54232fc32185ae5215fe6b218ec2a768e [file] [log] [blame]
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +02001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +02003 *
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.drivers.bmv2;
18
19import com.google.common.base.MoreObjects;
20import com.google.common.base.Objects;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.pi.runtime.PiMatchKey;
23import org.onosproject.net.pi.runtime.PiTableId;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27public final class Bmv2TableEntryReference {
28
29 private final DeviceId deviceId;
30 private final PiTableId tableId;
31 private final PiMatchKey matchKey;
32
33 /**
34 * Creates a new table entry reference.
35 *
36 * @param deviceId a device ID
37 * @param tableId a table name
38 * @param matchKey a match key
39 */
40 public Bmv2TableEntryReference(DeviceId deviceId, PiTableId tableId, PiMatchKey matchKey) {
41 this.deviceId = checkNotNull(deviceId);
42 this.tableId = checkNotNull(tableId);
43 this.matchKey = checkNotNull(matchKey);
44 }
45
46 /**
47 * Returns the device ID of this table entry reference.
48 *
49 * @return a device ID
50 */
51 public DeviceId deviceId() {
52 return deviceId;
53 }
54
55 /**
56 * Returns the table id of this table entry reference.
57 *
58 * @return a table name
59 */
60 public PiTableId tableId() {
61 return tableId;
62 }
63
64 /**
65 * Returns the match key of this table entry reference.
66 *
67 * @return a match key
68 */
69 public PiMatchKey matchKey() {
70 return matchKey;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hashCode(deviceId, tableId, matchKey);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (obj == null || getClass() != obj.getClass()) {
84 return false;
85 }
86 final Bmv2TableEntryReference other = (Bmv2TableEntryReference) obj;
87 return Objects.equal(this.deviceId, other.deviceId)
88 && Objects.equal(this.tableId, other.tableId)
89 && Objects.equal(this.matchKey, other.matchKey);
90 }
91
92 @Override
93 public String toString() {
94 return MoreObjects.toStringHelper(this)
95 .add("deviceId", deviceId)
96 .add("tableId", tableId)
97 .add("matchKey", matchKey)
98 .toString();
99 }
100}