Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subscriber support to simapp #7

Merged
4 commits merged into from Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions config/simapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ configuration:
APP:
ReportCaller: false
debugLevel: info
subscribers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have range based + single subscriber both options

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, already put the one subscriber and a range based subscriber in yaml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add final config in helm chart as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- ueId-start: 123456789123458
ueId-end: 123456789123458
plmnId: 20893
opc: 8e27b6af0e692e750f32667a3b14605d
key: 8baf473f2f8fd09487cccbd7097c6862
sequenceNumber: 16f3b3f70fc2
- ueId-start: 123456789123460
ueId-end: 123456789123465
plmnId: 222222
opc: 22222222222222222222222222222222
key: 22222222222222222222222222222222
sequenceNumber: 222222222
sub-provision-endpt:
addr: webui
port: 5000
device-groups:
- name: "iot-camera"
imsis:
Expand Down
95 changes: 88 additions & 7 deletions simapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net"
"net/http"
"time"
"strconv"
)

type Config struct {
Expand All @@ -32,6 +33,8 @@ type Configuration struct {
ConfigSlice bool `yaml:"provision-network-slice,omitempty"`
DevGroup []*DevGroup `yaml:"device-groups,omitempty"`
NetworkSlice []*NetworkSlice `yaml:"network-slices,omitempty"`
Subscriber []*Subscriber `yaml:"subscribers,omitempty"`
SubProvisionEndpt *SubProvisionEndpt `yaml:"sub-provision-endpt,omitempty"`
}

type DevGroup struct {
Expand All @@ -49,6 +52,21 @@ type IpDomain struct {
UePool string `yaml:"ue-ip-pool,omitempty" json:"ue-ip-pool,omitempty"`
}

type Subscriber struct {
UeId string
UeIdStart string `yaml:"ueId-start,omitempty" json:"ueId-start,omitempty"`
UeIdEnd string `yaml:"ueId-end,omitempty" json:"ueId-end,omitempty"`
PlmnId string `yaml:"plmnId,omitempty" json:"plmnId,omitempty"`
OPc string `yaml:"opc,omitempty" json:"opc,omitempty"`
Key string `yaml:"key,omitempty" json:"key,omitempty"`
SequenceNumber string `yaml:"sequenceNumber,omitempty" json:"sequenceNumber,omitempty"`
}

type SubProvisionEndpt struct {
Addr string `yaml:"addr,omitempty" json:"addr,omitempty"`
Port string `yaml:"port,omitempty" json:"port,omitempty"`
}

type NetworkSlice struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
SliceId *SliceId `yaml:"slice-id,omitempty" json:"slice-id,omitempty"`
Expand Down Expand Up @@ -104,6 +122,7 @@ type AppInfo struct {
const (
device_group = iota
network_slice
subscriber
)

type configMessage struct {
Expand All @@ -114,7 +133,7 @@ type configMessage struct {

var SimappConfig Config

func InitConfigFactory(f string, configMsgChan chan configMessage) error {
func InitConfigFactory(f string, configMsgChan chan configMessage, subProvisionEndpt *SubProvisionEndpt) error {
fmt.Println("Function called ", f)
if content, err := ioutil.ReadFile(f); err != nil {
fmt.Println("Readfile failed called ", err)
Expand All @@ -132,6 +151,56 @@ func InitConfigFactory(f string, configMsgChan chan configMessage) error {
return nil
}

fmt.Println("Number of subscriber ranges", len(SimappConfig.Configuration.Subscriber))
for o := 0; o < len(SimappConfig.Configuration.Subscriber); o++ {
subscribers := SimappConfig.Configuration.Subscriber[o]
fmt.Println("Subscribers:")
fmt.Println(" UeIdStart", subscribers.UeIdStart)
fmt.Println(" UeIdEnd", subscribers.UeIdEnd)
fmt.Println(" PlmnId", subscribers.PlmnId)
fmt.Println(" OPc", subscribers.OPc)
fmt.Println(" Key", subscribers.Key)
fmt.Println(" SequenceNumber", subscribers.SequenceNumber)

start, err := strconv.ParseUint(subscribers.UeIdStart, 0, 64)
if err != nil {
fmt.Println("error in ParseUint with UeIdStart", err)
continue
}
end, err := strconv.ParseUint(subscribers.UeIdEnd, 0, 64)
if err != nil {
fmt.Println("error in ParseUint with UeIdEnd", err)
continue
}
for i := start; i <= end; i++ {
subscribers.UeId = strconv.FormatUint(i, 10)
fmt.Println(" UeId", subscribers.UeId)
if err != nil {
fmt.Println("error in FormatUint with UeId", err)
continue
}
subscribers.UeIdStart = ""
subscribers.UeIdEnd = ""
b, err := json.Marshal(subscribers)
if err != nil {
fmt.Println("error in marshal with subscribers", err)
continue
}
reqMsgBody := bytes.NewBuffer(b)
var msg configMessage
msg.msgPtr = reqMsgBody
msg.msgType = subscriber
msg.name = subscribers.UeId
configMsgChan <- msg
}
}

fmt.Println("Subscriber Provision Endpoint:")
fmt.Println("Address ", SimappConfig.Configuration.SubProvisionEndpt.Addr)
fmt.Println("Port ", SimappConfig.Configuration.SubProvisionEndpt.Port)
subProvisionEndpt.Addr = SimappConfig.Configuration.SubProvisionEndpt.Addr
subProvisionEndpt.Port = SimappConfig.Configuration.SubProvisionEndpt.Port

fmt.Println("Number of device Groups ", len(SimappConfig.Configuration.DevGroup))
for g := 0; g < len(SimappConfig.Configuration.DevGroup); g++ {
group := SimappConfig.Configuration.DevGroup[g]
Expand Down Expand Up @@ -162,7 +231,7 @@ func InitConfigFactory(f string, configMsgChan chan configMessage) error {
var msg configMessage
msg.msgPtr = reqMsgBody
msg.msgType = device_group
msg.name = group.Name
msg.name = group.Name
configMsgChan <- msg
}

Expand Down Expand Up @@ -223,20 +292,28 @@ func InitConfigFactory(f string, configMsgChan chan configMessage) error {

func main() {
configMsgChan := make(chan configMessage, 10)
var subProvisionEndpt SubProvisionEndpt

fmt.Println("SimApp started")
go sendMessage(configMsgChan)
InitConfigFactory("./config/simapp.yaml", configMsgChan)
InitConfigFactory("./config/simapp.yaml", configMsgChan, &subProvisionEndpt)
go sendMessage(configMsgChan, subProvisionEndpt)
for {
time.Sleep(100 * time.Second)
}
}

func sendMessage(msgChan chan configMessage) {
func sendMessage(msgChan chan configMessage, subProvisionEndpt SubProvisionEndpt ) {
var devGroupHttpend string
var networkSliceHttpend string
var subscriberHttpend string

fmt.Println("Subscriber Provision Endpoint in sendMessage:")
fmt.Println("Address ", subProvisionEndpt.Addr)
fmt.Println("Port ", subProvisionEndpt.Port)


for {
ip, err := net.ResolveIPAddr("ip", "webui")
ip, err := net.ResolveIPAddr("ip", subProvisionEndpt.Addr)
if err != nil {
fmt.Println("failed to resolve name")
time.Sleep(10 * time.Second)
Expand All @@ -247,6 +324,8 @@ func sendMessage(msgChan chan configMessage) {
fmt.Println("device trigger http endpoint ", devGroupHttpend)
networkSliceHttpend = "http://" + ip.String() + ":9089/config/v1/network-slice/"
fmt.Println("network slice http endpoint ", devGroupHttpend)
subscriberHttpend = "http://" + ip.String() + ":" + subProvisionEndpt.Port + "/api/subscriber/imsi-"
fmt.Println("subscriber http endpoint ", subscriberHttpend)
break
}
for {
Expand All @@ -259,6 +338,8 @@ func sendMessage(msgChan chan configMessage) {
httpend = devGroupHttpend + msg.name
case network_slice:
httpend = networkSliceHttpend + msg.name
case subscriber:
httpend = subscriberHttpend + msg.name
}

for {
Expand All @@ -278,7 +359,7 @@ func sendMessage(msgChan chan configMessage) {
time.Sleep(1 * time.Second)
continue
}
fmt.Printf("Message Post %v Success\n", devGroupHttpend)
fmt.Printf("Message Post %v Success\n", httpend)
break
}
}
Expand Down