blob: f36cae45ebd42718cd3c3d3a6890520664916962 [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 (
20 "fmt"
21
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080022 "gerrit.opencord.org/voltha-bbsim/common/logger"
23
Matteo Scandolo88e91892018-11-06 16:29:19 -080024 "gerrit.opencord.org/voltha-bbsim/device"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080025 log "github.com/sirupsen/logrus"
Matteo Scandolo88e91892018-11-06 16:29:19 -080026)
27
28func OnuToSn(onu *device.Onu) string {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080029 // FIXME
Matteo Scandolo88e91892018-11-06 16:29:19 -080030 // see https://github.com/opencord/voltha/blob/master/voltha/adapters/openolt/openolt_device.py#L929-L943
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080031 return string(onu.SerialNumber.VendorId) + "00000" + fmt.Sprint(onu.IntfID) + "0" + fmt.Sprintf("%x", onu.OnuID-1)
32}
33
34func LoggerWithOnu(onu *device.Onu) *log.Entry {
35
36 if onu == nil {
37 logger.Warn("utils.LoggerWithOnu has been called without Onu")
38 return logger.GetLogger()
39 }
40
Matteo Scandolo2a659142018-11-15 11:23:45 -080041 return logger.GetLogger().WithFields(log.Fields{
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080042 "serial_number": OnuToSn(onu),
43 "interfaceId": onu.IntfID,
44 "onuId": onu.OnuID,
45 "oltId": onu.OltID,
46 })
Matteo Scandolo88e91892018-11-06 16:29:19 -080047}