Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net) |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 3 | * Copyright 2020-present Open Networking Foundation |
| 4 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 8 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Andrea Campanella | 7167ebb | 2020-02-24 09:56:38 +0100 | [diff] [blame] | 10 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 17 | /* |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 18 | * NOTE: This file was generated, manual edits will be overwritten! |
| 19 | * |
| 20 | * Generated by 'goCodeGenerator.py': |
| 21 | * https://github.com/cboling/OMCI-parser/README.md |
| 22 | */ |
| 23 | |
| 24 | package generated |
| 25 | |
| 26 | import ( |
| 27 | "fmt" |
| 28 | "github.com/deckarep/golang-set" |
| 29 | "github.com/google/gopacket" |
| 30 | ) |
| 31 | |
| 32 | // MsgType represents a OMCI message-type |
| 33 | type MsgType byte |
| 34 | |
| 35 | // MsgType represents the status field in a OMCI Response frame |
| 36 | type Results byte |
| 37 | |
| 38 | // AttributeAccess represents the access allowed to an Attribute. Some MEs |
| 39 | // are instantiated by the ONU autonomously. Others are instantiated on |
| 40 | // explicit request of the OLT via a create command, and a few ME types may |
| 41 | // be instantiated in either way, depending on the ONU architecture or |
| 42 | // circumstances. |
| 43 | // |
| 44 | // Attributes of an ME that is auto-instantiated by the ONU can be read (R), |
| 45 | // write (W), or read, write (R, W). On the other hand, attributes of a ME |
| 46 | // that is instantiated by the OLT can be either (R), (W), (R, W), |
| 47 | // (R, set by create) or (R, W, set by create). |
| 48 | type AttributeAccess byte |
| 49 | |
| 50 | // ClassID is a 16-bit value that uniquely defines a Managed Entity clas |
| 51 | // from the ITU-T G.988 specification. |
| 52 | type ClassID uint16 |
| 53 | |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 54 | // AlarmMap is a mapping of alarm bit numbers to alarm names and can be |
| 55 | // used during decode of Alarm Notification messages |
| 56 | type AlarmMap map[uint8]string |
| 57 | |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 58 | func (cid ClassID) String() string { |
| 59 | if entity, err := LoadManagedEntityDefinition(cid); err.StatusCode() == Success { |
| 60 | return fmt.Sprintf("[%s] (%d/%#x)", |
| 61 | entity.GetManagedEntityDefinition().GetName(), uint16(cid), uint16(cid)) |
| 62 | } |
| 63 | return fmt.Sprintf("unknown ClassID: %d (%#x)", uint16(cid), uint16(cid)) |
| 64 | } |
| 65 | |
| 66 | const ( |
| 67 | // AK (Bit 6), indicates whether this message is an AK to an action request. |
| 68 | // If a message is an AK, this bit is set to 1. If the message is not a |
| 69 | // response to a command, this bit is set to 0. In messages sent by the OLT, |
| 70 | // this bit is always 0. |
| 71 | AK byte = 0x20 |
| 72 | |
| 73 | // AR (Bit 7), acknowledge request, indicates whether the message requires an |
| 74 | // AK. An AK is a response to an action request, not a link layer handshake. |
| 75 | // If an AK is expected, this bit is set to 1. If no AK is expected, this bit |
| 76 | // is 0. In messages sent by the ONU, this bit is always 0 |
| 77 | AR byte = 0x40 |
| 78 | |
| 79 | // MsgTypeMask provides a mask to get the base message type |
| 80 | MsgTypeMask = 0x1F |
| 81 | ) |
| 82 | |
| 83 | const ( |
| 84 | // Message Types |
| 85 | Create MsgType = 4 |
| 86 | Delete MsgType = 6 |
| 87 | Set MsgType = 8 |
| 88 | Get MsgType = 9 |
| 89 | GetAllAlarms MsgType = 11 |
| 90 | GetAllAlarmsNext MsgType = 12 |
| 91 | MibUpload MsgType = 13 |
| 92 | MibUploadNext MsgType = 14 |
| 93 | MibReset MsgType = 15 |
| 94 | AlarmNotification MsgType = 16 |
| 95 | AttributeValueChange MsgType = 17 |
| 96 | Test MsgType = 18 |
| 97 | StartSoftwareDownload MsgType = 19 |
| 98 | DownloadSection MsgType = 20 |
| 99 | EndSoftwareDownload MsgType = 21 |
| 100 | ActivateSoftware MsgType = 22 |
| 101 | CommitSoftware MsgType = 23 |
| 102 | SynchronizeTime MsgType = 24 |
| 103 | Reboot MsgType = 25 |
| 104 | GetNext MsgType = 26 |
| 105 | TestResult MsgType = 27 |
| 106 | GetCurrentData MsgType = 28 |
| 107 | SetTable MsgType = 29 // Defined in Extended Message Set Only |
Chip Boling | 157c9b9 | 2021-04-21 09:58:36 -0500 | [diff] [blame] | 108 | ExtendedOffset MsgType = 0x80 |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 109 | ) |
| 110 | |
| 111 | func (mt MsgType) String() string { |
| 112 | switch mt { |
| 113 | default: |
| 114 | return "Unknown" |
| 115 | case Create: |
| 116 | return "Create" |
| 117 | case Delete: |
| 118 | return "Delete" |
| 119 | case Set: |
| 120 | return "Set" |
| 121 | case Get: |
| 122 | return "Get" |
| 123 | case GetAllAlarms: |
| 124 | return "Get All Alarms" |
| 125 | case GetAllAlarmsNext: |
| 126 | return "Get All Alarms Next" |
| 127 | case MibUpload: |
| 128 | return "MIB Upload" |
| 129 | case MibUploadNext: |
| 130 | return "MIB Upload Next" |
| 131 | case MibReset: |
| 132 | return "MIB Reset" |
| 133 | case AlarmNotification: |
| 134 | return "Alarm Notification" |
| 135 | case AttributeValueChange: |
| 136 | return "Attribute Value Change" |
| 137 | case Test: |
| 138 | return "Test" |
| 139 | case StartSoftwareDownload: |
| 140 | return "Start Software Download" |
| 141 | case DownloadSection: |
| 142 | return "Download Section" |
| 143 | case EndSoftwareDownload: |
| 144 | return "EndSoftware Download" |
| 145 | case ActivateSoftware: |
| 146 | return "Activate Software" |
| 147 | case CommitSoftware: |
| 148 | return "Commit Software" |
| 149 | case SynchronizeTime: |
| 150 | return "Synchronize Time" |
| 151 | case Reboot: |
| 152 | return "Reboot" |
| 153 | case GetNext: |
| 154 | return "Get Next" |
| 155 | case TestResult: |
| 156 | return "Test Result" |
| 157 | case GetCurrentData: |
| 158 | return "Get Current Data" |
| 159 | case SetTable: |
| 160 | return "Set Table" |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | var allNotificationTypes = [...]MsgType{ |
| 165 | AlarmNotification, |
| 166 | AttributeValueChange, |
| 167 | TestResult, |
| 168 | } |
| 169 | |
| 170 | // SupportsMsgType returns true if the managed entity supports the desired |
| 171 | // Message Type / action |
| 172 | func SupportsMsgType(entity IManagedEntityDefinition, msgType MsgType) bool { |
| 173 | return entity.GetMessageTypes().Contains(msgType) |
| 174 | } |
| 175 | |
| 176 | func IsAutonomousNotification(mt MsgType) bool { |
| 177 | for _, m := range allNotificationTypes { |
| 178 | if mt == m { |
| 179 | return true |
| 180 | } |
| 181 | } |
| 182 | return false |
| 183 | } |
| 184 | |
| 185 | const ( |
| 186 | // Response status codes |
| 187 | Success Results = 0 // command processed successfully |
| 188 | ProcessingError Results = 1 // command processing error |
| 189 | NotSupported Results = 2 // command not supported |
| 190 | ParameterError Results = 3 // parameter error |
| 191 | UnknownEntity Results = 4 // unknown managed entity |
| 192 | UnknownInstance Results = 5 // unknown managed entity instance |
| 193 | DeviceBusy Results = 6 // device busy |
| 194 | InstanceExists Results = 7 // instance exists |
| 195 | AttributeFailure Results = 9 // Attribute(s) failed or unknown |
| 196 | ) |
| 197 | |
| 198 | func (rc Results) String() string { |
| 199 | switch rc { |
| 200 | default: |
| 201 | return "Unknown" |
| 202 | case Success: |
| 203 | return "Success" |
| 204 | case ProcessingError: |
| 205 | return "Processing Error" |
| 206 | case NotSupported: |
| 207 | return "Not Supported" |
| 208 | case ParameterError: |
| 209 | return "Parameter Error" |
| 210 | case UnknownEntity: |
| 211 | return "Unknown Entity" |
| 212 | case UnknownInstance: |
| 213 | return "Unknown Instance" |
| 214 | case DeviceBusy: |
| 215 | return "Device Busy" |
| 216 | case InstanceExists: |
| 217 | return "Instance Exists" |
| 218 | case AttributeFailure: |
| 219 | return "Attribute Failure" |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | const ( |
| 224 | // Access allowed on a Managed Entity attribute |
| 225 | Read AttributeAccess = 1 << iota |
| 226 | Write |
| 227 | SetByCreate |
| 228 | ) |
| 229 | |
| 230 | func (access AttributeAccess) String() string { |
| 231 | switch access { |
| 232 | default: |
| 233 | return "Unknown" |
| 234 | case Read: |
| 235 | return "Read" |
| 236 | case Write: |
| 237 | return "Write" |
| 238 | case SetByCreate: |
| 239 | return "SetByCreate" |
| 240 | case Read | Write: |
| 241 | return "Read/Write" |
| 242 | case Read | SetByCreate: |
| 243 | return "Read/SetByCreate" |
| 244 | case Write | SetByCreate: |
| 245 | return "Write/SetByCreate" |
| 246 | case Read | Write | SetByCreate: |
| 247 | return "Read/Write/SetByCreate" |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // SupportsAttributeAccess returns true if the managed entity attribute |
| 252 | // supports the desired access |
| 253 | func SupportsAttributeAccess(attr AttributeDefinition, acc AttributeAccess) bool { |
| 254 | return attr.GetAccess().Contains(acc) |
| 255 | } |
| 256 | |
| 257 | type IManagedEntityDefinition interface { |
| 258 | GetName() string |
| 259 | GetClassID() ClassID |
| 260 | GetMessageTypes() mapset.Set |
| 261 | GetAllowedAttributeMask() uint16 |
| 262 | GetAttributeDefinitions() AttributeDefinitionMap |
Chip Boling | 34ebcb6 | 2021-02-02 12:13:58 -0600 | [diff] [blame] | 263 | GetAlarmMap() AlarmMap |
Chip Boling | 6e27b35 | 2020-02-14 09:10:01 -0600 | [diff] [blame] | 264 | |
| 265 | DecodeAttributes(uint16, []byte, gopacket.PacketBuilder, byte) (AttributeValueMap, error) |
| 266 | SerializeAttributes(AttributeValueMap, uint16, gopacket.SerializeBuffer, byte, int, bool) (error, uint16) |
| 267 | } |
| 268 | |
| 269 | type IManagedEntity interface { |
| 270 | IManagedEntityDefinition |
| 271 | GetManagedEntityDefinition() IManagedEntityDefinition |
| 272 | |
| 273 | GetEntityID() uint16 |
| 274 | SetEntityID(uint16) error |
| 275 | |
| 276 | GetAttributeMask() uint16 |
| 277 | |
| 278 | GetAttributeValueMap() AttributeValueMap |
| 279 | GetAttribute(string) (interface{}, error) |
| 280 | GetAttributeByIndex(uint) (interface{}, error) |
| 281 | |
| 282 | SetAttribute(string, interface{}) error |
| 283 | SetAttributeByIndex(uint, interface{}) error |
| 284 | |
| 285 | DeleteAttribute(string) error |
| 286 | DeleteAttributeByIndex(uint) error |
| 287 | } |