blob: 02a8a547fe01d01c40c4eb054fd39cb30343249f [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 Session on the UPF-programmable device.
Daniele Morof3a5ab02022-01-26 16:47:08 +010028 * Provide means to set up the UPF UE Session in the downlink direction.
tosinski36ba33a2021-11-22 16:53:00 +010029 */
30@Beta
Daniele Morof3a5ab02022-01-26 16:47:08 +010031public final class UpfSessionDownlink implements UpfEntity {
tosinski36ba33a2021-11-22 16:53:00 +010032 // Match Keys
33 private final Ip4Address ueAddress;
34 // Action parameters
35 private final Byte tunPeerId;
Daniele Moro909b9582022-01-26 15:47:29 +010036 private final int sessionMeterIdx;
tosinski36ba33a2021-11-22 16:53:00 +010037 private final boolean buffering;
38 private final boolean dropping;
39
Daniele Morof3a5ab02022-01-26 16:47:08 +010040 private UpfSessionDownlink(Ip4Address ipv4Address,
41 Byte tunPeerId,
Daniele Moro909b9582022-01-26 15:47:29 +010042 int sessionMeterIdx,
Daniele Morof3a5ab02022-01-26 16:47:08 +010043 boolean buffering,
44 boolean drop) {
tosinski36ba33a2021-11-22 16:53:00 +010045 this.ueAddress = ipv4Address;
Daniele Moro909b9582022-01-26 15:47:29 +010046 this.sessionMeterIdx = sessionMeterIdx;
tosinski36ba33a2021-11-22 16:53:00 +010047 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 Morof3a5ab02022-01-26 16:47:08 +010056 @Override
tosinski36ba33a2021-11-22 16:53:00 +010057 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 Morof3a5ab02022-01-26 16:47:08 +010068 UpfSessionDownlink that = (UpfSessionDownlink) object;
tosinski36ba33a2021-11-22 16:53:00 +010069
70 return this.buffering == that.buffering &&
71 this.dropping == that.dropping &&
Daniele Moro909b9582022-01-26 15:47:29 +010072 this.sessionMeterIdx == that.sessionMeterIdx &&
tosinski36ba33a2021-11-22 16:53:00 +010073 Objects.equals(ueAddress, that.ueAddress) &&
74 Objects.equals(tunPeerId, that.tunPeerId);
75 }
76
Daniele Morof3a5ab02022-01-26 16:47:08 +010077 @Override
tosinski36ba33a2021-11-22 16:53:00 +010078 public int hashCode() {
Daniele Moro909b9582022-01-26 15:47:29 +010079 return java.util.Objects.hash(ueAddress, sessionMeterIdx, tunPeerId, buffering, dropping);
tosinski36ba33a2021-11-22 16:53:00 +010080 }
81
82 @Override
83 public String toString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010084 return "UpfSessionDL(" + matchString() + " -> " + actionString() + ")";
tosinski36ba33a2021-11-22 16:53:00 +010085 }
86
87 private String matchString() {
88 return "Match(ue_addr=" + this.ueAddress() + ")";
89 }
90
91 private String actionString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010092 StringBuilder actionStrBuilder = new StringBuilder("Action(");
tosinski36ba33a2021-11-22 16:53:00 +010093 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 Moro909b9582022-01-26 15:47:29 +0100102 return actionStrBuilder.append(" tun_peer=").append(this.tunPeerId())
103 .append(", session_meter_idx=").append(this.sessionMeterIdx()).append(")")
tosinski36ba33a2021-11-22 16:53:00 +0100104 .toString();
105 }
106
107 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100108 * True if this UPF UE Session needs buffering of the downlink traffic.
tosinski36ba33a2021-11-22 16:53:00 +0100109 *
Daniele Morof3a5ab02022-01-26 16:47:08 +0100110 * @return true if the UPF UE Session needs buffering.
tosinski36ba33a2021-11-22 16:53:00 +0100111 */
112 public boolean needsBuffering() {
113 return buffering;
114 }
115
116 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100117 * True if this UPF UE Session needs dropping of the downlink traffic.
tosinski36ba33a2021-11-22 16:53:00 +0100118 *
Daniele Morof3a5ab02022-01-26 16:47:08 +0100119 * @return true if the UPF UE Session needs dropping.
tosinski36ba33a2021-11-22 16:53:00 +0100120 */
121 public boolean needsDropping() {
122 return dropping;
123 }
124
125 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100126 * Get the UE IP address of this downlink UPF UE session.
tosinski36ba33a2021-11-22 16:53:00 +0100127 *
128 * @return UE IP address
129 */
130 public Ip4Address ueAddress() {
131 return ueAddress;
132 }
133
134 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100135 * Get the GTP tunnel peer ID that is set by this UPF UE Session rule.
tosinski36ba33a2021-11-22 16:53:00 +0100136 *
137 * @return GTP tunnel peer ID
138 */
139 public Byte tunPeerId() {
140 return tunPeerId;
141 }
142
Daniele Moro909b9582022-01-26 15:47:29 +0100143 /**
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
tosinski36ba33a2021-11-22 16:53:00 +0100152 @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 Moro909b9582022-01-26 15:47:29 +0100160 private int sessionMeterIdx = DEFAULT_SESSION_INDEX;
tosinski36ba33a2021-11-22 16:53:00 +0100161 private boolean buffer = false;
162 private boolean drop = false;
163
164 public Builder() {
165
166 }
167
168 /**
Daniele Moro909b9582022-01-26 15:47:29 +0100169 * Sets the UE IP address that this downlink UPF UE session rule matches on.
tosinski36ba33a2021-11-22 16:53:00 +0100170 *
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 Moro909b9582022-01-26 15:47:29 +0100180 * Sets the GTP tunnel peer ID that is set by this UPF UE Session rule.
tosinski36ba33a2021-11-22 16:53:00 +0100181 *
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 Moro909b9582022-01-26 15:47:29 +0100191 * Sets whether to buffer downlink UPF UE session traffic or not.
tosinski36ba33a2021-11-22 16:53:00 +0100192 *
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 Moro909b9582022-01-26 15:47:29 +0100202 * Sets whether to drop downlink UPF UE session traffic or not.
tosinski36ba33a2021-11-22 16:53:00 +0100203 *
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 Moro909b9582022-01-26 15:47:29 +0100212 /**
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 Morof3a5ab02022-01-26 16:47:08 +0100224 public UpfSessionDownlink build() {
tosinski36ba33a2021-11-22 16:53:00 +0100225 // Match fields are required
226 checkNotNull(ueAddress, "UE address must be provided");
Daniele Moro909b9582022-01-26 15:47:29 +0100227 return new UpfSessionDownlink(ueAddress, tunPeerId, sessionMeterIdx, buffer, drop);
tosinski36ba33a2021-11-22 16:53:00 +0100228 }
229 }
230}