Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [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.p4runtime.model; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 21 | import org.onosproject.net.pi.model.PiActionProfileModel; |
| 22 | import org.onosproject.net.pi.model.PiTableId; |
| 23 | |
| 24 | import java.util.Collection; |
| 25 | import java.util.Objects; |
| 26 | |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Implementation of PiActionProfileModel for P4Runtime. |
| 31 | */ |
| 32 | final class P4ActionProfileModel implements PiActionProfileModel { |
| 33 | |
| 34 | private final PiActionProfileId id; |
| 35 | private final ImmutableSet<PiTableId> tables; |
| 36 | private final boolean hasSelector; |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 37 | private final long size; |
| 38 | private final int maxGroupSize; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 39 | |
| 40 | P4ActionProfileModel(PiActionProfileId id, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 41 | ImmutableSet<PiTableId> tables, boolean hasSelector, |
| 42 | long size, int maxGroupSize) { |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 43 | this.id = id; |
| 44 | this.tables = tables; |
| 45 | this.hasSelector = hasSelector; |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 46 | this.size = size; |
| 47 | this.maxGroupSize = maxGroupSize; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public PiActionProfileId id() { |
| 52 | return id; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public Collection<PiTableId> tables() { |
| 57 | return tables; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean hasSelector() { |
| 62 | return hasSelector; |
| 63 | } |
| 64 | |
| 65 | @Override |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 66 | public long size() { |
| 67 | return size; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int maxGroupSize() { |
| 72 | return maxGroupSize; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 77 | return Objects.hash(id, tables, hasSelector, size, maxGroupSize); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 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 P4ActionProfileModel other = (P4ActionProfileModel) obj; |
| 89 | return Objects.equals(this.id, other.id) |
| 90 | && Objects.equals(this.tables, other.tables) |
| 91 | && Objects.equals(this.hasSelector, other.hasSelector) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 92 | && Objects.equals(this.size, other.size) |
| 93 | && Objects.equals(this.maxGroupSize, other.maxGroupSize); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 94 | } |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 95 | |
| 96 | @Override |
| 97 | public String toString() { |
| 98 | return toStringHelper(this) |
| 99 | .add("id", id) |
| 100 | .add("tables", tables) |
| 101 | .add("hasSelector", hasSelector) |
| 102 | .add("size", size) |
| 103 | .add("maxGroupSize", maxGroupSize) |
| 104 | .toString(); |
| 105 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 106 | } |