Takahiro Suzuki | d7bf820 | 2020-12-17 20:21:59 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020-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 | package core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "fmt" |
| 21 | "time" |
| 22 | |
| 23 | "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif" |
| 24 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/core/l2oam" |
| 25 | ) |
| 26 | |
| 27 | var startWatchStatus bool = false |
| 28 | |
| 29 | // WatchStatus ovserves the setting file is updated or not |
| 30 | func WatchStatus(ctx context.Context, cp adapterif.CoreProxy) { |
| 31 | if startWatchStatus { |
| 32 | return |
| 33 | } |
| 34 | startWatchStatus = true |
| 35 | logger.Debug(ctx, "Start WatchStatus()") |
| 36 | ticker := time.NewTicker(1000 * time.Millisecond) |
| 37 | for range ticker.C { |
| 38 | onuList, err := l2oam.ReadOnuStatusList() |
| 39 | if err == nil { |
| 40 | for i, onu := range onuList { |
| 41 | if onu.RebootState == "reboot" { |
| 42 | logger.Debug(ctx, fmt.Sprintf("WatchStatus() reboot: %s", onu.ID)) |
| 43 | // reboot flag is set to off immediately |
| 44 | onuList[i].RebootState = "" |
| 45 | |
| 46 | // find onu using MAC address |
| 47 | onuDevice := FindL2oamDevice(onu.MacAddress) |
| 48 | if onuDevice == nil { |
| 49 | logger.Debug(ctx, fmt.Sprintf("WatchStatus() device not found: %s", onu.ID)) |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | // send Reset ONU message |
| 54 | if err := onuDevice.send(l2oam.GenerateSetResetOnu(l2oam.OnuPkgType)); err != nil { |
| 55 | continue |
| 56 | } |
| 57 | _, err := onuDevice.waitResponse(ResponseTimer) |
| 58 | if err != nil { |
| 59 | logger.Error(ctx, fmt.Sprintf("[%s] reset ONU Send Error: %v", onuDevice.getDeviceName(), err)) |
| 60 | continue |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | if err := l2oam.WriteOnuStatusList(onuList); err != nil { |
| 65 | continue |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |