Alex Bikfalvi
SimStream Documentation
LayerUdp.cpp
00001 #include "Headers.h" 00002 #include "LayerUdp.h" 00003 00004 CLayerUdp::CLayerUdp(CSimHandler* sim) : CLayer(sim) 00005 { 00006 this->delegateRecv = new Delegate3<CLayerUdp, void, __uint32, CPacketIp*, CPacket*>(this, &CLayerUdp::Recv); 00007 this->eventRecv = new Event4<void, __uint32, CPacketIp*, CPacketUdp*, CPacket*>(); 00008 this->delegateSend = new Delegate5<CLayerUdp, void, __uint16, __uint16, CAddress, __byte, CPacket*>(this, &CLayerUdp::Send); 00009 this->eventSend = new Event3<void, CAddress, __byte, CPacket*>(); 00010 } 00011 00012 CLayerUdp::~CLayerUdp() 00013 { 00014 delete this->delegateRecv; 00015 delete this->eventRecv; 00016 00017 delete this->delegateSend; 00018 delete this->eventSend; 00019 } 00020 00021 void CLayerUdp::Recv(__uint32 entry, CPacketIp* ip, CPacket* packet) 00022 { 00023 // Verify the packet is IP 00024 if(NULL == packet) return; 00025 if(packet->Type() != PACKET_TYPE_UDP) return; 00026 00027 // Send the packet to the upper layers 00028 (*this->eventRecv)(entry, ip, type_cast<CPacketUdp*>(packet), packet->Payload()); 00029 } 00030 00031 void CLayerUdp::Send(__uint16 src, __uint16 dst, CAddress address, __byte ttl, CPacket* payload) 00032 { 00033 // Create a new UDP packet 00034 CPacketUdp* packet = new CPacketUdp(src, dst, payload); 00035 00036 // Send the packet to the lower layer 00037 (*this->eventSend)(address, ttl, packet); 00038 }
Last updated: February 8, 2011