Alex Bikfalvi
SimStream Documentation
LayerIpRoute.cpp
00001 #include "Headers.h" 00002 #include "LayerIpRoute.h" 00003 00004 CLayerIpRoute::CLayerIpRoute( 00005 CSimHandler* sim, 00006 CAddress address, 00007 CRoute* route 00008 ) : CLayer(sim) 00009 { 00010 this->address = address; 00011 this->route = route; 00012 00013 // Delegate and event 00014 this->delegateRecv = new Delegate2<CLayerIpRoute, void, __uint32, CPacketIp*>(this, &CLayerIpRoute::Recv); 00015 this->eventSend = new Event2<void, __uint32, CPacketIp*>(); 00016 } 00017 00018 CLayerIpRoute::~CLayerIpRoute() 00019 { 00020 delete this->delegateRecv; 00021 delete this->eventSend; 00022 } 00023 00024 void CLayerIpRoute::Recv(__uint32 entry, CPacketIp* packet) 00025 { 00026 // Forward all unicast packets that are not address to local address and have a TTL greater than zero 00027 if(packet->Ttl() == 0) return; 00028 if(packet->Dst().IsMulticast()) return; 00029 if(packet->Dst() == this->address) return; 00030 00031 #ifdef LOG_LAYER 00032 printf("\n\tT = %7.3lf IP_ROUTE RECV local=%u bytes=%u src=%u dst=%u", this->sim->Time(), this->address, packet->Size(), packet->Src(), packet->Dst()); 00033 #endif 00034 00035 __uint32 link = this->route->Forward(this->address, packet->Dst()); 00036 00037 (*this->eventSend)(link, type_cast<CPacketIp*>(packet->Copy())); 00038 }
Last updated: February 8, 2011