From: Leandro Lucarella Date: Thu, 15 Jun 2006 08:00:18 +0000 (+0000) Subject: Se implementa IP con la nueva capa física sobre TCP. Se agrega un ejemplo de X-Git-Tag: svn_import~40 X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/commitdiff_plain/810ed30ec72d5339d6efa8a88702b74d95693503 Se implementa IP con la nueva capa física sobre TCP. Se agrega un ejemplo de poll y rutas de pruebas para TCP. --- diff --git a/practicas/pipi/rutas_ejemplo/route_10.10.10.141_tcp.txt b/practicas/pipi/rutas_ejemplo/route_10.10.10.141_tcp.txt new file mode 100644 index 0000000..98cf91e --- /dev/null +++ b/practicas/pipi/rutas_ejemplo/route_10.10.10.141_tcp.txt @@ -0,0 +1,2 @@ +10.10.10.2 0.0.0.0 25 0 +10.10.10.141 0.0.0.0 25 0 diff --git a/practicas/pipi/rutas_ejemplo/route_10.10.10.2_tcp.txt b/practicas/pipi/rutas_ejemplo/route_10.10.10.2_tcp.txt new file mode 100644 index 0000000..98cf91e --- /dev/null +++ b/practicas/pipi/rutas_ejemplo/route_10.10.10.2_tcp.txt @@ -0,0 +1,2 @@ +10.10.10.2 0.0.0.0 25 0 +10.10.10.141 0.0.0.0 25 0 diff --git a/practicas/pipi/src/Makefile b/practicas/pipi/src/Makefile index 80e3177..f708d0c 100644 --- a/practicas/pipi/src/Makefile +++ b/practicas/pipi/src/Makefile @@ -31,7 +31,7 @@ CC=g++ # Programas targets=ip -tests=test_send test_recv test_ipaddr test_ipin test_ipout test_devtcp +tests=test_send test_recv test_ipaddr test_ipin test_ipout test_devtcp test_poll # Fuentes fuentes ?= $(wildcard *.cpp) $(wildcard *.c) @@ -58,7 +58,9 @@ test_ipout: test_ipout.o ipout.o ipaddr.o ipheader.o devque.o routetable.o test_devtcp: test_devtcp.o devtcp.o libtcp.o ipaddr.o -ip: ip.o ipout.o ipin.o ipaddr.o ipheader.o devque.o routetable.o +test_poll: test_poll.o libtcp.o + +ip: ip.o ipout.o ipin.o ipaddr.o ipheader.o devque.o devtcp.o routetable.o libtcp.o depend: @makedepend $(fuentes) > /dev/null 2>&1 @@ -123,7 +125,8 @@ devtcp.o: /usr/include/sys/msg.h /usr/include/bits/msq.h ip.o: ipout.h ipaddr.h ipheader.h /usr/include/stdint.h ip.o: /usr/include/features.h /usr/include/sys/cdefs.h ip.o: /usr/include/gnu/stubs.h /usr/include/bits/wchar.h -ip.o: /usr/include/bits/wordsize.h routetable.h dev.h ipin.h devque.h +ip.o: /usr/include/bits/wordsize.h routetable.h dev.h ipin.h devtcp.h +ip.o: /usr/include/sys/poll.h /usr/include/bits/poll.h devque.h ip.o: /usr/include/unistd.h /usr/include/bits/posix_opt.h ip.o: /usr/include/bits/types.h /usr/include/bits/typesizes.h ip.o: /usr/include/bits/confname.h /usr/include/getopt.h /usr/include/fcntl.h @@ -290,3 +293,39 @@ libtcp.o: /usr/include/netinet/in.h /usr/include/stdint.h libtcp.o: /usr/include/bits/in.h /usr/include/bits/byteswap.h libtcp.o: /usr/include/arpa/inet.h /usr/include/netdb.h libtcp.o: /usr/include/rpc/netdb.h /usr/include/bits/netdb.h +test_poll.o: libtcp.h /usr/include/stdio.h /usr/include/features.h +test_poll.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h +test_poll.o: /usr/include/bits/types.h /usr/include/bits/wordsize.h +test_poll.o: /usr/include/bits/typesizes.h /usr/include/libio.h +test_poll.o: /usr/include/_G_config.h /usr/include/wchar.h +test_poll.o: /usr/include/bits/wchar.h /usr/include/gconv.h +test_poll.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h +test_poll.o: /usr/include/stdlib.h /usr/include/sys/types.h +test_poll.o: /usr/include/time.h /usr/include/endian.h +test_poll.o: /usr/include/bits/endian.h /usr/include/sys/select.h +test_poll.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +test_poll.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +test_poll.o: /usr/include/bits/pthreadtypes.h /usr/include/bits/sched.h +test_poll.o: /usr/include/alloca.h /usr/include/unistd.h +test_poll.o: /usr/include/bits/posix_opt.h /usr/include/bits/confname.h +test_poll.o: /usr/include/getopt.h /usr/include/signal.h +test_poll.o: /usr/include/bits/signum.h /usr/include/bits/siginfo.h +test_poll.o: /usr/include/bits/sigaction.h /usr/include/bits/sigcontext.h +test_poll.o: /usr/include/asm/sigcontext.h /usr/include/asm-i486/sigcontext.h +test_poll.o: /usr/include/linux/compiler.h /usr/include/bits/sigstack.h +test_poll.o: /usr/include/bits/sigthread.h /usr/include/sys/wait.h +test_poll.o: /usr/include/sys/resource.h /usr/include/bits/resource.h +test_poll.o: /usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h +test_poll.o: /usr/include/string.h /usr/include/sys/socket.h +test_poll.o: /usr/include/sys/uio.h /usr/include/bits/uio.h +test_poll.o: /usr/include/bits/socket.h /usr/include/limits.h +test_poll.o: /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h +test_poll.o: /usr/include/linux/limits.h /usr/include/bits/posix2_lim.h +test_poll.o: /usr/include/bits/sockaddr.h /usr/include/asm/socket.h +test_poll.o: /usr/include/asm-i486/socket.h /usr/include/asm/sockios.h +test_poll.o: /usr/include/asm-i486/sockios.h /usr/include/netinet/in.h +test_poll.o: /usr/include/stdint.h /usr/include/bits/in.h +test_poll.o: /usr/include/bits/byteswap.h /usr/include/arpa/inet.h +test_poll.o: /usr/include/netdb.h /usr/include/rpc/netdb.h +test_poll.o: /usr/include/bits/netdb.h /usr/include/assert.h +test_poll.o: /usr/include/sys/poll.h /usr/include/bits/poll.h diff --git a/practicas/pipi/src/ip.cpp b/practicas/pipi/src/ip.cpp index db99e1a..f3fed6e 100644 --- a/practicas/pipi/src/ip.cpp +++ b/practicas/pipi/src/ip.cpp @@ -3,6 +3,7 @@ #include "ipin.h" #include "ipaddr.h" #include "routetable.h" +#include "devtcp.h" #include "devque.h" #include #include @@ -17,7 +18,7 @@ #include #include -// Uso: ./test_ipout ip [router forward routes_file queue_id proto] +// Uso: ./test_ipout ip [router forward routes_file port proto] void send_loop(IPOut& ipout, unsigned proto); @@ -28,12 +29,12 @@ int main(int argc, char* argv[]) bool router = false; bool forward = false; unsigned proto = 0; - key_t queue_id = DEVQUE_DEFAULT_KEY; + uint16_t port = DEVTCP_DEFAULT_PORT; std::string fname = "route.txt"; if (argc < 2) { std::cerr << "Uso: ./test_ipout ip [router forward routes_file " - "queue_id proto]\n"; + "port proto]\n"; return 1; } IPAddr addr(argv[1]); @@ -44,16 +45,15 @@ int main(int argc, char* argv[]) if (argc > 4) fname = argv[4]; if (argc > 5) - queue_id = atoi(argv[5]); + port = atoi(argv[5]); if (argc > 6) proto = atoi(argv[6]); - // Creo colas - int que_id = msgget(queue_id, IPC_CREAT | 0666); assert(que_id != -1); - que_id = msgget(DEVQUE_DEFAULT_KEY-1, IPC_CREAT | 0666); assert(que_id != -1); + // Creo cola para comunicar el IPIn con IPOut + int que_id = msgget(DEVQUE_DEFAULT_KEY-1, IPC_CREAT | 0666); assert(que_id != -1); // Abro archivo con rutas std::ifstream ifs(fname.c_str()); assert(ifs); // Creo medio físico y cola para forwarding - DevQue dev(addr, queue_id); + DevTCP dev(addr, port); DevQue fwque(addr, DEVQUE_DEFAULT_KEY-1); // Creo procesos pid_t pid_send = fork(); diff --git a/practicas/pipi/src/test_poll.c b/practicas/pipi/src/test_poll.c new file mode 100644 index 0000000..31fa213 --- /dev/null +++ b/practicas/pipi/src/test_poll.c @@ -0,0 +1,52 @@ + +#include "libtcp.h" +#include +#include + +#define MAX 10 +#define PORT 5000 + +#define ISSET(var, flag) ((var & flag) == flag) + +int main() +{ + int ssock = libtcp_open_pasivo(PORT); assert(ssock != -1); + struct pollfd pfds[MAX]; + pfds[0].fd = ssock; + pfds[0].events = POLLIN | POLLPRI; + int pfds_size = 1; + while (1) + { + int res; + res = poll(pfds, pfds_size, 5000); assert(res != -1); + if (!res) + continue; + if (ISSET(pfds[0].revents, POLLIN) + || ISSET(pfds[0].revents, POLLPRI)) + { + if (pfds_size == MAX) + { + printf("Demasiadas conexiones, ignorando...\n"); + continue; + } + pfds[pfds_size].fd = accept(ssock, NULL, NULL); + assert(pfds[pfds_size].fd != -1); + printf("Nueva conexión...\n"); + pfds[pfds_size].events = POLLIN | POLLPRI; + ++pfds_size; + } + for (int i = 1; i < pfds_size; ++i) + { + if (ISSET(pfds[i].revents, POLLIN) + || ISSET(pfds[i].revents, POLLPRI)) + { + char buf[10]; + int recibidos = libtcp_receive_bin(pfds[i].fd, buf, 10); + //assert(recibidos == 10); + if (recibidos) + printf("recibido %s\n", buf); + } + } + } +} +