Example #1
0
void CFX_CTTGSUBTable::ParseLookupList(FT_Bytes raw, TLookupList* rec) {
  int i;
  FT_Bytes sp = raw;
  rec->LookupCount = GetUInt16(sp);
  if (rec->LookupCount <= 0) {
    return;
  }
  rec->Lookup = new struct TLookup[rec->LookupCount];
  for (i = 0; i < rec->LookupCount; i++) {
    TT_uint16_t offset = GetUInt16(sp);
    ParseLookup(&raw[offset], &rec->Lookup[i]);
  }
}
Example #2
0
int main( int argc, char **argv){

	filePointer = (FILE *) malloc(10 * sizeof(FILE)); 
	int nextHopOctet1 = 0,nextHopOctet2 = 0,nextHopOctet3 = 0,nextHopOctet4 = 0;
	int i = 0, j = 0;
	tempStr = (char *)calloc(1,2*sizeof(char));
	charToStr = (char *)calloc(1,sizeof(char));
	nextHop = (char *)calloc(1,15*sizeof(char));
	data = (char *)calloc(1,20*sizeof(char));
	data1 = (char *)calloc(1,20*sizeof(char));
	mdata = (char *)calloc(1,20*sizeof(char));
	mdata1 = (char *)calloc(1,20*sizeof(char));
	trie = (BiTrie *)calloc(1,sizeof(BiTrie));
	mtrie = (mTrie *)calloc(1,sizeof(mTrie));
	node = (struct TrieNode *)calloc(1,sizeof(struct TrieNode));
	mnode = (struct mTrieNode *)calloc(1,sizeof(struct mTrieNode));
	mflag = (char *)calloc(1,2*sizeof(char));
	tempNode2 = (struct TrieNode *)calloc(1,sizeof(struct TrieNode));
	tempNode1 = (struct TrieNode *)calloc(1,sizeof(struct TrieNode));
	mtempNode2 = (struct mTrieNode *)calloc(1,sizeof(struct mTrieNode));
	mtempNode1 = (struct mTrieNode *)calloc(1,sizeof(struct mTrieNode));
	nextHop1 = (char *)calloc(1,20*sizeof(char));
	mprefixFinal = (char **)calloc(16,sizeof(char *));
	mlookupFinal = (char **)calloc(16,sizeof(char *));
	muprefixFinal = (char **)calloc(16,sizeof(char *));
	lookupfile = (char *)calloc(1,10*sizeof(char));
	updatefile = (char *)calloc(1,10*sizeof(char));
	prefixfile = (char *)calloc(1,10*sizeof(char));
	
	for(i = 0; i<16 ; i++) 
		if( (mprefixFinal[i] = (char *)calloc(3,sizeof(char))) == NULL )
			  fprintf(stderr, "\nMemory cannot be allocated");

	for(i = 0; i<16 ; i++) 
		if( (mlookupFinal[i] = (char *)calloc(3,sizeof(char))) == NULL )
			  fprintf(stderr, "\nMemory cannot be allocated");
	for(i = 0; i<16 ; i++) 
		if( (muprefixFinal[i] = (char *)calloc(3,sizeof(char))) == NULL )
			  fprintf(stderr, "\nMemory cannot be allocated");
	i = 0;

	BiTrieInit(trie);
	mTrieInit(mtrie);

	strcpy(prefixfile,argv[1]);
	filePointer = fopen(prefixfile, "r+");
	
	
	if( filePointer == NULL) 
		fprintf(stderr,"\nMemory cannot be allocated to filepointer");

	else 
	while( !feof(filePointer) ) {
		
		c = (char)getc(filePointer);
		sprintf(charToStr,"%c",c);
		strcat(tempStr,charToStr);
		
		if( c == '.' || c == ' ' || c == '/' || c == '\n') {

			i++;
			if(i == 1) {
				prefixOctet1 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 2) {
				prefixOctet2 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 3) {
				prefixOctet3 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 4) {
				prefixOctet4 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
		
			if(i == 5) {
				prefixLength = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 6) {
				nextHopOctet1 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 7) {
				nextHopOctet2 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 8) {
				nextHopOctet3 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
			if(i == 9) {
				nextHopOctet4 = atoi(tempStr);
				strcpy(tempStr,initializer);
			}
		
		}
			if (c == '\n' ) {
				i = 0;
				strcpy(nextHop,initializer);
				strcpy(data,initializer);
				strcpy(mdata,initializer);
				
			//	printf("\n prefix %d.%d.%d.%d/%d  nextHop %d.%d.%d.%d", prefixOctet1,prefixOctet2, prefixOctet3, prefixOctet4, prefixLength, nextHopOctet1,nextHopOctet2,nextHopOctet3,nextHopOctet4);
				if(prefixLength <= 1 || prefixLength >= 31) {		
					badprefixCount++;
					continue;
				}
				getPrefix(prefixOctet1, prefixOctet2,prefixOctet3,prefixOctet4 ,prefixLength, prefixFinal, mprefixFinal);
				prefixCount++;
				sprintf(nextHop,"%d.%d.%d.%d",nextHopOctet1,nextHopOctet2,nextHopOctet3,nextHopOctet4);
				
				//printf(" prefixFinal : ");
				//for(j = 0 ; j< prefixLength; j++)
					//printf("%d", prefixFinal[j]);
				
				rdtsc(p);
				
				for(j = 0 ; j< prefixLength; j++){
			
					data = NULL;
					
					if( j == 0 && prefixCount > 1) trie->curRoot = trie->root;
					
					if(j == prefixLength -1) {
						data = (char *)calloc(1,20*sizeof(char));
						strcpy(data,nextHop);
					}
					
					if(prefixFinal[j] == 0){	
						trie->curRoot = BiTrieInsert(trie,trie->curRoot,data,0);
						continue;
					}
					
					else {
						if(prefixFinal[j] == 1){
							 trie->curRoot = BiTrieInsert(trie,trie->curRoot,data,1);
						 	 continue;
						}						
					}
				}
				
				rdtsc(q);
				unisum += (q-p);
				rdtsc(r);
				for(j = 0 ; j< mprefixLength; j++){
			
					mdata = NULL;
					
					if( j == 0 && prefixCount > 1) mtrie->curRoot = mtrie->root;
					
					if(j == mprefixLength -1) {
						mdata = (char *)calloc(1,20*sizeof(char));
						strcpy(mdata,nextHop);
					}
					
					if(strcmp(mprefixFinal[j],"00") == 0){	
						mtrie->curRoot = mTrieInsert(mtrie,mtrie->curRoot,mdata,"00",0);
						continue;
					}
					
					if(strcmp(mprefixFinal[j],"01") == 0){	
						mtrie->curRoot = mTrieInsert(mtrie,mtrie->curRoot,mdata,"01",0);
						continue;
					}
					
					if(strcmp(mprefixFinal[j],"10") == 0){	
						mtrie->curRoot = mTrieInsert(mtrie,mtrie->curRoot,mdata,"10",0);
						continue;
					}
					
					if(strcmp(mprefixFinal[j],"11") == 0){	
						mtrie->curRoot = mTrieInsert(mtrie,mtrie->curRoot,mdata,"11",0);
						continue;
					}
					
					else {
						if(strcmp(mprefixFinal[j],"0") == 0){
							 mTrieInsert(mtrie,mtrie->curRoot,mdata,"00",1);
						 	 mTrieInsert(mtrie,mtrie->curRoot,mdata,"01",1);
						 	 
						 	 continue;
						}
						else if(strcmp(mprefixFinal[j],"1") == 0){
							 mTrieInsert(mtrie,mtrie->curRoot,mdata,"10",1);
						 	 mTrieInsert(mtrie,mtrie->curRoot,mdata,"11",1);
						 	 
						 	 continue;
						}
					}
				}
			
				rdtsc(s);
				multisum += (s-r);
			}
		}	
		
	printf("\n-------------------------------------------------------------");	
		
	printf("\nThe total number of nodes in the unibit trie before update is %ld", trie->size);
	printf("\nThe total number of nodes in the multibit trie before update is %ld", mtrie->size);
	printf("\n-------------------------------------------------------------");	
	printf("\nThe total number of prefixes outside specified lengths is %ld", badprefixCount);
	printf("\nThe total time taken to construct unibit trie is %llu cycles", unisum);
	printf("\nThe total time taken to construct multibit trie is %llu cycles", multisum);
	printf("\n-------------------------------------------------------------");	
	printf("\nTotal number of loaded prefixes is %ld", prefixCount);
	printf("\nTotal number of prefixes (loaded + bad) is %ld", prefixCount + badprefixCount);
	printf("\nThe size of the unibit trie is %ld bytes or %ld MB ",(trie->size)*(sizeof(struct TrieNode)), (trie->size)*(sizeof(struct TrieNode))/(1024*1024) );
	printf("\nThe size of the multibit trie is %ld bytes or %ld MB",(mtrie->size)*(sizeof(struct mTrieNode)),(mtrie->size)*(sizeof(struct mTrieNode))/(1024*1024));
	printf("\n-------------------------------------------------------------");	
	
	printf("\nPlease Enter: \n1.Longest Prefix Match \n2.Update \n3.Exit\n");
	
	while(o = getchar()) {
		
		if(o == '1'){
			//printf("\nLooking up...");
			printf("\n--------------");
			printf("\nPlease Enter the filename: ");
			scanf("%s",lookupfile);
			ParseLookup(lookupfile);
		}
		else if(o == '2'){
			//printf("\nUpdating...");
			printf("\n--------------");
			printf("\nPlease Enter the filename: ");
			scanf("%s", updatefile);
			ParseUpdate(updatefile);
		}
		else if(o == '3')
			return 0;
	
		else 
			continue;
	
	
	printf("\n-----------------------------------------------------------------------");
	printf("\n Longest Prefix Match stats");
	printf("\n-----------------------------------------------------------------------");
	printf("\nNumber of addresses looked up is %ld", lookupCount);
	printf("\nThe Median time taken to perform lpm for unibit tries is %u cycles", ulpmmedian);
	printf("\nThe Median time taken to perform lpm for multi bit tries is %u cycles", mlpmmedian);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Mean time taken to perform lpm for unibit tries is %u cycles", ulpmmean);
	printf("\nThe Mean time taken to perform lpm for multi bit tries is %u cycles", mlpmmean);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Min time taken to perform lpm for unibit tries is %u cycles", ulpmmin);
	printf("\nThe Min time taken to perform lpm for multi bit tries is %u cycles", mlpmmin);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Max time taken to perform lpm for unibit tries is %u cycles", ulpmmax);
	printf("\nThe Max time taken to perform lpm for multi bit tries is %u cycles", mlpmmax);
	
	printf("\n-----------------------------------------------------------------------");
	printf("\n Update and Delete stats");
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Total number of values  updated/deleted is %ld", uprefixCount);
	printf("\nThe Total number of new unibit  nodes created is %d\n", newnodes);
	printf("\nThe Total number of new multibit nodes created is %d\n", mnewnodes);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Median time taken to perform updates for unibit tries is %u cycles", uupdatemedian);
	printf("\nThe Median time taken to perform updates for multi bit tries is %u cycles", mupdatemedian);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Mean time taken to perform updates for unibit tries is %u cycles", uupdatemean);
	printf("\nThe Mean time taken to perform updates for multi bit tries is %u cycles", mupdatemean);
	printf("\n-----------------------------------------------------------------------");
	printf("\nThe Min time taken to perform updates for unibit tries is %u cycles", uupdatemin);
	printf("\nThe Min time taken to perform updates for multi bit tries is %u cycles", mupdatemin);
	printf("\n-----------------------------------------------------------------------");	
	printf("\nThe Max time taken to perform updates for unibit tries is %u cycles", uupdatemax);
	printf("\nThe Max time taken to perform updates for multi bit tries is %u cycles", mupdatemax);
	printf("\n-------------------------------------------------------------");	
	

	printf("\n\nThe total number of nodes in the trie after update is %ld", trie->size);
	printf("\n\nThe total number of nodes in the multibit trie after update is %ld", mtrie->size);
	printf("\nThe size of the unibit trie is %ld bytes or %ld MB ",(trie->size)*(sizeof(struct TrieNode)), (trie->size)*(sizeof(struct TrieNode))/(1024*1024) );
	printf("\nThe size of the multibit trie is %ld bytes or %ld MB",(mtrie->size)*(sizeof(struct mTrieNode)),(mtrie->size)*(sizeof(struct mTrieNode))/(1024*1024));
	
	
	
	
	//printf("\nThe lengths of different arrays are %llu, %llu, %llu, %llu\n",ulpmcount, mlpmcount, uupdatecount, mupdatecount);
	
	printf("\n-------------------------------------------------------------");	
	
	printf("\nPlease Enter: \n1.Longest Prefix Match \n2.Update \n3.Exit\n");
	
	}
	
	return 0;
	
}