J release: Release container Image
[ric-plt/submgr.git] / pkg / control / e2if_state.go
index b86ef81..e8ceef2 100644 (file)
@@ -22,9 +22,10 @@ package control
 import (
        "encoding/json"
        "fmt"
-       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        "strings"
        "sync"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
 )
 
 type XappRnibIf struct {
@@ -48,14 +49,16 @@ func CreateXappRnibIfInstance() XappRnibInterface {
 }
 
 type E2IfState struct {
-       mutex   sync.Mutex
-       control *Control
-       NbIdMap map[string]string
+       mutex         sync.Mutex
+       control       *Control
+       NbIdMap       map[string]string
+       NbIdStatusMap map[string]string
 }
 
 func (e *E2IfState) Init(c *Control) {
        e.control = c
        e.NbIdMap = make(map[string]string, 0)
+       e.NbIdStatusMap = make(map[string]string, 0)
        e.ReadE2ConfigurationFromRnib()
        err := e.SubscribeChannels()
        if err != nil {
@@ -105,6 +108,7 @@ func (e *E2IfState) NotificationCb(ch string, events ...string) {
                }
                xapp.Logger.Debug("E2 CONNECTED. NbId=%s", nbId)
                e.NbIdMap[nbId] = nbId
+               e.NbIdStatusMap[nbId] = "CONNECTED"
        } else if strings.Contains(events[0], "_DISCONNECTED") {
                e.control.UpdateCounter(cE2StateChangedToDown)
                nbId, err := ExtractNbiIdFromString(events[0])
@@ -114,9 +118,23 @@ func (e *E2IfState) NotificationCb(ch string, events ...string) {
                }
                xapp.Logger.Debug("E2 DISCONNECTED. NbId=%s", nbId)
                if _, ok := e.NbIdMap[nbId]; ok {
+                       e.NbIdStatusMap[nbId] = "DISCONNECTED"
                        delete(e.NbIdMap, nbId)
                        e.control.registry.DeleteAllE2Subscriptions(nbId, e.control)
                }
+       } else if strings.Contains(events[0], "_UNDER_RESET") {
+               xapp.Logger.Debug("NotificationCb UNDER_RESET len(nbId) == 0 ")
+               e.control.UpdateCounter(cE2StateUnderReset)
+               nbId, err := ExtractNbiIdFromString(events[0])
+               if err != nil {
+                       xapp.Logger.Error("NotificationCb _UNDER_RESET %v ", err)
+                       return
+               }
+               e.NbIdStatusMap[nbId] = "UNDER_RESET"
+               xapp.Logger.Debug("E2 Under Reset. NbId=%s", nbId)
+               if _, ok := e.NbIdMap[nbId]; ok {
+                       e.control.registry.DeleteAllE2Subscriptions(nbId, e.control)
+               }
        }
 }
 
@@ -182,6 +200,15 @@ func (e *E2IfState) IsE2ConnectionUp(nbId *string) bool {
        }
 }
 
+func (e *E2IfState) IsE2ConnectionUnderReset(nbId *string) bool {
+
+       if status := e.NbIdStatusMap[*nbId]; status == "UNDER_RESET" {
+               return true
+       } else {
+               return false
+       }
+}
+
 func ExtractNbiIdFromString(s string) (string, error) {
 
        // Expected string formats are below
@@ -197,6 +224,9 @@ func ExtractNbiIdFromString(s string) (string, error) {
        } else if strings.Contains(s, "_DISCONNECTED") {
                splitStringTbl := strings.Split(s, "_DISCONNECTED")
                nbId = splitStringTbl[0]
+       } else if strings.Contains(s, "_UNDER_RESET") {
+               splitStringTbl := strings.Split(s, "_UNDER_RESET")
+               nbId = splitStringTbl[0]
        }
        if len(nbId) == 0 {
                return "", fmt.Errorf("ExtractNbiIdFromString(): len(nbId) == 0 ")