Example #1
0
void readRouter()
{
	////FILE * datafile;
	FILE * outfile;
	struct network* target;
	////int id1;
	////int id2;
	////double weight;
	////int error;
	////int totalNum;
	struct netInfo* netinfo;
	struct CLSTS* clsts;
	FILE * pFile_node;
	FILE * pFile_pajek;

	// 2) analyze the properties
	target=NULL;
	outfile=fopen("./realdata/Router_net.txt", "r");
	inputNetwork(&target, outfile);
	fclose (outfile);

	printf("\n %d %d \n", target->nodeNum, target->linkNum);

	// getNetwork Info
	netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
	initNetInfo(netinfo, target);
	getBasicNetInfo(target, netinfo);
	clsts=NULL;
	getCLSTS(target,&clsts);
	getClstNetInfo(target, clsts, netinfo); 

	pFile_node=fopen("Router_node.txt", "w");
	outputNodeInfo(netinfo, pFile_node);
	fclose (pFile_node);
	// statis info

	pFile_pajek=fopen("Router_pajek.txt", "w");
	outputNetwork_pajek( target, pFile_pajek);
	fclose (pFile_pajek);
	
	printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
	
	freeNetwork(target);
	freeCLSTS(clsts);
	freeNetInfo(netinfo);

}
Example #2
0
PyObject *_netzInfo(PyObject *self, PyObject *args)
{
	netinfo *nInfo;
	char *s;
	PyObject *plist, *name, *ip, *service, *mac, *result, *domain, *host;
	int i;

	if(!PyArg_ParseTuple(args, "s", &s)) {
		PyErr_SetString(error, "netzInfo(ip/24)");
		return NULL;
	}

	if(!(plist= PyList_New(0)))  return NULL;
	if(!(result= PyList_New(0)))  return NULL;
	nInfo = newNetInfo();
	netzInfo(s, nInfo);
	for (i=0; i<256; i++) 
	{ 
		if(nInfo[i].ip[0] == '\0') {
			break;
		}
		else
		{
			host = Py_BuildValue("s", "host");
			service = Py_BuildValue("s", nInfo[i].service);
			domain = Py_BuildValue("s", nInfo[i].domain);
			ip = Py_BuildValue("s", nInfo[i].ip);
			name = Py_BuildValue("s", nInfo[i].name); 
			mac = Py_BuildValue("s", nInfo[i].mac);
			PyList_Append(plist, host);
			PyList_Append(plist, name);
			PyList_Append(plist, ip);
			PyList_Append(plist, mac);
			PyList_Append(plist, domain);
			PyList_Append(plist, service);
			PyList_Append(result, plist);
			if(!(plist= PyList_New(0)))  return NULL;
			
		}
	} 
	freeNetInfo(nInfo);
	return result;
	//return Py_BuildValue("s", nInfo[0].name);
}
Example #3
0
void 
ER1Test()
{
	int i;
	int nodeNum, linkNum;

	FILE * pFile_lck;
	//FILE * pFile_node;
	FILE * pFile_net;

      FILE * pFile_pk;
	struct network * target;
	struct netInfo *  netinfo;
	struct CLSTS *   clsts;

	double av_k;
	double      max_k;
	double av_coef ;
	double e_loc ;
	double S_size ; 
	double av_s;
	double S_avspl ;
	double 	S_maxspl ;				 		   
	double	e_glob_active  ;
	double	S_e_glob  ;		
	
	target=NULL;
	netinfo=NULL;
	clsts=NULL;
	
	pFile_lck = fopen("er1_lck.txt","a");
		
	//nodeNum = 332;
	//linkNum = 2126;	

	nodeNum = 20000;
	linkNum = 50000;	
	
	i=0;
	av_k      = 0;
	max_k     = 0;
	av_coef   = 0;
	e_loc       = 0;
	S_size     = 0;
	av_s        = 0;
	S_avspl   = 0;
	S_maxspl  = 0;		 		   
	e_glob_active   = 0;
	S_e_glob  = 0;
	while(1)
	{
		if(i==1)
		{
			break;
		}
		printf(" i = %d  ..............................  \n", i);
		target=(struct network *)mem_alloc(sizeof(struct network));
		erModel_1(target, nodeNum, linkNum);

		pFile_net=fopen("er1_net.txt", "w");
		pFile_pk=fopen("er1_pk.txt","w");
		outputNetwork(target, pFile_net);
		outputpk(target,  pFile_pk);
		fclose (pFile_net);
		fclose (pFile_pk);
/*
		// getNetwork Info
		netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
		initNetInfo(netinfo, target);
		getBasicNetInfo(target, netinfo);
		clsts=NULL;
		getCLSTS(target,&clsts);
		getClstNetInfo(target, clsts, netinfo); 

		pFile_node=fopen("er1_node.txt", "w");
		outputNodeInfo(netinfo, pFile_node);
		fclose (pFile_node);

		
		
		// statis info
	
		av_k      += netinfo->av_k ;
		max_k    += netinfo->max_k;
		av_coef  += netinfo->av_coef;
		e_loc      += netinfo->e_loc;
		S_size     +=  netinfo->S_size; 
		av_s       +=  netinfo->av_s;
		S_avspl   +=    netinfo->S_avspl;
		S_maxspl +=     netinfo->S_maxspl;				 		   
		e_glob_active  +=   netinfo->e_glob_active;
		S_e_glob        +=   netinfo->S_e_glob;		
		
		printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		
		fprintf(pFile_lck, " %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		
		
*/
		i++;
		freeNetwork(target);
		freeCLSTS(clsts);
		freeNetInfo(netinfo);
	}
	/*
	av_k/=i;
	max_k/=i;
	av_coef/=i;
	e_loc/=i; 
	S_size/=i; 
	av_s/=i; 
	S_avspl/=i; 
	S_maxspl/=i; 			 		   
	e_glob_active/=i; 	
	S_e_glob/=i; 	
	
      fprintf(pFile_lck, " %.5f  %.5f %.5f  %.5f  %.5f  %.5f  %.5f  %.5f  %.5f  %.5f \n",
		    			av_k,
					max_k,
					av_coef,
					e_loc, 
					S_size, 
					av_s, 
					S_avspl, 
					S_maxspl, 			 		   
					e_glob_active,	
					S_e_glob); 	
	*/
      	
	fclose(pFile_lck);      

}
Example #4
0
// for software network test
void 
ERTest()
{
	int i;
	int nodeNum;
	time_t time_begin,time_end;
	FILE * pFile_lck;
	FILE * pFile_node;
	FILE * pFile_link;
	FILE * pFile_net;
	struct network * target;
	struct netInfo *  netinfo;
	struct CLSTS *   clsts;
	double p;
	
	target=NULL;
	netinfo=NULL;
	clsts=NULL;
	pFile_lck = fopen("er_lck.txt","a");
	pFile_node=fopen("er_node.txt", "w");
	pFile_link=fopen("er_link.txt", "w");
	pFile_net=fopen("er_net.txt", "w");

/*	
	nodeNum = 2999;
	linkNum = 97676;
	par.p=(double)(65.8/(double)nodeNum/(double)2);
*/

	nodeNum = 10;
	p=0.3;


	time(&time_begin);
	i=0;
	while(1)
	{
		if(i==1)
		{
			break;
		}
		printf(" i = %d  ..............................  \n", i);

		target=(struct network *)mem_alloc(sizeof(struct network));		
		erModel(target, nodeNum, p);

		
		showNetwork(target);
		outputNetwork(target, pFile_net);
		
		// getNetwork Info
		netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
		initNetInfo(netinfo, target);
		getBasicNetInfo(target, netinfo);

		// ouput the basic info
		outputNodeInfo(netinfo, pFile_node);
		outputLinkInfo(netinfo, pFile_link);
				
		clsts=NULL;
		getCLSTS(target,&clsts);
		getClstNetInfo(target, clsts, netinfo); 

		// statis info
		/*
		av_k      = netinfo->av_k ;
		max_k     = netinfo->max_k;
		av_coef  = netinfo->av_coef;
		e_loc      = netinfo->e_loc;
		S_size     =  netinfo->S_size; 
		av_s       =  netinfo->av_s;
		S_avspl   =    netinfo->S_avspl;
		S_maxspl =     netinfo->S_maxspl;				 		   
		e_glob_active  =   netinfo->e_glob_active;
		S_e_glob        =   netinfo->S_e_glob;		
		*/
		printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		
		fprintf(pFile_lck, " %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		i++;
		freeNetwork(target);
		freeCLSTS(clsts);
		freeNetInfo(netinfo);
	}
	/*
	av_k/=i;
	max_k/=i;
	av_coef/=i;
	e_loc/=i; 
	S_size/=i; 
	av_s/=i; 
	S_avspl/=i; 
	S_maxspl/=i; 			 		   
	e_glob_active/=i; 	
	S_e_glob/=i; 	
	
      fprintf(pFile_lck, "  %.2f  %.2f  %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f \n",
		    			av_k,
					max_k,
					av_coef,
					e_loc, 
					S_size, 
					av_s, 
					S_avspl, 
					S_maxspl, 			 		   
					e_glob_active,	
					S_e_glob); 	
	*/
	time(&time_end);
      	printf("\n exhausted time: %ld \n",time_end-time_begin);
      	
	fclose(pFile_lck);   
	fclose (pFile_node);
	fclose (pFile_link);
	fclose (pFile_net);

}
Example #5
0
// for software network test
void 
expTest()
{
	int step;
	int i;
	int nodeNum, linkNum;
	time_t time_begin,time_end;
	FILE * pFile_lck;
	FILE * pFile_node;
	struct network * target=NULL;
	struct netInfo *  netinfo=NULL;
	struct CLSTS *   clsts=NULL;
	int m0, m, M;

	//double av_k, max_k, av_coef,e_loc;
	//double S_size, av_s, S_avspl, S_maxspl, e_glob_active,S_e_glob;
	target=NULL;
	netinfo=NULL;
	clsts=NULL;
	pFile_lck = fopen("exp_lck.txt","a");
	nodeNum = 2999;
	linkNum = 97676;
	m=33;
	m0=33;
	M=33; // no local world effect  - > generating exp network
	step=nodeNum-m0;
	
	time(&time_begin);
	i=0;
	while(1)
	{
		if(i==1)
		{
			break;
		}
		printf(" i = %d  ..............................  \n", i);
		target=(struct network *)mem_alloc(sizeof(struct network));
		lwModel(target, m0, M, m, step);

		// getNetwork Info
		netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
		initNetInfo(netinfo, target);
		getBasicNetInfo(target, netinfo);
		clsts=NULL;
		getCLSTS(target,&clsts);
		getClstNetInfo(target, clsts, netinfo); 

		pFile_node=fopen("exp_node.txt", "w");
		outputNodeInfo(netinfo, pFile_node);
		fclose (pFile_node);
		
		// statis info
		/*
		av_k      = netinfo->av_k ;
		max_k     = netinfo->max_k;
		av_coef  = netinfo->av_coef;
		e_loc      = netinfo->e_loc;
		S_size     =  netinfo->S_size; 
		av_s       =  netinfo->av_s;
		S_avspl   =    netinfo->S_avspl;
		S_maxspl =     netinfo->S_maxspl;				 		   
		e_glob_active  =   netinfo->e_glob_active;
		S_e_glob        =   netinfo->S_e_glob;		
		*/
		printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %.5d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl,
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		
		fprintf(pFile_lck, " %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %.5d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl,
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
		i++;
		freeNetwork(target);
		freeCLSTS(clsts);
		freeNetInfo(netinfo);
	}
	/*
	av_k/=i;
	max_k/=i;
	av_coef/=i;
	e_loc/=i; 
	S_size/=i; 
	av_s/=i; 
	S_avspl/=i; 
	S_maxspl/=i; 			 		   
	e_glob_active/=i; 	
	S_e_glob/=i; 	
	
      fprintf(pFile_lck, "  %.2f  %.2f  %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f \n",
		    			av_k,
					max_k,
					av_coef,
					e_loc, 
					S_size, 
					av_s, 
					S_avspl, 
					S_maxspl, 			 		   
					e_glob_active,	
					S_e_glob); 	
	*/
	time(&time_end);
      	printf("\n exhausted time: %ld \n",time_end-time_begin);
      	
	fclose(pFile_lck);      

}
Example #6
0
/*
     Analyze the statistical properties of SCN
  */
void
analyzeSCN(struct network *  scn,  // input : the network
           char *                dir_p) // input: the dir to store the info files
{
    // <1>  structural properties: regard the network as an unweighted one
    struct netInfo* netinfo;
    struct CLSTS* clsts;
    char * filename;
    int name_size=30;
    FILE *outfile;

    filename=(char *)mem_alloc(name_size*sizeof(char));
    //  basic information
    memset(filename, 0, name_size);
    strcat(filename, dir_p);
    strcat(filename, "basic.txt");
    outfile=fopen(filename, "w");
    fprintf(outfile,"%d %d", scn->nodeNum, scn->linkNum/2);
    fclose (outfile);

    // getNetwork Info
    netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
    initNetInfo(netinfo, scn);
    printf(" begin to get basic info  ---------------------------- \n");
    getBasicNetInfo(scn, netinfo);
    clsts=NULL;
    printf(" begin to get clst info  ---------------------------- \n");
    getCLSTS(scn,&clsts);
    getClstNetInfo(scn, clsts, netinfo);
    memset(filename, 0, name_size);
    strcat(filename, dir_p);
    strcat(filename, "property.txt");
    outfile=fopen(filename, "w");
    printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d %.5f  %.5f \n",
           netinfo->av_k,
           netinfo->max_k,
           netinfo->av_coef,
           netinfo->e_loc,
           netinfo->S_size,
           netinfo->av_s,
           netinfo->S_avspl,
           netinfo->S_maxspl,
           netinfo->e_glob_active,
           netinfo->S_e_glob);

    fprintf(outfile, " %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d %.5f  %.5f\n",
            netinfo->av_k,
            netinfo->max_k,
            netinfo->av_coef,
            netinfo->e_loc,
            netinfo->S_size,
            netinfo->av_s,
            netinfo->S_avspl,
            netinfo->S_maxspl,
            netinfo->e_glob_active,
            netinfo->S_e_glob);
    fclose (outfile);

    // structural properties: regard the network as a weighted one
    printf(" begin to output node info into .txt file  ---------------------------- \n");
    memset(filename, 0, name_size);
    strcat(filename, dir_p);
    strcat(filename, "node_info.txt");
    outfile=fopen(filename, "w");
    outputNodeInfo(netinfo, outfile);
    fclose (outfile);
    printf(" begin to output link info into .txt file  ---------------------------- \n");
    memset(filename, 0, name_size);
    strcat(filename, dir_p);
    strcat(filename, "link_info.txt");
    outfile=fopen(filename, "w");
    outputLinkInfo(netinfo, outfile);
    fclose (outfile);

    freeNetInfo(netinfo);
    freeCLSTS(clsts);
    mem_free(filename);
}
Example #7
0
void
read_AS_caida()
{
	FILE * datafile;
	FILE * outfile;
	struct network* target;
	int id1;
	int id2;
	double weight;
	int error;
	int totalNum;
	struct netInfo* netinfo;
	struct CLSTS* clsts;
	FILE * pFile_node;

	
	// 1) read the network data from the raw-data file "AS_oregon2.txt"
	target=(struct network *)mem_alloc(sizeof(struct network));

	totalNum=11461;
	initNetwork(target, totalNum, UN_DIRECT_UN_WEIGHT);

	datafile = fopen("./realdata/AS_oregon2.txt", "r");
	while(1)
	{
		error=fscanf(datafile, "%d %d \n", &id1, &id2, &weight);
		// use (id1 id2 weight) to construct  a network
		//printf(" %d (%d , %d) %f \n",error, id1,id2,weight);
		//getchar();
		if(error==-1)
			break;
		error=addLinkToNetwork(target, id1, id2, 1.0);
		error=addLinkToNetwork(target, id2, id1, 1.0);
	}
	fclose(datafile);
	
	outfile=fopen("./realdata/AS_oregon2_net.txt", "w");
	outputNetwork(target, outfile);
	fclose (outfile);

	freeNetwork(target);

	// 2) analyze the properties
	target=NULL;
	outfile=fopen("./realdata/AS_oregon2_net.txt", "r");
	inputNetwork(&target, outfile);
	fclose (outfile);

	printf("\n %d %d \n", target->nodeNum, target->linkNum);

	// getNetwork Info
	netinfo=(struct netInfo*)mem_alloc(sizeof(struct netInfo));
	initNetInfo(netinfo, target);
	getBasicNetInfo(target, netinfo);
	clsts=NULL;
	getCLSTS(target,&clsts);
	getClstNetInfo(target, clsts, netinfo); 

	pFile_node=fopen("AS_oregon2_node.txt", "w");
	outputNodeInfo(netinfo, pFile_node);
	fclose (pFile_node);
	// statis info

	printf(" %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f  %d  %.5f  %.5f \n",
		    			netinfo->av_k,
					netinfo->max_k,
					netinfo->av_coef,
					netinfo->e_loc, 
					netinfo->S_size, 
					netinfo->av_s, 
					netinfo->S_avspl, 
					netinfo->S_maxspl, 			 		   
					netinfo->e_glob_active,	
					netinfo->S_e_glob); 
	
	freeNetwork(target);
	freeCLSTS(clsts);
	freeNetInfo(netinfo);

}