Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 17 | package org.onosproject.pipelines.fabric.impl.behaviour; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 18 | |
| 19 | import org.onosproject.net.pi.model.PiPipeconf; |
Carmelo Cascone | 2102bfb | 2020-12-04 16:54:24 -0800 | [diff] [blame] | 20 | import org.onosproject.pipelines.fabric.FabricConstants; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 21 | import org.slf4j.Logger; |
| 22 | |
| 23 | import java.io.BufferedReader; |
| 24 | import java.io.IOException; |
| 25 | import java.io.InputStream; |
| 26 | import java.io.InputStreamReader; |
| 27 | import java.util.Optional; |
| 28 | |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.CPU_PORT_TXT; |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame^] | 31 | import static org.onosproject.pipelines.fabric.FabricConstants.FABRIC_INGRESS_SPGW_DOWNLINK_PDRS; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 32 | import static org.slf4j.LoggerFactory.getLogger; |
| 33 | |
| 34 | /** |
| 35 | * Representation of the capabilities of a given fabric pipeconf. |
| 36 | */ |
| 37 | public class FabricCapabilities { |
| 38 | |
| 39 | private final Logger log = getLogger(getClass()); |
| 40 | |
| 41 | private final PiPipeconf pipeconf; |
| 42 | |
Carmelo Cascone | 356ab8b | 2019-09-25 01:02:53 -0700 | [diff] [blame] | 43 | public FabricCapabilities(PiPipeconf pipeconf) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 44 | this.pipeconf = checkNotNull(pipeconf); |
| 45 | } |
| 46 | |
| 47 | public boolean hasHashedTable() { |
| 48 | return pipeconf.pipelineModel() |
| 49 | .table(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).isPresent(); |
| 50 | } |
| 51 | |
| 52 | public Optional<Integer> cpuPort() { |
| 53 | // This is probably brittle, but needed to dynamically get the CPU port |
| 54 | // for different platforms. |
| 55 | if (!pipeconf.extension(CPU_PORT_TXT).isPresent()) { |
| 56 | log.warn("Missing {} extension in pipeconf {}", CPU_PORT_TXT, pipeconf.id()); |
| 57 | return Optional.empty(); |
| 58 | } |
| 59 | try { |
| 60 | final InputStream stream = pipeconf.extension(CPU_PORT_TXT).get(); |
| 61 | final BufferedReader buff = new BufferedReader( |
| 62 | new InputStreamReader(stream)); |
| 63 | final String str = buff.readLine(); |
| 64 | buff.close(); |
| 65 | if (str == null) { |
| 66 | log.error("Empty CPU port file for {}", pipeconf.id()); |
| 67 | return Optional.empty(); |
| 68 | } |
| 69 | try { |
| 70 | return Optional.of(Integer.parseInt(str)); |
| 71 | } catch (NumberFormatException e) { |
| 72 | log.error("Invalid CPU port for {}: {}", pipeconf.id(), str); |
| 73 | return Optional.empty(); |
| 74 | } |
| 75 | } catch (IOException e) { |
| 76 | log.error("Unable to read CPU port file of {}: {}", |
Carmelo Cascone | da15af8 | 2019-12-09 22:36:48 -0800 | [diff] [blame] | 77 | pipeconf.id(), e.getMessage()); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 78 | return Optional.empty(); |
| 79 | } |
| 80 | } |
Daniele Moro | f51d0c1 | 2019-07-30 10:43:10 -0700 | [diff] [blame] | 81 | |
| 82 | public boolean supportDoubleVlanTerm() { |
| 83 | if (pipeconf.pipelineModel() |
| 84 | .table(FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN).isPresent()) { |
| 85 | return pipeconf.pipelineModel().table(FabricConstants.FABRIC_INGRESS_NEXT_NEXT_VLAN) |
| 86 | .get().action(FabricConstants.FABRIC_INGRESS_NEXT_SET_DOUBLE_VLAN) |
| 87 | .isPresent(); |
| 88 | } |
| 89 | return false; |
| 90 | } |
Carmelo Cascone | da15af8 | 2019-12-09 22:36:48 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
Daniele Moro | 8d630f1 | 2021-06-15 20:53:22 +0200 | [diff] [blame^] | 93 | * Returns true if the pipeconf supports UPF capabilities, false otherwise. |
| 94 | * |
| 95 | * @return boolean |
| 96 | */ |
| 97 | public boolean supportUpf() { |
| 98 | return pipeconf.pipelineModel() |
| 99 | .table(FABRIC_INGRESS_SPGW_DOWNLINK_PDRS) |
| 100 | .isPresent(); |
| 101 | } |
| 102 | |
| 103 | /** |
Carmelo Cascone | da15af8 | 2019-12-09 22:36:48 -0800 | [diff] [blame] | 104 | * Returns true if the pipeconf supports BNG user plane capabilities, false |
| 105 | * otherwise. |
| 106 | * |
| 107 | * @return boolean |
| 108 | */ |
| 109 | public boolean supportBng() { |
| 110 | return pipeconf.pipelineModel() |
| 111 | .counter(FabricConstants.FABRIC_INGRESS_BNG_INGRESS_DOWNSTREAM_C_LINE_RX) |
| 112 | .isPresent(); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Returns the maximum number of BNG lines supported, or 0 if this pipeconf |
| 117 | * does not support BNG capabilities. |
| 118 | * |
| 119 | * @return maximum number of lines supported |
| 120 | */ |
| 121 | public long bngMaxLineCount() { |
| 122 | if (!supportBng()) { |
| 123 | return 0; |
| 124 | } |
| 125 | return pipeconf.pipelineModel() |
| 126 | .counter(FabricConstants.FABRIC_INGRESS_BNG_INGRESS_DOWNSTREAM_C_LINE_RX) |
| 127 | .orElseThrow().size(); |
| 128 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 129 | } |