blob: 753dc85e7431df6c3fbb48474ed7cdc7313b6e3d [file] [log] [blame]
Yi Tsengf33c0772017-06-06 14:56:18 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengf33c0772017-06-06 14:56:18 -07003 *
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.bmv2.model;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.Objects;
21import org.onosproject.net.pi.model.PiMatchType;
22import org.onosproject.net.pi.model.PiTableMatchFieldModel;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.*;
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * BMv2 table match field model.
30 */
31@Beta
32public final class Bmv2TableMatchFieldModel implements PiTableMatchFieldModel {
33 private final PiMatchType matchType;
34 private final Bmv2HeaderFieldModel field;
35
36 /**
37 * Creates new BMv2 table match field model using the given type and header field.
38 *
39 * @param matchType the match type
40 * @param field the header field
41 */
42 public Bmv2TableMatchFieldModel(PiMatchType matchType, Bmv2HeaderFieldModel field) {
43 checkNotNull(matchType, "Match type can't be null");
44 checkNotNull(field, "Header field can't be null");
45
46 this.matchType = matchType;
47 this.field = field;
48 }
49
50 @Override
51 public PiMatchType matchType() {
52 return matchType;
53 }
54
55 @Override
56 public Bmv2HeaderFieldModel field() {
57 return field;
58 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hashCode(matchType, field);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj == null || getClass() != obj.getClass()) {
71 return false;
72 }
73 final Bmv2TableMatchFieldModel other = (Bmv2TableMatchFieldModel) obj;
74 return Objects.equal(this.matchType, other.matchType)
75 && Objects.equal(this.field, other.field);
76 }
77
78 @Override
79 public String toString() {
80 return toStringHelper(this)
81 .add("matchType", matchType)
82 .add("field", field)
83 .toString();
84 }
85
86
87}