blob: 1c6dd56491bb344d10f2788ca5720a288a400b40 [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;
39 private final boolean dropping;
40
Daniele Moroa1c7ba42022-01-13 19:16:34 +010041 private UpfTerminationUplink(Ip4Address ueSessionId, byte applicationId, Integer ctrId, Byte trafficClass,
tosinski36ba33a2021-11-22 16:53:00 +010042 boolean dropping) {
43 this.ueSessionId = ueSessionId;
Daniele Moroa1c7ba42022-01-13 19:16:34 +010044 this.applicationId = applicationId;
tosinski36ba33a2021-11-22 16:53:00 +010045 this.ctrId = ctrId;
46 this.trafficClass = trafficClass;
47 this.dropping = dropping;
48 }
49
50 public static Builder builder() {
51 return new Builder();
52 }
53
54 @Override
55 public boolean equals(Object obj) {
56 if (obj == this) {
57 return true;
58 }
59 if (obj == null) {
60 return false;
61 }
62 if (getClass() != obj.getClass()) {
63 return false;
64 }
65 UpfTerminationUplink that = (UpfTerminationUplink) obj;
66
67 // Safe comparisons between potentially null objects
68 return this.dropping == that.dropping &&
69 Objects.equals(this.ueSessionId, that.ueSessionId) &&
Daniele Moroa1c7ba42022-01-13 19:16:34 +010070 Objects.equals(this.applicationId, that.applicationId) &&
tosinski36ba33a2021-11-22 16:53:00 +010071 Objects.equals(this.ctrId, that.ctrId) &&
72 Objects.equals(this.trafficClass, that.trafficClass);
73 }
74
75 @Override
76 public int hashCode() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +010077 return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, dropping);
tosinski36ba33a2021-11-22 16:53:00 +010078 }
79
80 /**
81 * Get UE Session ID associated with UPF Termination rule.
82 *
83 * @return UE Session ID
84 */
85 public Ip4Address ueSessionId() {
86 return ueSessionId;
87 }
88
89 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +010090 * Get the application ID associated with UPF Termination rule.
91 *
92 * @return Application ID
93 */
94 public byte applicationId() {
95 return applicationId;
96 }
97
98 /**
tosinski36ba33a2021-11-22 16:53:00 +010099 * Get PDR Counter ID associated with UPF Termination rule.
100 *
101 * @return PDR counter cell ID
102 */
103 public Integer counterId() {
104 return ctrId;
105 }
106
107 /**
108 * Get Traffic Class set by this UPF Termination rule.
109 *
110 * @return Traffic Class
111 */
112 public Byte trafficClass() {
113 return trafficClass;
114 }
115
116 /**
117 * True if this UPF Termination needs to drop traffic.
118 *
119 * @return true if the UPF Termination needs dropping.
120 */
121 public boolean needsDropping() {
122 return dropping;
123 }
124
125 @Override
126 public UpfEntityType type() {
127 return UpfEntityType.TERMINATION_UPLINK;
128 }
129
130 @Override
131 public String toString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100132 return "TerminationUL{" + matchString() + " -> " + actionString() + "}";
tosinski36ba33a2021-11-22 16:53:00 +0100133 }
134
135 private String matchString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100136 return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId() + ")";
tosinski36ba33a2021-11-22 16:53:00 +0100137 }
138
139 private String actionString() {
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100140 String fwd = "FWD";
141 if (this.needsDropping()) {
142 fwd = "DROP";
143 }
144 return "(" + fwd +
145 ", CTR_ID=" + this.counterId() +
146 ", TC=" + this.trafficClass() +
147 ")";
tosinski36ba33a2021-11-22 16:53:00 +0100148 }
149
150 public static class Builder {
151 private Ip4Address ueSessionId = null;
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100152 private Byte applicationId = null;
tosinski36ba33a2021-11-22 16:53:00 +0100153 private Integer ctrId = null;
154 private Byte trafficClass = null;
155 private boolean dropping = false;
156
157 public Builder() {
158
159 }
160
161 /**
162 * Set the ID of the UE session.
163 *
164 * @param ueSessionId UE session ID
165 * @return This builder object
166 */
167 public Builder withUeSessionId(Ip4Address ueSessionId) {
168 this.ueSessionId = ueSessionId;
169 return this;
170 }
171
172 /**
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100173 * Set the ID of the application.
174 *
175 * @param applicationId Application ID
176 * @return This builder object
177 */
178 public Builder withApplicationId(byte applicationId) {
179 this.applicationId = applicationId;
180 return this;
181 }
182
183 /**
tosinski36ba33a2021-11-22 16:53:00 +0100184 * Set the dataplane counter cell ID.
185 *
186 * @param ctrId PDR counter cell ID
187 * @return This builder object
188 */
189 public Builder withCounterId(int ctrId) {
190 this.ctrId = ctrId;
191 return this;
192 }
193
194 /**
195 * Set the Traffic Class.
196 *
197 * @param trafficClass Traffic Class
198 * @return This builder object
199 */
200 public Builder withTrafficClass(byte trafficClass) {
201 this.trafficClass = trafficClass;
202 return this;
203 }
204
205 /**
206 * Sets whether to drop uplink UPF termination traffic or not.
207 *
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100208 * @param dropping True if request to drop, false otherwise
tosinski36ba33a2021-11-22 16:53:00 +0100209 * @return This builder object
210 */
211 public Builder needsDropping(boolean dropping) {
212 this.dropping = dropping;
213 return this;
214 }
215
216 public UpfTerminationUplink build() {
217 // Match fields must be provided
218 checkNotNull(ueSessionId, "UE session ID must be provided");
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100219 if (applicationId == null) {
220 applicationId = DEFAULT_APP_ID;
221 }
tosinski36ba33a2021-11-22 16:53:00 +0100222 checkNotNull(ctrId, "Counter ID must be provided");
223 // TODO: should we verify that when dropping no other fields are provided
224 return new UpfTerminationUplink(
Daniele Moroa1c7ba42022-01-13 19:16:34 +0100225 this.ueSessionId, this.applicationId, this.ctrId,
226 this.trafficClass, this.dropping
227 );
tosinski36ba33a2021-11-22 16:53:00 +0100228 }
229
230 }
231
232}