First commit

This commit is contained in:
Leonardo Bonati
2021-12-08 20:17:46 +00:00
commit 60dffad583
2923 changed files with 463894 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
##############################################################################
#
# Copyright (c) 2019 AT&T Intellectual Property.
#
# 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.
#
##############################################################################
FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:2-u16.04-nng as ubuntu
WORKDIR /opt/kubsimulator
COPY . .
ENV PATH=$PATH:/usr/local/go/bin:/usr/lib/go-1.12/bin
RUN go build main.go
FROM ubuntu:16.04
COPY --from=ubuntu /opt/kubsimulator/main /opt/kubsimulator/main
COPY --from=ubuntu /opt/kubsimulator/resources /opt/kubsimulator/resources
WORKDIR /opt/kubsimulator
CMD exec ./main

View File

@@ -0,0 +1,54 @@
# ========================LICENSE_START=================================
# O-RAN-SC
#
# Copyright (C) 2019 AT&T Intellectual Property and Nokia
#
# 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.
# ========================LICENSE_END===================================
# This source code is part of the near-RT RIC (RAN Intelligent Controller)
# platform project (RICP).
openapi: 3.0.0
info:
title: Kubernetes Simulator
description: Kubernetes Simulator APIs
version: 0.0.1
servers:
- url: 'http://{apiRoot}/api/v1'
variables:
apiRoot:
default: 'localhost:59009'
paths:
'/namespaces/{namespace}/pods/{pod}':
delete:
summary: Delete Pod
tags:
- Delete Pod
operationId: DeletePod
parameters:
- name: namespace
in: path
required: true
schema:
type: string
- name: pod
in: path
required: true
description: pod to delete
schema:
type: string
responses:
'200':
description: Successful operation

View File

@@ -0,0 +1,57 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 configuration
import (
"fmt"
"github.com/spf13/viper"
)
type Configuration struct {
Http struct {
Port int
}
}
func ParseConfiguration() *Configuration{
viper.SetConfigType("yaml")
viper.SetConfigName("configuration")
viper.AddConfigPath("KubernetesSimulator/resources/")
viper.AddConfigPath("./resources/") //For production
viper.AddConfigPath("../resources/") //For test under Docker
viper.AddConfigPath("../../resources/") //For test under Docker
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Sprintf("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err))
}
config := Configuration{}
config.fillHttpConfig(viper.Sub("http"))
return &config
}
func (c *Configuration)fillHttpConfig(httpConfig *viper.Viper) {
if httpConfig == nil {
panic(fmt.Sprintf("#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n"))
}
c.Http.Port = httpConfig.GetInt("port")
}

View File

@@ -0,0 +1,76 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 configuration
import (
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"testing"
)
func TestParseConfigurationSuccess(t *testing.T) {
config := ParseConfiguration()
assert.Equal(t, 59009, config.Http.Port)
}
func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
configPath := "../resources/configuration.yaml"
configPathTmp := "../resources/configuration.yaml_tmp"
err := os.Rename(configPath, configPathTmp)
if err != nil {
t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
defer func() {
err = os.Rename(configPathTmp, configPath)
if err != nil {
t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
}()
assert.Panics(t, func() { ParseConfiguration() })
}
func TestHttpConfigNotFoundFailure(t *testing.T) {
configPath := "../resources/configuration.yaml"
configPathTmp := "../resources/configuration.yaml_tmp"
err := os.Rename(configPath, configPathTmp)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
defer func() {
err = os.Rename(configPathTmp, configPath)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
}()
yamlMap := map[string]interface{}{}
buf, err := yaml.Marshal(yamlMap)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
}
err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
}
assert.PanicsWithValue(t, "#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
func() { ParseConfiguration() })
}

View File

@@ -0,0 +1,13 @@
module kubsimulator
go 1.12
require (
github.com/gorilla/mux v1.7.0
github.com/pkg/errors v0.8.1
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.4.0
go.uber.org/atomic v1.5.0
go.uber.org/zap v1.13.0
gopkg.in/yaml.v2 v2.2.4
)

View File

@@ -0,0 +1,174 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

View File

@@ -0,0 +1,30 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 kubernetes
import (
"net/http"
)
func DeletePod(writer http.ResponseWriter, r *http.Request) {
writer.Header().Set("Content-Type", "application/json; charset=UTF-8")
writer.WriteHeader(http.StatusOK)
}

View File

@@ -0,0 +1,56 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 kubernetes
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
)
func Logger(inner http.Handler, name string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
inner.ServeHTTP(w, r)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("Error reading body: %v", err)
http.Error(w, "can't read body", http.StatusBadRequest)
return
}
buffer := new(bytes.Buffer)
_ =json.Compact(buffer, body)
log.Printf(
"%s %s body: %s elapsed: %s",
r.Method,
r.RequestURI,
buffer,
time.Since(start),
)
})
}

View File

@@ -0,0 +1,28 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 kubernetes
type Request struct {
Kind string `json:"kind"`
ApiVersion string `json:"apiVersion"`
}

View File

@@ -0,0 +1,64 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 kubernetes
import (
//"fmt"
"net/http"
"strings"
"github.com/gorilla/mux"
)
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route
func NewRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc
handler = Logger(handler, route.Name)
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
return router
}
var routes = Routes{
Route{
"DeletePod",
strings.ToUpper("Delete"),
"/api/v1/namespaces/{namespace}/pods/{pod}",
DeletePod,
},
}

View File

@@ -0,0 +1,40 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 main
import (
"fmt"
"kubsimulator/configuration"
"kubsimulator/go"
"log"
"net/http"
)
func main() {
config := configuration.ParseConfiguration()
port := config.Http.Port
log.Printf("Server started on port %d", port)
router := kubernetes.NewRouter()
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), router))
}

View File

@@ -0,0 +1,2 @@
http:
port: 59009

View File

@@ -0,0 +1,37 @@
##############################################################################
#
# Copyright (c) 2019 AT&T Intellectual Property.
#
# 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.
#
##############################################################################
FROM nexus3.o-ran-sc.org:10004/o-ran-sc/bldr-ubuntu18-c-go:9-u18.04 as ubuntu
WORKDIR /opt/rmsimulator
COPY . .
ENV PATH=$PATH:/usr/local/go/bin:/usr/lib/go-1.12/bin
RUN apt-get update \
&& apt-get --allow-releaseinfo-change update \
&& apt upgrade -y
RUN go build main.go
FROM ubuntu:18.04
COPY --from=ubuntu /opt/rmsimulator/main /opt/rmsimulator/main
COPY --from=ubuntu /opt/rmsimulator/resources /opt/rmsimulator/resources
WORKDIR /opt/rmsimulator
#CMD mkdir -p resources/conf exec ./xappmock
CMD exec ./main

View File

