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