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 Session on the UPF-programmable device. |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 28 | * Provide means to set up the UPF UE Session in the downlink direction. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 29 | */ |
| 30 | @Beta |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 31 | public final class UpfSessionDownlink implements UpfEntity { |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 32 | // Match Keys |
| 33 | private final Ip4Address ueAddress; |
| 34 | // Action parameters |
| 35 | private final Byte tunPeerId; |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 36 | private final int sessionMeterIdx; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 37 | private final boolean buffering; |
| 38 | private final boolean dropping; |
| 39 | |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 40 | private UpfSessionDownlink(Ip4Address ipv4Address, |
| 41 | Byte tunPeerId, |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 42 | int sessionMeterIdx, |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 43 | boolean buffering, |
| 44 | boolean drop) { |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 45 | this.ueAddress = ipv4Address; |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 46 | this.sessionMeterIdx = sessionMeterIdx; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 47 | this.tunPeerId = tunPeerId; |
| 48 | this.buffering = buffering; |
| 49 | this.dropping = drop; |
| 50 | } |
| 51 | |
| 52 | public static Builder builder() { |
| 53 | return new Builder(); |
| 54 | } |
| 55 | |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 56 | @Override |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 57 | public boolean equals(Object object) { |
| 58 | if (object == this) { |
| 59 | return true; |
| 60 | } |
| 61 | if (object == null) { |
| 62 | return false; |
| 63 | } |
| 64 | if (getClass() != object.getClass()) { |
| 65 | return false; |
| 66 | } |
| 67 | |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 68 | UpfSessionDownlink that = (UpfSessionDownlink) object; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 69 | |
| 70 | return this.buffering == that.buffering && |
| 71 | this.dropping == that.dropping && |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 72 | this.sessionMeterIdx == that.sessionMeterIdx && |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 73 | Objects.equals(ueAddress, that.ueAddress) && |
| 74 | Objects.equals(tunPeerId, that.tunPeerId); |
| 75 | } |
| 76 | |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 77 | @Override |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 78 | public int hashCode() { |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 79 | return java.util.Objects.hash(ueAddress, sessionMeterIdx, tunPeerId, buffering, dropping); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String toString() { |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 84 | return "UpfSessionDL(" + matchString() + " -> " + actionString() + ")"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | private String matchString() { |
| 88 | return "Match(ue_addr=" + this.ueAddress() + ")"; |
| 89 | } |
| 90 | |
| 91 | private String actionString() { |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 92 | StringBuilder actionStrBuilder = new StringBuilder("Action("); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 93 | if (this.needsBuffering() && this.needsDropping()) { |
| 94 | actionStrBuilder.append("BUFF+DROP, "); |
| 95 | } else if (this.needsBuffering()) { |
| 96 | actionStrBuilder.append("BUFF, "); |
| 97 | } else if (this.needsDropping()) { |
| 98 | actionStrBuilder.append("DROP, "); |
| 99 | } else { |
| 100 | actionStrBuilder.append("FWD, "); |
| 101 | } |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 102 | return actionStrBuilder.append(" tun_peer=").append(this.tunPeerId()) |
| 103 | .append(", session_meter_idx=").append(this.sessionMeterIdx()).append(")") |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 104 | .toString(); |
| 105 | } |
| 106 | |
| 107 | /** |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 108 | * True if this UPF UE Session needs buffering of the downlink traffic. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 109 | * |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 110 | * @return true if the UPF UE Session needs buffering. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 111 | */ |
| 112 | public boolean needsBuffering() { |
| 113 | return buffering; |
| 114 | } |
| 115 | |
| 116 | /** |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 117 | * True if this UPF UE Session needs dropping of the downlink traffic. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 118 | * |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 119 | * @return true if the UPF UE Session needs dropping. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 120 | */ |
| 121 | public boolean needsDropping() { |
| 122 | return dropping; |
| 123 | } |
| 124 | |
| 125 | /** |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 126 | * Get the UE IP address of this downlink UPF UE session. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 127 | * |
| 128 | * @return UE IP address |
| 129 | */ |
| 130 | public Ip4Address ueAddress() { |
| 131 | return ueAddress; |
| 132 | } |
| 133 | |
| 134 | /** |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 135 | * Get the GTP tunnel peer ID that is set by this UPF UE Session rule. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 136 | * |
| 137 | * @return GTP tunnel peer ID |
| 138 | */ |
| 139 | public Byte tunPeerId() { |
| 140 | return tunPeerId; |
| 141 | } |
| 142 | |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 143 | /** |
| 144 | * Get the session meter index that is set by this UPF UE Session rule. |
| 145 | * |
| 146 | * @return Session meter index |
| 147 | */ |
| 148 | public int sessionMeterIdx() { |
| 149 | return this.sessionMeterIdx; |
| 150 | } |
| 151 | |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 152 | @Override |
| 153 | public UpfEntityType type() { |
| 154 | return UpfEntityType.SESSION_DOWNLINK; |
| 155 | } |
| 156 | |
| 157 | public static class Builder { |
| 158 | private Ip4Address ueAddress = null; |
| 159 | private Byte tunPeerId = null; |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 160 | private int sessionMeterIdx = DEFAULT_SESSION_INDEX; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 161 | private boolean buffer = false; |
| 162 | private boolean drop = false; |
| 163 | |
| 164 | public Builder() { |
| 165 | |
| 166 | } |
| 167 | |
| 168 | /** |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 169 | * Sets the UE IP address that this downlink UPF UE session rule matches on. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 170 | * |
| 171 | * @param ueAddress UE IP address |
| 172 | * @return This builder object |
| 173 | */ |
| 174 | public Builder withUeAddress(Ip4Address ueAddress) { |
| 175 | this.ueAddress = ueAddress; |
| 176 | return this; |
| 177 | } |
| 178 | |
| 179 | /** |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 180 | * Sets the GTP tunnel peer ID that is set by this UPF UE Session rule. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 181 | * |
| 182 | * @param tunnelPeerId GTP tunnel peer ID |
| 183 | * @return This builder object |
| 184 | */ |
| 185 | public Builder withGtpTunnelPeerId(Byte tunnelPeerId) { |
| 186 | this.tunPeerId = tunnelPeerId; |
| 187 | return this; |
| 188 | } |
| 189 | |
| 190 | /** |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 191 | * Sets whether to buffer downlink UPF UE session traffic or not. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 192 | * |
| 193 | * @param buffer True if request to buffer, false otherwise |
| 194 | * @return This builder object |
| 195 | */ |
| 196 | public Builder needsBuffering(boolean buffer) { |
| 197 | this.buffer = buffer; |
| 198 | return this; |
| 199 | } |
| 200 | |
| 201 | /** |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 202 | * Sets whether to drop downlink UPF UE session traffic or not. |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 203 | * |
| 204 | * @param drop True if request to buffer, false otherwise |
| 205 | * @return This builder object |
| 206 | */ |
| 207 | public Builder needsDropping(boolean drop) { |
| 208 | this.drop = drop; |
| 209 | return this; |
| 210 | } |
| 211 | |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 212 | /** |
| 213 | * Sets the meter index associated with this UE session. |
| 214 | * If not set, default to {@link UpfEntity#DEFAULT_SESSION_INDEX}. |
| 215 | * |
| 216 | * @param sessionMeterIdx Session meter index |
| 217 | * @return This builder object |
| 218 | */ |
| 219 | public Builder withSessionMeterIdx(int sessionMeterIdx) { |
| 220 | this.sessionMeterIdx = sessionMeterIdx; |
| 221 | return this; |
| 222 | } |
| 223 | |
Daniele Moro | f3a5ab0 | 2022-01-26 16:47:08 +0100 | [diff] [blame] | 224 | public UpfSessionDownlink build() { |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 225 | // Match fields are required |
| 226 | checkNotNull(ueAddress, "UE address must be provided"); |
Daniele Moro | 909b958 | 2022-01-26 15:47:29 +0100 | [diff] [blame] | 227 | return new UpfSessionDownlink(ueAddress, tunPeerId, sessionMeterIdx, buffer, drop); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | } |