Skip to content

Commit

Permalink
AMF controller full code
Browse files Browse the repository at this point in the history
  • Loading branch information
vireshnavalli committed May 26, 2023
1 parent d780f83 commit 5e4721b
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 125 deletions.
55 changes: 52 additions & 3 deletions free5gc-operator/controllers/amfdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -262,9 +263,9 @@ func free5gcAMFDeployment(log logr.Logger, amfDeploy *workloadv1alpha1.AMFDeploy
},
},

Command: []string{
"sh", "-c", "set -x; do while [ $(curl --insecure --connect-timeout 1 -s -o /dev/null -w \"%{http_code}\" \"http://nrf-nnrf:8000\") -ne 200 ]; do echo waiting for dependencies; sleep 1; done;",
},
Command: []string{"./amf"},
Args: []string{"-c", "../config/amfcfg.yaml"},

VolumeMounts: []apiv1.VolumeMount{
{
MountPath: "/free5gc/config/",
Expand Down Expand Up @@ -312,6 +313,34 @@ func free5gcAMFDeployment(log logr.Logger, amfDeploy *workloadv1alpha1.AMFDeploy
return deployment, nil
}

func free5gcAMFCreateService(amfDeploy *workloadv1alpha1.AMFDeployment) *apiv1.Service {
namespace := amfDeploy.ObjectMeta.Namespace
instanceName := amfDeploy.ObjectMeta.Name

labels := map[string]string{
"name": instanceName,
}

service := &apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: instanceName + "-amf-svc",
Namespace: namespace,
},
Spec: apiv1.ServiceSpec{
Selector: labels,
Ports: []apiv1.ServicePort{{
Name: "http",
Protocol: apiv1.ProtocolTCP,
Port: 80,
TargetPort: intstr.FromInt(80),
}},
Type: apiv1.ServiceTypeClusterIP,
},
}

return service
}

