Alex Bikfalvi
SimStream Documentation
LayerIpLocal.cpp
00001 #include "Headers.h" 00002 #include "LayerIpLocal.h" 00003 00004 CLayerIpLocal::CLayerIpLocal( 00005 CSimHandler* sim, 00006 CAddress address, 00007 CRoute* route 00008 ) : CLayer(sim) 00009 { 00010 this->address = address; 00011 this->route = route; 00012 00013 // Delegates 00014 this->delegateRecv = new Delegate2<CLayerIpLocal, void, __uint32, CPacketIp*>(this, &CLayerIpLocal::Recv); 00015 this->delegateRecvMcast = new Delegate2<CLayerIpLocal, void, __uint32, CPacketIp*>(this, &CLayerIpLocal::RecvMcast); 00016 this->delegateSend = new Delegate3<CLayerIpLocal, void, CAddress, __byte, CPacket*>(this, &CLayerIpLocal::Send); 00017 00018 // Events 00019 this->eventRecv = new Event3<void, __uint32, CPacketIp*, CPacket*>(); 00020 this->eventSend = new Event2<void, __uint32, CPacketIp*>(); 00021 this->eventSendMcast = new Event1<void, CPacketIp*>(); 00022 } 00023 00024 CLayerIpLocal::~CLayerIpLocal() 00025 { 00026 // Delegates 00027 delete this->delegateRecv; 00028 delete this->delegateRecvMcast; 00029 delete this->delegateSend; 00030 00031 // Events 00032 delete this->eventRecv; 00033 delete this->eventSend; 00034 delete this->eventSendMcast; 00035 } 00036 00037 void CLayerIpLocal::Recv(__uint32 entry, CPacketIp* packet) 00038 { 00039 // Verify the packet destination is the current address 00040 if(NULL == packet) return; 00041 if(packet->Dst() != this->address) return; 00042 00043 #ifdef LOG_LAYER 00044 printf("\n\tT = %7.3lf IP_LOCAL RECV local=%u entry=%u bytes=%u src=%u dst=%u", this->sim->Time(), this->address, entry, packet->Size(), packet->Src(), packet->Dst()); 00045 #endif 00046 00047 // Send the packet payload to the upper layers 00048 (*this->eventRecv)(entry, packet, packet->Payload()); 00049 } 00050 00051 void CLayerIpLocal::RecvMcast(__uint32 entry, CPacketIp* packet) 00052 { 00053 // Verify the packet destination is a multicast address 00054 if(NULL == packet) return; 00055 if(!packet->Dst().IsMulticast()) return; 00056 00057 #ifdef LOG_LAYER 00058 printf("\n\tT = %7.3lf IP_LOCAL RECV_MCAST local=%u entry=%u bytes=%u src=%u dst=%u", this->sim->Time(), this->address, entry, packet->Size(), packet->Src(), packet->Dst()); 00059 #endif 00060 00061 // Send the packet payload to the upper layers 00062 (*this->eventRecv)(entry, packet, packet->Payload()); 00063 } 00064 00065 void CLayerIpLocal::Send(CAddress dst, __byte ttl, CPacket *payload) 00066 { 00067 // Create a new IP packet 00068 CPacketIp* packet = new CPacketIp(this->address, dst, ttl, payload); 00069 00070 #ifdef LOG_LAYER 00071 printf("\n\tT = %7.3lf IP_LOCAL SEND local=%u bytes=%u src=%u dst=%u", this->sim->Time(), this->address, packet->Size(), packet->Src(), packet->Dst()); 00072 #endif 00073 00074 // If destination is multicast 00075 if(dst.IsMulticast()) 00076 { 00077 // Send the packet to the lower multicast layer 00078 (*this->eventSendMcast)(packet); 00079 } 00080 // If destination is unicast 00081 else 00082 { 00083 // Calculate the link to send the packet 00084 __uint32 link = this->route->Forward(this->address, dst); 00085 00086 // Send the packet to the lower layer 00087 (*this->eventSend)(link, packet); 00088 } 00089 }
Last updated: February 8, 2011