@@ -0,0 +1,384 @@
# ========================LICENSE_START=================================
# O-RAN-SC
#
# Copyright (C) 2019 AT&T Intellectual Property and Nokia
#
# 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.
# ========================LICENSE_END===================================
# This source code is part of the near-RT RIC (RAN Intelligent Controller)
# platform project (RICP).
swagger: "2.0"
info:
description: "This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound\
\ API."
version: "0.4.0"
title: "Routing Manager"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "rtmgr"
basePath: "/ric/v1"
tags:
- name: "handle"
description: "Available handles"
- name: "health"
description: "Health of the system"
schemes:
- "http"
paths:
/health:
get:
tags:
- "health"
summary: "Retrive the health of Routing Manager"
description: "By performing a GET method on the health resource, the API caller\
\ is able to retrieve the health of Routing Manager"
operationId: "get_health"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
"200":
description: "The health of the system"
schema:
$ref: "#/definitions/health-status"
/handles:
get:
tags:
- "handle"
summary: "Placeholder for further usage"
description: "Placeholder for further usage."
operationId: "get_handles"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
"200":
description: "Dummy response"
/handles/xapp-handle:
post:
tags:
- "handle"
summary: "Provide callback"
description: "By performing a POST method on the xapp-handle resource, the API\
\ caller is able to perform a callback on Routing Manager."
operationId: "provide_xapp_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "xapp-callback-data"
description: "xApp related callback data"
required: true
schema:
$ref: "#/definitions/xapp-callback-data"
x-exportParamName: "XappCallbackData"
responses:
"201":
description: "Callback received"
"400":
description: "Invalid data"
/handles/xapp-subscription-handle:
post:
tags:
- "handle"
summary: "API for updating about new xapp subscription"
description: "By performing a POST method on the xapp-subscription-handle resource,\
\ the API caller is able to update the Routing manager about the creation\
\ of new subscription by an Xapp instance."
operationId: "provide_xapp_subscription_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "xapp-subscription-data"
description: "xApp related subscription data"
required: true
schema:
$ref: "#/definitions/xapp-subscription-data"
x-exportParamName: "XappSubscriptionData"
responses:
"201":
description: "Xapp Subscription data received"
"400":
description: "Invalid data"
delete:
tags:
- "handle"
summary: "API for deleting an xapp subscription"
description: "By performing the delete operation on xapp-subscription-handle\
\ resource, the API caller will be able to update routing manager about the\
\ deletion of an xapp's subscription"
operationId: "delete_xapp_subscription_handle"
consumes:
- "application/json"
parameters:
- in: "body"
name: "xapp-subscription-data"
description: "xApp related subscription data"
required: true
schema:
$ref: "#/definitions/xapp-subscription-data"
x-exportParamName: "XappSubscriptionData"
responses:
"200":
description: "Xapp Subscription deleted"
"204":
description: "Content not found"
/handles/xapp-subscription-handle/{subscription_id}:
put:
tags:
- "handle"
summary: "API for updating the subscriber xApp list"
description: "By performing a PUT method on a xapp-subscription-handle/{subscription_id}\
\ resource, the API caller is able to update the Routing manager about the\
\ list of subscriber xApps related to the subscription denoted by the {subsription_id}."
operationId: "update_xapp_subscription_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "subscription_id"
in: "path"
description: "Subscription ID"
required: true
type: "integer"
format: "uint16"
x-exportParamName: "SubscriptionId"
- in: "body"
name: "xapp-list"
description: "xApp list"
required: true
schema:
$ref: "#/definitions/xapp-list"
x-exportParamName: "XappList"
responses:
"201":
description: "Xapp list received"
"400":
description: "Invalid data"
/handles/e2t:
post:
tags:
- "handle"
summary: "API for establishing platform routes when a new e2t instance gets\
\ added to platform"
description: "E2T updates its FQDN to E2M during its initialisation, hence\
\ after E2M informs routing manager about new E2T instances FQDN. At this\
\ point Routing Mgr would establish platform routes"
operationId: "create_new_e2t_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "e2t-data"
description: "FQDN of the newly joined E2T instance"
required: true
schema:
$ref: "#/definitions/e2t-data"
x-exportParamName: "E2tData"
responses:
"201":
description: "new e2t instance is considered and platform routes are established"
"400":
description: "Invalid data"
delete:
tags:
- "handle"
summary: "API for clearing routes specific to a particular e2T instance"
description: "E2M would monitor E2T instances using its keep alive based mechanism\
\ during this time if an E2T instance is detected to be dead, E2M would distribute\
\ already associated ran's to other available/healthy E2T instances. Here\
\ E2M would share E2T instance address to be removed OR which is unhealthy\
\ and list of RAN instances to be dissociated and an association list which\
\ contains E2T FQDN and associated RAN names"
operationId: "delete_e2t_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "e2t-data"
description: "FQDN of the newly joined E2T instance"
required: true
schema:
$ref: "#/definitions/e2t-delete-data"
x-exportParamName: "E2tData"
responses:
"201":
description: "new e2t instance is considered and platform routes are established"
"400":
description: "Invalid data"
/handles/associate-ran-to-e2t:
post:
tags:
- "handle"
summary: "API for associating a ran to e2t instance"
description: "By performing a POST method on rane2tmapping, the API caller is\
\ able to update the Routing manager about the ran to e2t mapping which would\
\ be finally used to distribute routes to corresponding xApp and E2T instance"
operationId: "associate_ran_to_e2t_handle"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "ran-e2t-list"
description: "ran to e2t mapping"
required: true
schema:
$ref: "#/definitions/ran-e2t-map"
x-exportParamName: "RanE2tList"
responses:
"201":
description: "e2t ran mapping recieved, platform routes"
"400":
description: "Invalid data"
/handles/dissociate-ran:
post:
tags:
- "handle"
summary: "API to dissociate ran from e2t"
description: "By performing a POST method on rane2tmapping, routing manager\
\ will dissociate ran name from e2t instance by updating or clearing routes"
operationId: "dissociate_ran"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "dissociate-list"
description: "list of RAN to dissociate"
required: true
schema:
$ref: "#/definitions/ran-e2t-map"
x-exportParamName: "DissociateList"
responses:
"201":
description: "ran instances disociated"
"400":
description: "Invalid data"
definitions:
health-status:
type: "object"
properties:
status:
type: "string"
enum:
- "healthy"
- "unhealthy"
example:
status: "healthy"
xapp-callback-data:
type: "object"
properties:
id:
type: "string"
event:
type: "string"
version:
type: "integer"
format: "int64"
xApps:
type: "string"
xapp-subscription-data:
type: "object"
required:
- "address"
- "port"
- "subscription_id"
properties:
address:
type: "string"
port:
type: "integer"
format: "uint16"
minimum: 0
maximum: 65535
subscription_id:
type: "integer"
format: "int32"
xapp-list:
type: "array"
items:
$ref: "#/definitions/xapp-element"
xapp-element:
type: "object"
required:
- "address"
- "port"
properties:
address:
type: "string"
port:
type: "integer"
format: "uint16"
minimum: 0
maximum: 65535
ran-e2t-map:
type: "array"
items:
$ref: "#/definitions/ran-e2t-element"
ran-e2t-element:
type: "object"
required:
- "E2TAddress"
properties:
E2TAddress:
type: "string"
ranNamelist:
$ref: "#/definitions/ranNamelist"
ranNamelist:
type: "array"
items:
type: "string"
e2t-data:
type: "object"
required:
- "E2TAddress"
properties:
E2TAddress:
type: "string"
ranNamelist:
$ref: "#/definitions/ranNamelist"
e2t-delete-data:
type: "object"
required:
- "E2TAddress"
properties:
E2TAddress:
type: "string"
ranNamelistTobeDissociated:
$ref: "#/definitions/ranNamelist"
ranAssocList:
$ref: "#/definitions/ran-e2t-map"
externalDocs:
description: "Routing Manager"
url: "http://placeholder"

View File

@@ -0,0 +1,57 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 configuration
import (
"fmt"
"github.com/spf13/viper"
)
type Configuration struct {
Http struct {
Port int
}
}
func ParseConfiguration() *Configuration{
viper.SetConfigType("yaml")
viper.SetConfigName("configuration")
viper.AddConfigPath("RoutingManagerSimulator/resources/")
viper.AddConfigPath("./resources/") //For production
viper.AddConfigPath("../resources/") //For test under Docker
viper.AddConfigPath("../../resources/") //For test under Docker
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Sprintf("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err))
}
config := Configuration{}
config.fillHttpConfig(viper.Sub("http"))
return &config
}
func (c *Configuration)fillHttpConfig(httpConfig *viper.Viper) {
if httpConfig == nil {
panic(fmt.Sprintf("#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n"))
}
c.Http.Port = httpConfig.GetInt("port")
}

View File

@@ -0,0 +1,76 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 configuration
import (
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"testing"
)
func TestParseConfigurationSuccess(t *testing.T) {
config := ParseConfiguration()
assert.Equal(t, 12020, config.Http.Port)
}
func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
configPath := "../resources/configuration.yaml"
configPathTmp := "../resources/configuration.yaml_tmp"
err := os.Rename(configPath, configPathTmp)
if err != nil {
t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
defer func() {
err = os.Rename(configPathTmp, configPath)
if err != nil {
t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
}()
assert.Panics(t, func() { ParseConfiguration() })
}
func TestHttpConfigNotFoundFailure(t *testing.T) {
configPath := "../resources/configuration.yaml"
configPathTmp := "../resources/configuration.yaml_tmp"
err := os.Rename(configPath, configPathTmp)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
defer func() {
err = os.Rename(configPathTmp, configPath)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
}
}()
yamlMap := map[string]interface{}{}
buf, err := yaml.Marshal(yamlMap)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
}
err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
if err != nil {
t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
}
assert.PanicsWithValue(t, "#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n",
func() { ParseConfiguration() })
}

View File

@@ -0,0 +1,13 @@
module rmsimulator
go 1.12
require (
github.com/gorilla/mux v1.7.0
github.com/pkg/errors v0.8.1
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.4.0
go.uber.org/atomic v1.5.0
go.uber.org/zap v1.13.0
gopkg.in/yaml.v2 v2.2.4
)

View File

@@ -0,0 +1,174 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

View File

