blob: 0a6bfa43660c11c9505be90d2c102445003a050e [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 uplink direction.
tosinski36ba33a2021-11-22 16:53:00 +010029 */
30@Beta
Daniele Morof3a5ab02022-01-26 16:47:08 +010031public final class UpfSessionUplink implements UpfEntity {
tosinski36ba33a2021-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
38
Daniele Morof3a5ab02022-01-26 16:47:08 +010039 private UpfSessionUplink(Ip4Address tunDestAddr,
40 Integer teid,
41 boolean drop) {
tosinski36ba33a2021-11-22 16:53:00 +010042 this.tunDestAddr = tunDestAddr;
43 this.teid = teid;
44 this.dropping = drop;
45 }
46
47 public static Builder builder() {
48 return new Builder();
49 }
50
Daniele Morof3a5ab02022-01-26 16:47:08 +010051 @Override
tosinski36ba33a2021-11-22 16:53:00 +010052 public boolean equals(Object object) {
53 if (object == this) {
54 return true;
55 }
56 if (object == null) {
57 return false;
58 }
59 if (getClass() != object.getClass()) {
60 return false;
61 }
62
Daniele Morof3a5ab02022-01-26 16:47:08 +010063 UpfSessionUplink that = (UpfSessionUplink) object;
tosinski36ba33a2021-11-22 16:53:00 +010064
65 return this.dropping == that.dropping &&
66 Objects.equals(tunDestAddr, that.tunDestAddr) &&
67 Objects.equals(teid, that.teid);
68 }
69
Daniele Morof3a5ab02022-01-26 16:47:08 +010070 @Override
tosinski36ba33a2021-11-22 16:53:00 +010071 public int hashCode() {
72 return Objects.hash(tunDestAddr, teid, dropping);
73 }
74
75 @Override
76 public String toString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010077 return "UpfSessionUL(" + matchString() + " -> " + actionString() + ")";
tosinski36ba33a2021-11-22 16:53:00 +010078 }
79
80 private String matchString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010081 return "Match(tun_dst_addr=" + this.tunDstAddr() + ", teid=" + this.teid() + ")";
tosinski36ba33a2021-11-22 16:53:00 +010082 }
83
84 private String actionString() {
Daniele Morof3a5ab02022-01-26 16:47:08 +010085 StringBuilder actionStrBuilder = new StringBuilder("Action(");
tosinski36ba33a2021-11-22 16:53:00 +010086 if (this.needsDropping()) {
87 actionStrBuilder.append("DROP");
88
89 } else {
90 actionStrBuilder.append("FWD");
91 }
92 return actionStrBuilder.append(")").toString();
93 }
94
95 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +010096 * True if this UPF UE Session needs dropping of the uplink traffic.
tosinski36ba33a2021-11-22 16:53:00 +010097 *
98 * @return true if the UE Session needs dropping.
99 */
100 public boolean needsDropping() {
101 return dropping;
102 }
103
104 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100105 * Get the tunnel destination IP address in the uplink UPF UE session (N3/S1U IP address).
tosinski36ba33a2021-11-22 16:53:00 +0100106 *
107 * @return UE IP address
108 */
109 public Ip4Address tunDstAddr() {
110 return tunDestAddr;
111 }
112
113 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100114 * Get the identifier of the GTP tunnel that this UPF UE Session rule matches on.
tosinski36ba33a2021-11-22 16:53:00 +0100115 *
116 * @return GTP tunnel ID
117 */
118 public Integer teid() {
119 return teid;
120 }
121
122 @Override
123 public UpfEntityType type() {
124 return UpfEntityType.SESSION_UPLINK;
125 }
126
127 public static class Builder {
128 private Ip4Address tunDstAddr = null;
129 private Integer teid = null;
130 private boolean drop = false;
131
132 public Builder() {
133
134 }
135
136 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100137 * Set the tunnel destination IP address (N3/S1U address) that this UPF UE Session rule matches on.
tosinski36ba33a2021-11-22 16:53:00 +0100138 *
139 * @param tunDstAddr The tunnel destination IP address
140 * @return This builder object
141 */
142 public Builder withTunDstAddr(Ip4Address tunDstAddr) {
143 this.tunDstAddr = tunDstAddr;
144 return this;
145 }
146
147 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100148 * Set the identifier of the GTP tunnel that this UPF UE Session rule matches on.
tosinski36ba33a2021-11-22 16:53:00 +0100149 *
150 * @param teid GTP tunnel ID
151 * @return This builder object
152 */
153 public Builder withTeid(Integer teid) {
154 this.teid = teid;
155 return this;
156 }
157
158
159 /**
Daniele Morof3a5ab02022-01-26 16:47:08 +0100160 * Sets whether to drop uplink UPF UE session traffic or not.
tosinski36ba33a2021-11-22 16:53:00 +0100161 *
162 * @param drop True if request to buffer, false otherwise
163 * @return This builder object
164 */
165 public Builder needsDropping(boolean drop) {
166 this.drop = drop;
167 return this;
168 }
169
Daniele Morof3a5ab02022-01-26 16:47:08 +0100170 public UpfSessionUplink build() {
tosinski36ba33a2021-11-22 16:53:00 +0100171 // Match keys are required.
172 checkNotNull(tunDstAddr, "Tunnel destination must be provided");
173 checkNotNull(teid, "TEID must be provided");
Daniele Morof3a5ab02022-01-26 16:47:08 +0100174 return new UpfSessionUplink(tunDstAddr, teid, drop);
tosinski36ba33a2021-11-22 16:53:00 +0100175 }
176 }
177}