//******************************************** // IDS_rev32.cpp // ------------------------------------------- // Main program of the SKETCH module // // Author: Yan Gao // Updated by: Leiwen Deng // Date: 12/10/2005 // // The SKETCH module is spawned by the AE and // it handles the SIGUSR1 signal sent from AE. // Every time it receives a SIGUSR1 signal, it // starts to process the input data from a file // and outputs the result to another file, // after which it sends the SIGUSR1 to the AE // to indicate that the processing is done. //******************************************** #include #include #include #include #include #include "globals.h" #include "hash.h" #include "revHash.h" #include "revKSketch.h" #include "IDS.h" using namespace std; static unsigned long long totalitems; // ************* Begin ************* // AE module code #include #define FLAG_RUN_SKETCH 0x1 #define FLAG_EXIT 0x2 static char signal_flag = 0; // ************* End *************** void Load_flow(char *filename, RevKSketch * sketch,int flag) { fstream f; record_t rec; // open the input file f.open(filename, ios::in | ios::binary); if (!f) { cerr << "Error opening the file " << filename << endl; } if (flag == 1) { while (f.read((char *) &rec, sizeof(rec))) { if(rec.src_ip == 145326934) cerr<< rec.src_ip << " " << rec.size << endl; sketch->AddValue(rec.src_ip, flag); totalitems++; } } else { while (f.read((char *) &rec, sizeof(rec))) { sketch->AddValue(rec.src_ip, 0); totalitems++; } } f.close(); } // ************* Begin ************* // AE module code void Sig_User1( int sig_num ) { // Re-set the signal handler, for the next time signal( SIGUSR1, Sig_User1 ); // Set the FLAG_RUN_SKETCH bit signal_flag |= FLAG_RUN_SKETCH; } void Quit( int sig_num ) { signal_flag |= FLAG_EXIT; } // ************* End *************** int main(int argc, char **argv) { // ************* Begin ************* // AE module code if (argc != 5) { cerr << "Usage: IDS_Srev32 " << endl; exit(1); } // ************* End *************** double delta = strtod(argv[1], NULL); int r = 1; int numTbls = 6; int inxBits = 12; int iterSize = 100; int OnumTbls = 6; int OinxBits = 14; cerr<<"OK\n"< 3) { fprintf(stderr, "time=%d\n", current); RevSketchSub(Sketch1, Sketch1, estimate); value2 = Sketch1->extraSketch->EstValue(IPkey); value3 = estimate->extraSketch->EstValue(IPkey); fprintf(stderr,"%.f %.f %.f\n", value2, value3, value4); Sketch1->Detection(offendingKeys, 0); // open the output file f.open(output, ios::out | ios::trunc ); if (!f) { cerr << "Error opening the output file" << endl; } for (list < KeyType >::iterator listIt = offendingKeys.begin(); listIt != offendingKeys.end(); ++listIt) { value=Sketch1->extraSketch->EstValue(*listIt); value2=estimate->extraSketch->EstValue(*listIt); value3=estimate2->extraSketch->EstValue(*listIt); sprintf(ipformat, "%u", (*listIt)); f << ipformat; sprintf(out_format," %.f %.f %.f\n",value, value2, value3); f << out_format; } f.close(); // ************* Begin ************* // AE module code // Send signal to AE indicating that data processing is finished kill( getppid(), SIGUSR1 ); // ************* End *************** } if(n > 1) { RevSketchSum(mid_Sketch1, HWSketch1, Sketch0); RevSketchSum(HWSketch1, HWSketch1, HWSketch2); RevSketchSMul(HWSketch1, 1-alfa); RevSketchSMul(cur_Sketch, alfa); RevSketchSum(HWSketch1, cur_Sketch, HWSketch1); RevSketchSub(mid_Sketch2, HWSketch1, mid_Sketch1); RevSketchSMul(mid_Sketch2, beta); RevSketchSMul(HWSketch2, 1-beta); RevSketchSum(HWSketch2, HWSketch2, mid_Sketch2); RevSketchSum(estimate2, HWSketch2, HWSketch1); RevSketchSub(cur_Sketch2, cur_Sketch2, estimate2); RevSketchABS(cur_Sketch2); RevSketchSMul(cur_Sketch2, gamma); RevSketchSMul(dt_Sketch, 1-gamma); RevSketchSum(d_Sketch, dt_Sketch, cur_Sketch2); RevSketchSum(dt_Sketch, dt_Sketch, cur_Sketch2); RevSketchSMul(d_Sketch, delta); RevSketchSum(estimate, estimate2, d_Sketch); } delete Sketch1; delete cur_Sketch; delete cur_Sketch2; delete mid_Sketch1; delete mid_Sketch2; delete d_Sketch; // ************* Begin ************* // AE module code cerr << "End SKETCH algorithm\n\n"; // ************* End *************** } delete HWSketch1; delete HWSketch2; delete Sketch0; delete dt_Sketch; delete estimate; delete estimate2; return 0; }