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