X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/918a7b42017533f6f18edc8735d6d82a5494f055..f48d95822c7810a45daf26854de7262ccc20a940:/practicas/pipi/src/ip.cpp diff --git a/practicas/pipi/src/ip.cpp b/practicas/pipi/src/ip.cpp index dd38b9b..0e9d0de 100644 --- a/practicas/pipi/src/ip.cpp +++ b/practicas/pipi/src/ip.cpp @@ -3,7 +3,8 @@ #include "ipin.h" #include "ipaddr.h" #include "routetable.h" -#include "dev.h" +#include "devtcp.h" +#include "devque.h" #include #include #include @@ -17,23 +18,21 @@ #include #include -// Uso: ./test_ipout ip [router forward routes_file queue_id proto] +// Uso: ./ip ip [router forward routes_file port proto] void send_loop(IPOut& ipout, unsigned proto); -void add_routes(RouteTable& rt, std::istream& is, Dev& dev); - int main(int argc, char* argv[]) { bool router = false; bool forward = false; - unsigned proto = 0; - key_t queue_id = DEV_DEFAULT_KEY; + uint8_t proto = 0; + 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"; + std::cerr << "Uso: " << argv[0] << " ip [router forward routes_file " + "port proto]\n"; return 1; } IPAddr addr(argv[1]); @@ -44,17 +43,14 @@ 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(DEV_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 - Dev dev(addr, queue_id); - Dev fwque(addr, DEV_DEFAULT_KEY-1); + DevTCP dev(addr, port); + DevQue fwque(addr, DEVQUE_DEFAULT_KEY-1); // Creo procesos pid_t pid_send = fork(); if (pid_send == -1) @@ -97,7 +93,8 @@ int main(int argc, char* argv[]) IPAddr src, dst; std::string s = ipin.recv(proto, src, dst); std::cout << "Recibido '" << s << "' (len " << s.size() << ") de " - << src << " para " << dst << " (proto = " << proto << ")\n"; + << src << " para " << dst << " (proto = " << unsigned(proto) + << ")\n"; } return 0; } @@ -119,21 +116,4 @@ void send_loop(IPOut& ipout, unsigned proto) } } -void add_routes(RouteTable& rt, std::istream& is, Dev& dev) -{ - std::string line; - while (std::getline(is, line)) - { - std::istringstream iss(line); - std::string net; - std::string gw; - unsigned mtu; - unsigned metric; - iss >> net >> gw >> mtu >> metric; - if (net == "0") net = "0.0.0.0"; - if (gw == "0") gw = "0.0.0.0"; - rt.add(net.c_str(), gw.c_str(), metric, mtu, dev); - } -} - // vim: set et sw=4 sts=4 :