VOL-4465 raise ONU/OLT deleted events
Change-Id: I8f8aea3dcf97996816f8a856b05e751f7c391ee4
diff --git a/go.mod b/go.mod
index 0d90e6d..1386ecf 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.3.0
- github.com/opencord/voltha-lib-go/v7 v7.1.1
+ github.com/opencord/voltha-lib-go/v7 v7.1.2
github.com/opencord/voltha-protos/v5 v5.1.1
github.com/opentracing/opentracing-go v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
diff --git a/go.sum b/go.sum
index c96969b..fe86759 100644
--- a/go.sum
+++ b/go.sum
@@ -191,8 +191,8 @@
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.14.0 h1:ep6kpPVwmr/nTbklSx2nrLNSIO62DoYAhnPNIMhK8gI=
github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
-github.com/opencord/voltha-lib-go/v7 v7.1.1 h1:GWh0Ix7A1gr3b9L7GNy5pSDkLaPyZzJk/4ZNsj/B3eg=
-github.com/opencord/voltha-lib-go/v7 v7.1.1/go.mod h1:LjoFfwqdf/OHKUmzMqzBDGmoxfjmq9l/Y47yeBsK1xI=
+github.com/opencord/voltha-lib-go/v7 v7.1.2 h1:pLO6eorxrPTvABar0Q+4D4znk8S8ndb6t24BmbbWOXs=
+github.com/opencord/voltha-lib-go/v7 v7.1.2/go.mod h1:LjoFfwqdf/OHKUmzMqzBDGmoxfjmq9l/Y47yeBsK1xI=
github.com/opencord/voltha-protos/v5 v5.1.0/go.mod h1:Ff7eoWsL0K7oNtOBB4UcuWDZdv1zBQ9lLHvpJr02erE=
github.com/opencord/voltha-protos/v5 v5.1.1 h1:Mj3HQVUw/SNwKOQB1do0fd09ZL/DCSOiFUqa7xR4IsE=
github.com/opencord/voltha-protos/v5 v5.1.1/go.mod h1:Ff7eoWsL0K7oNtOBB4UcuWDZdv1zBQ9lLHvpJr02erE=
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index d819fae..1adf88c 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -209,6 +209,8 @@
if err := agent.dbProxy.Remove(ctx, agent.deviceID); err != nil {
return err
}
+ //send the device event to the message bus
+ _ = agent.deviceMgr.Agent.SendDeviceDeletedEvent(ctx, agent.device, time.Now().Unix())
close(agent.exitChannel)
diff --git a/rw_core/core/device/event/event.go b/rw_core/core/device/event/event.go
index ab80736..5d8ccda 100644
--- a/rw_core/core/device/event/event.go
+++ b/rw_core/core/device/event/event.go
@@ -321,3 +321,27 @@
logger.Debugw(ctx, "device-state-change-sent", log.Fields{"event": *de})
return nil
}
+
+// SendDeviceDeletedEvent sends Device deleted Event to message bus
+func (q *Agent) SendDeviceDeletedEvent(ctx context.Context, device *voltha.Device, raisedTs int64) error {
+
+ var onuId uint32
+ var ponId uint32
+
+ subCategory := voltha.EventSubCategory_OLT
+ if !device.Root {
+ onuId = device.ProxyAddress.OnuId
+ ponId = device.ProxyAddress.ChannelId
+ subCategory = voltha.EventSubCategory_ONU
+ }
+ de := ev.CreateDeviceDeletedEvent(device.SerialNumber, device.Id, device.ParentId,
+ onuId, ponId, device.Root)
+
+ if err := q.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT,
+ subCategory, raisedTs); err != nil {
+ logger.Errorw(ctx, "error-sending-device-deleted-event", log.Fields{"id": device.Id, "err": err})
+ return err
+ }
+ logger.Debugw(ctx, "device-deleted-event-sent", log.Fields{"event": *de})
+ return nil
+}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v7/pkg/events/utils.go b/vendor/github.com/opencord/voltha-lib-go/v7/pkg/events/utils.go
index 4598161..f02c3bc 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v7/pkg/events/utils.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v7/pkg/events/utils.go
@@ -48,12 +48,20 @@
ContextIsRoot ContextType = "is-root"
// ContextParentPort is for the parent interface id of child in the context of the event
ContextParentPort ContextType = "parent-port"
+ //ContextPonID is the PON ID the Child device is connected to
+ ContextPonID ContextType = "pon-id"
+ //ContextOnuID is the Onu ID of the child device
+ ContextOnuID ContextType = "onu-id"
+ //ContextParentSerialNum is the serila number of the parent device
+ ContextParentSerialNum ContextType = "olt-serial-number"
)
type EventName string
const (
DeviceStateChangeEvent EventName = "DEVICE_STATE_CHANGE"
+ OltDeviceStateDeleted EventName = "OLT_DELETED_RAISE_EVENT"
+ OnuDeviceStateDeleted EventName = "ONU_DELETED_RAISE_EVENT"
)
type EventAction string
@@ -89,3 +97,27 @@
DeviceEventName: fmt.Sprintf("%s_%s", string(DeviceStateChangeEvent), string(Raise)),
}
}
+
+//CreateDeviceDeletedEvent forms and returns a new DeviceState Event
+func CreateDeviceDeletedEvent(serialNumber string, deviceID string, parentID string,
+ onuId uint32, parentPonPort uint32, isRoot bool) *voltha.DeviceEvent {
+
+ context := make(map[string]string)
+ eventName := string(OltDeviceStateDeleted)
+ /* Populating event context */
+ context[string(ContextSerialNumber)] = serialNumber
+ context[string(ContextDeviceID)] = deviceID
+ if !isRoot {
+ context[string(ContextPonID)] = strconv.FormatUint(uint64(parentPonPort), 10)
+ context[string(ContextOnuID)] = strconv.FormatUint(uint64(onuId), 10)
+ context[string(ContextParentID)] = parentID
+ eventName = string(OnuDeviceStateDeleted)
+
+ }
+
+ return &voltha.DeviceEvent{
+ Context: context,
+ ResourceId: deviceID,
+ DeviceEventName: eventName,
+ }
+}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 650f720..f45379f 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -211,7 +211,7 @@
github.com/modern-go/concurrent
# github.com/modern-go/reflect2 v1.0.1
github.com/modern-go/reflect2
-# github.com/opencord/voltha-lib-go/v7 v7.1.1
+# github.com/opencord/voltha-lib-go/v7 v7.1.2
## explicit
github.com/opencord/voltha-lib-go/v7/pkg/adapters/common
github.com/opencord/voltha-lib-go/v7/pkg/config