[VOL-1385] : Changes to support ONU delete
Tested with,
1. ONU disable->delete
2. ONU delete
3. OLT delete
Change-Id: I8e6ff41a7ea8e94014700f274cb24fea73ac41f4
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index d20874a..877d991 100755
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -705,35 +705,19 @@
log.Debugw("device-already-in-deleted-state", log.Fields{"id": agent.deviceID})
return nil
}
- if (cloned.AdminState != voltha.AdminState_DISABLED) &&
- (cloned.AdminState != voltha.AdminState_PREPROVISIONED) {
- log.Debugw("device-not-disabled", log.Fields{"id": agent.deviceID})
- //TODO: Needs customized error message
- return status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceID, voltha.AdminState_DISABLED)
- }
if cloned.AdminState != voltha.AdminState_PREPROVISIONED {
- // Send the request to an Adapter only if the device is not in poreporovision state and wait for a response
if err := agent.adapterProxy.DeleteDevice(ctx, cloned); err != nil {
log.Debugw("deleteDevice-error", log.Fields{"id": agent.deviceID, "error": err})
return err
}
}
- // Set the state to deleted after we receive an Ack - this will trigger some background process to clean up
- // the device as well as its association with the logical device
+ //Set the state to deleted - this will trigger some background process to invoke parent adapter to delete child
+ //device and clean up the device as well as its association with the logical device
cloned.AdminState = voltha.AdminState_DELETED
+
if err := agent.updateDeviceInStoreWithoutLock(ctx, cloned, false, ""); err != nil {
return err
}
- // If this is a child device then remove the associated peer ports on the parent device
- if !cloned.Root {
- go func() {
- // since the caller does not wait for this for complete, use background context
- err := agent.deviceMgr.deletePeerPorts(context.Background(), cloned.ParentId, cloned.Id)
- if err != nil {
- log.Errorw("unable-to-delete-peer-ports", log.Fields{"error": err})
- }
- }()
- }
return nil
}
@@ -1296,8 +1280,6 @@
}
func (agent *DeviceAgent) deletePeerPorts(ctx context.Context, deviceID string) error {
- agent.lockDevice.Lock()
- defer agent.lockDevice.Unlock()
log.Debug("deletePeerPorts")
cloned := agent.getDeviceWithoutLock()
@@ -1466,3 +1448,21 @@
}
return nil
}
+
+func (agent *DeviceAgent) ChildDeviceLost(ctx context.Context, device *voltha.Device) error {
+
+ agent.lockDevice.Lock()
+ defer agent.lockDevice.Unlock()
+ log.Debugw("ChildDeviceLost", log.Fields{"id": device.Id})
+
+ //Remove the associated peer ports on the parent device
+ if err := agent.deviceMgr.deletePeerPorts(ctx, device.ParentId, device.Id); err != nil {
+ return err
+ }
+
+ if err := agent.adapterProxy.ChildDeviceLost(ctx, agent.deviceType, agent.deviceID, device.ParentPortNo, device.ProxyAddress.OnuId); err != nil {
+ log.Warnw("ChildDeviceLost-error", log.Fields{"error": err})
+ }
+ return nil
+
+}