blob: e278d9b0c38dea15c241959c5d1078dc30650a43 [file] [log] [blame]
Shad Ansari1106b022019-01-16 22:22:35 -08001/*
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 */
16package core
17
18import (
19 "bytes"
20 "encoding/binary"
21 "errors"
Shad Ansari53935c02019-01-17 16:41:45 -080022 "log"
Shad Ansari1106b022019-01-16 22:22:35 -080023)
24
25//
26// OMCI definitions
27//
28
29// OmciMsgType represents a OMCI message-type
30type OmciMsgType byte
31
32const (
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
60const (
61 // Managed Entity Class values
Zdravko Bozakov3d762142019-07-15 16:57:17 +020062 EthernetPMHistoryData OmciClass = 24
63 ONUG OmciClass = 256
64 ANIG OmciClass = 263
65 GEMPortNetworkCTP OmciClass = 268
Shad Ansari1106b022019-01-16 22:22:35 -080066)
67
68// OMCI Managed Entity Class
69type OmciClass uint16
70
71// OMCI Message Identifier
72type OmciMessageIdentifier struct {
73 Class OmciClass
74 Instance uint16
75}
76
77type OmciContent [32]byte
78
79type OmciMessage struct {
80 TransactionId uint16
81 MessageType OmciMsgType
82 DeviceId uint8
83 MessageId OmciMessageIdentifier
84 Content OmciContent
85}
86
87func 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 Ansari53935c02019-01-17 16:41:45 -080093 log.Printf("binary.Read failed: %s", err)
Shad Ansari1106b022019-01-16 22:22:35 -080094 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
95 }
Mahir Gunyel133913f2019-02-14 19:57:07 -080096 /* Message Type = Set
Zdravko Bozakov8e9d85a2019-05-27 21:02:59 +020097 0... .... = Destination Bit: 0x0
98 .1.. .... = Acknowledge Request: 0x1
99 ..0. .... = Acknowledgement: 0x0
100 ...0 1000 = Message Type: Set (8)
Mahir Gunyel133913f2019-02-14 19:57:07 -0800101 */
Shad Ansari53935c02019-01-17 16:41:45 -0800102 log.Printf("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
Mahir Gunyel133913f2019-02-14 19:57:07 -0800103 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 Ansari1106b022019-01-16 22:22:35 -0800105}