2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
36 MaxAsn1CodecAllocationBufferSize = 64 * 1024
37 MaxAsn1PackedBufferSize = 4096
38 MaxAsn1CodecMessageBufferSize = 4096
42 shortMacro_eNB_ID = 18
48 /*The Ric Id is the combination of pLMNId and ENBId*/
52 var ricFlag = [3]byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
54 type SetupRequestHandler struct {
55 rnibWriterProvider func() rNibWriter.RNibWriter
58 func NewSetupRequestHandler(rnibWriterProvider func() rNibWriter.RNibWriter) *SetupRequestHandler {
59 return &SetupRequestHandler{
60 rnibWriterProvider: rnibWriterProvider,
64 func (handler SetupRequestHandler) PreHandle(logger *logger.Logger, details *models.RequestDetails) error {
65 nodebInfo, nodebIdentity := rnibBuilders.CreateInitialNodeInfo(details)
67 rNibErr := handler.rnibWriterProvider().SaveNodeb(nodebIdentity, nodebInfo)
69 logger.Errorf("#setup_request_handler.PreHandle - failed to save initial nodeb entity for ran name: %v in RNIB. Error: %s", details.RanName, rNibErr.Error())
71 logger.Infof("#setup_request_handler.PreHandle - initial nodeb entity for ran name: %v was saved to RNIB ", details.RanName)
77 func (SetupRequestHandler) CreateMessage(logger *logger.Logger, requestDetails *models.RequestDetails, messageChannel chan *models.E2RequestMessage, e2sessions sessions.E2Sessions, startTime time.Time, wg sync.WaitGroup) {
81 payload, err := packX2apSetupRequest(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, MaxAsn1PackedBufferSize /*max packed buffer*/, MaxAsn1CodecMessageBufferSize /*max message buffer*/, pLMNId, eNBId, eNBIdBitqty)
83 logger.Errorf("#setup_request_handler.CreateMessage - pack was failed. Error: %v", err)
85 transactionId := requestDetails.RanName
86 e2sessions[transactionId] = sessions.E2SessionDetails{SessionStart: startTime, Request: requestDetails}
87 setupRequestMessage := models.NewE2RequestMessage(transactionId, requestDetails.RanIp, requestDetails.RanPort, requestDetails.RanName, payload)
89 logger.Debugf("#setup_request_handler.CreateMessage - setupRequestMessage was created successfully. setup request details(transactionId = [%s]): %+v", transactionId, setupRequestMessage)
90 messageChannel <- setupRequestMessage
96 func asn1bstringToString(val []byte, numBits uint) string {
102 // If num bits is not evenly divisable by 8 ...
104 // ... shift the value to the higher bits (in our case: 0x0b -> 0xb0)
109 return fmt.Sprintf("%02x", c)
111 return fmt.Sprintf("%02x%02x", val[:len(val)-1], c)
114 //Expected value in RIC_ID = pLMN_Identity-eNB_ID/<eNB_ID size in bits>
115 //<6 hex digits>-<6 or 8 hex digits>/<18|20|21|28>
116 //Each byte is represented by two hex digits, the value in the lowest byte of the eNB_ID must be assigned to the lowest bits
117 //For example, to get the value of ffffeab/28 the last byte must be 0x0b, not 0xb0 (-ffffea0b/28).
118 func parseRicID(ricId string) error {
119 if _, err := fmt.Sscanf(ricId, "%6x-%8x/%2d", &pLMNId, &eNBId, &eNBIdBitqty); err != nil {
120 return fmt.Errorf("unable to extract the value of %s: %s", ENV_RIC_ID, err)
124 return fmt.Errorf("invalid value for %s, len(pLMNId:%v) != 3", ENV_RIC_ID, pLMNId)
128 return fmt.Errorf("invalid value for %s, len(eNBId:%v) != 3 or 4", ENV_RIC_ID, eNBId)
131 if eNBIdBitqty != shortMacro_eNB_ID && eNBIdBitqty != macro_eNB_ID && eNBIdBitqty != longMacro_eNB_ID && eNBIdBitqty != home_eNB_ID {
132 return fmt.Errorf("invalid value for %s, eNBIdBitqty: %d", ENV_RIC_ID, eNBIdBitqty)
139 func (SetupRequestHandler) GetMessageType() int {
140 return rmrCgo.RIC_X2_SETUP_REQ
144 ricId := os.Getenv(ENV_RIC_ID)
145 //ricId="bbbccc-ffff0e/20"
146 //ricId="bbbccc-abcd0e/20"
147 if err := parseRicID(ricId); err != nil {