comm

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

README

RETHi Communication Network Emulator

Version 1.1 2023 annual review

https://purdue.edu/rethi

Usage

docker build -t amyangxyz111/rethi-comm . && docker compose up --force-recreate

Change Local/Remote IP addresses and ports in the docker-compose.yml if necessary

Application-layer Protocol

On top of UDP

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      SRC      |       DST     | TYPE  | PRIO  |  VER  |  RES  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     PHYSICAL_TIMESTAMP                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     SIMULINK_TIMESTAMP                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            SEQUENCE           |              LEN              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      DATA…
+-+-+-+-+-+-+-+-+

Code structure

Backend - Golang
  • main.go: entry and configurations (some from env)
  • subsys.go: a UDP server/client represents an outside subsystem
  • switch.go: emulate TSN MIMOMQ switch, follows 802.1Qbv schedule
  • gate.go,link.go: emulate the gates and cables of TSN switches
  • topo.go: form the topology and find routing paths
  • packet.go: define the app-layer protocol format
  • db.go: database connector, mainly for topo and statistics
  • web.go: set up a Web server
  • utils.go: utility functions
Frontend - Vue+ECharts

Documentation

Overview

Communication Network Emulator for NASA RETHi project, based on Time-Sensitive Networking.

Index

Constants

View Source
const (
	PKT_BUF_LEN         = 8096
	PORT_NUM_SUBSYS     = 8
	PORT_NUM_SWITCH     = 8
	QUEUE_NUM_SWITCH    = 8
	QUEUE_LEN_SWITCH    = 8096
	SAVE_STATS_PERIOD   = 10 // in seconds
	UPLOAD_STATS_PERIOD = 3  // in seconds
	WSLOG_HEARTBEAT     = -1
	WSLOG_MSG           = 0
	WSLOG_STAT          = 1
	WSLOG_PKT_TX        = 2
	FAULT_FAILURE       = "Failure"
	FAULT_SLOW          = "Slow"
	FAULT_OVERFLOW      = "Overflow"
	FAULT_FLOODING      = "Flooding"
	FAULT_MIS_ROUTING   = "Mis-routing"
)
View Source
const (
	PACKET_TYPE_CTRL = 0x00
	PACKET_TYPE_DATA = 0x01
)

Variables

View Source
var (
	SpeedWireless     float64 = 300000000   // m/s
	DistanceWireless  float64 = 57968000000 // meter 54500000000-401300000000
	BandwidthWireless float64 = 2048        // bps, 500~32000, ref: https://mars.nasa.gov/msl/mission/communications/
	SpeedWire         float64 = 231000000   // .77c
	DistanceWire      float64 = 30          // meter
	BandwidthWire     float64 = 1073741824  // 1Gbps
	PacketLossRate    float64 = 0           // percenttge
)

default values

View Source
var (
	ASN               = 0           // Absolute Slot Number for TSN schedule
	NEW_SLOT_SIGNAL   chan int      // for slot increment of TSN schedule execution
	HYPER_PERIOD                    = 100
	SLOT_DURATION     time.Duration = 100   // us, interval of ASN incremental
	ANIMATION_ENABLED               = false // enable animation on the frontend
	CONSOLE_ENABLED                 = false // enable console log on the frontend
	DELAY_ENABLED                   = false // enable real delay (wall clock)
	FRER_ENABLED                    = false // enable 802.1CB FRER protocol
	REROUTE_ENABLED                 = false // enable rerouting upon switch failure
	TAS_ENABLED                     = false // enable 802.1Qbv schedule
	SAVE_STATS                      = false // save packet stats into db
	DUP_ELI_ENABLED                 = false // enable du
	JITTER_BASE                     = 0     // base (mean) value of the random jitter

	WSLog      = make(chan Log, 65536) // websocket logging channel
	SUBSYS_MAP = map[string]uint8{
		"GCC":   0,
		"HMS":   1,
		"STR":   2,
		"SPL":   11,
		"ECLSS": 5,
		"PWR":   3,
		"AGT":   6,
		"IE":    8,
		"DTB":   9,
		"EXT":   7,
		"COORD": 10,
	}
	SequenceNumber int32 = 0 // packet sequence number
	UID                  = 0 // packet UID
	Subsystems     []*Subsys
	Switches       []*Switch
	Links          []*Link
	ActiveTopoTag  = ""
)
View Source
var UIDIncMutex sync.Mutex // for packet UID increment

Functions

func Connect

func Connect(n1, n2 Node)

Connect the ports of two nodes. Each node has a used ports counter, so no need to specify the port index here

Types

type Fault

type Fault struct {
	Type      string
	Happening bool
	Durtaion  int
}

Fault injected to the switch

type Flow

type Flow struct {
	Name string   `json:"name"` // subsys name
	ID   int      `json:"id"`   // subsys id
	Dst  []string `json:"dst"`
	Freq string   `json:"freq"`
}
type Link struct {
	PacketLossRate float64 // percentage
	Bandwidth      float64 // in Mbps
	Speed          float64 // m/s
	Distance       float64 // in meter

	// for mars-earth
	HardcodedDelay float64
	Failed         bool
	// contains filtered or unexported fields
}

Emulate ethernet cables, connect two ports, no direction

func (*Link) Stop

func (l *Link) Stop()

type Log

