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.
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
38 MaxAsn1CodecAllocationBufferSize = 64 * 1024
39 MaxAsn1PackedBufferSize = 4096
40 MaxAsn1CodecMessageBufferSize = 4096
44 /*The Ric Id is the combination of pLMNId and ENBId*/
48 var ricFlag = []byte{0xbb, 0xbc, 0xcc} /*pLMNId [3]bytes*/
50 type SetupRequestHandler struct {
51 rnibWriterProvider func() rNibWriter.RNibWriter
54 func NewSetupRequestHandler(rnibWriterProvider func() rNibWriter.RNibWriter) *SetupRequestHandler {
55 return &SetupRequestHandler{
56 rnibWriterProvider: rnibWriterProvider,
60 func (handler SetupRequestHandler) PreHandle(logger *logger.Logger, details *models.RequestDetails) error {
61 nodebInfo, nodebIdentity := rnibBuilders.CreateInitialNodeInfo(details, entities.E2ApplicationProtocol_X2_SETUP_REQUEST)
63 rNibErr := handler.rnibWriterProvider().SaveNodeb(nodebIdentity, nodebInfo)
65 logger.Errorf("#setup_request_handler.PreHandle - failed to save initial nodeb entity for ran name: %v in RNIB. Error: %s", details.RanName, rNibErr.Error())
67 logger.Infof("#setup_request_handler.PreHandle - initial nodeb entity for ran name: %v was saved to RNIB ", details.RanName)
73 func (SetupRequestHandler) CreateMessage(logger *logger.Logger, requestDetails *models.RequestDetails, messageChannel chan *models.E2RequestMessage, e2sessions sessions.E2Sessions, startTime time.Time, wg sync.WaitGroup) {
77 transactionId := requestDetails.RanName
78 e2sessions[transactionId] = sessions.E2SessionDetails{SessionStart: startTime, Request: requestDetails}
79 setupRequestMessage := models.NewE2RequestMessage(transactionId, requestDetails.RanIp, requestDetails.RanPort, requestDetails.RanName, e2pdus.PackedX2setupRequest)
81 logger.Debugf("#setup_request_handler.CreateMessage - PDU: %s", e2pdus.PackedX2setupRequestAsString)
82 logger.Debugf("#setup_request_handler.CreateMessage - setupRequestMessage was created successfully. setup request details(transactionId = [%s]): %+v", transactionId, setupRequestMessage)
83 messageChannel <- setupRequestMessage
88 //Expected value in RIC_ID = pLMN_Identity-eNB_ID/<eNB_ID size in bits>
89 //<6 hex digits>-<6 or 8 hex digits>/<18|20|21|28>
90 //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
91 //For example, to get the value of ffffeab/28 the last byte must be 0x0b, not 0xb0 (-ffffea0b/28).
92 func parseRicID(ricId string) error {
93 if _, err := fmt.Sscanf(ricId, "%6x-%8x/%2d", &pLMNId, &eNBId, &eNBIdBitqty); err != nil {
94 return fmt.Errorf("unable to extract the value of %s: %s", ENV_RIC_ID, err)
98 return fmt.Errorf("invalid value for %s, len(pLMNId:%v) != 3", ENV_RIC_ID, pLMNId)
102 return fmt.Errorf("invalid value for %s, len(eNBId:%v) != 3 or 4", ENV_RIC_ID, eNBId)
105 if eNBIdBitqty != e2pdus.ShortMacro_eNB_ID && eNBIdBitqty != e2pdus.Macro_eNB_ID && eNBIdBitqty != e2pdus.LongMacro_eNB_ID && eNBIdBitqty != e2pdus.Home_eNB_ID {
106 return fmt.Errorf("invalid value for %s, eNBIdBitqty: %d", ENV_RIC_ID, eNBIdBitqty)
113 func (SetupRequestHandler) GetMessageType() int {
114 return rmrCgo.RIC_X2_SETUP_REQ
119 ricId := os.Getenv(ENV_RIC_ID)
120 //ricId="bbbccc-ffff0e/20"
121 //ricId="bbbccc-abcd0e/20"
122 if err = parseRicID(ricId); err != nil {
126 e2pdus.PackedEndcX2setupRequest,e2pdus.PackedEndcX2setupRequestAsString, err = e2pdus.PreparePackedEndcX2SetupRequest(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize,pLMNId, eNBId, eNBIdBitqty, ricFlag )
130 e2pdus.PackedX2setupRequest,e2pdus.PackedX2setupRequestAsString, err = e2pdus.PreparePackedX2SetupRequest(MaxAsn1PackedBufferSize, MaxAsn1CodecMessageBufferSize,pLMNId, eNBId, eNBIdBitqty, ricFlag )