⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rp-agent.cc

📁 模拟器提供了一个简单易用的平台
💻 CC
字号:
/************************************************** *  File: rp-agent.cc  Author: Suman Banerjee <suman@cs.umd.edu>  Date: 15th March, 2001  Terms: GPL  Narada implementation in myns  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ***************************************************/#include <assert.h>#include "misc.h"#include "rp-agent.h"void rpAgent::init (int Id, int Index, Node *N) {  Agent::init(Id,Index,N);  t = AGENT_APPLICATION_RP;  rp_id = id;  return;}void rpAgent::start (void) {  Agent::start();  return;}void rpAgent::specific_rx_pkt_handler  (Packet *p) {  if (p->t != PACKET_APP) {     printf ("[Err] RP received unknown packet type\n");     return;  }  AppPacket *ap = (AppPacket *)p;  switch (ap->st) {    case PING_RP :      handle_rp_ping(ap);      break;    default :      printf ("[Err] RP received unknown packet subtype\n");  }  return;}void rpAgent::handle_rp_ping (AppPacket *p) {  assert (p->st == PING_RP);  /* Create ping response packet */  AppPacket *resp_p = new AppPacket(PING_RP_RESPONSE);  resp_p->u.pingresp_p.ret_nbr_cnt = p->u.ping_p.seek_nbr_cnt;  if (resp_p->u.pingresp_p.ret_nbr_cnt > mc_agent_list.GetSize())    resp_p->u.pingresp_p.ret_nbr_cnt = mc_agent_list.GetSize();  int *ret_indices = get_rand_set(resp_p->u.pingresp_p.ret_nbr_cnt,mc_agent_list.GetSize());  int ind = 0;  int running_index = 0;  for (void *pos = mc_agent_list.GetHeadPosition();       pos != NULL;       mc_agent_list.GetNext(pos) ) {    if (ret_indices[ind] == running_index) {      AgentInfo *a = mc_agent_list.GetAt(pos);      resp_p->u.pingresp_p.ret_nbrs[ind].agent_id = a->agent_id;      resp_p->u.pingresp_p.ret_nbrs[ind].node_id = a->node_id;      ind ++;    }    running_index ++;  }  delete [] ret_indices;  send_pkt(resp_p,p->src_agent,p->src);  /* Add this agent to the agent list */  AgentInfo *ai = new AgentInfo (p->src_agent,p->src);  mc_agent_list.Add(ai,p->src_agent);  return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -