blob: 7cdff7e93acc581dd80cdcf415274d14c1fbb8d1 [file] [log] [blame]
tosinskia57652d2021-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 Morode1f1f72022-01-26 16:47:08 +010028 * Provide means to set up the UPF UE Session in the uplink direction.
tosinskia57652d2021-11-22 16:53:00 +010029 */
30@Beta
Daniele Morode1f1f72022-01-26 16:47:08 +010031public final class UpfSessionUplink implements UpfEntity {
tosinskia57652d2021-11-22 16:53:00 +010032 // Match Keys
33 private final Ip4Address tunDestAddr; // The tunnel destination address (N3/S1U IPv4 address)
34 private final Integer teid; // The Tunnel Endpoint ID that this UeSession matches on
35
36 // Action parameters
37 private final boolean dropping; // Used to convey dropping information
Daniele Morob25299a2022-01-26 15:47:29 +010038 private final int sessionMeterIdx;
tosinskia57652d2021-11-22 16:53:00 +010039
Daniele Morode1f1f72022-01-26 16:47:08 +010040 private UpfSessionUplink(Ip4Address tunDestAddr,
41 Integer teid,
Daniele Morob25299a2022-01-26 15:47:29 +010042 int sessionMeterIdx,
Daniele Morode1f1f72022-01-26 16:47:08 +010043 boolean drop) {
tosinskia57652d2021-11-22 16:53:00 +010044 this.tunDestAddr = tunDestAddr;
45 this.teid = teid;
Daniele Morob25299a2022-01-26 15:47:29 +010046 this.sessionMeterIdx = sessionMeterIdx;
tosinskia57652d2021-11-22 16:53:00 +010047 this.dropping = drop;
48 }
49
50 public static Builder builder() {
51 return new Builder();
52 }
53
Daniele Morode1f1f72022-01-26 16:47:08 +010054 @Override
tosinskia57652d2021-11-22 16:53:00 +010055 public boolean equals(Object object) {
56 if (object == this) {
57 return true;
58 }
59 if (object == null) {
60 return false;
61 }
62 if (getClass() != object.getClass()) {
63 return false;
64 }
65
Daniele Morode1f1f72022-01-26 16:47:08 +010066 UpfSessionUplink that = (UpfSessionUplink) object;
tosinskia57652d2021-11-22 16:53:00 +010067
68 return this.dropping == that.dropping &&
Daniele Morob25299a2022-01-26 15:47:29 +010069 this.sessionMeterIdx == that.sessionMeterIdx &&
tosinskia57652d2021-11-22 16:53:00 +010070 Objects.equals(tunDestAddr, that.tunDestAddr) &&
71 Objects.equals(teid, that.teid);
72 }
73
Daniele Morode1f1f72022-01-26 16:47:08 +010074 @Override
tosinskia57652d2021-11-22 16:53:00 +010075 public int hashCode() {
Daniele Morob25299a2022-01-26 15:47:29 +010076 return Objects.hash(tunDestAddr, teid, sessionMeterIdx, dropping);
tosinskia57652d2021-11-22 16:53:00 +010077 }
78
79 @Override
80 public String toString() {
Daniele Morode1f1f72022-01-26 16:47:08 +010081 return "UpfSessionUL(" + matchString() + " -> " + actionString() + ")";
tosinskia57652d2021-11-22 16:53:00 +010082 }
83
84 private String matchString() {
Daniele Morode1f1f72022-01-26 16:47:08 +010085 return "Match(tun_dst_addr=" + this.tunDstAddr() + ", teid=" + this.teid() + ")";
tosinskia57652d2021-11-22 16:53:00 +010086 }
87
88 private String actionString() {
Daniele Morode1f1f72022-01-26 16:47:08 +010089 StringBuilder actionStrBuilder = new StringBuilder("Action(");
tosinskia57652d2021-11-22 16:53:00 +010090 if (this.needsDropping()) {
91 actionStrBuilder.append("DROP");
92
93 } else {
94 actionStrBuilder.append("FWD");
95 }
Daniele Morob25299a2022-01-26 15:47:29 +010096 return actionStrBuilder
97 .append(", session_meter_idx=").append(this.sessionMeterIdx())
98 .append(")").toString();
tosinskia57652d2021-11-22 16:53:00 +010099 }
100
101 /**
Daniele Morode1f1f72022-01-26 16:47:08 +0100102 * True if this UPF UE Session needs dropping of the uplink traffic.
tosinskia57652d2021-11-22 16:53:00 +0100103 *
104 * @return true if the UE Session needs dropping.
105 */
106 public boolean needsDropping() {
107 return dropping;
108 }
109
110 /**
Daniele Morode1f1f72022-01-26 16:47:08 +0100111 * Get the tunnel destination IP address in the uplink UPF UE session (N3/S1U IP address).
tosinskia57652d2021-11-22 16:53:00 +0100112 *
113 * @return UE IP address
114 */
115 public Ip4Address tunDstAddr() {
116 return tunDestAddr;
117 }
118
119 /**
Daniele Morode1f1f72022-01-26 16:47:08 +0100120 * Get the identifier of the GTP tunnel that this UPF UE Session rule matches on.
tosinskia57652d2021-11-22 16:53:00 +0100121 *
122 * @return GTP tunnel ID
123 */
124 public Integer teid() {
125 return teid;
126 }
127
Daniele Morob25299a2022-01-26 15:47:29 +0100128 /**
129 * Get the session meter index that is set by this UPF UE Session rule.
130 *
131 * @return Session meter index
132 */
133 public int sessionMeterIdx() {
134 return this.sessionMeterIdx;
135 }
136
tosinskia57652d2021-11-22 16:53:00 +0100137 @Override
138 public UpfEntityType type() {
139 return UpfEntityType.SESSION_UPLINK;
140 }
141
142 public static class Builder {
143 private Ip4Address tunDstAddr = null;
144 private Integer teid = null;
Daniele Morob25299a2022-01-26 15:47:29 +0100145 public int sessionMeterIdx = DEFAULT_SESSION_INDEX;
tosinskia57652d2021-11-22 16:53:00 +0100146 private boolean drop = false;
147
148 public Builder() {
149
150 }
151
152 /**
Daniele Morob25299a2022-01-26 15:47:29 +0100153 * Sets the tunnel destination IP address (N3/S1U address) that this UPF UE Session rule matches on.
tosinskia57652d2021-11-22 16:53:00 +0100154 *
155 * @param tunDstAddr The tunnel destination IP address
156 * @return This builder object
157 */
158 public Builder withTunDstAddr(Ip4Address tunDstAddr) {
159 this.tunDstAddr = tunDstAddr;
160 return this;
161 }
162
163 /**
Daniele Morob25299a2022-01-26 15:47:29 +0100164 * Sets the identifier of the GTP tunnel that this UPF UE Session rule matches on.
tosinskia57652d2021-11-22 16:53:00 +0100165 *
166 * @param teid GTP tunnel ID
167 * @return This builder object
168 */
169 public Builder withTeid(Integer teid) {
170 this.teid = teid;
171 return this;
172 }
173
174
175 /**
Daniele Morode1f1f72022-01-26 16:47:08 +0100176 * Sets whether to drop uplink UPF UE session traffic or not.
tosinskia57652d2021-11-22 16:53:00 +0100177 *
178 * @param drop True if request to buffer, false otherwise
179 * @return This builder object
180 */
181 public Builder needsDropping(boolean drop) {
182 this.drop = drop;
183 return this;
184 }
185
Daniele Morob25299a2022-01-26 15:47:29 +0100186 /**
187 * Sets the meter index associated with this UE session.
188 * If not set, default to {@link UpfEntity#DEFAULT_SESSION_INDEX}.
189 *
190 * @param sessionMeterIdx Session meter index
191 * @return This builder object
192 */
193 public Builder withSessionMeterIdx(int sessionMeterIdx) {
194 this.sessionMeterIdx = sessionMeterIdx;
195 return this;
196 }
197
Daniele Morode1f1f72022-01-26 16:47:08 +0100198 public UpfSessionUplink build() {
tosinskia57652d2021-11-22 16:53:00 +0100199 // Match keys are required.
200 checkNotNull(tunDstAddr, "Tunnel destination must be provided");
201 checkNotNull(teid, "TEID must be provided");
Daniele Morob25299a2022-01-26 15:47:29 +0100202 return new UpfSessionUplink(tunDstAddr, teid, sessionMeterIdx, drop);
tosinskia57652d2021-11-22 16:53:00 +0100203 }
204 }
205}