From dc4960762be081e9e50104f08b64e27a8e45b18e Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Thu, 2 Nov 2023 16:53:00 +0900 Subject: [PATCH 1/8] Fix that some type of the range relationship was not considered in LazyReusePool.Reserve. --- internal/context/pool/lazyReusePool.go | 12 ++-- internal/context/pool/lazyReusePool_test.go | 72 +++++++++++++++++++++ 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/internal/context/pool/lazyReusePool.go b/internal/context/pool/lazyReusePool.go index 051faa10..9acf3026 100644 --- a/internal/context/pool/lazyReusePool.go +++ b/internal/context/pool/lazyReusePool.go @@ -168,12 +168,12 @@ func (p *LazyReusePool) Reserve(first, last int) error { for cur, prev := p.head, (*segment)(nil); cur != nil; cur = cur.next { switch { - case cur.first == first && cur.last > last: + case cur.first >= first && cur.first <= last && cur.last > last: + p.remain -= last - cur.first + 1 cur.first = last + 1 - p.remain -= last - first + 1 - case cur.first < first && cur.last == last: + case cur.first < first && cur.last >= first && cur.last <= last: + p.remain -= cur.last - first + 1 cur.last = first - 1 - p.remain -= last - first + 1 case cur.first < first && cur.last > last: cur.next = &segment{ first: last + 1, @@ -184,10 +184,12 @@ func (p *LazyReusePool) Reserve(first, last int) error { p.remain -= last - first + 1 // this segment in reserve range - case cur.first > first && cur.last < last: + case cur.first >= first && cur.last <= last: p.remain -= cur.last - cur.first + 1 if prev != nil { prev.next = cur.next + } else { + p.head = cur.next } } diff --git a/internal/context/pool/lazyReusePool_test.go b/internal/context/pool/lazyReusePool_test.go index 933b3359..06218b4d 100644 --- a/internal/context/pool/lazyReusePool_test.go +++ b/internal/context/pool/lazyReusePool_test.go @@ -262,6 +262,78 @@ func TestLazyReusePool_ReserveSection(t *testing.T) { require.Equal(t, expected, allocated) } +func TestLazyReusePool_ReserveSection2(t *testing.T) { + p, err := NewLazyReusePool(10, 100) + require.NoError(t, err) + assert.Equal(t, (100 - 10 + 1), p.Remain()) + require.Equal(t, &segment{first: 10, last: 100}, p.head) + + err = p.Reserve(0, 5) + assert.Error(t, err) + + err = p.Reserve(10, 20) + require.NoError(t, err) + assert.Equal(t, (100 - 21 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 100}, p.head) + + err = p.Reserve(90, 100) + require.NoError(t, err) + assert.Equal(t, (89 - 21 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 89}, p.head) + + err = p.Reserve(40, 50) + require.NoError(t, err) + assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + + err = p.Reserve(10, 20) + require.NoError(t, err) + assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + + err = p.Reserve(40, 50) + require.NoError(t, err) + assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + + err = p.Reserve(90, 100) + require.NoError(t, err) + assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + + err = p.Reserve(36, 55) + require.NoError(t, err) + assert.Equal(t, (35 - 21 + 1 + 89 - 56 + 1), p.Remain()) + assert.Equal(t, &segment{first: 21, last: 35, next: &segment{first: 56, last: 89}}, p.head) + + err = p.Reserve(21, 35) + require.NoError(t, err) + assert.Equal(t, (89 - 56 + 1), p.Remain()) + assert.Equal(t, &segment{first: 56, last: 89}, p.head) + + err = p.Reserve(60, 65) + require.NoError(t, err) + err = p.Reserve(70, 75) + require.NoError(t, err) + assert.Equal(t, (59 - 56 + 1 + 69 - 66 + 1 + 89 - 76 + 1), p.Remain()) + assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 66, last: 69, next: &segment{first: 76, last: 89}}}, p.head) + + err = p.Reserve(60, 75) + require.NoError(t, err) + assert.Equal(t, (59 - 56 + 1 + 89 - 76 + 1), p.Remain()) + assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 76, last: 89}}, p.head) + + err = p.Reserve(70, 90) + require.NoError(t, err) + assert.Equal(t, (59 - 56 + 1), p.Remain()) + assert.Equal(t, &segment{first: 56, last: 59}, p.head) + + err = p.Reserve(50, 60) + require.NoError(t, err) + assert.Equal(t, 0, p.Remain()) + assert.Nil(t, p.head) +} + func TestLazyReusePool_ManyGoroutine(t *testing.T) { p, err := NewLazyReusePool(101, 1000) assert.NoError(t, err) From 5d151678c5d98c13bcc68e7d00e183da79d29f91 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Thu, 2 Nov 2023 17:04:32 +0900 Subject: [PATCH 2/8] Fix the behavior when the address range near the boundary is specified in staticPools. --- internal/context/ue_ip_pool.go | 14 ++++---------- internal/context/ue_ip_pool_test.go | 22 +++++++++++----------- internal/context/user_plane_information.go | 11 +++++++++++ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/internal/context/ue_ip_pool.go b/internal/context/ue_ip_pool.go index 07ab23aa..742cd9f9 100644 --- a/internal/context/ue_ip_pool.go +++ b/internal/context/ue_ip_pool.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "errors" "fmt" - "math" "net" "github.com/free5gc/smf/internal/context/pool" @@ -72,10 +71,7 @@ RETURNIP: func (ueIPPool *UeIPPool) exclude(excludePool *UeIPPool) error { excludeMin := excludePool.pool.Min() - excludeMax := excludePool.pool.Max() + 1 - if !ueIPPool.ueSubNet.IP.Equal(excludePool.ueSubNet.IP) { - excludeMin -= 1 - } + excludeMax := excludePool.pool.Max() if err := ueIPPool.pool.Reserve(excludeMin, excludeMax); err != nil { return fmt.Errorf("exclude uePool fail: %v", err) } @@ -136,11 +132,9 @@ func isOverlap(pools []*UeIPPool) bool { func calcAddrRange(ipNet *net.IPNet) (minAddr, maxAddr uint32, err error) { maskVal := binary.BigEndian.Uint32(ipNet.Mask) baseIPVal := binary.BigEndian.Uint32(ipNet.IP) - if maskVal == math.MaxUint32 { - return baseIPVal, baseIPVal, nil - } - minAddr = (baseIPVal & maskVal) + 1 // 0 is network address - maxAddr = (baseIPVal | ^maskVal) - 1 // all 1 is broadcast address + // move removing network and broadcast address later + minAddr = (baseIPVal & maskVal) + maxAddr = (baseIPVal | ^maskVal) if minAddr > maxAddr { return minAddr, maxAddr, errors.New("Mask is invalid.") } diff --git a/internal/context/ue_ip_pool_test.go b/internal/context/ue_ip_pool_test.go index 21fb6fce..b9a00557 100644 --- a/internal/context/ue_ip_pool_test.go +++ b/internal/context/ue_ip_pool_test.go @@ -22,13 +22,13 @@ func TestUeIPPool(t *testing.T) { // make allowed ip pools var ipPoolList []net.IP - for i := 1; i < 255; i += 1 { + for i := 0; i <= 255; i += 1 { ipStr := fmt.Sprintf("10.10.0.%d", i) ipPoolList = append(ipPoolList, net.ParseIP(ipStr).To4()) } // allocate - for i := 1; i < 255; i += 1 { + for i := 0; i < 256; i += 1 { allocIP = ueIPPool.allocate(nil) require.Contains(t, ipPoolList, allocIP) } @@ -38,7 +38,7 @@ func TestUeIPPool(t *testing.T) { require.Nil(t, allocIP) // release IP - for _, i := range rand.Perm(254) { + for _, i := range rand.Perm(256) { ueIPPool.release(ipPoolList[i]) } @@ -54,24 +54,24 @@ func TestUeIPPool_ExcludeRange(t *testing.T) { Cidr: "10.10.0.0/24", }) - require.Equal(t, 0x0a0a0001, ueIPPool.pool.Min()) - require.Equal(t, 0x0a0a00FE, ueIPPool.pool.Max()) - require.Equal(t, 254, ueIPPool.pool.Remain()) + require.Equal(t, 0x0a0a0000, ueIPPool.pool.Min()) + require.Equal(t, 0x0a0a00FF, ueIPPool.pool.Max()) + require.Equal(t, 256, ueIPPool.pool.Remain()) excludeUeIPPool := NewUEIPPool(&factory.UEIPPool{ Cidr: "10.10.0.0/28", }) - require.Equal(t, 0x0a0a0001, excludeUeIPPool.pool.Min()) - require.Equal(t, 0x0a0a000E, excludeUeIPPool.pool.Max()) + require.Equal(t, 0x0a0a0000, excludeUeIPPool.pool.Min()) + require.Equal(t, 0x0a0a000F, excludeUeIPPool.pool.Max()) - require.Equal(t, 14, excludeUeIPPool.pool.Remain()) + require.Equal(t, 16, excludeUeIPPool.pool.Remain()) err := ueIPPool.exclude(excludeUeIPPool) require.NoError(t, err) - require.Equal(t, 239, ueIPPool.pool.Remain()) + require.Equal(t, 240, ueIPPool.pool.Remain()) - for i := 16; i <= 254; i++ { + for i := 16; i <= 255; i++ { allocate := ueIPPool.allocate(nil) require.Equal(t, net.ParseIP(fmt.Sprintf("10.10.0.%d", i)).To4(), allocate) diff --git a/internal/context/user_plane_information.go b/internal/context/user_plane_information.go index 2ccabe19..0090a446 100644 --- a/internal/context/user_plane_information.go +++ b/internal/context/user_plane_information.go @@ -164,6 +164,17 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan } } } + for _, pool := range ueIPPools { + if err := pool.pool.Reserve(pool.pool.Min(), pool.pool.Min()); err != nil { + logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) + } + if err := pool.pool.Reserve(pool.pool.Max(), pool.pool.Max()); err != nil { + logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) + } + logger.InitLog.Debugf("%d-%s %s %s", + snssaiInfo.SNssai.Sst, snssaiInfo.SNssai.Sd, + dnnInfoConfig.Dnn, pool.dump()) + } snssaiInfo.DnnList = append(snssaiInfo.DnnList, &DnnUPFInfoItem{ Dnn: dnnInfoConfig.Dnn, DnaiList: dnnInfoConfig.DnaiList, From 342bff83da2a710ac991f61b074b50c669ed6e12 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Mon, 6 Nov 2023 10:42:29 +0900 Subject: [PATCH 3/8] Fix case that netmask of pool is /32 --- internal/context/user_plane_information.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/context/user_plane_information.go b/internal/context/user_plane_information.go index 0090a446..fde298ca 100644 --- a/internal/context/user_plane_information.go +++ b/internal/context/user_plane_information.go @@ -165,11 +165,13 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan } } for _, pool := range ueIPPools { - if err := pool.pool.Reserve(pool.pool.Min(), pool.pool.Min()); err != nil { - logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) - } - if err := pool.pool.Reserve(pool.pool.Max(), pool.pool.Max()); err != nil { - logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) + if pool.pool.Min() != pool.pool.Max() { + if err := pool.pool.Reserve(pool.pool.Min(), pool.pool.Min()); err != nil { + logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) + } + if err := pool.pool.Reserve(pool.pool.Max(), pool.pool.Max()); err != nil { + logger.InitLog.Errorf("Remove network address failed for %s: %s", pool.ueSubNet.String(), err) + } } logger.InitLog.Debugf("%d-%s %s %s", snssaiInfo.SNssai.Sst, snssaiInfo.SNssai.Sd, From 539bb7a37b358b2db11a4b83146b3a284cfb04a5 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Mon, 6 Nov 2023 11:10:11 +0900 Subject: [PATCH 4/8] Add test code for lazyReusePool --- internal/context/pool/lazyReusePool_test.go | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/internal/context/pool/lazyReusePool_test.go b/internal/context/pool/lazyReusePool_test.go index 06218b4d..f16f5500 100644 --- a/internal/context/pool/lazyReusePool_test.go +++ b/internal/context/pool/lazyReusePool_test.go @@ -91,6 +91,34 @@ func TestLazyReusePool_SingleSegment(t *testing.T) { assert.True(t, ok) assert.Equal(t, 0, p.Remain()) assert.Equal(t, 2, p.Total()) + + // try use from empty pool + ok = p.Use(1) + assert.False(t, ok) + assert.Equal(t, 0, p.Remain()) + assert.Equal(t, 2, p.Total()) + + ok = p.Free(1) + assert.True(t, ok) + assert.Equal(t, 1, p.Remain()) + assert.Equal(t, 2, p.Total()) + + // try use from assigned value + ok = p.Use(2) + assert.False(t, ok) + assert.Equal(t, 1, p.Remain()) + assert.Equal(t, 2, p.Total()) + + ok = p.Free(2) + assert.True(t, ok) + assert.Equal(t, 2, p.Remain()) + assert.Equal(t, 2, p.Total()) + + // split from s.last + ok = p.Use(2) + assert.True(t, ok) + assert.Equal(t, 1, p.Remain()) + assert.Equal(t, 2, p.Total()) } func TestLazyReusePool_ManySegment(t *testing.T) { @@ -268,24 +296,29 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { assert.Equal(t, (100 - 10 + 1), p.Remain()) require.Equal(t, &segment{first: 10, last: 100}, p.head) + // try reserve outside range err = p.Reserve(0, 5) assert.Error(t, err) + // reserve entries on head err = p.Reserve(10, 20) require.NoError(t, err) assert.Equal(t, (100 - 21 + 1), p.Remain()) assert.Equal(t, &segment{first: 21, last: 100}, p.head) + // reserve entries on tail err = p.Reserve(90, 100) require.NoError(t, err) assert.Equal(t, (89 - 21 + 1), p.Remain()) assert.Equal(t, &segment{first: 21, last: 89}, p.head) + // reserve entries on center err = p.Reserve(40, 50) require.NoError(t, err) assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + // try reserve range was already reserved err = p.Reserve(10, 20) require.NoError(t, err) assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) @@ -301,16 +334,19 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { assert.Equal(t, (39 - 21 + 1 + 89 - 51 + 1), p.Remain()) assert.Equal(t, &segment{first: 21, last: 39, next: &segment{first: 51, last: 89}}, p.head) + // reserve range includes reserved and non-reserved addresses err = p.Reserve(36, 55) require.NoError(t, err) assert.Equal(t, (35 - 21 + 1 + 89 - 56 + 1), p.Remain()) assert.Equal(t, &segment{first: 21, last: 35, next: &segment{first: 56, last: 89}}, p.head) + // remove entire segment err = p.Reserve(21, 35) require.NoError(t, err) assert.Equal(t, (89 - 56 + 1), p.Remain()) assert.Equal(t, &segment{first: 56, last: 89}, p.head) + // generate 3 segments err = p.Reserve(60, 65) require.NoError(t, err) err = p.Reserve(70, 75) @@ -318,16 +354,19 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { assert.Equal(t, (59 - 56 + 1 + 69 - 66 + 1 + 89 - 76 + 1), p.Remain()) assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 66, last: 69, next: &segment{first: 76, last: 89}}}, p.head) + // remove center segment err = p.Reserve(60, 75) require.NoError(t, err) assert.Equal(t, (59 - 56 + 1 + 89 - 76 + 1), p.Remain()) assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 76, last: 89}}, p.head) + // remove tail segment err = p.Reserve(70, 90) require.NoError(t, err) assert.Equal(t, (59 - 56 + 1), p.Remain()) assert.Equal(t, &segment{first: 56, last: 59}, p.head) + // remove last segment err = p.Reserve(50, 60) require.NoError(t, err) assert.Equal(t, 0, p.Remain()) From a276a7524f6320cf240b2a334ade6097449f13aa Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Mon, 6 Nov 2023 13:00:43 +0900 Subject: [PATCH 5/8] Fix segment split code in LazyReusePool.Reserve() --- internal/context/pool/lazyReusePool.go | 1 + internal/context/pool/lazyReusePool_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/context/pool/lazyReusePool.go b/internal/context/pool/lazyReusePool.go index 9acf3026..f57dc5dd 100644 --- a/internal/context/pool/lazyReusePool.go +++ b/internal/context/pool/lazyReusePool.go @@ -178,6 +178,7 @@ func (p *LazyReusePool) Reserve(first, last int) error { cur.next = &segment{ first: last + 1, last: cur.last, + next: cur.next, } cur.last = first - 1 diff --git a/internal/context/pool/lazyReusePool_test.go b/internal/context/pool/lazyReusePool_test.go index f16f5500..2f19ed55 100644 --- a/internal/context/pool/lazyReusePool_test.go +++ b/internal/context/pool/lazyReusePool_test.go @@ -347,10 +347,13 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { assert.Equal(t, &segment{first: 56, last: 89}, p.head) // generate 3 segments - err = p.Reserve(60, 65) - require.NoError(t, err) err = p.Reserve(70, 75) require.NoError(t, err) + assert.Equal(t, (69 - 56 + 1 + 89 - 76 + 1), p.Remain()) + assert.Equal(t, &segment{first: 56, last: 69, next: &segment{first: 76, last: 89}}, p.head) + + err = p.Reserve(60, 65) + require.NoError(t, err) assert.Equal(t, (59 - 56 + 1 + 69 - 66 + 1 + 89 - 76 + 1), p.Remain()) assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 66, last: 69, next: &segment{first: 76, last: 89}}}, p.head) From f6ecdd5593b53ea3a0a4b9519c718a20332a23e4 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Mon, 6 Nov 2023 13:12:42 +0900 Subject: [PATCH 6/8] Fix segment remove code in LazyReusePool.Reserve() --- internal/context/pool/lazyReusePool.go | 2 ++ internal/context/pool/lazyReusePool_test.go | 23 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/context/pool/lazyReusePool.go b/internal/context/pool/lazyReusePool.go index f57dc5dd..df96ae01 100644 --- a/internal/context/pool/lazyReusePool.go +++ b/internal/context/pool/lazyReusePool.go @@ -192,6 +192,8 @@ func (p *LazyReusePool) Reserve(first, last int) error { } else { p.head = cur.next } + // do not update prev + continue } prev = cur diff --git a/internal/context/pool/lazyReusePool_test.go b/internal/context/pool/lazyReusePool_test.go index 2f19ed55..d1ac6b83 100644 --- a/internal/context/pool/lazyReusePool_test.go +++ b/internal/context/pool/lazyReusePool_test.go @@ -376,6 +376,29 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { assert.Nil(t, p.head) } +func TestLazyReusePool_ReserveSection3(t *testing.T) { + p, err := NewLazyReusePool(10, 99) + require.NoError(t, err) + assert.Equal(t, (99 - 10 + 1), p.Remain()) + require.Equal(t, &segment{first: 10, last: 99}, p.head) + + // generate 4 segments + err = p.Reserve(20, 29) + require.NoError(t, err) + err = p.Reserve(40, 49) + require.NoError(t, err) + err = p.Reserve(60, 69) + require.NoError(t, err) + require.Equal(t, (19 - 10 + 1 + 39 - 30 + 1 + 59 - 50 + 1 + 99 - 70 + 1), p.Remain()) + require.Equal(t, &segment{first: 10, last: 19, next: &segment{first: 30, last: 39, next: &segment{first: 50, last: 59, next: &segment{first: 70, last: 99}}}}, p.head) + + // remove two segments + err = p.Reserve(30, 59) + require.NoError(t, err) + require.Equal(t, (19 - 10 + 1 + 99 - 70 + 1), p.Remain()) + require.Equal(t, &segment{first: 10, last: 19, next: &segment{first: 70, last: 99}}, p.head) +} + func TestLazyReusePool_ManyGoroutine(t *testing.T) { p, err := NewLazyReusePool(101, 1000) assert.NoError(t, err) From c4dd62d1095a1fdabf1d1574bb5ee13cd34cb216 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 10 Nov 2023 14:54:23 +0900 Subject: [PATCH 7/8] Fix golangci-lint error --- internal/context/pool/lazyReusePool_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/context/pool/lazyReusePool_test.go b/internal/context/pool/lazyReusePool_test.go index d1ac6b83..85f02a24 100644 --- a/internal/context/pool/lazyReusePool_test.go +++ b/internal/context/pool/lazyReusePool_test.go @@ -355,7 +355,10 @@ func TestLazyReusePool_ReserveSection2(t *testing.T) { err = p.Reserve(60, 65) require.NoError(t, err) assert.Equal(t, (59 - 56 + 1 + 69 - 66 + 1 + 89 - 76 + 1), p.Remain()) - assert.Equal(t, &segment{first: 56, last: 59, next: &segment{first: 66, last: 69, next: &segment{first: 76, last: 89}}}, p.head) + assert.Equal(t, &segment{first: 56, last: 59, next: &segment{ + first: 66, last: 69, + next: &segment{first: 76, last: 89}, + }}, p.head) // remove center segment err = p.Reserve(60, 75) @@ -390,7 +393,10 @@ func TestLazyReusePool_ReserveSection3(t *testing.T) { err = p.Reserve(60, 69) require.NoError(t, err) require.Equal(t, (19 - 10 + 1 + 39 - 30 + 1 + 59 - 50 + 1 + 99 - 70 + 1), p.Remain()) - require.Equal(t, &segment{first: 10, last: 19, next: &segment{first: 30, last: 39, next: &segment{first: 50, last: 59, next: &segment{first: 70, last: 99}}}}, p.head) + require.Equal(t, &segment{first: 10, last: 19, next: &segment{ + first: 30, last: 39, + next: &segment{first: 50, last: 59, next: &segment{first: 70, last: 99}}, + }}, p.head) // remove two segments err = p.Reserve(30, 59) From 91bd2df162434815a799a3148355945c7c7719e7 Mon Sep 17 00:00:00 2001 From: brianchennn Date: Fri, 17 Nov 2023 08:51:15 +0000 Subject: [PATCH 8/8] style: rename variable: ueIPPool -> staticUeIPPool --- internal/context/user_plane_information.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/context/user_plane_information.go b/internal/context/user_plane_information.go index fde298ca..0a2e7772 100644 --- a/internal/context/user_plane_information.go +++ b/internal/context/user_plane_information.go @@ -148,17 +148,17 @@ func NewUserPlaneInformation(upTopology *factory.UserPlaneInformation) *UserPlan allUEIPPools = append(allUEIPPools, ueIPPool) } } - for _, pool := range dnnInfoConfig.StaticPools { - ueIPPool := NewUEIPPool(pool) - if ueIPPool == nil { - logger.InitLog.Fatalf("invalid pools value: %+v", pool) + for _, staticPool := range dnnInfoConfig.StaticPools { + staticUeIPPool := NewUEIPPool(staticPool) + if staticUeIPPool == nil { + logger.InitLog.Fatalf("invalid pools value: %+v", staticPool) } else { - staticUeIPPools = append(staticUeIPPools, ueIPPool) + staticUeIPPools = append(staticUeIPPools, staticUeIPPool) for _, dynamicUePool := range ueIPPools { - if dynamicUePool.ueSubNet.Contains(ueIPPool.ueSubNet.IP) { - if err := dynamicUePool.exclude(ueIPPool); err != nil { + if dynamicUePool.ueSubNet.Contains(staticUeIPPool.ueSubNet.IP) { + if err := dynamicUePool.exclude(staticUeIPPool); err != nil { logger.InitLog.Fatalf("exclude static Pool[%s] failed: %v", - ueIPPool.ueSubNet, err) + staticUeIPPool.ueSubNet, err) } } }