blob: ddec2e4946f650908ffcac0e138bbb8cf0486c8d [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 uplink 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).
tosinski36ba33a2021-11-22 16:53:00 +010030 */
31@Beta
32public final class UpfTerminationUplink 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;
Daniele Moro909b9582022-01-26 15:47:29 +010039 private final int appMeterIdx;
tosinski36ba33a2021-11-22 16:53:00 +010040 private final boolean dropping;
41
Daniele Moro909b9582022-01-26 15:47:29 +010042 private UpfTerminationUplink(Ip4Address ueSessionId, byte applicationId,
43 Integer ctrId, Byte trafficClass,
44 int appMeterIdx, boolean dropping) {
tosinski36ba33a2021-11-22 16:53:00 +010045 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;
Daniele Moro909b9582022-01-26 15:47:29 +010049 this.appMeterIdx = appMeterIdx;
tosinski36ba33a2021-11-22 16:53:00 +010050 this.dropping = dropping;
51 }
52
53 public static Builder builder() {
54 return new Builder();
55 }
56
57 @Override
58 public boolean equals(Object obj) {
59 if (obj == this) {
60 return true;
61 }
62 if (obj == null) {
63 return false;
64 }
65 if (getClass() != obj.getClass()) {
66 return false;
67 }
68 UpfTerminationUplink that = (UpfTerminationUplink) obj;
69
70 // Safe comparisons between potentially null objects
71 return this.dropping == that.dropping &&
72 Objects.equals(this.ueSessionId, that.ueSessionId) &&
Daniele Moroa1c7ba42022-01-13 19:16:34 +010073 Objects.equals(this.applicationId, that.applicationId) &&
tosinski36ba33a2021-11-22 16:53:00 +010074 Objects.equals(this.ctrId, that.ctrId) &&
Daniele Moro909b9582022-01-26 15:47:29 +010075 this.appMeterIdx == that.appMeterIdx &&
tosinski36ba33a2021-11-22 16:53:00 +010076 Objects.equals(this.trafficClass, that.trafficClass);
77 }
78
79 @Override
80 public int hashCode() {
Daniele Moro909b9582022-01-26 15:47:29 +010081 return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, appMeterIdx, dropping);
tosinski36ba33a2021-11-22 16:53:00 +010082 }
83
84 /**
85 * Get UE Session ID associated with UPF Termination rule.
86 *
87 * @return UE Session ID
88 */
89 public Ip4Address ueSessionId() {
90 return ueSessionId;
91 }
92
93 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +010094 * Get the application ID associated with UPF Termination rule.
95 *
96 * @return Application ID
97 */
98 public byte applicationId() {
99 return applicationId;
100 }
101
102 /**
tosinski36ba33a2021-11-22 16:53:00 +0100103 * Get PDR Counter ID associated with UPF Termination rule.
104 *
105 * @return PDR counter cell ID
106 */
107 public Integer counterId() {
108 return ctrId;
109 }
110
111 /**
112 * Get Traffic Class set by this UPF Termination rule.
113 *
114 * @return Traffic Class
115 */
116 public Byte trafficClass() {
117 return trafficClass;
118 }
119
120 /**
121 * True if this UPF Termination needs to drop traffic.
122 *
123 * @return true if the UPF Termination needs dropping.
124 */
125 public boolean needsDropping() {
126 return dropping;
127 }
128
Daniele Moro909b9582022-01-26 15:47:29 +0100129 /**
130 * Get the app meter index set by this UPF Termination rule.
131 *
132 * @return App meter index
133 */
134 public int appMeterIdx() {
135 return appMeterIdx;
136 }
137
tosinski36ba33a2021-11-22 16:53:00 +0100138 @Override
139 public UpfEntityType type() {
140 return UpfEntityType.TERMINATION_UPLINK;
141 }
142
143 @Override
144 public String toString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +0100145 return "UpfTerminationUL(" + matchString() + " -> " + actionString() + ")";
tosinski36ba33a2021-11-22 16:53:00 +0100146 }
147
148 private String matchString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100149 return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId() + ")";
tosinski36ba33a2021-11-22 16:53:00 +0100150 }
151
152 private String actionString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100153 String fwd = "FWD";
154 if (this.needsDropping()) {
155 fwd = "DROP";
156 }
Daniele Morof3a5ab02022-01-26 16:47:08 +0100157 return "Action(" + fwd +
158 ", ctr_id=" + this.counterId() +
159 ", tc=" + this.trafficClass() +
Daniele Moro909b9582022-01-26 15:47:29 +0100160 ", app_meter_idx=" + this.appMeterIdx() +
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100161 ")";
tosinski36ba33a2021-11-22 16:53:00 +0100162 }
163
164 public static class Builder {
165 private Ip4Address ueSessionId = null;
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100166 private Byte applicationId = null;
tosinski36ba33a2021-11-22 16:53:00 +0100167 private Integer ctrId = null;
168 private Byte trafficClass = null;
Daniele Moro909b9582022-01-26 15:47:29 +0100169 private int appMeterIdx = DEFAULT_APP_INDEX;
tosinski36ba33a2021-11-22 16:53:00 +0100170 private boolean dropping = false;
171
172 public Builder() {
173
174 }
175
176 /**
177 * Set the ID of the UE session.
178 *
179 * @param ueSessionId UE session ID
180 * @return This builder object
181 */
182 public Builder withUeSessionId(Ip4Address ueSessionId) {
183 this.ueSessionId = ueSessionId;
184 return this;
185 }
186
187 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100188 * Set the ID of the application.
Daniele Moro909b9582022-01-26 15:47:29 +0100189 * If not set, default to {@link UpfEntity#DEFAULT_APP_ID}.
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100190 *
191 * @param applicationId Application ID
192 * @return This builder object
193 */
194 public Builder withApplicationId(byte applicationId) {
195 this.applicationId = applicationId;
196 return this;
197 }
198
199 /**
tosinski36ba33a2021-11-22 16:53:00 +0100200 * Set the dataplane counter cell ID.
201 *
202 * @param ctrId PDR counter cell ID
203 * @return This builder object
204 */
205 public Builder withCounterId(int ctrId) {
206 this.ctrId = ctrId;
207 return this;
208 }
209
210 /**
211 * Set the Traffic Class.
212 *
213 * @param trafficClass Traffic Class
214 * @return This builder object
215 */
216 public Builder withTrafficClass(byte trafficClass) {
217 this.trafficClass = trafficClass;
218 return this;
219 }
220
221 /**
222 * Sets whether to drop uplink UPF termination traffic or not.
223 *
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100224 * @param dropping True if request to drop, false otherwise
tosinski36ba33a2021-11-22 16:53:00 +0100225 * @return This builder object
226 */
227 public Builder needsDropping(boolean dropping) {
228 this.dropping = dropping;
229 return this;
230 }
231
Daniele Moro909b9582022-01-26 15:47:29 +0100232 /**
233 * Sets the app meter index.
234 * If not set, default to {@link UpfEntity#DEFAULT_APP_INDEX}.
235 *
236 * @param appMeterIdx App meter index
237 * @return This builder object
238 */
239 public Builder withAppMeterIdx(int appMeterIdx) {
240 this.appMeterIdx = appMeterIdx;
241 return this;
242 }
243
tosinski36ba33a2021-11-22 16:53:00 +0100244 public UpfTerminationUplink build() {
245 // Match fields must be provided
246 checkNotNull(ueSessionId, "UE session ID must be provided");
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100247 if (applicationId == null) {
248 applicationId = DEFAULT_APP_ID;
249 }
tosinski36ba33a2021-11-22 16:53:00 +0100250 checkNotNull(ctrId, "Counter ID must be provided");
251 // TODO: should we verify that when dropping no other fields are provided
252 return new UpfTerminationUplink(
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100253 this.ueSessionId, this.applicationId, this.ctrId,
Daniele Moro909b9582022-01-26 15:47:29 +0100254 this.trafficClass, this.appMeterIdx, this.dropping
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100255 );
tosinski36ba33a2021-11-22 16:53:00 +0100256 }
257
258 }
259
260}