FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu20-c-go:1.1.0 AS a1-build
+
+#TODO check why defualt golang is not working
+ARG GOVERSION="1.18.5"
+RUN wget -nv https://dl.google.com/go/go${GOVERSION}.linux-amd64.tar.gz \
+ && tar -xf go${GOVERSION}.linux-amd64.tar.gz \
+ && mv go /opt/go/${GOVERSION} \
+ && rm -f go*.gz
+
+
+ENV DEFAULTPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ENV PATH=$DEFAULTPATH:/usr/local/go/bin:/opt/go/${GOVERSION}/bin:/root/go/bin
+
RUN apt-get update -y && apt-get install -y jq
# Update CA certificates
--- /dev/null
+/*
+==================================================================================
+ Copyright (c) 2022 Samsung
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ platform project (RICP).
+==================================================================================
+*/
+
+package policy
+
+import (
+ "strconv"
+
+ "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+ "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
+)
+
+const (
+ a1HandlerPrefix = "a1.policy_handler."
+ a1MediatorNs = "A1m_ns"
+)
+
+func NewPolicyManager(sdl *sdlgo.SyncStorage) *PolicyManager {
+ return createPolicyManager(sdl)
+}
+
+func createPolicyManager(sdlInst iSdl) *PolicyManager {
+ pm := &PolicyManager{
+ db: sdlInst,
+ }
+ return pm
+}
+func (pm *PolicyManager) SetPolicyInstanceStatus(policyTypeId int, policyInstanceID int, status string) error {
+ a1.Logger.Debug("message recieved for %d and %d", policyTypeId, policyInstanceID)
+ instancehandlerKey := a1HandlerPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + strconv.FormatInt((int64(policyInstanceID)), 10)
+ err := pm.db.Set(a1MediatorNs, instancehandlerKey, status)
+ if err != nil {
+ a1.Logger.Error("error1 :%+v", err)
+ return err
+ }
+ return nil
+}
--- /dev/null
+/*
+==================================================================================
+ Copyright (c) 2022 Samsung
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ platform project (RICP).
+==================================================================================
+*/
+
+package policy
+
+type PolicyManager struct {
+ db iSdl
+}
+type iSdl interface {
+ Set(ns string, pairs ...interface{}) error
+}
"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
+ "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/policy"
+ "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/rmr"
"gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
"github.com/santhosh-tekuri/jsonschema/v5"
return err == invalidJsonSchema
}
func NewResthook() *Resthook {
- return createResthook(sdlgo.NewSyncStorage(), rmr.NewRMRSender())
+ sdl := sdlgo.NewSyncStorage()
+ policyManager := policy.NewPolicyManager(sdl)
+ return createResthook(sdl, rmr.NewRMRSender(policyManager))
}
func createResthook(sdlInst iSdl, rmrSenderInst rmr.IRmrSender) *Resthook {
- return &Resthook{
+ rh := &Resthook{
db: sdlInst,
iRmrSenderInst: rmrSenderInst,
}
+
+ return rh
}
func (rh *Resthook) GetA1Health() bool {
package rmr
import (
+ "encoding/json"
+
"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+ "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/policy"
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
)
)
type RmrSender struct {
- rmrclient *xapp.RMRClient
+ rmrclient *xapp.RMRClient
+ policyManager *policy.PolicyManager
}
type IRmrSender interface {
RmrSendToXapp(httpBodyString string, messagetype int) bool
}
-func NewRMRSender() IRmrSender {
+func NewRMRSender(policyManager *policy.PolicyManager) IRmrSender {
RMRclient := xapp.NewRMRClientWithParams(&xapp.RMRClientParams{
StatDesc: "",
RmrData: xapp.PortData{
+ //TODO: Read configuration from config file
Name: "",
MaxSize: 65534,
ThreadType: 0,
LowLatency: false,
FastAck: false,
MaxRetryOnFailure: 1,
+ Port: 4561,
},
})
- return &RmrSender{
- rmrclient: RMRclient,
+
+ rmrsender := &RmrSender{
+ rmrclient: RMRclient,
+ policyManager: policyManager,
}
+
+ rmrsender.RmrRecieveStart()
+ return rmrsender
}
func (rmr *RmrSender) RmrSendToXapp(httpBodyString string, messagetype int) bool {
a1.Logger.Debug("rmrSendToXapp: sending: %+v", s)
return s
}
+
+func (rmr *RmrSender) Consume(msg *xapp.RMRParams) (err error) {
+ a1.Logger.Debug("In the Consume function")
+ id := xapp.Rmr.GetRicMessageName(msg.Mtype)
+ a1.Logger.Debug("Message received: name=%s meid=%s subId=%d txid=%s len=%d", id, msg.Meid.RanName, msg.SubId, msg.Xid, msg.PayloadLen)
+
+ switch id {
+
+ case "A1_POLICY_RESP":
+ a1.Logger.Debug("Recived policy responose")
+ payload := msg.Payload
+ a1.Logger.Debug("message recieved : %s", payload)
+ var result map[string]interface{}
+ err := json.Unmarshal([]byte(payload), &result)
+ if err != nil {
+ a1.Logger.Error("Unmarshal error : %+v", err)
+ return err
+ }
+ a1.Logger.Debug("message recieved for %d and %d with status : %s", result["policy_type_id"], result["policy_instance_id"], result["status"])
+ rmr.policyManager.SetPolicyInstanceStatus(int(result["policy_type_id"].(float64)), int(result["policy_instance_id"].(float64)), result["status"].(string))
+ default:
+ xapp.Logger.Error("Unknown message type '%d', discarding", msg.Mtype)
+ }
+
+ defer func() {
+ rmr.rmrclient.Free(msg.Mbuf)
+ msg.Mbuf = nil
+ }()
+ return
+}
+
+func (rmr *RmrSender) RmrRecieveStart() {
+ a1.Logger.Debug("Inside RmrRecieveStart function ")
+ rmr.rmrclient.Start(rmr)
+ a1.Logger.Debug("Reciever started")
+}