blob: 90c0fbd221ac5e68bed794e8191cef46e0c75a48 [file] [log] [blame]
Carmelo Cascone17fc9e42016-05-31 11:29:21 -07001/*
Brian O'Connorce2a03d2017-08-03 19:21:03 -07002 * Copyright 2016-present Open Networking Foundation
Carmelo Cascone17fc9e42016-05-31 11:29:21 -07003 *
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.bmv2.api.runtime;
18
Carmelo Cascone9e39e312016-06-16 14:47:09 -070019import com.google.common.annotations.Beta;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070020import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.DeviceId;
23
24/**
25 * A reference to a table entry installed on a BMv2 device.
26 */
Carmelo Cascone9e39e312016-06-16 14:47:09 -070027@Beta
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070028public final class Bmv2TableEntryReference {
29
30
31 private final DeviceId deviceId;
32 private final String tableName;
33 private final Bmv2MatchKey matchKey;
34
35 /**
36 * Creates a new table entry reference.
37 *
38 * @param deviceId a device ID
39 * @param tableName a table name
40 * @param matchKey a match key
41 */
42 public Bmv2TableEntryReference(DeviceId deviceId, String tableName, Bmv2MatchKey matchKey) {
43 this.deviceId = deviceId;
44 this.tableName = tableName;
45 this.matchKey = matchKey;
46 }
47
48 /**
49 * Returns the device ID of this table entry reference.
50 *
51 * @return a device ID
52 */
53 public DeviceId deviceId() {
54 return deviceId;
55 }
56
57 /**
58 * Returns the name of the table of this table entry reference.
59 *
60 * @return a table name
61 */
62 public String tableName() {
63 return tableName;
64 }
65
66 /**
67 * Returns the match key of this table entry reference.
68 *
69 * @return a match key
70 */
71 public Bmv2MatchKey matchKey() {
72 return matchKey;
73 }
74
75 @Override
76 public int hashCode() {
77 return Objects.hashCode(deviceId, tableName, matchKey);
78 }
79
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj == null || getClass() != obj.getClass()) {
86 return false;
87 }
88 final Bmv2TableEntryReference other = (Bmv2TableEntryReference) obj;
89 return Objects.equal(this.deviceId, other.deviceId)
90 && Objects.equal(this.tableName, other.tableName)
91 && Objects.equal(this.matchKey, other.matchKey);
92 }
93
94 @Override
95 public String toString() {
96 return MoreObjects.toStringHelper(this)
97 .add("deviceId", deviceId)
98 .add("tableName", tableName)
99 .add("matchKey", matchKey)
100 .toString();
101 }
102}