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