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