145
1* *1
1* *1
1* *1
/ ••••**••**••••••••••••••••••••••••••••••••••••••*••**.*.*****••••*••****./
'include <stdio. h>
'include <stdlib.1»
'include <math.1»
'include <time.1»
'include <string.h>
'include <malloc.I»
'include "header.h"
'define DEBUG 2 'define PKT_DEBUG 1 'define DATA_SLOTS_DEBUG 1
#define· CALL_DEBUG 1 'define END_QUEUE_DEBUG 0
#define ROUTING_PROl 1
#define CONG_CTRL1
#def ine NO _ROUTE_COUlf!' 0
#define FIFO 0
#define CHANNEL_HODEL 0
#define CHANNEL_HODE2 0 'define BOTH_MODELS1 'define LINK_STATE1 'define CLUST_ALGORl 1
#define CLUST_ALGOR2 0 'define CLUST_ALGOR3 0
#define CLUST_ALGOR4 0 1/ SIHULATIOH EllTITIES entity synchronizerO;
entity coordinator();
entity nodes (int. int. int) ; entity channel (ename);
entity traffic..gen(int);
I I DATA STRUCTURES struct SIGNAL_STRENGTH {
int id;
int my_sig;
};
struct MOBILITY_STATUS {
int id;
int my_mob;
};
1
struct ROUTING_LIST {
int nert_addr[N];
int hop[N];
int head[II];
};
struct SIGHAL_STRENGTH signals[H][H];
struct MOBILITY_STATUS mobi[N][N];
struc1; POSITIOH position[N];
struct POSITION old_position[Nl;
II MESSAGES
message idmsg{ename id;};
message idmsg1{enllllle id1[H];};
message idmsg2{en....e id2;};
message idmsg7{ename id7;};
message idmsg8{ename id8s;};
lIlessage idmsg3{ename id3[N);};
message idmsg4{en....e id4[N];};
message idmsg5{ename id5[N];};
message step_msg{int step;};
message lillkstate_pkt{int id; int nu; int no;} I_state;
message LINKSTATE_PKT {
1nt source_id;
int dest_id;
int source_type;
int scope;
unsigned long sequence_num;
int update_type;
int cost_metric;
int time_gen;
};
message ROUTE_REQ {
int source_id;
int dest_id;
int source_type;
int scope;
unsigned long sequence_num;
int prev_node;
int update_type;
int cost_metric;
int time..gen;
};
lIlessage ROUTE_REP
2
1nt scope:
unsigned long sequence_num:
1nt update_type:
int cost_metric;
1nt time_gen;
}:
message linkstate{1nt id: 1nt nu: 1nt no;} links;
message position.-msg{1nt id; 1nt x: 1nt y:} p;
message lilY_Signal {1nt id: struet SIGIlll_STRENGTH sig[N] EN]:} signal_stxen;
message lIly_stabil {1nt id: struct 1I0BILITY_STATUS mob[N] [N];}mobi_rate:
message ctrLph{1nt id: 1nt I8Jllch; 1nt neighbox[N]; struet ROUTING_LIST x_list: struct DATA_SLOTS d_slots[H+I];}:
message ctrl_ph2{1nt id: 1nt Iaach: 1nt neighbor[N]:struet ROUTING_LIST x_list; };
message data_out{1nt slot_no: struct ACTIVE_Q pkt_1n;}datUJDO;
message data_slot_end{}:
message SIR_ready{}:
message ctrl_turn.-msg{}:
message ctrl_end_msg{};
message moveO:
message data_1n{1nt slot_no: struet ACTIVE_Q pkt_1n:}datum;
messagethe_data~slot{1ntno;} the_d_slot;
message call_xeq{struct PKT first_pkt:}c_req;
message call_trfc-sen{struct PKT pkt:}c_trfc:
message xadio_signal{}:
/ / DEFAULT VALUES FOR PA!WIETERS and CONSTANTS int signal [N] :
1nt mobil [N] ; 1nt cong_flag[N][N];
int I_&m_clnsterhead[N];
.int old_Cam..clusterhead[N];
int C&m_gv[N];
int old_Cam-!"[N]:
1nt ch_changesaO, my_ch_changes=O;
int changes =0:
1nt mob_count[100];
long FRA!IE_TIHE:
int source_id;
int dest_id;
int INFINITE_HOP;
int P_suc_lst_try:
extern void drav_xoute():
int useful_link(intni, 1nt 02);
int xes_link(1nt nl, int 02):
extern long lrand480;
extern double drand480;
extern long sxand48():
3
.!
I
1nt Done:
extern 1nt stoi():
extern long stolO:
void cal_statistics():
void dtostrO;
char stat_text[40] [80],01d_stat_text[40] [80]:
extern double pov8r_measure();
extern void impulse_produce():
char temp_str1ng[80];
1nt temp1:
ename e_traffic_gen[N],e_no_route_checker:
int frame-O;
int irame_counter;
struet QUEUE {
int pkt_num;
. in't hops_traversed;
struct QUEUE ..next;
};
struet QUEUE ..queue[N] ; extern drav_pkt();
void forvard_pkt();
double exp_pickO:_
1nt CAU_ON[N] [N];
1nt pkt_gen.-PRHA=O, pkt_got_PRIIA"O ,pkt_dropped_PRIIA=O, out_of_seq=O, no_of_loops=O;
struet PKT_STATUS pkt_status[N] [H];
double mean_delayeO. 0, mean_square_delayeO. 0, var_delay-O. 0, avg_hops_traversed=O.O;
double mean_no_of_clusters=O.O:
1nt last_frame_res_link[N][N];
1nt xes_linkO;
1nt 1I0VING_PATTERN[H];
struct POSITION traj[H];
FILE "filel, "file2:
long seed:
int seed2;
entity drivex () {
ename node [10] , cooxd, sync,coo[10],syn[10];
ename channl;
ename name[10];
ename coid;
int i,j ,k;
clocktype time:
setmaxclock(1000);
FRAKE_TIHEa(long)N"CTRL_SLOT_TIHE+num_data_slots"DATA_SLOT_TIHE:
INFINITE_HOPaN:
4
{
traj[i].xcl-(int)(lrand48()%3);
traj[i].y-l-(int)(lrand48()%3);
}
vhile «traj[i] .x--O)kt(traj[i).y=-O»;
}
tor(i-O;i<H;i++) queue [i]-NULL;
for(i-O;i<N;i++) tor(j-o; j<N;j++) {
CALL_ON[i]w-O;
cOIls-tlag(i] [j]-O;
pkt_status[i] (j].received-O;
pkt_status[i] (j].repeat_receivedaO;
pkt_status[i] (j].dropped-O;
pkt_statuB[i] [j].repeat_dropped-O;
pkt_status[i] [j).no_routa_pkts-O;
pkt_statuB(i) (j].loops-O;
pkt_status[i] (j].no_route_trames=O;
pkt_BtatuB[i] (j].last_pkt_heard=O;
pkt_statuB[i] [j].out_of_seq-O;
pkt_status[i] [j].idle=O;
for(k-O;k<=DELAY_REQ;k++) {
pkt_status[i][j).got [k]=O;
pkt_status[i][j].lost[lc]=O;
} }
for (i = 0; i<N; i++) {
node(i] = nev nodeB(i, (int)lrand48()Y~_x, (int)lrand48()Y~_y);
coord • nev coordinator();
sync • nev synchronizer0 ;
e_traffic_gen[i] =nev traffic_gen(i);
if«CHANNEL_KODEL)! I(BOTH_MODELS»
{
channl - nev channel(coord);
send idmsg{channl} to coord;
} }
for (i~O; i < N; i++) {
send idmsg{coord} to node[i];
send idmsg2{coord} to sync;
send idmsg7{sync} to node [i) ; send idmsg3{node} to coord;
send idmsg4{node} to sync;
send idmsg5{node} to e_traffic_gen[i];}
}
double estimate ( double I1SX, double nsy, double ndx, double ndy, double
5
y_change= osy - nay ;
source_change~ sqrt ( x_change * x_change +y_change * y_change ) x_change - odx - ndx ;
y_change = ody - ndy ;
end_change = sqrt ( x_change*x_change +y_change *y_change ) total_change = source_change+ end~change ;
return ( total_change);
}
double path_loBs ( lambda, length ) double lambda, length ;
{
double loss, pover_loss if (length <- 0.000000001
loss • 1 ; else
loss = lambda / ( 4 * PI *length ) power_loss= loss • loss
return (pover_loss) }
double path_length ( begin, end) struct point *begin, .end ; double length, length_x, length_y
length_x = end->x_location - begin->x_location length_y= end->y_location - begin->y_location
length = sqrt ( length_x*length_x +length_y *length_y ) return ( length) ;
}
double bkgnoise() {
double =_noisetig, =_temp, rx_bw ; double bkg_temp, bkg_noise, amb_noise double noise ;
rx_noisetig = 1.2 ;
=_temp = (rx_noisetig - 1.0) *290.0 bkS-temp = BKG_TEKP ;
=_bv = 10000000.0 ;
bks-noise = (=_temp+ bks-temp) • =_bv*BOLTZl!ANll amb_noise ==_bv * AHB_NOISE_LEVEL
noise = bkg_noise+amb_noise ; return(noise)
}
double exp_pick(double para) {
6
int j,jj,jjj;
int int_d;
double trac_d;
int_d-(ut)d;
trac_d-d-(double)int_d;
j-O;
do {
string [j++)-int_d%lO+ '0 , ; }
while «int_d/clO) >0) ; string[j] -'\0';
for(j-O,jj-strlen(string)-l;j<jj;j++,jj--) {
jjj-string[j) ; strug[j)-string[jj) ; string[jj)-jjj;
}
j=strlen(string);
string [j++)-' .';
string[j++)-(int) (frac_d*10) %10+ '0' ; string[j++)-(int) (frac_d*100)%10+'O';
string[j++)c(int)(frac_d*1000)%10+'0';
string [j ++)-(int) (frac_d*10000)%10+'O';
string[j)-'\O' ; }
int res_link(int nl,int n2) {
if( (last_frame_res_link[n1)[02)I=O)&t(frame=- last_frame_res_link [nl] [02] +1) )
return(l) ; else
return(O);
}
int useful._link(int nl, int%12) {
int It;
for(lt=l; It<H;It++)
it (I_llm..clusterhead[Jt)&t(sqrt(po,,( (double) (position[nl] . x-position [k] .x) , 2.0)+pow«double) (position[nl] .y-position[k] .y) ,2.0) <= COHIUWlGE)&t (sqrt( pow«double)(position(k] .x-position[n2] .x) ,2.0)+ pow«double) (position(k] .y-position[n2].y) ,2.0»)<=COMICRANGE»
{ return(l);
}
7
I
int pltt_num;
static pkt_num_last_got=O;
struct QUEUE ..temp1, *temp2;
int just_forwarded[N];
int pkt_drawn;
int temp_hops_traversed;
double temp_delay, temp_no_of_clusters;
pltt_drawn=O;
for(i=O;i<H;i++) {just_forwarded[i]-O; redra,,_pltt[i].pkt_num-O; } templc(struet QUEUE ")malloc(siz80f(struct QUEUE»;
templ->pkt_numzfram~;
templ->hops_traversed=O;
templ->next=NULL;
i:f(queue[source_id)I=NULL) {
temp2=queue[source_id];
.while(temp2->nextl-NULL) temp2=temp2->nert;
temp2->nertetempl;
} else
queue [source_id] =templ;
pltt_got_PRHA++;
pkt_status[datum.pkt_in.pkt.source)[datum.pkt_in.pkt.dest].received++;
for(i=O;i<N;i++) {
if( «' just_forwarded [i])U (queue[i]'-NULL» 11
«just_forwarded[i])&t(queue[i)I-NULL)&t(queue[i)->nexti-NULL») {
templ=queue[i];
pkt_num=queue[i]->pkt_num;
temp_hops_traversed-queue[i)->ttops_traversed;
queue[i)=queue[i)->nert;
free(templ);
if( (routing_table[i].hop[dest_id]i=INFIIlITE_HOP)&t (routing_table[i].nert_addr[dest_id]l=source_id)tt
(useful.~link(i,routing_table[i].next_addr[dest_idl»tl
«res_link(i,routing_table[i).nert_addr[dest_id]»II(
rand()%100<P_suc_lst_try» ) {
last_frame_res_link[i] [routin&-table[i).nert_addr[dest_id])=:frame ; pkt_drawn++ ;
redraw_pltt[pkt_drawnJ.pkt_num-pkt_num;
redraw_pltt [pltt_drawnJ .nodel=i;
redraw_pltt [pkt_drawnJ .node2=routing_table [i) .nert_addr [dest_id] ; if(routing_table[i).next_addr[dest_id]i=dest_id)
{
templ-(struct QUEUE ")malloc(sizeof(struet QUEUE»;
templ->pkt_num-pltt_num;
templ->hops_traversedBtemp_hops_traversed+l;
8
temp2->oext-templ;
} else
queue [routing_table [i] .oext_addr [dest_id]] "1:empl;
just_forvarded[rout~table[i].oext_addr[dest_id]]xl:
} else {
pkt~ot_PRKA++;
pkt_status[datum.pkt_in.pkt.source) [datum.pkt_in.pkt.dest).received++;
avg_hops_traversed*(double) (pkt_got_PRMA-l))/(double)pkt_got_PRHA;
} } else
{
pkt_dropped_PRKA++;
} }
pkt_got_PRKA++;
temp_delay=(double) (frame-pkt_uum+1);
mean_delay=(double)temp_delay/(double)pkt_got_PRHA +(double)meaa_delay/(double)pkt_got_PRHA*(double)
(pkt_got_PRHA-l.) ;
mean_square_delay-(double) (pow«double)temp_delay,2.0)+
mean_square_delay*(pkt_got_PRHA-1.))/(double)pkt_got_PRHA:
var_delayzmean_square_delay-pow(mean_delay,2.0);
avg_bops_traversed=(double) «double) (temp_hops_traversed+1)+
av~hops_traversed*(double)(pkt_got_PRHA-l))/(double)pkt_got_PRHA;
i t(DEBUG>=l)
i t(pkt_oum<pkt_oum_last_got) out_of_seq++:
pkt_oum_last_got-pkt_oum;
}
temp_oo_of_clusters=O.O;
tor(i=O;i<N;i++) if(I_am_clusterbead[i])
{
temp_oo_ot_clusters=temp_oo_ot_clusters+1.0;
mean_oo_ot_clusters=«double)temp_oo_of_cluaters+
mean_oo_of_clusters*«double)trame-1.))/(double)frame;
} } }
void cal_statistics() {
static int old_pkt-f;eo_PRHA=O .old_pkt_got_PRHA=O .old_pkt_dropped_PRHA- O,old_out_of_seq=O,old_oo_of_loopa=O;
static double ol<Lmeaa_delay=O. 0 ,old....ean_square_delay=O. 0,
old_var_delay=O.O,old_avg_hops_traversed=O.O.old_mean_uo_ot_clusters=O.O:
static int old_ch_changes-O. old....y_ch_changes=O;
9
- -
old_stat_tert[i) [j]-stat_text[i] [j];
for(ixO;i<40;i++) stat_text[i] [0]-'\0';
strcat(btat_text[l] [0] ,"offered load at this frame = ");
itostr(pkt_Keo_PRHA-old_pkt-f;en_PRHA, ttext[O]);
strcat (kstat_text [1] [O],ttext[O]);
itostr(pkt_got]RHA-old_pkt-f;ot]RHA, ttext [0)):
strcat(kstat_text[2] [0) ,ttext [OJ):
strcat(kstat_text[3] [0) ,ktext[O]);
temp_pkt_dup=O;
for(i=O;i<N:i++) for(j=O;j<N;j++)
temp_pkt_dup"1:emp_pkt_dup+pkt_status[i) [j].repeat_received:
strcat(btat_text[4) [0] ,lr:text[O]);
strcat (kstat_text [5] (O),ktext[O]);
temp_pkt_dup=O:
for(i=O:i<N;i++) for(j=O ;j<N;j++)
temp_pkt_dup-temp_pkt_dup+pkt_status[i] [j).repea.t_received:
itostr(pkt_got_PRHA-temp_pkt_dup, ktext[O]);
strcat(kstat_text[5) [0] ,,ttext[O]);
for(i=O;i<N;i++) for(j-O:j<N:j++)
temp_pkt_dup=temp_pkt_dup+pkt_status[i)[j).repeat_dropped;
}
eotity channel (eoeme coord) stacksize (20000) {
ename coordl;
double distance
double signal_power, inter_pover, noise, vamis_sir double loss, lambda ;
double free_space ; double shadolling, change struct point head, toot ; int match_code;
int conflict, initial, start, sBall_scale int i, j. k ;
message SIR_ready sready;
correlat_value = 0.0 ; start_simulate • 0 ; for ( i cO; i < N ; i++ )
for ( j = 1 ; j < N ; j ++
{
link[i] [j).sx_locatioo = 0.0 link[i] [j].sy_locationD 0.0 link[iJ[j].d:z:_locatioo - 0.0 link [i) [j).dy_locatioo = 0.0
for ( k x 0 ; k < Hax_duratioo ; k++ )
10
link[iJ [jJ .power[kJ .phase '" 0.0 ; link [iJ [jJ •power [k) . signal '" 0 l1nk[iJ[j].set_already'" 0;
} }
for ( ; ; )
receive ( radio_signal rads {
if ( start_simulate==0) initial '" 0 start_simuJ.ate '" 1 ;
for ( i • 0;· ( i <N ) ; i++ ) :it ( trcver [iJ •status - 'r' {
signal_pover=0.0 ; lambda= C / TX_freq noise llI: 0.0 ; match..code = 0 ; conflict = 0
foot. x_location '" trcver[i].x_location ; foot.y_location· trcver[iJ.y_location ; for ( j = 1 ; ( ( j <N) It&: ( conflict - 0) ) j++ )
if ( trcver[j] •status== 't' )
{
head.x_location= trcver[j].x_location head.y_location= trcver[j].y_location distance =path_length ( &:head, tfoot ) ; loss • path_loss ( lambda, distance ) ; if ( trcver [i] •code - trcver [j] . code ) {
if ( match_COde~ 0 {
m.atch_code= 1;
change • estimate (
trcver[j].x_location, trcver[j].y_location, trcver[l].x_location, trcver[i].y_location, link[jJ[i].sx_location,link[j][i].sy_location, link[j][i].dx_location,link[j][i].dy_location);
trcver[i) .trans_n1llll= j ; if ( change > Small_Scale )
small_scale= 0 else
small_SCale '"
if ( link [j] [i] . set_already - 0 ) start =1
else start '" 0 :it ( change == 0.0 )
{
11
signal_pover '" shadowing;
link[j] [i].set_already '" 1 link[j] [i).distance '" distance link [j] [i] •shadowing '" shadowing ;}
} , else {
conflict '" 1 signal_power '" 0 }
} else {
inter_pover=Initial_Power'" loss ; inter_power=inter_power / Processing_Gain noisec noise +inter_pover i
}
link[j][i].sx_location'" head. x_location link[j][i] .sy_location=head.y_location link[j][i].dx_location=foot.x_location link[j] [i].dy_location '" foot.y_location }
inter_power =noise +bkgnoise() ; wamis_sir = signal_power / inter_power
trcver[i).sir_value=signal_power / inter_power;
free_space '" free_space / inter_pover if(trcver[i].sir_value>O.O)
trcver[i].sir_value '" 10.0'" log10 ( trcver[i].sir_value) else
{
trcver[i).sir_value'" -100000.;
} }
initial= 1 ; send sready to coord;
} }
entity synchronizer() stacksize (20000) {
int i,i;
sname node[N]-;
en~e step_id, coid,s_id;
ename id;
message testmes2 {aname ids2[10);};
int step_y;
int cycounter,nidcount2;
receive(idmsg2 idms) coid=idms.id2;
12
} } for (;;) {
}
for(j-O; j<N; j++)
for(j=O;j<-num_dats_slots;j++) {
hold(ACQ_TIIlE);
i f (PKT_DEBUG) for(i-D;i<N;i++)
send the_data_slot{j} to node[i];
send dsta-slot_endO to coid;
}
}
= p.x;
S p.Yi
=p.id;
ccount+lj
hold(1) ; p=posi;
pos[p.id] [0]
pes[p.id][l) nid ccount= hold(1) ;
for(i=O; i<N;i++) { hold(2);
for(i=O;i<N;i++) {
for(i-O; i<N;i++) {
signals [id] [i] .my_sig = 0;
send my_signal {id, signals} to node [i];
}
dist [i] = (sqrt (pov ( (double)(pos [ctrl. id][O] -pes [i][O] ) .2.0) + pov«double) (pos [ctrl. id) [l]-pos[i] [1]) ,2.0»);
signals [id) [i] .my_sig = .dist[i];
if (dist < COKK_RANGE*3/4) signals [id] [i] .my_sig -1;
else } for Co;)
receive Cpesition_msg posi) {
send ctrl_turn_msg {} to node[i);
message ctrl_ph ctrl;
int no_pkt_process-o,busy_i;
int slot_no, pkt_in_range[N), pkt_lleard;
struct ACTIVE_Q pkt [N] ; ename channl,cyid[10];
int id, nidcount2,nid;
receive(idmsg3 idms) for ( i =0; i<N;i++) {
node [i] = idms. id3(1) ; if«CHANNEL_KODEL)11(BOTH_KODELS»
{receive(idmsg idms) channl-idms . id;
{ hold[1] ;
if (PKT_DEBUG) for (i=O;i<N;i++)
send the_dsta_slot{j} to node [i] ; hold(1) ;
send data_slot_end{} to coid;
hold(1) ; }
if«1)11(ClWlNEL_HODEL) {
if (frame <100) {
tile1=topen("frame.!11e'I,"v");
fprintf (f ile1 , .. fr""",-7,d, ch_ changes-7,lf, my_ch_changes-7,1f\n· • frame, (double) ch-changes/frame , (double)my_ch_changes/frame);
iprintf(fi1el, n*****·*.*••*\nll)j
fclose(filel) ; }
frame++j
for(i-O; i<N;i++) { hold(S) ;
send ctrl_turn~g{} to node[i];
hold(1); }
i f(PKT",-DEBUG) for (jE();j<N;j++)
send ctrl_end~g{}to node[j];
for (j-1;j<num_data_slots;j++) {
}
}
i f(lrand48()7,100<Koving_prob) ontity coordinator() stacksize (60000)
{send mo to node[i];
double dis1:;
int i, j, jj, pos(10][2];
} }
13 14
[mobi_rate.id] .mYJllob;
for (i=O;i<N;i++) {
send mobi_rate to node[i] after 5:
} }
or receive (ctrl_ph cntr) {
ctrl= cntr;
for(i=O:i<N:i++) {
if (i >3 )
{ Signal_st = 5;
} if ( i - 1)
{ mobi_st = 1:}
send linkstate {i, Signal_st, mobi_st} to node[i]:}
send radio_signal{} to channl;
I_am_clusterhead[ctrl.id]=ctrl.lamch;
if (CHANNEL_KODEL) {
for(i=O:i<N;i++)
{ trever[i] .status='r'; trcver[i] .code=l; } trcver[ctrl.id].status='t';
send radio_signal{} to chann1;
receive(SIR_ready sir) {
for(i=O:i<N;i++)
if«ctrl. id<i)kt(trever[i] .sir_value>=54.-20. *log10«double) COMM_RANGE/250.»kk(Neighbors[i] [ctrl.id]==l»
{
send ctrl to node[i];
}
else if«ctrl.id<i)kt(trever[i].sir_value>=54.-20*log10«double) COMM_RANGE/250.)+6.4)lk(Neighbors[i] [ctrl.id] 1=1»
{ send ctrl to node[i]:
}
else if«ctrl.id>i)kk(Neighbors[ctrl.id] [i]==l»
send ctrl to node [i] ; }
} else
{
for (i=O; i<N; i++) if (i != etrl.id)
15
} } }
or receive(data_out datao) {
datumo=datao;
slot_no=datumo.slot_no:
if (no_pkt_process >10) {no_pkt_process = 10; break:}
no_pkt_process++;
pkt[no_pkt_process].pkt.typezdatumo.pkt_in.pkt.type:
pkt[no_pkt_process].pkt.sourcezdatumo.pkt_in.pkt.source;
pkt[no_pkt_process].pkt.dest=datumo.pkt_in.pkt.dest:
pkt[no_pkt_process].pkt.pkt_num=datumo.pkt_in.pkt.pkt_num;
pkt[no_pkt_process].pkt.time_gen=datumo.pkt_in.pkt.time~en;
pkt[no_pkt_process].inter_source=datumo.pkt_in.inter_source;
pkt[no_pkt_process].inter_dest=datumo.pkt_in.inter_dest;
pkt[no_pkt_process].code=datumo.pkt_in.code:
or receive (data_slot_end datae) {
if«no_pkt_process!=O)kk (no_pkt_process <=
datumo.pkt_in.pkt.pkt_num:»
{
for(i=O;i<N;i++) {
for (j=O: j< 4:j++)
send data_in{slot_no,pkt[i]} to node[i];
busy_i=O;
for(j=l;j<=no_pkt_process;j++)
if(pkt[j].inter_source==i) {busy_i=O; break;}
i f (busy_il=O) continue;
for(j=l:j<=no_pkt_process:j++) if«lCHANNEL_MODEL)kk
(sqrt(pow«double) (pos[i] [O]-pos[pkt[j].inter_source] [0]) ,2.0)+
pow «double) (pos[i] [l]-pos[pkt[j] •inter_source] [1]) ,2.0»
<=(double)COMM_RANGE» { pkt_in_range [j] =1;
}
else i f«CHANNEL_HODEL)kk(Neighbors[i] [pkt[j].inter_source]==l»
pkt_in_range[j]=l;
else {
pkt_in_range[j]=O; } for(j=l;j<=no_pkt_process;j++)
if«pkt_in_range[j])kk(pkt[j].pkt.pkt_num>O»
{
pkt_heard=l;
for(jj=l:jj<=no_pkt_process:jj++)
if«j!=jj)kk(pkt_~range[jj])lk(pkt[j].code==pkt[jj] .code)kk
16
}
else if«pkt_in_range[j])tl(pkt[j].pkt.pkt-Dum<~O»
{
pkt_heard=l;
for(jj-l;jj<=no_pkt_process;jj++)
if«jl=jj)tl(pkt_1n-range[jj])tl(pkt[j] .code=-pkt[jj].code»
{ pkt_heard++; break;}
if(pkt~heard==l)
Beud data_in{slot_Do, pkt [j]} to node [i] ;
} } }
Do_pkt_process=O;
}
entity traffic_gen(int id) {
ename Dode [H];
8truCt PKT first_pkt ,pkt;
int tBlllp_dest;
int accept;
int pkt_nUIII;
double call_service_time;
double call_int_arrvl_time;
int temp_DUIII_pktS - 5;
int i,j;
receive(idmag5 id) for (i-O;i<H;i++) { Dode [i] - id. ic15 (i] ; }
llhile(l) {
accept=O;
pkt-DUD=O;
llhile(accept. .O) {
call_int_arrvl_time=(double)exp_pick«double)1.0/(double) IlEAN_CALL_INT_ARRVL_TIIIE) ;
hold(l);
llhile(t~p_dest• (int)(lrand4B()1Ji+l)--id);
{
call_service_time-(double)erp_pick«double)1. O/(double) IlEAN_CALL_SERVICE_TIME);}
if (PR_ALDBA) {accept-l ;break; }
17
first_pkt.pkt_Dum~-l;
.first_pkt. time.-gen-trame;
send call_req{first_pkt} to Dode [id];
for(i=0;i<=NUM_CALL_SET_UP_PKTS-6;i++)
~
hold(l);
if (CALL_ON [id] [temp_dest] >0) { accept-l; break;
}
first_pkt.pkt_uum~kt_Dum;
first_pkt.time_gen=frame;
temp_dest =(int) (Irand48()%N+l);
send call_trfc_geu{first_pkt} to node[id];
}
for(i=O;i<temp_num_pkts;i++) {
if«CONG_CTRL)kk(!PR_ALOHA»
{
j-O;
llhile(coug_flag[id] [temp_dest] >0) {
pkt .type='r'; pkt.source-id; pkt .dest=temp_dest;
pkt.time.-gen=frame;
if(j%2~O)
{ pkt.pkt_uum=O; pkt_status[id] [temp_dest]. idle++;
}
else if(i<temp_uUIII_pkts)
{pkt_umu++; i++; pkt.pkt_uum=pkt_nUll; pkt_geu_PRIIA++;
} else
{ break;}
j++;
send call_trfc~en{pkt}to uode [id];
18
pkt.source-id:
pkt.destztemp_dest;
pkt. pkt_utlll=pkt_nUlll;
pkt •tiJRe~Sl1-trame;
pkt_gen_PR!U++:
if «PR_ALOHA)U (pkt_num=-l)) {
send cal.l_req{pkt} to node [id];
} else
{
send call_trfc..gen{pkt} to node [id];
} }
CALL_ON [id] [temp_dest]-o;
pkt_status[id] [temp_dest].last_pktjheard=O;
for(i-O;i<DELAY_REQ:i++) {
pkt_status[id] [temp_dest].got[i]=O:
pkt_status[id] [temp_dest].lost[i]=O;
} } }
tity nodes(int id, intx, int y) stacksize(60000)
int i,j ,iij int i1,i2,i3;
int j1,j2,j3;
int neighbor[N];
in~nidcount,move_count 8 0;
int nidcount2 - 0;
double dist;
int nidi int I_am....ch[l() :
clocktype updated_tiJRe[N];
struct ROUTING_LIST routins-list,
struct ROUTING_LIST other_routing_lists[N];
struct -.DATA_SLOTS dat....slots[N][K+1] : int my_ch,my_2nd_ch,mY_3rd_eh,temp_eh:
int temp_addr;
int try [K+1] ; /
struct ACTIVE_Q active_q[K+1]:
struct PRKA_Q .teap1_PRKA~q,.temp2_PRKA_q,.temp3_PRHA_q,
19
ename coid, s~id,channl;
message ctrl_ph2 etr12;
mes6age ctrl_ph ctrl;
ename node[10],coord,sync:
ename c_id,syid[10);
ename var3[10],var4[10);
ename nod;
int pos [10] [2) ; int runner;
for(i-O:i<N:i++) {
updated_time[i)=simclock();
l_am_ch[i]=0;
neighbor[i]=O:
Neighbors[id) [i)=O:
}
for(i=O:i<N;i++) tor(j-O;j<N:j++)
my_cong_flag[i) [j]=O;
tirst_PRHA_q=NULL: PRHA_q=NULL:
for(i=O:i<N:i++)
tor(j-1:j<=nUlll_data_slots;j++) {
data_slots[i][j].status='i':
data_slots [i] [j] . code = i:
}
if (ROUTING_PRO1) {
tor(i~;i<N:i++)
it(il-id) for(j-O;j<N:j++) {
other_routing_lists[i].next_addr[j]=O;
other_routing_lists[i).hop[j]-INFINITE_HOP:
} }
tor(i=O;i<N:i++) {
routins-list.next_addr[i)-O;
routins-list.hop[i]-INFINITE_HOP;
}
routins-list.next_addr[id]=id:
routing_list.hop[id]-o;
receive(idmsg idms)
20