X-Git-Url: https://git.llucax.com/z.facultad/75.74/practicos.git/blobdiff_plain/7a01801db38786c0f1cab79b3867b8b529d5cb1c..659563a75d668130df84664e7e6b1220667cbc28:/practicas/pipi/src/test_ipin.cpp diff --git a/practicas/pipi/src/test_ipin.cpp b/practicas/pipi/src/test_ipin.cpp index 750ffd4..e170b38 100644 --- a/practicas/pipi/src/test_ipin.cpp +++ b/practicas/pipi/src/test_ipin.cpp @@ -1,25 +1,54 @@ #include "ipin.h" #include "ipaddr.h" +#include "dev.h" #include +#include +#include #include #include #include #include #include -int main() +// Uso: ./test_ipin ip mtu router forward proto queue_id + +int main(int argc, char* argv[]) { - Dev dev(4321); - IPIn ipin(IPAddr("10.10.10.1"), dev); + IPAddr addr("10.10.10.1"); + unsigned mtu = 25; + bool router = false; + bool forward = false; + unsigned proto = 0; + key_t queue_id = DEV_DEFAULT_KEY; + if (argc > 1) + addr = IPAddr(argv[1]); + if (argc > 2) + mtu = atoi(argv[2]); + if (argc > 3) + router = atoi(argv[3]); + if (argc > 4) + forward = atoi(argv[4]); + if (argc > 5) + proto = atoi(argv[5]); + if (argc > 6) + queue_id = atoi(argv[6]); + int que_id = msgget(queue_id, IPC_CREAT | 0666); + assert(que_id != -1); + Dev dev(addr, mtu, queue_id); + que_id = msgget(queue_id+1, IPC_CREAT | 0666); + assert(que_id != -1); + Dev fwque(addr, DEV_MAX_MTU, queue_id+1); + IPIn ipin(addr, dev, fwque, router, forward, std::cerr); struct msqid_ds minfo; for (msgctl(dev.que_id, IPC_STAT, &minfo); minfo.msg_qnum; msgctl(dev.que_id, IPC_STAT, &minfo)) { IPAddr src, dst; std::cout << "Quedan " << minfo.msg_qnum << " mensajes en la cola\n"; - std::string s = ipin.recv(0, src, dst); - std::cout << "Recibido '" << s << "' (len " << s.size() << ")\n"; + std::string s = ipin.recv(proto, src, dst); + std::cout << "Recibido '" << s << "' (len " << s.size() << ") de " + << src << " para " << dst << " (proto = " << proto << ")\n"; } return 0; }