Daniele Moro | 464e5ed | 2019-07-25 14:45:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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.bng; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.onosproject.net.flow.criteria.Criterion; |
| 21 | import org.onosproject.net.flow.criteria.PiCriterion; |
Carmelo Cascone | b1f5cfd | 2020-12-04 16:54:24 -0800 | [diff] [blame^] | 22 | import org.onosproject.pipelines.fabric.FabricConstants; |
Daniele Moro | 464e5ed | 2019-07-25 14:45:01 -0700 | [diff] [blame] | 23 | |
| 24 | import java.util.Set; |
| 25 | import java.util.stream.Collectors; |
| 26 | |
| 27 | /** |
| 28 | * Factory to build criteria to punt packet to the CPU from the BNG pipeline. |
| 29 | */ |
| 30 | final class PuntCpuCriterionFactory { |
| 31 | |
| 32 | private static final ImmutableList<Byte> PPPOE_CODE = |
| 33 | ImmutableList.<Byte>builder() |
| 34 | .add((byte) 0x09) // PADI |
| 35 | .add((byte) 0x07) // PADO |
| 36 | .add((byte) 0x19) // PADR |
| 37 | .add((byte) 0x65) // PADS |
| 38 | .add((byte) 0xa7) // PADT |
| 39 | .build(); |
| 40 | |
| 41 | private static final ImmutableList<Short> PPP_PROTOCOL = |
| 42 | ImmutableList.<Short>builder() |
| 43 | .add((short) 0xc021) // LCP |
| 44 | .add((short) 0x8021) // IPCP |
| 45 | .add((short) 0xc023) // PAP |
| 46 | .add((short) 0xc223) // CHAP |
| 47 | .build(); |
| 48 | |
| 49 | private static final byte PPP_PROTOCOL_DEFAULT_MASK = (byte) 0xFFFF; |
| 50 | |
| 51 | private PuntCpuCriterionFactory() { |
| 52 | // Hide constructor |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Build all the Protocol Independent criteria starting from all the PPPoE |
| 57 | * codes. |
| 58 | * |
| 59 | * @return The list of Protocol Independent criteria. |
| 60 | */ |
| 61 | static Set<Criterion> getAllPuntCriterion() { |
| 62 | Set<Criterion> criteria = PPPOE_CODE.stream() |
| 63 | .map(PuntCpuCriterionFactory::getPppoePiCriterion).collect(Collectors.toSet()); |
| 64 | |
| 65 | criteria.addAll(PPP_PROTOCOL.stream() |
| 66 | .map(PuntCpuCriterionFactory::getPppPiCriterion) |
| 67 | .collect(Collectors.toSet())); |
| 68 | return criteria; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Build the Protocol Independent criterion related to the specific PPPoE |
| 73 | * code. |
| 74 | * |
| 75 | * @param pppoeCode PPPoE code field. |
| 76 | * @return The built criterion. |
| 77 | */ |
| 78 | private static PiCriterion getPppoePiCriterion(byte pppoeCode) { |
| 79 | return PiCriterion.builder() |
| 80 | .matchExact(FabricConstants.HDR_PPPOE_CODE, new byte[]{pppoeCode}) |
| 81 | .build(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Build the Protocol Independent criterion related to the specified PPPoE |
| 86 | * code and PPP protocol matching. |
| 87 | * <p> |
| 88 | * Match on PPPoE Protocol will be done with 0xFFFF as mask. |
| 89 | * |
| 90 | * @param pppProtocol PPP protocol field. |
| 91 | * @return The built criterion. |
| 92 | */ |
| 93 | private static PiCriterion getPppPiCriterion(short pppProtocol) { |
| 94 | return PiCriterion.builder() |
| 95 | .matchExact(FabricConstants.HDR_PPPOE_CODE, 0) |
| 96 | .matchTernary(FabricConstants.HDR_PPPOE_PROTOCOL, |
| 97 | pppProtocol, |
| 98 | PPP_PROTOCOL_DEFAULT_MASK) |
| 99 | .build(); |
| 100 | } |
| 101 | } |
| 102 | |