[VOL-1349] EPON OLT adapter (package B)
Change-Id: I634ef62c53813dcf4456f54948f13e06358e263c
diff --git a/internal/pkg/core/status.go b/internal/pkg/core/status.go
new file mode 100644
index 0000000..6a3181e
--- /dev/null
+++ b/internal/pkg/core/status.go
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package core
+
+import (
+ "context"
+ "fmt"
+ "time"
+
+ "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
+ "github.com/opencord/voltha-openolt-adapter/internal/pkg/core/l2oam"
+)
+
+var startWatchStatus bool = false
+
+// WatchStatus ovserves the setting file is updated or not
+func WatchStatus(ctx context.Context, cp adapterif.CoreProxy) {
+ if startWatchStatus {
+ return
+ }
+ startWatchStatus = true
+ logger.Debug(ctx, "Start WatchStatus()")
+ ticker := time.NewTicker(1000 * time.Millisecond)
+ for range ticker.C {
+ onuList, err := l2oam.ReadOnuStatusList()
+ if err == nil {
+ for i, onu := range onuList {
+ if onu.RebootState == "reboot" {
+ logger.Debug(ctx, fmt.Sprintf("WatchStatus() reboot: %s", onu.ID))
+ // reboot flag is set to off immediately
+ onuList[i].RebootState = ""
+
+ // find onu using MAC address
+ onuDevice := FindL2oamDevice(onu.MacAddress)
+ if onuDevice == nil {
+ logger.Debug(ctx, fmt.Sprintf("WatchStatus() device not found: %s", onu.ID))
+ continue
+ }
+
+ // send Reset ONU message
+ if err := onuDevice.send(l2oam.GenerateSetResetOnu(l2oam.OnuPkgType)); err != nil {
+ continue
+ }
+ _, err := onuDevice.waitResponse(ResponseTimer)
+ if err != nil {
+ logger.Error(ctx, fmt.Sprintf("[%s] reset ONU Send Error: %v", onuDevice.getDeviceName(), err))
+ continue
+ }
+ }
+ }
+ if err := l2oam.WriteOnuStatusList(onuList); err != nil {
+ continue
+ }
+ }
+ }
+}