@@ -0,0 +1,25 @@
# Go API Server for swagger
This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
## Overview
This server was generated by the [swagger-codegen]
(https://github.com/swagger-api/swagger-codegen) project.
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
-
To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
- API version: 0.4.0
- Build date: 2019-12-30T10:52:31.803Z
### Running the server
To run the server, follow these simple steps:
```
go run main.go
```

View File

@@ -0,0 +1,79 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
import (
"net/http"
)
func AssociateRanToE2tHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func CreateNewE2tHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func DeleteE2tHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func DeleteXappSubscriptionHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func DissociateRan(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func GetHandles(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func ProvideXappHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func ProvideXappSubscriptionHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func UpdateXappSubscriptionHandle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}

View File

@@ -0,0 +1,38 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
import (
"net/http"
)
func GetHealth(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}

View File

@@ -0,0 +1,64 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
)
func Logger(inner http.Handler, name string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
inner.ServeHTTP(w, r)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("Error reading body: %v", err)
http.Error(w, "can't read body", http.StatusBadRequest)
return
}
buffer := new(bytes.Buffer)
_ =json.Compact(buffer, body)
log.Printf(
"%s %s body: %s elapsed: %s",
r.Method,
r.RequestURI,
buffer,
time.Since(start),
)
})
}

View File

@@ -0,0 +1,36 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type E2tData struct {
E2TAddress string `json:"E2TAddress"`
RanNamelist *RanNamelist `json:"ranNamelist,omitempty"`
}

View File

@@ -0,0 +1,38 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type E2tDeleteData struct {
E2TAddress string `json:"E2TAddress"`
RanNamelistTobeDissociated *RanNamelist `json:"ranNamelistTobeDissociated,omitempty"`
RanAssocList *RanE2tMap `json:"ranAssocList,omitempty"`
}

View File

@@ -0,0 +1,34 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type HealthStatus struct {
Status string `json:"status,omitempty"`
}

View File

@@ -0,0 +1,36 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type RanE2tElement struct {
E2TAddress string `json:"E2TAddress"`
RanNamelist *RanNamelist `json:"ranNamelist,omitempty"`
}

View File

@@ -0,0 +1,32 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type RanE2tMap struct {
}

View File

@@ -0,0 +1,32 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type RanNamelist struct {
}

View File

@@ -0,0 +1,40 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type XappCallbackData struct {
Id string `json:"id,omitempty"`
Event string `json:"event,omitempty"`
Version int64 `json:"version,omitempty"`
XApps string `json:"xApps,omitempty"`
}

View File

@@ -0,0 +1,36 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type XappElement struct {
Address string `json:"address"`
Port int32 `json:"port"`
}

View File

@@ -0,0 +1,32 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type XappList struct {
}

View File

@@ -0,0 +1,38 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
type XappSubscriptionData struct {
Address string `json:"address"`
Port int32 `json:"port"`
SubscriptionId int32 `json:"subscription_id"`
}

View File

@@ -0,0 +1,146 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package swagger
import (
"fmt"
"net/http"
"strings"
"github.com/gorilla/mux"
)
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route
func NewRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc
handler = Logger(handler, route.Name)
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
return router
}
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World!")
}
var routes = Routes{
Route{
"Index",
"GET",
"/ric/v1/",
Index,
},
Route{
"AssociateRanToE2tHandle",
strings.ToUpper("Post"),
"/ric/v1/handles/associate-ran-to-e2t",
AssociateRanToE2tHandle,
},
Route{
"CreateNewE2tHandle",
strings.ToUpper("Post"),
"/ric/v1/handles/e2t",
CreateNewE2tHandle,
},
Route{
"DeleteE2tHandle",
strings.ToUpper("Delete"),
"/ric/v1/handles/e2t",
DeleteE2tHandle,
},
Route{
"DeleteXappSubscriptionHandle",
strings.ToUpper("Delete"),
"/ric/v1/handles/xapp-subscription-handle",
DeleteXappSubscriptionHandle,
},
Route{
"DissociateRan",
strings.ToUpper("Post"),
"/ric/v1/handles/dissociate-ran",
DissociateRan,
},
Route{
"GetHandles",
strings.ToUpper("Get"),
"/ric/v1/handles",
GetHandles,
},
Route{
"ProvideXappHandle",
strings.ToUpper("Post"),
"/ric/v1/handles/xapp-handle",
ProvideXappHandle,
},
Route{
"ProvideXappSubscriptionHandle",
strings.ToUpper("Post"),
"/ric/v1/handles/xapp-subscription-handle",
ProvideXappSubscriptionHandle,
},
Route{
"UpdateXappSubscriptionHandle",
strings.ToUpper("Put"),
"/ric/v1/handles/xapp-subscription-handle/{subscription_id}",
UpdateXappSubscriptionHandle,
},
Route{
"GetHealth",
strings.ToUpper("Get"),
"/ric/v1/health",
GetHealth,
},
}

View File

