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 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 19 | import org.onosproject.net.pi.model.PiPacketMetadataId; |
| 20 | import org.onosproject.net.pi.model.PiPacketMetadataModel; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 21 | |
| 22 | import java.util.Objects; |
| 23 | |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 26 | /** |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 27 | * Implementation of PiPacketMetadataModel for P4Runtime. |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 28 | */ |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 29 | final class P4PacketMetadataModel implements PiPacketMetadataModel { |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 30 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 31 | private final PiPacketMetadataId id; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 32 | private final int bitWidth; |
| 33 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 34 | P4PacketMetadataModel(PiPacketMetadataId id, int bitWidth) { |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 35 | this.id = id; |
| 36 | this.bitWidth = bitWidth; |
| 37 | } |
| 38 | |
| 39 | @Override |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 40 | public PiPacketMetadataId id() { |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 41 | return id; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public int bitWidth() { |
| 46 | return bitWidth; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public int hashCode() { |
| 51 | return Objects.hash(id, bitWidth); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean equals(Object obj) { |
| 56 | if (this == obj) { |
| 57 | return true; |
| 58 | } |
| 59 | if (obj == null || getClass() != obj.getClass()) { |
| 60 | return false; |
| 61 | } |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 62 | final P4PacketMetadataModel other = (P4PacketMetadataModel) obj; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 63 | return Objects.equals(this.id, other.id) |
| 64 | && Objects.equals(this.bitWidth, other.bitWidth); |
| 65 | } |
pierventre | 4d2a542 | 2021-01-10 17:29:03 -0800 | [diff] [blame^] | 66 | |
| 67 | @Override |
| 68 | public String toString() { |
| 69 | return toStringHelper(this) |
| 70 | .add("id", id) |
| 71 | .add("bitWidth", bitWidth) |
| 72 | .toString(); |
| 73 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 74 | } |