I.Two Phases: set up communication & request processing

--------------------------------------------------------------------------------

                 ser                                         cli

--------------------------------------------------------------------------------
phrase 1       creat socket and listen

                                    <------------------   hInfo.ifName
                                                          maxSpeed
             fork child process
              readline hInfo.ifName
              readline maxSpeed

phrase 2                                          request ID      request
                                    <------------------
                                                          by wrap_ioctl()

             ioctl(request ID,
                   data)            ------------------->  data







================================================================================

II Compare with old monitor



            old monitor:

            +----------+
            |  Display |
            +----------+
               A   |
               |   V
            +----------+
            | retrieve |
            | ioctl()  |
            +----------+
               A   |
               |   V
            +----------+
            | kernel   |
            +----------+

-------------------------------------------------------------------------------

                                 new monitor

              client                              server

            +----------+
            |  Display |
            +----------+
               A   |
               |   V
            +----------------+ request ID       +-------------+
            | retrieve:      |----------------> | retrieve:   |
            | wrapt_ioctl()  |<---------------  | ioctl()     |
            +----------------+  Data*           +-------------+
                                                   A     |
                                                   |     V
                                                +-------------+
                                                | kernel      |
                                                +-------------+

* the Data sent by server to client by Passing Binary Structures.

==============================================================================

III. Protocols for request communication between Client and Server




wrap_iocl() ----------at end of client

------------------------------------------------------------------------------


int wrap_ioctl(int id,  void *pointer){

  if(id == CLASSIFIER_NUM_CLASSES) {
     write(sockfd, "0", 1);
     write(sockfd, "\n", 1);
     printf("writ id to socket: 0\n");
     Readn(sockfd, pointer, sizeof(num_classes));
  }


  if(id == CLASSIFIER_DEL_CLASS) {
     write(sockfd, "1", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(del_class_t));
  } 

  if(id == CLASSIFIER_BACKLOG_ON){
     write(sockfd, "2", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(interface_name));
     printf("id = 2 \n");
  }

  if(id == CLASSIFIER_BACKLOG_ON) {
     write(sockfd, "3", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(interface_name));
     printf("id = 3 \n");
  }

  if(id == CLASSIFIER_BACKLOG_ON) {
     write(sockfd, "4", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(interface_name));
     printf("id = 4 \n"); 
  }

  if(id == CLASSIFIER_BACKLOG_ON) {
     write(sockfd, "5", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(interface_name));
     printf("id = 5 \n"); 
  }
  
  if(id == CLASSIFIER_MOD_CLASS){ 
     write(sockfd, "6", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(interface_name));
      printf("id = 6 \n");  
  }

  if(id == CLASSIFIER_MOV_CLASS){
     write(sockfd, "7", 1 );
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(mov_class_t));
     printf("id = 7 \n"); 
  }
  if(id == CLASSIFIER_CREATE_CLASS){  
     write(sockfd, "8", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(create_class_t));   
     printf("id = 8 \n");
  }  
   
  if(id == CLASSIFIER_NTH_CLASS){  
     write(sockfd, "9", 1);
     write(sockfd, "\n", 1);
     Readn(sockfd, pointer, sizeof(nthClass));   
     printf("id = 9 \n");
  } 
  printf("OK for writing a id\n");
  return 1;
}
-----------------------------------------------------------------------
request_handle   ---------at end of server

----------------------------------------------------------------------

get request_id from client..........


void serve_client(int socket_to_client, int socket_to_kernel){
  del_class_t    delClass;
  interface_name in;
  mod_class_t    modClass;
  mov_class_t    movClass;
  create_class_t newClass;
  nth_class      nthClass;
  num_classes    nc;

  int            n, request_id;
  int            ret;
  char           line[MAXLINE];

  request_id = atoi(line);
 
  switch (request_id) {
      
  case 0:
    ret = ioctl(socket_to_kernel, CLASSIFIER_NUM_CLASSES, &nc);
    Writen(socket_to_client,  &nc , sizeof(num_classes));
    break;
      
  case 1:
    ret = ioctl(socket_to_kernel, CLASSIFIER_DEL_CLASS, &delClass);
    Writen(socket_to_client,  &delClass , sizeof(del_class_t));
    break;
      
  case 2:
    ret = ioctl(socket_to_kernel, CLASSIFIER_BACKLOG_ON, &in);
    Writen(socket_to_client,  &in , sizeof(interface_name));
    break;
      
  case 3:
    ret = ioctl(socket_to_kernel, CLASSIFIER_BACKLOG_OFF, &in);
    Writen(socket_to_client,  &in , sizeof(interface_name));
    break;

  case 4:
    ret = ioctl(socket_to_kernel,  CLASSIFIER_MMODE_ON, &in);
    Writen(socket_to_client,  &in , sizeof(interface_name));
    break;
      
  case 5:
    ret = ioctl(socket_to_kernel,  CLASSIFIER_MMODE_OFF, &in);
    Writen(socket_to_client,  &in , sizeof(interface_name));
    break;

  case 6:
    ret = ioctl(socket_to_kernel, CLASSIFIER_MOD_CLASS, &modClass);
    Writen(socket_to_client,  &modClass , sizeof(mod_class_t));
    break;
      
  case 7:
    ret = ioctl(socket_to_kernel, CLASSIFIER_MOV_CLASS, &movClass);
    Writen(socket_to_client,  &movClass , sizeof(mov_class_t));
    break;

  case 8:
    ret = ioctl(socket_to_kernel, CLASSIFIER_CREATE_CLASS, &newClass);
    Writen(socket_to_client,  &newClass , sizeof(create_class_t));
    break;
      
  case 9:
    bzero(&nthClass, sizeof(nth_class));
    ret = ioctl(socket_to_kernel,  CLASSIFIER_NTH_CLASS, &nthClass);
    Writen(socket_to_client,  &nthClass , sizeof(nth_class));
    break;
  }
} 
============================================================================