blob: ccf8af88eef963d80a8a97ae8b6972eecc7fdebf [file] [log] [blame]
FrankWangea70de32018-05-08 15:41:25 +08001/*
2 * Copyright 2018-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.net.pi.runtime.data;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.Objects;
21import com.google.common.collect.ImmutableList;
22import org.onosproject.net.pi.model.PiData;
23
24import java.util.List;
25import java.util.StringJoiner;
26
27/**
28 * Instance of a PiHeaderStack in a protocol-independent pipeline.
29 */
30@Beta
31public final class PiHeaderStack implements PiData {
32 private final ImmutableList<PiHeader> headers;
33
34 /**
35 * Creates a new protocol-independent header stack instance for the given collection of Header.
36 *
37 * @param headers the collection of header
38 */
39 private PiHeaderStack(List<PiHeader> headers) {
40 this.headers = ImmutableList.copyOf(headers);
41 }
42
43 /**
44 * Returns a new protocol-independent header stack.
45 * @param headers the list of header
46 * @return header stack
47 */
48 public static PiHeaderStack of(List<PiHeader> headers) {
49 return new PiHeaderStack(headers);
50 }
51
52 /**
53 * Return the list of header.
54 *
55 * @return the list of header
56 */
57 public List<PiHeader> headers() {
58 return this.headers;
59 }
60
61 @Override
62 public Type type() {
63 return Type.HEADERSTACK;
64 }
65
66 @Override
67 public boolean equals(Object o) {
68 if (this == o) {
69 return true;
70 }
71 if (o == null || getClass() != o.getClass()) {
72 return false;
73 }
74 PiHeaderStack stack = (PiHeaderStack) o;
75 return Objects.equal(headers, stack.headers);
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hashCode(headers);
81 }
82
83 @Override
84 public String toString() {
85 StringJoiner stringParams = new StringJoiner(", ", "(", ")");
86 this.headers().forEach(p -> stringParams.add(p.toString()));
87 return stringParams.toString();
88 }
89}