blob: d345f151be954d9f696c24368897d5e652991e56 [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
Andrea Campanella0288c872017-08-07 18:32:51 +020017package org.onosproject.p4runtime.api;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020018
19import com.google.common.base.MoreObjects;
20import com.google.common.base.Objects;
21import org.onosproject.net.DeviceId;
Carmelo Cascone87892e22017-11-13 16:01:29 -080022import org.onosproject.net.pi.model.PiTableId;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020023import org.onosproject.net.pi.runtime.PiMatchKey;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020024
25import static com.google.common.base.Preconditions.checkNotNull;
26
Andrea Campanella0288c872017-08-07 18:32:51 +020027/**
28 * Class containing the reference for a table entry in P4Runtime.
29 */
30public final class P4RuntimeTableEntryReference {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020031
32 private final DeviceId deviceId;
33 private final PiTableId tableId;
34 private final PiMatchKey matchKey;
35
36 /**
37 * Creates a new table entry reference.
38 *
39 * @param deviceId a device ID
40 * @param tableId a table name
41 * @param matchKey a match key
42 */
Andrea Campanella0288c872017-08-07 18:32:51 +020043 public P4RuntimeTableEntryReference(DeviceId deviceId, PiTableId tableId, PiMatchKey matchKey) {
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020044 this.deviceId = checkNotNull(deviceId);
45 this.tableId = checkNotNull(tableId);
46 this.matchKey = checkNotNull(matchKey);
47 }
48
49 /**
50 * Returns the device ID of this table entry reference.
51 *
52 * @return a device ID
53 */
54 public DeviceId deviceId() {
55 return deviceId;
56 }
57
58 /**
59 * Returns the table id of this table entry reference.
60 *
61 * @return a table name
62 */
63 public PiTableId tableId() {
64 return tableId;
65 }
66
67 /**
68 * Returns the match key of this table entry reference.
69 *
70 * @return a match key
71 */
72 public PiMatchKey matchKey() {
73 return matchKey;
74 }
75
76 @Override
77 public int hashCode() {
78 return Objects.hashCode(deviceId, tableId, matchKey);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
86 if (obj == null || getClass() != obj.getClass()) {
87 return false;
88 }
Andrea Campanella0288c872017-08-07 18:32:51 +020089 final P4RuntimeTableEntryReference other = (P4RuntimeTableEntryReference) obj;
Carmelo Cascone0b22d8f2017-07-31 07:22:27 +020090 return Objects.equal(this.deviceId, other.deviceId)
91 && Objects.equal(this.tableId, other.tableId)
92 && Objects.equal(this.matchKey, other.matchKey);
93 }
94
95 @Override
96 public String toString() {
97 return MoreObjects.toStringHelper(this)
98 .add("deviceId", deviceId)
99 .add("tableId", tableId)
100 .add("matchKey", matchKey)
101 .toString();
102 }
103}