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 |
| 62 | GEMPortNetworkCTP OmciClass = 268 |
Zdravko Bozakov | 8e9d85a | 2019-05-27 21:02:59 +0200 | [diff] [blame^] | 63 | ONUG OmciClass = 256 |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 64 | ) |
| 65 | |
| 66 | // OMCI Managed Entity Class |
| 67 | type OmciClass uint16 |
| 68 | |
| 69 | // OMCI Message Identifier |
| 70 | type OmciMessageIdentifier struct { |
| 71 | Class OmciClass |
| 72 | Instance uint16 |
| 73 | } |
| 74 | |
| 75 | type OmciContent [32]byte |
| 76 | |
| 77 | type OmciMessage struct { |
| 78 | TransactionId uint16 |
| 79 | MessageType OmciMsgType |
| 80 | DeviceId uint8 |
| 81 | MessageId OmciMessageIdentifier |
| 82 | Content OmciContent |
| 83 | } |
| 84 | |
| 85 | func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) { |
| 86 | var m OmciMessage |
| 87 | |
| 88 | r := bytes.NewReader(pkt) |
| 89 | |
| 90 | if err := binary.Read(r, binary.BigEndian, &m); err != nil { |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 91 | log.Printf("binary.Read failed: %s", err) |
Shad Ansari | 1106b02 | 2019-01-16 22:22:35 -0800 | [diff] [blame] | 92 | return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed") |
| 93 | } |
Mahir Gunyel | 133913f | 2019-02-14 19:57:07 -0800 | [diff] [blame] | 94 | /* Message Type = Set |
Zdravko Bozakov | 8e9d85a | 2019-05-27 21:02:59 +0200 | [diff] [blame^] | 95 | 0... .... = Destination Bit: 0x0 |
| 96 | .1.. .... = Acknowledge Request: 0x1 |
| 97 | ..0. .... = Acknowledgement: 0x0 |
| 98 | ...0 1000 = Message Type: Set (8) |
Mahir Gunyel | 133913f | 2019-02-14 19:57:07 -0800 | [diff] [blame] | 99 | */ |
Shad Ansari | 53935c0 | 2019-01-17 16:41:45 -0800 | [diff] [blame] | 100 | 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] | 101 | m.TransactionId, m.MessageType&0x1F, m.MessageId.Class, m.MessageId.Instance, m.Content) |
| 102 | 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] | 103 | } |