blob: c62bf8bb6023574f982384763917f4f9262dc66b [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
mzadige4ad1d22018-07-27 15:27:22 -040018import voltha.protos.device_pb2 as dev_pb2
Shad Ansari22920932018-05-17 00:33:34 +000019
20"""
21Encoding of identifiers
22=======================
23
Shad Ansari22920932018-05-17 00:33:34 +000024Flow 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
44Logical (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
Nicolas Palpacuer5780e152018-09-05 17:25:42 -040056Logical (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
Shad Ansari22920932018-05-17 00:33:34 +000067
68PON 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"""
78
Shad Ansari9712dc92018-09-26 17:46:00 +000079# MAX_ONUS_PER_PON = 112
80MAX_ONUS_PER_PON = 32
Shad Ansarif9d2d102018-06-13 02:15:26 +000081
Shad Ansaricd20a6d2018-10-02 14:36:33 +000082class OpenOltPlatform(object):
83
84 def __init__(self, log, device_info):
85 self.log = log
86 self.device_info = device_info
87
Shad Ansaricd20a6d2018-10-02 14:36:33 +000088 def mk_uni_port_num(self, intf_id, onu_id):
89 return intf_id << 11 | onu_id << 4
Shad Ansari22920932018-05-17 00:33:34 +000090
Shad Ansaricd20a6d2018-10-02 14:36:33 +000091 def mk_flow_id(self, intf_id, onu_id, idx):
92 return intf_id << 9 | onu_id << 4 | idx
Shad Ansarif9d2d102018-06-13 02:15:26 +000093
Shad Ansari22920932018-05-17 00:33:34 +000094
Shad Ansaricd20a6d2018-10-02 14:36:33 +000095 def onu_id_from_port_num(self, port_num):
96 return (port_num >> 4) & 0x7F
Shad Ansari22920932018-05-17 00:33:34 +000097
Shad Ansarif9d2d102018-06-13 02:15:26 +000098
Shad Ansaricd20a6d2018-10-02 14:36:33 +000099 def intf_id_from_uni_port_num(self, port_num):
100 return (port_num >> 11) & 0xF
Shad Ansari22920932018-05-17 00:33:34 +0000101
Shad Ansarif9d2d102018-06-13 02:15:26 +0000102
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000103 def intf_id_from_pon_port_no(self, port_no):
104 return port_no & 0xF
Nicolas Palpacuer36a93442018-05-23 17:38:57 -0400105
Shad Ansarif9d2d102018-06-13 02:15:26 +0000106
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000107 def intf_id_to_port_no(self, intf_id, intf_type):
108 if intf_type is Port.ETHERNET_NNI:
109 return (0x1 << 16) | intf_id
110 elif intf_type is Port.PON_OLT:
111 return 0x2 << 28 | intf_id
112 else:
113 raise Exception('Invalid port type')
Nicolas Palpacuer7d902812018-06-07 16:17:09 -0400114
Shad Ansarif9d2d102018-06-13 02:15:26 +0000115
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000116 def intf_id_from_nni_port_num(self, port_num):
117 return port_num & 0xFFFF
mzadige4ad1d22018-07-27 15:27:22 -0400118
mzadige4ad1d22018-07-27 15:27:22 -0400119
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000120 def intf_id_to_port_type_name(self, intf_id):
121 if (2 << 28 ^ intf_id) < 16:
122 return Port.PON_OLT
123 elif intf_id & (0x1 << 16) == (0x1 << 16):
124 return Port.ETHERNET_NNI
125 else:
126 return None
mzadige4ad1d22018-07-27 15:27:22 -0400127
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000128 def port_type_name_by_port_index(self, port_index):
129 try:
130 return dev_pb2._PORT_PORTTYPE.values_by_number[port_index].name
131 except Exception as err:
132 raise Exception(err)
mzadige4ad1d22018-07-27 15:27:22 -0400133
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000134 def extract_access_from_flow(self, in_port, out_port):
135 if self.is_upstream(out_port):
136 return (self.intf_id_from_uni_port_num(in_port),
137 self.onu_id_from_port_num(in_port))
138 else:
139 return (self.intf_id_from_uni_port_num(out_port),
140 self.onu_id_from_port_num(out_port))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400141
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000142 def is_upstream(self, out_port):
Nicolas Palpacuer5780e152018-09-05 17:25:42 -0400143
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000144 if out_port in [0xfffd, 0xfffffffd]:
145 # To Controller
146 return True
147 if (out_port & (0x1 << 16)) == (0x1 << 16):
148 # NNI interface
149 return True
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400150
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000151 return False
Girish Gowdru141ced82018-09-17 20:19:14 -0700152
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000153 def max_onus_per_pon(self):
154 return MAX_ONUS_PER_PON