📄 output.c
字号:
} //CRC v4->v6 add memset(&address, 0, sizeof(address)); //memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr), &(message->originator),sizeof(struct in6_addr)); //commented by Y.Ge memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr), &addr_manet[ifp->my_index],sizeof(struct in6_addr)); //added by Y.Ge address.sa_family = AF_INET6; interf = if_ifwithaddr6(&address); if (debug_level > 3) { printf("hellobusytime: %d\n", my_busy_time); //printf ("outputsize: %d\n", outputsize); fprintf(y_file, "hellobusytime: %d\n", my_busy_time); //fprintf (y_file, "outputsize: %d\n", outputsize); } /* include the busy time */ memcpy(hello_busy_time, &my_busy_time, sizeof(olsr_u32_t)); hello_busy_time ++; /* build message headers */ outputsize = (char *)hello_busy_time - packet; msg->olsr_packlen = htons(outputsize); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); m->olsr_msgtype = QOSHELLO_PACKET; m->olsr_vtime = olsr_compute_vtime (neighbor_hold_time); m->olsr_msgsize = (char *)hello_busy_time - (char *)m; m->olsr_msgsize = htons(m->olsr_msgsize); m->olsr_ttl = 1; m->olsr_hopcount = 0; m->olsr_msgseq = htons(msg_seqnum.hello_seqnum + hello_chunk[ifp->my_index] - 1); //the qos message sequence number = the last hello sequence number memcpy(&(m->olsr_source), &my_main_addr, sizeof(struct olsr_ip_addr)); if (debug_level > 3) { printf ("++++++++++ QoS HELLO packet built finished!\n"); //printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum)); printf (" QoS Hello sequence: %d\n", ntohs(m->olsr_msgseq)); printf (" QoS HELLO packet size: %d\n", (char *)hello_busy_time - (char *)m); fprintf (y_file,"++++++++++ QoS HELLO packet built finished!\n"); //fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum)); fprintf (y_file," QoS Hello sequence: %d\n", ntohs(m->olsr_msgseq)); fprintf (y_file," QoS HELLO packet size: %d\n", (char *)hello_busy_time - (char *)m); } if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) { //TRACE_OUTPUT(ifp, dst, outputsize); //(*output)(s6, flags, dst, outputsize); //inet6_output(s6, flags, dst, outputsize); //commented by Y.Ge tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); //added by Y.Ge }}void qostc_build(struct sockaddr *dst, struct qos_tc_message *qosmessage, struct tc_message *message, int flags, struct interface *ifp, int relay){ int remainsize = outputsize - comm_head_size; int outputsize_tmp = 0; int current_qostc_position; char packet_tmp[MAXPACKETSIZE+1]; struct olsr *msg_tmp = (struct olsr *)packet_tmp; struct olsrmsg *m_tmp = (struct olsrmsg *) msg_tmp->olsr_msg; struct tcmsg *tc = m_tmp->olsr_tc; struct tc_mpr_addr *mprs, *prev_mprs; struct olsr_ip_addr *mprsaddr = tc->tc_mprsaddr; struct olsrmsg *m = outputsize ? (struct olsrmsg *)((char *)msg->olsr_msg + remainsize) : msg->olsr_msg; struct qostcmsg *qostc = m->olsr_qos_tc; struct tc_mpr_busy_time *mprsbusy, *prev_mprsbusy; olsr_u32_t *mprsbusytime = qostc->tc_mpr_busy; struct interface *interf; struct sockaddr address; int found = 0; int current_seq_number; int i, j; if (debug_level > 3) { printf ("\n\n-------------- in qos tc build -----------------\n"); fprintf (y_file,"\n\n-------------- in qos tc build -----------------\n"); printf ("originator address: %s\n", convert_address_to_string(&message->originator)); fprintf (y_file, "originator address: %s\n", convert_address_to_string(&message->originator)); printf ("sending address: %s\n", convert_address_to_string(&addr_manet[ifp->my_index])); fprintf (y_file,"sending address: %s\n", convert_address_to_string(&addr_manet[ifp->my_index])); } /*printf ("mprsaddr: %d, packet_tmp: %d\n",(char *)mprsaddr, packet_tmp); printf("mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); printf ("outputsize: %d\n", outputsize); printf("---address: %d\n", &address); printf ("--- address->sin6_addr.s6_addr: %d\n", &(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr)); printf("1: mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); memset(&address, 0, sizeof(address)); printf("2: mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); memcpy(&(((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr), &(my_main_addr),sizeof(struct in6_addr)); //added by Y.Ge printf("3: mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); address.sa_family = AF_INET6; printf("4: mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); interf = if_ifwithaddr6(&address); printf("5: mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet);*/ if (outputsize > MAXPACKETSIZE - (int)sizeof (struct olsrmsg)) { msg->olsr_packlen = htons(outputsize); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); //added by Y.Ge tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); //added by Y.Ge } if (!message) return; if (!qosmessage) return; if(message->packet_seq_number != qosmessage->packet_seq_number) { printf("XXXXXXXXXXX something wrong with packet sequence number! XXXXXXXXX\n"); printf("tc seq: %d, qostc seq: %d\n",message->packet_seq_number, qosmessage->packet_seq_number); exit(1); } /*printf ("mprsaddr: %d, packet_tmp: %d\n",(char *)mprsaddr, packet_tmp); printf("mprsbusytime: %d, packet: %d\n", (char *)mprsbusytime, packet); printf ("outputsize: %d\n", outputsize);*/ if (debug_level > 3) { printf ("include the mpr selector addresses and its busy time!\n"); fprintf (y_file,"include the mpr selector addresses and its busy time!\n"); } mprsbusy = qosmessage->multipoint_relay_selector_busy_time; for (mprs = message->multipoint_relay_selector_address; mprs != NULL; mprs = mprs->next) { if (debug_level > 3) { printf ("+++ mpr selector: %s, busy time: %d\n", convert_address_to_string(&mprs->address), mprsbusy->busy_time); fprintf (y_file,"+++ mpr selector: %s, busy time: %d\n", convert_address_to_string(&mprs->address), mprsbusy->busy_time); } outputsize_tmp = (char *)mprsaddr - packet_tmp -4; current_qostc_position = (char *)mprsbusytime - packet; outputsize = current_qostc_position + outputsize_tmp; /*printf ("outputsize_tmp:%d, mprsaddr: %d, packet_tmp: %d\n", outputsize_tmp, (char *)mprsaddr, packet_tmp); printf("current_pos_position: %d, mprsbusytime: %d, packet: %d\n", current_qostc_position, (char *)mprsbusytime, packet); printf ("outputsize: %d\n", outputsize);*/ /*fprintf (y_file, "outputsize_tmp: %d, current position: %d\n", outputsize_tmp, current_qostc_position); fprintf (y_file,"outputsize: %d, maxpacketsize: %d, maxpacketsize - int: %d\n", outputsize, MAXPACKETSIZE, (MAXPACKETSIZE - (int)sizeof (mprsbusytime) - (int)sizeof(mprsaddr))); fprintf (y_file, "sizeof busy time: %d, sizeof addr: %d\n", (int)sizeof (mprsbusytime), (int)sizeof (mprsaddr));*/ if (outputsize > (MAXPACKETSIZE - (int)sizeof (olsr_u32_t) - (int)sizeof (struct olsr_ip_addr))) { /* deal with the packet sequence number for the chunked packet */ if (relay) { printf (" XXXXXXXX something wrong! relayed QoS TC and TC should not be chunked XXXXXX\n"); exit (1); } current_seq_number = message->packet_seq_number + tc_chunk[ifp->my_index]; tc_chunk[ifp->my_index] ++; /*m->olsr_msgseq = htons(message->packet_seq_number + tc_chunk[ifp->my_index]); tc_chunk[ifp->my_index] ++;*/ /* set the OLSR packet head */ msg->olsr_packlen = htons(outputsize); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); /* set the qos packet head */ m->olsr_msgtype = QOSTC_PACKET; m->olsr_vtime = message->v_time; m->olsr_msgsize = (char *)mprsbusytime - (char *)m; m->olsr_msgsize = htons(m->olsr_msgsize); m->olsr_ttl = qosmessage->time_to_live; m->olsr_hopcount = qosmessage->hop_count; m->olsr_msgseq = htons(current_seq_number); memcpy(&(m->olsr_source),&(qosmessage->originator),sizeof(struct olsr_ip_addr)); qostc->qostc_mprseqnum = htons(qosmessage->mssn); memset(qostc->qostc_res, 0, sizeof(qostc->qostc_res)); qostc->qostc_originator_busy = qosmessage->my_busy_time; /* set the TC packet head */ m_tmp->olsr_msgtype = TC_PACKET; m_tmp->olsr_vtime = message->v_time; m_tmp->olsr_msgsize = (char *)mprsaddr - (char *)m_tmp; m_tmp->olsr_msgsize = htons(m_tmp->olsr_msgsize); m_tmp->olsr_ttl = message->time_to_live; m_tmp->olsr_hopcount = message->hop_count; m_tmp->olsr_msgseq = htons(current_seq_number); memcpy(&(m_tmp->olsr_source),&(message->originator),sizeof(struct olsr_ip_addr)); tc->tc_mprseqnum = htons(message->mssn); memset(tc->tc_res, 0, sizeof(tc->tc_res)); /* copy the TC packet from packet_tmp to packet */ for (i=0; i<outputsize_tmp; i++) { packet[current_qostc_position+i]=packet_tmp[i+4]; } if (debug_level > 3) { printf ("++++++++++ QoS TC packet chunked!\n"); //printf (" Message sequence: %d\n", ntohs(msg->olsr_seqnum)); printf (" TC sequence: %d\n", ntohs(m->olsr_msgseq)); printf (" TC mssn: %d\n", message->mssn); printf (" Originator's busy time: %d\n", qostc->qostc_originator_busy); printf (" QoS TC packet size: %d\n", (char *)mprsbusytime - (char *)m); printf (" TC packet size: %d\n", (char *)mprsaddr - (char *)m_tmp); fprintf (y_file,"++++++++++ TC packet chunked!\n"); //fprintf (y_file," Message sequence: %d\n", ntohs(msg->olsr_seqnum)); fprintf (y_file," TC sequence: %d\n",ntohs(m->olsr_msgseq)); fprintf (y_file," TC mssn: %d\n", message->mssn); fprintf (y_file," Originator's busy time: %d\n", qostc->qostc_originator_busy); fprintf (y_file," QoS TC packet size: %d\n", (char *)mprsbusytime - (char *)m); fprintf (y_file," TC packet size: %d\n", (char *)mprsaddr - (char *)m_tmp); } tointerface (sndmsg, (struct hello_message *)NULL, (struct tc_message *)NULL, (struct mid_message *)NULL,(struct hna_message *)NULL, (struct interface *)NULL, ifp->my_index); m = msg->olsr_msg; m_tmp = msg_tmp->olsr_msg; qostc = m->olsr_qos_tc; tc = m_tmp->olsr_tc; mprsbusytime = qostc->tc_mpr_busy; mprsaddr = tc->tc_mprsaddr; found = 0; } found = 1; memcpy(mprsbusytime, &(mprsbusy->busy_time), sizeof(olsr_u32_t)); mprsbusytime++; memcpy(mprsaddr,&(mprs->address),sizeof(struct olsr_ip_addr)); mprsaddr++; mprsbusy = mprsbusy->next; } /* * Y.Ge: TC (together with QoS TC) should be sent out in the following conditions * a) mpr selector table is not NULL * b) mpr selector table times out and become empty for the first time * c) the TC is to be relayed */ if (found || (found ==0 && changes) || (found ==0 && relay)) { /************** added by Y.Ge *************/ if (debug_level > 3) { if (found ==0 && changes) { printf ("XXXXXXXXXXX MPR selector table becomes empty! Send out an empty QoS TC !\n"); fprintf (y_file,"XXXXXXXXXXX MPR selector table becomes empty! Send out an empty QoS TC !\n"); } if (found ==0 && relay) { printf ("XXXXXXXXXXX RELAY out an empty QoS TC !\n"); fprintf (y_file,"XXXXXXXXXXX RELAY out an empty QoS TC !\n"); } } outputsize_tmp = (char *)mprsaddr - (char *)m_tmp;; current_qostc_position = (char *)mprsbusytime - packet; outputsize = current_qostc_position + outputsize_tmp; /*printf ("outputsize_tmp:%d, mprsaddr: %d, packet_tmp: %d\n", outputsize_tmp, (char *)mprsaddr, packet_tmp); printf("current_pos_position: %d, mprsbusytime: %d, packet: %d\n", current_qostc_position, (char *)mprsbusytime, packet); printf ("outputsize: %d\n", outputsize); printf ("outputsize_tmp: %d, current_qos_position: %d, outputsize: %d\n", outputsize_tmp, current_qostc_position, outputsize); */ /* set the OLSR packet head */ msg->olsr_packlen = htons(outputsize); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); /* deal with packet sequence number */ if(!relay) { current_seq_number = message->packet_seq_number + tc_chunk[ifp->my_index]; tc_chunk[ifp->my_index] ++; } /* set the qos packet head */ m->olsr_msgtype = QOSTC_PACKET; m->olsr_vtime = message->v_time; m->olsr_msgsize = (char *)mprsbusytime - (char *)m; m->olsr_msgsize = htons(m->olsr_msgsize); m->olsr_ttl = qosmessage->time_to_live; m->olsr_hopcount = qosmessage->hop_count; if (relay) m->olsr_msgseq = htons(qosmessage->packet_seq_number); else m->olsr_msgseq = htons(current_seq_number); memcpy(&(m->olsr_source),&(qosmessage->originator),sizeof(struct olsr_ip_addr)); qostc->qostc_mprseqnum = htons(qosmessage->mssn); memset(qostc->qostc_res, 0, sizeof(qostc->qostc_res)); qostc->qostc_originator_busy = qosmessage->my_busy_time; msg->olsr_packlen = htons(outputsize); //msg->olsr_seqnum = htons(pkt_seqnum[ifp->my_index]++); /* set the TC packet head */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -