00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #include "simple-channel.h" 00021 #include "simple-net-device.h" 00022 #include "ns3/simulator.h" 00023 #include "ns3/packet.h" 00024 00025 namespace ns3 { 00026 00027 TypeId 00028 SimpleChannel::GetTypeId (void) 00029 { 00030 static TypeId tid = TypeId ("ns3::SimpleChannel") 00031 .SetParent<Channel> () 00032 .AddConstructor<SimpleChannel> () 00033 ; 00034 return tid; 00035 } 00036 00037 SimpleChannel::SimpleChannel () 00038 {} 00039 00040 void 00041 SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol, 00042 Mac48Address to, Mac48Address from, 00043 Ptr<SimpleNetDevice> sender) 00044 { 00045 for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin (); i != m_devices.end (); ++i) 00046 { 00047 Ptr<SimpleNetDevice> tmp = *i; 00048 if (tmp == sender) 00049 { 00050 continue; 00051 } 00052 Simulator::ScheduleNow (&SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from); 00053 } 00054 } 00055 00056 void 00057 SimpleChannel::Add (Ptr<SimpleNetDevice> device) 00058 { 00059 m_devices.push_back (device); 00060 } 00061 00062 uint32_t 00063 SimpleChannel::GetNDevices (void) const 00064 { 00065 return m_devices.size (); 00066 } 00067 Ptr<NetDevice> 00068 SimpleChannel::GetDevice (uint32_t i) const 00069 { 00070 return m_devices[i]; 00071 } 00072 00073 } // namespace ns3