dosdbell.c

Go to the documentation of this file.
00001 //This file outputs a ns file for a dumbell network to be used for
00002 //DDOS experiments.
00003 /*the input file is a script file which is read by the program to get
00004 the parameters of the network.
00005 
00006 A typical file example
00007 d (diameter of the network) H (hurtz parameter)  
00008 n1 (no of incoming TCP nodes) rate (rate) 
00009 n2 (no. of DDOS attackers in the subtree) master (0/1) rate (rate)
00010 */
00011 
00012 #include<stdio.h>
00013 #include<stdlib.h>
00014 #include "dosdbell.h"
00015 
00016 
00017 void set_Topology(FILE *filer);
00018 void TCL_Write_Initial(FILE *);
00019 void TCL_Write_Nodes(FILE *);
00020 void TCL_Write_Connections(FILE*);
00021 void TCL_Write_Agents(FILE *);
00022 void TCL_Write_DDOS_Agent(FILE*);
00023 void TCL_Write_Final(FILE*);
00024 
00025 struct Topology topo;
00026 int diameter;
00027 double TCP_start_time;
00028 double DDOS_start_time;
00029 double finish_time;
00030 double bw;
00031 int pack_size;
00032 float bn_delay;
00033 float bn_bw ; 
00034 
00035 main(int argc, char **argv){
00036   FILE *filer;
00037  
00038   if(argc !=3){
00039     printf("USAGE: %s parameter_filename tcloutput_filename\n",argv[0]);
00040     exit(0);
00041   }
00042   else{
00043     filer = fopen(argv[1],"r");
00044     set_Topology(filer);
00045     fclose(filer);
00046     filer = fopen(argv[2],"w");
00047     TCL_Write_Initial(filer);
00048     TCL_Write_Nodes(filer);
00049     TCL_Write_Connections(filer);
00050     TCL_Write_Agents(filer);
00051     TCL_Write_DDOS_Agent(filer);
00052     TCL_Write_Final(filer);
00053     fclose(filer);
00054   }  
00055 }
00056 
00057 
00058   
00059 void set_Topology(FILE *filer){
00060   double perT, perFTP, perCBR, perV;
00061   int i;
00062   double H;
00063   double rnd;
00064   int attackNo,master;
00065   double DDOSRate;
00066   double hop;  
00067 
00068   fscanf(filer,"%d %f %f\n",&diameter,&bn_bw,&bn_delay);
00069   fscanf(filer,"%d %lf %lf\n",&topo.TCPNodes.NoNodes,&bw,&TCP_start_time);  
00070   topo.TCPNodes.TCPNode = (struct TCP_Node_Info *)malloc(topo.TCPNodes.NoNodes*sizeof(struct TCP_Node_Info));
00071 
00072   for(i=0;i<topo.TCPNodes.NoNodes;i++){
00073     
00074     /* Based on the topology, get the number of hops from the source to destination.
00075        Since a dumbbell has a minimum of three hops, the number of hops returned 
00076        should be greater than 3 
00077     */ 
00078 
00079     do{
00080       topo.TCPNodes.TCPNode[i].delayFrom = (double) Inet_default_no_hops(diameter);
00081     }while(topo.TCPNodes.TCPNode[i].delayFrom<=3);
00082 
00083     /* Calculate the delay in for both the links */
00084     topo.TCPNodes.TCPNode[i].delayTo = ceil(drand48()*(topo.TCPNodes.TCPNode[i].delayFrom-2));
00085     topo.TCPNodes.TCPNode[i].delayFrom -= topo.TCPNodes.TCPNode[i].delayTo;
00086     
00087     // Maximum delay between the start of all sources 
00088     rnd = ((double)(drand48()*TCP_start_time));
00089     topo.TCPNodes.TCPNode[i].startTime = rnd;
00090   }
00091 
00092   fscanf(filer,"%d %lf %d %d %lf\n",&topo.CBRTraffic.NoAttackers,&topo.CBRTraffic.DDOSRate,&pack_size,&master,&DDOS_start_time); 
00093   CBRTrafficInet(diameter,topo.CBRTraffic.NoAttackers, master, topo.CBRTraffic.DDOSRate, &topo.CBRTraffic.DDOSTraffic);
00094   if(master==0)
00095     topo.CBRTraffic.master = NoMaster;
00096   else
00097     topo.CBRTraffic.master = Master;
00098   topo.CBRTraffic.MaxTime = topo.CBRTraffic.DDOSTraffic.Events[topo.CBRTraffic.DDOSTraffic.NoEvents-1].delay;
00099   fscanf(filer,"%lf\n",&finish_time);
00100   printf("Topology Generated Using:\n Diameter=%d BottleNeck: BW=%.3fMbps Delay=%.3fms\n \
00101 Background Traffic: TCP Nodes=%d BW=%.3lfMbps Starttime=%.1lfs\n \
00102 Dos Traffic       : Attacker= %d BW=%.3lfMbps Starttime=%.1lfs\n \
00103 PacketSize=%dB  Master = %d  Finishtime = %.1lfs\n", \
00104      diameter,bn_bw,bn_delay,topo.TCPNodes.NoNodes,bw,TCP_start_time, \
00105      topo.CBRTraffic.NoAttackers, \
00106          topo.CBRTraffic.DDOSRate, DDOS_start_time,pack_size,master,finish_time);
00107 }
00108 
00109 void TCL_Write_Initial(FILE *filew){
00110   fprintf(filew, "set ns [new Simulator]\n\n\n");
00111   /* Incase we need nam support */
00112   //fprintf(filew, "set nf [open out.nam w]\n");
00113   //fprintf(filew, "$ns namtrace-all $nf\n\n\n");
00114   //fprintf(filew, "proc finish {} { \n  global ns nf \n  $ns flush-trace \n  close $nf \n  exec nam out.nam & \n  exit 0 \n  }\n\n\n");
00115   /***till here***/
00116   fprintf(filew, "proc finish {} {\n  exit 0 \n  }\n\n\n");
00117 }
00118 
00119 
00120 void TCL_Write_Nodes(FILE *filew){
00121   fprintf(filew, "for {set i 0} {$i < %d} {incr i} { \n  set TCPSend($i) [$ns node] \n  }\n\n",topo.TCPNodes.NoNodes);
00122   fprintf(filew, "for {set i 0} {$i < %d} {incr i} { \n  set TCPRecv($i) [$ns node] \n  }\n\n",topo.TCPNodes.NoNodes);
00123 
00124   
00125    fprintf(filew,"set BotLeft [$ns node] \n");
00126    fprintf(filew,"set BotRight [$ns node] \n");
00127    fprintf(filew,"set DDOSNode [$ns node] \n");
00128    fprintf(filew,"set Victim [$ns node] \n");
00129 
00130    fprintf(filew,"\n\n");
00131 }
00132 
00133 
00134 void TCL_Write_Connections(FILE *filew){
00135   int i;
00136   for(i=0;i<topo.TCPNodes.NoNodes;i++){
00137     fprintf(filew,"$ns duplex-link $TCPSend(%d) $BotLeft %.3lfMb %.3lfms DropTail\n",i,bw,topo.TCPNodes.TCPNode[i].delayTo*bn_delay); 
00138     fprintf(filew,"$ns duplex-link $TCPRecv(%d) $BotRight %.3lfMb %.3lfms DropTail\n",i,bw,topo.TCPNodes.TCPNode[i].delayFrom*bn_delay); 
00139   }
00140 
00141    fprintf(filew,"\n\n");
00142    fprintf(filew,"$ns duplex-link $BotLeft $BotRight %.3lfMb %.3lfms DropTail\n",bn_bw,bn_delay); 
00143    fprintf(filew,"$ns duplex-link $BotLeft $DDOSNode %.3lfMb %.3lfms DropTail\n",10*bn_bw,bn_delay);
00144    fprintf(filew,"$ns duplex-link $BotRight $Victim %.3lfMb %.3lfms DropTail\n",10*bn_bw,bn_delay);
00145    fprintf(filew,"\n\n");
00146 }
00147 
00148 
00149 void TCL_Write_Agents(FILE *filew){
00150   int i;
00151   double time;
00152 
00153   fprintf(filew, "for {set i 0} {$i < %d} {incr i} { \n    \
00154 set TCPSendAg($i) [new Agent/TCP] \n  \
00155 $ns attach-agent $TCPSend($i) $TCPSendAg($i) \n     \
00156 set TCPSendTraffic($i) [new Application/FTP] \n     \
00157 $TCPSendTraffic($i) attach-agent $TCPSendAg($i) \n   \
00158 set TCPRecvAg($i) [new Agent/TCPSink] \n    \
00159 $ns attach-agent $TCPRecv($i) $TCPRecvAg($i) \n   \
00160 $ns connect $TCPSendAg($i) $TCPRecvAg($i) \n  \
00161 $TCPSendAg($i) set class_ 1 \n}\n\n",topo.TCPNodes.NoNodes);
00162 
00163   fprintf(filew,"\n\n\n");
00164 
00165   for(i=0;i<topo.TCPNodes.NoNodes;i++){
00166     fprintf(filew,"$ns at %lf \"$TCPSendTraffic(%d) start\"\n",topo.TCPNodes.TCPNode[i].startTime,i);
00167   }
00168   fprintf(filew,"\n\n");
00169 }
00170 
00171 
00172 
00173 void TCL_Write_DDOS_Agent(FILE* filew){
00174   int i;
00175 
00176   fprintf(filew,"\n\n");
00177   fprintf(filew,"set DDOSUDP [new Agent/UDP]\n");
00178   fprintf(filew,"$ns attach-agent $DDOSNode $DDOSUDP\n");
00179   fprintf(filew,"set DDOSTraffic [new Application/Traffic/CBR]\n");
00180   fprintf(filew,"$DDOSTraffic attach-agent $DDOSUDP\n");
00181   fprintf(filew,"set VictimAgent [new Agent/Null]\n");
00182   fprintf(filew,"$ns attach-agent $Victim $VictimAgent\n");
00183   fprintf(filew,"$ns connect $DDOSUDP $VictimAgent\n");
00184   fprintf(filew,"$DDOSUDP set class_ 2\n");
00185 
00186 
00187   fprintf(filew,"\n\n\n");
00188 
00189   DDOS_start_time*=1000;
00190   fprintf(filew,"$ns at %lf \"$DDOSTraffic set rate_ %lfMb \"\n",ceil(DDOS_start_time+topo.CBRTraffic.DDOSTraffic.Events[0].delay*bn_delay)/1000, \
00191                                        topo.CBRTraffic.DDOSTraffic.Events[0].NetCBR);
00192   fprintf(filew,"$ns at %lf \"$DDOSTraffic set packet_size_ %d \"\n",\
00193                                        ceil(DDOS_start_time+topo.CBRTraffic.DDOSTraffic.Events[0].delay*bn_delay)/1000,pack_size);
00194   fprintf(filew,"$ns at %lf \"$DDOSTraffic start\"\n",ceil(DDOS_start_time+topo.CBRTraffic.DDOSTraffic.Events[0].delay*bn_delay)/1000);
00195 
00196   for(i=1;i<topo.CBRTraffic.DDOSTraffic.NoEvents;i++){
00197     fprintf(filew,"$ns at %lf \"$DDOSTraffic set rate_ %lfMb\"\n",\
00198                                        ceil(DDOS_start_time+topo.CBRTraffic.DDOSTraffic.Events[i].delay*bn_delay)/1000, 
00199                                        topo.CBRTraffic.DDOSTraffic.Events[i].NetCBR);
00200   }
00201 
00202   fprintf(filew,"\n\n");
00203 
00204 }
00205 
00206 
00207 void TCL_Write_Final(FILE *filew){
00208   fprintf(filew,"\n\n");
00209   fprintf(filew,"set outfile [open qtrace.tr w]\n$ns trace-queue $BotLeft $BotRight $outfile\n\n\n");
00210   fprintf(filew,"$ns at %lf \"finish\"\n",finish_time);
00211   fprintf(filew, "$ns run\n");
00212 }
00213 
00214 
00215 
00216 
00217 
00218 

Generated on Tue Mar 6 16:47:44 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6