blob: bf5bfaaf888c91b062a0c93fe28d6010c5ce4a86 [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 (
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090020 "fmt"
Matteo Scandolo88e91892018-11-06 16:29:19 -080021
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080022 "gerrit.opencord.org/voltha-bbsim/common/logger"
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080023 log "github.com/sirupsen/logrus"
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090024 "strconv"
Matteo Scandolo88e91892018-11-06 16:29:19 -080025)
26
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090027func OnuToSn(onu *Onu) string {
28 // FIXME
29 // see https://github.com/opencord/voltha/blob/master/voltha/adapters/openolt/openolt_device.py#L929-L943
30 return string(onu.SerialNumber.VendorId) + "00000" + fmt.Sprint(onu.IntfID) + "0" + fmt.Sprintf("%x", onu.OnuID-1)
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080031}
32
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090033func LoggerWithOnu(onu *Onu) *log.Entry {
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080034
35 if onu == nil {
36 logger.Warn("utils.LoggerWithOnu has been called without Onu")
37 return logger.GetLogger()
38 }
39
Matteo Scandolo2a659142018-11-15 11:23:45 -080040 return logger.GetLogger().WithFields(log.Fields{
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080041 "serial_number": OnuToSn(onu),
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090042 "interfaceId": onu.IntfID,
43 "onuId": onu.OnuID,
44 "oltId": onu.OltID,
Matteo Scandolo2aca22c2018-11-08 14:12:07 -080045 })
Matteo Scandolo88e91892018-11-06 16:29:19 -080046}
Keita NISHIMOTO9617c852019-06-17 21:46:44 +090047
48func ConvB2S(b []byte) string {
49 s := ""
50 for _, i := range b {
51 s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16)
52 }
53 return s
54}