Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | f850dca | 2024-01-18 18:25:46 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 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 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 16 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 17 | package platform |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 18 | |
| 19 | import ( |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 20 | "context" |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 21 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 22 | "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 23 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 24 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 25 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 26 | "google.golang.org/grpc/codes" |
| 27 | "google.golang.org/grpc/status" |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 28 | ) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 29 | |
| 30 | /*===================================================================== |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 31 | Logical (OF) UNI port number |
| 32 | |
| 33 | OpenFlow port number corresponding to PON UNI |
| 34 | |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 35 | 24 16 8 0 |
| 36 | +--+--------+----------+----------+ |
| 37 | |0 | pon id | onu id | uni id | |
| 38 | +--+--------+----------+----------+ |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 39 | |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 40 | pon id = 8 bits = 256 PON ports |
| 41 | onu id = 8 bits = 256 ONUs per PON port |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 42 | uni id = 8 bits = 256 UNIs per ONU |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 43 | |
| 44 | Logical (OF) NNI port number |
| 45 | |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 46 | OpenFlow port number corresponding to PON NNI |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 47 | |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 48 | 24 0 |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 49 | +--+----------------------------+ |
| 50 | |1 | intf_id | |
| 51 | +--+----------------------------+ |
| 52 | |
| 53 | No overlap with UNI port number space |
| 54 | |
| 55 | |
| 56 | PON OLT (OF) port number |
| 57 | |
| 58 | OpenFlow port number corresponding to PON OLT ports |
| 59 | |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 60 | 31 28 0 |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 61 | +--------+------------------------~~~------+ |
| 62 | | 0x2 | pon intf id | |
| 63 | +--------+------------------------~~~------+ |
| 64 | */ |
| 65 | |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 66 | const ( |
| 67 | // Number of bits for the physical UNI of the ONUs |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 68 | bitsForUniID = 8 |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 69 | // Number of bits for the ONU ID |
| 70 | bitsForONUID = 8 |
| 71 | // Number of bits for PON ID |
| 72 | bitsForPONID = 8 |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 73 | // MaxOnusPerPon is Max number of ONUs on any PON port |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 74 | MaxOnusPerPon = (1 << bitsForONUID) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 75 | // MaxPonsPerOlt is Max number of PON ports on any OLT |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 76 | MaxPonsPerOlt = (1 << bitsForPONID) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 77 | // MaxUnisPerOnu is the Max number of UNI ports on any ONU |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 78 | MaxUnisPerOnu = (1 << bitsForUniID) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 79 | // Bit position where the differentiation bit is located |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 80 | nniUniDiffPos = (bitsForUniID + bitsForONUID + bitsForPONID) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 81 | // Bit position where the marker for PON port type of OF port is present |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 82 | ponIntfMarkerPos = 28 |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 83 | // Value of marker used to distinguish PON port type of OF port |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 84 | ponIntfMarkerValue = 0x2 |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 85 | // minNniPortNum is used to store start range of nni port number (1 << 24) 16777216 |
| 86 | minNniPortNum = (1 << nniUniDiffPos) |
| 87 | // maxNniPortNum is used to store the maximum range of nni port number ((1 << 25)-1) 33554431 |
| 88 | maxNniPortNum = ((1 << (nniUniDiffPos + 1)) - 1) |
| 89 | // minPonIntfPortNum stores the minimum pon port number (536870912) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 90 | minPonIntfPortNum = ponIntfMarkerValue << ponIntfMarkerPos |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 91 | // maxPonIntfPortNum stores the maximum pon port number (536871167) |
| 92 | maxPonIntfPortNum = ((ponIntfMarkerValue << ponIntfMarkerPos) | (1 << bitsForPONID)) - 1 |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 93 | upstream = "upstream" |
| 94 | downstream = "downstream" |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 95 | //Technology Profiles ID start value |
| 96 | TpIDStart = 64 |
| 97 | //Technology Profiles ID end value |
| 98 | TpIDEnd = 256 |
| 99 | //Number of Technology Profiles can be defined. |
| 100 | TpRange = TpIDEnd - TpIDStart |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 101 | ) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 102 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 103 | // MkUniPortNum returns new UNIportNum based on intfID, inuID and uniID |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 104 | func MkUniPortNum(ctx context.Context, intfID, onuID, uniID uint32) uint32 { |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 105 | var limit = int(intfID) |
| 106 | if limit > MaxPonsPerOlt { |
| 107 | logger.Warn(ctx, "Warning: exceeded the MAX pons per OLT") |
| 108 | } |
| 109 | limit = int(onuID) |
gerardo.laurenzi | 72c8438 | 2019-07-11 15:03:46 +0000 | [diff] [blame] | 110 | if limit > MaxOnusPerPon { |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 111 | logger.Warn(ctx, "Warning: exceeded the MAX ONUS per PON") |
| 112 | } |
| 113 | limit = int(uniID) |
| 114 | if limit > MaxUnisPerOnu { |
| 115 | logger.Warn(ctx, "Warning: exceeded the MAX UNIS per ONU") |
gerardo.laurenzi | 72c8438 | 2019-07-11 15:03:46 +0000 | [diff] [blame] | 116 | } |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 117 | return (intfID << (bitsForUniID + bitsForONUID)) | (onuID << bitsForUniID) | uniID |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 118 | } |
| 119 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 120 | // OnuIDFromPortNum returns ONUID derived from portNumber |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 121 | func OnuIDFromPortNum(portNum uint32) uint32 { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 122 | return (portNum >> bitsForUniID) & (MaxOnusPerPon - 1) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 123 | } |
| 124 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 125 | // IntfIDFromUniPortNum returns IntfID derived from portNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 126 | func IntfIDFromUniPortNum(portNum uint32) uint32 { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 127 | return (portNum >> (bitsForUniID + bitsForONUID)) & (MaxPonsPerOlt - 1) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 128 | } |
| 129 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 130 | // UniIDFromPortNum return UniID derived from portNum |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 131 | func UniIDFromPortNum(portNum uint32) uint32 { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 132 | return (portNum) & (MaxUnisPerOnu - 1) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 133 | } |
| 134 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 135 | // IntfIDToPortNo returns portId derived from intftype, intfId and portType |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 136 | func IntfIDToPortNo(intfID uint32, intfType voltha.Port_PortType) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 137 | if (intfType) == voltha.Port_ETHERNET_NNI { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 138 | return (1 << nniUniDiffPos) | intfID |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 139 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 140 | if (intfType) == voltha.Port_PON_OLT { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 141 | return (ponIntfMarkerValue << ponIntfMarkerPos) | intfID |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 142 | } |
| 143 | return 0 |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 144 | } |
| 145 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 146 | // PortNoToIntfID returns portnumber derived from interfaceID |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 147 | func PortNoToIntfID(portno uint32, intfType voltha.Port_PortType) uint32 { |
| 148 | if (intfType) == voltha.Port_ETHERNET_NNI { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 149 | return (1 << nniUniDiffPos) ^ portno |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 150 | } |
| 151 | if (intfType) == voltha.Port_PON_OLT { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 152 | return (ponIntfMarkerValue << ponIntfMarkerPos) ^ portno |
Naga Manjunath | 7615e55 | 2019-10-11 22:35:47 +0530 | [diff] [blame] | 153 | } |
| 154 | return 0 |
| 155 | } |
| 156 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 157 | // IntfIDFromNniPortNum returns Intf ID derived from portNum |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 158 | func IntfIDFromNniPortNum(ctx context.Context, portNum uint32) (uint32, error) { |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 159 | if portNum < minNniPortNum || portNum > maxNniPortNum { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 160 | logger.Errorw(ctx, "nniportnumber-is-not-in-valid-range", log.Fields{"portnum": portNum}) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 161 | return uint32(0), status.Errorf(codes.InvalidArgument, "nni-port-number-out-of-range:%d", portNum) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 162 | } |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 163 | return (portNum & (minNniPortNum - 1)), nil |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 164 | } |
| 165 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 166 | // IntfIDFromPonPortNum returns Intf ID derived from portNum |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 167 | func IntfIDFromPonPortNum(ctx context.Context, portNum uint32) (uint32, error) { |
| 168 | if portNum < minPonIntfPortNum || portNum > maxPonIntfPortNum { |
| 169 | logger.Errorw(ctx, "ponportnumber-is-not-in-valid-range", log.Fields{"portnum": portNum}) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 170 | return uint32(0), status.Errorf(codes.InvalidArgument, "invalid-pon-port-number:%d", portNum) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 171 | } |
Mahir Gunyel | 0c009fc | 2021-10-22 17:47:16 -0700 | [diff] [blame] | 172 | return (portNum & ((1 << ponIntfMarkerPos) - 1)), nil |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 175 | // IntfIDToPortTypeName returns port type derived from the intfId |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 176 | func IntfIDToPortTypeName(intfID uint32) voltha.Port_PortType { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 177 | if ((ponIntfMarkerValue << ponIntfMarkerPos) ^ intfID) < MaxPonsPerOlt { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 178 | return voltha.Port_PON_OLT |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 179 | } |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 180 | if (intfID & (1 << nniUniDiffPos)) == (1 << nniUniDiffPos) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 181 | return voltha.Port_ETHERNET_NNI |
| 182 | } |
| 183 | return voltha.Port_ETHERNET_UNI |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 184 | } |
| 185 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 186 | // ExtractAccessFromFlow returns AccessDevice information |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 187 | func ExtractAccessFromFlow(inPort, outPort uint32) (uint32, uint32, uint32, uint32) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 188 | if IsUpstream(outPort) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 189 | return inPort, IntfIDFromUniPortNum(inPort), OnuIDFromPortNum(inPort), UniIDFromPortNum(inPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 190 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 191 | return outPort, IntfIDFromUniPortNum(outPort), OnuIDFromPortNum(outPort), UniIDFromPortNum(outPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 192 | } |
| 193 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 194 | // IsUpstream returns true for Upstream and false for downstream |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 195 | func IsUpstream(outPort uint32) bool { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 196 | if IsControllerBoundFlow(outPort) { |
| 197 | return true |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 198 | } |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 199 | return (outPort & (1 << nniUniDiffPos)) == (1 << nniUniDiffPos) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 200 | } |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 201 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 202 | // IsControllerBoundFlow returns true/false |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 203 | func IsControllerBoundFlow(outPort uint32) bool { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 204 | return outPort == uint32(ofp.OfpPortNo_OFPP_CONTROLLER) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 205 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 206 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 207 | // OnuIDFromUniPortNum returns onuId from give portNum information. |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 208 | func OnuIDFromUniPortNum(portNum uint32) uint32 { |
Amit Ghosh | d4cbe48 | 2019-11-21 12:07:14 +0000 | [diff] [blame] | 209 | return (portNum >> bitsForUniID) & (MaxOnusPerPon - 1) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Mahir Gunyel | 7e4cd8a | 2023-07-24 09:44:07 +0300 | [diff] [blame] | 212 | // FlowExtractInfo fetches uniport from the flow, based on which it gets and returns ponInf, onuID, uniID, inPort and ethType |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 213 | func FlowExtractInfo(ctx context.Context, flow *ofp.OfpFlowStats, flowDirection string) (uint32, uint32, uint32, uint32, uint32, uint32, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 214 | var uniPortNo uint32 |
| 215 | var ponIntf uint32 |
| 216 | var onuID uint32 |
| 217 | var uniID uint32 |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 218 | var inPort uint32 |
| 219 | var ethType uint32 |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 220 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 221 | if flowDirection == upstream { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 222 | if uniPortNo = flows.GetChildPortFromTunnelId(flow); uniPortNo == 0 { |
| 223 | for _, field := range flows.GetOfbFields(flow) { |
| 224 | if field.GetType() == flows.IN_PORT { |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 225 | uniPortNo = field.GetPort() |
| 226 | break |
| 227 | } |
| 228 | } |
| 229 | } |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 230 | } else if flowDirection == downstream { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 231 | if uniPortNo = flows.GetChildPortFromTunnelId(flow); uniPortNo == 0 { |
| 232 | for _, field := range flows.GetOfbFields(flow) { |
| 233 | if field.GetType() == flows.METADATA { |
| 234 | for _, action := range flows.GetActions(flow) { |
| 235 | if action.Type == flows.OUTPUT { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 236 | if out := action.GetOutput(); out != nil { |
| 237 | uniPortNo = out.GetPort() |
| 238 | } |
| 239 | break |
| 240 | } |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 241 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 242 | } else if field.GetType() == flows.IN_PORT { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 243 | inPort = field.GetPort() |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 244 | } else if field.GetType() == flows.ETH_TYPE { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 245 | ethType = field.GetEthType() |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if uniPortNo == 0 { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 252 | return 0, 0, 0, 0, 0, 0, status.Errorf(codes.NotFound, "uni-not-found-flow-diraction:%s", flowDirection) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 255 | ponIntf = IntfIDFromUniPortNum(uniPortNo) |
| 256 | onuID = OnuIDFromUniPortNum(uniPortNo) |
| 257 | uniID = UniIDFromPortNum(uniPortNo) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 258 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 259 | logger.Debugw(ctx, "flow-extract-info-result", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 260 | log.Fields{ |
| 261 | "uniportno": uniPortNo, |
| 262 | "pon-intf": ponIntf, |
| 263 | "onu-id": onuID, |
| 264 | "uni-id": uniID, |
| 265 | "inport": inPort, |
| 266 | "ethtype": ethType}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 267 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 268 | return uniPortNo, ponIntf, onuID, uniID, inPort, ethType, nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 269 | } |