import (
"fmt"
+ "strings"
)
const cLogBufferMaxSize = 1024
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) {
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")])
}
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=
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/spf13/viper"
- "math/rand"
"sync"
"time"
)
RanName string
}
-var seedSN uint16
-
const (
CREATE Action = 0
MERGE Action = 1
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 {
rtmgrClient := RtmgrClient{client, handle, deleteHandle}
registry := new(Registry)
- registry.Initialize(seedSN)
+ registry.Initialize()
registry.rtmgrClient = &rtmgrClient
tracker := new(Tracker)
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
}
// Wait that subs is cleaned
mainCtrl.wait_subs_clean(t, e2SubsId, 10)
}
-
-/* */
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
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,
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 {
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
}