📄 input.c
字号:
if (mid_to_relay == 1) { /* send out that MID packet even the jitter time has not expired */ for (ifp = ifnet; ifp; ifp = ifp->int_next) { if (debug_level > 3) { printf ("XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY MID! XXXXXXXXXXXXXXXXXXXXXXX\n"); printf ("XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) MID sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY MID! XXXXXXXXXXXXXXXXXXXXXXX\n"); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) MID sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); } mid_build((struct sockaddr *)NULL,(struct hello_message *)NULL, (struct tc_message *)NULL, &midpacket_relay, (struct hna_message *)NULL, 0, ifp, 1); tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); } /* free memory */ olsr_destroy_mid_message(&midpacket_relay); midpacket_relay.mid_interface_address=NULL; mid_to_relay = 0; mid_relay_interval = 0; mid_relay_size = 0; } /***** set the timer to relay the mid *****/ olsr_copy_mid_packet(midpacket_out, &midpacket_relay); /***** set the timer to relay the tc *****/ /* relay jitter is 1/4 of HELLO_INTERVAL */ mid_relay_jitter = (float) random()/(((double)RAND_MAX +1)/((double)HELLO_INTERVAL/4)); if (debug_level > 3) { printf (" ----- mid relay jetter is: %f\n", mid_relay_jitter); fprintf (y_file," ----- mid relay jetter is: %f\n", mid_relay_jitter); } mid_to_relay = 1; mid_relay_size = ntohs(m->olsr_msgsize); //remember the size of the MID /*** free the memery ***/ olsr_destroy_mid_message(midpacket_out); } break; /****************** end of revision ************/ //CRC HNA add case HNA_PACKET: hna_chgestruct(&hnapacket_in, m, from, index); //"index" added by Y.Ge olsr_process_received_hna(index, &hnapacket_in, &hnapacket_out); //"index" added by Y.Ge if (hnapacket_out) { //toall(hna_build, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL, hnapacket_out, (struct interface *)NULL); //commented by Y.Ge /************** added by Y.Ge **************/ /***** check if there is already another TC packet to be relayed *****/ if (hna_to_relay ==1) { /* send out that TC packet even the jitter time has not expired */ for (ifp = ifnet; ifp; ifp = ifp->int_next) { if (debug_level > 3) { printf ("XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY HNA! XXXXXXXXXXXXXXXXXXXXXXX\n"); printf ("XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) HNA sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX send out the OLD RELAY HNA! XXXXXXXXXXXXXXXXXXXXXXX\n"); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) HNA sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); } hna_build((struct sockaddr *)NULL,(struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,&hnapacket_relay , 0, ifp, 1); tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); } /* free memory */ olsr_destroy_hna_message (&hnapacket_relay); hnapacket_relay.hna_net_addrs = NULL; hna_to_relay = 0; hna_relay_interval = 0; hna_relay_size = 0; } olsr_copy_hna_packet(hnapacket_out, &hnapacket_relay); /***** set the timer to relay the hna *****/ /* relay jitter is 1/4 of HELLO_INTERVAL */ hna_relay_jitter = (float) random()/(((double)RAND_MAX +1)/((double)HELLO_INTERVAL/4)); if (debug_level > 3) { printf (" ----- hna relay jetter is: %f\n", hna_relay_jitter); fprintf (y_file," ----- hna relay jetter is: %f\n", hna_relay_jitter); } hna_to_relay = 1; hna_relay_size = ntohs(m->olsr_msgsize); //remember the size of the HNA /*** free the memery ***/ olsr_destroy_hna_message (hnapacket_out); /*************** end of rrevision **********/ } break; default: /************** added by Y.Ge *************/ /* make sure I won't process QoS TC twice */ if (m->olsr_ttl > 1 && !qos_tc_rcvd) { /* * even if the node doesn't understand what is the received packet, * it still check if the message should be forwarded */ if (debug_level > 3) { printf ("******** UNKNOWN message! I may need to forward this message! ********\n"); fprintf (y_file,"******** UNKNOWN message I may need to forward this message! ********\n"); } relay_unknown_pk = olsr_forward_unknown_packets (m->olsr_msgtype,&(((struct sockaddr_in6 *)from)->sin6_addr),&m->olsr_source,ntohs(m->olsr_msgseq),index); if (relay_unknown_pk) { unknown_pk_rcvd = 1; if (debug_level > 3) { printf ("+++++++ prepare to forward this message ! +++++++\n"); fprintf (y_file,"+++++++ prepare to forward this message ! +++++++\n"); } m->olsr_ttl -= 1; m->olsr_hopcount +=1; memcpy(((struct olsrmsg *)unknown_packet + unknown_msg_size), m, (ntohs(m->olsr_msgsize))); unknown_msg_size += ntohs(m->olsr_msgsize); } } /************* end of revision **********/ break; } /* switch */ } /* for olsr_msg */ /*********** added by Y.Ge ********/ fprintf (y_file, "unknown_pk_rcvd: %d, tc_to_relay: %d, qostc_to_relay: %d\n",unknown_pk_rcvd, tc_to_relay, qostc_to_relay); /* * if I should forward an unknown packet && I have received tc * && it is possible that I have received a qos tc * should forward the unknown packet together with tc */ if(unknown_pk_rcvd == 1) { /* * if I need to forward the received tc, don't waite until the tcrelay_jitter expires * send it out immediately, as I may have received a QoS TC without understanding it */ if (tc_to_relay ==1 && qostc_to_relay ==0) { /* send out that TC packet even the jitter time has not expired */ for (ifp = ifnet; ifp; ifp = ifp->int_next) { if (debug_level > 3) { printf ("XXXXXXXXXXXXXXXXXXXX send out the RELAY TC together with unknown packet! XXXXXXXXXXXXXXXXXXXXXXX\n"); printf ("XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) TC sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX send out the RELAY TC together with unknown packet! XXXXXXXXXXXXXXXXXXXXXXX\n"); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) TC sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); } /* copy the unknown packet to the output queue */ /* the first 4 bytes is the common packet header */ memcpy(((char *)packet +4), (char *)unknown_packet, unknown_msg_size); /* set the outputsize, don't neet to set the packet head now, as "tc_build" will deal with it */ outputsize = unknown_msg_size + 4; tc_build((struct sockaddr *)NULL,(struct hello_message *)NULL, &tcpacket_relay, (struct mid_message *)NULL, (struct hna_message *)NULL,0,ifp, 1); tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); } /* free memory */ olsr_destroy_tc_message (&tcpacket_relay); tcpacket_relay.multipoint_relay_selector_address = NULL; tc_to_relay = 0; tc_relay_interval = 0; tc_relay_size = 0; } else { if (debug_level > 3) { printf ("XXXXXXXXXXXXXXXXXXXX send out the unknown packet alone! XXXXXXXXXXXXXXXXXXXXXXX\n"); printf ("XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) unknown packet sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX send out the unknown packet alone! XXXXXXXXXXXXXXXXXXXXXXX\n"); fprintf (y_file,"XXXXXXXXXXXXXXXXXXXX time (%02d:%02d:%02d.%06lu) unknown packet sent from interface %d!XXXXXXXXXXXXXXXXXX\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec, ifp->my_index); } for (ifp = ifnet; ifp; ifp = ifp->int_next) { /* copy the unknown packet to output queue */ memcpy(((char *)packet +4), (char *)unknown_packet, unknown_msg_size); outputsize = 4 + unknown_msg_size; msg->olsr_packlen = htons (4 + unknown_msg_size); msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index] ++); tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); } } } /* check if the qos stuff is correct */ if (qos_tc_rcvd == 1 && tc_rcvd == 0) { printf("XXXXXXXXXX qos tc received but tc is not received! XXXXXXXXXX\n"); exit(1); } /* Y.Ge: process changes at one time after all the messages are received */ if (use_qos) olsr_process_changes_with_qos(); else olsr_process_changes(); if(debug_level > 2) { printf ("\n\n************ after process the received messages, the routing table:\n"); if (use_qos) qos_olsr_print_routing_table(routingtable); else olsr_print_routing_table(routingtable); fprintf (y_file, "\n\n************ after process the received messages, the routing table:\n"); if (use_qos) qos_olsr_print_trace_routing_table(routingtable); else olsr_print_trace_routing_table(routingtable); } /*********** end of revision ******/ sigpending(&psigset); /* If SIGALRM is pending, wait for the end of * the received packet process to send the stored * msg(s) with next broadcast msg(s). */ //added by L.Qin //test the status// printf("The SIGALARM is pending? %d %d\n",sigismember(&psigset, SIGALRM),outputsize); //***** if ( outputsize && !sigismember(&psigset, SIGALRM) ){ printf("Will you?\n"); toall(sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL,(struct mid_message *)NULL, (struct hna_message *)NULL, (struct interface *)NULL ); }}/** Process tools packets.*/void tools_input(struct sockaddr *from, struct afswitch *afp,struct olsr *olsr, int size, int iface_index) //"iface_index" added by Y.Ge{ struct olsrmsg *m = olsr->olsr_msg; struct hello_message hellopacket; struct rt_message *routepacket = NULL; struct interface *ifp = 0; switch (m->olsr_msgtype) { case HELLO_REQUEST: olsr_build_hello_packet(&hellopacket, iface_index); //"iface_index" added by Y.Ge supply(from, &hellopacket, (struct rt_message *)NULL, m->olsr_msgtype, iface_index); //"iface_index" added by Y.Ge return; case ROUTE_REQUEST: olsr_build_routing_packet(&routepacket); supply(from, (struct hello_message *)NULL, routepacket,m->olsr_msgtype, iface_index);//"iface_index" added by Y.Ge return; case UPDATE_NEIGHBOR: hello_chgestruct(&hellopacket, m, from, iface_index); update_static_neighborhood(&hellopacket); return; case OLSRD_TRACEON: case OLSRD_TRACEOFF: /* verify message came from a privileged port */ if ((*afp->af_portcheck)(from) == 0) return; ((char *)olsr)[size] = '\0'; if (m->olsr_msgtype == OLSRD_TRACEON) { traceon(m->olsr_tracefile); bumploglevel(); bumploglevel(); bumploglevel(); } else traceoff(); return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -