Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | package core |
| 17 | |
| 18 | import ( |
| 19 | "bytes" |
| 20 | "encoding/binary" |
| 21 | "errors" |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 22 | "log" |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | // |
| 26 | // OMCI definitions |
| 27 | // |
| 28 | |
| 29 | // OmciMsgType represents a OMCI message-type |
| 30 | type OmciMsgType byte |
| 31 | |
| 32 | const ( |
| 33 | // Message Types |
| 34 | _ = iota |
| 35 | Create OmciMsgType = 4 |
| 36 | Delete OmciMsgType = 6 |
| 37 | Set OmciMsgType = 8 |
| 38 | Get OmciMsgType = 9 |
| 39 | GetAllAlarms OmciMsgType = 11 |
| 40 | GetAllAlarmsNext OmciMsgType = 12 |
| 41 | MibUpload OmciMsgType = 13 |
| 42 | MibUploadNext OmciMsgType = 14 |
| 43 | MibReset OmciMsgType = 15 |
| 44 | AlarmNotification OmciMsgType = 16 |
| 45 | AttributeValueChange OmciMsgType = 17 |
| 46 | Test OmciMsgType = 18 |
| 47 | StartSoftwareDownload OmciMsgType = 19 |
| 48 | DownloadSection OmciMsgType = 20 |
| 49 | EndSoftwareDownload OmciMsgType = 21 |
| 50 | ActivateSoftware OmciMsgType = 22 |
| 51 | CommitSoftware OmciMsgType = 23 |
| 52 | SynchronizeTime OmciMsgType = 24 |
| 53 | Reboot OmciMsgType = 25 |
| 54 | GetNext OmciMsgType = 26 |
| 55 | TestResult OmciMsgType = 27 |
| 56 | GetCurrentData OmciMsgType = 28 |
| 57 | SetTable OmciMsgType = 29 // Defined in Extended Message Set Only |
| 58 | ) |
| 59 | |
| 60 | const ( |
| 61 | // Managed Entity Class values |
Zdravko Bozakov | 3d76214 | 2019-07-15 16:57:17 +0200 | [diff] [blame] | 62 | EthernetPMHistoryData OmciClass = 24 |
| 63 | ONUG OmciClass = 256 |
| 64 | ANIG OmciClass = 263 |
| 65 | GEMPortNetworkCTP OmciClass = 268 |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 66 | ) |
| 67 | |
| 68 | // OMCI Managed Entity Class |
| 69 | type OmciClass uint16 |
| 70 | |
| 71 | // OMCI Message Identifier |
| 72 | type OmciMessageIdentifier struct { |
| 73 | Class OmciClass |
| 74 | Instance uint16 |
| 75 | } |
| 76 | |
| 77 | type OmciContent [32]byte |
| 78 | |
| 79 | type OmciMessage struct { |
| 80 | TransactionId uint16 |
| 81 | MessageType OmciMsgType |
| 82 | DeviceId uint8 |
| 83 | MessageId OmciMessageIdentifier |
| 84 | Content OmciContent |
| 85 | } |
| 86 | |
| 87 | func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) { |
| 88 | var m OmciMessage |
| 89 | |
| 90 | r := bytes.NewReader(pkt) |
| 91 | |
| 92 | if err := binary.Read(r, binary.BigEndian, &m); err != nil { |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 93 | log.Printf("binary.Read failed: %s", err) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 94 | return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed") |
| 95 | } |
Mahir Gunyel | 133913f | 2019-02-14 19:57:07 -0800 | [diff] [blame] | 96 | /* Message Type = Set |
Zdravko Bozakov | 8e9d85a | 2019-05-27 21:02:59 +0200 | [diff] [blame] | 97 | 0... .... = Destination Bit: 0x0 |
| 98 | .1.. .... = Acknowledge Request: 0x1 |
| 99 | ..0. .... = Acknowledgement: 0x0 |
| 100 | ...0 1000 = Message Type: Set (8) |
Mahir Gunyel | 133913f | 2019-02-14 19:57:07 -0800 | [diff] [blame] | 101 | */ |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 102 | log.Printf("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x", |
Mahir Gunyel | 133913f | 2019-02-14 19:57:07 -0800 | [diff] [blame] | 103 | m.TransactionId, m.MessageType&0x1F, m.MessageId.Class, m.MessageId.Instance, m.Content) |
| 104 | return m.TransactionId, m.DeviceId, m.MessageType & 0x1F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 105 | } |