type Log struct {
	Type       int               `json:"type"` // -1: heartbeat, 0: log, 1: statistics
	Msg        string            `json:"msg"`
	Statistics map[string][2]int `json:"stats_comm"`
	PktTx      PktTx             `json:"pkt_tx"`
}

type Node

type Node interface {
	Name() string
	OutPort() *Port // return an idle outcoming port for connecting
	InPort() *Port  // return an idle incoming port for connecting
	Start()
}

switch or subsys

type Packet

type Packet struct {
	// protocol use
	Src          uint8  `json:"src"`
	Dst          uint8  `json:"dst"`
	MessageType  uint8  `json:"message_type"`
	Priority     uint8  `json:"priority"`
	Version      uint8  `json:"version"`
	Reserved     uint8  `json:"reserved"`
	PhysicalTime uint32 `json:"physical_time"`
	SimulinkTime uint32 `json:"simulink_time"`
	Sequence     uint16 `json:"sequence"`
	Length       uint16 `json:"length"`
	Payload      []byte `json:"-"`

	// internal use
	IsSim       bool
	RawBytes    []byte
	Delay       float64
	Path        []string
	UID         int   // for animation
	Seq         int32 // for 802.1CB-FRER
	RxTimestamp int64
	TxTimestamp int64
	DupID       int
}

func (*Packet) Dup

func (pkt *Packet) Dup() *Packet

deep copy/duplicate a packet

func (*Packet) FromBuf

func (pkt *Packet) FromBuf(buf []byte) error

Decode packet from received buffer

func (*Packet) ToBuf

func (pkt *Packet) ToBuf() []byte

Encode packet to buffer

type PktTx

type PktTx struct {
	Node     string `json:"node"`
	UID      int    `json:"uid"`
	Finished bool   `json:"finished"`
}

type Port

type Port struct {
	ID       int
	Owner    string
	Neighbor string
	Channel  chan *Packet
	Failed   bool
}

Send/Receive interface of switch/subsys based on Go channel

func NewPort

func NewPort(id int, owner string) *Port

type Priority

type Priority struct {
	Name     string      `json:"name"`
	Priority json.Number `json:"priority"`
}

type RoutingEntry

type RoutingEntry struct {
	NextHop  string
	HopCount int
}

type StatsDelay

type StatsDelay struct {
	Source string       `json:"source"`
	Data   [][2]float64 `json:"data"`
}

type Subsys

type Subsys struct {
	Priority int // will overwrite priority in packets

	RoutingTable map[string][]RoutingEntry

	SeqRecoverHistory      map[int32]bool // for frer
	SeqRecoverHistoryMutex sync.Mutex
	// contains filtered or unexported fields
}

Subsys is the virtual node that represents a subsystem, it communicates with outside real subsystem and pass packets to TSN switches

func NewSubsys

func NewSubsys(name string, position [2]int) *Subsys

returns a Subsys pointer

func (*Subsys) CreateFlow

func (s *Subsys) CreateFlow(dst int)

create a simulated internal packet flow

func (*Subsys) InPort

func (s *Subsys) InPort() *Port

implement Node interface

func (*Subsys) Name

func (s *Subsys) Name() string

implement Node interface

func (*Subsys) OutPort

func (s *Subsys) OutPort() *Port

implement Node interface

func (*Subsys) Start

func (s *Subsys) Start()

Start the Subsys

func (*Subsys) Stop

func (s *Subsys) Stop()

Stop the Subsys

type Switch

type Switch struct {
	GCL [PORT_NUM_SWITCH][]TimeWindow // portid:schedule

	Neighbors []string

	Faults map[string]Fault

	SeqRecoverHistory      map[int32]bool
	SeqRecoverHistoryMutex sync.Mutex
	RoutingTable           map[string][]RoutingEntry
	// contains filtered or unexported fields
}

Switch simulates MIMOMQ TSN switch

func NewSwitch

func NewSwitch(name string, position [2]int) *Switch

New switch

func (*Switch) Classify

func (sw *Switch) Classify(pkt *Packet)

classify packet belongs to which out-port

func (*Switch) InPort

func (sw *Switch) InPort() *Port

implement Node interface

func (*Switch) Name

func (sw *Switch) Name() string

implement Node interface

func (*Switch) OutPort

func (sw *Switch) OutPort() *Port

implement Node interface

func (*Switch) Start

func (sw *Switch) Start()

starts the switch routine

func (*Switch) Stop

func (sw *Switch) Stop()

Stop stops the switch

type TimeWindow

type TimeWindow struct {
	Queue int `json:"queue"`
}

type TopoGraph

type TopoGraph struct {
	Nodes []*TopologyGraphNode
}

for routing table generation

var (
	Graph *TopoGraph
)

func (*TopoGraph) FindAllPaths

func (g *TopoGraph) FindAllPaths(src, dst string) [][]string

FindAllPaths returns all paths from src to dst

type TopologyData

type TopologyData struct {
	Tag   string         `json:"tag"`
	Nodes []TopologyNode `json:"nodes"`
	Edges [][2]string    `json:"edges"`
}

for en/decode

type TopologyGraphNode

type TopologyGraphNode struct {
	// contains filtered or unexported fields
}

type TopologyNode

type TopologyNode struct {
	Name     string `json:"name"`
	Position [2]int `json:"value"`
}

for en/decode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL