blob: f311acf47ad1fbbd0df224b189106370e4a20760 [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
19import org.onosproject.net.pi.model.PiMatchFieldId;
20import org.onosproject.net.pi.model.PiMatchFieldModel;
21import org.onosproject.net.pi.model.PiMatchType;
22
23import java.util.Objects;
24
pierventre4d2a5422021-01-10 17:29:03 -080025import static com.google.common.base.MoreObjects.toStringHelper;
26
Carmelo Cascone87892e22017-11-13 16:01:29 -080027/**
28 * Implementation of PiMatchFieldModel for P4Runtime.
29 */
30final class P4MatchFieldModel implements PiMatchFieldModel {
31
32 private final PiMatchFieldId id;
33 private final int bitWidth;
34 private final PiMatchType matchType;
35
36 P4MatchFieldModel(PiMatchFieldId id, int bitWidth, PiMatchType matchType) {
37 this.id = id;
38 this.bitWidth = bitWidth;
39 this.matchType = matchType;
40 }
41
42 @Override
43 public PiMatchFieldId id() {
44 return id;
45 }
46
47 @Override
48 public int bitWidth() {
49 return bitWidth;
50 }
51
52 @Override
53 public PiMatchType matchType() {
54 return matchType;
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(id, bitWidth, matchType);
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (this == obj) {
65 return true;
66 }
67 if (obj == null || getClass() != obj.getClass()) {
68 return false;
69 }
70 final P4MatchFieldModel other = (P4MatchFieldModel) obj;
71 return Objects.equals(this.id, other.id)
72 && Objects.equals(this.bitWidth, other.bitWidth)
73 && Objects.equals(this.matchType, other.matchType);
74 }
pierventre4d2a5422021-01-10 17:29:03 -080075
76 @Override
77 public String toString() {
78 return toStringHelper(this)
79 .add("id", id)
80 .add("bitWidth", bitWidth)
81 .add("matchType", matchType)
82 .toString();
83 }
Carmelo Cascone87892e22017-11-13 16:01:29 -080084}