mtcp-stack / mtcp

mTCP: A Highly Scalable User-level TCP Stack for Multicore Systems
Other
1.98k stars 435 forks source link

Issue establishing tcp connection #268

Closed agdomacena2 closed 4 years ago

agdomacena2 commented 4 years ago

Hi, I am creating a simple application where a server sends a file to a client through tcp. My server code is running in a vanilla Linux TCP stack while my client runs using mTCP and DPDK. I am having issues connecting the client to the server with mtcp_connect as the server does not send the SYN/ACK needed for the 3 way handshake. I already tried doing this with the sample epwget application and a connection is established so I believe that the server is not the problem. My main function where the mtcp_connect is below.


int main(int argc , char *argv[])
 {
  int socket_desc;
  in_addr_t saddr, daddr;
  in_port_t dport;
  struct sockaddr_in server;
  struct mtcp_conf;
  struct mtcp_epoll_event ev, events[MAX_EVENTS];
  int core_limit = 1;
  int core = 1;
  int ret;
  int ep;
  int nevents;
  char *conf_file = "test.conf";
  ret = mtcp_init(conf_file);
  if(ret){
    printf("NO CONFIGURATION\n");
    return 1;
  }
  mctx_t mctx = mtcp_create_context(core);

  saddr = inet_addr("10.0.0.1");
  daddr = inet_addr("10.0.0.2");
  dport = htons(8889);
  mtcp_init_rss(mctx, saddr, 1, daddr, dport);
  ep = mtcp_epoll_create(mctx, MAX_EVENTS);

  //Create socket
  socket_desc = mtcp_socket(mctx, AF_INET , SOCK_STREAM , 0);

  if (socket_desc < 0) {
  printf("Could not create socket");
  }

  memset(&server,0,sizeof(server));
  server.sin_addr.s_addr = daddr;
  server.sin_family = AF_INET;
  server.sin_port = htons( 8898 );
  printf("CONNECTING\n");

  //Connect to remote server
  ret = mtcp_connect(mctx, socket_desc, (struct sockaddr *)&server, sizeof(server));
  printf("CONNECTING\n");
  if (ret < 0) {
    if (errno != EINPROGRESS) {
      perror("mtcp_connect");
      mtcp_close(mctx, socket_desc);
      return -1;
    }
   }
 // ...
}
ajamshed commented 4 years ago

Hi, I am creating a simple application where a server sends a file to a client through tcp. My server code is running in a vanilla Linux TCP stack while my client runs using mTCP and DPDK. I am having issues connecting the client to the server with mtcp_connect as the server does not send the SYN/ACK needed for the 3 way handshake. I already tried doing this with the sample epwget application and a connection is established so I believe that the server is not the problem. My main function where the mtcp_connect is below.

int main(int argc , char *argv[])
 {
  int socket_desc;
  in_addr_t saddr, daddr;
  in_port_t dport;
  struct sockaddr_in server;
  struct mtcp_conf;
  struct mtcp_epoll_event ev, events[MAX_EVENTS];
  int core_limit = 1;
  int core = 1;
  int ret;
  int ep;
  int nevents;
  char *conf_file = "test.conf";
  ret = mtcp_init(conf_file);
  if(ret){
    printf("NO CONFIGURATION\n");
    return 1;
  }
  mctx_t mctx = mtcp_create_context(core);

  saddr = inet_addr("10.0.0.1");
  daddr = inet_addr("10.0.0.2");
  dport = htons(8889);
  mtcp_init_rss(mctx, saddr, 1, daddr, dport);
  ep = mtcp_epoll_create(mctx, MAX_EVENTS);

  //Create socket
  socket_desc = mtcp_socket(mctx, AF_INET , SOCK_STREAM , 0);

  if (socket_desc < 0) {
  printf("Could not create socket");
  }

  memset(&server,0,sizeof(server));
  server.sin_addr.s_addr = daddr;
  server.sin_family = AF_INET;
  server.sin_port = htons( 8898 );
  printf("CONNECTING\n");

It will be super-awkward if this is the root cause of the problem. Please notice the port number (8889 -> 8898)

  //Connect to remote server
  ret = mtcp_connect(mctx, socket_desc, (struct sockaddr *)&server, sizeof(server));
  printf("CONNECTING\n");
  if (ret < 0) {
    if (errno != EINPROGRESS) {
      perror("mtcp_connect");
      mtcp_close(mctx, socket_desc);
      return -1;
    }
   }
 // ...
}
agdomacena2 commented 4 years ago

Hi, it seems my problem was actually with my epoll event queue handling instead of the ports, Thanks for answering.