Changeset 95

Show
Ignore:
Timestamp:
02/09/09 16:51:58 (15 years ago)
Author:
trnewman
Message:

Cleaned up the code and put in the hooks for optimization request messages

Location:
vtcross/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/CR_engines/CBR/src/main_cognitive_engine.c

    r89 r95  
    285285    strcpy(buffer, "xml received"); 
    286286    SendMessage(sockfd, buffer); 
    287     printf("xml reception done\n"); 
     287    //printf("xml reception done\n"); 
    288288     
    289289    return 1; 
     
    306306} 
    307307 
     308int GetRequest(int sockfd) 
     309{ 
     310    char buffer[256]; 
     311 
     312        bzero(buffer,256); 
     313        ReadMessage(sockfd,buffer); 
     314 
     315    return 1; 
     316} 
    308317 
    309318int GetExperience(int sockfd, int num_rows, int num_cols,  
     
    536545    // get xml info from server 
    537546    GetXMLFromServer(sockfd, uList, pList, oList, &ce_info); 
    538     print_current_config(uList, pList, oList, &ce_info);  
    539  
     547    printf("Received Radio Operation Profile from Server Successfully.\n\n"); 
     548    //print_current_config(uList, pList, oList, &ce_info);  
     549     
     550     
    540551    // get experience size from server 
    541552    int num_rows, num_cols; 
    542553    GetExperienceSize(sockfd, &num_rows, &num_cols); 
     554     
    543555    // get experience 
    544556    int i, j; 
    545     /*float **past_exp; 
    546     past_exp = (float **)malloc(sizeof(float)*num_rows); 
    547     for (i = 0; i< 1; i++){ 
    548         past_exp[i] = (float*)malloc(sizeof(float)*num_cols); 
    549     }*/ 
    550557    float past_exp[num_rows][num_cols]; 
    551558    GetExperience(sockfd, num_rows, num_cols, past_exp); 
    552     for (i = 0; i < num_rows; i++){ 
    553         printf("experience #%d:\n", i+1); 
    554         for (j = 0; j < num_cols; j++){ 
    555         printf(" %f", past_exp[i][j]); 
    556         } 
    557         printf("\n"); 
    558     } 
    559     
     559    printf("Received Previous Radio Experience from Server Successfully.\n\n"); 
     560     
    560561    // calculate utility 
    561      
    562562 
    563563    // cbr operation 
     
    567567    num_cols = num_cols + ce_info.numObservables; 
    568568    num_cols = num_cols + 1;    // overall utility 
    569     printf("number of rows: %d, number of columns: %d\n", 
    570             num_rows, num_cols); 
    571     RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows,  
     569    
     570    //while(1) { 
     571         
     572        // Wait until request is received from server to perform optimization  
     573        //printf("Waiting for Request for optimization from Server\n\n"); 
     574        //GetRequest(sockfd); 
     575        //printf("Received optimization request from server\n\n"); 
     576        RunCBREngine(uList, pList, oList, &ce_info, num_cols, num_rows,  
    572577            past_exp);     
    573     // print out results 
    574     //int i; 
    575     printf("search result: "); 
    576     for (i=0;i<ce_info.numUtilities; i++) 
    577         printf("%f, ",uList[i].value); 
    578     for (i=0;i<ce_info.numParameters; i++) 
    579         printf("%f, ",pList[i].value); 
    580     for (i=0;i<ce_info.numObservables; i++) 
    581         printf("%f, ",oList[i].value); 
    582     printf("\n"); 
    583      
    584     // send results back to server 
    585     SendCEResults(sockfd, uList, pList, oList, &ce_info); 
    586  
    587  
    588   return 0; 
    589 } 
     578    
     579        printf("Sending optimization results to server.\n\n"); 
     580        // send results back to server 
     581        SendCEResults(sockfd, uList, pList, oList, &ce_info); 
     582    //} 
     583     
     584    return 0; 
     585} 
  • vtcross/trunk/CR_shell/Makefile

    r66 r95  
    33# 
    44 
    5 TESTS = cognitive_radio cognitive_engine 
     5TESTS = cognitive_radio 
    66#CTESTS = client 
    77all: $(TESTS) $(CTESTS) 
     
    1515 
    1616OBJS = tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o 
    17 SOCKET_OBJS = ServerSocket.o Socket.o 
     17#SOCKET_OBJS = ServerSocket.o Socket.o 
    1818#OBJS = cbr.o sqlite3.o utility.o cognitive_radio_test.o ezxml.o 
    1919 
     
    2323#                 src/utility.h src/cognitive_radio_test.h 
    2424 
    25 $(SOCKET_OBJS) : %.o : src/socket/%.cpp 
    26         $(CC) $(CFLAGS) -c $< -o $@ 
     25#$(SOCKET_OBJS) : %.o : src/socket/%.cpp 
     26#       $(CC) $(CFLAGS) -c $< -o $@ 
    2727 
    2828$(OBJS) : %.o : src/%.cpp $(HEADERS) 
  • vtcross/trunk/CR_shell/src/main_cognitive_radio.cpp

    r90 r95  
    5959        for(i = 0; i < ce_info->numParameters; i++) { 
    6060                cout << "Parameter:  " << pList[i]->name << endl; 
     61        printf("Radio Operation Profile has been sucessfully sent.\n"); 
    6162                cout << "       Units:   " << pList[i]->units << endl; 
    6263                cout << "       Min:     " << pList[i]->min << endl; 
     
    115116        } 
    116117        ce_info->numUtilities = i;       
    117         cout << "Parsed " << ce_info->numUtilities << " utilities." << endl; 
     118        cout << "Initialize:: Parsed " << ce_info->numUtilities << " utilities." << endl; 
    118119 
    119120        // Pull observable information from XML file. 
     
    157158        } 
    158159        ce_info->numObservables = i;     
    159         cout << "Parsed " << ce_info->numObservables << " observables." << endl; 
     160        cout << "Initialize:: Parsed " << ce_info->numObservables << " observables." << endl; 
    160161         
    161162 
     
    210211        } 
    211212        ce_info->numParameters = i;      
    212         cout << "Parsed " << ce_info->numParameters << " parameters." << endl; 
     213        cout << "Initialize:: Parsed " << ce_info->numParameters << " parameters." << endl; 
    213214        return 1; 
    214215} 
     
    269270        //int total_bytes;    
    270271 
    271         printf("Sending configuration to CE.\n"); 
     272        printf("Sending Radio Operating Profile to Cognitive Engine.\n\n"); 
    272273  
    273274        // utilities 
     
    319320        } 
    320321         
    321         printf("Configuration sent, waiting for ACK...\n"); 
    322322        // Receive ACK for utils 
    323323    char buffer[256]; 
    324324        string message; 
    325325        n = ReceiveMessage(socketfd, buffer); 
    326     printf("%s\n", buffer); 
     326    //printf("%s\n", buffer); 
    327327        //cout << message << endl; 
    328         printf("ACK received.\n"); 
     328        //printf("ACK received.\n"); 
    329329 
    330330} 
     
    368368    } 
    369369 
    370     printf("experience sent\n"); 
    371370} 
    372371 
     
    389388    float var; 
    390389 
    391     /*// utility 
    392     for (i = 0; i < ce_info->numUtilities; i++){ 
    393         bzero(buffer,256); 
    394         ReceiveMessage(sockfd,buffer); 
    395         var = atof(buffer); 
    396         uList[i]->value = var; 
    397         printf("utility %s, value %f\n" 
    398                 , uList[i]->name.c_str(), uList[i]->value); 
    399     }*/ 
    400      
    401     // paramter 
     390    // Send request optimization message followed by the current environment parameters. 
     391    /* 
     392    SendMessage(sockfd,"request");  
     393    for (i = 0; i < ce_info->numObservables; i++){ 
     394        SendMessage(sockfd,..); 
     395    } 
     396    */ 
     397 
     398    // Receive optimized values from the Cognitive Engine  
    402399    for (i = 0; i < ce_info->numParameters; i++){ 
    403400        bzero(buffer,256); 
     
    405402        var = atof(buffer); 
    406403        pList[i]->value = var; 
    407         printf("parameter %s, value %f\n" 
    408                 , pList[i]->name.c_str(), pList[i]->value); 
    409404    } 
    410405 
    411     /*// observable 
    412     for (i = 0; i < ce_info->numObservables; i++){ 
    413         bzero(buffer,256); 
    414         ReceiveMessage(sockfd,buffer); 
    415         var = atof(buffer); 
    416         oList[i]->value = var; 
    417         printf("observable %s, value %f\n" 
    418                 , oList[i]->name.c_str(), oList[i]->value); 
    419     }*/ 
    420406 
    421407    return 1; 
     
    476462 
    477463        // update ce with experience 
     464    printf("Sending Previous Experience to New Cognitive Engine.\n\n"); 
    478465    UpdateCEExperience(socketfd, num_rows, num_cols, past_exp);  
    479466 
     
    484471        // Start socket server 
    485472        int sockfd, newsockfd, clilen; 
     473        int peer_len = sizeof(struct sockaddr); 
    486474        struct sockaddr_in serv_addr, cli_addr; 
     475        struct sockaddr_in peer; 
     476 
    487477 
    488478        // Setup server socket connection 
     
    507497                        error("ERROR on accept"); 
    508498 
     499        if(getpeername(newsockfd, (struct sockaddr *) &peer, (socklen_t*)&peer_len) == -1) { 
     500            perror("getpeername() failed"); 
     501            return -1; 
     502        } 
     503 
     504        printf("Received a connection from a Cognitive Engine with IP address: %s\n\n",inet_ntoa(peer.sin_addr)); 
     505 
    509506                // Begin parsing the messages 
    510507                StartMessaging(newsockfd, uList, pList, oList, ce_info); 
     
    541538        } 
    542539 
    543         cout << "Attemping to parse " << pFilename << "." << endl; 
     540        cout << "\n\nInitialize:: Attemping to parse " << pFilename << "." << endl; 
    544541        parse_ce_config( &doc , uList, pList, oList, &ce_info); 
    545         cout << "Configuration file parsing completed." << endl; 
     542        cout << "Initialize:: Configuration file parsing completed.\n" << endl; 
    546543 
    547544    //print_current_config(uList, pList, oList, &ce_info);