blob: 1f363edfc94d737fbcc2610ddfbd0494948ba2a8 [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 */
17package meframe
18
19import (
20 "errors"
21 "github.com/google/gopacket"
22 . "github.com/opencord/omci-lib-go"
23 me "github.com/opencord/omci-lib-go/generated"
24)
25
26func CreateRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
27 if opt.frameFormat == ExtendedIdent {
28 return nil, errors.New("extended message set for this message type is not supported")
29 }
30 // NOTE: The OMCI parser does not extract the default values of set-by-create attributes
31 // and are the zero 'default' (or nil) at this time. For this reason, make sure
32 // you specify all non-zero default values and pass them in appropriate
33 meLayer := &CreateRequest{
34 MeBasePacket: MeBasePacket{
35 EntityClass: m.GetClassID(),
36 EntityInstance: m.GetEntityID(),
37 Extended: opt.frameFormat == ExtendedIdent,
38 },
39 Attributes: m.GetAttributeValueMap(),
40 }
41 // Add any missing SetByCreate options if requested
42 if opt.addDefaults {
43 if attrDefs, err := me.GetAttributesDefinitions(m.GetClassID()); err.StatusCode() == me.Success {
44 for index, attr := range attrDefs {
45 if me.SupportsAttributeAccess(attr, me.SetByCreate) {
46 if index == 0 {
47 continue // Skip Entity ID, if it is SetByCreate, they should always specify it
48 }
49 if _, found := meLayer.Attributes[attr.GetName()]; !found {
50 meLayer.Attributes[attr.GetName()] = attr.DefValue
51 }
52 }
53 }
54 }
55 }
56 return meLayer, nil
57}
58
59func CreateResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
60 if opt.frameFormat == ExtendedIdent {
61 return nil, errors.New("extended message set for this message type is not supported")
62 }
63 meLayer := &CreateResponse{
64 MeBasePacket: MeBasePacket{
65 EntityClass: m.GetClassID(),
66 EntityInstance: m.GetEntityID(),
67 Extended: opt.frameFormat == ExtendedIdent,
68 },
69 Result: opt.result,
70 }
71 if meLayer.Result == me.ParameterError {
72 meLayer.AttributeExecutionMask = opt.attrExecutionMask
73 }
74 return meLayer, nil
75}