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