blob: ac0f242b21500bae874f89a3b564a552ba34824e [file] [log] [blame]
Chip Boling610117d2021-09-09 11:24:34 -05001/*
2 * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
3 * Copyright 2020-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package meframe
19
20import (
21 "errors"
22 "fmt"
23 "github.com/google/gopacket"
24 . "github.com/opencord/omci-lib-go"
25 me "github.com/opencord/omci-lib-go/generated"
26)
27
28func GetAllAlarmsRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
29 if opt.frameFormat == ExtendedIdent {
30 return nil, errors.New("extended message set for this message type is not supported")
31 }
32 // Common for all MEs
33 meLayer := &GetAllAlarmsRequest{
34 MeBasePacket: MeBasePacket{
35 EntityClass: m.GetClassID(),
36 EntityInstance: m.GetEntityID(),
37 Extended: opt.frameFormat == ExtendedIdent,
38 },
39 AlarmRetrievalMode: opt.mode,
40 }
41 return meLayer, nil
42}
43
44func GetAllAlarmsResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
45 if opt.frameFormat == ExtendedIdent {
46 return nil, errors.New("extended message set for this message type is not supported")
47 }
48 // Common for all MEs
49 meLayer := &GetAllAlarmsResponse{
50 MeBasePacket: MeBasePacket{
51 EntityClass: m.GetClassID(),
52 EntityInstance: m.GetEntityID(),
53 Extended: opt.frameFormat == ExtendedIdent,
54 },
55 NumberOfCommands: opt.sequenceNumberCountOrSize,
56 }
57 return meLayer, nil
58}
59
60func GetAllAlarmsNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
61 if opt.frameFormat == ExtendedIdent {
62 return nil, errors.New("extended message set for this message type is not supported")
63 }
64 // Common for all MEs
65 meLayer := &GetAllAlarmsNextRequest{
66 MeBasePacket: MeBasePacket{
67 EntityClass: m.GetClassID(),
68 EntityInstance: m.GetEntityID(),
69 Extended: opt.frameFormat == ExtendedIdent,
70 },
71 CommandSequenceNumber: opt.sequenceNumberCountOrSize,
72 }
73 return meLayer, nil
74}
75
76func GetAllAlarmsNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
77 if opt.frameFormat == ExtendedIdent {
78 return nil, errors.New("extended message set for this message type is not supported")
79 }
80 // Common for all MEs
81 meLayer := &GetAllAlarmsNextResponse{
82 MeBasePacket: MeBasePacket{
83 EntityClass: m.GetClassID(),
84 EntityInstance: m.GetEntityID(),
85 Extended: opt.frameFormat == ExtendedIdent,
86 },
87 AlarmEntityClass: opt.alarm.AlarmClassID,
88 AlarmEntityInstance: opt.alarm.AlarmInstance,
89 }
90 if len(opt.alarm.AlarmBitmap) > 28 {
91 return nil, errors.New("invalid Alarm Bitmap Size. Must be [0..27]")
92 }
93 for octet := 0; octet < len(opt.alarm.AlarmBitmap); octet++ {
94 meLayer.AlarmBitMap[octet] = opt.alarm.AlarmBitmap[octet]
95 }
96 for octet := len(opt.alarm.AlarmBitmap); octet < 28; octet++ {
97 meLayer.AlarmBitMap[octet] = 0
98 }
99 return meLayer, nil
100}
101
102func AlarmNotificationFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
103 if opt.frameFormat == ExtendedIdent {
104 return nil, errors.New("extended message set for this message type is not supported")
105 }
106 mask, err := checkAttributeMask(m, opt.attributeMask)
107 if err != nil {
108 return nil, err
109 }
110 // Common for all MEs
111 meLayer := &AlarmNotificationMsg{
112 MeBasePacket: MeBasePacket{
113 EntityClass: m.GetClassID(),
114 EntityInstance: m.GetEntityID(),
115 Extended: opt.frameFormat == ExtendedIdent,
116 },
117 }
118 // Get payload space available
119 maxPayload := maxPacketAvailable(m, opt)
120 payloadAvailable := int(maxPayload) - 1 // Less alarm sequence number
121
122 // TODO: Lots of work to do
123 fmt.Println(mask, maxPayload, payloadAvailable)
124
125 return meLayer, errors.New("todo: Not implemented")
126}