This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
NFManagemant.go
91 lines (86 loc) · 2.6 KB
/
NFManagemant.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package udr_consumer
import (
"context"
"fmt"
"free5gc/lib/Nnrf_NFManagement"
"free5gc/lib/openapi/models"
"free5gc/src/udr/factory"
"free5gc/src/udr/udr_context"
"net/http"
"strings"
"time"
)
func BuildNFInstance(context *udr_context.UDRContext) (profile models.NfProfile) {
config := factory.UdrConfig
profile.NfInstanceId = context.NfId
profile.NfType = models.NfType_UDR
profile.NfStatus = models.NfStatus_REGISTERED
version := config.Info.Version
tmpVersion := strings.Split(version, ".")
versionUri := "v" + tmpVersion[0]
apiPrefix := fmt.Sprintf("%s://%s:%d", context.UriScheme, context.HttpIPv4Address, context.HttpIpv4Port)
services := []models.NfService{
{
ServiceInstanceId: "DataRepository",
ServiceName: models.ServiceName_NUDR_DR,
Versions: &[]models.NfServiceVersion{
{
ApiFullVersion: version,
ApiVersionInUri: versionUri,
},
},
Scheme: models.UriScheme(context.UriScheme),
NfServiceStatus: models.NfServiceStatus_REGISTERED,
ApiPrefix: apiPrefix,
IpEndPoints: &[]models.IpEndPoint{
{
Ipv4Address: context.HttpIPv4Address,
Transport: models.TransportProtocol_TCP,
Port: int32(context.HttpIpv4Port),
},
},
},
}
profile.NfServices = &services
// TODO: finish the Udr Info
profile.UdrInfo = &models.UdrInfo{
SupportedDataSets: []models.DataSetId{
// models.DataSetId_APPLICATION,
// models.DataSetId_EXPOSURE,
// models.DataSetId_POLICY,
models.DataSetId_SUBSCRIPTION,
},
}
return
}
func SendRegisterNFInstance(nrfUri, nfInstanceId string, profile models.NfProfile) (resouceNrfUri string, retrieveNfInstanceId string, err error) {
// Set client and set url
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("UDR register to NRF Error[%s]", err.Error()))
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("handler returned wrong status code", status)
fmt.Println("NRF return wrong status code", status)
}
}
return
}