@@ -0,0 +1,49 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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).
/*
* Routing Manager
*
* This is the Swagger/OpenAPI 2.0 definition of Routing Manager's Northbound API.
*
* API version: 0.4.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package main
import (
"fmt"
"log"
"net/http"
"rmsimulator/configuration"
"rmsimulator/go"
)
func main() {
config := configuration.ParseConfiguration()
port := config.Http.Port
log.Printf("Server started on port %d", port)
router := swagger.NewRouter()
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), router))
}

View File

@@ -0,0 +1,2 @@
http:
port: 12020

View File

@@ -0,0 +1,48 @@
##############################################################################
#
# Copyright (c) 2019 AT&T Intellectual Property.
#
# 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).
#
FROM nexus3.o-ran-sc.org:10004/bldr-ubuntu16-c-go:2-u16.04-nng as ubuntu
WORKDIR /opt/xappmock
COPY . .
ENV PATH=$PATH:/usr/local/go/bin:/usr/lib/go-1.12/bin
# Install RMr library and dev files
RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr_1.10.0_amd64.deb/download.deb
RUN dpkg -i rmr_1.10.0_amd64.deb
RUN wget --content-disposition https://packagecloud.io/o-ran-sc/staging/packages/debian/stretch/rmr-dev_1.10.0_amd64.deb/download.deb
RUN dpkg -i rmr-dev_1.10.0_amd64.deb
RUN go build main/xappmock.go
FROM ubuntu:16.04
COPY --from=ubuntu /opt/xappmock/xappmock /opt/xappmock/xappmock
COPY --from=ubuntu /opt/xappmock/resources /opt/xappmock/resources
COPY --from=ubuntu /usr/local/lib/librmr_nng.so.1 /usr/local/lib/librmr_nng.so.1
COPY --from=ubuntu /usr/local/lib/libnng.so.1 /usr/local/lib/libnng.so.1
WORKDIR /opt/xappmock
ENV LD_LIBRARY_PATH=/usr/local/lib
ENV RMR_SEED_RT=resources/router.txt
ENV RMR_PORT=5001
#CMD mkdir -p resources/conf exec ./xappmock
CMD mkdir -p resources/conf && exec /bin/bash

View File

@@ -0,0 +1,405 @@
// This source code is part of the near-RT RIC (RAN Intelligent Controller)
// platform project (RICP).
// Copyright 2019 Nokia
//
// 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 dispatcher
import (
"context"
"fmt"
"github.com/pkg/errors"
"reflect"
"sync"
"time"
"xappmock/enums"
"xappmock/logger"
"xappmock/models"
"xappmock/rmr"
"xappmock/sender"
)
// Id -> Command
var configuration = make(map[string]*models.JsonCommand)
// Rmr Message Id -> Command
var waitForRmrMessageType = make(map[int]*models.JsonCommand)
func addRmrMessageToWaitFor(rmrMessageToWaitFor string, command models.JsonCommand) error {
rmrMsgId, err := rmr.MessageIdToUint(rmrMessageToWaitFor)
if err != nil {
return errors.New(fmt.Sprintf("invalid rmr message id: %s", rmrMessageToWaitFor))
}
waitForRmrMessageType[int(rmrMsgId)] = &command
return nil
}
type Dispatcher struct {
rmrService *rmr.Service
processResult models.ProcessResult
logger *logger.Logger
jsonSender *sender.JsonSender
}
func (d *Dispatcher) GetProcessResult() models.ProcessResult {
return d.processResult
}
func New(logger *logger.Logger, rmrService *rmr.Service, jsonSender *sender.JsonSender) *Dispatcher {
return &Dispatcher{
rmrService: rmrService,
logger: logger,
jsonSender: jsonSender,
}
}
func (d *Dispatcher) JsonCommandsDecoderCB(cmd models.JsonCommand) error {
if len(cmd.Id) == 0 {
return errors.New(fmt.Sprintf("invalid cmd, no id"))
}
configuration[cmd.Id] = &cmd
return nil
// if len(cmd.ReceiveCommandId) == 0 {
// return nil
// }
//
// return addRmrMessageToWaitFor(cmd.ReceiveCommandId, cmd)
}
func (d *Dispatcher) sendNoRepeat(command models.JsonCommand) error {
if enums.CommandAction(command.Action) == enums.SendRmrMessage && d.processResult.StartTime == nil {
now := time.Now()
d.processResult.StartTime = &now
}
err := d.jsonSender.SendJsonRmrMessage(command, nil, d.rmrService)
if err != nil {
d.logger.Errorf("#Dispatcher.sendNoRepeat - error sending rmr message: %s", err)
d.processResult.Err = err
d.processResult.Stats.SentErrorCount.Inc()
return err
}
d.processResult.Stats.SentCount.Inc()
return nil
}
func (d *Dispatcher) sendWithRepeat(ctx context.Context, command models.JsonCommand) {
if enums.CommandAction(command.Action) == enums.SendRmrMessage && d.processResult.StartTime == nil {
now := time.Now()
d.processResult.StartTime = &now
}
for repeatCount := command.RepeatCount; repeatCount > 0; repeatCount-- {
select {
case <-ctx.Done():
return
default:
}
err := d.jsonSender.SendJsonRmrMessage(command, nil, d.rmrService)
if err != nil {
d.logger.Errorf("#Dispatcher.sendWithRepeat - error sending rmr message: %s", err)
d.processResult.Stats.SentErrorCount.Inc()
continue
}
d.processResult.Stats.SentCount.Inc()
time.Sleep(time.Duration(command.RepeatDelayInMs) * time.Millisecond)
}
}
func getReceiveRmrMessageType(receiveCommandId string) (string, error) {
command, ok := configuration[receiveCommandId]
if !ok {
return "", errors.New(fmt.Sprintf("invalid receive command id: %s", receiveCommandId))
}
if len(command.RmrMessageType) == 0 {
return "", errors.New(fmt.Sprintf("missing RmrMessageType for command id: %s", receiveCommandId))
}
return command.RmrMessageType, nil
}
func (d *Dispatcher) sendHandler(ctx context.Context, sendAndReceiveWg *sync.WaitGroup, command models.JsonCommand) {
defer sendAndReceiveWg.Done()
var listenAndHandleWg sync.WaitGroup
if len(command.ReceiveCommandId) > 0 {
rmrMessageToWaitFor, err := getReceiveRmrMessageType(command.ReceiveCommandId)
if err != nil {
d.processResult.Err = err
return
}
err = addRmrMessageToWaitFor(rmrMessageToWaitFor, command)
if err != nil {
d.processResult.Err = err
return
}
listenAndHandleWg.Add(1)
go d.listenAndHandle(ctx, &listenAndHandleWg, command)
}
if command.RepeatCount == 0 {
err := d.sendNoRepeat(command)
if err != nil {
return
}
} else {
d.sendWithRepeat(ctx, command)
}
if len(command.ReceiveCommandId) > 0 {
listenAndHandleWg.Wait()
}
}
func (d *Dispatcher) receiveHandler(ctx context.Context, sendAndReceiveWg *sync.WaitGroup, command models.JsonCommand) {
defer sendAndReceiveWg.Done()
err := addRmrMessageToWaitFor(command.RmrMessageType, command)
if err != nil {
d.processResult.Err = err
return
}
var listenAndHandleWg sync.WaitGroup
listenAndHandleWg.Add(1) // this is due to the usage of listenAndHandle as a goroutine in the sender case
d.listenAndHandle(ctx, &listenAndHandleWg, command)
}
func getMergedCommand(cmd *models.JsonCommand) (models.JsonCommand, error) {
var command models.JsonCommand
if len(cmd.Id) == 0 {
return command, errors.New(fmt.Sprintf("invalid command, no id"))
}
command = *cmd
conf, ok := configuration[cmd.Id]
if ok {
command = *conf
mergeConfigurationAndCommand(&command, cmd)
}
return command, nil
}
func (d *Dispatcher) ProcessJsonCommand(ctx context.Context, cmd *models.JsonCommand) {
command, err := getMergedCommand(cmd)
if err != nil {
d.processResult.Err = err
return
}
var sendAndReceiveWg sync.WaitGroup
commandAction := enums.CommandAction(command.Action)
switch commandAction {
case enums.SendRmrMessage:
sendAndReceiveWg.Add(1)
go d.sendHandler(ctx, &sendAndReceiveWg, command)
case enums.ReceiveRmrMessage:
sendAndReceiveWg.Add(1)
go d.receiveHandler(ctx, &sendAndReceiveWg, command)
default:
d.processResult = models.ProcessResult{Err: errors.New(fmt.Sprintf("invalid command action %s", command.Action))}
return
}
sendAndReceiveWg.Wait()
}
func getResponseCommand(command models.JsonCommand) (*models.JsonCommand, error) {
responseCommand, ok := configuration[command.SendCommandId]
if !ok {
return nil, errors.New(fmt.Sprintf("invalid SendCommandId %s", command.SendCommandId))
}
return responseCommand, nil
}
func (d *Dispatcher) listenAndHandleNoRepeat(ctx context.Context, command models.JsonCommand) {
for {
select {
case <-ctx.Done():
return
default:
}
mbuf, err := d.rmrService.RecvMessage()
if err != nil {
d.logger.Errorf("#Dispatcher.listenAndHandleNoRepeat - error receiving message: %s", err)
d.processResult.Err = err
d.processResult.Stats.ReceivedErrorCount.Inc()
return
}
if enums.CommandAction(command.Action) == enums.ReceiveRmrMessage && d.processResult.StartTime == nil {
now := time.Now()
d.processResult.StartTime = &now
}
messageInfo := models.NewMessageInfo(mbuf.MType, mbuf.Meid, mbuf.Payload, mbuf.XAction)
_, ok := waitForRmrMessageType[mbuf.MType]
if !ok {
d.logger.Infof("#Dispatcher.listenAndHandleNoRepeat - received unexpected msg: %s", messageInfo)
d.processResult.Stats.ReceivedUnexpectedCount.Inc()
continue
}
d.logger.Infof("#Dispatcher.listenAndHandleNoRepeat - received expected msg: %s", messageInfo)
d.processResult.Stats.ReceivedExpectedCount.Inc()
if len(command.SendCommandId) > 0 {
responseCommand, err := getResponseCommand(command)
if err != nil {
d.processResult.Err = err
return
}
_ = d.sendNoRepeat(*responseCommand)
}
return
}
}
func (d *Dispatcher) listenAndHandleWithRepeat(ctx context.Context, command models.JsonCommand) {
var responseCommand *models.JsonCommand
if len(command.SendCommandId) > 0 {
var err error
responseCommand, err = getResponseCommand(command)
if err != nil {
d.processResult.Err = err
return
}
}
for d.processResult.Stats.ReceivedExpectedCount.Load() < int32(command.RepeatCount) {
select {
case <-ctx.Done():
return
default:
}
mbuf, err := d.rmrService.RecvMessage()
if err != nil {
d.logger.Errorf("#Dispatcher.listenAndHandleWithRepeat - error receiving message: %s", err)
d.processResult.Stats.ReceivedErrorCount.Inc()
continue
}
if enums.CommandAction(command.Action) == enums.ReceiveRmrMessage && d.processResult.StartTime == nil {
now := time.Now()
d.processResult.StartTime = &now
}
messageInfo := models.NewMessageInfo(mbuf.MType, mbuf.Meid, mbuf.Payload, mbuf.XAction)
_, ok := waitForRmrMessageType[mbuf.MType]
if !ok {
d.logger.Infof("#Dispatcher.listenAndHandleWithRepeat - received unexpected msg: %s", messageInfo)
d.processResult.Stats.ReceivedUnexpectedCount.Inc()
continue
}
d.logger.Infof("#Dispatcher.listenAndHandleWithRepeat - received expected msg: %s", messageInfo)
d.processResult.Stats.ReceivedExpectedCount.Inc()
if responseCommand != nil {
_ = d.sendNoRepeat(*responseCommand) // TODO: goroutine? + error handling
}
}
}
func (d *Dispatcher) listenAndHandle(ctx context.Context, listenAndHandleWg *sync.WaitGroup, command models.JsonCommand) {
defer listenAndHandleWg.Done()
if command.RepeatCount == 0 {
d.listenAndHandleNoRepeat(ctx, command)
return
}
d.listenAndHandleWithRepeat(ctx, command)
}
func mergeConfigurationAndCommand(conf *models.JsonCommand, cmd *models.JsonCommand) {
nFields := reflect.Indirect(reflect.ValueOf(cmd)).NumField()
for i := 0; i < nFields; i++ {
if fieldValue := reflect.Indirect(reflect.ValueOf(cmd)).Field(i); fieldValue.IsValid() {
switch fieldValue.Kind() {
case reflect.String:
if fieldValue.Len() > 0 {
reflect.Indirect(reflect.ValueOf(conf)).Field(i).Set(fieldValue)
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if fieldValue.Int() != 0 {
reflect.Indirect(reflect.ValueOf(conf)).Field(i).Set(fieldValue)
}
case reflect.Bool:
if fieldValue.Bool() {
reflect.Indirect(reflect.ValueOf(conf)).Field(i).Set(fieldValue)
}
case reflect.Float64, reflect.Float32:
if fieldValue.Float() != 0 {
reflect.Indirect(reflect.ValueOf(conf)).Field(i).Set(fieldValue)
}
default:
reflect.Indirect(reflect.ValueOf(conf)).Field(i).Set(fieldValue)
}
}
}
}

View File

@@ -0,0 +1,28 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 enums
type CommandAction string
const (
SendRmrMessage CommandAction = "send"
ReceiveRmrMessage CommandAction = "receive"
)

View File

@@ -0,0 +1,59 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 frontend
import (
"github.com/pkg/errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func ProcessConfigurationFile(resourcesFolder, inputFolder, suffix string, processor func(data []byte) error) error {
cwd, err := os.Getwd()
if err != nil {
return errors.New(err.Error())
}
inputDir := filepath.Join(cwd, resourcesFolder, inputFolder)
files, err := ioutil.ReadDir(inputDir)
if err != nil {
return errors.New(err.Error())
}
for _, file := range files {
if file.Mode().IsRegular() && strings.HasSuffix(strings.ToLower(file.Name()), suffix) {
filespec := filepath.Join(inputDir, file.Name())
data, err := ioutil.ReadFile(filespec)
if err != nil {
return errors.New(err.Error())
}
err = processor(data)
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -0,0 +1,57 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 frontend
import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io"
"xappmock/models"
)
func DecodeJsonCommand(data []byte) (*models.JsonCommand, error) {
dec := json.NewDecoder(bytes.NewReader(data))
var cmd models.JsonCommand
if err := dec.Decode(&cmd); err != nil && err != io.EOF {
return nil, errors.New(err.Error())
}
return &cmd, nil
}
func JsonCommandsDecoder(data []byte, processor func(models.JsonCommand) error) error {
dec := json.NewDecoder(bytes.NewReader(data))
for {
var commands []models.JsonCommand
if err := dec.Decode(&commands); err == io.EOF {
break
} else if err != nil {
return errors.New(err.Error())
}
for i, cmd := range commands {
if err := processor(cmd); err != nil {
return errors.New(fmt.Sprintf("processing error at #%d, %s", i, err))
}
}
}
return nil
}

View File

@@ -0,0 +1,9 @@
module xappmock
go 1.12
require (
github.com/pkg/errors v0.8.1
go.uber.org/atomic v1.5.0
go.uber.org/zap v1.13.0
)

View File

@@ -0,0 +1,57 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c h1:IGkKhmfzcztjm6gYkykvu/NiS8kaqbCWAEWWAyf8J5U=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

View File

@@ -0,0 +1,187 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 logger
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"strings"
"time"
)
type Logger struct {
Logger *zap.Logger
}
// Copied from zap logger
//
// A Level is a logging priority. Higher levels are more important.
type LogLevel int8
const (
// DebugLevel logs are typically voluminous, and are usually disabled in
// production.
DebugLevel LogLevel = iota - 1
// InfoLevel is the default logging priority.
InfoLevel
// WarnLevel logs are more important than Info, but don't need individual
// human review.
WarnLevel
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
ErrorLevel
// DPanicLevel logs are particularly important errors. In development the
// logger panics after writing the message.
DPanicLevel
// PanicLevel logs a message, then panics.
PanicLevel
// FatalLevel logs a message, then calls os.Exit(1).
FatalLevel
_minLevel = DebugLevel
_maxLevel = FatalLevel
)
var logLevelTokenToLevel = map[string] LogLevel {
"debug" : DebugLevel,
"info": InfoLevel,
"warn": WarnLevel,
"error": ErrorLevel,
"dpanic": DPanicLevel,
"panic": PanicLevel,
"fatal": FatalLevel,
}
func LogLevelTokenToLevel(level string) (LogLevel, bool) {
if level, ok := logLevelTokenToLevel[strings.TrimSpace(strings.ToLower(level))];ok {
return level, true
}
return _maxLevel+1, false
}
func InitLogger(requested LogLevel) (*Logger, error) {
var logger *zap.Logger
var err error
switch requested {
case DebugLevel:
logger, err = initLoggerByLevel(zapcore.DebugLevel)
case InfoLevel:
logger, err = initLoggerByLevel(zapcore.InfoLevel)
case WarnLevel:
logger, err = initLoggerByLevel(zapcore.WarnLevel)
case ErrorLevel:
logger, err = initLoggerByLevel(zapcore.ErrorLevel)
case DPanicLevel:
logger, err = initLoggerByLevel(zapcore.DPanicLevel)
case PanicLevel:
logger, err = initLoggerByLevel(zapcore.PanicLevel)
case FatalLevel:
logger, err = initLoggerByLevel(zapcore.FatalLevel)
default:
err = fmt.Errorf("Invalid logging Level :%d",requested)
}
if err != nil {
return nil, err
}
return &Logger{Logger:logger}, nil
}
func(l *Logger)Sync() error {
l.Debugf("#logger.Sync - Going to flush buffered log")
return l.Logger.Sync()
}
func (l *Logger)Infof(formatMsg string, a ...interface{}) {
if l.InfoEnabled() {
msg := fmt.Sprintf(formatMsg, a...)
l.Logger.Info(msg, zap.Any("mdc", l.getTimeStampMdc()))
}
}
func (l *Logger)Debugf(formatMsg string, a ...interface{}) {
if l.DebugEnabled(){
msg := fmt.Sprintf(formatMsg, a...)
l.Logger.Debug(msg, zap.Any("mdc", l.getTimeStampMdc()))
}
}
func (l *Logger)Errorf(formatMsg string, a ...interface{}) {
msg := fmt.Sprintf(formatMsg, a...)
l.Logger.Error(msg, zap.Any("mdc", l.getTimeStampMdc()))
}
func (l *Logger)Warnf(formatMsg string, a ...interface{}) {
msg := fmt.Sprintf(formatMsg, a...)
l.Logger.Warn(msg, zap.Any("mdc", l.getTimeStampMdc()))
}
func (l *Logger) getTimeStampMdc() map[string]string {
timeStr := time.Now().Format("2006-01-02 15:04:05.000")
mdc := map[string]string{"time": timeStr}
return mdc
}
func (l *Logger)InfoEnabled()bool{
return l.Logger.Core().Enabled(zap.InfoLevel)
}
func (l *Logger)DebugEnabled()bool{
return l.Logger.Core().Enabled(zap.DebugLevel)
}
func (l *Logger)DPanicf(formatMsg string, a ...interface{}) {
msg := fmt.Sprintf(formatMsg, a...)
l.Logger.DPanic(msg, zap.Any("mdc", l.getTimeStampMdc()))
}
func initLoggerByLevel(l zapcore.Level) (*zap.Logger, error) {
cfg := zap.Config{
Encoding: "json",
Level: zap.NewAtomicLevelAt(l),
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
EncoderConfig: zapcore.EncoderConfig{
MessageKey: "msg",
LevelKey: "crit",
EncodeLevel: zapcore.CapitalLevelEncoder,
TimeKey: "ts",
EncodeTime: epochMillisIntegerTimeEncoder,
CallerKey: "id",
EncodeCaller: xAppMockCallerEncoder,
},
}
return cfg.Build()
}
func xAppMockCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString("xAppMock")
}
func epochMillisIntegerTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
nanos := t.UnixNano()
millis := int64(nanos) / int64(time.Millisecond)
enc.AppendInt64(millis)
}

View File

@@ -0,0 +1,119 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"strconv"
"time"
"xappmock/dispatcher"
"xappmock/frontend"
"xappmock/logger"
"xappmock/rmr"
"xappmock/sender"
)
const (
ENV_RMR_PORT = "RMR_PORT"
RMR_PORT_DEFAULT = 5001
)
var rmrService *rmr.Service
func main() {
logLevel, _ := logger.LogLevelTokenToLevel("info")
logger, err := logger.InitLogger(logLevel)
if err != nil {
fmt.Printf("#app.main - failed to initialize logger, error: %s", err)
os.Exit(1)
}
var rmrContext *rmr.Context
var rmrConfig = rmr.Config{Port: RMR_PORT_DEFAULT, MaxMsgSize: rmr.RMR_MAX_MSG_SIZE, MaxRetries: 10, Flags: 0}
if port, err := strconv.ParseUint(os.Getenv(ENV_RMR_PORT), 10, 16); err == nil {
rmrConfig.Port = int(port)
} else {
logger.Infof("#main - %s: %s, using default (%d).", ENV_RMR_PORT, err, RMR_PORT_DEFAULT)
}
rmrService = rmr.NewService(rmrConfig, rmrContext)
jsonSender := sender.NewJsonSender(logger)
dispatcherDesc := dispatcher.New(logger, rmrService, jsonSender)
/* Load configuration file*/
err = frontend.ProcessConfigurationFile("resources", "conf", ".json",
func(data []byte) error {
return frontend.JsonCommandsDecoder(data, dispatcherDesc.JsonCommandsDecoderCB)
})
if err != nil {
logger.Errorf("#main - processing error: %s", err)
os.Exit(1)
}
logger.Infof("#main - xApp Mock is up and running...")
flag.Parse()
cmd := flag.Arg(0) /*first remaining argument after flags have been processed*/
command, err := frontend.DecodeJsonCommand([]byte(cmd))
if err != nil {
logger.Errorf("#main - command decoding error: %s", err)
rmrService.CloseContext()
logger.Infof("#main - xApp Mock is down")
return
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
ctx, cancel := context.WithCancel(context.Background())
go func() {
oscall := <-c
logger.Infof("system call:%+v", oscall)
cancel()
rmrService.CloseContext()
}()
dispatcherDesc.ProcessJsonCommand(ctx, command)
pr := dispatcherDesc.GetProcessResult()
if pr.Err != nil {
logger.Errorf("#main - command processing Error: %s", pr.Err)
}
if pr.StartTime != nil {
processElapsedTimeInMs := float64(time.Since(*pr.StartTime)) / float64(time.Millisecond)
logger.Infof("#main - processing (sending/receiving) messages took %.2f ms", processElapsedTimeInMs)
}
logger.Infof("#main - process stats: %s", pr.Stats)
rmrService.CloseContext() // TODO: called twice
logger.Infof("#main - xApp Mock is down")
}

