blob: ffa2063b73581f00dd8cf67cb10ee4682f2a1102 [file] [log] [blame]
pierventre26eb65d2020-10-08 17:21:49 +02001/*
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 org.onosproject.net.flow.TrafficSelector;
20
21import java.util.Objects;
22
23/**
24 * Represents a traceable packet composed by a traffic selector and metadata.
25 */
26public final class PipelineTraceablePacket {
27
28 // stores metadata associated with the packet
29 private PipelineTraceableMetadata metadata;
30 // representation of the packet
31 private TrafficSelector packet;
32
33 /**
34 * Builds a traceable packet without metadata.
35 * Note this can be used for legacy device like ofdpa.
36 *
37 * @param packet the packet selector
38 */
39 public PipelineTraceablePacket(TrafficSelector packet) {
40 this.packet = packet;
41 }
42
43 /**
44 * Builds a traceable packet with metadata.
45 * @param packet the packet selector
46 * @param metadata the packet metadata
47 */
48 public PipelineTraceablePacket(TrafficSelector packet, PipelineTraceableMetadata metadata) {
49 this.packet = packet;
50 this.metadata = metadata;
51 }
52
53 /**
54 * Getter for the metadata.
55 *
56 * @return the packet metadata
57 */
58 public PipelineTraceableMetadata metadata() {
59 return metadata;
60 }
61
62 /**
63 * Getter for the packet selector.
64 *
65 * @return the packet selector
66 */
67 public TrafficSelector packet() {
68 return packet;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hash(metadata, packet);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj instanceof PipelineTraceablePacket) {
82 PipelineTraceablePacket that = (PipelineTraceablePacket) obj;
83 return Objects.equals(this.metadata, that.metadata) &&
84 Objects.equals(this.packet, that.packet);
85 }
86 return false;
87 }
88
89 @Override
90 public String toString() {
91 return "PipelineTraceablePacket{" +
92 "metadata=" + metadata +
93 ", packet=" + packet +
94 '}';
95 }
96}