Add example of E2 subscription via REST + alarm raising 70/3170/3
authorMohamed Abukar <abukar.mohamed@nokia.com>
Mon, 6 Apr 2020 18:15:45 +0000 (21:15 +0300)
committerMohamed Abukar <abukar.mohamed@nokia.com>
Tue, 7 Apr 2020 04:57:54 +0000 (07:57 +0300)
Change-Id: Ie9c9c29e62b166f2755dbec6ab0c1ff348485fed
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
examples/build/build_example_xapp.sh
examples/cmd/example-xapp.go
examples/go.mod
examples/go.sum
pkg/restapi/server.go

index 96e69c2..297a33c 100755 (executable)
@@ -46,6 +46,6 @@ GO111MODULE=on GO_ENABLED=0 GOOS=linux
 
 
 # Build
-go build -a -installsuffix cgo -o alarm-adapter -o example_xapp cmd/example-xapp.go
+go build -a -installsuffix cgo -o example_xapp cmd/example-xapp.go
 
 echo "--> build_example_xapp.sh ends"
index 8fe7873..a08844b 100755 (executable)
    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 main
 
 import (
+       "gerrit.o-ran-sc.org/r/ric-plt/alarm-go.git/alarm"
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        "net/http"
 )
 
 // This could be defined in types.go
 type ExampleXapp struct {
-       msgChan    chan *xapp.RMRParams
-       stats      map[string]xapp.Counter
-       rmrReady   bool
-       waitForSdl bool
+       msgChan               chan *xapp.RMRParams
+       stats                 map[string]xapp.Counter
+       rmrReady              bool
+       waitForSdl            bool
+       subscriptionInstances []*clientmodel.SubscriptionInstance
+       subscriptionId        *string
 }
 
 func (e *ExampleXapp) handleRICIndication(ranName string, r *xapp.RMRParams) {
@@ -67,6 +74,47 @@ func (e *ExampleXapp) messageLoop() {
        }
 }
 
+func (e *ExampleXapp) Subscribe() {
+       // Setup response callback to handle subscription response from SubMgr
+       xapp.Subscription.SetResponseCB(func(resp *clientmodel.SubscriptionResponse) {
+               if *e.subscriptionId == *resp.SubscriptionID {
+                       for _, s := range resp.SubscriptionInstances {
+                               e.subscriptionInstances = append(e.subscriptionInstances, s)
+                       }
+               }
+       })
+
+       // Fill subscription parameters: type=REPORT
+       ranName := "en-gnb:369-11105-aaaaa8"
+       functionId := int64(1)
+       clientEndpoint := "localhost:4560"
+
+       reportParams := clientmodel.ReportParams{
+               Meid:           ranName,
+               RANFunctionID:  &functionId,
+               ClientEndpoint: &clientEndpoint,
+               EventTriggers: clientmodel.EventTriggerList{
+                       &clientmodel.EventTrigger{
+                               InterfaceDirection: int64(0),
+                               ProcedureCode:      int64(27),
+                               TypeOfMessage:      int64(1),
+                       },
+               },
+       }
+
+       // Now subscribe ...
+       if resp, err := xapp.Subscription.SubscribeReport(&reportParams); err == nil {
+               e.subscriptionId = resp.SubscriptionID
+               xapp.Logger.Info("Subscriptions for RanName='%s' [subscriptionId=%s] done!", ranName, *resp.SubscriptionID)
+               return
+       }
+
+       // Subscription failed, raise alarm (only for demo purpose!)
+       if err := xapp.Alarm.Raise(8006, alarm.SeverityCritical, ranName, "subscriptionFailed"); err != nil {
+               xapp.Logger.Info("Raising alarm failed with error: %v", err)
+       }
+}
+
 func (e *ExampleXapp) Consume(rp *xapp.RMRParams) (err error) {
        e.msgChan <- rp
        return
index 78e55fe..53baac5 100644 (file)
@@ -4,7 +4,7 @@ module gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/example-xapp
 
 require gerrit.o-ran-sc.org/r/ric-plt/xapp-frame v0.4.1
 
-replace gerrit.o-ran-sc.org/r/ric-plt/xapp-frame => gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.1
+replace gerrit.o-ran-sc.org/r/ric-plt/xapp-frame => gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.6
 
 replace gerrit.o-ran-sc.org/r/ric-plt/sdlgo => gerrit.o-ran-sc.org/r/ric-plt/sdlgo.git v0.5.0
 
index 9ec3615..4db27b8 100644 (file)
@@ -15,6 +15,8 @@ gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.0.26 h1:zFsExCZVAX9vTcLEHNsYgxnK
 gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.0.26/go.mod h1:lW3UYpVXwPiOR39t6JgNCE4kdmMSdPVelMPC/Pp9fQM=
 gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.1 h1:ydw6WM3PNOKI0LAEyCKWCJ4LncHMfyHdpvCAHBYwrdE=
 gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.1/go.mod h1:29CdUcCrNEqVBjQWAlgeGrYxSWqSZ4e67xzhuSf6BkI=
+gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.6 h1:Yhizs1A+0n0TLFxeGZO1YYQy8eBX9UEj4e4PgmK008k=
+gerrit.o-ran-sc.org/r/ric-plt/xapp-frame.git v0.4.6/go.mod h1:29CdUcCrNEqVBjQWAlgeGrYxSWqSZ4e67xzhuSf6BkI=
 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
index 544be19..23fda83 100644 (file)
@@ -489,7 +489,7 @@ func (s *Server) TLSListener() (net.Listener, error) {
 
 func handleInterrupt(once *sync.Once, s *Server) {
        once.Do(func() {
-               for _ = range s.interrupt {
+               for range s.interrupt {
                        if s.interrupted {
                                s.Logf("Server already shutting down")
                                continue