blob: f7592020a82ffbd1fe3cb7e48281ff3e39458002 [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 Termination in the uplink direction on the
28 * UPF-programmable device.
29 * Provides means to configure the traffic behavior (e.g. set Traffic Class).
30 */
31@Beta
32public final class UpfTerminationUplink implements UpfEntity {
33 // Match Keys
34 private final Ip4Address ueSessionId; // UE Session ID, use UE IP address to uniquely identify a session.
35 // Action parameters
36 private final Integer ctrId; // Counter ID unique to this UPF Termination Rule
37 private final Byte trafficClass;
38 private final boolean dropping;
39
40 private UpfTerminationUplink(Ip4Address ueSessionId, Integer ctrId, Byte trafficClass,
41 boolean dropping) {
42 this.ueSessionId = ueSessionId;
43 this.ctrId = ctrId;
44 this.trafficClass = trafficClass;
45 this.dropping = dropping;
46 }
47
48 public static Builder builder() {
49 return new Builder();
50 }
51
52 @Override
53 public boolean equals(Object obj) {
54 if (obj == this) {
55 return true;
56 }
57 if (obj == null) {
58 return false;
59 }
60 if (getClass() != obj.getClass()) {
61 return false;
62 }
63 UpfTerminationUplink that = (UpfTerminationUplink) obj;
64
65 // Safe comparisons between potentially null objects
66 return this.dropping == that.dropping &&
67 Objects.equals(this.ueSessionId, that.ueSessionId) &&
68 Objects.equals(this.ctrId, that.ctrId) &&
69 Objects.equals(this.trafficClass, that.trafficClass);
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hash(ueSessionId, ctrId, trafficClass, dropping);
75 }
76
77 /**
78 * Get UE Session ID associated with UPF Termination rule.
79 *
80 * @return UE Session ID
81 */
82 public Ip4Address ueSessionId() {
83 return ueSessionId;
84 }
85
86 /**
87 * Get PDR Counter ID associated with UPF Termination rule.
88 *
89 * @return PDR counter cell ID
90 */
91 public Integer counterId() {
92 return ctrId;
93 }
94
95 /**
96 * Get Traffic Class set by this UPF Termination rule.
97 *
98 * @return Traffic Class
99 */
100 public Byte trafficClass() {
101 return trafficClass;
102 }
103
104 /**
105 * True if this UPF Termination needs to drop traffic.
106 *
107 * @return true if the UPF Termination needs dropping.
108 */
109 public boolean needsDropping() {
110 return dropping;
111 }
112
113 @Override
114 public UpfEntityType type() {
115 return UpfEntityType.TERMINATION_UPLINK;
116 }
117
118 @Override
119 public String toString() {
Daniele Morodfc23852022-01-05 11:23:51 +0100120 return "TerminationUL{" + matchString() + "->" + actionString() + "}";
tosinski36ba33a2021-11-22 16:53:00 +0100121 }
122
123 private String matchString() {
124 return "Match(ue_addr=" + this.ueSessionId() + ")";
125 }
126
127 private String actionString() {
128 return "(CTR_ID=" + this.counterId() + ", TC=" + this.trafficClass() + ")";
129 }
130
131 public static class Builder {
132 private Ip4Address ueSessionId = null;
133 private Integer ctrId = null;
134 private Byte trafficClass = null;
135 private boolean dropping = false;
136
137 public Builder() {
138
139 }
140
141 /**
142 * Set the ID of the UE session.
143 *
144 * @param ueSessionId UE session ID
145 * @return This builder object
146 */
147 public Builder withUeSessionId(Ip4Address ueSessionId) {
148 this.ueSessionId = ueSessionId;
149 return this;
150 }
151
152 /**
153 * Set the dataplane counter cell ID.
154 *
155 * @param ctrId PDR counter cell ID
156 * @return This builder object
157 */
158 public Builder withCounterId(int ctrId) {
159 this.ctrId = ctrId;
160 return this;
161 }
162
163 /**
164 * Set the Traffic Class.
165 *
166 * @param trafficClass Traffic Class
167 * @return This builder object
168 */
169 public Builder withTrafficClass(byte trafficClass) {
170 this.trafficClass = trafficClass;
171 return this;
172 }
173
174 /**
175 * Sets whether to drop uplink UPF termination traffic or not.
176 *
177 * @param dropping True if request to buffer, false otherwise
178 * @return This builder object
179 */
180 public Builder needsDropping(boolean dropping) {
181 this.dropping = dropping;
182 return this;
183 }
184
185 public UpfTerminationUplink build() {
186 // Match fields must be provided
187 checkNotNull(ueSessionId, "UE session ID must be provided");
188
189 checkNotNull(ctrId, "Counter ID must be provided");
190 // TODO: should we verify that when dropping no other fields are provided
191 return new UpfTerminationUplink(
192 this.ueSessionId, this.ctrId, this.trafficClass, this.dropping);
193 }
194
195 }
196
197}