blob: 5e8a7335b884be98a1509a34254cc23f13a58b1a [file] [log] [blame]
Matteo Scandolof9d43412021-01-12 11:11:34 -08001/*
Joey Armstrong14628cd2023-01-10 08:38:31 -05002 * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolof9d43412021-01-12 11:11:34 -08003
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 */
16
17package omci
18
19import (
20 "errors"
21 "github.com/google/gopacket"
Andrea Campanella10426e22021-10-15 17:58:04 +020022 "github.com/opencord/omci-lib-go/v2"
23 me "github.com/opencord/omci-lib-go/v2/generated"
Matteo Scandolof9d43412021-01-12 11:11:34 -080024 log "github.com/sirupsen/logrus"
25)
26
27func ParseRebootRequest(omciPkt gopacket.Packet) (*omci.RebootRequest, error) {
28 msgLayer := omciPkt.Layer(omci.LayerTypeRebootRequest)
29 if msgLayer == nil {
30 err := "omci Msg layer could not be detected for LayerTypeRebootRequest"
31 omciLogger.Error(err)
32 return nil, errors.New(err)
33 }
34 msgObj, msgOk := msgLayer.(*omci.RebootRequest)
35 if !msgOk {
36 err := "omci Msg layer could not be assigned for LayerTypeRebootRequest"
37 omciLogger.Error(err)
38 return nil, errors.New(err)
39 }
40 return msgObj, nil
41}
42
43func CreateRebootResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) {
44
45 msgObj, err := ParseRebootRequest(omciPkt)
46
47 if err != nil {
48 return nil, err
49 }
50
51 omciLogger.WithFields(log.Fields{
52 "EntityClass": msgObj.EntityClass,
53 "EntityInstance": msgObj.EntityInstance,
54 }).Trace("received-omci-set-request")
55
56 response := &omci.SetResponse{
57 MeBasePacket: omci.MeBasePacket{
58 EntityClass: msgObj.EntityClass,
59 EntityInstance: msgObj.EntityInstance,
60 },
61 Result: me.Success,
62 }
63
Matteo Scandolo992a23e2021-02-04 15:35:04 -080064 pkt, err := Serialize(omci.RebootResponseType, response, omciMsg.TransactionID)
Matteo Scandolof9d43412021-01-12 11:11:34 -080065 if err != nil {
66 omciLogger.WithFields(log.Fields{
67 "Err": err,
Matteo Scandolo992a23e2021-02-04 15:35:04 -080068 }).Error("cannot-Serialize-RebootResponse")
Matteo Scandolof9d43412021-01-12 11:11:34 -080069 return nil, err
70 }
71
72 return pkt, nil
73
74}