2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 type TransactionIf interface {
36 SendEvent(interface{}, time.Duration) (bool, bool)
37 WaitEvent(time.Duration) (interface{}, bool)
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
44 type Transaction struct {
46 Seq uint64 //transaction sequence
47 tracker *Tracker //tracker instance
48 Meid *xapp.RMRMeid //meid transaction related
49 Mtype int //Encoded message type to be send
50 Payload *e2ap.PackedData //Encoded message to be send
51 EventChan chan interface{}
54 func (t *Transaction) String() string {
57 meidstr = t.Meid.String()
59 return "trans(" + strconv.FormatUint(uint64(t.Seq), 10) + "/" + meidstr + ")"
62 func (t *Transaction) SendEvent(event interface{}, waittime time.Duration) (bool, bool) {
65 case t.EventChan <- event:
67 case <-time.After(waittime):
76 func (t *Transaction) WaitEvent(waittime time.Duration) (interface{}, bool) {
79 case event := <-t.EventChan:
81 case <-time.After(waittime):
85 event := <-t.EventChan
89 func (t *Transaction) GetMtype() int {
91 defer t.mutex.Unlock()
95 func (t *Transaction) GetMeid() *xapp.RMRMeid {
97 defer t.mutex.Unlock()
104 /* // This function is not used. Commented out to get better test coverage result
105 func (t *Transaction) GetPayload() *e2ap.PackedData {
107 defer t.mutex.Unlock()
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 type TransactionSubs struct {
118 func (t *TransactionSubs) String() string {
119 return "transsubs(" + t.Transaction.String() + ")"
122 func (t *TransactionSubs) Release() {
124 xapp.Logger.Debug("RELEASE %s", t.String())
129 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
132 type TransactionXappKey struct {
134 Xid string // xapp xid in req
137 func (key *TransactionXappKey) String() string {
138 return "transkey(" + key.RmrEndpoint.String() + "/" + key.Xid + ")"
141 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 type TransactionXapp struct {
146 XappKey *TransactionXappKey
147 RequestId e2ap.RequestId
150 func (t *TransactionXapp) String() string {
151 var transkey string = "transkey(N/A)"
152 if t.XappKey != nil {
153 transkey = t.XappKey.String()
155 return "transxapp(" + t.Transaction.String() + "/" + transkey + "/" + strconv.FormatUint(uint64(t.RequestId.InstanceId), 10) + ")"
158 func (t *TransactionXapp) GetEndpoint() *xapp.RmrEndpoint {
160 defer t.mutex.Unlock()
161 if t.XappKey != nil {
162 return &t.XappKey.RmrEndpoint
167 func (t *TransactionXapp) GetXid() string {
169 defer t.mutex.Unlock()
170 if t.XappKey != nil {
176 /* // This function is not used. Commented out to get better test coverage result
177 func (t *TransactionXapp) GetSrc() string {
179 defer t.mutex.Unlock()
180 if t.XappKey != nil {
181 return t.XappKey.RmrEndpoint.String()
186 func (t *TransactionXapp) GetSubId() uint32 {
188 defer t.mutex.Unlock()
189 return t.RequestId.InstanceId
192 func (t *TransactionXapp) Release() {
194 xapp.Logger.Debug("RELEASE %s", t.String())
200 if tracker != nil && xappkey != nil {
201 tracker.UnTrackTransaction(*xappkey)