📄 macedon-conv.c
字号:
} temp = temp->next; } fprintf(cfile, " Unlock();\n"); fprintf(cfile, "}\n");}command_function(){ fprintf(cfile, "int %s_Agent::command(int argc, const char*const* argv)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " if (strcmp(argv[1], \"join\") == 0)\n"); fprintf(cfile, " {\n"); fprintf(cfile, " utility_timer_.start(MACEDON_UTIL_TIMER_VALUE); \n"); fprintf(cfile, " macedon_init();\n"); if (base_name) fprintf(cfile, " base_agent->command(argc, argv);\n"); fprintf(cfile, " }\n"); fprintf(cfile, " if (strcmp(argv[1], \"dump-overlay\") == 0)\n"); fprintf(cfile, " {\n"); fprintf(cfile, " dump_state();\n"); fprintf(cfile, " debug_macro(\"REPLAY_PAYLOAD %%qd\\n\", bytes_sent/1000);\n"); if (base_name) fprintf(cfile, " base_agent->command(argc, argv);\n"); fprintf(cfile, " }\n"); fprintf(cfile, "}\n"); fprintf(cfile, "\n");}create_function(){ message *temp = my_messages; message_field *field; while (temp) { fprintf(cfile, "char* %s_Agent::create_%s(int &bufsize, int toaddr", protocol_name, temp->simple_name); field = temp->fields; while (field) { if (!strcmp(field->field_size,"1")) { fprintf(cfile,", %s %s", field->field_type, field->field_nickname); } else { fprintf(cfile,", %s* %s", field->field_type, field->field_nickname); } field = field->next; } fprintf(cfile,", char* msg, int size) \n"); fprintf(cfile,"{\n"); fprintf(cfile," char* buffer = new char[sizeof(hdr_%s_%s)+size];\n", protocol_name, temp->simple_name); fprintf(cfile," ASSERT(buffer != NULL);\n"); fprintf(cfile," bzero(buffer, sizeof(hdr_%s_%s)+size);\n", protocol_name, temp->simple_name); fprintf(cfile," ((macedon_fields*)buffer)->mh_type_ = %s;\n", temp->message_name); fprintf(cfile," ((macedon_fields*)buffer)->mh_dest_addr_ = toaddr;\n"); if (addressing == AD_HASH) fprintf(cfile," ((macedon_fields*)buffer)->mh_src_addr_ = macedon_hash(here_.addr_);\n"); else fprintf(cfile," ((macedon_fields*)buffer)->mh_src_addr_ = here_.addr_;\n");#ifndef VARIABLE_HEADERS fprintf(cfile," bufsize=sizeof(hdr_%s_%s);\n", protocol_name, temp->simple_name); fprintf(cfile," hdr_%s_%s* outhdr = (hdr_%s_%s*)buffer; \n", protocol_name, temp->simple_name, protocol_name, temp->simple_name);#else fprintf(cfile," ((struct macedon_fields*)buffer)->mh_expanded_size_=sizeof(hdr_%s_%s); \n", protocol_name, temp->simple_name); fprintf(cfile," char* outhdr = buffer; \n"); fprintf(cfile," int position=sizeof(hdr_%s); \n",protocol_name);#endif fill_pkt(temp, cfile, "\n");#ifdef VARIABLE_HEADERS fprintf(cfile," ASSERT(position <= sizeof(hdr_%s_%s)+size\n", protocol_name, temp->simple_name); fprintf(cfile," bufsize = position;\n");#endif fprintf(cfile," if(size > 0) {\n"); fprintf(cfile," bcopy(msg, buffer+bufsize, size);\n"); fprintf(cfile," bufsize+=size;\n"); fprintf(cfile," }\n"); fprintf(cfile," return buffer;\n"); fprintf(cfile,"}\n\n"); temp = temp->next; } temp = my_messages; fprintf(cfile, "Packet * %s_Agent::create_pkt(int type, int toaddr)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " Packet* p;\n"); fprintf(cfile, " p = macedon_pkt_alloc();\n"); fprintf(cfile, " hdr_ip * iphdr = gethdrip( p );\n"); fprintf(cfile, " hdr_%s* hdr = gethdr%s( p );\n", protocol_name, protocol_name); fprintf(cfile, " hdr_cmn* ch = gethdrcmn( p );\n"); fprintf(cfile, "\n");#ifdef ALLINONEDHDR fprintf(cfile, " bzero(hdr, sizeof(hdr_%s));\n", protocol_name);#else while (temp) { fprintf(cfile, " if(type == %s)\n", temp->message_name); fprintf(cfile, " {\n"); fprintf(cfile, " bzero(hdr, sizeof(hdr_%s_%s));\n", protocol_name, temp->simple_name); fprintf(cfile, " p->hdrlen_ = sizeof(hdr_cmn) + sizeof(hdr_ip) + sizeof(hdr_%s_%s);\n", protocol_name, temp->simple_name); fprintf(cfile, " }\n"); temp = temp->next; }#endif fprintf(cfile, " iphdr->dst_.addr_ = toaddr;\n"); fprintf(cfile, " iphdr->dst_.port_ = 0;\n"); fprintf(cfile, " iphdr->src_.port_ = 0;\n"); fprintf(cfile, " iphdr->fid_ = type; \n"); fprintf(cfile, " hdr->%s_mf_.mh_type_ = type;\n", protocol_name); fprintf(cfile, " hdr->%s_mf_.mh_dest_addr_ = toaddr;\n", protocol_name); if (addressing == AD_HASH) fprintf(cfile, " hdr->%s_mf_.mh_src_addr_ = macedon_hash(here_.addr_);\n", protocol_name); else fprintf(cfile, " hdr->%s_mf_.mh_src_addr_ = here_.addr_;\n", protocol_name); fprintf(cfile, " ch->size() = 0;\n"); /* fprintf(cfile, " debug_macro(\"Packet: allocated packet with destination %%.8x and type %%d\\n\", iphdr->dst_.addr_, iphdr->fid_ );"); */ fprintf(cfile, " return p;\n"); fprintf(cfile, "}\n\n");}register_function(){ fprintf(cfile, "void \n"); fprintf(cfile, "%s_Agent::macedon_register_handlers(macedon_forward_handler fr, macedon_deliver_handler dl, macedon_notify_handler nl, macedon_upcall_handler ul)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, "forward_handler = fr;\n"); fprintf(cfile, "deliver_handler = dl;\n"); fprintf(cfile, "notify_handler = nl;\n"); fprintf(cfile, "upcall_handler = ul;\n"); fprintf(cfile, "return;\n"); fprintf(cfile, "}\n");}dumppkt_function(){ char *hdr_string = (char *) malloc (400); message *temp = my_messages; message_field *field; declare *mytempfields; fprintf(cfile, "void %s_Agent::dump_packet(Packet *p, char *descrip, int recv_flag)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " hdr_ip * iphdr = gethdrip( p );\n"); fprintf(cfile, " hdr_%s* hdr = gethdr%s( p );\n", protocol_name, protocol_name); fprintf(cfile, " hdr_cmn* ch = gethdrcmn( p );\n"); fprintf(cfile, " struct macedon_fields *mf = getmacedonfields(p);\n"); fprintf(cfile, " Lock_Write();\n"); fprintf(cfile, " char *temp_trace = trace_buf_;\n"); fprintf(cfile, " int i;\n"); fprintf(cfile, " int j;\n"); fprintf(cfile, "\n"); fprintf(cfile, " if (recv_flag==0)\n"); fprintf(cfile, " { debug_macro(\"%%.8x -> %%.8x (%%d)\\n\", hdr->%s_mf_.mh_src_addr_, hdr->%s_mf_.mh_dest_addr_, hdr->%s_mf_.mh_type_); }\n", protocol_name, protocol_name, protocol_name); fprintf(cfile, " else if (recv_flag==2)\n"); fprintf(cfile, " { debug_macro(\"%%.8x +> %%.8x (%%d)\\n\", hdr->%s_mf_.mh_src_addr_, hdr->%s_mf_.mh_dest_addr_, hdr->%s_mf_.mh_type_); }\n", protocol_name, protocol_name, protocol_name); fprintf(cfile, " else if (recv_flag==3)\n"); fprintf(cfile, " { debug_macro(\"%%.8x <+ %%.8x (%%d)\\n\", hdr->%s_mf_.mh_dest_addr_, hdr->%s_mf_.mh_src_addr_, hdr->%s_mf_.mh_type_); }\n", protocol_name, protocol_name, protocol_name); fprintf(cfile, " else if (recv_flag==1)\n"); fprintf(cfile, " { debug_macro(\"%%.8x <- %%.8x (%%d)\\n\", hdr->%s_mf_.mh_dest_addr_, hdr->%s_mf_.mh_src_addr_, hdr->%s_mf_.mh_type_); }\n", protocol_name, protocol_name, protocol_name); fprintf(cfile, " else \n"); fprintf(cfile, " abort();\n"); if(tracing >= 2) { fprintf(cfile, "if (hdr->%s_mf_.mh_type_ >= MH_TYPE_HIGHER)\n", protocol_name); fprintf(cfile, "{\n"); /* fprintf(cfile, " debug_macro(\"Packet: seq number %%d\\n\", mf->mh_send_seqno_);\n"); */ temp = my_messages; while (temp) {#ifndef ALLINONEHDR fprintf(cfile, " if (hdr->%s_mf_.mh_type_ == %s)\n", protocol_name, temp->message_name); fprintf(cfile, " {\n"); fprintf(cfile, " hdr_%s_%s *hdr_%s = (hdr_%s_%s *)hdr;\n", protocol_name, temp->simple_name, temp->simple_name, protocol_name, temp->simple_name); sprintf(hdr_string, "hdr_%s", temp->simple_name);#else sprintf(hdr_string, "hdr");#endif field = temp->fields; while (field) {#ifdef ALLINONEHDR if (!field->field_dupe) {#endif if (!strcmp(field->field_size, "1")) { fprintf(cfile, " temp_trace = trace_buf_;\n"); if (!strcmp(field->field_type, "int")) { fprintf(cfile, " debug_macro(\"Fi: %s %%.8x\\n\", %s->%s);\n", field->field_name, hdr_string, field->field_name); } else if (!strcmp(field->field_type, "double")) { fprintf(cfile, " debug_macro(\"Fi: %s %%f\\n\", %s->%s);\n", field->field_name, hdr_string, field->field_name); } else if (!strncmp(field->field_type, "candidate_set", 13)) { fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " sprintf(trace_buf_,\"Fi: %s \");\n", field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " %s->%s.dumpem(temp_trace); \n", hdr_string, field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); } else if (field->neighbor) { fprintf(cfile, " if (%s->%s.count > 0)\n", hdr_string, field->field_name); fprintf(cfile, " {\n"); fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " sprintf(temp_trace,\"Fi: neigh %s [%%d]: \", %s->%s.count);\n", field->field_name, hdr_string, field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " for(i=0; i<%s->%s.count; i++)\n", hdr_string, field->field_name); fprintf(cfile, " {\n"); fprintf(cfile, " sprintf(temp_trace,\"[%%d] %%.8x %%f \", i, %s->%s.entries[i].ipaddr, %s->%s.entries[i].delay);\n", hdr_string, field->field_name, hdr_string, field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); if (field->neighbor) { mytempfields = field->neighbor->fields; while (mytempfields) { if (!strcmp(mytempfields->type, "int")) fprintf(cfile, " sprintf(temp_trace,\"%%.8x \", %s->%s.entries[i].%s);\n", hdr_string, field->field_name, mytempfields->name); mytempfields = mytempfields->next; fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); } } fprintf(cfile, " }\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); fprintf(cfile, " }\n"); } } else { fprintf(cfile, " for(i=0; i<%s; i++)\n", field->field_size); fprintf(cfile, " {\n"); if (!strcmp(field->field_type, "int")) { fprintf(cfile, " debug_macro(\"Fi: %s[%%d] %%d\\n\", i, %s->%s);\n", field->field_name, hdr_string, field->field_name); } else if (!strcmp(field->field_type, "double")) { fprintf(cfile, " debug_macro(\"Fi: %s[%%d] %%d\\n\", i, %s->%s);\n", field->field_name, hdr_string, field->field_name); } else if (field->neighbor) { fprintf(cfile, " if (%s->%s[i].count > 0)\n", hdr_string, field->field_name); fprintf(cfile, " {\n"); fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " temp_trace = trace_buf_;\n"); fprintf(cfile, " sprintf(temp_trace,\"Fi: neigh %s[%%d] [%%d]: \", i, %s->%s[i].count);\n", field->field_name, hdr_string, field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " for(j=0; j<%s->%s[i].count; j++)\n", hdr_string, field->field_name); fprintf(cfile, " {\n"); fprintf(cfile, " sprintf(temp_trace,\"[%%d] %%.8x %%f \", j, %s->%s[i].entries[j].ipaddr, %s->%s[i].entries[j].delay);\n", hdr_string, field->field_name, hdr_string, field->field_name); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); mytempfields = field->neighbor->fields; while (mytempfields) { if (!strcmp(mytempfields->type, "int")) fprintf(cfile, " sprintf(temp_trace,\"%%.8x \", %s->%s[i].entries[j].%s);\n", hdr_string, field->field_name, mytempfields->name); mytempfields = mytempfields->next; fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); } fprintf(cfile, " }\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); fprintf(cfile, " }\n"); } fprintf(cfile, " }\n"); }#ifdef ALLINONEHDR }#endif field = field->next; }#ifndef ALLINONEHDR fprintf(cfile, " }\n");#endif temp = temp->next; } fprintf(cfile, "}\n"); } if(tracing >= 3) { fprintf(cfile, " debug_macro(\"dumping header hex\");\n"); fprintf(cfile, " dump_hex(p->bits_, p->hdrlen_);\n"); fprintf(cfile, " debug_macro(\"dumping data hex\");\n"); fprintf(cfile, " dump_hex(p->data_, p->size_);\n"); } fprintf(cfile, " Unlock();\n"); fprintf(cfile, " return;\n"); fprintf(cfile, "}\n\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -