blob: 3bfd0de8674bbc8e7dfe22296d52e87bd9130468 [file] [log] [blame]
Matteo Scandolo88e91892018-11-06 16:29:19 -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 utils
18
19import (
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020020 "strconv"
Matteo Scandolo88e91892018-11-06 16:29:19 -080021
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080022 "gerrit.opencord.org/voltha-bbsim/common/logger"
Matteo Scandolo88e91892018-11-06 16:29:19 -080023 "gerrit.opencord.org/voltha-bbsim/device"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080024 log "github.com/sirupsen/logrus"
Matteo Scandolo88e91892018-11-06 16:29:19 -080025)
26
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020027// ConvB2S converts byte array to string
28func ConvB2S(b []byte) string {
29 s := ""
30 for _, i := range b {
31 s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16)
32 }
33 return s
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080034}
35
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020036// OnuToSn returns serial number in string format for given ONU
37func OnuToSn(onu *device.Onu) string {
38 return string(onu.SerialNumber.VendorId) + ConvB2S(onu.SerialNumber.VendorSpecific)
39}
40
41// LoggerWithOnu method logs ONU fields
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080042func LoggerWithOnu(onu *device.Onu) *log.Entry {
43
44 if onu == nil {
45 logger.Warn("utils.LoggerWithOnu has been called without Onu")
46 return logger.GetLogger()
47 }
48
Matteo Scandolo2a659142018-11-15 11:23:45 -080049 return logger.GetLogger().WithFields(log.Fields{
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080050 "serial_number": OnuToSn(onu),
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020051 "interfaceID": onu.IntfID,
52 "onuID": onu.OnuID,
53 "oltID": onu.OltID,
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080054 })
Matteo Scandolo88e91892018-11-06 16:29:19 -080055}