blob: 413c7ed4eba140bfbb351f9711208ac3c3e02419 [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;
36 private final boolean buffering;
37 private final boolean dropping;
38
Daniele Morof3a5ab02022-01-26 16:47:08 +010039 private UpfSessionDownlink(Ip4Address ipv4Address,
40 Byte tunPeerId,
41 boolean buffering,
42 boolean drop) {
tosinski36ba33a2021-11-22 16:53:00 +010043 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 Morof3a5ab02022-01-26 16:47:08 +010053 @Override
tosinski36ba33a2021-11-22 16:53:00 +010054 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 Morof3a5ab02022-01-26 16:47:08 +010065 UpfSessionDownlink that = (UpfSessionDownlink) object;
tosinski36ba33a2021-11-22 16:53:00 +010066
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 Morof3a5ab02022-01-26 16:47:08 +010073 @Override
tosinski36ba33a2021-11-22 16:53:00 +010074 public int hashCode() {
75 return java.util.Objects.hash(ueAddress, tunPeerId, buffering, dropping);
76 }
77
78 @Override
79 public String toString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010080 return "UpfSessionDL(" + matchString() + " -> " + actionString() + ")";
tosinski36ba33a2021-11-22 16:53:00 +010081 }
82
83 private String matchString() {
84 return "Match(ue_addr=" + this.ueAddress() + ")";
85 }
86
87 private String actionString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010088 StringBuilder actionStrBuilder = new StringBuilder("Action(");
tosinski36ba33a2021-11-22 16:53:00 +010089 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 Morof3a5ab02022-01-26 16:47:08 +0100103 * True if this UPF UE Session needs buffering of the downlink traffic.
tosinski36ba33a2021-11-22 16:53:00 +0100104 *
Daniele Morof3a5ab02022-01-26 16:47:08 +0100105 * @return true if the UPF UE Session needs buffering.
tosinski36ba33a2021-11-22 16:53:00 +0100106 */
107 public boolean needsBuffering() {
108 return buffering;
109 }
110
111 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100112 * True if this UPF UE Session needs dropping of the downlink traffic.
tosinski36ba33a2021-11-22 16:53:00 +0100113 *
Daniele Morof3a5ab02022-01-26 16:47:08 +0100114 * @return true if the UPF UE Session needs dropping.
tosinski36ba33a2021-11-22 16:53:00 +0100115 */
116 public boolean needsDropping() {
117 return dropping;
118 }
119
120 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100121 * Get the UE IP address of this downlink UPF UE session.
tosinski36ba33a2021-11-22 16:53:00 +0100122 *
123 * @return UE IP address
124 */
125 public Ip4Address ueAddress() {
126 return ueAddress;
127 }
128
129 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100130 * Get the GTP tunnel peer ID that is set by this UPF UE Session rule.
tosinski36ba33a2021-11-22 16:53:00 +0100131 *
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 Morof3a5ab02022-01-26 16:47:08 +0100154 * Set the UE IP address that this downlink UPF UE session rule matches on.
tosinski36ba33a2021-11-22 16:53:00 +0100155 *
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 Morof3a5ab02022-01-26 16:47:08 +0100165 * Set the GTP tunnel peer ID that is set by this UPF UE Session rule.
tosinski36ba33a2021-11-22 16:53:00 +0100166 *
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 Morof3a5ab02022-01-26 16:47:08 +0100176 * Set whether to buffer downlink UPF UE session traffic or not.
tosinski36ba33a2021-11-22 16:53:00 +0100177 *
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 Morof3a5ab02022-01-26 16:47:08 +0100187 * Set whether to drop downlink UPF UE session traffic or not.
tosinski36ba33a2021-11-22 16:53:00 +0100188 *
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 Morof3a5ab02022-01-26 16:47:08 +0100197 public UpfSessionDownlink build() {
tosinski36ba33a2021-11-22 16:53:00 +0100198 // Match fields are required
199 checkNotNull(ueAddress, "UE address must be provided");
Daniele Morof3a5ab02022-01-26 16:47:08 +0100200 return new UpfSessionDownlink(ueAddress, tunPeerId, buffer, drop);
tosinski36ba33a2021-11-22 16:53:00 +0100201 }
202 }
203}