Skip to content

Commit

Permalink
fix: remove functions for the previous OT device
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinicius Guimaraes committed Sep 15, 2022
1 parent 9bade00 commit ae7a872
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 109 deletions.
6 changes: 1 addition & 5 deletions dispatcher/Node.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ func (node *Node) String() string {
func (node *Node) Send(elapsed uint64, data []byte) {
msg := make([]byte, len(data)+11)
binary.LittleEndian.PutUint64(msg[:8], elapsed)
if node.D.IsCollisionAware { // TODO: Delete after OT has been merged with the new timing PR
msg[8] = eventTypeRadioComm
} else {
msg[8] = eventTypeRadioReceived
}
msg[8] = eventTypeRadioComm

binary.LittleEndian.PutUint16(msg[9:11], uint16(len(data)))
n := copy(msg[11:], data)
Expand Down
109 changes: 5 additions & 104 deletions dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ type Dispatcher struct {
DispatchByShortAddrFail uint64
DispatchAllInRange uint64
}
watchingNodes map[NodeId]struct{}
energyAnalyser *energy.EnergyAnalyser
stopped bool
IsCollisionAware bool // TODO: Remove this variable when OT simulation is updated with correct transmission delays
watchingNodes map[NodeId]struct{}
energyAnalyser *energy.EnergyAnalyser
stopped bool
}

func NewDispatcher(ctx *progctx.ProgCtx, cfg *Config, cbHandler CallbackHandler) *Dispatcher {
Expand Down Expand Up @@ -182,7 +181,6 @@ func NewDispatcher(ctx *progctx.ProgCtx, cfg *Config, cbHandler CallbackHandler)
watchingNodes: map[NodeId]struct{}{},
goDurationChan: make(chan goDuration, 10),
visOptions: defaultVisualizationOptions(),
IsCollisionAware: false,
}
d.speed = d.normalizeSpeed(d.speed)
if !d.cfg.NoPcap {
Expand Down Expand Up @@ -338,11 +336,7 @@ func (d *Dispatcher) handleRecvEvent(evt *event) {
d.Counters.AlarmEvents += 1
d.setSleeping(nodeid)
d.alarmMgr.SetTimestamp(nodeid, evtTime)
case eventTypeRadioReceived: // TODO: Remove this event when OT simulation is updated with correct transmission delays
d.Counters.RadioEvents += 1
d.sendQueue.Add(d.CurTime+1, nodeid, evt.Data)
case eventTypeRadioComm:
d.IsCollisionAware = true
d.Counters.RadioEvents += 1
d.sendQueue.Add(evtTime, nodeid, evt.Data)
d.startNewtransmission(nodeid, evt.Delay, evtTime)
Expand Down Expand Up @@ -481,12 +475,7 @@ func (d *Dispatcher) processNextEvent() bool {
if d.cfg.DumpPackets {
d.dumpPacket(s)
}
// TODO: remove this conditon when OT simulation is updated with correct transmission delays
if d.IsCollisionAware {
d.sendNodeMessageCollisionAware(s)
} else {
d.sendNodeMessage(s)
}
d.sendNodeMessageCollisionAware(s)
}

nextAlarmTime = d.alarmMgr.NextTimestamp()
Expand Down Expand Up @@ -598,89 +587,6 @@ func (d *Dispatcher) SendToUART(id NodeId, data []byte) {
d.setAlive(node.Id)
}

// TODO: Remove this function after the new version of the OT simulation is released.
func (d *Dispatcher) sendNodeMessage(sit *sendItem) {
// send the message to all nodes
srcnodeid := sit.NodeId
srcnode := d.nodes[srcnodeid]
if srcnode == nil {
if _, ok := d.deletedNodes[srcnodeid]; !ok {
simplelogger.Errorf("%s: node %d not found", d, srcnodeid)
}
return
}

// send to self as notify for tx done (should do even if the node is failed)
d.sendOneMessage(sit, srcnode, srcnode)

if srcnode.isFailed {
return
}

pktinfo := dissectpkt.Dissect(sit.Data)
pktframe := pktinfo.MacFrame

// try to dispatch the message by extaddr directly
dispatchedByDstAddr := false
dstAddrMode := pktframe.FrameControl.DstAddrMode()

if dstAddrMode == wpan.DstAddrModeExtended {
// the message should only be dispatched to the target node with the extaddr
dstnode := d.extaddrMap[pktframe.DstAddrExtended]
if dstnode != srcnode && dstnode != nil {
if d.checkRadioReachable(srcnode, dstnode) {
d.sendOneMessage(sit, srcnode, dstnode)
d.visSendFrame(srcnodeid, dstnode.Id, pktframe)
} else {
d.visSendFrame(srcnodeid, InvalidNodeId, pktframe)
}

d.Counters.DispatchByExtAddrSucc++
} else {
d.Counters.DispatchByExtAddrFail++
d.visSendFrame(srcnodeid, InvalidNodeId, pktframe)
}

dispatchedByDstAddr = true
} else if dstAddrMode == wpan.DstAddrModeShort {
if pktframe.DstAddrShort != threadconst.BroadcastRloc16 {
// unicast message should only be dispatched to target node with the rloc16
dstnodes := d.rloc16Map[pktframe.DstAddrShort]
dispatchCnt := 0

if len(dstnodes) > 0 {
for _, dstnode := range dstnodes {
if d.checkRadioReachable(srcnode, dstnode) {
d.sendOneMessage(sit, srcnode, dstnode)
d.visSendFrame(srcnodeid, dstnode.Id, pktframe)
dispatchCnt++
}
}
d.Counters.DispatchByShortAddrSucc++
} else {
d.Counters.DispatchByShortAddrFail++
}

if dispatchCnt == 0 {
d.visSendFrame(srcnodeid, InvalidNodeId, pktframe)
}

dispatchedByDstAddr = true
}
}

if !dispatchedByDstAddr {
// TODO: optimize ACK message dispatching by sending it only to the correct node(s)
for _, dstnode := range d.nodes {
if d.checkRadioReachable(srcnode, dstnode) {
d.sendOneMessage(sit, srcnode, dstnode)
}
}

d.visSendFrame(srcnodeid, BroadcastNodeId, pktframe)
}
}

func (d *Dispatcher) sendNodeMessageCollisionAware(sit *sendItem) {
// send the message to all nodes
srcnodeid := sit.NodeId
Expand Down Expand Up @@ -824,12 +730,7 @@ func (d *Dispatcher) sendOneMessage(sit *sendItem, srcnode *Node, dstnode *Node)
d.setAlive(dstnodeid)

if d.isWatching(dstnodeid) {
// TODO: remove this if when the new OT simulation with timed transmissions is released in OT.
if dstnode == srcnode {
simplelogger.Warnf("Node %d >>> TX DONE", dstnodeid)
} else {
simplelogger.Warnf("Node %d >>> received message from node %d", dstnodeid, srcnode.Id)
}
simplelogger.Warnf("Node %d >>> received message from node %d", dstnodeid, srcnode.Id)
}
}

Expand Down

0 comments on commit ae7a872

Please sign in to comment.