我已经编写了一个代理并添加到节点 1 以使用 RemoteGetParamReq 获取节点 2 的物理参数(传播速度、节点能量等),该方法在代理 startup() 方法中工作。如何根据需要在代理 processRequest() 方法中使用 RemoteGetParamReq当节点 1 触发 DatagramReq 时获取远程节点 2 的参数值,以便我可以获得最新的参数值。
class MyRemoteParam extends UnetAgent {
AgentID phy,rmt
RemoteGetParamReq req
Message rsp
@Override
protected void setup() {
super.setup()
register(Services.PHYSICAL);
register(Services.DATAGRAM);
}
void startup() {
phy = agentForService Services.PHYSICAL
rmt= agentForService Services.REMOTE
req = new RemoteGetParamReq();
req.setRecipient(rmt);
req.setRemoteAgentID(phy);
req.setTo(2);
req.get(PhysicalParam.propagationSpeed);
req.get(PhysicalParam.timestampedTxDelay);
req.get(MyEnergyParameters.init_energy);
rsp = phy.request(req, 2000);
System.out.println "Node 2 propogation speed:"+rsp.get(PhysicalParam.propagationSpeed)
System.out.println "Node 2 energy:"+rsp.get(MyEnergyParameters.init_energy)
}
@Override
Message processRequest(Message msg) {
if (msg instanceof DatagramReq) {
req = new RemoteGetParamReq();
req.setRecipient(rmt);
req.setRemoteAgentID(phy);
req.setTo(2);
req.get(PhysicalParam.propagationSpeed);
req.get(PhysicalParam.timestampedTxDelay);
req.get(MyEnergyParameters.init_energy);
rsp = phy.request(req, 2000);
System.out.println "Node 2 propogation speed:"+rsp.get(PhysicalParam.propagationSpeed)
System.out.println "Node 2 energy:"+rsp.get(MyEnergyParameters.init_energy)
return new Message(msg, Performative.AGREE)
}
return null
}//end of processrequest
}//end of MyRemoteParam class