X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/093ef819f410add240cf97b72f9e7dcab5abd16c..659563a75d668130df84664e7e6b1220667cbc28:/practicas/pipi/src/ipout.cpp?ds=sidebyside diff --git a/practicas/pipi/src/ipout.cpp b/practicas/pipi/src/ipout.cpp index cf5c28c..9c6d705 100644 --- a/practicas/pipi/src/ipout.cpp +++ b/practicas/pipi/src/ipout.cpp @@ -7,6 +7,9 @@ #include #include #include +#ifdef DEBUG +#include +#endif /// Constructor IPOut::IPOut(const IPAddr& ip, RouteTable& rtable, Dev& forward_que, std::ostream& log): @@ -16,12 +19,14 @@ IPOut::IPOut(const IPAddr& ip, RouteTable& rtable, Dev& forward_que, std::ostrea void IPOut::drop(const std::string& msg, const std::string& buf) { - log << "IPOut::drop: " << msg << "\n\tBuffer: " << buf << "\n"; + log << "IPOut::drop (" << ip << "): " << msg << "\n\tBuffer: " << buf + << "\n"; } void IPOut::drop(const std::string& msg, const IPHeader& iph) { - log << "IPOut::drop: " << msg << "\n\tIPHeader: " << iph << "\n"; + log << "IPOut::drop (" << ip << "): " << msg << "\n\tIPHeader: " << iph + << "\n"; } /// Envía un paquete IP @@ -35,7 +40,7 @@ bool IPOut::send(const std::string& data, uint8_t proto, IPAddr dst, IPAddr src, std::string buf = forward_que.receive(); IPHeader iph(buf); #ifdef DEBUG - log << "IPOut::send: A forwardear => IPHeader: " << iph << "\n"; + std::cout << "IPOut::send (" << ip << "): A forwardear\n"; #endif send(iph, buf.substr(iph.header_len())); } @@ -57,12 +62,14 @@ bool IPOut::send(IPHeader iph, std::string data) throw (std::runtime_error) RouteTable::Route* r = rtable.get(iph.dst); if (!r) { - drop("No existe una ruta para el destino", iph); + // ICMP + drop("No existe una ruta para el destino -> ICMP", iph); return false; } // No quieren fragmentar if (iph.df && (IPHeader::header_len() + data.size() > r->iface->mtu)) { + // Silencioso drop("Tamaño de paquete más grande que MTU y DF=1", iph); return false; } @@ -82,8 +89,10 @@ bool IPOut::send(IPHeader iph, std::string data) throw (std::runtime_error) std::string buf((char*) &iph2, sizeof(IPHeader)); buf += data.substr(i * max_payload, max_payload); #ifdef DEBUG - log << "IPOut::send: Fragmento 0 => IPHeader: " << iph2 << "\n"; - log << "\tbuf (" << buf.size() << ") = " << buf << "\n"; + std::cout << "IPOut::send (" << ip << "): Fragmento " << i + << " => IPHeader: " << iph2 << "\n"; + std::string tmp = data.substr(i * max_payload, max_payload); + std::cout << "\tdata (" << tmp.size() << ") = " << tmp << "\n"; #endif r->iface->transmit(buf, r->gateway ? r->gateway : IPAddr(iph.dst)); }