This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
/
NFManagement.go
63 lines (59 loc) · 1.9 KB
/
NFManagement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package ausf_consumer
import (
"context"
"fmt"
"free5gc/lib/Nnrf_NFManagement"
"free5gc/lib/openapi/models"
"free5gc/src/ausf/ausf_context"
"net/http"
"strings"
"time"
)
func BuildNFInstance(ausfContext *ausf_context.AUSFContext) (profile models.NfProfile, err error) {
profile.NfInstanceId = ausfContext.NfId
profile.NfType = models.NfType_AUSF
profile.NfStatus = models.NfStatus_REGISTERED
profile.Ipv4Addresses = append(profile.Ipv4Addresses, ausfContext.HttpIPv4Address)
services := []models.NfService{}
for _, nfService := range ausfContext.NfService {
services = append(services, nfService)
}
if len(services) > 0 {
profile.NfServices = &services
}
var ausfInfo models.AusfInfo
ausfInfo.GroupId = ausfContext.GroupId
profile.AusfInfo = &ausfInfo
profile.PlmnList = &ausfContext.PlmnList
return
}
func SendRegisterNFInstance(nrfUri, nfInstanceId string, profile models.NfProfile) (resouceNrfUri string, retrieveNfInstanceID string, err error) {
configuration := Nnrf_NFManagement.NewConfiguration()
configuration.SetBasePath(nrfUri)
client := Nnrf_NFManagement.NewAPIClient(configuration)
var res *http.Response
for {
_, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(context.TODO(), nfInstanceId, profile)
if err != nil || res == nil {
//TODO : add log
fmt.Println(fmt.Errorf("AUSF register to NRF Error[%v]", err))
time.Sleep(2 * time.Second)
continue
}
status := res.StatusCode
if status == http.StatusOK {
// NFUpdate
break
} else if status == http.StatusCreated {
// NFRegister
resourceUri := res.Header.Get("Location")
resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")]
retrieveNfInstanceID = resourceUri[strings.LastIndex(resourceUri, "/")+1:]
break
} else {
fmt.Println(fmt.Errorf("handler returned wrong status code %d", status))
fmt.Println(fmt.Errorf("NRF return wrong status code %d", status))
}
}
return
}