tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.behaviour.upf; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onlab.packet.Ip4Address; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | import 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 29 | * Provide means to configure the traffic behavior (e.g. set Traffic Class, GTP TEID, or QFI). |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 30 | */ |
| 31 | @Beta |
| 32 | public 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 35 | private final byte applicationId; // Application ID, defaults to DEFAULT_APP_ID |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 36 | // 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 43 | private UpfTerminationDownlink(Ip4Address ueSessionId, byte applicationId, Integer ctrId, Byte trafficClass, |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 44 | Integer teid, Byte qfi, boolean dropping) { |
| 45 | this.ueSessionId = ueSessionId; |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 46 | this.applicationId = applicationId; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 47 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 74 | Objects.equals(this.applicationId, that.applicationId) && |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 75 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 83 | return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, teid, qfi, dropping); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 84 | } |
| 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 96 | * 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 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 105 | * 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 Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame^] | 156 | return "UpfTerminationDL(" + matchString() + " -> " + actionString() + ")"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private String matchString() { |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 160 | return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId + ")"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | private String actionString() { |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 164 | String fwd = "FWD"; |
| 165 | if (this.needsDropping()) { |
| 166 | fwd = "DROP"; |
| 167 | } |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame^] | 168 | return "Action(" + fwd + |
| 169 | ", teid=" + this.teid() + |
| 170 | ", ctr_id=" + this.counterId() + |
| 171 | ", qfi=" + this.qfi() + |
| 172 | ", tc=" + this.trafficClass() + |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 173 | ")"; |
| 174 | } |
| 175 | |
| 176 | public static class Builder { |
| 177 | private Ip4Address ueSessionId = null; |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 178 | private Byte applicationId = null; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 179 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 201 | * 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 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 212 | * 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 258 | * @param drop True if request to drop, false otherwise |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 259 | * @return This builder object |
| 260 | */ |
| 261 | public Builder needsDropping(boolean drop) { |
| 262 | this.drop = drop; |
| 263 | return this; |
| 264 | } |
| 265 | |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 266 | public UpfTerminationDownlink build() { |
| 267 | // Match fields must be provided |
| 268 | checkNotNull(ueSessionId, "UE session ID must be provided"); |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 269 | if (applicationId == null) { |
| 270 | applicationId = DEFAULT_APP_ID; |
| 271 | } |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 272 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame] | 275 | this.ueSessionId, this.applicationId, this.ctrId, this.trafficClass, |
| 276 | this.teid, this.qfi, this.drop |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 277 | ); |
| 278 | } |
| 279 | |
| 280 | } |
| 281 | |
| 282 | } |