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