blob: 8f63fe4db3e265c00b6072a40f7bd1fc221194ac [file] [log] [blame]
Daniele Moro464e5ed2019-07-25 14:45:01 -07001/*
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
17package org.onosproject.pipelines.fabric.impl.behaviour.bng;
18
19import com.google.common.collect.ImmutableList;
20import org.onosproject.net.flow.criteria.Criterion;
21import org.onosproject.net.flow.criteria.PiCriterion;
Carmelo Casconeb1f5cfd2020-12-04 16:54:24 -080022import org.onosproject.pipelines.fabric.FabricConstants;
Daniele Moro464e5ed2019-07-25 14:45:01 -070023
24import java.util.Set;
25import java.util.stream.Collectors;
26
27/**
28 * Factory to build criteria to punt packet to the CPU from the BNG pipeline.
29 */
30final 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