@@ -2,6 +2,7 @@ package context
22
33import (
44 "errors"
5+ "fmt"
56 "math/rand"
67 "net"
78 "reflect"
@@ -80,7 +81,7 @@ func AllocateUPFID() {
8081}
8182
8283// NewUserPlaneInformation process the configuration then returns a new instance of UserPlaneInformation
83- func NewUserPlaneInformation (upTopology * factory.UserPlaneInformation ) * UserPlaneInformation {
84+ func NewUserPlaneInformation (upTopology * factory.UserPlaneInformation ) ( * UserPlaneInformation , error ) {
8485 nodePool := make (map [string ]* UPNode )
8586 upfPool := make (map [string ]* UPNode )
8687 anPool := make (map [string ]* UPNode )
@@ -142,7 +143,7 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan
142143 for _ , pool := range dnnInfoConfig .Pools {
143144 ueIPPool := NewUEIPPool (pool )
144145 if ueIPPool == nil {
145- logger . InitLog . Fatalf ("invalid pools value: %+v" , pool )
146+ return nil , fmt . Errorf ("invalid pools value: %+v" , pool )
146147 } else {
147148 ueIPPools = append (ueIPPools , ueIPPool )
148149 allUEIPPools = append (allUEIPPools , ueIPPool )
@@ -151,13 +152,13 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan
151152 for _ , staticPool := range dnnInfoConfig .StaticPools {
152153 staticUeIPPool := NewUEIPPool (staticPool )
153154 if staticUeIPPool == nil {
154- logger . InitLog . Fatalf ("invalid pools value: %+v" , staticPool )
155+ return nil , fmt . Errorf ("invalid pools value: %+v" , staticPool )
155156 } else {
156157 staticUeIPPools = append (staticUeIPPools , staticUeIPPool )
157158 for _ , dynamicUePool := range ueIPPools {
158159 if dynamicUePool .ueSubNet .Contains (staticUeIPPool .ueSubNet .IP ) {
159160 if err := dynamicUePool .Exclude (staticUeIPPool ); err != nil {
160- logger . InitLog . Fatalf ("exclude static Pool[%s] failed: %v" ,
161+ return nil , fmt . Errorf ("exclude static Pool[%s] failed: %v" ,
161162 staticUeIPPool .ueSubNet , err )
162163 }
163164 }
@@ -200,7 +201,7 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan
200201 }
201202
202203 if isOverlap (allUEIPPools ) {
203- logger . InitLog . Fatalf ("overlap cidr value between UPFs" )
204+ return nil , fmt . Errorf ("overlap cidr value between UPFs" )
204205 }
205206
206207 for _ , link := range upTopology .Links {
@@ -229,7 +230,7 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan
229230 DefaultUserPlanePathToUPF : make (map [string ]map [string ][]* UPNode ),
230231 }
231232
232- return userplaneInformation
233+ return userplaneInformation , nil
233234}
234235
235236func (upi * UserPlaneInformation ) UpNodesToConfiguration () map [string ]* factory.UPNode {
@@ -358,13 +359,51 @@ func (upi *UserPlaneInformation) LinksToConfiguration() []*factory.UPLink {
358359 return links
359360}
360361
361- func (upi * UserPlaneInformation ) UpNodesFromConfiguration (upTopology * factory.UserPlaneInformation ) {
362+ func (upi * UserPlaneInformation ) UpNodesFromConfiguration (upTopology * factory.UserPlaneInformation ) error {
363+ candidateUPNodes := make (map [string ]* UPNode , len (upi .UPNodes ))
364+ for name , node := range upi .UPNodes {
365+ candidateUPNodes [name ] = node
366+ }
367+
368+ candidateUPFs := make (map [string ]* UPNode , len (upi .UPFs ))
369+ for name , node := range upi .UPFs {
370+ candidateUPFs [name ] = node
371+ }
372+
373+ candidateAccessNetwork := make (map [string ]* UPNode , len (upi .AccessNetwork ))
374+ for name , node := range upi .AccessNetwork {
375+ candidateAccessNetwork [name ] = node
376+ }
377+
378+ candidateUPFsID := make (map [string ]string , len (upi .UPFsID ))
379+ for name , id := range upi .UPFsID {
380+ candidateUPFsID [name ] = id
381+ }
382+
383+ candidateUPFsIPtoID := make (map [string ]string , len (upi .UPFsIPtoID ))
384+ for ip , id := range upi .UPFsIPtoID {
385+ candidateUPFsIPtoID [ip ] = id
386+ }
387+
388+ candidateUPFIPToName := make (map [string ]string , len (upi .UPFIPToName ))
389+ for ip , name := range upi .UPFIPToName {
390+ candidateUPFIPToName [ip ] = name
391+ }
392+
393+ createdUPFs := make ([]* UPF , 0 )
394+ cleanupCreatedUPFs := func () {
395+ for _ , upf := range createdUPFs {
396+ upfPool .Delete (upf .UUID ())
397+ }
398+ }
399+
362400 for name , node := range upTopology .UPNodes {
363- if _ , ok := upi . UPNodes [name ]; ok {
401+ if _ , ok := candidateUPNodes [name ]; ok {
364402 logger .InitLog .Warningf ("Node [%s] already exists in SMF.\n " , name )
365403 continue
366404 }
367405 upNode := new (UPNode )
406+ upNode .Name = name
368407 upNode .Type = UPNodeType (node .Type )
369408 switch upNode .Type {
370409 case UPNODE_UPF :
@@ -397,6 +436,7 @@ func (upi *UserPlaneInformation) UpNodesFromConfiguration(upTopology *factory.Us
397436 }
398437
399438 upNode .UPF = NewUPF (& upNode .NodeID , node .InterfaceUpfInfoList )
439+ createdUPFs = append (createdUPFs , upNode .UPF )
400440 snssaiInfos := make ([]* SnssaiUPFInfo , 0 )
401441 for _ , snssaiInfoConfig := range node .SNssaiInfos {
402442 snssaiInfo := & SnssaiUPFInfo {
@@ -413,21 +453,24 @@ func (upi *UserPlaneInformation) UpNodesFromConfiguration(upTopology *factory.Us
413453 for _ , pool := range dnnInfoConfig .Pools {
414454 ueIPPool := NewUEIPPool (pool )
415455 if ueIPPool == nil {
416- logger .InitLog .Fatalf ("invalid pools value: %+v" , pool )
456+ cleanupCreatedUPFs ()
457+ return fmt .Errorf ("invalid pools value: %+v" , pool )
417458 } else {
418459 ueIPPools = append (ueIPPools , ueIPPool )
419460 }
420461 }
421462 for _ , pool := range dnnInfoConfig .StaticPools {
422463 ueIPPool := NewUEIPPool (pool )
423464 if ueIPPool == nil {
424- logger .InitLog .Fatalf ("invalid pools value: %+v" , pool )
465+ cleanupCreatedUPFs ()
466+ return fmt .Errorf ("invalid pools value: %+v" , pool )
425467 } else {
426468 staticUeIPPools = append (staticUeIPPools , ueIPPool )
427469 for _ , dynamicUePool := range ueIPPools {
428470 if dynamicUePool .ueSubNet .Contains (ueIPPool .ueSubNet .IP ) {
429471 if err := dynamicUePool .Exclude (ueIPPool ); err != nil {
430- logger .InitLog .Fatalf ("exclude static Pool[%s] failed: %v" ,
472+ cleanupCreatedUPFs ()
473+ return fmt .Errorf ("exclude static Pool[%s] failed: %v" ,
431474 ueIPPool .ueSubNet , err )
432475 }
433476 }
@@ -445,39 +488,49 @@ func (upi *UserPlaneInformation) UpNodesFromConfiguration(upTopology *factory.Us
445488 snssaiInfos = append (snssaiInfos , snssaiInfo )
446489 }
447490 upNode .UPF .SNssaiInfos = snssaiInfos
448- upi . UPFs [name ] = upNode
491+ candidateUPFs [name ] = upNode
449492
450493 // AllocateUPFID
451494 upfid := upNode .UPF .UUID ()
452495 upfip := upNode .NodeID .ResolveNodeIdToIp ().String ()
453- upi . UPFsID [name ] = upfid
454- upi . UPFsIPtoID [upfip ] = upfid
496+ candidateUPFsID [name ] = upfid
497+ candidateUPFsIPtoID [upfip ] = upfid
455498
456499 case UPNODE_AN :
457500 upNode .ANIP = net .ParseIP (node .ANIP )
458- upi . AccessNetwork [name ] = upNode
501+ candidateAccessNetwork [name ] = upNode
459502 default :
460503 logger .InitLog .Warningf ("invalid UPNodeType: %s\n " , upNode .Type )
461504 }
462505
463- upi . UPNodes [name ] = upNode
506+ candidateUPNodes [name ] = upNode
464507
465508 ipStr := upNode .NodeID .ResolveNodeIdToIp ().String ()
466- upi . UPFIPToName [ipStr ] = name
509+ candidateUPFIPToName [ipStr ] = name
467510 }
468511
469512 // overlap UE IP pool validation
470513 allUEIPPools := []* UeIPPool {}
471- for _ , upf := range upi . UPFs {
514+ for _ , upf := range candidateUPFs {
472515 for _ , snssaiInfo := range upf .UPF .SNssaiInfos {
473516 for _ , dnn := range snssaiInfo .DnnList {
474517 allUEIPPools = append (allUEIPPools , dnn .UeIPPools ... )
475518 }
476519 }
477520 }
478521 if isOverlap (allUEIPPools ) {
479- logger .InitLog .Fatalf ("overlap cidr value between UPFs" )
522+ cleanupCreatedUPFs ()
523+ return fmt .Errorf ("overlap cidr value between UPFs" )
480524 }
525+
526+ upi .UPNodes = candidateUPNodes
527+ upi .UPFs = candidateUPFs
528+ upi .AccessNetwork = candidateAccessNetwork
529+ upi .UPFsID = candidateUPFsID
530+ upi .UPFsIPtoID = candidateUPFsIPtoID
531+ upi .UPFIPToName = candidateUPFIPToName
532+
533+ return nil
481534}
482535
483536func (upi * UserPlaneInformation ) LinksFromConfiguration (upTopology * factory.UserPlaneInformation ) {
0 commit comments