Chip Boling | 32aab30 | 2019-01-23 10:50:18 -0600 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 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 | from enum import Enum, IntEnum |
| 17 | |
| 18 | class OmciUninitializedFieldError(Exception): |
| 19 | pass |
| 20 | |
| 21 | |
| 22 | class OmciInvalidTypeError(Exception): |
| 23 | pass |
| 24 | |
| 25 | def bitpos_from_mask(mask, lsb_pos=0, increment=1): |
| 26 | """ |
| 27 | Turn a decimal value (bitmask) into a list of indices where each |
| 28 | index value corresponds to the bit position of a bit that was set (1) |
| 29 | in the mask. What numbers are assigned to the bit positions is controlled |
| 30 | by lsb_pos and increment, as explained below. |
| 31 | :param mask: a decimal value used as a bit mask |
| 32 | :param lsb_pos: The decimal value associated with the LSB bit |
| 33 | :param increment: If this is +i, then the bit next to LSB will take |
| 34 | the decimal value of lsb_pos + i. |
| 35 | :return: List of bit positions where the bit was set in mask |
| 36 | """ |
| 37 | out = [] |
| 38 | while mask: |
| 39 | if mask & 0x01: |
| 40 | out.append(lsb_pos) |
| 41 | lsb_pos += increment |
| 42 | mask >>= 1 |
| 43 | return sorted(out) |
| 44 | |
| 45 | |
| 46 | class AttributeAccess(Enum): |
| 47 | Readable = 1 |
| 48 | R = 1 |
| 49 | Writable = 2 |
| 50 | W = 2 |
| 51 | SetByCreate = 3 |
| 52 | SBC = 3 |
| 53 | |
| 54 | |
| 55 | OmciNullPointer = 0xffff |
| 56 | OmciSectionDataSize = 31 |
| 57 | |
| 58 | class EntityOperations(Enum): |
| 59 | # keep these numbers match msg_type field per OMCI spec |
| 60 | Create = 4 |
| 61 | CreateComplete = 5 |
| 62 | Delete = 6 |
| 63 | Set = 8 |
| 64 | Get = 9 |
| 65 | GetComplete = 10 |
| 66 | GetAllAlarms = 11 |
| 67 | GetAllAlarmsNext = 12 |
| 68 | MibUpload = 13 |
| 69 | MibUploadNext = 14 |
| 70 | MibReset = 15 |
| 71 | AlarmNotification = 16 |
| 72 | AttributeValueChange = 17 |
| 73 | Test = 18 |
| 74 | StartSoftwareDownload = 19 |
| 75 | DownloadSection = 20 |
| 76 | EndSoftwareDownload = 21 |
| 77 | ActivateSoftware = 22 |
| 78 | CommitSoftware = 23 |
| 79 | SynchronizeTime = 24 |
| 80 | Reboot = 25 |
| 81 | GetNext = 26 |
| 82 | TestResult = 27 |
| 83 | GetCurrentData = 28 |
| 84 | SetTable = 29 # Defined in Extended Message Set Only |
| 85 | |
| 86 | |
| 87 | class ReasonCodes(IntEnum): |
| 88 | # OMCI Result and reason codes |
| 89 | Success = 0, # Command processed successfully |
| 90 | ProcessingError = 1, # Command processing error |
| 91 | NotSupported = 2, # Command not supported |
| 92 | ParameterError = 3, # Parameter error |
| 93 | UnknownEntity = 4, # Unknown managed entity |
| 94 | UnknownInstance = 5, # Unknown managed entity instance |
| 95 | DeviceBusy = 6, # Device busy |
| 96 | InstanceExists = 7, # Instance Exists |
| 97 | AttributeFailure = 9, # Attribute(s) failed or unknown |
| 98 | |
| 99 | OperationCancelled = 255 # Proprietary defined for internal use |
| 100 | |