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

📄 insignia.cc

📁 INSIGNIA是专门为无线ad hoc网络设计的qos信令协议
💻 CC
📖 第 1 页 / 共 2 页
字号:
  if (!rsv_cache)  {    rsv_cache = (rsvcache *) malloc(sizeof(rsvcache));    rsv_cache->next_ = rsv_tail;    rsv_tail = rsv_cache;    rsv_cache->src_    = iph->src();    rsv_cache->dst_    = iph->dst();    rsv_cache->sport_  = iph->sport();    rsv_cache->dport_  = iph->dport();    rsv_cache->rpt_seq = 0;    rsv_cache->etime   = ctime;    rsv_cache->htime   = ctime;    rsv_cache->htimer  = HTIMER;    rsv_cache->bw_mon  = insh->bw_ind;  }  rsv_cache->msg_type = BM;  rsv_cache->backoff = 0;  rsv_cache->bw_ind  = insh->bw_ind;  return rsv_cache;}rsvcache *INSIGNIA::lookup_rsvcache(Packet *pkt){  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  rsvcache *rsv_c = 0;  rsvcache *rsv_c1;  rsvcache *rsv_c2;  int bw_sum = 0;  if (!rsv_tail)  {    this_bw = 0;    return rsv_c;  }  rsv_c1 = rsv_tail;  while (rsv_c1->next_)  {    rsv_c2 = rsv_c1->next_;    if (rsv_c2->src_ == iph->src_ && 	rsv_c2->dst_ == iph->dst_ && 	rsv_c2->sport_ == iph->sport_ && 	rsv_c2->dport_ == iph->dport_)    {      rsv_c = rsv_c2;      rsv_c->htimer = (rsv_c->htimer + (ctime - rsv_c->htime) * H_FACTOR) / 2;      if (rsv_c->htimer < HTIMER / 5) rsv_c->htimer = HTIMER / 5;      rsv_c->htime = ctime;      if (!rsv_c->backoff) bw_sum -= rsv_c->bw_ind;    }    if (expire_rsvcache(rsv_c2))    {      rsv_c1->next_ = rsv_c2->next_;      free(rsv_c2);    }    else    {      rsv_c1 = rsv_c1->next_;      bw_sum += rsv_c1->bw_ind;    }  }  if (rsv_tail->src_ == iph->src_ &&      rsv_tail->dst_ == iph->dst_ &&      rsv_tail->sport_ == iph->sport_ &&      rsv_tail->dport_ == iph->dport_)  {    rsv_c = rsv_tail;    rsv_c->htimer = (rsv_c->htimer + (ctime - rsv_c->htime) * H_FACTOR) / 2;    if (rsv_c->htimer < HTIMER / 5) rsv_c->htimer = HTIMER / 5;    rsv_c->htime = ctime;    if (!rsv_c->backoff) bw_sum -= rsv_tail->bw_ind;  }  if (expire_rsvcache(rsv_tail))  {    rsv_c2 = rsv_tail;    rsv_tail = rsv_tail->next_;    free(rsv_c2);  }  else  {    bw_sum += rsv_tail->bw_ind;  }  this_bw = bw_sum;  return rsv_c;}intINSIGNIA::expire_rsvcache(rsvcache *rsv_cache){  if ((net_id != rsv_cache->dst_) &&      (ctime - rsv_cache->htime > rsv_cache->htimer))  {    if (ins_tr)    {      fprint_cache(rsv_cache);      fprintf(fp, "htimer expired");    }    return 1;  // expired  }    if (net_id == rsv_cache->src_ && (ctime - rsv_cache->etime > ETIMER))  {    if (ins_tr && rsv_cache->backoff != 2)    {      fprint_cache(rsv_cache);      fprintf(fp, "etimer expired");    }    if (net_id == rsv_cache->src_ &&	ctime < rsv_cache->etime + BACKOFF + ETIMER)    {      if (rsv_cache->backoff != 2) rsv_cache->backoff = 1;      return 0; // backoff    }    return 1;  // expired  }  return 0;  // not expired}voidINSIGNIA::send_QOSreport(Packet *pkt, Handler *h){  hdr_ip* old_iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* old_insh = (hdr_insignia*)pkt->access(off_insignia_);  Packet *p_copy = Packet::alloc();  hdr_cmn *cmnh = (hdr_cmn*)p_copy->access(off_cmn_);  hdr_ip *iph = (hdr_ip*)p_copy->access(off_ip_);  hdr_insignia *insh = (hdr_insignia*)p_copy->access(off_insignia_);  cmnh->ptype_ = PT_CBR;  cmnh->size_  = IP_HDR_LEN + 4;  iph->src_   = old_iph->dst_;  iph->dst_   = old_iph->src_;  iph->sport_ = old_iph->dport_;  iph->dport_ = old_iph->sport_;  iph->ttl_   = 255;  iph->tos_   = RPT;  insh->bw_ind = old_insh->bw_ind;  insh->min_bw = 0;  insh->max_bw = old_insh->max_bw;  if (ins_tr)  {    fprint_pkt(p_copy);    fprintf(fp, "send QOS report");  }  target_->recv(p_copy, h);}voidINSIGNIA::recv_QOSreport(Packet *pkt){  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* insh = (hdr_insignia*)pkt->access(off_insignia_);  rsvcache *rsv_cache;  int i = iph->sport();  nsaddr_t temp_src_ = iph->src_;  nsaddr_t temp_sport_ = iph->sport_;  iph->src_   = iph->dst_;  iph->dst_   = temp_src_;  iph->sport_ = iph->dport_;  iph->dport_ = temp_sport_;  rsv_cache = lookup_rsvcache(pkt);  if (rsv_cache)  {    if (ins_tr)    {      fprint_pkt(pkt);      fprintf(fp, "recv QOS report");    }    if (rsv_cache->backoff)    {      if (ins_tr) fprintf(fp, " ignored");      return;    }    rsv_cache->msg_type = RU;    rsv_cache->etime = ctime;    if (insh->bw_ind > rsv_cache->bw_ind)    {      rsv_cache->scu_cnt += 1;      rsv_cache->scd_cnt = 0;      if (rsv_cache->scu_cnt >= port[i]->adpt_pr)      {	rsv_cache->bw_ind = insh->bw_ind;      }    }    if (insh->bw_ind < rsv_cache->bw_ind)    {      rsv_cache->scu_cnt = 0;      rsv_cache->scd_cnt += 1;      if (rsv_cache->scd_cnt >= port[i]->adpt_pr)      {	rsv_cache->bw_ind = insh->bw_ind;      }    }  }}voidINSIGNIA::local_bw_monitor(Packet *pkt){  struct hdr_mac802_11 *mh = HDR_MAC11(pkt);  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* insh = (hdr_insignia*)pkt->access(off_insignia_);  u_int32_t mac_src = ETHER_ADDR(mh->dh_da);  bwmcache *bwm_c1, *bwm_c2;  int bwm_new = 1;  int bwm_sum = 0;  if (mac_src == mac_id) return;  /* prune bwm_cache and update neighbor_bw */  if (bwm_tail)  {    bwm_c1 = bwm_tail;    while (bwm_c1->next_)    {      bwm_c2 = bwm_c1->next_;      if (bwm_c2->mac_src == mac_src && bwm_c2->src_ == iph->src_	  && bwm_c2->sport_ == iph->sport_ && bwm_c2->dst_ == iph->dst_ &&	  bwm_c2->dport_ == iph->dport_)      {	bwm_new = 0;	bwm_c2->bw_ind = insh->bw_ind;	bwm_c2->btime = ctime;      }      if (ctime - bwm_c2->btime > BTIMER)      {	bwm_c1->next_ = bwm_c2->next_;	free(bwm_c2);      }      else      {	bwm_sum += bwm_c2->bw_ind;	bwm_c1 = bwm_c1->next_;      }    }    if (bwm_tail->mac_src == mac_src && bwm_tail->src_ == iph->src_	&& bwm_tail->sport_ == iph->sport_ && bwm_tail->dst_ == iph->dst_ &&	bwm_tail->dport_ == iph->dport_)    {      bwm_new = 0;      bwm_tail->bw_ind = insh->bw_ind;      bwm_tail->btime = ctime;    }    if (ctime - bwm_tail->btime > BTIMER)    {      bwm_c2 = bwm_tail;      bwm_tail = bwm_tail->next_;      free(bwm_c2);    }  }  if (bwm_new)  {    bwm_sum += insh->bw_ind;    /* add new bwm_cache */    bwm_c1 = (bwmcache *) malloc(sizeof(bwmcache));    bwm_c1->next_ = bwm_tail;    bwm_tail = bwm_c1;    bwm_c1->bw_ind  = insh->bw_ind;    bwm_c1->btime   = ctime;    bwm_c1->mac_src = ETHER_ADDR(mh->dh_da);    bwm_c1->src_    = iph->src();    bwm_c1->dst_    = iph->dst();    bwm_c1->sport_  = iph->sport();    bwm_c1->dport_  = iph->dport();  }  /* update neighbor_bw */  neighbor_bw = bwm_sum;  if (neighbor_bw > 1000) printf("%u\n", neighbor_bw);}voidINSIGNIA::measureSRC(Packet *pkt){  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* insh = (hdr_insignia*)pkt->access(off_insignia_);  int i = iph->sport();  port[i]->src_ = iph->src_;  port[i]->dst_ = iph->dst_;  port[i]->sport_ = iph->sport_;  port[i]->dport_ = iph->dport_;  if (insh->srv_mode == RES)  {    if (insh->pl_ind == BQ)    {      port[i]->s_bqres += 1;    }    else if (insh->pl_ind == EQ)    {      port[i]->s_eqres += 1;    }  }  else if (insh->srv_mode == BE)  {    if (insh->pl_ind == BQ)    {      port[i]->s_bqbe += 1;    }    else if (insh->pl_ind == EQ)    {      port[i]->s_bqbe += 1;    }  }}voidINSIGNIA::measureDST(Packet *pkt){  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* insh = (hdr_insignia*)pkt->access(off_insignia_);  int i = iph->sport();  port[i]->src_ = iph->src_;  port[i]->dst_ = iph->dst_;  port[i]->sport_ = iph->sport_;  port[i]->dport_ = iph->dport_;  float cdelay = ctime - insh->src_time;  port[i]->delay += cdelay;  if (cdelay > port[i]->maxdelay) port[i]->maxdelay = cdelay;  if (cdelay < port[i]->mindelay) port[i]->mindelay = cdelay;  if (insh->srv_mode == RES)  {    if (insh->pl_ind == BQ)    {      port[i]->r_bqres += 1;    }    else if (insh->pl_ind == EQ)    {      port[i]->r_eqres += 1;    }      port[i]->res_delay += cdelay;      if (cdelay > port[i]->res_maxdelay) port[i]->res_maxdelay = cdelay;      if (cdelay < port[i]->res_mindelay) port[i]->res_mindelay = cdelay;  }  else if (insh->srv_mode == BE)  {    if (insh->pl_ind == BQ)    {      port[i]->r_bqbe += 1;    }    else if (insh->pl_ind == EQ)    {      port[i]->r_bqbe += 1;    }    port[i]->be_delay += cdelay;    if (cdelay > port[i]->be_maxdelay) port[i]->be_maxdelay = cdelay;    if (cdelay < port[i]->be_mindelay) port[i]->be_mindelay = cdelay;  }}voidINSIGNIA::fprint_pkt(Packet *pkt){  hdr_ip* iph = (hdr_ip*)pkt->access(off_ip_);  hdr_insignia* insh = (hdr_insignia*)pkt->access(off_insignia_);  fprintf(fp, "\n%6.2f : ", ctime);  if (net_id == iph->src_) fprintf(fp, "s ");  else if (net_id == iph->dst_) fprintf(fp, "d ");  else fprintf(fp, "h ");  fprintf(fp, "%d %2d:%d %2d:%d [%u %u %3u %3u %3u] ", net_id, iph->src_, iph->sport_, iph->dst_, iph->dport_, insh->srv_mode, insh->pl_ind, insh->bw_ind, insh->min_bw, insh->max_bw);}voidINSIGNIA::fprint_cache(rsvcache *rsv_cache){  fprintf(fp, "\n%6.2f : ", ctime);  if (net_id == rsv_cache->src_) fprintf(fp, "s ");  else if (net_id == rsv_cache->dst_) fprintf(fp, "d ");  else fprintf(fp, "h ");  fprintf(fp, "%d %2d:%d %2d:%d [x x %3u   x   x] ", net_id, rsv_cache->src_, rsv_cache->sport_, rsv_cache->dst_, rsv_cache->dport_, rsv_cache->bw_ind);}voidINSIGNIA::fprint_sum(int i){  int send_    = port[i]->s_bqres + port[i]->s_bqbe                 + port[i]->s_eqres + port[i]->s_eqbe;  int recv_    = port[i]->r_bqres + port[i]->r_bqbe                + port[i]->r_eqres + port[i]->r_eqbe;  int recv_res = port[i]->r_bqres + port[i]->r_eqres;  int recv_be  = port[i]->r_bqbe  + port[i]->r_eqbe;  float avg_delay, res_avg_delay, be_avg_delay;  if (recv_ == 0) avg_delay = 0;  else avg_delay = port[i]->delay / recv_;  if (recv_res == 0) res_avg_delay = 0;  else res_avg_delay = port[i]->res_delay / recv_res;  if (recv_be == 0) be_avg_delay = 0;  else be_avg_delay = port[i]->be_delay / recv_be;  fprintf(fp, "\n------+---------------+---------------+-------+-------+-------");  fprintf(fp, "\n  ID  |     Sent      |   Received    | Delay :  Min  :  Max");  fprintf(fp, "\n------+---------------+---------------+-------+-------+-------");  fprintf(fp, "\n SRC  | ALL           | ALL           |  ALL  |  ALL  |  ALL");  fprintf(fp, "\n DST  | BQ/RES EQ/RES | BQ/RES EQ/RES |  RES  |  RES  |  RES");  fprintf(fp, "\n      | BQ/BE  EQ/BE  | BQ/BE  EQ/BE  |  BE   |  BE   |  BE");  fprintf(fp, "\n------+---------------+---------------+-------+-------+-------");  fprintf(fp, "\n %2u:%1u | ", port[i]->src_, port[i]->sport_);  if (send_ == 0) fprintf(fp, "              | ");  else fprintf(fp, "%6d        | ", send_);  if (recv_ == 0) fprintf(fp, "              | ");  else fprintf(fp, "%6d        | ", recv_);  if (port[i]->delay == 0) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", avg_delay);  if (port[i]->mindelay == 100) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", port[i]->mindelay);  if (port[i]->maxdelay == 0) fprintf(fp, " ");  else fprintf(fp, "%5.2f", port[i]->maxdelay);  fprintf(fp, "\n %2u:%1u | ", port[i]->dst_, port[i]->dport_);  if (port[i]->s_bqres == 0) fprintf(fp, "       ");  else fprintf(fp, "%6d ", port[i]->s_bqres);  if (port[i]->s_eqres == 0) fprintf(fp, "       | ");  else fprintf(fp, "%6d | ", port[i]->s_eqres);  if (port[i]->r_bqres == 0) fprintf(fp, "       ");  else fprintf(fp, "%6d ", port[i]->r_bqres);  if (port[i]->r_eqres == 0) fprintf(fp, "       | ");  else fprintf(fp, "%6d | ", port[i]->r_eqres);  if (port[i]->res_delay == 0) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", res_avg_delay);  if (port[i]->res_mindelay == 100) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", port[i]->res_mindelay);  if (port[i]->res_maxdelay == 0) fprintf(fp, " ");  else fprintf(fp, "%5.2f", port[i]->res_maxdelay);  fprintf(fp, "\n      | ");  if (port[i]->s_bqbe == 0) fprintf(fp, "       ");  else fprintf(fp, "%6d ", port[i]->s_bqbe);  if (port[i]->s_eqbe == 0) fprintf(fp, "       | ");  else fprintf(fp, "%6d  | ", port[i]->s_eqbe);  if (port[i]->r_bqbe == 0) fprintf(fp, "       ");  else fprintf(fp, "%6d ", port[i]->r_bqbe);  if (port[i]->r_eqbe == 0) fprintf(fp, "       | ");  else fprintf(fp, "%6d | ", port[i]->r_eqbe);  if (port[i]->be_delay == 0) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", be_avg_delay);  if (port[i]->be_mindelay == 100) fprintf(fp, "      | ");  else fprintf(fp, "%5.2f | ", port[i]->be_mindelay);  if (port[i]->be_maxdelay == 0) fprintf(fp, " ");  else fprintf(fp, "%5.2f", port[i]->be_maxdelay);  fprintf(fp, "\n------+---------------+---------------+-------+-------+------");}

⌨️ 快捷键说明

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