View File

@@ -0,0 +1,38 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 models
type JsonCommand struct {
Id string
RmrMessageType string
SendCommandId string
ReceiveCommandId string
TransactionId string
RanName string
RanIp string
RanPort int
PayloadHeader string
PackedPayload string
Payload string
Action string
RepeatCount int
RepeatDelayInMs int
}

View File

@@ -0,0 +1,51 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 models
import (
"fmt"
"time"
)
// TODO: message command id / source / dest
type MessageInfo struct {
MessageTimestamp int64 `json:"messageTimestamp"`
MessageType int `json:"messageType"`
Meid string `json:"meid"`
Payload []byte `json:"payload"`
TransactionId string `json:"transactionId"`
}
func NewMessageInfo(messageType int, meid string, payload []byte, transactionId []byte) MessageInfo {
return MessageInfo{
MessageTimestamp: time.Now().Unix(),
MessageType: messageType,
Meid: meid,
Payload: payload,
TransactionId: string(transactionId),
}
}
func (mi MessageInfo) String() string {
return fmt.Sprintf("message timestamp: %d | message type: %d | meid: %s | payload: %x | transaction id: %s",
mi.MessageTimestamp, mi.MessageType, mi.Meid, mi.Payload, mi.TransactionId)
}

View File

@@ -0,0 +1,46 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 models
import (
"fmt"
"go.uber.org/atomic"
"time"
)
type ProcessStats struct {
SentCount atomic.Int32
SentErrorCount atomic.Int32
ReceivedExpectedCount atomic.Int32
ReceivedUnexpectedCount atomic.Int32
ReceivedErrorCount atomic.Int32
}
type ProcessResult struct {
StartTime *time.Time
Stats ProcessStats
Err error
}
func (ps ProcessStats) String() string {
return fmt.Sprintf("sent messages: %d | send errors: %d | expected received messages: %d | unexpected received messages: %d | receive errors: %d",
ps.SentCount, ps.SentErrorCount, ps.ReceivedExpectedCount, ps.ReceivedUnexpectedCount, ps.ReceivedErrorCount)
}

