Squash-merging e2ap-v2.0 branch
[ric-plt/e2mgr.git] / E2Manager / models / ric_service_query_message.go
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 //  platform project (RICP).
18
19 package models
20
21 import (
22         "encoding/xml"
23         "math/rand"
24         "strconv"
25         "time"
26
27         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
28 )
29
30 type RanFunctionIdItem struct {
31         Text                string `xml:",chardata"`
32         RanFunctionId       uint32 `xml:"ranFunctionID"`
33         RanFunctionRevision uint32 `xml:"ranFunctionRevision"`
34 }
35
36 type RicServiceQueryProtocolIESingleContainer struct {
37         Text        string `xml:",chardata"`
38         Id          string `xml:"id"`
39         Criticality struct {
40                 Text   string `xml:",chardata"`
41                 Reject string `xml:"reject"`
42         } `xml:"criticality"`
43         Value struct {
44                 Text              string            `xml:",chardata"`
45                 RanFunctionIdItem RanFunctionIdItem `xml:"RANfunctionID-Item"`
46         } `xml:"value"`
47 }
48
49 type RICServiceQueryIEs struct {
50         Text        string `xml:",chardata"`
51         Id          string `xml:"id"`
52         Criticality struct {
53                 Text   string `xml:",chardata"`
54                 Reject string `xml:"reject"`
55         } `xml:"criticality"`
56         Value interface{} `xml:"value"`
57 }
58
59 type RICServiceQueryRANFunctionIdList struct {
60         Text              string `xml:",chardata"`
61         RANFunctionIdList struct {
62                 Text                      string                                     `xml:",chardata"`
63                 ProtocolIESingleContainer []RicServiceQueryProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
64         } `xml:"RANfunctionsID-List"`
65 }
66 type RICServiceQueryTransactionID struct {
67         Text          string `xml:",chardata"`
68         TransactionID string `xml:"TransactionID"`
69 }
70
71 type RICServiceQuery struct {
72         Text        string `xml:",chardata"`
73         ProtocolIEs struct {
74                 Text               string               `xml:",chardata"`
75                 RICServiceQueryIEs []RICServiceQueryIEs `xml:"RICserviceQuery-IEs"`
76         } `xml:"protocolIEs"`
77 }
78
79 type InitiatingMessage struct {
80         Text          string `xml:",chardata"`
81         ProcedureCode string `xml:"procedureCode"`
82         Criticality   struct {
83                 Text   string `xml:",chardata"`
84                 Ignore string `xml:"ignore"`
85         } `xml:"criticality"`
86         Value struct {
87                 Text            string          `xml:",chardata"`
88                 RICServiceQuery RICServiceQuery `xml:"RICserviceQuery"`
89         } `xml:"value"`
90 }
91
92 type RicServiceQueryE2APPDU struct {
93         XMLName           xml.Name          `xml:"E2AP-PDU"`
94         Text              string            `xml:",chardata"`
95         InitiatingMessage InitiatingMessage `xml:"initiatingMessage"`
96 }
97
98 type RICServiceQueryMessage struct {
99         XMLName xml.Name               `xml:"RICserviceQueryMessage"`
100         Text    string                 `xml:",chardata"`
101         E2APPDU RicServiceQueryE2APPDU `xml:"E2AP-PDU"`
102 }
103
104 func NewRicServiceQueryMessage(ranFunctions []*entities.RanFunction) RICServiceQueryMessage {
105         rand.Seed(time.Now().Unix())
106
107         txIE := RICServiceQueryIEs{
108                 Id: ProtocolIE_ID_id_TransactionID,
109                 Value: RICServiceQueryTransactionID{
110                         TransactionID: strconv.FormatUint(rand.Uint64(), 10),
111                 },
112         }
113
114         protocolIESingleContainer := make([]RicServiceQueryProtocolIESingleContainer, len(ranFunctions))
115         for i := 0; i < len(ranFunctions); i++ {
116                 protocolIESingleContainer[i].Id = ProtocolIE_ID_id_RANfunctionID_Item
117                 protocolIESingleContainer[i].Value.RanFunctionIdItem.RanFunctionId = ranFunctions[i].RanFunctionId
118                 protocolIESingleContainer[i].Value.RanFunctionIdItem.RanFunctionRevision = ranFunctions[i].RanFunctionRevision
119         }
120
121         funcListIE := RICServiceQueryIEs{
122                 Id: ProtocolIE_ID_id_RANfunctionsAccepted,
123                 Value: RICServiceQueryRANFunctionIdList{
124                         RANFunctionIdList: struct {
125                                 Text                      string                                     `xml:",chardata"`
126                                 ProtocolIESingleContainer []RicServiceQueryProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
127                         }{
128                                 ProtocolIESingleContainer: protocolIESingleContainer,
129                         },
130                 },
131         }
132
133         initiatingMessage := InitiatingMessage{
134                 ProcedureCode: ProcedureCode_id_RICserviceQuery,
135                 Value: struct {
136                         Text            string          `xml:",chardata"`
137                         RICServiceQuery RICServiceQuery `xml:"RICserviceQuery"`
138                 }{
139                         RICServiceQuery: RICServiceQuery{
140                                 ProtocolIEs: struct {
141                                         Text               string               `xml:",chardata"`
142                                         RICServiceQueryIEs []RICServiceQueryIEs `xml:"RICserviceQuery-IEs"`
143                                 }{
144                                         RICServiceQueryIEs: []RICServiceQueryIEs{txIE, funcListIE},
145                                 },
146                         },
147                 },
148         }
149
150         return RICServiceQueryMessage{E2APPDU: RicServiceQueryE2APPDU{InitiatingMessage: initiatingMessage}}
151 }