blob: 598f3e7544ae56a28a639b695ad5363bdadb473d [file] [log] [blame]
Carmelo Cascone87b9b392017-10-02 18:33:20 +02001/*
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.base.Objects;
20import org.onosproject.net.group.GroupKey;
21
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * Implementation of GroupKey for the case of a protocol-independent pipeline.
26 */
27public final class PiGroupKey implements GroupKey {
28
29 private final PiTableId tableId;
30 private final PiActionProfileId piActionProfileId;
31 private final int groupId;
32
33 /**
34 * Returns a new group key for the given table ID, action profile ID, and group ID.
35 *
36 * @param tableId table ID
37 * @param piActionProfileId action profile ID
38 * @param groupId group ID
39 */
40 public PiGroupKey(PiTableId tableId, PiActionProfileId piActionProfileId, int groupId) {
41 this.tableId = checkNotNull(tableId);
42 this.piActionProfileId = checkNotNull(piActionProfileId);
43 this.groupId = groupId;
44 }
45
46 /**
47 * Returns the table ID defined by this key.
48 *
49 * @return table ID
50 */
51 public PiTableId tableId() {
52 return tableId;
53 }
54
55 /**
56 * Returns the group ID defined by this key.
57 *
58 * @return group ID
59 */
60 public int groupId() {
61 return groupId;
62 }
63
64 /**
65 * Returns the action profile ID defined by this key.
66 *
67 * @return action profile ID
68 */
69 public PiActionProfileId actionProfileId() {
70 return piActionProfileId;
71 }
72
73 @Override
74 public byte[] key() {
75 return toString().getBytes();
76 }
77
78 @Override
79 public boolean equals(Object o) {
80 if (this == o) {
81 return true;
82 }
83 if (!(o instanceof PiGroupKey)) {
84 return false;
85 }
86 PiGroupKey that = (PiGroupKey) o;
87 return groupId == that.groupId &&
88 Objects.equal(tableId, that.tableId) &&
89 Objects.equal(piActionProfileId, that.piActionProfileId);
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hashCode(tableId, piActionProfileId, groupId);
95 }
96
97 @Override
98 public String toString() {
99 return tableId.id() + "-" + piActionProfileId.id() + "-" + String.valueOf(groupId);
100 }
101}