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