diff --git a/go.mod b/go.mod index 7d0371c..ae8f456 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/onosproject/onos-e2-sm/servicemodels/e2sm_rsm v0.8.43 github.com/onosproject/onos-lib-go v0.10.24 github.com/onosproject/onos-ric-sdk-go v0.8.12 - github.com/onosproject/onos-rsm v0.2.5 google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.33.0 ) diff --git a/go.sum b/go.sum index 4f722c1..a3a06d8 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,6 @@ github.com/onosproject/onos-lib-go v0.10.24 h1:CX/6a0U2ZAhHeYiZnmO+kOIoLv8V+aim0 github.com/onosproject/onos-lib-go v0.10.24/go.mod h1:xprZr/FtQ8YhDxA3WI7AqMUzK97QJvrsrrmY5KiX46I= github.com/onosproject/onos-ric-sdk-go v0.8.12 h1:aT6gevAeJ58/mkxzY/LDceyfKsik3DwIstsrVqyMEuY= github.com/onosproject/onos-ric-sdk-go v0.8.12/go.mod h1:/UMaxqFFzwxG7iBNquZKKM7o5mCNMppAoIkvjCQh0mE= -github.com/onosproject/onos-rsm v0.2.5 h1:21LSicrnpu4cP8bSJ7KUcY09wHdb+6JwGcwvjK0u2eo= -github.com/onosproject/onos-rsm v0.2.5/go.mod h1:m6FlTFuRBy5pDmDhTZ40rY55JpUEjzM9n7Uf/NUMong= github.com/openconfig/gnmi v0.9.1 h1:hVOdLTaRjdy68oCGJbkf2vrmnUoQ5xbINqBOAMix4xM= github.com/openconfig/gnmi v0.9.1/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 9b720a3..723911f 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -7,8 +7,11 @@ import ( appConfig "github.com/gercom-ufpa/iqos-xapp/pkg/config" "github.com/gercom-ufpa/iqos-xapp/pkg/nib/rnib" "github.com/gercom-ufpa/iqos-xapp/pkg/nib/uenib" + nbi "github.com/gercom-ufpa/iqos-xapp/pkg/northbound" + "github.com/gercom-ufpa/iqos-xapp/pkg/slicing" "github.com/gercom-ufpa/iqos-xapp/pkg/southbound/e2" "github.com/onosproject/onos-lib-go/pkg/logging" + "github.com/onosproject/onos-lib-go/pkg/northbound" ) // log initialize @@ -45,6 +48,8 @@ func NewManager(config Config) *Manager { log.Warn(err) } + rsmReqCh := make(chan *nbi.RsmMsg) + // Control messages used by the e2 and slicemgr packages slicingCtrlMsgs := e2.SlicingCtrlMsgs{ CtrlReqChsSliceCreate: make(map[string]chan *e2.CtrlMsg), @@ -53,6 +58,13 @@ func NewManager(config Config) *Manager { CtrlReqChsUeAssociate: make(map[string]chan *e2.CtrlMsg), } + slicingManager := slicing.NewManager( + slicing.WithRnibClient(rnibClient), + slicing.WithUenibClient(uenibClient), + slicing.WithCtrlReqChs(slicingCtrlMsgs.CtrlReqChsSliceCreate, slicingCtrlMsgs.CtrlReqChsSliceUpdate, slicingCtrlMsgs.CtrlReqChsSliceDelete, slicingCtrlMsgs.CtrlReqChsUeAssociate), + slicing.WithNbiReqChs(rsmReqCh), + slicing.WithAckTimer(config.AckTimer), + ) // Creates App Managers // A1 Manager (or client?? - TODO) @@ -87,11 +99,13 @@ func NewManager(config Config) *Manager { // App Manager manager := &Manager{ - appConfig: appCfg, - config: config, - E2Manager: e2Manager, - UenibClient: uenibClient, - RnibClient: rnibClient, + appConfig: appCfg, + config: config, + E2Manager: e2Manager, + SlicingManager: slicingManager, + UenibClient: uenibClient, + RnibClient: rnibClient, + RsmReqCh: rsmReqCh, } return manager @@ -106,14 +120,23 @@ func (mgr *Manager) Run() { // starts xAPP processes func (mgr *Manager) start() error { + + // starts Northbound server + err := mgr.startNorthboundServer() + if err != nil { + log.Warn(err) + return err + } + // starts E2 subscriptions - err := mgr.E2Manager.Start() // TODO + err = mgr.E2Manager.Start() // TODO if err != nil { log.Warnf("Fail to start E2 Manager: %v", err) return err } // starts Slice Module (TODO) + go mgr.SlicingManager.Run(context.Background()) return nil } @@ -123,3 +146,27 @@ func (m *Manager) Close() { // TODO // syscall.Kill(syscall.Getpid(), syscall.SIGINT) } + +func (mgr *Manager) startNorthboundServer() error { + s := northbound.NewServer(northbound.NewServerCfg( + mgr.config.CAPath, + mgr.config.KeyPath, + mgr.config.CertPath, + int16(mgr.config.GRPCPort), + true, + northbound.SecurityConfig{})) + + s.AddService(nbi.NewService(mgr.RnibClient, mgr.UenibClient, mgr.RsmReqCh)) + + doneCh := make(chan error) + go func() { + err := s.Serve(func(started string) { + log.Info("Started NBI on ", started) + close(doneCh) + }) + if err != nil { + doneCh <- err + } + }() + return <-doneCh +} diff --git a/pkg/manager/options.go b/pkg/manager/options.go index 3d1a96c..ec4e93b 100644 --- a/pkg/manager/options.go +++ b/pkg/manager/options.go @@ -4,6 +4,8 @@ import ( appConfig "github.com/gercom-ufpa/iqos-xapp/pkg/config" "github.com/gercom-ufpa/iqos-xapp/pkg/nib/rnib" "github.com/gercom-ufpa/iqos-xapp/pkg/nib/uenib" + nbi "github.com/gercom-ufpa/iqos-xapp/pkg/northbound" + "github.com/gercom-ufpa/iqos-xapp/pkg/slicing" "github.com/gercom-ufpa/iqos-xapp/pkg/southbound/e2" ) @@ -15,6 +17,7 @@ type Config struct { CertPath string E2tEndpoint string E2tPort int + GRPCPort int TopoEndpoint string TopoPort int UeNibEndpoint string @@ -24,13 +27,16 @@ type Config struct { KpmSMVersion string RsmSMName string RsmSMVersion string + AckTimer int } // Manager is an abstract struct for manager type Manager struct { - appConfig appConfig.Config - config Config - E2Manager e2.Manager - UenibClient uenib.Client - RnibClient rnib.Client + appConfig appConfig.Config + config Config + E2Manager e2.Manager + UenibClient uenib.Client + RnibClient rnib.Client + SlicingManager slicing.Manager + RsmReqCh chan *nbi.RsmMsg } diff --git a/pkg/nib/rnib/rnib.go b/pkg/nib/rnib/rnib.go index b95649f..8e30c6b 100644 --- a/pkg/nib/rnib/rnib.go +++ b/pkg/nib/rnib/rnib.go @@ -112,6 +112,18 @@ func (c *Client) GetRsmSliceItemAspects(ctx context.Context, nodeID topoapi.ID) return rsmSliceList.GetRsmSliceList(), nil } +func (t *Client) UpdateRsmSliceItemAspect(ctx context.Context, nodeID topoapi.ID, msg *topoapi.RSMSlicingItem) error { + err := t.DeleteRsmSliceItemAspect(ctx, nodeID, msg.GetID()) + if err != nil { + return err + } + err = t.AddRsmSliceItemAspect(ctx, nodeID, msg) + if err != nil { + return err + } + return nil +} + // Gets RsmSliceItemList aspect on Node | return RsmSliceItemList aspect per slice func (c *Client) GetRsmSliceListAspect(ctx context.Context, nodeID topoapi.ID) (*topoapi.RSMSliceItemList, error) { // gets a topo object by ID diff --git a/pkg/northbound/rsm.go b/pkg/northbound/rsm.go index 519bc26..a321def 100644 --- a/pkg/northbound/rsm.go +++ b/pkg/northbound/rsm.go @@ -6,21 +6,24 @@ package northbound import ( "context" + + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/rnib" + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/uenib" rsmapi "github.com/onosproject/onos-api/go/onos/rsm" topoapi "github.com/onosproject/onos-api/go/onos/topo" "github.com/onosproject/onos-lib-go/pkg/logging/service" - "github.com/onosproject/onos-rsm/pkg/nib/rnib" - "github.com/onosproject/onos-rsm/pkg/nib/uenib" "google.golang.org/grpc" ) -//Creates a new service with the provided clients and the RSM messaging channel. -func NewService(rnibClient rnib.TopoClient, uenibClient uenib.Client, rsmReqCh chan *RsmMsg) service.Service { + +// Creates a new service with the provided clients and the RSM messaging channel. +func NewService(rnibClient rnib.Client, uenibClient uenib.Client, rsmReqCh chan *RsmMsg) service.Service { return &Service{ rnibClient: rnibClient, uenibClient: uenibClient, rsmReqCh: rsmReqCh, } } + // Register registers the service on the provided gRPC server. func (s Service) Register(r *grpc.Server) { server := &Server{ @@ -30,7 +33,8 @@ func (s Service) Register(r *grpc.Server) { } rsmapi.RegisterRsmServer(r, server) } -//Creates a new slice using the given parameters. + +// Creates a new slice using the given parameters. func (s Server) CreateSlice(_ context.Context, request *rsmapi.CreateSliceRequest) (*rsmapi.CreateSliceResponse, error) { // Create a confirmation channel. ackCh := make(chan Ack) @@ -44,7 +48,7 @@ func (s Server) CreateSlice(_ context.Context, request *rsmapi.CreateSliceReques go func(msg *RsmMsg) { s.rsmReqCh <- msg }(msg) - // Wait for confirmation of the operation. + // Wait for confirmation of the operation. ack := <-ackCh // Returns the response. return &rsmapi.CreateSliceResponse{ @@ -113,4 +117,4 @@ func (s Server) SetUeSliceAssociation(_ context.Context, request *rsmapi.SetUeSl Cause: ack.Reason, }, }, nil -} \ No newline at end of file +} diff --git a/pkg/northbound/types.go b/pkg/northbound/types.go index 9e22683..2d06d06 100644 --- a/pkg/northbound/types.go +++ b/pkg/northbound/types.go @@ -5,9 +5,9 @@ package northbound import ( + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/rnib" + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/uenib" topoapi "github.com/onosproject/onos-api/go/onos/topo" - "github.com/onosproject/onos-rsm/pkg/nib/rnib" - "github.com/onosproject/onos-rsm/pkg/nib/uenib" ) // Confirmation message for an operation, containing a boolean @@ -29,14 +29,14 @@ type RsmMsg struct { // This Service struct encapsulates the clients for rnib and uenib, as well as a channel // for receiving RSM messages. It is intended to be used to provide RSM-related services. type Service struct { - rnibClient rnib.TopoClient + rnibClient rnib.Client uenibClient uenib.Client rsmReqCh chan *RsmMsg } // Create a gRPC server to serve RPC requests type Server struct { - rnibClient rnib.TopoClient + rnibClient rnib.Client uenibClient uenib.Client rsmReqCh chan *RsmMsg } diff --git a/pkg/slicing/manager.go b/pkg/slicing/manager.go index 0363778..1d3a228 100644 --- a/pkg/slicing/manager.go +++ b/pkg/slicing/manager.go @@ -6,14 +6,14 @@ import ( "strconv" "time" + "github.com/gercom-ufpa/iqos-xapp/pkg/northbound" + "github.com/gercom-ufpa/iqos-xapp/pkg/southbound/e2" rsmapi "github.com/onosproject/onos-api/go/onos/rsm" topoapi "github.com/onosproject/onos-api/go/onos/topo" uenib_api "github.com/onosproject/onos-api/go/onos/uenib" // used by delete func e2sm_rsm "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_rsm/v1/e2sm-rsm-ies" e2sm_v2_ies "github.com/onosproject/onos-e2-sm/servicemodels/e2sm_rsm/v1/e2sm-v2-ies" "github.com/onosproject/onos-lib-go/pkg/logging" - "github.com/onosproject/onos-rsm/pkg/northbound" // TODO - "github.com/onosproject/onos-rsm/pkg/southbound/e2" // TODO ) var log = logging.GetLogger("iqos-xapp", "slicemgr") @@ -56,8 +56,8 @@ func (m *Manager) DispatchNbiMsg(ctx context.Context) { err = m.handleNbiUpdateSliceRequest(ctx, msg.Message.(*rsmapi.UpdateSliceRequest), msg.NodeID) case *rsmapi.DeleteSliceRequest: err = m.handleNbiDeleteSliceRequest(ctx, msg.Message.(*rsmapi.DeleteSliceRequest), msg.NodeID) - //case *rsmapi.SetUeSliceAssociationRequest: - // err = m.handleNbiSetUeSliceAssociationRequest(ctx, msg.Message.(*rsmapi.SetUeSliceAssociationRequest), msg.NodeID) + case *rsmapi.SetUeSliceAssociationRequest: + err = m.handleNbiSetUeSliceAssociationRequest(ctx, msg.Message.(*rsmapi.SetUeSliceAssociationRequest), msg.NodeID) default: err = fmt.Errorf("unknown msg type: %v", msg) } @@ -240,7 +240,7 @@ func (m *Manager) handleNbiDeleteSliceRequest(ctx context.Context, req *rsmapi.D return fmt.Errorf("failed to delete slice information to onos-topo although control message was sent: %v", err) } - ues, err := m.uenibClient.GetUEs(ctx) // try get a list of UEs registered in UENIB + ues, err := m.uenibClient.GetRsmUEs(ctx) // try get a list of UEs registered in UENIB if err != nil { return fmt.Errorf("failed to get UEs in UENIB: %v", err) // error getting } @@ -255,7 +255,7 @@ func (m *Manager) handleNbiDeleteSliceRequest(ctx context.Context, req *rsmapi.D } } if changed { - err = m.uenibClient.UpdateUE(ctx, ues[i]) // return a error if wasn't possible update UE's data + err = m.uenibClient.UpdateRsmUE(ctx, ues[i]) // return a error if wasn't possible update UE's data if err != nil { return fmt.Errorf("failed to update UENIB: %v", err) } @@ -372,7 +372,7 @@ func (m *Manager) handleNbiUpdateSliceRequest(ctx context.Context, req *rsmapi.U return fmt.Errorf("failed to update slice information to onos-topo although control message was sent: %v", err) } - ues, err := m.uenibClient.GetUEs(ctx) // try get a list of UEs registered in UENIB client + ues, err := m.uenibClient.GetRsmUEs(ctx) // try get a list of UEs registered in UENIB client if err != nil { return fmt.Errorf("failed to get UEs in UENIB: %v", err) // error getting } @@ -387,7 +387,7 @@ func (m *Manager) handleNbiUpdateSliceRequest(ctx context.Context, req *rsmapi.U } } if changed { - err = m.uenibClient.UpdateUE(ctx, ues[i]) // return a error if wasn't possible update UE's data + err = m.uenibClient.UpdateRsmUE(ctx, ues[i]) // return a error if wasn't possible update UE's data if err != nil { return fmt.Errorf("failed to update UENIB: %v", err) } @@ -493,7 +493,7 @@ func (m *Manager) handleNbiSetUeSliceAssociationRequest(ctx context.Context, req }, } - rsmUEInfo, err := m.uenibClient.GetUEWithPreferredID(ctx, string(cuNodeID), uenib_api.UeIdType_UE_ID_TYPE_DU_UE_F1_AP_ID, DuUeF1apID) + rsmUEInfo, err := m.uenibClient.GetRsmUEWithPreferredID(ctx, string(cuNodeID), uenib_api.UeIdType_UE_ID_TYPE_DU_UE_F1_AP_ID, DuUeF1apID) if err != nil { return fmt.Errorf("failed to get UENIB UE info (CuID %v DUID %v UEID %v): err: %v", cuNodeID, duNodeID, ueID, err) } @@ -622,7 +622,7 @@ func (m *Manager) handleNbiSetUeSliceAssociationRequest(ctx context.Context, req } } - err = m.uenibClient.UpdateUE(ctx, rsmUEInfo) + err = m.uenibClient.UpdateRsmUE(ctx, &rsmUEInfo) if err != nil { return fmt.Errorf("tried to update du e2node ID on uenib (because there was no du ID) but failed to update du id UENIB UE info (CuID %v DUID %v UEID %v uenib UE info %v): err: %v", cuNodeID, duNodeID, ueID, rsmUEInfo, err) } @@ -849,7 +849,7 @@ func (m *Manager) handleNbiSetUeSliceAssociationRequest(ctx context.Context, req rsmUEInfo.SliceList = append(rsmUEInfo.SliceList, sliceInfo) } - err = m.uenibClient.UpdateUE(ctx, rsmUEInfo) + err = m.uenibClient.UpdateRsmUE(ctx, &rsmUEInfo) if err != nil { return fmt.Errorf("Failed to update uenib: %v", err) } @@ -953,7 +953,7 @@ func (m *Manager) handleNbiSetUeSliceAssociationRequest(ctx context.Context, req rsmUEInfo.SliceList = append(rsmUEInfo.SliceList, sliceInfo) - err = m.uenibClient.UpdateUE(ctx, rsmUEInfo) + err = m.uenibClient.UpdateRsmUE(ctx, &rsmUEInfo) if err != nil { return fmt.Errorf("Failed to update uenib: %v", err) } diff --git a/pkg/slicing/options.go b/pkg/slicing/options.go index f028eb6..e70b522 100644 --- a/pkg/slicing/options.go +++ b/pkg/slicing/options.go @@ -1,10 +1,10 @@ package slicing import ( - "github.com/onosproject/onos-rsm/pkg/nib/rnib" - "github.com/onosproject/onos-rsm/pkg/nib/uenib" - "github.com/onosproject/onos-rsm/pkg/northbound" // todo: create pkg/northbound - "github.com/onosproject/onos-rsm/pkg/southbound/e2" // todo: modify pkg/southbound + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/rnib" + "github.com/gercom-ufpa/iqos-xapp/pkg/nib/uenib" + "github.com/gercom-ufpa/iqos-xapp/pkg/northbound" // todo: create pkg/northbound + "github.com/gercom-ufpa/iqos-xapp/pkg/southbound/e2" // todo: modify pkg/southbound ) type Manager struct { @@ -13,7 +13,7 @@ type Manager struct { ctrlReqChsSliceUpdate map[string]chan *e2.CtrlMsg ctrlReqChsSliceDelete map[string]chan *e2.CtrlMsg ctrlReqChsUeAssociate map[string]chan *e2.CtrlMsg - rnibClient rnib.TopoClient + rnibClient rnib.Client uenibClient uenib.Client ctrlMsgHandler e2.ControlMessageHandler ackTimer int @@ -38,7 +38,7 @@ type Channels struct { } type AppOptions struct { - RnibClient rnib.TopoClient + RnibClient rnib.Client UenibClient uenib.Client @@ -81,7 +81,7 @@ func WithNbiReqChs(rsmMsgCh chan *northbound.RsmMsg) Option { }) } -func WithRnibClient(rnibClient rnib.TopoClient) Option { +func WithRnibClient(rnibClient rnib.Client) Option { return newOption(func(options *Options) { options.App.RnibClient = rnibClient })