blob: 634d1d3f219da13f943774499e0bec96cc0daafe [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"
22
23 logger "github.com/sirupsen/logrus"
24)
25
26//
27// OMCI definitions
28//
29
30// OmciMsgType represents a OMCI message-type
31type OmciMsgType byte
32
33const (
34 // Message Types
35 _ = iota
36 Create OmciMsgType = 4
37 Delete OmciMsgType = 6
38 Set OmciMsgType = 8
39 Get OmciMsgType = 9
40 GetAllAlarms OmciMsgType = 11
41 GetAllAlarmsNext OmciMsgType = 12
42 MibUpload OmciMsgType = 13
43 MibUploadNext OmciMsgType = 14
44 MibReset OmciMsgType = 15
45 AlarmNotification OmciMsgType = 16
46 AttributeValueChange OmciMsgType = 17
47 Test OmciMsgType = 18
48 StartSoftwareDownload OmciMsgType = 19
49 DownloadSection OmciMsgType = 20
50 EndSoftwareDownload OmciMsgType = 21
51 ActivateSoftware OmciMsgType = 22
52 CommitSoftware OmciMsgType = 23
53 SynchronizeTime OmciMsgType = 24
54 Reboot OmciMsgType = 25
55 GetNext OmciMsgType = 26
56 TestResult OmciMsgType = 27
57 GetCurrentData OmciMsgType = 28
58 SetTable OmciMsgType = 29 // Defined in Extended Message Set Only
59)
60
61const (
62 // Managed Entity Class values
63 GEMPortNetworkCTP OmciClass = 268
64)
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 {
91 logger.Error("binary.Read failed: %s", err)
92 return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
93 }
94 logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
95 m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content)
96 return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
97}