Skip to content

Commit

Permalink
Add reliabilitylevel_string autogen code
Browse files Browse the repository at this point in the history
  • Loading branch information
vposloncec committed Jan 25, 2024
1 parent 9e779b2 commit d7a7536
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
26 changes: 17 additions & 9 deletions base/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ package base

import (
"go.uber.org/zap"
"strconv"
"time"
)

type NodeID int

func (n NodeID) String() string {
return strconv.Itoa(int(n))
}

type PacketWithSender struct {
Packet *Packet
Sender *Node
}

type Node struct {
ID NodeID
Log *zap.SugaredLogger
MessageQueue chan *PacketWithSender
Subscribers []*Node
PacketHistory map[PacketUUID]*PacketLog
Reliability ReliabilityLevel
CpuScore int
packagesSent int
packagesDropped int
ID NodeID
Log *zap.SugaredLogger
MessageQueue chan *PacketWithSender
Subscribers []*Node
PacketHistory map[PacketUUID]*PacketLog
Reliability ReliabilityLevel
CpuScore int
PackagesReceived int
packagesSent int
packagesDropped int
}

type PacketLog struct {
Expand Down Expand Up @@ -60,6 +67,7 @@ func (n *Node) RecvPacket(callerNode *Node, p *Packet) {
n.MessageQueue <- &PacketWithSender{
Sender: callerNode,
Packet: p}
n.PackagesReceived++
}

func (n *Node) AlreadyReceived(id PacketUUID) bool {
Expand Down
1 change: 1 addition & 0 deletions base/reliability.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/rand"
)

//go:generate stringer -type=ReliabilityLevel
type ReliabilityLevel int

const (
Expand Down
27 changes: 27 additions & 0 deletions base/reliabilitylevel_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"github.com/vposloncec/go-ssip/orchestration"

"github.com/spf13/cobra"
"github.com/vposloncec/go-ssip/orchestration"
)

// runCmd represents the run command
Expand Down
3 changes: 1 addition & 2 deletions export/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package export
import (
"bytes"
"encoding/csv"
"fmt"
"github.com/vposloncec/go-ssip/base"
"strconv"
)
Expand All @@ -28,7 +27,7 @@ func nodeToRow(node *base.Node) []string {
row := make([]string, len(nodeHeaders))
row[0] = node.ID.String()
row[1] = strconv.Itoa(node.PackagesReceived)
row[2] = fmt.Sprint(node.Reliability)
row[2] = node.Reliability.String()

return row
}
10 changes: 9 additions & 1 deletion orchestration/orchestrator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package orchestration

import (
"fmt"
"github.com/spf13/viper"
"github.com/vposloncec/go-ssip/base"
"github.com/vposloncec/go-ssip/export"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
"time"
)

Expand All @@ -18,9 +21,12 @@ func StartFromInput(nodeNum int, connections []base.ConnectionPair) {
graph.Nodes[0].SendPacket(p)
time.Sleep(3 * time.Second)
graph.CalcPacketReach(p.ID)
export.EdgesToCSV(graph.Connections).WriteTo(os.Stdout)
fmt.Println("==============================")
export.NodesToCSV(graph.Nodes).WriteTo(os.Stdout)
}

func StartRandom(nodeNum int, connections int) {
func StartRandom(nodeNum int, connections int) *base.Graph {
log := getLogger()

maxId := nodeNum - 1
Expand All @@ -33,6 +39,8 @@ func StartRandom(nodeNum int, connections int) {
graph.Nodes[0].SendPacket(p)
time.Sleep(3 * time.Second)
graph.CalcPacketReach(p.ID)

return graph
}

func getLogger() *zap.SugaredLogger {
Expand Down

0 comments on commit d7a7536

Please sign in to comment.