RICPLT-3008 Subscription register free id list 34/2234/4
authorAnssi Mannila <anssi.mannila@nokia.com>
Wed, 15 Jan 2020 13:40:57 +0000 (15:40 +0200)
committerAnssi Mannila <anssi.mannila@nokia.com>
Wed, 15 Jan 2020 17:52:36 +0000 (19:52 +0200)
Change-Id: I535333896bcd74e7d46f3ba2e01aff6e799cd68c
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
e2ap/pkg/packer/packer.go
go.sum
pkg/control/control.go
pkg/control/messaging_test.go
pkg/control/registry.go

index 63c0c2f..ab2ac96 100644 (file)
@@ -21,6 +21,7 @@ package packer
 
 import (
        "fmt"
+       "strings"
 )
 
 const cLogBufferMaxSize = 1024
@@ -46,9 +47,7 @@ func PduPackerPack(entry PduPackerIf, trgBuf *PackedData) error {
        if err == nil {
                return nil
        }
-       reterr := fmt.Errorf("Pack failed: err: %s, logbuffer: %s", err.Error(), string(logBuffer[:]))
-       //reterr = fmt.Errorf("%s: PDU:%s", reterr.Error(), string(logBuffer))
-       return reterr
+       return fmt.Errorf("Pack failed: err: %s, logbuffer: %s", err.Error(), logBuffer[:strings.Index(string(logBuffer[:]), "\000")])
 }
 
 func PduPackerPackAllocTrg(entry PduPackerIf, trgBuf *PackedData) (error, *PackedData) {
@@ -79,7 +78,5 @@ func PduPackerUnPack(entry PduUnPackerIf, data *PackedData) error {
        if err == nil {
                return nil
        }
-       reterr := fmt.Errorf("Unpack failed: err: %s, logbuffer: %s", err.Error(), string(logBuffer[:]))
-       //reterr = fmt.Errorf("%s: PDU:%s", reterr.Error(), string(logBuffer))
-       return reterr
+       return fmt.Errorf("Unpack failed: err: %s, logbuffer: %s", err.Error(), logBuffer[:strings.Index(string(logBuffer[:]), "\000")])
 }
diff --git a/go.sum b/go.sum
index 7de3fb3..1edade9 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -118,6 +118,7 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
 github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
index ef27530..cc176c2 100755 (executable)
@@ -28,7 +28,6 @@ import (
        httptransport "github.com/go-openapi/runtime/client"
        "github.com/go-openapi/strfmt"
        "github.com/spf13/viper"
-       "math/rand"
        "sync"
        "time"
 )
@@ -57,8 +56,6 @@ type RMRMeid struct {
        RanName string
 }
 
-var seedSN uint16
-
 const (
        CREATE Action = 0
        MERGE  Action = 1
@@ -71,15 +68,6 @@ func init() {
        viper.AutomaticEnv()
        viper.SetEnvPrefix("submgr")
        viper.AllowEmptyEnv(true)
-       seedSN = uint16(viper.GetInt("seed_sn"))
-       if seedSN == 0 {
-               rand.Seed(time.Now().UnixNano())
-               seedSN = uint16(rand.Intn(65535))
-       }
-       if seedSN > 65535 {
-               seedSN = 0
-       }
-       xapp.Logger.Info("SUBMGR: Initial Sequence Number: %v", seedSN)
 }
 
 func NewControl() *Control {
@@ -91,7 +79,7 @@ func NewControl() *Control {
        rtmgrClient := RtmgrClient{client, handle, deleteHandle}
 
        registry := new(Registry)
-       registry.Initialize(seedSN)
+       registry.Initialize()
        registry.rtmgrClient = &rtmgrClient
 
        tracker := new(Tracker)
index 1b50c8b..ed31423 100644 (file)
@@ -548,24 +548,24 @@ func (mc *testingMainControl) wait_subs_trans_clean(t *testing.T, e2SubsId int,
        return false
 }
 
-func (mc *testingMainControl) get_seqcnt(t *testing.T) uint16 {
+func (mc *testingMainControl) get_subid(t *testing.T) uint16 {
        mc.c.registry.mutex.Lock()
        defer mc.c.registry.mutex.Unlock()
-       return mc.c.registry.counter
+       return mc.c.registry.subIds[0]
 }
 
-func (mc *testingMainControl) wait_seqcnt_change(t *testing.T, orig uint16, secs int) (uint16, bool) {
+func (mc *testingMainControl) wait_subid_change(t *testing.T, origSubId uint16, secs int) (uint16, bool) {
        i := 1
        for ; i <= secs*2; i++ {
                mc.c.registry.mutex.Lock()
-               curr := mc.c.registry.counter
+               currSubId := mc.c.registry.subIds[0]
                mc.c.registry.mutex.Unlock()
-               if curr != orig {
-                       return curr, true
+               if currSubId != origSubId {
+                       return currSubId, true
                }
                time.Sleep(500 * time.Millisecond)
        }
-       testError(t, "(general) no seq change within %d secs", secs)
+       testError(t, "(general) no subId change within %d secs", secs)
        return 0, false
 }
 
@@ -1306,5 +1306,3 @@ func TestSubDelReqSubDelFailRespInSubmgr(t *testing.T) {
        // Wait that subs is cleaned
        mainCtrl.wait_subs_clean(t, e2SubsId, 10)
 }
-
-/* */
index a1fe4b8..c27e6a2 100644 (file)
@@ -31,14 +31,17 @@ import (
 type Registry struct {
        mutex       sync.Mutex
        register    map[uint16]*Subscription
-       counter     uint16
+       subIds      []uint16
        rtmgrClient *RtmgrClient
 }
 
 // This method should run as a constructor
-func (r *Registry) Initialize(seedsn uint16) {
+func (r *Registry) Initialize() {
        r.register = make(map[uint16]*Subscription)
-       r.counter = seedsn
+       var i uint16
+       for i = 0; i < 65535; i++ {
+               r.subIds = append(r.subIds, i+1)
+       }
 }
 
 // Reserves and returns the next free sequence number
@@ -50,12 +53,8 @@ func (r *Registry) ReserveSubscription(endPoint *RmrEndpoint, meid *xapp.RMRMeid
        var subs *Subscription = nil
        var retrytimes uint16 = 1000
        for ; subs == nil && retrytimes > 0; retrytimes-- {
-               sequenceNumber := r.counter
-               if r.counter == 65535 {
-                       r.counter = 0
-               } else {
-                       r.counter++
-               }
+               sequenceNumber := r.subIds[0]
+               r.subIds = r.subIds[1:]
                if _, ok := r.register[sequenceNumber]; ok == false {
                        subs := &Subscription{
                                registry:    r,
@@ -80,7 +79,7 @@ func (r *Registry) ReserveSubscription(endPoint *RmrEndpoint, meid *xapp.RMRMeid
                        return subs, nil
                }
        }
-       return nil, fmt.Errorf("Registry: Failed to reserves subcription. RmrEndpoint: %s, Meid: %s", endPoint, meid.RanName)
+       return nil, fmt.Errorf("Registry: Failed to reserves subscription. RmrEndpoint: %s, Meid: %s", endPoint, meid.RanName)
 }
 
 func (r *Registry) GetSubscription(sn uint16) *Subscription {
@@ -97,6 +96,7 @@ func (r *Registry) DelSubscription(sn uint16) bool {
        r.mutex.Lock()
        defer r.mutex.Unlock()
        if _, ok := r.register[sn]; ok {
+               r.subIds = append(r.subIds, sn)
                delete(r.register, sn)
                return true
        }