Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Dec 11, 2023
1 parent 5e69ec8 commit aa08b20
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 36 deletions.
12 changes: 6 additions & 6 deletions context/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func SetupSmfCollection() {
}

smfCount := MongoDBLibrary.GetUniqueIdentity("smfCount")
logger.CtxLog.Infof("unique id - init smfCount %v\n", smfCount)
logger.CtxLog.Infof("unique id - init smfCount %+v\n", smfCount)

// set os env
os.Setenv("SMF_COUNT", strconv.Itoa(int(smfCount)))
Expand Down Expand Up @@ -248,7 +248,7 @@ func StoreSmContextInDB(smContext *SMContext) {
defer smContext.SMLock.Unlock()
smContextBsonA := ToBsonM(smContext)
filter := bson.M{"ref": smContext.Ref}
logger.CtxLog.Infof("filter: %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)

MongoDBLibrary.RestfulAPIPost(SmContextDataColl, filter, smContextBsonA)

Expand All @@ -273,7 +273,7 @@ func StoreSeidContextInDB(seidUint uint64, smContext *SMContext) {
}
itemBsonA := ToBsonMSeidRef(item)
filter := bson.M{"seid": seid}
logger.CtxLog.Infof("filter : %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)

MongoDBLibrary.RestfulAPIPost(SeidSmContextCol, filter, itemBsonA)
}
Expand All @@ -287,7 +287,7 @@ func StoreRefToSeidInDB(seidUint uint64, smContext *SMContext) {
}
itemBsonA := ToBsonMSeidRef(item)
filter := bson.M{"ref": smContext.Ref}
logger.CtxLog.Infof("filter : %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)

MongoDBLibrary.RestfulAPIPost(RefSeidCol, filter, itemBsonA)
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func DeleteSmContextInDBBySEID(seidUint uint64) {
seid := SeidConv(seidUint)
fmt.Println("db - delete SMContext In DB by seid")
filter := bson.M{"seid": seid}
logger.CtxLog.Infof("filter : %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)

result := MongoDBLibrary.RestfulAPIGetOne(SeidSmContextCol, filter)
if result != nil {
Expand All @@ -367,7 +367,7 @@ func DeleteSmContextInDBBySEID(seidUint uint64) {
func DeleteSmContextInDBByRef(ref string) {
fmt.Println("db - delete SMContext In DB w ref")
filter := bson.M{"ref": ref}
logger.CtxLog.Infof("filter : %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)
MongoDBLibrary.RestfulAPIDeleteOne(SmContextDataColl, filter)
}

Expand Down
2 changes: 1 addition & 1 deletion context/db_uptunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func ToBsonMNodeInDB(data *DataPathNodeInDB) (ret bson.M) {
func StoreNodeInDB(nodeInDB *DataPathNodeInDB) {
itemBsonA := ToBsonMNodeInDB(nodeInDB)
filter := bson.M{"nodeIDInDB": nodeInDB.DataPathNodeUPFNodeID}
logger.CtxLog.Infof("filter : %v\n", filter)
logger.CtxLog.Infof("filter : %+v\n", filter)

MongoDBLibrary.RestfulAPIPost(NodeInDBCol, filter, itemBsonA)
}
Expand Down
5 changes: 4 additions & 1 deletion context/ip_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ func (a *IPAllocator) Allocate(imsi string) (net.IP, error) {
}

if offset, err := a.g.allocate(); err != nil {
return nil, errors.New("ip allocation failed " + err.Error())
return nil, errors.New("ip allocation failed" + err.Error())
} else {
// smfCount := MongoDBLibrary.GetSmfCountFromDb()

smfCountStr := os.Getenv("SMF_COUNT")
if smfCountStr == "" {
smfCountStr = "1"
}
smfCount, _ := strconv.Atoi(smfCountStr)
ip := IPAddrWithOffset(a.ipNetwork.IP, int(offset)+(int(smfCount)-1)*5000)
fmt.Printf("unique id - ip %v \n", ip)
Expand Down
30 changes: 15 additions & 15 deletions context/ip_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,57 +42,57 @@ func TestIPPoolAlloc(t *testing.T) {

func TestIPPoolAllocRelease(t *testing.T) {

allocator, err := smf_context.NewIPAllocator("192.168.0.0/16")
allocator, err := smf_context.NewIPAllocator("192.168.1.0/24")
if err != nil {
t.Errorf("failed to allocate pool %v\n", err)
t.Errorf("failed to allocate pool %v", err)
}

ip1 := net.ParseIP("192.168.237.121")
ip1 := net.ParseIP("192.168.1.1")
for i := 1; i <= 255; i++ {
ip, err := allocator.Allocate("")
if err != nil {
t.Errorf("failed to allocate ip address %v\n", err)
t.Errorf("failed to allocate pool %v", err)
}
fmt.Printf("Allocated address = %v\n", ip)
if i == 1 {
if ip.Equal(ip1) == false {
t.Errorf("address not allocated in order ? allocated address %v\n", ip1)
t.Errorf("address not allocated in order ? allocated address %v", ip1)
}
allocator.Release("", ip)
}
if i == 2 {
ip2 := net.ParseIP("192.168.237.122")
ip2 := net.ParseIP("192.168.1.2")
if ip.Equal(ip2) == false {
t.Errorf("address not allocated in order ? allocated address %v\n", ip2)
t.Errorf("address not allocated in order ? allocated address %v", ip2)
}
}
//rollover, we should not be using first address again
if i == 255 && ip.Equal(ip1) == true {
//rollover, we should be using first address again
if i == 255 && ip.Equal(ip1) != true {
t.Errorf("Failed to allocate IP address = %v %v \n", ip, ip1)
}
}
}

func TestIPPoolAllocLeastRecentlyUsed(t *testing.T) {
allocator, err := smf_context.NewIPAllocator("192.168.0.0/16")
allocator, err := smf_context.NewIPAllocator("192.168.1.0/24")
if err != nil {
t.Errorf("failed to allocate pool %v\n", err)
t.Errorf("failed to allocate pool %v", err)
}

ip1, err := allocator.Allocate("")
if err != nil {
t.Errorf("failed to allocate pool %v\n", err)
t.Errorf("failed to allocate pool %v", err)
}
fmt.Printf("Allocated address = %v\n", ip1)
allocator.Release("", ip1)
ip2, err := allocator.Allocate("")
if err != nil {
t.Errorf("failed to allocate pool %v\n", err)
t.Errorf("failed to allocate pool %v", err)
}
fmt.Printf("Allocated address = %v\n", ip2)

//Same address is not allocate again.
//Same address is not allocate again..
if ip1.Equal(ip2) {
t.Errorf("ip1 %v & ip2 %v same\n ", ip1, ip2)
t.Errorf("ip1 %v & ip2 %v same ", ip1, ip2)
}
}
8 changes: 4 additions & 4 deletions pfcp/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func HandlePfcpSessionEstablishmentResponse(msg *pfcpUdp.Message) {
}
smContext := smf_context.GetSMContextBySEID(SEID)
logger.PfcpLog.Infoln("In HandlePfcpSessionEstablishmentResponse SEID ", SEID)
logger.PfcpLog.Infof("In HandlePfcpSessionEstablishmentResponse smContext %v\n", smContext)
logger.PfcpLog.Infof("In HandlePfcpSessionEstablishmentResponse smContext %+v\n", smContext)

//Get NodeId from Seq:NodeId Map
seq := msg.PfcpMessage.Header.SequenceNumber
Expand Down Expand Up @@ -235,13 +235,13 @@ func HandlePfcpSessionModificationResponse(msg *pfcpUdp.Message) {
logger.PfcpLog.Infoln("In HandlePfcpSessionModificationResponse")

pfcpRsp := msg.PfcpMessage.Body.(pfcp.PFCPSessionModificationResponse)
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse pfcpRsp.Cause.CauseValue = [%v], accepted?? %v\n", pfcpRsp.Cause.CauseValue, pfcpRsp.Cause.CauseValue == pfcpType.CauseRequestAccepted)
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse pfcpRsp.Cause.CauseValue = [%+v], accepted?? %+v\n", pfcpRsp.Cause.CauseValue, pfcpRsp.Cause.CauseValue == pfcpType.CauseRequestAccepted)

SEID := msg.PfcpMessage.Header.SEID
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse SEID %v\n", SEID)
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse SEID %+v\n", SEID)

smContext := smf_context.GetSMContextBySEID(SEID)
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse smContext found by SEID %v\n", smContext)
logger.PfcpLog.Infof("In HandlePfcpSessionModificationResponse smContext found by SEID %+v\n", smContext)

if SEID == 0 {
if eventData, ok := msg.EventData.(pfcpUdp.PfcpEventData); !ok {
Expand Down
10 changes: 5 additions & 5 deletions pfcp/message/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func SendHeartbeatRequest(upNodeID pfcpType.NodeID, upfPort uint16) error {
logger.PfcpLog.Fatalln(err)
}
pfcpMsgString := string(pfcpMsgBytes)
logger.PfcpLog.Debugf("pfcp rsp status ok, %v\n", pfcpMsgString)
logger.PfcpLog.Debugf("pfcp rsp status ok, %+v\n", pfcpMsgString)
pfcpRspMsg := pfcp.Message{}
json.Unmarshal(pfcpMsgBytes, &pfcpRspMsg)
adapter.HandleAdapterPfcpRsp(pfcpRspMsg, nil)
Expand Down Expand Up @@ -182,7 +182,7 @@ func SendPfcpAssociationSetupRequest(upNodeID pfcpType.NodeID, upfPort uint16) {
logger.PfcpLog.Fatalln(err)
}
pfcpMsgString := string(pfcpMsgBytes)
logger.PfcpLog.Debugf("pfcp rsp status ok, %v\n", pfcpMsgString)
logger.PfcpLog.Debugf("pfcp rsp status ok, %+v\n", pfcpMsgString)
pfcpRspMsg := pfcp.Message{}
json.Unmarshal(pfcpMsgBytes, &pfcpRspMsg)
adapter.HandleAdapterPfcpRsp(pfcpRspMsg, nil)
Expand Down Expand Up @@ -322,7 +322,7 @@ func SendPfcpSessionEstablishmentRequest(
logger.PfcpLog.Fatalln(err)
}
pfcpMsgString := string(pfcpMsgBytes)
logger.PfcpLog.Debugf("pfcp rsp status ok, %v", pfcpMsgString)
logger.PfcpLog.Debugf("pfcp rsp status ok, %+v", pfcpMsgString)
pfcpRspMsg := pfcp.Message{}
json.Unmarshal(pfcpMsgBytes, &pfcpRspMsg)
eventData := pfcpUdp.PfcpEventData{LSEID: ctx.PFCPContext[ip.String()].LocalSEID, ErrHandler: HandlePfcpSendError}
Expand Down Expand Up @@ -406,7 +406,7 @@ func SendPfcpSessionModificationRequest(upNodeID pfcpType.NodeID,
logger.PfcpLog.Fatalln(err)
}
pfcpMsgString := string(pfcpMsgBytes)
logger.PfcpLog.Debugf("pfcp rsp status ok, %v\n", pfcpMsgString)
logger.PfcpLog.Debugf("pfcp rsp status ok, %+v\n", pfcpMsgString)
pfcpRspMsg := pfcp.Message{}
json.Unmarshal(pfcpMsgBytes, &pfcpRspMsg)
eventData := pfcpUdp.PfcpEventData{LSEID: ctx.PFCPContext[nodeIDtoIP].LocalSEID, ErrHandler: HandlePfcpSendError}
Expand Down Expand Up @@ -487,7 +487,7 @@ func SendPfcpSessionDeletionRequest(upNodeID pfcpType.NodeID, ctx *smf_context.S
logger.PfcpLog.Fatalln(err)
}
pfcpMsgString := string(pfcpMsgBytes)
logger.PfcpLog.Debugf("pfcp rsp status ok, %v\n", pfcpMsgString)
logger.PfcpLog.Debugf("pfcp rsp status ok, %+v\n", pfcpMsgString)
pfcpRspMsg := pfcp.Message{}
json.Unmarshal(pfcpMsgBytes, &pfcpRspMsg)
eventData := pfcpUdp.PfcpEventData{LSEID: ctx.PFCPContext[nodeIDtoIP].LocalSEID, ErrHandler: HandlePfcpSendError}
Expand Down
4 changes: 2 additions & 2 deletions pfcp/message/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
package message_test

import (
"github.com/omec-project/pfcp/pfcpType"
"github.com/omec-project/smf/context"
"net"
"testing"
"time"

"github.com/omec-project/pfcp/pfcpType"
"github.com/omec-project/smf/context"
smf_pfcp "github.com/omec-project/smf/pfcp"
"github.com/omec-project/smf/pfcp/message"
"github.com/omec-project/smf/pfcp/udp"
Expand Down
4 changes: 2 additions & 2 deletions qos/qos_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package qos

import (
"github.com/omec-project/smf/logger"
"log"
"strconv"
"strings"

"github.com/omec-project/nas/nasMessage"
"github.com/omec-project/openapi/models"
"github.com/omec-project/smf/logger"
)

// TS 24.501 Table 9.11.4.12
Expand Down Expand Up @@ -84,7 +84,7 @@ type QosFlowsUpdate struct {
func GetQosFlowIdFromQosId(qosId string) uint8 {
id, err := strconv.Atoi(qosId)
if err != nil {
logger.CtxLog.Errorf("String can not be converted to integer: %v", err)
logger.CtxLog.Errorf("String can not be converted to integer: %+v", err)
return 0
} else {
return uint8(id)
Expand Down

0 comments on commit aa08b20

Please sign in to comment.