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

📄 mad_rlc.c

📁 这个程序实现了FLUTE协议
💻 C
📖 第 1 页 / 共 2 页
字号:
	if(s->rlc->rx_nblost_since_sp <= s->rlc->loss_accepted	    && s->rlc->rx_nblate_since_sp <= s->rlc->late_accepted) {		if(s->addr_family == PF_INET) {			if(s->addr_type == 1) {				addr_nb = ntohl(inet_addr(s->ch_list[s->nb_channel - 1]->addr));			}			else {				addr_nb = ntohl(inet_addr(s->ch_list[s->nb_channel - 1]->addr)) + 1;			}			port_nb = atoi(s->ch_list[s->nb_channel - 1]->port) + 1;			ipv4.sin_addr.s_addr = htonl(addr_nb);			memset(addrs[s->nb_channel], 0, MAX_LENGTH);			memset(ports[s->nb_channel], 0, MAX_LENGTH);						sprintf(addrs[s->nb_channel], "%s", inet_ntoa(ipv4.sin_addr));			sprintf(ports[s->nb_channel], "%i", port_nb);						ch_id = add_alc_channel(s->s_id, ports[s->nb_channel], addrs[s->nb_channel],									s->ch_list[s->nb_channel - 1]->intface,									s->ch_list[s->nb_channel - 1]->intface_name);			if(!(ch_id < 0)) {				s->rlc->rx_nblost_since_sp = 0;				s->rlc->rx_nblate_since_sp = 0;				retval = 1;			}		}		else if(s->addr_family == PF_INET6) {			port_nb = atoi(s->ch_list[s->nb_channel - 1]->port) + 1;					retcode = ushort_ipv6addr(s->ch_list[s->nb_channel - 1]->addr,									  &ipv6addr[0], &nb_ipv6_part);			if(retcode == -1) {				return -1;							}			if(s->addr_type == 0) {				for(l = nb_ipv6_part;; l--) {					if(l == 0) {						printf("Only %i channel possible!\n", s->nb_channel);						fflush(stdout);						return -1;						}					if(ipv6addr[l] + 1 > 0xFFFF) {						continue;					}											if(ipv6addr[l] == 0) {						if(nb_ipv6_part == 7) {							ipv6addr[l]++;							break;						}						for(m = nb_ipv6_part; m > l; m--) {							ipv6addr[m + 1] = ipv6addr[m];							}						ipv6addr[l + 1] = 1;						nb_ipv6_part++;						break;					}					else {						ipv6addr[l]++;						break;					}				}			}			memset(addrs[s->nb_channel], 0, MAX_LENGTH);			dup_sep = 0;			for(k = 0; k < nb_ipv6_part + 1; k++) {				memset(tmp, 0, 5);				if(ipv6addr[k] != 0) {					sprintf(tmp, "%x", ipv6addr[k]);					strcat(addrs[s->nb_channel], tmp);				}				else {					if(dup_sep == 0) {						dup_sep = 1;					}					else {						printf("Invalid IPv6 address!\n");						fflush(stdout);						return -1;						}					}				if(k != nb_ipv6_part) {					strcat(addrs[s->nb_channel], ":");				}			}			sprintf(ports[s->nb_channel], "%i", port_nb);			ch_id = add_alc_channel(s->s_id, ports[s->nb_channel], addrs[s->nb_channel],									s->ch_list[s->nb_channel - 1]->intface,									s->ch_list[s->nb_channel - 1]->intface_name);			if(!(ch_id < 0)) {				s->rlc->rx_nblost_since_sp = 0;				s->rlc->rx_nblate_since_sp = 0;				retval = 1;			}		}	}	return retval;}/* * This function adds late packet to session's late list. * * Params:	alc_session_t *s: Pointer to session, *			int layer: Layer number, *			int nseq: Packet sequence number. * * Return:	int: 0 in success, -1 otherwise. * */int mad_rlc_add_late(alc_session_t *s, int layer, int nseq) {	late_list_t	*new_missing;	double currenttime;	if(layer > s->nb_channel) {		return -1;	}	if(!( new_missing = (late_list_t *)malloc(sizeof(late_list_t))) ) {		printf("Could not alloc memory for late_list_t structure!\n");		return -1;	}	currenttime = sec();	new_missing->seq_num = nseq;	new_missing->losttime = currenttime + (double)((double)s->rlc->pkt_timeout / (double)1000);	new_missing->next = s->rlc->rx_missing[layer].next;	s->rlc->rx_missing[layer].next = new_missing;	s->rlc->rx_nblate++;	s->rlc->rx_nblate_since_sp++;		/* update stats: assume a late pkt is lost (corrected later if req.) */	s->lost_packets++;			return 0;}/* * This function removes late packet from session's late list. * * Params:	alc_session_t *s: Pointer to session, *			int layer: Layer number, *			int nseq: Packet sequence number. * * Return:	int: 0 in success, -1 otherwise. * */int mad_rlc_remove_late(alc_session_t *s, int layer, int nseq) {	late_list_t *prev;	late_list_t *current;	if(layer > s->nb_channel) {		return -1;	}	prev = &(s->rlc->rx_missing[layer]);	current = prev->next;		while(current != NULL && current->seq_num != nseq ) {		prev = current;		current = current->next;	}	if(current == NULL) {		return -1;	}	else {		prev->next = current->next;		free(current);		s->rlc->rx_nblate--;		s->rlc->rx_nblate_since_sp--;	}	/* correct stats... */	s->lost_packets++;	return 0;}/* * This function updates session's late list. * * Params:	alc_session_t *s: Pointer to session. * * Return:	int: 0 in success, -1 otherwise. * */int mad_rlc_update_late_list(alc_session_t *s) {	int layer;	late_list_t *prev;	late_list_t *current;	double currenttime;	for(layer = 0; layer < s->nb_channel; layer++) {		currenttime = sec();		prev = &(s->rlc->rx_missing[layer]);		current = prev->next;				while(current != NULL) {			if(current->losttime <= currenttime) {				/* this one is lost! */				prev->next = current->next;				free(current);				s->rlc->rx_nblate--;				s->rlc->rx_nblate_since_sp--;								if(mad_rlc_add_lost(s) == -1000) {					return -1; /* roca 0 */				}			}			else {				prev = current;				current = prev->next;			}		}	}	return 0;}/* * This function adds lost packet to session's lost list. * * Params:	alc_session_t *s: Pointer to session. * * Return:	int: -1000 when layer drop, 0 when no layer drop, -1 otherwise. * */int mad_rlc_add_lost(alc_session_t *s) {		lost_list_t	*new_lost;	double currenttime;	currenttime = sec();	s->rlc->rx_nblost++;	s->rlc->rx_nblost_since_sp++;		if(s->rlc->rx_nblost >= s->rlc->loss_limit) {		/* too many losses... drop a layer! */				s->rlc->drop_highest_layer = true;		/* initial state for future potential use of this layer*/		s->rlc->rx_first_pkt[s->ch_list[s->nb_channel - 1]->ch_id] = 1;		/* Clean up late and lost lists... */		mad_rlc_free_lists(s);		/* entering the deaf period... */		s->rlc->rx_deaf_wait = currenttime + (double)s->rlc->deaf_period / (double)1000;		return -1000;	}	if(!(new_lost = (lost_list_t *)malloc(sizeof(lost_list_t)))) {		printf("Could not alloc memory for lost_list_t structure!\n");		return -1;	}	new_lost->pkt_remaining = s->rlc->loss_timeout;	new_lost->next = s->rlc->rx_lost.next;	s->rlc->rx_lost.next = new_lost;		return 0;}/* * This function updates session's lost list. * * Params:	alc_session_t *s: Pointer to session. * * Return:	int: 0. * */int mad_rlc_update_loss_list(alc_session_t *s) {	lost_list_t *prev;	lost_list_t *current;	prev = &(s->rlc->rx_lost);	current = prev->next;	while(current != NULL) { 			if(--(current->pkt_remaining) == 0) { /* this loss is too old : removing */					prev->next = current->next;			free(current);			s->rlc->rx_nblost--;		}		else {			prev = current;		}		current = prev->next;	}	return 0;}/* * This function free lists. * * Params:	alc_session_t *s: Pointer to session. * * Return:	void * */void mad_rlc_free_lists(alc_session_t *s) {	int i;	late_list_t *current_late;	lost_list_t *current_lost;	for(i = 0; i < MAX_CHANNELS_IN_SESSION; i++) {			current_late = s->rlc->rx_missing[i].next;		while(current_late != NULL) {			s->rlc->rx_missing[i].next = current_late->next;			free(current_late);			current_late = s->rlc->rx_missing[i].next;		}		s->rlc->rx_missing[i].next = NULL; /* redundant, isn't it? */	}	current_lost = s->rlc->rx_lost.next;	while(current_lost != NULL) {		s->rlc->rx_lost.next = current_lost->next;		free(current_lost);		current_lost = s->rlc->rx_lost.next;	}	s->rlc->rx_lost.next = NULL; /* redundant, isn't it? */	s->rlc->rx_nblost = 0;	s->rlc->rx_nblate = 0;	s->rlc->rx_nblost_since_sp = 0;	s->rlc->rx_nblate_since_sp = 0;}

⌨️ 快捷键说明

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