X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftracker.go;h=75127a7a7190d2825a0c44f49dec0697527b5a40;hb=56e0383cad5307302f547a95755c3bcdd9e3251d;hp=584b331c1313abf629c5c8a35e5db07a09b72133;hpb=8046c70a77be2de39ffda0092b1d86008145d81a;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/tracker.go b/pkg/control/tracker.go index 584b331..75127a7 100644 --- a/pkg/control/tracker.go +++ b/pkg/control/tracker.go @@ -25,135 +25,62 @@ import ( "sync" ) -type TransactionKey struct { - SubID uint16 // subscription id / sequence number - TransType Action // action ongoing (CREATE/DELETE etc) -} - -type TransactionXappKey struct { - Addr string // xapp addr - Port uint16 // xapp port - Xid string // xapp xid in req -} - -type Transaction struct { - tracker *Tracker // tracker instance - Key TransactionKey // action key - Xappkey TransactionXappKey // transaction key - OrigParams *xapp.RMRParams // request orginal params - RespReceived bool - ForwardRespToXapp bool -} - -func (t *Transaction) SubRouteInfo() SubRouteInfo { - return SubRouteInfo{t.Key.TransType, t.Xappkey.Addr, t.Xappkey.Port, t.Key.SubID} -} - -/* -Implements a record of ongoing transactions and helper functions to CRUD the records. -*/ +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- type Tracker struct { - transactionTable map[TransactionKey]*Transaction - transactionXappTable map[TransactionXappKey]*Transaction mutex sync.Mutex + transactionXappTable map[TransactionXappKey]*Transaction } func (t *Tracker) Init() { - t.transactionTable = make(map[TransactionKey]*Transaction) t.transactionXappTable = make(map[TransactionXappKey]*Transaction) } -/* -Checks if a tranascation with similar type has been ongoing. If not then creates one. -Returns error if there is similar transatcion ongoing. -*/ -func (t *Tracker) TrackTransaction(subID uint16, act Action, addr string, port uint16, params *xapp.RMRParams, respReceived bool, forwardRespToXapp bool) (*Transaction, error) { - key := TransactionKey{subID, act} - xappkey := TransactionXappKey{addr, port, params.Xid} - trans := &Transaction{t, key, xappkey, params, respReceived, forwardRespToXapp} - t.mutex.Lock() - defer t.mutex.Unlock() - if _, ok := t.transactionTable[key]; ok { - // TODO: Implement merge related check here. If the key is same but the value is different. - err := fmt.Errorf("transaction tracker: Similar transaction with sub id %d and type %s is ongoing", key.SubID, key.TransType) - return nil, err - } - if _, ok := t.transactionXappTable[xappkey]; ok { - // TODO: Implement merge related check here. If the key is same but the value is different. - err := fmt.Errorf("transaction tracker: Similar transaction with xapp key %v is ongoing", xappkey) +func (t *Tracker) TrackTransaction( + endpoint *RmrEndpoint, + mtype int, + xid string, + meid *xapp.RMRMeid, + respReceived bool, + forwardRespToXapp bool) (*Transaction, error) { + + if endpoint == nil { + err := fmt.Errorf("Tracker: No valid endpoint given") return nil, err } - t.transactionTable[key] = trans - t.transactionXappTable[xappkey] = trans - return trans, nil -} -/* -Retreives the transaction table entry for the given request. Controls that only one response is sent to xapp. -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) RetriveTransaction(subID uint16, act Action) (*Transaction, error) { - key := TransactionKey{subID, act} - t.mutex.Lock() - defer t.mutex.Unlock() - if trans, ok := t.transactionTable[key]; ok { - return trans, nil + trans := &Transaction{ + tracker: nil, + Subs: nil, + RmrEndpoint: *endpoint, + Mtype: mtype, + Xid: xid, + Meid: meid, + RespReceived: respReceived, + ForwardRespToXapp: forwardRespToXapp, } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return nil, err -} -/* -Deletes the transaction table entry for the given request and returns the deleted xapp's address and port for reference. -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) completeTransaction(subID uint16, act Action) (*Transaction, error) { - key := TransactionKey{subID, act} t.mutex.Lock() defer t.mutex.Unlock() - if trans, ok1 := t.transactionTable[key]; ok1 { - if _, ok2 := t.transactionXappTable[trans.Xappkey]; ok2 { - delete(t.transactionXappTable, trans.Xappkey) - } - delete(t.transactionTable, key) - return trans, nil - } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return nil, err -} -/* -Makes possible to to detect has response already received from BTS -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) CheckResponseReceived(subID uint16, act Action) (*Transaction, bool, error) { - key := TransactionKey{subID, act} - t.mutex.Lock() - defer t.mutex.Unlock() - if trans, ok := t.transactionTable[key]; ok { - if trans.RespReceived == false { - trans.RespReceived = true - // This is used to control that only one response action (success response, failure or timer) is excecuted for the transaction - return trans, false, nil - } - return trans, true, nil + xappkey := TransactionXappKey{*endpoint, xid} + if _, ok := t.transactionXappTable[xappkey]; ok { + err := fmt.Errorf("Tracker: Similar transaction with xappkey %s is ongoing, transaction %s not created ", xappkey, trans) + return nil, err } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return nil, false, err + + trans.tracker = t + t.transactionXappTable[xappkey] = trans + return trans, nil } -/* -Makes possible to receive response to retransmitted request to BTS -Returns error in case the transaction cannot be found. -*/ -func (t *Tracker) RetryTransaction(subID uint16, act Action) error { - key := TransactionKey{subID, act} +func (t *Tracker) UnTrackTransaction(xappKey TransactionXappKey) (*Transaction, error) { t.mutex.Lock() defer t.mutex.Unlock() - if trans, ok := t.transactionTable[key]; ok { - trans.RespReceived = false - return nil + if trans, ok2 := t.transactionXappTable[xappKey]; ok2 { + delete(t.transactionXappTable, xappKey) + return trans, nil } - err := fmt.Errorf("transaction record for Subscription ID %d and action %s does not exist", subID, act) - return err + return nil, fmt.Errorf("Tracker: No record for xappkey %s", xappKey) }