blob: cbb601b30950d2d760d7107b0087e55ddf2c37c3 [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.
Daniele Moroa1c7ba42022-01-13 19:16:34 +010029 * Provide means to configure the traffic behavior (e.g. set Traffic Class, GTP TEID, or QFI).
tosinski36ba33a2021-11-22 16:53:00 +010030 */
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.
Daniele Moroa1c7ba42022-01-13 19:16:34 +010035 private final byte applicationId; // Application ID, defaults to DEFAULT_APP_ID
tosinski36ba33a2021-11-22 16:53:00 +010036 // Action parameters
37 private final Integer ctrId; // Counter ID unique to this UPF Termination Rule
38 private final Byte trafficClass;
39 private final Integer teid; // Tunnel Endpoint Identifier
40 private final Byte qfi; // QoS Flow Identifier
41 private final boolean dropping;
42
Daniele Moroa1c7ba42022-01-13 19:16:34 +010043 private UpfTerminationDownlink(Ip4Address ueSessionId, byte applicationId, Integer ctrId, Byte trafficClass,
tosinski36ba33a2021-11-22 16:53:00 +010044 Integer teid, Byte qfi, boolean dropping) {
45 this.ueSessionId = ueSessionId;
Daniele Moroa1c7ba42022-01-13 19:16:34 +010046 this.applicationId = applicationId;
tosinski36ba33a2021-11-22 16:53:00 +010047 this.ctrId = ctrId;
48 this.trafficClass = trafficClass;
49 this.teid = teid;
50 this.qfi = qfi;
51 this.dropping = dropping;
52 }
53
54 public static Builder builder() {
55 return new Builder();
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (obj == this) {
61 return true;
62 }
63 if (obj == null) {
64 return false;
65 }
66 if (getClass() != obj.getClass()) {
67 return false;
68 }
69 UpfTerminationDownlink that = (UpfTerminationDownlink) obj;
70
71 // Safe comparisons between potentially null objects
72 return this.dropping == that.dropping &&
73 Objects.equals(this.ueSessionId, that.ueSessionId) &&
Daniele Moroa1c7ba42022-01-13 19:16:34 +010074 Objects.equals(this.applicationId, that.applicationId) &&
tosinski36ba33a2021-11-22 16:53:00 +010075 Objects.equals(this.ctrId, that.ctrId) &&
76 Objects.equals(this.trafficClass, that.trafficClass) &&
77 Objects.equals(this.teid, that.teid) &&
78 Objects.equals(this.qfi, that.qfi);
79 }
80
81 @Override
82 public int hashCode() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +010083 return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, teid, qfi, dropping);
tosinski36ba33a2021-11-22 16:53:00 +010084 }
85
86 /**
87 * Get UE Session ID associated with UPF Termination rule.
88 *
89 * @return UE Session ID
90 */
91 public Ip4Address ueSessionId() {
92 return ueSessionId;
93 }
94
95 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +010096 * Get the application ID associated with UPF Termination rule.
97 *
98 * @return the application ID
99 */
100 public byte applicationId() {
101 return applicationId;
102 }
103
104 /**
tosinski36ba33a2021-11-22 16:53:00 +0100105 * Get PDR Counter ID associated with UPF Termination rule.
106 *
107 * @return PDR counter cell ID
108 */
109 public Integer counterId() {
110 return ctrId;
111 }
112
113 /**
114 * Get Traffic Class set by this UPF Termination rule.
115 *
116 * @return Traffic Class
117 */
118 public Byte trafficClass() {
119 return trafficClass;
120 }
121
122 /**
123 * Get GTP TEID set by this UPF Termination rule.
124 *
125 * @return GTP tunnel ID
126 */
127 public Integer teid() {
128 return teid;
129 }
130
131 /**
132 * Get QoS Flow Identifier set by this UPF Termination rule.
133 *
134 * @return QoS Flow Identifier
135 */
136 public Byte qfi() {
137 return qfi;
138 }
139
140 /**
141 * True if this UPF Termination needs to drop traffic.
142 *
143 * @return true if the UPF Termination needs dropping.
144 */
145 public boolean needsDropping() {
146 return dropping;
147 }
148
149 @Override
150 public UpfEntityType type() {
151 return UpfEntityType.TERMINATION_DOWNLINK;
152 }
153
154 @Override
155 public String toString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100156 return "TerminationDL{" + matchString() + " -> " + actionString() + "}";
tosinski36ba33a2021-11-22 16:53:00 +0100157 }
158
159 private String matchString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100160 return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId + ")";
tosinski36ba33a2021-11-22 16:53:00 +0100161 }
162
163 private String actionString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100164 String fwd = "FWD";
165 if (this.needsDropping()) {
166 fwd = "DROP";
167 }
168 return "(" + fwd +
169 ", TEID=" + this.teid() +
tosinski36ba33a2021-11-22 16:53:00 +0100170 ", CTR_ID=" + this.counterId() +
171 ", QFI=" + this.qfi() +
172 ", TC=" + this.trafficClass() +
173 ")";
174 }
175
176 public static class Builder {
177 private Ip4Address ueSessionId = null;
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100178 private Byte applicationId = null;
tosinski36ba33a2021-11-22 16:53:00 +0100179 private Integer ctrId = null;
180 private Byte trafficClass = null;
181 private Integer teid = null;
182 private Byte qfi = null;
183 private boolean drop = false;
184
185 public Builder() {
186
187 }
188
189 /**
190 * Set the ID of the UE session.
191 *
192 * @param ueSessionId UE session ID
193 * @return This builder object
194 */
195 public Builder withUeSessionId(Ip4Address ueSessionId) {
196 this.ueSessionId = ueSessionId;
197 return this;
198 }
199
200 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100201 * Set the ID of the application.
202 *
203 * @param applicationId Application ID
204 * @return This builder object
205 */
206 public Builder withApplicationId(byte applicationId) {
207 this.applicationId = applicationId;
208 return this;
209 }
210
211 /**
tosinski36ba33a2021-11-22 16:53:00 +0100212 * Set the dataplane counter cell ID.
213 *
214 * @param ctrId PDR counter cell ID
215 * @return This builder object
216 */
217 public Builder withCounterId(int ctrId) {
218 this.ctrId = ctrId;
219 return this;
220 }
221
222 /**
223 * Set the Traffic Class.
224 *
225 * @param trafficClass Traffic Class
226 * @return This builder object
227 */
228 public Builder withTrafficClass(byte trafficClass) {
229 this.trafficClass = trafficClass;
230 return this;
231 }
232
233 /**
234 * Set the identifier of the unidirectional GTP tunnel that should be used for the UE Session.
235 *
236 * @param teid tunnel ID
237 * @return This builder object
238 */
239 public Builder withTeid(Integer teid) {
240 this.teid = teid;
241 return this;
242 }
243
244 /**
245 * Set the QoS Flow Identifier.
246 *
247 * @param qfi GTP Tunnel QFI
248 * @return This builder object
249 */
250 public Builder withQfi(byte qfi) {
251 this.qfi = qfi;
252 return this;
253 }
254
255 /**
256 * Sets whether to drop downlink UPF termination traffic or not.
257 *
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100258 * @param drop True if request to drop, false otherwise
tosinski36ba33a2021-11-22 16:53:00 +0100259 * @return This builder object
260 */
261 public Builder needsDropping(boolean drop) {
262 this.drop = drop;
263 return this;
264 }
265
tosinski36ba33a2021-11-22 16:53:00 +0100266 public UpfTerminationDownlink build() {
267 // Match fields must be provided
268 checkNotNull(ueSessionId, "UE session ID must be provided");
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100269 if (applicationId == null) {
270 applicationId = DEFAULT_APP_ID;
271 }
tosinski36ba33a2021-11-22 16:53:00 +0100272 checkNotNull(ctrId, "Counter ID must be provided");
273 // TODO: should we verify that when dropping no other fields are provided
274 return new UpfTerminationDownlink(
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100275 this.ueSessionId, this.applicationId, this.ctrId, this.trafficClass,
276 this.teid, this.qfi, this.drop
tosinski36ba33a2021-11-22 16:53:00 +0100277 );
278 }
279
280 }
281
282}