blob: d1d7c92f98d2ce51bb6aa0d77e85038ef92a9871 [file] [log] [blame]
Shad Ansari22920932018-05-17 00:33:34 +00001#
2# Copyright 2018 the original author or authors.
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
17from voltha.protos.device_pb2 import Port
18
19"""
20Encoding of identifiers
21=======================
22
23GEM port ID
24
25 GEM port id is unique per PON port
26
27 10 3 0
28 +--+--------------+------+
29 |1 | onu id | GEM |
30 | | | idx |
31 +--+--------------+------+
32
33 GEM port id range (0, 1023) is reserved
34 onu id = 7 bits = 128 ONUs per PON
35 GEM index = 3 bits = 8 GEM ports per ONU
36
37Alloc ID
38
39 Uniquely identifies a T-CONT
40 Ranges from 0 to 4095
41 Unique per PON interface
42
43 12 6 0
44 +------------+------------+
45 | onu id | Alloc idx |
46 +------------+------------+
47
48 onu id = 7 bits = 128 ONUs per PON
49 Alloc index = 6 bits = 64 GEM ports per ONU
50
51Flow id
52
53 Identifies a flow within a single OLT
54 Flow Id is unique per OLT
55 Multiple GEM ports can map to same flow id
56
57 13 11 4 0
58 +--------+--------------+------+
59 | pon id | onu id | Flow |
60 | | | idx |
61 +--------+--------------+------+
62
63 14 bits = 16384 flows (per OLT).
64
65 pon id = 4 bits = 16 PON ports
66 onu id = 7 bits = 128 ONUss per PON port
67 Flow index = 3 bits = 4 bi-directional flows per ONU
68 = 8 uni-directional flows per ONU
69
70
71Logical (OF) UNI port number
72
73 OpenFlow port number corresponding to PON UNI
74
75 15 11 4 0
76 +--+--------+--------------+------+
77 |0 | pon id | onu id | 0 |
78 +--+--------+--------------+------+
79
80 pon id = 4 bits = 16 PON ports
81 onu id = 7 bits = 128 ONUs per PON port
82
83
84PON OLT (OF) port number
85
86 OpenFlow port number corresponding to PON OLT ports
87
88 31 28 0
89 +--------+------------------------~~~------+
90 | 0x2 | pon intf id |
91 +--------+------------------------~~~------+
92
93"""
94
Shad Ansarif9d2d102018-06-13 02:15:26 +000095
Shad Ansari22920932018-05-17 00:33:34 +000096def mk_uni_port_num(intf_id, onu_id):
97 return intf_id << 11 | onu_id << 4
98
Shad Ansarif9d2d102018-06-13 02:15:26 +000099
Shad Ansari22920932018-05-17 00:33:34 +0000100def mk_alloc_id(onu_id, idx=0):
101 # FIXME - driver should do prefixing 1 << 10 as it is Maple specific
Shad Ansarif9d2d102018-06-13 02:15:26 +0000102 # return 1<<10 | onu_id<<6 | idx
103 return 1023 + onu_id # FIXME
104
Shad Ansari22920932018-05-17 00:33:34 +0000105
106def mk_gemport_id(onu_id, idx=0):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000107 return 1 << 10 | onu_id << 3 | idx
108
Shad Ansari22920932018-05-17 00:33:34 +0000109
110def onu_id_from_gemport_id(gemport_id):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000111 return (gemport_id & ~(1 << 10)) >> 3
112
Shad Ansari22920932018-05-17 00:33:34 +0000113
114def mk_flow_id(intf_id, onu_id, idx):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000115 return intf_id << 11 | onu_id << 4 | idx
116
Shad Ansari22920932018-05-17 00:33:34 +0000117
118def onu_id_from_port_num(port_num):
119 return (port_num >> 4) & 0x7F
120
Shad Ansarif9d2d102018-06-13 02:15:26 +0000121
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400122def intf_id_from_uni_port_num(port_num):
Shad Ansari22920932018-05-17 00:33:34 +0000123 return (port_num >> 11) & 0xF
124
Shad Ansarif9d2d102018-06-13 02:15:26 +0000125
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400126def intf_id_from_pon_port_no(port_no):
127 return port_no & 0xF
128
Shad Ansarif9d2d102018-06-13 02:15:26 +0000129
Shad Ansari22920932018-05-17 00:33:34 +0000130def intf_id_to_port_no(intf_id, intf_type):
131 if intf_type is Port.ETHERNET_NNI:
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400132 # FIXME - Remove hardcoded '128'
133 return intf_id + 128
Shad Ansari22920932018-05-17 00:33:34 +0000134 elif intf_type is Port.PON_OLT:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000135 return 0x2 << 28 | intf_id
Shad Ansari22920932018-05-17 00:33:34 +0000136 else:
137 raise Exception('Invalid port type')
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400138
Shad Ansarif9d2d102018-06-13 02:15:26 +0000139
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400140def intf_id_from_nni_port_num(port_num):
141 return port_num - 128