blob: a1e39b85e38629dda71158fdf6f36af61cff6072 [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.Collection;
25import java.util.List;
26import java.util.StringJoiner;
27
28/**
29 * PiHeaderUnionStack entity in a protocol-independent pipeline.
30 */
31@Beta
32public final class PiHeaderUnionStack implements PiData {
33 private final ImmutableList<PiHeaderUnion> headerUnions;
34
35 /**
36 * Creates a new protocol-independent header union stack instance for the given collection of HeaderUnion.
37 *
38 * @param headerUnions the collection of headerUnion
39 */
40 private PiHeaderUnionStack(List<PiHeaderUnion> headerUnions) {
41 this.headerUnions = ImmutableList.copyOf(headerUnions);
42 }
43
44 /**
45 * Returns a new protocol-independent header union stack.
46 * @param headerUnions the list of headerUnion
47 * @return header union stack
48 */
49 public static PiHeaderUnionStack of(List<PiHeaderUnion> headerUnions) {
50 return new PiHeaderUnionStack(headerUnions);
51 }
52
53 /**
54 * Return the collection of header union.
55 *
56 * @return the collection header union
57 */
58 public Collection<PiHeaderUnion> headerUnions() {
59 return this.headerUnions;
60 }
61
62 @Override
63 public Type type() {
64 return Type.HEADERUNIONSTACK;
65 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (this == o) {
70 return true;
71 }
72 if (o == null || getClass() != o.getClass()) {
73 return false;
74 }
75 PiHeaderUnionStack headerUnionStack = (PiHeaderUnionStack) o;
76 return Objects.equal(headerUnions, headerUnionStack.headerUnions);
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hashCode(headerUnions);
82 }
83
84 @Override
85 public String toString() {
86 StringJoiner stringParams = new StringJoiner(", ", "(", ")");
87 this.headerUnions().forEach(p -> stringParams.add(p.toString()));
88 return stringParams.toString();
89 }
90}