blob: 594ab005e330fa3b20ce0e007d7b25e56be9c84a [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
62 GEMPortNetworkCTP OmciClass = 268
Zdravko Bozakov8e9d85a2019-05-27 21:02:59 +020063 ONUG OmciClass = 256
Shad Ansari1106b022019-01-16 22:22:35 -080064)
65
66// OMCI Managed Entity Class
67type OmciClass uint16
68
69// OMCI Message Identifier
70type OmciMessageIdentifier struct {
71 Class OmciClass
72 Instance uint16
73}
74
75type OmciContent [32]byte
76
77type OmciMessage struct {
78 TransactionId uint16
79 MessageType OmciMsgType
80 DeviceId uint8
81 MessageId OmciMessageIdentifier
82 Content OmciContent
83}
84
85func 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 Ansari53935c02019-01-17 16:41:45 -080091 log.Printf("binary.Read failed: %s", err)
Shad Ansari1106b022019-01-16 22:22:35 -080092 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
93 }
Mahir Gunyel133913f2019-02-14 19:57:07 -080094 /* Message Type = Set
Zdravko Bozakov8e9d85a2019-05-27 21:02:59 +020095 0... .... = Destination Bit: 0x0
96 .1.. .... = Acknowledge Request: 0x1
97 ..0. .... = Acknowledgement: 0x0
98 ...0 1000 = Message Type: Set (8)
Mahir Gunyel133913f2019-02-14 19:57:07 -080099 */
Shad Ansari53935c02019-01-17 16:41:45 -0800100 log.Printf("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
Mahir Gunyel133913f2019-02-14 19:57:07 -0800101 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 Ansari1106b022019-01-16 22:22:35 -0800103}