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 | |
| 82 | func MkUniPortNum(intfId uint32, onuId uint32, uniId uint32) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 83 | /* TODO: Add checks */ |
| 84 | return ((intfId << 11) | (onuId << 4) | uniId) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | func MkFlowId(intfId uint32, onuId uint32, idx uint32) uint32 { |
| 88 | return (((intfId << 9) | (onuId << 4)) | idx) |
| 89 | } |
| 90 | |
| 91 | func OnuIdFromPortNum(portNum uint32) uint32 { |
| 92 | return ((portNum >> 4) & 127) |
| 93 | } |
| 94 | |
| 95 | func IntfIdFromUniPortNum(portNum uint32) uint32 { |
| 96 | return ((portNum >> 11) & 15) |
| 97 | } |
| 98 | |
| 99 | func UniIdFromPortNum(portNum uint32) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 100 | return ((portNum) & 0xF) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 101 | } |
| 102 | |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 103 | func IntfIdFromPonPortNo(portNo uint32) uint32 { |
| 104 | return (portNo & 15) |
| 105 | } |
| 106 | |
| 107 | func IntfIdToPortNo(intfId uint32, intfType voltha.Port_PortType) uint32 { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 108 | if (intfType) == voltha.Port_ETHERNET_NNI { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 109 | return ((1 << 16) | intfId) |
| 110 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 111 | if (intfType) == voltha.Port_PON_OLT { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 112 | return ((2 << 28) | intfId) |
| 113 | } else { |
| 114 | return 0 |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | func IntfIdFromNniPortNum(portNum uint32) uint32 { |
| 120 | return (portNum & 0xFFFF) |
| 121 | } |
| 122 | |
| 123 | func IntfIdToPortTypeName(intfId uint32) voltha.Port_PortType { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 124 | if ((2 << 28) ^ intfId) < 16 { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 125 | return voltha.Port_PON_OLT |
| 126 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 127 | if (intfId & (1 << 16)) == (1 << 16) { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 128 | return voltha.Port_ETHERNET_NNI |
| 129 | } else { |
| 130 | return voltha.Port_UNKNOWN |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | func PortTypeNameByPortIndex(portIndex int32) string { |
| 136 | return voltha.Port_PortType_name[portIndex] |
| 137 | } |
| 138 | |
| 139 | func ExtractAccessFromFlow(inPort uint32, outPort uint32) (uint32, uint32, uint32, uint32) { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 140 | if IsUpstream(outPort) { |
| 141 | return inPort, IntfIdFromUniPortNum(inPort), OnuIdFromPortNum(inPort), UniIdFromPortNum(inPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 142 | } else { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 143 | return outPort, IntfIdFromUniPortNum(outPort), OnuIdFromPortNum(outPort), UniIdFromPortNum(outPort) |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | func IsUpstream(outPort uint32) bool { |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 148 | if (outPort >= uint32(MIN_UPSTREAM_PORT_ID)) && (outPort <= uint32(MAX_UPSTREAM_PORT_ID)) { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 149 | return true |
| 150 | } |
Girish Gowdru | 0c588b2 | 2019-04-23 23:24:56 -0400 | [diff] [blame] | 151 | if (outPort & (1 << 16)) == (1 << 16) { |
Manjunath Vanaraj | 39ecd41 | 2019-03-15 20:05:41 +0530 | [diff] [blame] | 152 | return true |
| 153 | } |
| 154 | return false |
| 155 | } |