View File

@@ -0,0 +1,75 @@
[
{
"id": "X2_SETUP_REQUEST",
"rmrMessageType": "10060",
"transactionId": "e2e$",
"payloadHeader": "$ranIp|$ranPort|$ranName|#packedPayload|",
"packedPayload": "0006002a000002001500080013302300fffff000140017000001f700133023fffff0000000133023000000000001"
},
{
"id": "X2_SETUP_RESPONSE",
"rmrMessageType": "10061",
"packedPayload": "2006002a000002001500080002f82900007ab000140017000000630002f8290007ab00102002f829000001000133"
},
{
"id": "RIC_SUBSCRIPTION_REQUEST",
"rmrMessageType": "12010",
"transactionId": "e2e$",
"packedPayload": "00c9002b000003ea7e0005004eec0182ea6300020001ea810015000a0011121300212224264000ea6b000420000000"
},
{
"id": "RIC_SUBSCRIPTION_RESPONSE",
"rmrMessageType": "12011",
"transactionId": "e2e$",
"packedPayload": "20c9001d000003ea7e0005004eec0182ea6300020001ea6c000700ea6d40020000"
},
{
"id": "RIC_SUBSCRIPTION_FAILURE",
"rmrMessageType": "12012",
"transactionId": "e2e$",
"packedPayload": "40c9001f000003ea7e00050000010001ea6300020000ea6e000908ea6f400400014100"
},
{
"id": "RIC_SUBSCRIPTION_DELETE_REQUEST",
"rmrMessageType": "12020",
"transactionId": "e2e$",
"packedPayload": "00ca0012000002ea7e0005004eec0182ea6300020001"
},
{
"id": "RIC_SUBSCRIPTION_DELETE_RESPONSE",
"rmrMessageType": "12021",
"transactionId": "e2e$",
"packedPayload": "20ca0012000002ea7e0005004eec0182ea6300020001"
},
{
"id": "RIC_INDICATION",
"rmrMessageType": "12050"
},
{
"id": "RESOURCE_STATUS_REQUEST",
"rmrMessageType": "10090",
"transactionId": "e2e$",
"packedPayload": "0009003c0000080027000300000e001c00010000260004fe000000001d400d00001f4008000a0b0cabcd8000001e4001000040400100006d4001000091400100"
},
{
"id": "RESOURCE_STATUS_RESPONSE",
"rmrMessageType": "10091",
"transactionId": "e2e$",
"packedPayload": "20090065000003002700030000000028000300004a00414050000042404b4013302302b030a2800043400700020000000a000043400700040000000a000043400700080000000a000043400700200000000a000043400700400000000a000043400700800000000a00"
},
{
"id": "RESOURCE_STATUS_FAILURE",
"rmrMessageType": "10092",
"transactionId": "e2e$",
"packedPayload": "400900320000040027000300000e0028000300000c00054001620044401800004540130002f8290007ab500000434006000000000740"
},
{
"id": "RESOURCE_STATUS_UPDATE",
"rmrMessageType": "10090"
},
{
"id": "LOAD_INFORMATION",
"rmrMessageType": "10020"
}
]

View File

@@ -0,0 +1,29 @@
newrt|start
rte|10060|10.0.2.15:38000
rte|10360|10.0.2.15:38000
rte|10070|10.0.2.15:38000
rte|10071|10.0.2.15:3801
rte|10061|10.0.2.15:3801
rte|10361|10.0.2.15:3801
rte|10062|10.0.2.15:3801
rte|10362|10.0.2.15:3801
rte|1080|10.0.2.15:3801
rte|10020|10.0.2.15:5557
rte|10370|10.0.2.15:3801
rte|10371|10.0.2.15:38000
rte|10372|10.0.2.15:38000
rte|10080|10.0.2.15:3801
rte|10081|10.0.2.15:38000
rte|10082|10.0.2.15:38000
rte|1100|10.0.2.15:3801
rte|1090|10.0.2.15:38000
rte|1200|10.0.2.15:4801
rte|1210|10.0.2.15:4801
rte|1220|10.0.2.15:4801
rte|10090|10.0.2.15:38000
rte|12010|10.0.2.15:38000
rte|12011|10.0.2.15:5555
rte|12020|10.0.2.15:38000
rte|10091|10.0.2.15:4801
rte|10092|10.0.2.15:4801
newrt|end

View File

@@ -0,0 +1 @@
20060043000002001500080002f82900007a8000140030010000630002f8290007ab50102002f8290000010001330000640002f9290007ac50203202f82902f929000002000344

View File

