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 |
| 18 | |
| 19 | """ |
| 20 | Encoding of identifiers |
| 21 | ======================= |
| 22 | |
| 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 |
| 50 | |
| 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 | |
| 83 | |
| 84 | PON 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 Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 95 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 96 | def mk_uni_port_num(intf_id, onu_id): |
| 97 | return intf_id << 11 | onu_id << 4 |
| 98 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 99 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 100 | def mk_alloc_id(onu_id, idx=0): |
| 101 | # FIXME - driver should do prefixing 1 << 10 as it is Maple specific |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 102 | # return 1<<10 | onu_id<<6 | idx |
| 103 | return 1023 + onu_id # FIXME |
| 104 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 105 | |
| 106 | def mk_gemport_id(onu_id, idx=0): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 107 | return 1 << 10 | onu_id << 3 | idx |
| 108 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 109 | |
| 110 | def onu_id_from_gemport_id(gemport_id): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 111 | return (gemport_id & ~(1 << 10)) >> 3 |
| 112 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 113 | |
| 114 | def mk_flow_id(intf_id, onu_id, idx): |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 115 | return intf_id << 11 | onu_id << 4 | idx |
| 116 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 117 | |
| 118 | def onu_id_from_port_num(port_num): |
| 119 | return (port_num >> 4) & 0x7F |
| 120 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 121 | |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 122 | def intf_id_from_uni_port_num(port_num): |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 123 | return (port_num >> 11) & 0xF |
| 124 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 125 | |
Nicolas Palpacuer | 36a9344 | 2018-05-23 17:38:57 -0400 | [diff] [blame] | 126 | def intf_id_from_pon_port_no(port_no): |
| 127 | return port_no & 0xF |
| 128 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 129 | |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 130 | def intf_id_to_port_no(intf_id, intf_type): |
| 131 | if intf_type is Port.ETHERNET_NNI: |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 132 | # FIXME - Remove hardcoded '128' |
| 133 | return intf_id + 128 |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 134 | elif intf_type is Port.PON_OLT: |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 135 | return 0x2 << 28 | intf_id |
Shad Ansari | 2292093 | 2018-05-17 00:33:34 +0000 | [diff] [blame] | 136 | else: |
| 137 | raise Exception('Invalid port type') |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 138 | |
Shad Ansari | f9d2d10 | 2018-06-13 02:15:26 +0000 | [diff] [blame^] | 139 | |
Nicolas Palpacuer | 7d90281 | 2018-06-07 16:17:09 -0400 | [diff] [blame] | 140 | def intf_id_from_nni_port_num(port_num): |
| 141 | return port_num - 128 |