Chip Boling | f5af85d | 2019-02-12 15:36:17 -0600 | [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 pyvoltha.protos.device_pb2 import Port |
| 18 | import pyvoltha.protos.device_pb2 as dev_pb2 |
| 19 | |
| 20 | ####################################################################### |
| 21 | # |
| 22 | # This is a copy of the OpenOLT file of a similar name and is used |
| 23 | # when running in non-xPON (OpenOLT/SEBA) mode. We need to closely |
| 24 | # watch for changes in the OpenOLT and eventually work together to |
| 25 | # have a better way to do things (and more ONUs than 112) |
| 26 | # |
| 27 | # TODO: These duplicate some methods in the OLT Handler. Clean up |
| 28 | # and use a separate file and include it into OLT Handler object |
| 29 | # as something it derives from. |
| 30 | # |
| 31 | ####################################################################### |
| 32 | """ |
| 33 | Encoding of identifiers |
| 34 | ======================= |
| 35 | |
| 36 | Alloc ID |
| 37 | |
| 38 | Uniquely identifies a T-CONT |
| 39 | Ranges from 1024..16383 per ITU Standard |
| 40 | For Adtran, 1024..1919 |
| 41 | Unique per PON interface |
| 42 | |
| 43 | 9 8 7 0 |
| 44 | +-----+----------+ |
| 45 | | idx | onu_id | + (Min Alloc ID) |
| 46 | +-----+----------+ |
| 47 | |
| 48 | onu id = 8 bit |
| 49 | Alloc index = 2 bits (max 4 TCONTs/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 | |
| 95 | MIN_TCONT_ALLOC_ID = 1024 # 1024..16383 |
| 96 | MAX_TCONT_ALLOC_ID = 16383 |
| 97 | |
| 98 | MIN_GEM_PORT_ID = 2176 # 2176..4222 |
| 99 | MAX_GEM_PORT_ID = MIN_GEM_PORT_ID + 2046 |
| 100 | |
| 101 | MAX_ONUS_PER_PON = 128 |
| 102 | MAX_TCONTS_PER_ONU = 4 |
| 103 | MAX_GEM_PORTS_PER_ONU = 16 # Hardware can handle more |
| 104 | |
| 105 | |
| 106 | class adtran_platform(object): |
| 107 | def __init__(self): |
| 108 | pass |
| 109 | |
| 110 | def mk_uni_port_num(self, intf_id, onu_id, uni_id=0): |
| 111 | return intf_id << 11 | onu_id << 4 | uni_id |
| 112 | |
| 113 | def uni_id_from_uni_port(self, uni_port): |
| 114 | return uni_port & 0xF |
| 115 | |
| 116 | |
| 117 | def mk_uni_port_num(intf_id, onu_id, uni_id=0): |
| 118 | """ |
| 119 | Create a unique virtual UNI port number based up on PON and ONU ID |
| 120 | :param intf_id: |
| 121 | :param onu_id: (int) ONU ID (0..max) |
| 122 | :return: (int) UNI Port number |
| 123 | """ |
| 124 | return intf_id << 11 | onu_id << 4 | uni_id |
| 125 | |
| 126 | |
| 127 | def uni_id_from_uni_port(uni_port): |
| 128 | return uni_port & 0xF |
| 129 | |
| 130 | |
| 131 | def intf_id_from_uni_port_num(port_num): |
| 132 | """ |
| 133 | Extract the PON device port number from a virtual UNI Port number |
| 134 | |
| 135 | :param port_num: (int) virtual UNI / vENET port number on OLT PON |
| 136 | :return: (int) PON Port number (note, this is not the PON ID) |
| 137 | """ |
| 138 | return (port_num >> 11) & 0xF |
| 139 | |
| 140 | |
| 141 | def mk_alloc_id(_, onu_id, idx=0): |
| 142 | """ |
| 143 | Allocate a TCONT Alloc-ID. This is only called by the OLT |
| 144 | |
| 145 | :param _: (int) PON ID (not used) |
| 146 | :param onu_id: (int) ONU ID (0..MAX_ONUS_PER_PON-1) |
| 147 | :param idx: (int) TCONT Index (0..7) |
| 148 | """ |
| 149 | assert 0 <= onu_id < MAX_ONUS_PER_PON, 'Invalid ONU ID. Expect 0..{}'.format(MAX_ONUS_PER_PON-1) |
| 150 | assert 0 <= idx <= MAX_TCONTS_PER_ONU, 'Invalid TCONT instance. Expect 0..{}'.format(MAX_TCONTS_PER_ONU) |
| 151 | alloc_id = MIN_TCONT_ALLOC_ID + (idx << 8) + onu_id |
| 152 | return alloc_id |
| 153 | |
| 154 | |
| 155 | def intf_id_from_nni_port_num(port_num): |
| 156 | # OpenOLT starts at 128. We start at 1 (one-to-one mapping) |
| 157 | # return port_num - 128 |
| 158 | return port_num |
| 159 | |
| 160 | |
| 161 | def intf_id_to_intf_type(intf_id): |
| 162 | # if (2 << 28 ^ intf_id) < 16: |
| 163 | # return Port.PON_OLT |
| 164 | # elif 128 <= intf_id <= 132: |
| 165 | # return Port.ETHERNET_NNI |
| 166 | if 5 <= intf_id <= 20: |
| 167 | return Port.PON_OLT |
| 168 | elif 1 <= intf_id <= 4: |
| 169 | return Port.ETHERNET_NNI |
| 170 | else: |
| 171 | raise Exception('Invalid intf_id value') |
| 172 | |
| 173 | |
| 174 | def is_upstream(in_port, out_port): |
| 175 | # FIXME |
| 176 | # if out_port in [128, 129, 130, 131, 0xfffd, 0xfffffffd]: |
| 177 | # Not sure what fffd and the other is |
| 178 | return out_port in [1, 2, 3, 4, 0xfffd, 0xfffffffd] |
| 179 | |
| 180 | |
| 181 | def is_downstream(in_port, out_port): |
| 182 | return not is_upstream(in_port, out_port) |