@@ -0,0 +1,106 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 rmr
// #cgo LDFLAGS: -L/usr/local/lib -lrmr_nng -lnng
// #include <rmr/rmr.h>
// #include <stdlib.h>
import "C"
import (
"fmt"
"github.com/pkg/errors"
"time"
"unsafe"
)
func (*Context) Init(port string, maxMsgSize int, maxRetries int, flags int) *Messenger {
pp := C.CString(port)
defer C.free(unsafe.Pointer(pp))
ctx := NewContext(maxMsgSize, maxRetries, flags, C.rmr_init(pp, C.int(maxMsgSize), C.int(flags)))
start := time.Now()
for !ctx.IsReady() {
time.Sleep(time.Second)
if time.Since(start) >= time.Minute {
start = time.Now()
}
}
// Configure the rmr to make rounds of attempts to send a message before notifying the application that it should retry.
// Each round is about 1000 attempts with a short sleep between each round.
C.rmr_set_stimeout(ctx.RmrCtx, C.int(0))
r := Messenger(ctx)
return &r
}
func (ctx *Context) SendMsg(msg *MBuf) (*MBuf, error) {
allocatedCMBuf, err := ctx.getAllocatedCRmrMBuf(msg, ctx.MaxMsgSize)
if err != nil {
return nil, err
}
if state := allocatedCMBuf.state; state != RMR_OK {
errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to get allocated message. state: %v - %s", state, states[int(state)])
return nil, errors.New(errorMessage)
}
defer C.rmr_free_msg(allocatedCMBuf)
for i := 0; i < ctx.MaxRetries; i++ {
currCMBuf := C.rmr_send_msg(ctx.RmrCtx, allocatedCMBuf)
if state := currCMBuf.state; state != RMR_OK {
if state != RMR_ERR_RETRY {
errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to send message. state: %v - %s", state, states[int(state)])
return nil, errors.New(errorMessage)
}
time.Sleep(100 * time.Millisecond)
continue
}
return convertToMBuf(currCMBuf)
}
return nil, errors.New(fmt.Sprintf("#rmrCgoApi.SendMsg - Too many retries"))
}
func (ctx *Context) RecvMsg() (*MBuf, error) {
allocatedCMBuf, err := C.rmr_alloc_msg(ctx.RmrCtx, C.int(ctx.MaxMsgSize))
if err != nil {
return nil, err
}
if state := allocatedCMBuf.state; state != RMR_OK {
errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to get allocated message. state: %v - %s", state, states[int(state)])
return nil, errors.New(errorMessage)
}
defer C.rmr_free_msg(allocatedCMBuf)
currCMBuf := C.rmr_rcv_msg(ctx.RmrCtx, allocatedCMBuf)
if state := currCMBuf.state; state != RMR_OK {
errorMessage := fmt.Sprintf("#rmrCgoApi.RecvMsg - Failed to receive message. state: %v - %s", state, states[int(state)])
return nil, errors.New(errorMessage)
}
return convertToMBuf(currCMBuf)
}
func (ctx *Context) IsReady() bool {
return int(C.rmr_ready(ctx.RmrCtx)) != 0
}
func (ctx *Context) Close() {
C.rmr_close(ctx.RmrCtx)
}

View File

@@ -0,0 +1,124 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 rmr
// #cgo LDFLAGS: -L/usr/local/lib -lrmr_nng -lnng
// #include <rmr/rmr.h>
// #include <stdlib.h>
import "C"
import (
"fmt"
"unsafe"
)
func NewMBuf(mType int, len int, payload []byte, xAction []byte) *MBuf {
return &MBuf{
MType: mType,
Len: len,
Payload: payload,
XAction: xAction,
}
}
func NewContext(maxMsgSize int, maxRetries, flags int, ctx unsafe.Pointer) *Context {
return &Context{
MaxMsgSize: maxMsgSize,
MaxRetries: maxRetries,
Flags: flags,
RmrCtx: ctx,
}
}
const (
RMR_MAX_XACTION_LEN = int(C.RMR_MAX_XID)
RMR_MAX_MSG_SIZE = int(C.RMR_MAX_RCV_BYTES)
RMR_MAX_MEID_LEN = int(C.RMR_MAX_MEID)
//states
RMR_OK = C.RMR_OK
RMR_ERR_BADARG = C.RMR_ERR_BADARG
RMR_ERR_NOENDPT = C.RMR_ERR_NOENDPT
RMR_ERR_EMPTY = C.RMR_ERR_EMPTY
RMR_ERR_NOHDR = C.RMR_ERR_NOHDR
RMR_ERR_SENDFAILED = C.RMR_ERR_SENDFAILED
RMR_ERR_CALLFAILED = C.RMR_ERR_CALLFAILED
RMR_ERR_NOWHOPEN = C.RMR_ERR_NOWHOPEN
RMR_ERR_WHID = C.RMR_ERR_WHID
RMR_ERR_OVERFLOW = C.RMR_ERR_OVERFLOW
RMR_ERR_RETRY = C.RMR_ERR_RETRY
RMR_ERR_RCVFAILED = C.RMR_ERR_RCVFAILED
RMR_ERR_TIMEOUT = C.RMR_ERR_TIMEOUT
RMR_ERR_UNSET = C.RMR_ERR_UNSET
RMR_ERR_TRUNC = C.RMR_ERR_TRUNC
RMR_ERR_INITFAILED = C.RMR_ERR_INITFAILED
)
var states = map[int]string{
RMR_OK: "state is good",
RMR_ERR_BADARG: "argument passd to function was unusable",
RMR_ERR_NOENDPT: "send/call could not find an endpoint based on msg type",
RMR_ERR_EMPTY: "msg received had no payload; attempt to send an empty message",
RMR_ERR_NOHDR: "message didn't contain a valid header",
RMR_ERR_SENDFAILED: "send failed; errno has nano reason",
RMR_ERR_CALLFAILED: "unable to send call() message",
RMR_ERR_NOWHOPEN: "no wormholes are open",
RMR_ERR_WHID: "wormhole id was invalid",
RMR_ERR_OVERFLOW: "operation would have busted through a buffer/field size",
RMR_ERR_RETRY: "request (send/call/rts) failed, but caller should retry (EAGAIN for wrappers)",
RMR_ERR_RCVFAILED: "receive failed (hard error)",
RMR_ERR_TIMEOUT: "message processing call timed out",
RMR_ERR_UNSET: "the message hasn't been populated with a transport buffer",
RMR_ERR_TRUNC: "received message likely truncated",
RMR_ERR_INITFAILED: "initialisation of something (probably message) failed",
}
type MBuf struct {
MType int
Len int
Meid string //Managed entity id (RAN name)*/
Payload []byte
XAction []byte
}
func (m MBuf) String() string {
return fmt.Sprintf("{ MType: %d, Len: %d, Meid: %q, Xaction: %q, Payload: [%x] }", m.MType, m.Len, m.Meid, m.XAction, m.Payload)
}
type Context struct {
MaxMsgSize int
MaxRetries int
Flags int
RmrCtx unsafe.Pointer
}
type Messenger interface {
Init(port string, maxMsgSize int, maxRetries int, flags int) *Messenger
SendMsg(msg *MBuf) (*MBuf, error)
RecvMsg() (*MBuf, error)
IsReady() bool
Close()
}
type Config struct {
Port int
MaxMsgSize int
MaxRetries int
Flags int
}

View File

