blob: f3b5ddc7c9adf101bbcb9267880d7940dedf774d [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
25/**
26 * Implementation of PiMatchFieldModel for P4Runtime.
27 */
28final class P4MatchFieldModel implements PiMatchFieldModel {
29
30 private final PiMatchFieldId id;
31 private final int bitWidth;
32 private final PiMatchType matchType;
33
34 P4MatchFieldModel(PiMatchFieldId id, int bitWidth, PiMatchType matchType) {
35 this.id = id;
36 this.bitWidth = bitWidth;
37 this.matchType = matchType;
38 }
39
40 @Override
41 public PiMatchFieldId id() {
42 return id;
43 }
44
45 @Override
46 public int bitWidth() {
47 return bitWidth;
48 }
49
50 @Override
51 public PiMatchType matchType() {
52 return matchType;
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(id, bitWidth, matchType);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj == null || getClass() != obj.getClass()) {
66 return false;
67 }
68 final P4MatchFieldModel other = (P4MatchFieldModel) obj;
69 return Objects.equals(this.id, other.id)
70 && Objects.equals(this.bitWidth, other.bitWidth)
71 && Objects.equals(this.matchType, other.matchType);
72 }
73}