Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package utils |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame^] | 22 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 23 | |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 24 | "gerrit.opencord.org/voltha-bbsim/device" |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame^] | 25 | log "github.com/sirupsen/logrus" |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func OnuToSn(onu *device.Onu) string { |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame^] | 29 | // FIXME |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 30 | // see https://github.com/opencord/voltha/blob/master/voltha/adapters/openolt/openolt_device.py#L929-L943 |
Matteo Scandolo | 2aca22c | 2018-11-08 14:12:07 -0800 | [diff] [blame^] | 31 | return string(onu.SerialNumber.VendorId) + "00000" + fmt.Sprint(onu.IntfID) + "0" + fmt.Sprintf("%x", onu.OnuID-1) |
| 32 | } |
| 33 | |
| 34 | func 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 | |
| 41 | return logger.WithFields(log.Fields{ |
| 42 | "serial_number": OnuToSn(onu), |
| 43 | "interfaceId": onu.IntfID, |
| 44 | "onuId": onu.OnuID, |
| 45 | "oltId": onu.OltID, |
| 46 | }) |
Matteo Scandolo | 88e9189 | 2018-11-06 16:29:19 -0800 | [diff] [blame] | 47 | } |