blob: 9f8010d225a5f4b8c41a5c86271295a6eaba3a53 [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.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.pi.model.PiHeaderFieldModel;
23import org.onosproject.net.pi.model.PiHeaderFieldTypeModel;
24import org.onosproject.net.pi.model.PiHeaderModel;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * BMv2 header field model.
30 */
31@Beta
32public final class Bmv2HeaderFieldModel implements PiHeaderFieldModel {
33 private final Bmv2HeaderModel header;
34 private final Bmv2HeaderFieldTypeModel type;
35
36 /**
37 * Builds a BMv2 header field model with given BMv2 header model and header field type model.
38 *
39 * @param header the header model
40 * @param type the header field type model
41 */
42 public Bmv2HeaderFieldModel(Bmv2HeaderModel header, Bmv2HeaderFieldTypeModel type) {
43 checkNotNull(header, "Header can't be null");
44 checkNotNull(type, "Type can't be null");
45 this.header = header;
46 this.type = type;
47 }
48
49 @Override
50 public PiHeaderModel header() {
51 return header;
52 }
53
54 @Override
55 public PiHeaderFieldTypeModel type() {
56 return type;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hashCode(header, type);
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (!(obj instanceof Bmv2HeaderFieldModel)) {
70 return false;
71 }
72 Bmv2HeaderFieldModel that = (Bmv2HeaderFieldModel) obj;
73 return Objects.equal(this.header, that.header) &&
74 Objects.equal(this.type, that.type);
75 }
76
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(getClass())
80 .add("header", header)
81 .add("type", type)
82 .toString();
83 }
84}