blob: 1c11dcc49206d6c99579dcda401eeda43947b362 [file] [log] [blame]
tosinski36ba33a2021-11-22 16:53:00 +01001/*
2 * Copyright 2021-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.behaviour.upf;
18
19import com.google.common.annotations.Beta;
20import org.onlab.packet.Ip4Address;
21
22import java.util.Objects;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * A structure representing the UE Termination in the downlink direction on the
28 * UPF-programmable device.
29 * Provides means to configure the traffic behavior (e.g. set Traffic Class, GTP TEID, or QFI).
30 */
31@Beta
32public final class UpfTerminationDownlink implements UpfEntity {
33 // Match Keys
34 private final Ip4Address ueSessionId; // UE Session ID, use UE IP address to uniquely identify a session.
35 // Action parameters
36 private final Integer ctrId; // Counter ID unique to this UPF Termination Rule
37 private final Byte trafficClass;
38 private final Integer teid; // Tunnel Endpoint Identifier
39 private final Byte qfi; // QoS Flow Identifier
40 private final boolean dropping;
41
42 private UpfTerminationDownlink(Ip4Address ueSessionId, Integer ctrId, Byte trafficClass,
43 Integer teid, Byte qfi, boolean dropping) {
44 this.ueSessionId = ueSessionId;
45 this.ctrId = ctrId;
46 this.trafficClass = trafficClass;
47 this.teid = teid;
48 this.qfi = qfi;
49 this.dropping = dropping;
50 }
51
52 public static Builder builder() {
53 return new Builder();
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (obj == this) {
59 return true;
60 }
61 if (obj == null) {
62 return false;
63 }
64 if (getClass() != obj.getClass()) {
65 return false;
66 }
67 UpfTerminationDownlink that = (UpfTerminationDownlink) obj;
68
69 // Safe comparisons between potentially null objects
70 return this.dropping == that.dropping &&
71 Objects.equals(this.ueSessionId, that.ueSessionId) &&
72 Objects.equals(this.ctrId, that.ctrId) &&
73 Objects.equals(this.trafficClass, that.trafficClass) &&
74 Objects.equals(this.teid, that.teid) &&
75 Objects.equals(this.qfi, that.qfi);
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(ueSessionId, ctrId, trafficClass, teid, qfi, dropping);
81 }
82
83 /**
84 * Get UE Session ID associated with UPF Termination rule.
85 *
86 * @return UE Session ID
87 */
88 public Ip4Address ueSessionId() {
89 return ueSessionId;
90 }
91
92 /**
93 * Get PDR Counter ID associated with UPF Termination rule.
94 *
95 * @return PDR counter cell ID
96 */
97 public Integer counterId() {
98 return ctrId;
99 }
100
101 /**
102 * Get Traffic Class set by this UPF Termination rule.
103 *
104 * @return Traffic Class
105 */
106 public Byte trafficClass() {
107 return trafficClass;
108 }
109
110 /**
111 * Get GTP TEID set by this UPF Termination rule.
112 *
113 * @return GTP tunnel ID
114 */
115 public Integer teid() {
116 return teid;
117 }
118
119 /**
120 * Get QoS Flow Identifier set by this UPF Termination rule.
121 *
122 * @return QoS Flow Identifier
123 */
124 public Byte qfi() {
125 return qfi;
126 }
127
128 /**
129 * True if this UPF Termination needs to drop traffic.
130 *
131 * @return true if the UPF Termination needs dropping.
132 */
133 public boolean needsDropping() {
134 return dropping;
135 }
136
137 @Override
138 public UpfEntityType type() {
139 return UpfEntityType.TERMINATION_DOWNLINK;
140 }
141
142 @Override
143 public String toString() {
Daniele Morodfc23852022-01-05 11:23:51 +0100144 return "TerminationDL{" + matchString() + "->" + actionString() + "}";
tosinski36ba33a2021-11-22 16:53:00 +0100145 }
146
147 private String matchString() {
148 return "Match(ue_addr=" + this.ueSessionId() + ")";
149 }
150
151 private String actionString() {
152 return "(TEID=" + this.teid() +
153 ", CTR_ID=" + this.counterId() +
154 ", QFI=" + this.qfi() +
155 ", TC=" + this.trafficClass() +
156 ")";
157 }
158
159 public static class Builder {
160 private Ip4Address ueSessionId = null;
161 private Integer ctrId = null;
162 private Byte trafficClass = null;
163 private Integer teid = null;
164 private Byte qfi = null;
165 private boolean drop = false;
166
167 public Builder() {
168
169 }
170
171 /**
172 * Set the ID of the UE session.
173 *
174 * @param ueSessionId UE session ID
175 * @return This builder object
176 */
177 public Builder withUeSessionId(Ip4Address ueSessionId) {
178 this.ueSessionId = ueSessionId;
179 return this;
180 }
181
182 /**
183 * Set the dataplane counter cell ID.
184 *
185 * @param ctrId PDR counter cell ID
186 * @return This builder object
187 */
188 public Builder withCounterId(int ctrId) {
189 this.ctrId = ctrId;
190 return this;
191 }
192
193 /**
194 * Set the Traffic Class.
195 *
196 * @param trafficClass Traffic Class
197 * @return This builder object
198 */
199 public Builder withTrafficClass(byte trafficClass) {
200 this.trafficClass = trafficClass;
201 return this;
202 }
203
204 /**
205 * Set the identifier of the unidirectional GTP tunnel that should be used for the UE Session.
206 *
207 * @param teid tunnel ID
208 * @return This builder object
209 */
210 public Builder withTeid(Integer teid) {
211 this.teid = teid;
212 return this;
213 }
214
215 /**
216 * Set the QoS Flow Identifier.
217 *
218 * @param qfi GTP Tunnel QFI
219 * @return This builder object
220 */
221 public Builder withQfi(byte qfi) {
222 this.qfi = qfi;
223 return this;
224 }
225
226 /**
227 * Sets whether to drop downlink UPF termination traffic or not.
228 *
229 * @param drop True if request to buffer, false otherwise
230 * @return This builder object
231 */
232 public Builder needsDropping(boolean drop) {
233 this.drop = drop;
234 return this;
235 }
236
237
238 public UpfTerminationDownlink build() {
239 // Match fields must be provided
240 checkNotNull(ueSessionId, "UE session ID must be provided");
241
242 checkNotNull(ctrId, "Counter ID must be provided");
243 // TODO: should we verify that when dropping no other fields are provided
244 return new UpfTerminationDownlink(
245 this.ueSessionId, this.ctrId, this.trafficClass, this.teid,
246 this.qfi, this.drop
247 );
248 }
249
250 }
251
252}