blob: 6fee244441343a6f411a49146e0974c97afb0942 [file] [log] [blame]
Daniele Moro8d630f12021-06-15 20:53:22 +02001/*
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.pipelines.fabric.impl.behaviour.upf;
18
pierventre1eb98712021-07-13 18:03:22 +020019import com.google.common.hash.Hashing;
Daniele Moro8d630f12021-06-15 20:53:22 +020020import org.onlab.packet.Ip4Address;
21import org.onlab.packet.Ip4Prefix;
22import org.onlab.util.ImmutableByteSequence;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.core.DefaultApplicationId;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.behaviour.upf.ForwardingActionRule;
27import org.onosproject.net.behaviour.upf.PacketDetectionRule;
28import org.onosproject.net.behaviour.upf.UpfInterface;
29import org.onosproject.net.flow.DefaultFlowRule;
30import org.onosproject.net.flow.DefaultTrafficSelector;
31import org.onosproject.net.flow.DefaultTrafficTreatment;
32import org.onosproject.net.flow.FlowRule;
33import org.onosproject.net.flow.criteria.PiCriterion;
34import org.onosproject.net.pi.runtime.PiAction;
35import org.onosproject.net.pi.runtime.PiActionParam;
36
37import java.util.Arrays;
38
39import static org.onosproject.pipelines.fabric.FabricConstants.CTR_ID;
40import static org.onosproject.pipelines.fabric.FabricConstants.DROP;
41import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_DOWNLINK_PDRS;
42import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_FARS;
43import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_INTERFACES;
44import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_LOAD_IFACE;
45import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_LOAD_NORMAL_FAR;
46import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_LOAD_PDR;
47import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_LOAD_PDR_QOS;
48import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_LOAD_TUNNEL_FAR;
49import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_UPLINK_PDRS;
50import static org.onosproject.pipelines.fabric.FabricConstants.FAR_ID;
51import static org.onosproject.pipelines.fabric.FabricConstants.HDR_FAR_ID;
52import static org.onosproject.pipelines.fabric.FabricConstants.HDR_GTPU_IS_VALID;
53import static org.onosproject.pipelines.fabric.FabricConstants.HDR_IPV4_DST_ADDR;
54import static org.onosproject.pipelines.fabric.FabricConstants.HDR_TEID;
55import static org.onosproject.pipelines.fabric.FabricConstants.HDR_TUNNEL_IPV4_DST;
56import static org.onosproject.pipelines.fabric.FabricConstants.HDR_UE_ADDR;
57import static org.onosproject.pipelines.fabric.FabricConstants.NEEDS_GTPU_DECAP;
58import static org.onosproject.pipelines.fabric.FabricConstants.NOTIFY_CP;
59import static org.onosproject.pipelines.fabric.FabricConstants.QID;
60import static org.onosproject.pipelines.fabric.FabricConstants.SRC_IFACE;
61import static org.onosproject.pipelines.fabric.FabricConstants.TEID;
62import static org.onosproject.pipelines.fabric.FabricConstants.TUNNEL_DST_ADDR;
63import static org.onosproject.pipelines.fabric.FabricConstants.TUNNEL_SRC_ADDR;
64import static org.onosproject.pipelines.fabric.FabricConstants.TUNNEL_SRC_PORT;
65import static org.onosproject.pipelines.fabric.impl.behaviour.upf.FabricUpfTranslator.INTERFACE_ACCESS;
66import static org.onosproject.pipelines.fabric.impl.behaviour.upf.FabricUpfTranslator.INTERFACE_CORE;
67
68
69public final class TestUpfConstants {
70 public static final DeviceId DEVICE_ID = DeviceId.deviceId("CoolSwitch91");
71 public static final ApplicationId APP_ID = new DefaultApplicationId(5000, "up4");
72 public static final int DEFAULT_PRIORITY = 10;
73 // SESSION_ID_BITWIDTH / 8 = 12
74 public static final ImmutableByteSequence SESSION_ID = ImmutableByteSequence.ofOnes(12);
75 public static final int UPLINK_COUNTER_CELL_ID = 1;
76 public static final int DOWNLINK_COUNTER_CELL_ID = 2;
77 public static final int PDR_ID = 0; // TODO: PDR ID currently not stored on writes, so all reads are 0
78 public static final int UPLINK_FAR_ID = 1;
pierventre1eb98712021-07-13 18:03:22 +020079 public static final int UPLINK_PHYSICAL_FAR_ID = Hashing.murmur3_32()
80 .newHasher()
81 .putInt(UPLINK_FAR_ID)
82 .putBytes(SESSION_ID.asArray())
83 .hash()
84 .asInt();
Daniele Moro8d630f12021-06-15 20:53:22 +020085 public static final int DOWNLINK_FAR_ID = 2;
pierventre1eb98712021-07-13 18:03:22 +020086 public static final int DOWNLINK_PHYSICAL_FAR_ID = Hashing.murmur3_32()
87 .newHasher()
88 .putInt(DOWNLINK_FAR_ID)
89 .putBytes(SESSION_ID.asArray())
90 .hash()
91 .asInt();
Daniele Moro8d630f12021-06-15 20:53:22 +020092
93 public static final int UPLINK_PRIORITY = 9;
94 public static final int DOWNLINK_PRIORITY = 1;
95 public static final int UPLINK_QID = 1;
96 public static final int DOWNLINK_QID = 5;
97 public static final int DEFAULT_SCHEDULING_PRIORITY = 0;
98
99 public static final ImmutableByteSequence TEID_VALUE = ImmutableByteSequence.copyFrom(0xff);
100 public static final Ip4Address UE_ADDR = Ip4Address.valueOf("17.0.0.1");
101 public static final Ip4Address S1U_ADDR = Ip4Address.valueOf("192.168.0.1");
102 public static final Ip4Address ENB_ADDR = Ip4Address.valueOf("192.168.0.2");
103 public static final Ip4Prefix UE_POOL = Ip4Prefix.valueOf("17.0.0.0/16");
104 // TODO: tunnel source port currently not stored on writes, so all reads are 0
105 public static final short TUNNEL_SPORT = 2160;
106 public static final int PHYSICAL_COUNTER_SIZE = 512;
107 public static final int PHYSICAL_MAX_PDRS = 512;
108 public static final int PHYSICAL_MAX_FARS = 512;
109
110 public static final long COUNTER_BYTES = 12;
111 public static final long COUNTER_PKTS = 15;
112
113 public static final PacketDetectionRule UPLINK_PDR = PacketDetectionRule.builder()
114 .withTunnelDst(S1U_ADDR)
115 .withTeid(TEID_VALUE)
116 .withLocalFarId(UPLINK_FAR_ID)
117 .withSessionId(SESSION_ID)
118 .withCounterId(UPLINK_COUNTER_CELL_ID)
119 .withSchedulingPriority(DEFAULT_SCHEDULING_PRIORITY)
120 .build();
121
122 public static final PacketDetectionRule DOWNLINK_PDR = PacketDetectionRule.builder()
123 .withUeAddr(UE_ADDR)
124 .withLocalFarId(DOWNLINK_FAR_ID)
125 .withSessionId(SESSION_ID)
126 .withCounterId(DOWNLINK_COUNTER_CELL_ID)
127 .withSchedulingPriority(DEFAULT_SCHEDULING_PRIORITY)
128 .build();
129
130 public static final PacketDetectionRule UPLINK_PRIORITY_PDR = PacketDetectionRule.builder()
131 .withTunnelDst(S1U_ADDR)
132 .withTeid(TEID_VALUE)
133 .withLocalFarId(UPLINK_FAR_ID)
134 .withSessionId(SESSION_ID)
135 .withCounterId(UPLINK_COUNTER_CELL_ID)
136 .withSchedulingPriority(UPLINK_PRIORITY)
137 .build();
138
139 public static final PacketDetectionRule DOWNLINK_PRIORITY_PDR = PacketDetectionRule.builder()
140 .withUeAddr(UE_ADDR)
141 .withLocalFarId(DOWNLINK_FAR_ID)
142 .withSessionId(SESSION_ID)
143 .withCounterId(DOWNLINK_COUNTER_CELL_ID)
144 .withSchedulingPriority(DOWNLINK_PRIORITY)
145 .build();
146
147 public static final ForwardingActionRule UPLINK_FAR = ForwardingActionRule.builder()
148 .setFarId(UPLINK_FAR_ID)
149 .withSessionId(SESSION_ID).build();
150
151 public static final ForwardingActionRule DOWNLINK_FAR = ForwardingActionRule.builder()
152 .setFarId(DOWNLINK_FAR_ID)
153 .withSessionId(SESSION_ID)
154 .setTunnel(S1U_ADDR, ENB_ADDR, TEID_VALUE, TUNNEL_SPORT)
155 .build();
156
157 public static final UpfInterface UPLINK_INTERFACE = UpfInterface.createS1uFrom(S1U_ADDR);
158
159 public static final UpfInterface DOWNLINK_INTERFACE = UpfInterface.createUePoolFrom(UE_POOL);
160
161 public static final FlowRule FABRIC_UPLINK_PRIORITY_PDR = DefaultFlowRule.builder()
162 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
163 .forTable(FABRIC_INGRESS_SPGW_UPLINK_PDRS)
164 .withSelector(DefaultTrafficSelector.builder()
165 .matchPi(PiCriterion.builder()
166 .matchExact(HDR_TEID, TEID_VALUE.asArray())
167 .matchExact(HDR_TUNNEL_IPV4_DST, S1U_ADDR.toInt())
168 .build()).build())
169 .withTreatment(DefaultTrafficTreatment.builder()
170 .piTableAction(PiAction.builder()
171 .withId(FABRIC_INGRESS_SPGW_LOAD_PDR_QOS)
172 .withParameters(Arrays.asList(
173 new PiActionParam(CTR_ID, UPLINK_COUNTER_CELL_ID),
174 new PiActionParam(FAR_ID, UPLINK_PHYSICAL_FAR_ID),
175 new PiActionParam(NEEDS_GTPU_DECAP, 1),
176 new PiActionParam(QID, UPLINK_QID)
177 ))
178 .build()).build())
179 .withPriority(DEFAULT_PRIORITY)
180 .build();
181
182 public static final FlowRule FABRIC_DOWNLINK_PRIORITY_PDR = DefaultFlowRule.builder()
183 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
184 .forTable(FABRIC_INGRESS_SPGW_DOWNLINK_PDRS)
185 .withSelector(DefaultTrafficSelector.builder()
186 .matchPi(PiCriterion.builder()
187 .matchExact(HDR_UE_ADDR, UE_ADDR.toInt())
188 .build()).build())
189 .withTreatment(DefaultTrafficTreatment.builder()
190 .piTableAction(PiAction.builder()
191 .withId(FABRIC_INGRESS_SPGW_LOAD_PDR_QOS)
192 .withParameters(Arrays.asList(
193 new PiActionParam(CTR_ID, DOWNLINK_COUNTER_CELL_ID),
194 new PiActionParam(FAR_ID, DOWNLINK_PHYSICAL_FAR_ID),
195 new PiActionParam(NEEDS_GTPU_DECAP, 0),
196 new PiActionParam(QID, DOWNLINK_QID)
197 ))
198 .build()).build())
199 .withPriority(DEFAULT_PRIORITY)
200 .build();
201
202 public static final FlowRule FABRIC_UPLINK_PDR = DefaultFlowRule.builder()
203 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
204 .forTable(FABRIC_INGRESS_SPGW_UPLINK_PDRS)
205 .withSelector(DefaultTrafficSelector.builder()
206 .matchPi(PiCriterion.builder()
207 .matchExact(HDR_TEID, TEID_VALUE.asArray())
208 .matchExact(HDR_TUNNEL_IPV4_DST, S1U_ADDR.toInt())
209 .build()).build())
210 .withTreatment(DefaultTrafficTreatment.builder()
211 .piTableAction(PiAction.builder()
212 .withId(FABRIC_INGRESS_SPGW_LOAD_PDR)
213 .withParameters(Arrays.asList(
214 new PiActionParam(CTR_ID, UPLINK_COUNTER_CELL_ID),
215 new PiActionParam(FAR_ID, UPLINK_PHYSICAL_FAR_ID),
216 new PiActionParam(NEEDS_GTPU_DECAP, 1)
217 ))
218 .build()).build())
219 .withPriority(DEFAULT_PRIORITY)
220 .build();
221
222 public static final FlowRule FABRIC_DOWNLINK_PDR = DefaultFlowRule.builder()
223 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
224 .forTable(FABRIC_INGRESS_SPGW_DOWNLINK_PDRS)
225 .withSelector(DefaultTrafficSelector.builder()
226 .matchPi(PiCriterion.builder()
227 .matchExact(HDR_UE_ADDR, UE_ADDR.toInt())
228 .build()).build())
229 .withTreatment(DefaultTrafficTreatment.builder()
230 .piTableAction(PiAction.builder()
231 .withId(FABRIC_INGRESS_SPGW_LOAD_PDR)
232 .withParameters(Arrays.asList(
233 new PiActionParam(CTR_ID, DOWNLINK_COUNTER_CELL_ID),
234 new PiActionParam(FAR_ID, DOWNLINK_PHYSICAL_FAR_ID),
235 new PiActionParam(NEEDS_GTPU_DECAP, 0)
236 ))
237 .build()).build())
238 .withPriority(DEFAULT_PRIORITY)
239 .build();
240
241 public static final FlowRule FABRIC_UPLINK_FAR = DefaultFlowRule.builder()
242 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
243 .forTable(FABRIC_INGRESS_SPGW_FARS)
244 .withSelector(DefaultTrafficSelector.builder()
245 .matchPi(PiCriterion.builder()
246 .matchExact(HDR_FAR_ID, UPLINK_PHYSICAL_FAR_ID)
247 .build()).build())
248 .withTreatment(DefaultTrafficTreatment.builder()
249 .piTableAction(PiAction.builder()
250 .withId(FABRIC_INGRESS_SPGW_LOAD_NORMAL_FAR)
251 .withParameters(Arrays.asList(
252 new PiActionParam(DROP, 0),
253 new PiActionParam(NOTIFY_CP, 0)
254 ))
255 .build()).build())
256 .withPriority(DEFAULT_PRIORITY)
257 .build();
258
259 public static final FlowRule FABRIC_DOWNLINK_FAR = DefaultFlowRule.builder()
260 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
261 .forTable(FABRIC_INGRESS_SPGW_FARS)
262 .withSelector(DefaultTrafficSelector.builder()
263 .matchPi(PiCriterion.builder()
264 .matchExact(HDR_FAR_ID, DOWNLINK_PHYSICAL_FAR_ID)
265 .build()).build())
266 .withTreatment(DefaultTrafficTreatment.builder()
267 .piTableAction(PiAction.builder()
268 .withId(FABRIC_INGRESS_SPGW_LOAD_TUNNEL_FAR)
269 .withParameters(Arrays.asList(
270 new PiActionParam(DROP, 0),
271 new PiActionParam(NOTIFY_CP, 0),
272 new PiActionParam(TEID, TEID_VALUE),
273 new PiActionParam(TUNNEL_SRC_ADDR, S1U_ADDR.toInt()),
274 new PiActionParam(TUNNEL_DST_ADDR, ENB_ADDR.toInt()),
275 new PiActionParam(TUNNEL_SRC_PORT, TUNNEL_SPORT)
276 ))
277 .build()).build())
278 .withPriority(DEFAULT_PRIORITY)
279 .build();
280
281 public static final FlowRule FABRIC_UPLINK_INTERFACE = DefaultFlowRule.builder()
282 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
283 .forTable(FABRIC_INGRESS_SPGW_INTERFACES)
284 .withSelector(DefaultTrafficSelector.builder()
285 .matchPi(PiCriterion.builder()
286 .matchLpm(HDR_IPV4_DST_ADDR,
287 S1U_ADDR.toInt(),
288 32)
289 .matchExact(HDR_GTPU_IS_VALID, 1)
290 .build()).build())
291 .withTreatment(DefaultTrafficTreatment.builder()
292 .piTableAction(
293 PiAction.builder()
294 .withId(FABRIC_INGRESS_SPGW_LOAD_IFACE)
295 .withParameter(new PiActionParam(SRC_IFACE, INTERFACE_ACCESS))
296 .build()).build())
297 .withPriority(DEFAULT_PRIORITY)
298 .build();
299
300 public static final FlowRule FABRIC_DOWNLINK_INTERFACE = DefaultFlowRule.builder()
301 .forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent()
302 .forTable(FABRIC_INGRESS_SPGW_INTERFACES)
303 .withSelector(DefaultTrafficSelector.builder()
304 .matchPi(PiCriterion.builder()
305 .matchLpm(HDR_IPV4_DST_ADDR,
306 UE_POOL.address().toInt(),
307 UE_POOL.prefixLength())
308 .matchExact(HDR_GTPU_IS_VALID, 0)
309 .build()).build())
310 .withTreatment(DefaultTrafficTreatment.builder()
311 .piTableAction(PiAction.builder()
312 .withId(FABRIC_INGRESS_SPGW_LOAD_IFACE)
313 .withParameter(new PiActionParam(SRC_IFACE, INTERFACE_CORE))
314 .build()).build())
315 .withPriority(DEFAULT_PRIORITY)
316 .build();
317
318 /**
319 * Hidden constructor for utility class.
320 */
321 private TestUpfConstants() {
322 }
323}