dosdbellasim.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, "# Dumping asim data\n\n");
00111 }
00112 
00113 
00114 void TCL_Write_Nodes(FILE *filew){
00115     
00116 }
00117 
00118 void TCL_Write_Connections(FILE *filew){
00119   int i;
00120   int bw_;
00121   double del_;
00122   int c;
00123 
00124   bw_ = ((int)bn_bw * 125);
00125   del_ = bn_delay*1.0/1000;
00126   fprintf(filew,"m %d\n",topo.TCPNodes.NoNodes*2+3);
00127   fprintf(filew,"link 1  %.3lf %d %d 50 \n",del_,bw_,bw_);
00128 
00129   c=3;
00130   for(i=0;i<topo.TCPNodes.NoNodes;i++){
00131       bw_ = ((int)(bw*125));
00132       del_= topo.TCPNodes.TCPNode[i].delayTo*bn_delay/1000;
00133       fprintf(filew,"link %d  %.3lf %d %d 50 \n", c+1, del_,bw_,bw_);
00134       fprintf(filew,"link %d  %.3lf %d %d 50 \n", c+2, del_,bw_,bw_);
00135       c=c+2;
00136   }
00137 }
00138 
00139 
00140 void TCL_Write_Agents(FILE *filew){
00141     int i;
00142     double time;
00143     
00144     int c = 3;
00145     fprintf(filew,"n %d \n",topo.TCPNodes.NoNodes+1);
00146     for(i=1; i<=topo.TCPNodes.NoNodes; i++){
00147         fprintf(filew,"route %d 3 %d 1 %d\n", i, c+1,c+2);
00148         c=c+2;
00149     }
00150 }
00151 
00152 
00153 
00154 void TCL_Write_DDOS_Agent(FILE* filew){
00155 
00156     int i;
00157     double ddosbw;  
00158     fprintf(filew,"# Ddos stuff\n");
00159     
00160     ddosbw =  topo.CBRTraffic.DDOSTraffic.Events[0].NetCBR;
00161     for(i=1;i<topo.CBRTraffic.DDOSTraffic.NoEvents;i++){
00162         ddosbw+=topo.CBRTraffic.DDOSTraffic.Events[i].NetCBR;
00163     }
00164     fprintf(filew,"route %d 3 2 1 3 cbr %d\n",topo.TCPNodes.NoNodes+1,
00165         ((int)(ddosbw*125)));
00166 
00167 }
00168 
00169 
00170 void TCL_Write_Final(FILE *filew){
00171   fprintf(filew,"\n\n");
00172   fprintf(filew,"set outfile [open qtrace.tr w]\n$ns trace-queue $BotLeft $BotRight $outfile\n\n\n");
00173   fprintf(filew,"$ns at %lf \"finish\"\n",finish_time);
00174   fprintf(filew, "$ns run\n");
00175 }
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 

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