Chip Boling | 610117d | 2021-09-09 11:24:34 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package meframe |
| 19 | |
| 20 | import ( |
| 21 | "errors" |
| 22 | "github.com/google/gopacket" |
| 23 | . "github.com/opencord/omci-lib-go" |
| 24 | me "github.com/opencord/omci-lib-go/generated" |
| 25 | "time" |
| 26 | ) |
| 27 | |
| 28 | func SynchronizeTimeRequestFrame(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 := &SynchronizeTimeRequest{ |
| 34 | MeBasePacket: MeBasePacket{ |
| 35 | EntityClass: m.GetClassID(), |
| 36 | EntityInstance: m.GetEntityID(), |
| 37 | Extended: opt.frameFormat == ExtendedIdent, |
| 38 | }, |
| 39 | } |
| 40 | // Decode payload option. If nil, no timestamp provided |
| 41 | if timestamp, ok := opt.payload.(int64); ok { |
| 42 | tm := time.Unix(timestamp, 0) |
| 43 | meLayer.Year = uint16(tm.UTC().Year()) |
| 44 | meLayer.Month = uint8(tm.UTC().Month()) |
| 45 | meLayer.Day = uint8(tm.UTC().Day()) |
| 46 | meLayer.Hour = uint8(tm.UTC().Hour()) |
| 47 | meLayer.Minute = uint8(tm.UTC().Minute()) |
| 48 | meLayer.Second = uint8(tm.UTC().Second()) |
| 49 | } |
| 50 | return meLayer, nil |
| 51 | } |
| 52 | |
| 53 | func SynchronizeTimeResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) { |
| 54 | if opt.frameFormat == ExtendedIdent { |
| 55 | return nil, errors.New("extended message set for this message type is not supported") |
| 56 | } |
| 57 | // Common for all MEs |
| 58 | meLayer := &SynchronizeTimeResponse{ |
| 59 | MeBasePacket: MeBasePacket{ |
| 60 | EntityClass: m.GetClassID(), |
| 61 | EntityInstance: m.GetEntityID(), |
| 62 | Extended: opt.frameFormat == ExtendedIdent, |
| 63 | }, |
| 64 | Result: opt.result, |
| 65 | SuccessResults: opt.mode, |
| 66 | } |
| 67 | return meLayer, nil |
| 68 | } |