From: Leandro Lucarella Date: Mon, 3 Jul 2006 22:55:16 +0000 (+0000) Subject: Se emprolija un poco la info de debug. X-Git-Tag: svn_import~12 X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/commitdiff_plain/91fb3ca6b56328c626dabb35e2de9a5ae525b1b1?ds=sidebyside Se emprolija un poco la info de debug. --- diff --git a/practicas/pipi/src/Makefile b/practicas/pipi/src/Makefile index 983c3c1..6cd7baf 100644 --- a/practicas/pipi/src/Makefile +++ b/practicas/pipi/src/Makefile @@ -16,11 +16,18 @@ CFLAGS = -Wall -ansi -pedantic-errors # Para valgrind o debug CFLAGS += -ggdb -DDEBUG +debug = 1 # Para más verbose -CFLAGS += -DDEBUG2 +ifdef debug +#CFLAGS += -DDEBUG_IP +#CFLAGS += -DDEBUG_QUE +#CFLAGS += -DDEBUG_NAME +#CFLAGS += -DDEBUG_ROUTE +#CFLAGS += -DDEBUG_TRACE CFLAGS += -DDEBUG_RESOLV -CFLAGS += -DDEBUG_TRACE +#CFLAGS += -DDEBUG_LIBTCP +endif # Opciones para el compilador C++. CXXFLAGS = $(CFLAGS) -fno-inline @@ -34,8 +41,7 @@ CC=g++ # Programas targets=ip dns res tests=test_send test_recv test_ipaddr test_ipin test_ipout test_devtcp \ - test_poll test_resolvproto test_nameserver_file \ - test_nameserver_resolvnext + test_poll test_resolvproto # Fuentes fuentes ?= $(wildcard *.cpp) $(wildcard *.c) @@ -69,12 +75,6 @@ test_poll: test_poll.o libtcp.o test_resolvproto: test_resolvproto.o resolvproto.o ipaddr.o -test_nameserver_file: test_nameserver_file.o nameserver.o $(dns_objs) $(ip_objs) - -#FIXME no va libtcp.o, debe ir sobre mi implementación de ip. -test_nameserver_resolvnext: test_nameserver_resolvnext.o nameserver.o \ - $(dns_objs) $(ip_objs) - ip: ip.o $(ip_objs) dns: dns.o nameserver.o $(ip_objs) $(dns_objs) diff --git a/practicas/pipi/src/devque.cpp b/practicas/pipi/src/devque.cpp index 593f663..1e812ff 100644 --- a/practicas/pipi/src/devque.cpp +++ b/practicas/pipi/src/devque.cpp @@ -40,7 +40,7 @@ void DevQue::transmit(const std::string& data, const mac_type& mac) f->size = data.size(); memcpy(f->frame, data.data(), data.size()); int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevQue[" << que_id << "]::transmit(msgtype/mac = " << f->mac << ", size = " << f->size << ")\n"; #endif @@ -75,7 +75,7 @@ std::string DevQue::receive(mac_type& mac) throw (std::runtime_error) if (mac == 0) mac = f->mac; free(f); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevQue[" << que_id << "]::receive(msgtype/mac = " << mac << ", size = " << s.size() << ")\n"; #endif diff --git a/practicas/pipi/src/devtcp.cpp b/practicas/pipi/src/devtcp.cpp index e8828f4..6bc709c 100644 --- a/practicas/pipi/src/devtcp.cpp +++ b/practicas/pipi/src/devtcp.cpp @@ -26,12 +26,15 @@ DevTCP::DevTCP(mac_type mac, uint16_t port, size_t mtu) void DevTCP::transmit(const std::string& data, const mac_type& mac) throw (std::runtime_error, std::logic_error) { +#ifdef DEBUG_TRACE + std::cout << "DevTCP[" << port << "]::transmit()\n"; +#endif if (data.size() > mtu) throw std::logic_error("Tamaño de datos mayor al MTU"); if (tx_pool.find(mac) == tx_pool.end()) // No existe la conexión { std::string addr = IPAddr(mac); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::transmit: conectando a " << addr << ":" << port << "\n"; #endif tx_pool[mac] = libtcp_open_activo(addr.c_str(), port); @@ -43,7 +46,7 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) throw std::runtime_error("Error al enviar por el socket"); if ((unsigned)libtcp_send(tx_pool[mac], data.data(), data.size()) != data.size()) throw std::runtime_error("Error al enviar por el socket"); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::transmit(mac = " << mac << ", size = " << data.size() << ")\n"; #endif @@ -51,10 +54,13 @@ void DevTCP::transmit(const std::string& data, const mac_type& mac) std::string DevTCP::receive() throw (std::runtime_error) { +#ifdef DEBUG_TRACE + std::cout << "DevTCP[" << port << "]::receive()\n"; +#endif // Nos fijamos en todos los file descriptors si hay algo para nosotros. while (true) { - int res = poll(pfds, pfds_size, 5000); + int res = poll(pfds, pfds_size, -1); if (res == -1) throw std::runtime_error("Error al hacer poll"); if (!res) @@ -89,7 +95,7 @@ std::string DevTCP::receive() throw (std::runtime_error) continue; std::string ret(buf, size); free(buf); -#ifdef DEBUG2 +#ifdef DEBUG_QUE std::cout << "DevTCP::receive(msgtype/mac = " << mac << ", size = " << ret.size() << ")\n"; #endif diff --git a/practicas/pipi/src/ipin.cpp b/practicas/pipi/src/ipin.cpp index 1ff0560..7cb5abc 100644 --- a/practicas/pipi/src/ipin.cpp +++ b/practicas/pipi/src/ipin.cpp @@ -41,7 +41,7 @@ std::string IPIn::recv(uint8_t& proto, IPAddr& src, IPAddr& dst) continue; } IPHeader iph(buf); -#ifdef DEBUG +#ifdef DEBUG_IP std::cout << "IPIn::recv (" << ip << "): IPHeader: " << iph << "\n"; std::string tmp = buf.substr(iph.header_len()); std::cout << "\tdata (" << tmp.size() << ") = " << tmp << "\n"; @@ -99,7 +99,7 @@ std::string IPIn::recv(uint8_t& proto, IPAddr& src, IPAddr& dst) //TODO chequear que los fragmentos estén todos data += i->second; } -#ifdef DEBUG +#ifdef DEBUG_IP std::cout << "IPIn::recv (" << ip << "): Paquete completo: data = '" << data << "'\n"; #endif diff --git a/practicas/pipi/src/ipout.cpp b/practicas/pipi/src/ipout.cpp index 84a3733..dea18de 100644 --- a/practicas/pipi/src/ipout.cpp +++ b/practicas/pipi/src/ipout.cpp @@ -78,7 +78,7 @@ bool IPOut::send(IPHeader iph, std::string data) throw (std::runtime_error) iph2.do_checksum(); std::string buf((char*) &iph2, sizeof(IPHeader)); buf += data.substr(i * max_payload, max_payload); -#ifdef DEBUG +#ifdef DEBUG_IP std::cout << "IPOut::send (" << ip << "): Fragmento " << i << " => IPHeader: " << iph2 << "\n"; std::string tmp = data.substr(i * max_payload, max_payload); @@ -97,7 +97,7 @@ void IPOut::forward_loop() { std::string buf = forward_que.receive(); IPHeader iph(buf); -#ifdef DEBUG +#ifdef DEBUG_IP std::cout << "IPOut::forward_loop (" << ip << "): A forwardear (id " << iph.id << ", offset " << iph.offset << ")\n"; #endif diff --git a/practicas/pipi/src/libtcp.c b/practicas/pipi/src/libtcp.c index 68a6d2c..3184ff2 100644 --- a/practicas/pipi/src/libtcp.c +++ b/practicas/pipi/src/libtcp.c @@ -95,7 +95,7 @@ int libtcp_open_pasivo (int port) return -1; } -#ifdef DEBUG2 +#ifdef DEBUG_LIBTCP sprintf (mostrar, "LibTcp::ServerPasivo: socket creado %d\n", sockfd); write (fileno(stdout), mostrar, strlen (mostrar)); #endif @@ -105,7 +105,7 @@ int libtcp_open_pasivo (int port) return -1; } -#ifdef DEBUG2 +#ifdef DEBUG_LIBTCP sprintf (mostrar, "LibTcp::Server: se hizo el bind\n"); write(fileno(stdout), mostrar, strlen(mostrar)); #endif @@ -113,7 +113,7 @@ int libtcp_open_pasivo (int port) /* Definir la cola de espera = hasta 5 clientes */ listen(sockfd, 5); -#ifdef DEBUG2 +#ifdef DEBUG_LIBTCP sprintf (mostrar, "LibTcp::Server: se hizo el listen con el socket %d\n", sockfd); write(fileno(stdout), mostrar, strlen(mostrar)); #endif diff --git a/practicas/pipi/src/nameserver.cpp b/practicas/pipi/src/nameserver.cpp index 4c64604..f04b4ab 100644 --- a/practicas/pipi/src/nameserver.cpp +++ b/practicas/pipi/src/nameserver.cpp @@ -110,7 +110,7 @@ NameServer::NameServer(std::istream& is, IPIn& ipin, IPOut& ipout, #endif } -#ifdef DEBUG2 +#ifdef DEBUG_RESOLV std::cout << "NameServer: req_que_id = " << req_que.que_id << ", res_que_id = " << res_que.que_id << ", snd_que_id = " << snd_que.que_id << "\n"; diff --git a/practicas/pipi/src/routetable.cpp b/practicas/pipi/src/routetable.cpp index 43e3377..f8e6cbd 100644 --- a/practicas/pipi/src/routetable.cpp +++ b/practicas/pipi/src/routetable.cpp @@ -13,9 +13,9 @@ void RouteTable::add(const IPAddr& net, const IPAddr& gw, unsigned mtu, unsigned metric, Dev& iface) { table[net] = Route(gw, metric, mtu, iface); -#ifdef DEBUG - //std::cout << "Se agregó tabla para " << net << ": gw = " << gw - // << ", metric = " << metric << "\n"; +#ifdef DEBUG_ROUTE + std::cout << "Se agregó tabla para " << net << ": gw = " << gw + << ", metric = " << metric << "\n"; #endif }