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 uplink 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). |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 30 | */ |
| 31 | @Beta |
| 32 | public 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 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 boolean dropping; |
| 40 | |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 41 | private UpfTerminationUplink(Ip4Address ueSessionId, byte applicationId, Integer ctrId, Byte trafficClass, |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 42 | boolean dropping) { |
| 43 | this.ueSessionId = ueSessionId; |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 44 | this.applicationId = applicationId; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 45 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 70 | Objects.equals(this.applicationId, that.applicationId) && |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 71 | Objects.equals(this.ctrId, that.ctrId) && |
| 72 | Objects.equals(this.trafficClass, that.trafficClass); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 77 | return Objects.hash(ueSessionId, applicationId, ctrId, trafficClass, dropping); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 78 | } |
| 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 90 | * 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 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 99 | * 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 132 | return "TerminationUL{" + matchString() + " -> " + actionString() + "}"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | private String matchString() { |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 136 | return "Match(ue_addr=" + this.ueSessionId() + ", app_id=" + this.applicationId() + ")"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | private String actionString() { |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 140 | String fwd = "FWD"; |
| 141 | if (this.needsDropping()) { |
| 142 | fwd = "DROP"; |
| 143 | } |
| 144 | return "(" + fwd + |
| 145 | ", CTR_ID=" + this.counterId() + |
| 146 | ", TC=" + this.trafficClass() + |
| 147 | ")"; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | public static class Builder { |
| 151 | private Ip4Address ueSessionId = null; |
Daniele Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 152 | private Byte applicationId = null; |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 153 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 173 | * 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 | /** |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 184 | * 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 208 | * @param dropping True if request to drop, false otherwise |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 209 | * @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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 219 | if (applicationId == null) { |
| 220 | applicationId = DEFAULT_APP_ID; |
| 221 | } |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 222 | 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 Moro | a1c7ba4 | 2022-01-13 19:16:34 +0100 | [diff] [blame^] | 225 | this.ueSessionId, this.applicationId, this.ctrId, |
| 226 | this.trafficClass, this.dropping |
| 227 | ); |
tosinski | 36ba33a | 2021-11-22 16:53:00 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | } |
| 231 | |
| 232 | } |