blob: 2d4cc28cf1f917911224261c498736142f206aba [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
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090017package device
Matteo Scandolo88e91892018-11-06 16:29:19 -080018
19import (
Zack Williams2abf3932019-08-05 14:07:05 -070020 "github.com/opencord/voltha-bbsim/common/logger"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080021 log "github.com/sirupsen/logrus"
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090022 "strconv"
Matteo Scandolo88e91892018-11-06 16:29:19 -080023)
24
Zdravko Bozakov078a2712019-07-19 23:25:15 +020025// OnuToSn returns serial number in string format for given ONU
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090026func OnuToSn(onu *Onu) string {
Zdravko Bozakov078a2712019-07-19 23:25:15 +020027 return string(onu.SerialNumber.VendorId) + ConvB2S(onu.SerialNumber.VendorSpecific)
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080028}
29
Zdravko Bozakov078a2712019-07-19 23:25:15 +020030// LoggerWithOnu method logs ONU fields
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090031func LoggerWithOnu(onu *Onu) *log.Entry {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080032
33 if onu == nil {
34 logger.Warn("utils.LoggerWithOnu has been called without Onu")
35 return logger.GetLogger()
36 }
37
Matteo Scandolo2a659142018-11-15 11:23:45 -080038 return logger.GetLogger().WithFields(log.Fields{
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080039 "serial_number": OnuToSn(onu),
Zdravko Bozakov078a2712019-07-19 23:25:15 +020040 "interfaceID": onu.IntfID,
41 "onuID": onu.OnuID,
42 "oltID": onu.OltID,
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080043 })
Matteo Scandolo88e91892018-11-06 16:29:19 -080044}
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090045
Zdravko Bozakov078a2712019-07-19 23:25:15 +020046// ConvB2S converts byte array to string
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090047func ConvB2S(b []byte) string {
48 s := ""
49 for _, i := range b {
50 s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16)
51 }
52 return s
53}