# 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)
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
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
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
#include "ipin.h"
#include "ipaddr.h"
#include "routetable.h"
+#include "devtcp.h"
#include "devque.h"
#include <iostream>
#include <fstream>
#include <sys/msg.h>
#include <signal.h>
-// 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);
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]);
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();
--- /dev/null
+
+#include "libtcp.h"
+#include <assert.h>
+#include <sys/poll.h>
+
+#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);
+ }
+ }
+ }
+}
+