@@ -0,0 +1,119 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 rmr
// #cgo LDFLAGS: -L/usr/local/lib -lrmr_nng -lnng
// #include <rmr/rmr.h>
// #include <stdlib.h>
import "C"
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/pkg/errors"
"strconv"
"strings"
"unsafe"
)
/*
Allocates an mBuf and initialize it with the content of C.rmr_mbuf_t.
The xAction field is assigned a a value without trailing spaces.
*/
func convertToMBuf(m *C.rmr_mbuf_t) (*MBuf, error) {
payloadArr := C.GoBytes(unsafe.Pointer(m.payload), C.int(m.len))
xActionArr := C.GoBytes(unsafe.Pointer(m.xaction), C.int(RMR_MAX_XACTION_LEN))
// Trim padding (space and 0)
xActionStr := strings.TrimRight(string(xActionArr), "\040\000")
xActionArr = []byte(xActionStr)
mbuf := &MBuf{
MType: int(m.mtype),
Len: int(m.len),
//Payload: (*[]byte)(unsafe.Pointer(m.payload)),
Payload: payloadArr,
//XAction: (*[]byte)(unsafe.Pointer(m.xaction)),
XAction: xActionArr,
}
meidBuf := make([]byte, RMR_MAX_MEID_LEN)
if meidCstr := C.rmr_get_meid(m, (*C.uchar)(unsafe.Pointer(&meidBuf[0]))); meidCstr != nil {
mbuf.Meid = strings.TrimRight(string(meidBuf), "\000")
}
return mbuf, nil
}
/*
Allocates an C.rmr_mbuf_t and initialize it with the content of mBuf.
The xAction field is padded with trailing spaces upto capacity
*/
func (ctx *Context) getAllocatedCRmrMBuf(mBuf *MBuf, maxMsgSize int) (cMBuf *C.rmr_mbuf_t, rc error) {
var xActionBuf [RMR_MAX_XACTION_LEN]byte
var meidBuf [RMR_MAX_MEID_LEN]byte
cMBuf = C.rmr_alloc_msg(ctx.RmrCtx, C.int(maxMsgSize))
cMBuf.mtype = C.int(mBuf.MType)
cMBuf.len = C.int(mBuf.Len)
payloadLen := len(mBuf.Payload)
xActionLen := len(mBuf.XAction)
copy(xActionBuf[:], mBuf.XAction)
for i := xActionLen; i < RMR_MAX_XACTION_LEN; i++ {
xActionBuf[i] = '\040' //space
}
// Add padding
copy(meidBuf[:], mBuf.Meid)
for i := len(mBuf.Meid); i < RMR_MAX_MEID_LEN; i++ {
meidBuf[i] = 0
}
payloadArr := (*[1 << 30]byte)(unsafe.Pointer(cMBuf.payload))[:payloadLen:payloadLen]
xActionArr := (*[1 << 30]byte)(unsafe.Pointer(cMBuf.xaction))[:RMR_MAX_XACTION_LEN:RMR_MAX_XACTION_LEN]
err := binary.Read(bytes.NewReader(mBuf.Payload), binary.LittleEndian, payloadArr)
if err != nil {
return nil, errors.New(fmt.Sprintf("#rmrCgoUtils.getAllocatedCRmrMBuf - Failed to read payload to allocated RMR message buffer, %s", err))
}
err = binary.Read(bytes.NewReader(xActionBuf[:]), binary.LittleEndian, xActionArr)
if err != nil {
return nil, errors.New(fmt.Sprintf("#rmrCgoUtils.getAllocatedCRmrMBuf - Failed to read xAction data to allocated RMR message buffer, %s", err))
}
len := C.rmr_bytes2meid(cMBuf, (*C.uchar)(unsafe.Pointer(&meidBuf[0])), C.int(RMR_MAX_XACTION_LEN))
if int(len) != RMR_MAX_MEID_LEN {
return nil, errors.New(
"#rmrCgoUtils.getAllocatedCRmrMBuf - Failed to copy meid data to allocated RMR message buffer")
}
return cMBuf, nil
}
func MessageIdToUint(id string) (msgId uint64, err error) {
if len(id) == 0 {
msgId, err = 0, nil
} else {
msgId, err = strconv.ParseUint(id, 10, 16)
}
return
}

View File

@@ -0,0 +1,51 @@
//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// 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 rmr
import (
"strconv"
)
// RmrService holds an instance of RMR messenger as well as its configuration
type Service struct {
messenger *Messenger
}
// NewRmrService instantiates a new Rmr service instance
func NewService(rmrConfig Config, messenger Messenger) *Service {
return &Service{
messenger: messenger.Init("tcp:"+strconv.Itoa(rmrConfig.Port), rmrConfig.MaxMsgSize, rmrConfig.MaxRetries, rmrConfig.Flags),
}
}
func (r *Service) SendMessage(messageType int, ranName string, msg []byte, transactionId []byte) (*MBuf, error) {
mbuf := NewMBuf(messageType, len(msg), msg, transactionId)
mbuf.Meid = ranName
return (*r.messenger).SendMsg(mbuf)
}
func (r *Service) RecvMessage() (*MBuf, error) {
return (*r.messenger).RecvMsg()
}
func (r *Service) CloseContext() {
(*r.messenger).Close()
}

View File

@@ -0,0 +1,179 @@
// This source code is part of the near-RT RIC (RAN Intelligent Controller)
// platform project (RICP).
// Copyright 2019 Nokia
//
// 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 sender
import (
"fmt"
"github.com/pkg/errors"
"os"
"reflect"
"strconv"
"strings"
"sync/atomic"
"time"
"unicode"
"xappmock/logger"
"xappmock/models"
"xappmock/rmr"
)
var counter uint64
type JsonSender struct {
logger *logger.Logger
}
func NewJsonSender(logger *logger.Logger) *JsonSender {
return &JsonSender{
logger: logger,
}
}
func (s *JsonSender) SendJsonRmrMessage(command models.JsonCommand /*the copy is modified locally*/, xAction *[]byte, r *rmr.Service) error {
var payload []byte
_, err := fmt.Sscanf(command.PackedPayload, "%x", &payload)
if err != nil {
return errors.New(fmt.Sprintf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err))
}
command.PackedPayload = string(payload)
command.TransactionId = expandTransactionId(command.TransactionId)
if len(command.TransactionId) == 0 {
command.TransactionId = string(*xAction)
}
command.PayloadHeader = s.expandPayloadHeader(command.PayloadHeader, &command)
s.logger.Infof("#JsonSender.SendJsonRmrMessage - command payload header: %s", command.PayloadHeader)
rmrMsgId, err := rmr.MessageIdToUint(command.RmrMessageType)
if err != nil {
return errors.New(fmt.Sprintf("invalid rmr message id: %s", command.RmrMessageType))
}
msg := append([]byte(command.PayloadHeader), payload...)
messageInfo := models.NewMessageInfo(int(rmrMsgId), command.RanName, msg, []byte(command.TransactionId))
s.logger.Infof("#JsonSender.SendJsonRmrMessage - going to send message: %s", messageInfo)
_, err = r.SendMessage(int(rmrMsgId), command.RanName, msg, []byte(command.TransactionId))
return err
}
/*
* transactionId (xAction): The value may have a fixed value or $ or <prefix>$.
* $ is replaced by a value generated at runtime (possibly unique per message sent).
* If the tag does not exist, then the mock shall use the value taken from the incoming message.
*/
func expandTransactionId(id string) string {
if len(id) == 1 && id[0] == '$' {
return fmt.Sprintf("%d", incAndGetCounter())
}
if len(id) > 1 && id[len(id)-1] == '$' {
return fmt.Sprintf("%s%d", id[:len(id)-1], incAndGetCounter())
}
return id
}
/*
* payloadHeader: A prefix to combine with the payload that will be the messages payload. The value may include variables of the format $<name> or #<name> where:
* $<name> expands to the value of <name> if it exists or the empty string if not.
* #<name> expands to the length of the value of <name> if it exists or omitted if not.
* The intention is to allow the Mock to construct the payload header required by the setup messages (ranIp|ranPort|ranName|payload len|<payload>).
* Example: “payloadHeader”: “$ranIp|$ranPort|$ranName|#packedPayload|”
*/
func (s *JsonSender) expandPayloadHeader(header string, command *models.JsonCommand) string {
var name strings.Builder
var expandedHeader strings.Builder
r := strings.NewReader(header)
ch, err := r.ReadByte()
for {
if err != nil {
break
}
switch ch {
case '$':
for {
ch, err = r.ReadByte() //on error ch == 0
if unicode.IsDigit(rune(ch)) || unicode.IsLetter(rune(ch)) {
if name.Len() == 0 {
name.WriteByte(byte(unicode.ToUpper(rune(ch))))
} else {
name.WriteByte(ch)
}
} else {
if fieldValue := reflect.Indirect(reflect.ValueOf(command)).FieldByName(name.String()); fieldValue.IsValid() {
switch fieldValue.Kind() {
case reflect.String:
expandedHeader.WriteString(fieldValue.String())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
expandedHeader.WriteString(strconv.FormatInt(fieldValue.Int(), 10))
case reflect.Bool:
expandedHeader.WriteString(strconv.FormatBool(fieldValue.Bool()))
case reflect.Float64, reflect.Float32:
expandedHeader.WriteString(fmt.Sprintf("%g", fieldValue.Float()))
default:
s.logger.Errorf("#JsonSender.expandPayloadHeader - invalid type for $%s, value must be a string, an int, a bool or a float", name.String())
os.Exit(1)
}
}
name.Reset()
break
}
}
case '#':
for {
ch, err = r.ReadByte() //on error ch == 0
if unicode.IsDigit(rune(ch)) || unicode.IsLetter(rune(ch)) {
if name.Len() == 0 {
name.WriteByte(byte(unicode.ToUpper(rune(ch))))
} else {
name.WriteByte(ch)
}
} else {
if fieldValue := reflect.Indirect(reflect.ValueOf(command)).FieldByName(name.String()); fieldValue.IsValid() {
if fieldValue.Kind() == reflect.String {
expandedHeader.WriteString(strconv.FormatInt(int64(len(fieldValue.String())), 10))
} else {
s.logger.Errorf("#JsonSender.expandPayloadHeader - invalid type for #%s, value must be a string", name.String())
os.Exit(1)
}
}
name.Reset()
break
}
}
default:
if unicode.IsPrint(rune(ch)) {
expandedHeader.WriteByte(ch)
}
ch, err = r.ReadByte()
}
}
return expandedHeader.String()
}
func incAndGetCounter() uint64 {
return atomic.AddUint64(&counter, 1)
}
func init() {
counter = uint64(time.Now().Unix() - 1572000000)
}