char frame[1];
};
-Dev::Dev(mac_type mac, size_t mtu, key_t key) throw (std::runtime_error):
+Dev::Dev(mac_type mac, size_t mtu, key_t key)
+ throw (std::runtime_error, std::logic_error):
mac(mac), mtu(mtu)
{
+ if (mtu > DEV_MAX_MTU)
+ throw std::logic_error("MTU más grande que DEV_MAX_MTU");
que_id = msgget(key, 0666); // Debe estar previamente creada
if (que_id == -1)
throw std::runtime_error("No se pudo crear la cola");
int res = msgsnd(que_id, f, mtu + sizeof(size_t), 0);
#ifdef DEBUG
std::cout << "Dev::transmit(msgtype/mac = " << f->mac << ", size = "
- << f->size << ", data = " << f->frame << ")\n";
+ << f->size << ")\n";
#endif
free(f);
if (res == -1)
free(f);
#ifdef DEBUG
std::cout << "Dev::receive(msgtype/mac = " << mac << ", size = "
- << s.size() << ", data = " << s << ")\n";
+ << s.size() << ")\n";
#endif
return s;
}
#include <stdexcept>
#define DEV_DEFAULT_KEY 0x1abcdef1
+#define DEV_MAX_MTU 1500
/// Dispositivo de red (capa de enlace)
struct Dev
int que_id;
/// Constructor
- Dev(mac_type mac, size_t mtu = 1500, key_t key = DEV_DEFAULT_KEY)
- throw (std::runtime_error);
+ Dev(mac_type mac, size_t mtu = DEV_MAX_MTU, key_t key = DEV_DEFAULT_KEY)
+ throw (std::runtime_error, std::logic_error);
/// Envía un frame
void transmit(const std::string& data, const mac_type& mac)
IPHeader iph(buf);
#ifdef DEBUG
log << "IPIn::recv: IPHeader: " << iph << "\n";
+ std::string tmp = buf.substr(iph.header_len());
+ log << "\tdata (" << tmp.size() << ") = " << tmp << "\n";
#endif
if (iph.version != 4)
{
std::string buf = forward_que.receive();
IPHeader iph(buf);
#ifdef DEBUG
- log << "IPOut::send: A forwardear => IPHeader: " << iph << "\n";
+ log << "IPOut::send: A forwardear\n";
#endif
send(iph, buf.substr(iph.header_len()));
}
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::string tmp = data.substr(i * max_payload, max_payload);
+ log << "\tdata (" << tmp.size() << ") = " << tmp << "\n";
#endif
r->iface->transmit(buf, r->gateway ? r->gateway : IPAddr(iph.dst));
}
Dev dev(addr, mtu, queue_id);
int que_id = msgget(queue_id+1, IPC_CREAT | 0666);
assert(que_id != -1);
- Dev fwque(addr, mtu, queue_id+1);
+ Dev fwque(addr, DEV_MAX_MTU, queue_id+1);
IPIn ipin(addr, dev, fwque, router, forward);
struct msqid_ds minfo;
for (msgctl(dev.que_id, IPC_STAT, &minfo); minfo.msg_qnum;
que_id = msgget(queue_id+1, IPC_CREAT | 0666); assert(que_id != -1);
std::ifstream ifs(fname.c_str()); assert(ifs);
Dev dev(addr, mtu, queue_id);
- Dev fwque(addr, mtu, queue_id+1);
+ Dev fwque(addr, DEV_MAX_MTU, queue_id+1);
RouteTable table(dev);
add_routes(table, ifs, dev);
IPOut ipout(addr, table, fwque);