blob: 6e5f566f867a1f58dd9f164f5a866daa266b6b66 [file] [log] [blame]
pierventre4b72c472020-05-22 09:42:31 -07001/*
2 * Copyright 2020-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;
18
19import com.google.common.collect.Lists;
pierventre4b72c472020-05-22 09:42:31 -070020
21import java.util.List;
22import java.util.Objects;
23
24/**
25 * Class to represent the pipeline hit chain and the result of the pipeline processing.
26 */
pierventre26eb65d2020-10-08 17:21:49 +020027public final class PipelineTraceableHitChain {
pierventre4b72c472020-05-22 09:42:31 -070028
29 private ConnectPoint outputPort;
30 private List<DataPlaneEntity> hitChain;
pierventre26eb65d2020-10-08 17:21:49 +020031 private PipelineTraceablePacket egressPacket;
pierventre4b72c472020-05-22 09:42:31 -070032 // By default packets are dropped
33 private boolean dropped = true;
34
35 private PipelineTraceableHitChain() {
36 hitChain = Lists.newArrayList();
37 }
38
39 /**
40 * Creates a new PipelineTraceableHitChain.
41 *
42 * @param output the output connect point
43 * @param hits the hits in the pipeline (flows, groups and other abstractions)
pierventre26eb65d2020-10-08 17:21:49 +020044 * @param packet the traceable packet representing the final packet
pierventre4b72c472020-05-22 09:42:31 -070045 */
46 public PipelineTraceableHitChain(ConnectPoint output, List<DataPlaneEntity> hits,
pierventre26eb65d2020-10-08 17:21:49 +020047 PipelineTraceablePacket packet) {
pierventre4b72c472020-05-22 09:42:31 -070048 this.outputPort = output;
49 this.hitChain = hits;
50 this.egressPacket = packet;
51 }
52
53 /**
54 * Creates an empty pipeline hit chain.
55 *
56 * @return an empty pipeline hit chain
57 */
58 public static PipelineTraceableHitChain emptyHitChain() {
59 return new PipelineTraceableHitChain();
60 }
61
62 /**
63 * Returns the output connect point.
64 *
65 * @return the connect point
66 */
pierventre26eb65d2020-10-08 17:21:49 +020067 public ConnectPoint outputPort() {
pierventre4b72c472020-05-22 09:42:31 -070068 return outputPort;
69 }
70
71 /**
72 * Sets the output port.
73 *
74 * @param outputPort the output port
75 */
76 public void setOutputPort(ConnectPoint outputPort) {
77 this.outputPort = outputPort;
78 }
79
80 /**
81 * Returns the hit chain.
82 *
83 * @return flows and groups that matched.
84 */
pierventre26eb65d2020-10-08 17:21:49 +020085 public List<DataPlaneEntity> hitChain() {
pierventre4b72c472020-05-22 09:42:31 -070086 return hitChain;
87 }
88
89 /**
90 * Adds the provided dataplane entity to the end of the chain.
91 *
92 * @param dataPlaneEntity the dataplane entity
93 */
94 public void addDataPlaneEntity(DataPlaneEntity dataPlaneEntity) {
95 if (!hitChain.contains(dataPlaneEntity)) {
96 hitChain.add(dataPlaneEntity);
97 }
98 }
99
100 /**
101 * Removes the provided dataplane entity from the chain.
102 *
103 * @param dataPlaneEntity the dataplane entity
104 */
105 public void removeDataPlaneEntity(DataPlaneEntity dataPlaneEntity) {
106 if (hitChain.isEmpty()) {
107 return;
108 }
109 hitChain.remove(dataPlaneEntity);
110 }
111
112 /**
113 * Returns the egress packet after traversing the pipeline.
114 *
pierventre26eb65d2020-10-08 17:21:49 +0200115 * @return the traceable packet representing the packet infos
pierventre4b72c472020-05-22 09:42:31 -0700116 */
pierventre26eb65d2020-10-08 17:21:49 +0200117 public PipelineTraceablePacket egressPacket() {
pierventre4b72c472020-05-22 09:42:31 -0700118 return egressPacket;
119 }
120
121 /**
122 * Sets the egress packet.
123 *
124 * @param egressPacket the egress packet
125 */
pierventre26eb65d2020-10-08 17:21:49 +0200126 public void setEgressPacket(PipelineTraceablePacket egressPacket) {
pierventre4b72c472020-05-22 09:42:31 -0700127 this.egressPacket = egressPacket;
128 }
129
130 /**
131 * Return whether or not the packet has been dropped by the pipeline.
132 *
133 * @return true if the packet has been dropped. False, otherwise.
134 */
135 public boolean isDropped() {
136 return dropped;
137 }
138
139 /**
140 * Set the dropped flag.
141 */
142 public void dropped() {
143 this.dropped = true;
144 }
145
146 /**
147 * Unset the dropped flag.
148 */
149 public void pass() {
150 this.dropped = false;
151 }
152
153 @Override
154 public int hashCode() {
155 return Objects.hash(outputPort, hitChain, egressPacket, dropped);
156 }
157
158 @Override
159 public boolean equals(Object obj) {
160 if (this == obj) {
161 return true;
162 }
163 if (obj instanceof PipelineTraceableHitChain) {
164 PipelineTraceableHitChain that = (PipelineTraceableHitChain) obj;
165 return Objects.equals(this.outputPort, that.outputPort) &&
pierventre26eb65d2020-10-08 17:21:49 +0200166 Objects.equals(this.hitChain, that.hitChain) &&
pierventre4b72c472020-05-22 09:42:31 -0700167 Objects.equals(this.egressPacket, that.egressPacket) &&
168 Objects.equals(this.dropped, that.dropped);
169 }
170 return false;
171 }
172
173 @Override
174 public String toString() {
175 return "PipelineTraceableHitChain{" +
176 "outputPort=" + outputPort +
177 ", hitChain=" + hitChain +
178 ", egressPacket=" + egressPacket +
179 ", dropped=" + dropped +
180 '}';
181 }
182}