# 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
# 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)
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)
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
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
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);
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
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)
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
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";
//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
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);
{
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
return -1;
}
-#ifdef DEBUG2
+#ifdef DEBUG_LIBTCP
sprintf (mostrar, "LibTcp::ServerPasivo: socket creado %d\n", sockfd);
write (fileno(stdout), mostrar, strlen (mostrar));
#endif
return -1;
}
-#ifdef DEBUG2
+#ifdef DEBUG_LIBTCP
sprintf (mostrar, "LibTcp::Server: se hizo el bind\n");
write(fileno(stdout), mostrar, strlen(mostrar));
#endif
/* 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
#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";
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
}