Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [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 | package adaptercore |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 17 | |
| 18 | import ( |
| 19 | voltha "github.com/opencord/voltha-protos/go/voltha" |
| 20 | ) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 21 | |
| 22 | /*===================================================================== |
| 23 | |
| 24 | Flow id |
| 25 | |
| 26 | Identifies a flow within a single OLT |
| 27 | Flow Id is unique per OLT |
| 28 | Multiple GEM ports can map to same flow id |
| 29 | |
| 30 | 13 11 4 0 |
| 31 | +--------+--------------+------+ |
| 32 | | pon id | onu id | Flow | |
| 33 | | | | idx | |
| 34 | +--------+--------------+------+ |
| 35 | |
| 36 | 14 bits = 16384 flows (per OLT). |
| 37 | |
| 38 | pon id = 4 bits = 16 PON ports |
| 39 | onu id = 7 bits = 128 ONUss per PON port |
| 40 | Flow index = 3 bits = 4 bi-directional flows per ONU |
| 41 | = 8 uni-directional flows per ONU |
| 42 | |
| 43 | |
| 44 | Logical (OF) UNI port number |
| 45 | |
| 46 | OpenFlow port number corresponding to PON UNI |
| 47 | |
| 48 | 15 11 4 0 |
| 49 | +--+--------+--------------+------+ |
| 50 | |0 | pon id | onu id | 0 | |
| 51 | +--+--------+--------------+------+ |
| 52 | |
| 53 | pon id = 4 bits = 16 PON ports |
| 54 | onu id = 7 bits = 128 ONUs per PON port |
| 55 | |
| 56 | Logical (OF) NNI port number |
| 57 | |
| 58 | OpenFlow port number corresponding to PON UNI |
| 59 | |
| 60 | 16 0 |
| 61 | +--+----------------------------+ |
| 62 | |1 | intf_id | |
| 63 | +--+----------------------------+ |
| 64 | |
| 65 | No overlap with UNI port number space |
| 66 | |
| 67 | |
| 68 | PON OLT (OF) port number |
| 69 | |
| 70 | OpenFlow port number corresponding to PON OLT ports |
| 71 | |
| 72 | 31 28 0 |
| 73 | +--------+------------------------~~~------+ |
| 74 | | 0x2 | pon intf id | |
| 75 | +--------+------------------------~~~------+ |
| 76 | */ |
| 77 | |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 78 | var MAX_ONUS_PER_PON = 32 |
| 79 | var MIN_UPSTREAM_PORT_ID = 0xfffd |
| 80 | var MAX_UPSTREAM_PORT_ID = 0xfffffffd |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 81 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 82 | var controllerPorts []uint32 = []uint32{0xfffd, 0x7ffffffd, 0xfffffffd} |
| 83 | |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 84 | func MkUniPortNum(intfId uint32, onuId uint32, uniId uint32) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 85 | /* TODO: Add checks */ |
| 86 | return ((intfId << 11) | (onuId << 4) | uniId) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | func MkFlowId(intfId uint32, onuId uint32, idx uint32) uint32 { |
| 90 | return (((intfId << 9) | (onuId << 4)) | idx) |
| 91 | } |
| 92 | |
| 93 | func OnuIdFromPortNum(portNum uint32) uint32 { |
| 94 | return ((portNum >> 4) & 127) |
| 95 | } |
| 96 | |
| 97 | func IntfIdFromUniPortNum(portNum uint32) uint32 { |
| 98 | return ((portNum >> 11) & 15) |
| 99 | } |
| 100 | |
| 101 | func UniIdFromPortNum(portNum uint32) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 102 | return ((portNum) & 0xF) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 103 | } |
| 104 | |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 105 | func IntfIdFromPonPortNo(portNo uint32) uint32 { |
| 106 | return (portNo & 15) |
| 107 | } |
| 108 | |
| 109 | func IntfIdToPortNo(intfId uint32, intfType voltha.Port_PortType) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 110 | if (intfType) == voltha.Port_ETHERNET_NNI { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 111 | return ((1 << 16) | intfId) |
| 112 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 113 | if (intfType) == voltha.Port_PON_OLT { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 114 | return ((2 << 28) | intfId) |
| 115 | } else { |
| 116 | return 0 |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func IntfIdFromNniPortNum(portNum uint32) uint32 { |
| 122 | return (portNum & 0xFFFF) |
| 123 | } |
| 124 | |
| 125 | func IntfIdToPortTypeName(intfId uint32) voltha.Port_PortType { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 126 | if ((2 << 28) ^ intfId) < 16 { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 127 | return voltha.Port_PON_OLT |
| 128 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 129 | if (intfId & (1 << 16)) == (1 << 16) { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 130 | return voltha.Port_ETHERNET_NNI |
| 131 | } else { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 132 | return voltha.Port_ETHERNET_UNI |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func PortTypeNameByPortIndex(portIndex int32) string { |
| 138 | return voltha.Port_PortType_name[portIndex] |
| 139 | } |
| 140 | |
| 141 | func ExtractAccessFromFlow(inPort uint32, outPort uint32) (uint32, uint32, uint32, uint32) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 142 | if IsUpstream(outPort) { |
| 143 | return inPort, IntfIdFromUniPortNum(inPort), OnuIdFromPortNum(inPort), UniIdFromPortNum(inPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 144 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 145 | return outPort, IntfIdFromUniPortNum(outPort), OnuIdFromPortNum(outPort), UniIdFromPortNum(outPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | func IsUpstream(outPort uint32) bool { |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 150 | for _, port := range controllerPorts { |
| 151 | if port == outPort { |
| 152 | return true |
| 153 | } |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 154 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 155 | if (outPort & (1 << 16)) == (1 << 16) { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 156 | return true |
| 157 | } |
| 158 | return false |
| 159 | } |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 160 | |
| 161 | func IsControllerBoundFlow(outPort uint32) bool { |
| 162 | for _, port := range controllerPorts { |
| 163 | if port == outPort { |
| 164 | return true |
| 165 | } |
| 166 | } |
| 167 | return false |
| 168 | } |