func free5gcAMFCreateConfigmap(logger logr.Logger, amfDeploy *workloadv1alpha1.AMFDeployment) (*apiv1.ConfigMap, error) {
namespace := amfDeploy.ObjectMeta.Namespace
instanceName := amfDeploy.ObjectMeta.Name
Expand Down Expand Up @@ -506,6 +535,13 @@ func (r *AMFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
cmFound = true
}

svcFound := false
svcName := amfDeploy.ObjectMeta.Name + "-amf-svc"
currSvc := &apiv1.Service{}
if err := r.Client.Get(ctx, types.NamespacedName{Name: svcName, Namespace: namespace}, currSvc); err == nil {
svcFound = true
}

dmFound := false
dmName := amfDeploy.ObjectMeta.Name
currDeployment := &appsv1.Deployment{}
Expand Down Expand Up @@ -544,6 +580,19 @@ func (r *AMFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
}

if !svcFound {
svc := free5gcAMFCreateService(amfDeploy)
log.Info("Creating AMFDeployment service", "AMFDeployment.namespace", namespace, "Service.name", svc.ObjectMeta.Name)
// Set the controller reference, specifying that AMFDeployment controling underlying deployment
if err := ctrl.SetControllerReference(amfDeploy, svc, r.Scheme); err != nil {
log.Error(err, "Got error while setting Owner reference on AMF service.", "AMFDeployment.namespace", namespace)
}
if err := r.Client.Create(ctx, svc); err != nil {
log.Error(err, fmt.Sprintf("Error: failed to create an AMF service %s\n", err.Error()))
return reconcile.Result{}, err
}
}

if deployment, err := free5gcAMFDeployment(log, amfDeploy); err != nil {
log.Error(err, fmt.Sprintf("Error: failed to generate deployment %s\n", err.Error()))
return reconcile.Result{}, err
Expand Down
230 changes: 108 additions & 122 deletions free5gc-operator/controllers/free5gc_amfcfg.go
Original file line number Diff line number Diff line change
@@ -1,136 +1,122 @@
/*
Free5GC Config
N2: NF Deployment IF
sbi:
scheme: http
registerIPv4: amf-namf
bindingIPv4: 0.0.0.0
port: 80
tls:
key: config/TLS/smf.key
pem: config/TLS/smf.pem
nrfUri: http://nrf-nnrf:8000
*/
package controllers

var AMFCfgTemplate string = `
info:
version: 1.0.0
description: AMF configuration
info:
version: 1.0.3
description: AMF initial local configuration
configuration:
ReportCaller: false
debugLevel: info
serviceNameList:
- namf-comm
- namf-evts
- namf-oam
- namf-mt
- namf-loc
ngapIpList:
- addr: {{ .N2_IP }}
sbi:
ngapIpList:
- {{ .N2_IP }}
sbi:
scheme: http
registerIPv4: amf-namf
bindingIPv4: 0.0.0.0
registerIPv4: release-name-free5gc-amf-service # IP used to register to NRF
bindingIPv4: 0.0.0.0 # IP used to bind the service
port: 80
tls:
key: config/TLS/amf.key
pem: config/TLS/amf.pem
nrfUri: http://nrf-nnrf:8000
servedGuamiList:
- plmnId:
mcc: 208
mnc: 93
amfId: cafe00
supportTaiList:
- plmnId:
mcc: 208
mnc: 93
tac: 1
plmnSupportList:
- plmnId:
mcc: 208
mnc: 93
nrfUri: http://nrf-nnrf:8000
amfName: AMF
serviceNameList:
- namf-comm
- namf-evts
- namf-mt
- namf-loc
- namf-oam
servedGuamiList:
- plmnId:
mcc: 208
mnc: 93
amfId: cafe00
supportTaiList:
- plmnId:
mcc: 208
mnc: 93
tac: 1
plmnSupportList:
- plmnId:
mcc: 208
mnc: 93
snssaiList:
- sst: 1
sd: 010203
- sst: 1
sd: 112233
supportDnnList:
- internet
security:
integrityOrder:
- NIA2
cipheringOrder:
- NEA0
networkName:
full: free5GC
short: free
locality: area1 # Name of the location where a set of AMF, SMF and UPFs are located
networkFeatureSupport5GS: # 5gs Network Feature Support IE, refer to TS 24.501
enable: true # append this IE in Registration accept or not
length: 1 # IE content length (uinteger, range: 1~3)
imsVoPS: 0 # IMS voice over PS session indicator (uinteger, range: 0~1)
emc: 0 # Emergency service support indicator for 3GPP access (uinteger, range: 0~3)
emf: 0 # Emergency service fallback indicator for 3GPP access (uinteger, range: 0~3)
iwkN26: 0 # Interworking without N26 interface indicator (uinteger, range: 0~1)
mpsi: 0 # MPS indicator (uinteger, range: 0~1)
emcN3: 0 # Emergency service support indicator for Non-3GPP access (uinteger, range: 0~1)
mcsi: 0 # MCS indicator (uinteger, range: 0~1)
t3502Value: 720
t3512Value: 3600
non3gppDeregistrationTimerValue: 3240
# retransmission timer for paging message
t3513:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Registration Accept message
t3522:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Registration Accept message
t3550:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Authentication Request/Security Mode Command message
t3560:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Notification message
t3565:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
t3570:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
- sst: 1
sd: 010203
- sst: 1
sd: 112233
supportDnnList:
- internet
security:
integrityOrder:
- NIA2
cipheringOrder:
- NEA0
networkName:
full: free5GC
short: free
locality: area1 # Name of the location where a set of AMF, SMF and UPFs are located
networkFeatureSupport5GS: # 5gs Network Feature Support IE, refer to TS 24.501
enable: true # append this IE in Registration accept or not
length: 1 # IE content length (uinteger, range: 1~3)
imsVoPS: 0 # IMS voice over PS session indicator (uinteger, range: 0~1)
emc: 0 # Emergency service support indicator for 3GPP access (uinteger, range: 0~3)
emf: 0 # Emergency service fallback indicator for 3GPP access (uinteger, range: 0~3)
iwkN26: 0 # Interworking without N26 interface indicator (uinteger, range: 0~1)
mpsi: 0 # MPS indicator (uinteger, range: 0~1)
emcN3: 0 # Emergency service support indicator for Non-3GPP access (uinteger, range: 0~1)
mcsi: 0 # MCS indicator (uinteger, range: 0~1)
t3502Value: 720
t3512Value: 3600
non3gppDeregistrationTimerValue: 3240
# retransmission timer for paging message
t3513:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Registration Accept message
t3522:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Registration Accept message
t3550:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Authentication Request/Security Mode Command message
t3560:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
# retransmission timer for NAS Notification message
t3565:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
t3570:
enable: true # true or false
expireTime: 6s # default is 6 seconds
maxRetryTimes: 4 # the max number of retransmission
logger:
AMF:
ReportCaller: false
debugLevel: info
Aper:
ReportCaller: false
debugLevel: info
FSM:
ReportCaller: false
debugLevel: info
NAS:
ReportCaller: false
debugLevel: info
NGAP:
ReportCaller: false
debugLevel: info
`
logger:
AMF:
ReportCaller: false
debugLevel: info
Aper:
ReportCaller: false
debugLevel: info
FSM:
ReportCaller: false
debugLevel: info
NAS:
ReportCaller: false
debugLevel: info
NGAP:
ReportCaller: false
debugLevel: info
`

0 comments on commit 5e4721b

Please sign in to comment.