From b31b13f2e2603404d57c2f81260a6e2727aaeb97 Mon Sep 17 00:00:00 2001 From: Juha Hyttinen Date: Wed, 18 Mar 2020 10:25:30 +0200 Subject: [PATCH] move rmrendpoint into xapptweaks pkg Change-Id: I5cc422a930040469980ebcf2627be6c6184a78df Signed-off-by: Juha Hyttinen --- pkg/control/client.go | 3 +- pkg/control/control.go | 4 +- pkg/control/registry.go | 3 +- pkg/control/subscription.go | 2 +- pkg/control/tracker.go | 3 +- pkg/control/transaction.go | 4 +- pkg/control/types.go | 118 ----------------- pkg/xapptweaks/rmrendpoint.go | 141 +++++++++++++++++++++ .../rmrendpoint_test.go} | 2 +- pkg/xapptweaks/rmrwrapper.go | 1 + 10 files changed, 154 insertions(+), 127 deletions(-) create mode 100644 pkg/xapptweaks/rmrendpoint.go rename pkg/{control/types_test.go => xapptweaks/rmrendpoint_test.go} (99%) diff --git a/pkg/control/client.go b/pkg/control/client.go index fdafcb6..d26bbd0 100644 --- a/pkg/control/client.go +++ b/pkg/control/client.go @@ -24,6 +24,7 @@ import ( rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client" rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_models" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "strconv" "strings" @@ -34,7 +35,7 @@ import ( // //----------------------------------------------------------------------------- type SubRouteInfo struct { - EpList RmrEndpointList + EpList xapptweaks.RmrEndpointList SubID uint16 } diff --git a/pkg/control/control.go b/pkg/control/control.go index 152d08a..51c84e3 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -218,7 +218,7 @@ func (c *Control) handleXAPPSubscriptionRequest(params *xapptweaks.RMRParams) { return } - trans := c.tracker.NewXappTransaction(NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId.Seq, params.Meid) + trans := c.tracker.NewXappTransaction(xapptweaks.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId.Seq, params.Meid) if trans == nil { xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params)) return @@ -278,7 +278,7 @@ func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapptweaks.RMRPara return } - trans := c.tracker.NewXappTransaction(NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId.Seq, params.Meid) + trans := c.tracker.NewXappTransaction(xapptweaks.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId.Seq, params.Meid) if trans == nil { xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params)) return diff --git a/pkg/control/registry.go b/pkg/control/registry.go index b816b61..2570960 100644 --- a/pkg/control/registry.go +++ b/pkg/control/registry.go @@ -22,6 +22,7 @@ package control import ( "fmt" "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "sync" @@ -244,7 +245,7 @@ func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *Transaction // // Subscription route delete // - tmpList := RmrEndpointList{} + tmpList := xapptweaks.RmrEndpointList{} tmpList.AddEndpoint(trans.GetEndpoint()) subRouteAction := SubRouteInfo{tmpList, uint16(seqId)} r.rtmgrClient.SubscriptionRequestDelete(subRouteAction) diff --git a/pkg/control/subscription.go b/pkg/control/subscription.go index c3e1c20..ac68aa6 100644 --- a/pkg/control/subscription.go +++ b/pkg/control/subscription.go @@ -35,7 +35,7 @@ type Subscription struct { registry *Registry // Registry ReqId RequestId // ReqId (Requestor Id + Seq Nro a.k.a subsid) Meid *xapp.RMRMeid // Meid/ RanName - EpList RmrEndpointList // Endpoints + EpList xapptweaks.RmrEndpointList // Endpoints TransLock sync.Mutex // Lock transactions, only one executed per time for subs TheTrans TransactionIf // Ongoing transaction SubReqMsg *e2ap.E2APSubscriptionRequest // Subscription information diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index cf00af3..0879a4f 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -21,6 +21,7 @@ package control import ( "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" "sync" ) @@ -56,7 +57,7 @@ func (t *Tracker) NewSubsTransaction(subs *Subscription) *TransactionSubs { } func (t *Tracker) NewXappTransaction( - endpoint *RmrEndpoint, + endpoint *xapptweaks.RmrEndpoint, xid string, subid uint32, meid *xapp.RMRMeid) *TransactionXapp { diff --git a/pkg/control/transaction.go b/pkg/control/transaction.go index 1298925..d922d18 100644 --- a/pkg/control/transaction.go +++ b/pkg/control/transaction.go @@ -126,7 +126,7 @@ func (t *TransactionSubs) Release() { // //----------------------------------------------------------------------------- type TransactionXappKey struct { - RmrEndpoint + xapptweaks.RmrEndpoint Xid string // xapp xid in req } @@ -151,7 +151,7 @@ func (t *TransactionXapp) String() string { return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.SubId), 10) + ")" } -func (t *TransactionXapp) GetEndpoint() *RmrEndpoint { +func (t *TransactionXapp) GetEndpoint() *xapptweaks.RmrEndpoint { t.mutex.Lock() defer t.mutex.Unlock() if t.XappKey != nil { diff --git a/pkg/control/types.go b/pkg/control/types.go index 5408f48..08bcda4 100644 --- a/pkg/control/types.go +++ b/pkg/control/types.go @@ -21,8 +21,6 @@ package control import ( "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" - "strconv" - "strings" ) //----------------------------------------------------------------------------- @@ -35,119 +33,3 @@ type RequestId struct { func (rid *RequestId) String() string { return "reqid(" + rid.RequestId.String() + ")" } - -//----------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------- -type RmrEndpoint struct { - Addr string // xapp addr - Port uint16 // xapp port -} - -func (endpoint RmrEndpoint) String() string { - return endpoint.Addr + ":" + strconv.FormatUint(uint64(endpoint.Port), 10) -} - -func (endpoint *RmrEndpoint) Equal(ep *RmrEndpoint) bool { - if (endpoint.Addr == ep.Addr) && - (endpoint.Port == ep.Port) { - return true - } - return false -} - -func (endpoint *RmrEndpoint) GetAddr() string { - return endpoint.Addr -} - -func (endpoint *RmrEndpoint) GetPort() uint16 { - return endpoint.Port -} - -func (endpoint *RmrEndpoint) Set(src string) bool { - elems := strings.Split(src, ":") - if len(elems) == 2 { - srcAddr := elems[0] - srcPort, err := strconv.ParseUint(elems[1], 10, 16) - if err == nil { - endpoint.Addr = srcAddr - endpoint.Port = uint16(srcPort) - return true - } - } - return false -} - -//----------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------- -type RmrEndpointList struct { - Endpoints []RmrEndpoint -} - -func (eplist *RmrEndpointList) String() string { - valuesText := eplist.StringList() - return strings.Join(valuesText, ",") -} - -func (eplist *RmrEndpointList) StringList() []string { - tmpList := eplist.Endpoints - valuesText := []string{} - for i := range tmpList { - valuesText = append(valuesText, tmpList[i].String()) - } - return valuesText -} - -func (eplist *RmrEndpointList) Size() int { - return len(eplist.Endpoints) -} - -func (eplist *RmrEndpointList) AddEndpoint(ep *RmrEndpoint) bool { - for i := range eplist.Endpoints { - if eplist.Endpoints[i].Equal(ep) { - return false - } - } - eplist.Endpoints = append(eplist.Endpoints, *ep) - return true -} - -func (eplist *RmrEndpointList) DelEndpoint(ep *RmrEndpoint) bool { - for i := range eplist.Endpoints { - if eplist.Endpoints[i].Equal(ep) { - eplist.Endpoints[i] = eplist.Endpoints[len(eplist.Endpoints)-1] - eplist.Endpoints[len(eplist.Endpoints)-1] = RmrEndpoint{"", 0} - eplist.Endpoints = eplist.Endpoints[:len(eplist.Endpoints)-1] - return true - } - } - return false -} - -func (eplist *RmrEndpointList) DelEndpoints(otheplist *RmrEndpointList) bool { - var retval bool = false - for i := range otheplist.Endpoints { - if eplist.DelEndpoint(&otheplist.Endpoints[i]) { - retval = true - } - } - return retval -} - -func (eplist *RmrEndpointList) HasEndpoint(ep *RmrEndpoint) bool { - for i := range eplist.Endpoints { - if eplist.Endpoints[i].Equal(ep) { - return true - } - } - return false -} - -func NewRmrEndpoint(src string) *RmrEndpoint { - ep := &RmrEndpoint{} - if ep.Set(src) == false { - return nil - } - return ep -} diff --git a/pkg/xapptweaks/rmrendpoint.go b/pkg/xapptweaks/rmrendpoint.go new file mode 100644 index 0000000..4b5ae48 --- /dev/null +++ b/pkg/xapptweaks/rmrendpoint.go @@ -0,0 +1,141 @@ +/* +================================================================================== + Copyright (c) 2019 AT&T Intellectual Property. + Copyright (c) 2019 Nokia + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ + +package xapptweaks + +import ( + "strconv" + "strings" +) + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type RmrEndpoint struct { + Addr string // xapp addr + Port uint16 // xapp port +} + +func (endpoint RmrEndpoint) String() string { + return endpoint.Addr + ":" + strconv.FormatUint(uint64(endpoint.Port), 10) +} + +func (endpoint *RmrEndpoint) Equal(ep *RmrEndpoint) bool { + if (endpoint.Addr == ep.Addr) && + (endpoint.Port == ep.Port) { + return true + } + return false +} + +func (endpoint *RmrEndpoint) GetAddr() string { + return endpoint.Addr +} + +func (endpoint *RmrEndpoint) GetPort() uint16 { + return endpoint.Port +} + +func (endpoint *RmrEndpoint) Set(src string) bool { + elems := strings.Split(src, ":") + if len(elems) == 2 { + srcAddr := elems[0] + srcPort, err := strconv.ParseUint(elems[1], 10, 16) + if err == nil { + endpoint.Addr = srcAddr + endpoint.Port = uint16(srcPort) + return true + } + } + return false +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type RmrEndpointList struct { + Endpoints []RmrEndpoint +} + +func (eplist *RmrEndpointList) String() string { + valuesText := eplist.StringList() + return strings.Join(valuesText, ",") +} + +func (eplist *RmrEndpointList) StringList() []string { + tmpList := eplist.Endpoints + valuesText := []string{} + for i := range tmpList { + valuesText = append(valuesText, tmpList[i].String()) + } + return valuesText +} + +func (eplist *RmrEndpointList) Size() int { + return len(eplist.Endpoints) +} + +func (eplist *RmrEndpointList) AddEndpoint(ep *RmrEndpoint) bool { + for i := range eplist.Endpoints { + if eplist.Endpoints[i].Equal(ep) { + return false + } + } + eplist.Endpoints = append(eplist.Endpoints, *ep) + return true +} + +func (eplist *RmrEndpointList) DelEndpoint(ep *RmrEndpoint) bool { + for i := range eplist.Endpoints { + if eplist.Endpoints[i].Equal(ep) { + eplist.Endpoints[i] = eplist.Endpoints[len(eplist.Endpoints)-1] + eplist.Endpoints[len(eplist.Endpoints)-1] = RmrEndpoint{"", 0} + eplist.Endpoints = eplist.Endpoints[:len(eplist.Endpoints)-1] + return true + } + } + return false +} + +func (eplist *RmrEndpointList) DelEndpoints(otheplist *RmrEndpointList) bool { + var retval bool = false + for i := range otheplist.Endpoints { + if eplist.DelEndpoint(&otheplist.Endpoints[i]) { + retval = true + } + } + return retval +} + +func (eplist *RmrEndpointList) HasEndpoint(ep *RmrEndpoint) bool { + for i := range eplist.Endpoints { + if eplist.Endpoints[i].Equal(ep) { + return true + } + } + return false +} + +func NewRmrEndpoint(src string) *RmrEndpoint { + ep := &RmrEndpoint{} + if ep.Set(src) == false { + return nil + } + return ep +} diff --git a/pkg/control/types_test.go b/pkg/xapptweaks/rmrendpoint_test.go similarity index 99% rename from pkg/control/types_test.go rename to pkg/xapptweaks/rmrendpoint_test.go index 424021b..e56cea4 100644 --- a/pkg/control/types_test.go +++ b/pkg/xapptweaks/rmrendpoint_test.go @@ -17,7 +17,7 @@ ================================================================================== */ -package control +package xapptweaks import ( "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" diff --git a/pkg/xapptweaks/rmrwrapper.go b/pkg/xapptweaks/rmrwrapper.go index ac602bf..5d59363 100644 --- a/pkg/xapptweaks/rmrwrapper.go +++ b/pkg/xapptweaks/rmrwrapper.go @@ -67,6 +67,7 @@ func (tc *RmrWrapper) RmrSend(params *RMRParams, to time.Duration) (err error) { if status == false { err = fmt.Errorf("Failed with retries(%d) %s", i, params.String()) tc.Rmr.Free(params.Mbuf) + params.Mbuf = nil } else { tc.CntSentMsg++ } -- 2.16.6