Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 1 | # |
| 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 | |
| 17 | from voltha.protos.device_pb2 import Port |
mzadig | e4ad1d2 | 2018-07-27 15:27:22 -0400 | [diff] [blame] | 18 | import voltha.protos.device_pb2 as dev_pb2 |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 19 | |
| 20 | """ |
| 21 | Encoding of identifiers |
| 22 | ======================= |
Girish Gowdru | 1a3b704 | 2018-09-19 07:08:48 -0700 | [diff] [blame] | 23 | GEM 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 | |
| 37 | Alloc 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 |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 50 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 51 | Flow 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 | |
| 71 | Logical (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 | |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 83 | Logical (OF) NNI port number |
| 84 | |
| 85 | OpenFlow port number corresponding to PON UNI |
| 86 | |
| 87 | 16 0 |
| 88 | +--+----------------------------+ |
| 89 | |1 | intf_id | |
| 90 | +--+----------------------------+ |
| 91 | |
| 92 | No overlap with UNI port number space |
| 93 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 94 | |
| 95 | PON OLT (OF) port number |
| 96 | |
| 97 | OpenFlow port number corresponding to PON OLT ports |
| 98 | |
| 99 | 31 28 0 |
| 100 | +--------+------------------------~~~------+ |
| 101 | | 0x2 | pon intf id | |
| 102 | +--------+------------------------~~~------+ |
| 103 | |
| 104 | """ |
| 105 | |
Shad Ansari | 9712dc9 | 2018-09-26 17:46:00 +0000 | [diff] [blame^] | 106 | # MAX_ONUS_PER_PON = 112 |
| 107 | MAX_ONUS_PER_PON = 32 |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 108 | |
Girish Gowdru | 1a3b704 | 2018-09-19 07:08:48 -0700 | [diff] [blame] | 109 | def mk_alloc_id(intf_id, onu_id, idx=0): |
| 110 | # FIXME - driver should do prefixing 1 << 10 as it is Maple specific |
| 111 | # return 1<<10 | onu_id<<6 | idx |
| 112 | return 1023 + intf_id * MAX_ONUS_PER_PON + onu_id # FIXME |
| 113 | |
| 114 | |
| 115 | def mk_gemport_id(intf_id, onu_id, idx=0): |
| 116 | return 1024 + (((MAX_ONUS_PER_PON * intf_id + onu_id - 1) * 7) + idx) |
| 117 | |
| 118 | def onu_id_from_gemport_id(gemport_id): |
| 119 | return (((gemport_id - 1024) // 7) % MAX_ONUS_PER_PON) + 1 |
| 120 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 121 | def mk_uni_port_num(intf_id, onu_id): |
| 122 | return intf_id << 11 | onu_id << 4 |
| 123 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 124 | def mk_flow_id(intf_id, onu_id, idx): |
Shad Ansari | 9712dc9 | 2018-09-26 17:46:00 +0000 | [diff] [blame^] | 125 | return intf_id << 9 | onu_id << 4 | idx |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 126 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 127 | |
| 128 | def onu_id_from_port_num(port_num): |
| 129 | return (port_num >> 4) & 0x7F |
| 130 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 131 | |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 132 | def intf_id_from_uni_port_num(port_num): |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 133 | return (port_num >> 11) & 0xF |
| 134 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 135 | |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 136 | def intf_id_from_pon_port_no(port_no): |
| 137 | return port_no & 0xF |
| 138 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 139 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 140 | def intf_id_to_port_no(intf_id, intf_type): |
| 141 | if intf_type is Port.ETHERNET_NNI: |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 142 | return (0x1 << 16) | intf_id |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 143 | elif intf_type is Port.PON_OLT: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 144 | return 0x2 << 28 | intf_id |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 145 | else: |
| 146 | raise Exception('Invalid port type') |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 147 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame] | 148 | |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 149 | def intf_id_from_nni_port_num(port_num): |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 150 | return port_num & 0xFFFF |
mzadig | e4ad1d2 | 2018-07-27 15:27:22 -0400 | [diff] [blame] | 151 | |
mzadig | e4ad1d2 | 2018-07-27 15:27:22 -0400 | [diff] [blame] | 152 | |
| 153 | def intf_id_to_port_type_name(intf_id): |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 154 | if (2 << 28 ^ intf_id) < 16: |
| 155 | return Port.PON_OLT |
| 156 | elif intf_id & (0x1 << 16) == (0x1 << 16): |
| 157 | return Port.ETHERNET_NNI |
| 158 | else: |
| 159 | return None |
mzadig | e4ad1d2 | 2018-07-27 15:27:22 -0400 | [diff] [blame] | 160 | |
| 161 | def port_type_name_by_port_index(port_index): |
| 162 | try: |
| 163 | return dev_pb2._PORT_PORTTYPE.values_by_number[port_index].name |
| 164 | except Exception as err: |
| 165 | raise Exception(err) |
| 166 | |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 167 | def extract_access_from_flow(in_port, out_port): |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 168 | if is_upstream(out_port): |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 169 | return (intf_id_from_uni_port_num(in_port), onu_id_from_port_num( |
| 170 | in_port)) |
| 171 | else: |
| 172 | return (intf_id_from_uni_port_num(out_port), onu_id_from_port_num( |
| 173 | out_port)) |
| 174 | |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 175 | def is_upstream(out_port): |
| 176 | |
| 177 | if out_port in [0xfffd, 0xfffffffd]: |
| 178 | # To Controller |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 179 | return True |
Nicolas Palpacuer | 5780e15 | 2018-09-05 17:25:42 -0400 | [diff] [blame] | 180 | if (out_port & (0x1 << 16)) == (0x1 << 16): |
| 181 | # NNI interface |
| 182 | return True |
Nicolas Palpacuer | 0c7c316 | 2018-08-08 11:27:57 -0400 | [diff] [blame] | 183 | |
| 184 | return False |
Girish Gowdru | 141ced8 | 2018-09-17 20:19:14 -0700 | [diff] [blame] | 185 | |