move rmrendpoint into xapptweaks pkg 41/2841/1
authorJuha Hyttinen <juha.hyttinen@nokia.com>
Wed, 18 Mar 2020 08:25:30 +0000 (10:25 +0200)
committerJuha Hyttinen <juha.hyttinen@nokia.com>
Wed, 18 Mar 2020 08:25:43 +0000 (10:25 +0200)
Change-Id: I5cc422a930040469980ebcf2627be6c6184a78df
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
pkg/control/client.go
pkg/control/control.go
pkg/control/registry.go
pkg/control/subscription.go
pkg/control/tracker.go
pkg/control/transaction.go
pkg/control/types.go
pkg/xapptweaks/rmrendpoint.go [new file with mode: 0644]
pkg/xapptweaks/rmrendpoint_test.go [moved from pkg/control/types_test.go with 99% similarity]
pkg/xapptweaks/rmrwrapper.go

index fdafcb6..d26bbd0 100644 (file)
@@ -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
 }
 
index 152d08a..51c84e3 100755 (executable)
@@ -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
index b816b61..2570960 100644 (file)
@@ -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)
index c3e1c20..ac68aa6 100644 (file)
@@ -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
index cf00af3..0879a4f 100644 (file)
@@ -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 {
index 1298925..d922d18 100644 (file)
@@ -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 {
index 5408f48..08bcda4 100644 (file)
@@ -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 (file)
index 0000000..4b5ae48
--- /dev/null
@@ -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
+}
similarity index 99%
rename from pkg/control/types_test.go
rename to pkg/xapptweaks/rmrendpoint_test.go
index 424021b..e56cea4 100644 (file)
@@ -17,7 +17,7 @@
 ==================================================================================
 */
 
-package control
+package xapptweaks
 
 import (
        "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
index ac602bf..5d59363 100644 (file)
@@ -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++
        }