X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fe2if_state.go;h=5f7eb353360fdab9b050f2b047ed3c6054644948;hb=refs%2Fchanges%2F62%2F10962%2F5;hp=0f4305656e1ae8088a6b6a2559ef877fbe2f367a;hpb=c7da4ee19c2b2a96c1eeccd8da944902fcd9323f;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/e2if_state.go b/pkg/control/e2if_state.go index 0f43056..5f7eb35 100644 --- a/pkg/control/e2if_state.go +++ b/pkg/control/e2if_state.go @@ -20,10 +20,12 @@ 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 { @@ -56,7 +58,35 @@ func (e *E2IfState) Init(c *Control) { e.control = c e.NbIdMap = make(map[string]string, 0) e.ReadE2ConfigurationFromRnib() - e.SubscribeChannels() + err := e.SubscribeChannels() + if err != nil { + xapp.Logger.Error("Init(): SubscribeChannels() failed: %v", err) + } +} + +func (e *E2IfState) GetE2NodesJson() []byte { + + e.mutex.Lock() + defer e.mutex.Unlock() + + // Map contains something like this{"RAN_NAME_1":"RAN_NAME_1","RAN_NAME_11":"RAN_NAME_11","RAN_NAME_2":"RAN_NAME_2"} + var ranNameList []string + for _, ranName := range e.NbIdMap { + ranNameList = append(ranNameList, ranName) + } + + e2NodesJson, err := json.Marshal(ranNameList) + if err != nil { + xapp.Logger.Error("GetE2Node() json.Marshal error: %v", err) + } + return e2NodesJson +} + +func (e *E2IfState) GetAllE2Nodes() map[string]string { + + e.mutex.Lock() + defer e.mutex.Unlock() + return e.NbIdMap } func (e *E2IfState) NotificationCb(ch string, events ...string) { @@ -67,7 +97,8 @@ func (e *E2IfState) NotificationCb(ch string, events ...string) { return } - if strings.Contains(events[0], "_CONNECTED") { + if strings.Contains(events[0], "_CONNECTED") && !strings.Contains(events[0], "_CONNECTED_SETUP_FAILED") { + e.control.UpdateCounter(cE2StateChangedToUp) nbId, err := ExtractNbiIdFromString(events[0]) if err != nil { xapp.Logger.Error("NotificationCb CONNECTED len(nbId) == 0 ") @@ -76,6 +107,7 @@ func (e *E2IfState) NotificationCb(ch string, events ...string) { xapp.Logger.Debug("E2 CONNECTED. NbId=%s", nbId) e.NbIdMap[nbId] = nbId } else if strings.Contains(events[0], "_DISCONNECTED") { + e.control.UpdateCounter(cE2StateChangedToDown) nbId, err := ExtractNbiIdFromString(events[0]) if err != nil { xapp.Logger.Error("NotificationCb DISCONNECTED len(nbId) == 0 ") @@ -86,6 +118,18 @@ func (e *E2IfState) NotificationCb(ch string, events ...string) { 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 + } + xapp.Logger.Debug("E2 Under Reset. NbId=%s", nbId) + if _, ok := e.NbIdMap[nbId]; ok { + e.control.registry.DeleteAllE2Subscriptions(nbId, e.control) + } } } @@ -113,7 +157,6 @@ func (e *E2IfState) ReadE2ConfigurationFromRnib() { if e.isNodeBActive(nbIdentity.InventoryName) == false { if _, ok := e.NbIdMap[nbIdentity.InventoryName]; ok { delete(e.NbIdMap, nbIdentity.InventoryName) - e.control.UpdateCounter(cE2StateChangedToDown) xapp.Logger.Debug("E2 connection DISCONNETED: %v", nbIdentity.InventoryName) // Delete all subscriptions related to InventoryName/nbId @@ -124,7 +167,6 @@ func (e *E2IfState) ReadE2ConfigurationFromRnib() { if _, ok := e.NbIdMap[nbIdentity.InventoryName]; !ok { e.NbIdMap[nbIdentity.InventoryName] = nbIdentity.InventoryName - e.control.UpdateCounter(cE2StateChangedToDown) xapp.Logger.Debug("E2 connection CONNECTED: %v", nbIdentity.InventoryName) } } @@ -168,6 +210,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 ")