-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadGenerator.groovy
79 lines (66 loc) · 2.39 KB
/
LoadGenerator.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import org.arl.fjage.*
import org.arl.unet.*
import org.arl.unet.phy.*
import org.arl.unet.net.*
import org.arl.unet.PDU
import org.arl.unet.nodeinfo.NodeInfo
class LoadGenerator extends UnetAgent {
private List<Integer> destNodes // list of possible destination nodes
private float load // normalized load to generate
private AgentID phy, rdp, node
private int myAddr
LoadGenerator(List<Integer> destNodes, float load) {
this.destNodes = destNodes
this.load = load
}
def dataMsg = PDU.withFormat
{
uint16('source')
uint16('destination')
}
@Override
void setup()
{
register Services.ROUTING
}
@Override
void startup() {
phy = agentForService Services.PHYSICAL
subscribe phy
node = agentForService Services.NODE_INFO
myAddr = node.Address
rdp = agentForService Services.ROUTE_MAINTENANCE
float dataPktDuration = get(phy, Physical.DATA, PhysicalChannelParam.frameDuration)
// compute average packet arrival rate
float rate = load/dataPktDuration
// create Poisson arrivals at given rate
add new PoissonBehavior(1000/rate, {
rdp << new RouteDiscoveryReq(to: rnditem(destNodes), maxHops: 35, count: 1)
})
}
private void rxDisable()
{
//DisableReceiver
ParameterReq req = new ParameterReq(agentForService(Services.PHYSICAL))
req.get(PhysicalParam.rxEnable)
ParameterRsp rsp = (ParameterRsp) request(req, 1000)
rsp.set(PhysicalParam.rxEnable,false)
}
private void rxEnable()
{
//EnableReceiver
ParameterReq req = new ParameterReq(agentForService(Services.PHYSICAL))
req.get(PhysicalParam.rxEnable)
ParameterRsp rsp = (ParameterRsp)request(req, 1000)
rsp.set(PhysicalParam.rxEnable,true)
}
@Override
void processMessage(Message msg) {
if (msg instanceof RouteDiscoveryNtf && msg.reliability == true) {
phy << new ClearReq() // clear any on-going transmission.
rxDisable()
phy << new TxFrameReq(to: msg.nextHop, type: Physical.DATA, protocol: Protocol.DATA, data: dataMsg.encode([source: myAddr, destination: msg.to]))
add new WakerBehavior(214, {rxEnable()}) // Data packet duration of a 64-byte packet at 2400 bps: 214 ms
}
}
}