Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds subscribers to Am data collection when they are created. #84

Merged
13 changes: 8 additions & 5 deletions configapi/api_sub_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,18 @@ func GetSubscribers(c *gin.Context) {

logger.WebUILog.Infoln("Get All Subscribers List")

var subsList []configmodels.SubsListIE = make([]configmodels.SubsListIE, 0)
var subsList []configmodels.SubsListIE
amDataList := MongoDBLibrary.RestfulAPIGetMany(amDataColl, bson.M{})
for _, amData := range amDataList {
ueId := amData["ueId"]
servingPlmnId := amData["servingPlmnId"]

tmp := configmodels.SubsListIE{
PlmnID: servingPlmnId.(string),
UeId: ueId.(string),
UeId: amData["ueId"].(string),
}

if servingPlmnId, plmnIdExists := amData["servingPlmnId"]; plmnIdExists {
tmp.PlmnID = servingPlmnId.(string)
}

subsList = append(subsList, tmp)
}

Expand Down
23 changes: 22 additions & 1 deletion proto/server/configEvtHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func configHandler(configMsgChan chan *configmodels.ConfigMessage, configReceive
imsiData[imsiVal] = configMsg.AuthSubData
rwLock.Unlock()
configLog.Infof("Received Imsi [%v] configuration from config channel", configMsg.Imsi)
handleSubscriberPost(configMsg)
if factory.WebUIConfig.Configuration.Mode5G == true {
var configUMsg Update5GSubscriberMsg
configUMsg.Msg = configMsg
Expand Down Expand Up @@ -163,6 +164,17 @@ func configHandler(configMsgChan chan *configmodels.ConfigMessage, configReceive
}
}

func handleSubscriberPost(configMsg *configmodels.ConfigMessage) {
gab-arrobo marked this conversation as resolved.
Show resolved Hide resolved
rwLock.Lock()
basicAmData := map[string]interface{}{
"ueId": configMsg.Imsi,
}
filter := bson.M{"ueId": configMsg.Imsi}
basicDataBson := toBsonM(basicAmData)
RestfulAPIPost(amDataColl, filter, basicDataBson)
rwLock.Unlock()
}

func handleDeviceGroupPost(configMsg *configmodels.ConfigMessage, subsUpdateChan chan *Update5GSubscriberMsg) {
rwLock.Lock()
if factory.WebUIConfig.Configuration.Mode5G == true {
Expand Down Expand Up @@ -338,7 +350,13 @@ func updateAmProviosionedData(snssai *models.Snssai, qos *configmodels.DeviceGro
amDataBsonA := toBsonM(amData)
amDataBsonA["ueId"] = "imsi-" + imsi
amDataBsonA["servingPlmnId"] = mcc + mnc
filter := bson.M{"ueId": "imsi-" + imsi, "servingPlmnId": mcc + mnc}
filter := bson.M{
"ueId": "imsi-" + imsi,
"$or": []bson.M{
{"servingPlmnId": mcc + mnc},
{"servingPlmnId": bson.M{"$exists": false}},
},
}
RestfulAPIPost(amDataColl, filter, amDataBsonA)
}

Expand Down Expand Up @@ -414,6 +432,7 @@ func isDeviceGroupExistInSlice(msg *Update5GSubscriberMsg) *configmodels.Slice {
func getAddedGroupsList(slice, prevSlice *configmodels.Slice) (names []string) {
return getDeleteGroupsList(prevSlice, slice)
}

func getDeleteGroupsList(slice, prevSlice *configmodels.Slice) (names []string) {
for prevSlice == nil {
return
Expand All @@ -440,6 +459,7 @@ func getDeleteGroupsList(slice, prevSlice *configmodels.Slice) (names []string)

return
}

func Config5GUpdateHandle(confChan chan *Update5GSubscriberMsg) {
for confData := range confChan {
switch confData.Msg.MsgType {
Expand All @@ -457,6 +477,7 @@ func Config5GUpdateHandle(confChan chan *Update5GSubscriberMsg) {
logger.WebUILog.Debugln("Delete AuthenticationSubscription", imsi)
filter := bson.M{"ueId": "imsi-" + imsi}
RestfulAPIDeleteOne(authSubsDataColl, filter)
RestfulAPIDeleteOne(amDataColl, filter)
}
rwLock.RUnlock()

Expand Down
27 changes: 27 additions & 0 deletions proto/server/configEvtHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,30 @@ func Test_handleNetworkSlicePost_alreadyExists(t *testing.T) {
}
}
}

func Test_handleSubscriberPost(t *testing.T) {
imsi := "1234"
gab-arrobo marked this conversation as resolved.
Show resolved Hide resolved
factory.WebUIConfig.Configuration.Mode5G = true
configMsg := configmodels.ConfigMessage{
MsgType: configmodels.Sub_data,
Imsi: imsi,
}

postData = make([]map[string]interface{}, 0)
handleSubscriberPost(&configMsg)

expected_collection := "subscriptionData.provisionedData.amData"
if postData[0]["coll"] != expected_collection {
t.Errorf("Expected collection %v, got %v", expected_collection, postData[0]["coll"])
}

expected_filter := bson.M{"ueId": imsi}
if !reflect.DeepEqual(postData[0]["filter"], expected_filter) {
t.Errorf("Expected filter %v, got %v", expected_filter, postData[0]["filter"])
}

var result map[string]interface{} = postData[0]["data"].(map[string]interface{})
if result["ueId"] != imsi {
t.Errorf("Expected ueId %v, got %v", imsi, result["ueId"])
}
}