blob: a5e64744569bc3fc5fb179b5e8c12ff97928e095 [file] [log] [blame]
Girish Gowdraa539f522021-02-15 23:00:45 -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 */
16
17package omci
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 log "github.com/sirupsen/logrus"
25)
26
27func ParseSyncTimeRequest(omciPkt gopacket.Packet) (*omci.SynchronizeTimeRequest, error) {
28 msgLayer := omciPkt.Layer(omci.LayerTypeSynchronizeTimeRequest)
29 if msgLayer == nil {
30 err := "omci Msg layer could not be detected for LayerTypeSynchronizeTimeRequest"
31 omciLogger.Error(err)
32 return nil, errors.New(err)
33 }
34 msgObj, msgOk := msgLayer.(*omci.SynchronizeTimeRequest)
35 if !msgOk {
36 err := "omci Msg layer could not be assigned for LayerTypeSynchronizeTimeRequest"
37 omciLogger.Error(err)
38 return nil, errors.New(err)
39 }
40 return msgObj, nil
41}
42
43func CreateSyncTimeResponse(omciPkt gopacket.Packet, omciMsg *omci.OMCI) ([]byte, error) {
44
45 msgObj, err := ParseSyncTimeRequest(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-sync-time-request")
55
56 response := &omci.SynchronizeTimeResponse{
57 MeBasePacket: omci.MeBasePacket{
58 EntityClass: msgObj.EntityClass,
59 EntityInstance: msgObj.EntityInstance,
60 },
61 Result: me.Success,
62 }
63
64 pkt, err := Serialize(omci.SynchronizeTimeResponseType, response, omciMsg.TransactionID)
65 if err != nil {
66 omciLogger.WithFields(log.Fields{
67 "Err": err,
68 }).Error("cannot-Serialize-SyncTimeResponse")
69 return nil, err
70 }
71
72 return pkt, nil
73
74}