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

📄 macedon-macros.h

📁 这是一个著名的应用层组播中间件的源码
💻 H
字号:
//Copyright (c) 2004, Charles Killian, Adolfo Rodriguez, Dejan Kostic, Sooraj Bhat, and Amin Vahdat//All rights reserved.////Redistribution and use in source and binary forms, with or without//modification, are permitted provided that the following conditions are met:////   * Redistributions of source code must retain the above copyright//     notice, this list of conditions and the following disclaimer.//   * Redistributions in binary form must reproduce the above copyright//     notice, this list of conditions and the following disclaimer in//     the documentation and/or other materials provided with the//     distribution.//   * Neither the names of Duke University nor The University of//     California, San Diego, nor the names of its contributors//     may be used to endorse or promote products derived from//     this software without specific prior written permission.////THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"//AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE//IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE//FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL//DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,//OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./** * General-purpose macros for all MACEDON_Agents */#ifndef _MACEDON_MACROS_H#define _MACEDON_MACROS_Hextern int random_integer(int maximum);#define foreach_neighbor(t,a,A)  for (t a=(A).entries + (A).count - 1; a >= (A).entries; a--) #define me		here_.addr_ inline int hashof(int x)		{ return macedon_hash(x); } inline int randint(int x)		{ return random_integer(x); }inline double randdouble(double x)	{ return drand48()*x; }  #define timer_cancel(x) \ { \timer_##x->stop(); /*sprintf(trace_buf_,"Timer:  Cancelled timer "#x"\n"); trace_print(); */ \}    #define print_addr(x)	\ { \debug_macro( "REPLAY Address "#x" = %.8x\n", x); \}#define exception(x)	\ { \debug_macro("Exception:  Macedon ordered exception %d\n", x); exit(x); \}#define neighbor_size(n)	(n).count #define neighbor_query(n,who)  	(n).is_neighbor(who) #define neighbor_clear(n)  	(n).neighbor_clearit() #define neighbor_random(n)	((n).rand_neighbor()) #define neighbor_space(n) 	((n).count < (n).maxsize()) #define neighbor_entry(n,who)	((n).neighbor_entry(who)) #define neighbor_closest(n)	((n).neighbor_closest()) #define neighbor_worst(n)	((n).neighbor_worst()) #define neighbor_info(n,who,y)	neighbor_entry(n,who)->y #define neighbor_empty(n)	((n).count <= 0)#define neighbor_query_field(n,y,v,test) \  { \    test = false; \    for (int _idx_=0; _idx_<(n).count; _idx_++) \    { \      if ((n).entries[_idx_].y == v) \      { \        test = true; \        break; \      } \    }  \  } #define neighbor_field_ipaddr(n,y,v,ip) \  { \    ip = 0; \    for (int _idx_=0; _idx_<(n).count; _idx_++) \    { \      if ((n).entries[_idx_].y == v) \      { \        ip = (n).entries[_idx_].ipaddr; \        break; \      } \    }  \  } #define neighbor_add(n,who) \  { \ if ((n).count >= (n).maxsize()) \ { \  dump_state(); \  pthread_mutex_lock(&debug_lock); \  sprintf(trace_buf_, "Exception: Neighbor size %d exceeded at %d ", (n).maxsize(), (n).count); \  char *temp = trace_buf_ + strlen(trace_buf_); \  sprintf(temp,"%s", "for " #n " adding " #who "\n"); \  trace_print(); \  pthread_mutex_unlock(&debug_lock); \  exit(67); \ } \ neighbor_clear(((n).entries[(n).count])); \ (n).entries[(n).count].ipaddr = who; \ (n).entries[(n).count].time_last_heard = curtime; \ (n).count++;  \ }#define upcall_notify(n, type) \    { \      int *addr_list=NULL;\      if((n).count > 0) { \   addr_list = (int *)malloc(sizeof(int)*(n).count);\   if (addr_list == NULL) {\     printf("Malloc exception 3!\n");\     exit(72);\   }\      }\   for (int _idx_=0; _idx_<(n).count; _idx_++) \   { \     addr_list[_idx_] = (n).entries[_idx_].ipaddr; \   }  \   if (notify_handler)\     (* notify_handler)(type, (n).count, addr_list);\   if(addr_list != NULL) {::free(addr_list);} \   }    #define neighbor_remove(n, who) \  neighbor_remove_stable(n, who)/*{ \  for (int _idx_=0; _idx_<(n).count; _idx_++) \  { \    if ((n).entries[_idx_].ipaddr == who) \    { \      (n).entries[_idx_].neighbor_copy(&((n).entries[(n).count-1])); \        neighbor_clear((n).entries[(n).count-1]); \        (n).count--; \    } \  }  \}*/  #define neighbor_remove_stable(n, who) \  do { \    int matches=0;\    for (int _idx_=0; _idx_<(n).count; _idx_++) \    { \      if ((n).entries[_idx_].ipaddr == who) \      { \        matches++;\        if(_idx_+matches < (n).count) {\          (n).entries[_idx_].neighbor_copy(&((n).entries[_idx_+matches])); \        } \        (n).count--; \      } else if(matches>0) {\        (n).entries[_idx_].neighbor_copy(&((n).entries[_idx_+matches])); \      }\    }  \    if(matches>0) { \      for( int _idx_=0; _idx_<matches; _idx_++) { \        neighbor_clear((n).entries[(n).count+_idx_]); \      } \    } \  } while(0)  #define upcall_deliver(msg,size, type) \     if (deliver_handler) (*deliver_handler) (msg,size,type); else  #define upcall_forward(x,msg,size, type) \     ( forward_handler ? (*forward_handler) (msg,size,type,x,macedon_hash(x)) : 0 )  #define upcall_ext(func, arg) \     ( upcall_handler ? (*upcall_handler) (func, arg) : -1 )  #define replay_experiment() \ { \     debug_macro("REPLAY_EXPERIMENT %s 0 %d %d %d %d\n", \     get_hostname(), topo_, topo_nodes_, num_nodes_, seed_); \}  #define replay_init() \ { \     debug_macro("REPLAY_INIT %s 0\n", get_hostname()); \}  #define replay_add(from) \ { \      if ((from & htonl(0x0a000000)) == htonl(0x0a000000)) \      { \        debug_macro("REPLAY_ADD %s %s\n", get_hostname(from), get_hostname()); \      } \      else \      { \	      debug_macro("REPLAY_ADD %x %s\n", from, get_hostname()); \      } \}  /*  #define replay_add(from) \ *//*   { \ *//*       sprintf(trace_buf_,"REPLAY_ADD %x %s\n", from, get_hostname()); \ *//*       trace_print(); \ *//*  } */    #define replay_remove(from) \ { \     debug_macro("REPLAY_REMOVE %x %s\n", from, get_hostname()); \}  #define replay_delay(from, delay) \ { \     debug_macro("REPLAY_DELAY %s %f\n", get_hostname(from), delay); \}  #ifdef NSPORT#define prep_pkt(proto) \  size_ = size;\  Packet *p;\  p = macedon_pkt_alloc();\  hdr_ip*  ih = gethdrip( p );\  hdr_##proto * proto##h = gethdr##proto( p );\  hdr_cmn* ch = gethdrcmn( p );\  bzero(proto##h, sizeof(hdr_##proto));\  prev_send_seqno_++;\  ih->ttl_ = MACEDON_BIG_TTL;\  ih->dst_.port_ = 1; \  ih->src_.port_ = 1;\  ch->size() = size_ + 0;\  ih->src_.addr_ = 0;\  if (msg)\    {\      p->data_ = (unsigned char *)malloc(size);\      if (p->data_ == 0) {\        printf("Malloc exception 3!\n");\        exit(72);\      }\      bcopy(msg, p->data_, size);\     }#else#define prep_pkt(proto) \  size_ = size;\  Packet *p;\  p = macedon_pkt_alloc();\  hdr_ip*  ih = gethdrip( p );\  hdr_##proto * proto##h = gethdr##proto( p );\  hdr_cmn* ch = gethdrcmn( p );\  bzero(proto##h, sizeof(hdr_##proto));\  prev_send_seqno_++;\  proto##h->proto##_mf_.mh_time_sent_ = curtime;\  ih->ttl_ = MACEDON_BIG_TTL;\  ih->dst_.port_ = 1; \  ih->src_.port_ = 1;\  ch->size() = size_ + 0;\  ih->src_.addr_ = 0;#endif#define create_group(group_id) \  if(base_agent) {\    base_agent->macedon_create_group(group_id);\  }#define join(group_id) \  if(base_agent) {\    base_agent->macedon_join(group_id);\  }#define leave(group_id)\  if(base_agent) {\    base_agent->macedon_leave(group_id);\  }#define downcall_ext(x, func, arg)\  x = -1;\  if(base_agent) {\    x = base_agent->macedon_downcall_ext(func, arg);\  }extern pthread_mutex_t debug_lock;#define debug_macro(args...) \  { \    pthread_mutex_lock(&debug_lock); \    sprintf(trace_buf_,args);\    trace_print();\    pthread_mutex_unlock(&debug_lock); \  }#endif // _MACEDON_MACROS_H

⌨️ 快捷键说明

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