ok I attach the file which is the modified source of frag_ip.c
I can rtping from each to other on both sides.
I insert the rtudp module
I can do local udp message sending/receiving.
so far, no error has shown.
But when I try to send udp packet from one host to the other, it still
not happening as previous, so the error message is:
Sending message of 65505+2 bytes
rt_dev_sendmsg() = -11!
thank you for your help and patience
Jan Kiszka <jan.kis...@web.de> a écrit :
Am 14.09.2010 09:20, Michel He wrote:
Yes I started the program on _both_ nodes by specifying the other node
as destination, as follow :
/* bind the rt-socket to a port */
local_addr.sin_addr.s_addr = INADDR_ANY;
/* set destination address */
dest_addr.sin_addr = dest_ip;
So you modified the demo source code? The details are still unclear to
me, and as the effect you described is quite weird, something must be
different in your setup.
Btw, I'd like to know the difference between:
rt_dev_socket(AF_INET,SOCK_DGRAM,0);
and
rt_dev_socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
Why: 0 and IPPROTO_UDP ?
0 means "pick the default" - which is UDP for SOCK_DGRAM. So the lines
have the same effect.
Jan
/***
*
* examples/xenomai/frag-ip.c
*
* sends fragmented IP packets to another frag-ip instance - Xenomai version
*
* Copyright (C) 2003-2005 Jan Kiszka <jan.kis...@web.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <native/task.h>
#include <rtnet.h>
#include <rtnet_config.h> /* required for rt_task_wait_period() changes */
char *dest_ip_s = "127.0.0.1";
unsigned int size = 65505;
unsigned int add_rtskbs = 75;
#define CYCLE 1000*1000*1000 /* 1 s */
RT_TASK rt_xmit_task;
RT_TASK rt_recv_task;
#define PORT 37000
struct sockaddr_in dest_addr;
int sock;
char buffer_out[64*1024];
char buffer_in[64*1024];
void xmit_msg(void *arg)
{
int ret;
struct msghdr msg;
struct iovec iov[2];
unsigned short msgsize = size;
rt_task_set_periodic(NULL, TM_NOW, CYCLE);
while (1) {
iov[0].iov_base = &msgsize;
iov[0].iov_len = sizeof(msgsize);
iov[1].iov_base = buffer_out;
iov[1].iov_len = size;
memset(&msg, 0, sizeof(msg));
msg.msg_name = &dest_addr;
msg.msg_namelen = sizeof(dest_addr);
msg.msg_iov = iov;
msg.msg_iovlen = 2;
printf("Sending message of %d+2 bytes\n", size);
ret = rt_dev_sendmsg(sock, &msg, 0);
if (ret == -EBADF)
return;
else if (ret != (int)(sizeof(msgsize) + size))
printf(" rt_dev_sendmsg() = %d!\n", ret);
#ifdef CONFIG_XENO_2_0x /* imported via rtnet_config.h */
rt_task_wait_period(); /* old signature */
#else /* Xenomai 2.1 and later */
rt_task_wait_period(NULL);
#endif /* CONFIG_XENO_2_0x */
}
}
void recv_msg(void *arg)
{
int ret;
struct msghdr msg;
struct iovec iov[2];
unsigned short msgsize = size;
struct sockaddr_in addr;
while (1) {
iov[0].iov_base = &msgsize;
iov[0].iov_len = sizeof(msgsize);
iov[1].iov_base = buffer_in;
iov[1].iov_len = size;
memset(&msg, 0, sizeof(msg));
msg.msg_name = &addr;
msg.msg_namelen = sizeof(addr);
msg.msg_iov = iov;
msg.msg_iovlen = 2;
ret = rt_dev_recvmsg(sock, &msg, 0);
if (ret <= 0) {
printf(" rt_dev_recvmsg() = %d\n", ret);
return;
} else {
unsigned long ip = ntohl(addr.sin_addr.s_addr);
printf("received packet from %lu.%lu.%lu.%lu, length: %zd+2, "
"encoded length: %d,\n flags: %X, content %s\n", ip >> 24,
(ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF,
ret-sizeof(msgsize), msgsize, msg.msg_flags,
(memcmp(buffer_in, buffer_out, ret-sizeof(msgsize)) == 0) ?
"ok" : "corrupted");
}
}
}
void catch_signal(int sig)
{
}
int main(int argc, char *argv[])
{
int ret;
unsigned int i;
struct sockaddr_in local_addr;
struct in_addr dest_ip;
int client_side=0;
while (1) {
switch (getopt(argc, argv, "d:s:")) {
case 'd':
dest_ip_s = optarg;
client_side=1;
break;
case 's':
size = atoi(optarg);
break;
case -1:
goto end_of_opt;
default:
printf("usage: %s [-d <dest_ip>] [-s <size>]\n", argv[0]);
return 0;
}
}
end_of_opt:
inet_aton(dest_ip_s, &dest_ip);
if (size > 65505)
size = 65505;
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
signal(SIGHUP, catch_signal);
mlockall(MCL_CURRENT|MCL_FUTURE);
printf("destination ip address %s=%08x\n", dest_ip_s, dest_ip.s_addr);
printf("size %d\n", size);
/* fill output buffer with test pattern */
for (i = 0; i < sizeof(buffer_out); i++)
buffer_out[i] = i & 0xFF;
/* create rt-socket */
sock = rt_dev_socket(AF_INET,SOCK_DGRAM,0);
if (sock < 0) {
printf(" rt_dev_socket() = %d!\n", sock);
return sock;
}
/* extend the socket pool */
ret = rt_dev_ioctl(sock, RTNET_RTIOC_EXTPOOL, &add_rtskbs);
if (ret != (int)add_rtskbs) {
printf(" rt_dev_ioctl(RT_IOC_SO_EXTPOOL) = %d\n", ret);
rt_dev_close(sock);
return -1;
}
/*CLIENT IS SENDING*/
if (client_side)
{
/* set destination address */
memset(&dest_addr, 0, sizeof(struct sockaddr_in));
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(PORT);
dest_addr.sin_addr = dest_ip;
ret = rt_task_create(&rt_xmit_task, "Sender", 0, 9, 0);
if (ret != 0) {
printf(" rt_task_create(xmit) = %d!\n", ret);
rt_dev_close(sock);
rt_task_delete(&rt_recv_task);
return ret;
}
rt_task_start(&rt_xmit_task, xmit_msg, NULL);
/*CLIENT*/
}
else
{
/*SERVER IS LISTENING*/
/* bind the rt-socket to a port */
memset(&local_addr, 0, sizeof(struct sockaddr_in));
local_addr.sin_family = AF_INET;
local_addr.sin_port = htons(PORT);
local_addr.sin_addr.s_addr = INADDR_ANY;
ret = rt_dev_bind(sock, (struct sockaddr *)&local_addr,
sizeof(struct sockaddr_in));
if (ret < 0) {
printf(" rt_dev_bind() = %d!\n", ret);
rt_dev_close(sock);
return ret;
}
/* You may have to start the system timer manually
* on older Xenomai versions (2.0.x):
* rt_timer_start(TM_ONESHOT); */
ret = rt_task_create(&rt_recv_task, "Receiver", 0, 10, 0);
if (ret != 0) {
printf(" rt_task_create(recv) = %d!\n", ret);
rt_dev_close(sock);
return ret;
}
rt_task_start(&rt_recv_task, recv_msg, NULL);
/*SERVER*/
}
pause();
/* In case you started it in this program, see comment above.
* rt_timer_stop(); */
/* Note: The following loop and the strict ordering "close before task
* termination" is no longer required since Xenomai 2.4. */
while (rt_dev_close(sock) == -EAGAIN) {
printf("frag-ip: Socket busy - waiting...\n");
sleep(1);
}
if (client_side)
rt_task_delete(&rt_xmit_task);
else
rt_task_delete(&rt_recv_task);
return 0;
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
RTnet-users mailing list
RTnet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rtnet-users