blob: 7958b9113ac9487a1b265b72219e544d7e509d7f [file] [log] [blame]
/*
* Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
* Copyright 2020-present Open Networking Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package meframe
import (
"errors"
"fmt"
"github.com/google/gopacket"
. "github.com/opencord/omci-lib-go/v2"
me "github.com/opencord/omci-lib-go/v2/generated"
)
func GetAllAlarmsRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat == ExtendedIdent {
return nil, errors.New("extended message set for this message type is not supported")
}
// Common for all MEs
meLayer := &GetAllAlarmsRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
Extended: opt.frameFormat == ExtendedIdent,
},
AlarmRetrievalMode: opt.mode,
}
return meLayer, nil
}
func GetAllAlarmsResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat == ExtendedIdent {
return nil, errors.New("extended message set for this message type is not supported")
}
// Common for all MEs
meLayer := &GetAllAlarmsResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
Extended: opt.frameFormat == ExtendedIdent,
},
NumberOfCommands: opt.sequenceNumberCountOrSize,
}
return meLayer, nil
}
func GetAllAlarmsNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat == ExtendedIdent {
return nil, errors.New("extended message set for this message type is not supported")
}
// Common for all MEs
meLayer := &GetAllAlarmsNextRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
Extended: opt.frameFormat == ExtendedIdent,
},
CommandSequenceNumber: opt.sequenceNumberCountOrSize,
}
return meLayer, nil
}
func GetAllAlarmsNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat == ExtendedIdent {
return nil, errors.New("extended message set for this message type is not supported")
}
// Common for all MEs
meLayer := &GetAllAlarmsNextResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
Extended: opt.frameFormat == ExtendedIdent,
},
AlarmEntityClass: opt.alarm.AlarmClassID,
AlarmEntityInstance: opt.alarm.AlarmInstance,
}
if len(opt.alarm.AlarmBitmap) > 28 {
return nil, errors.New("invalid Alarm Bitmap Size. Must be [0..27]")
}
for octet := 0; octet < len(opt.alarm.AlarmBitmap); octet++ {
meLayer.AlarmBitMap[octet] = opt.alarm.AlarmBitmap[octet]
}
for octet := len(opt.alarm.AlarmBitmap); octet < 28; octet++ {
meLayer.AlarmBitMap[octet] = 0
}
return meLayer, nil
}
func AlarmNotificationFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat == ExtendedIdent {
return nil, errors.New("extended message set for this message type is not supported")
}
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
}
// Common for all MEs
meLayer := &AlarmNotificationMsg{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
maxPayload := maxPacketAvailable(m, opt)
payloadAvailable := int(maxPayload) - 1 // Less alarm sequence number
// TODO: Lots of work to do
fmt.Println(mask, maxPayload, payloadAvailable)
return meLayer, errors.New("todo: Not implemented")
}