blob: 19a6fa7f1fa093d8a78a0295ed84798a298d264b [file] [log] [blame]
Carmelo Cascone87892e22017-11-13 16:01:29 -08001/*
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.p4runtime.model;
18
Carmelo Cascone4c289b72019-01-22 15:30:45 -080019import org.onosproject.net.pi.model.PiPacketMetadataId;
20import org.onosproject.net.pi.model.PiPacketMetadataModel;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021
22import java.util.Objects;
23
pierventre4d2a5422021-01-10 17:29:03 -080024import static com.google.common.base.MoreObjects.toStringHelper;
25
Carmelo Cascone87892e22017-11-13 16:01:29 -080026/**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080027 * Implementation of PiPacketMetadataModel for P4Runtime.
Carmelo Cascone87892e22017-11-13 16:01:29 -080028 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080029final class P4PacketMetadataModel implements PiPacketMetadataModel {
Carmelo Cascone87892e22017-11-13 16:01:29 -080030
Carmelo Cascone4c289b72019-01-22 15:30:45 -080031 private final PiPacketMetadataId id;
Carmelo Cascone87892e22017-11-13 16:01:29 -080032 private final int bitWidth;
33
Carmelo Cascone4c289b72019-01-22 15:30:45 -080034 P4PacketMetadataModel(PiPacketMetadataId id, int bitWidth) {
Carmelo Cascone87892e22017-11-13 16:01:29 -080035 this.id = id;
36 this.bitWidth = bitWidth;
37 }
38
39 @Override
Carmelo Cascone4c289b72019-01-22 15:30:45 -080040 public PiPacketMetadataId id() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080041 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 Cascone4c289b72019-01-22 15:30:45 -080062 final P4PacketMetadataModel other = (P4PacketMetadataModel) obj;
Carmelo Cascone87892e22017-11-13 16:01:29 -080063 return Objects.equals(this.id, other.id)
64 && Objects.equals(this.bitWidth, other.bitWidth);
65 }
pierventre4d2a5422021-01-10 17:29:03 -080066
67 @Override
68 public String toString() {
69 return toStringHelper(this)
70 .add("id", id)
71 .add("bitWidth", bitWidth)
72 .toString();
73 }
Carmelo Cascone87892e22017-11-13 16:01:29 -080074}