Alex Bikfalvi
SimStream Documentation
LayerIp.cpp
00001 #include "Headers.h" 00002 #include "LayerIp.h" 00003 00004 CLayerIp::CLayerIp(CSimHandler* sim) : CLayer(sim) 00005 { 00006 this->delegateRecv = new Delegate2<CLayerIp, void, __uint32, CPacket*>(this, &CLayerIp::Recv); 00007 this->eventRecv = new Event2<void, __uint32, CPacketIp*>(); 00008 this->delegateSend = new Delegate2<CLayerIp, void, __uint32, CPacketIp*>(this, &CLayerIp::Send); 00009 this->eventSend = new Event2<void, __uint32, CPacket*>(); 00010 } 00011 00012 CLayerIp::~CLayerIp() 00013 { 00014 delete this->delegateRecv; 00015 delete this->eventRecv; 00016 00017 delete this->delegateSend; 00018 delete this->eventSend; 00019 } 00020 00021 void CLayerIp::Recv(__uint32 entry, CPacket* packet) 00022 { 00023 // Verify the packet is IP 00024 if(NULL == packet) return; 00025 if(packet->Type() != PACKET_TYPE_IP) return; 00026 00027 // Get the IP packet 00028 CPacketIp* ip = type_cast<CPacketIp*>(packet); 00029 00030 // Decrement the TTL 00031 ip->DecTtl(); 00032 00033 #ifdef LOG_LAYER 00034 printf("\n\tT = %7.3lf IP RECV entry=%u bytes=%u", this->sim->Time(), entry, packet->Size()); 00035 #endif 00036 00037 // Send the packet to the upper layers 00038 (*this->eventRecv)(entry, ip); 00039 } 00040 00041 void CLayerIp::Send(__uint32 entry, CPacketIp* packet) 00042 { 00043 if(NULL == packet) return; 00044 00045 #ifdef LOG_LAYER 00046 printf("\n\tT = %7.3lf IP SEND entry=%u bytes=%u", this->sim->Time(), entry, packet->Size()); 00047 #endif 00048 00049 // Send the packer to the lower layer 00050 (*this->eventSend)(entry, packet); 00051 }
Last updated: February 8, 2011