00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "simple-net-device.h"
00021 #include "simple-channel.h"
00022 #include "node.h"
00023 #include "ns3/packet.h"
00024
00025 namespace ns3 {
00026
00027 TypeId
00028 SimpleNetDevice::GetTypeId (void)
00029 {
00030 static TypeId tid = TypeId ("ns3::SimpleNetDevice")
00031 .SetParent<NetDevice> ()
00032 .AddConstructor<SimpleNetDevice> ()
00033 ;
00034 return tid;
00035 }
00036
00037 SimpleNetDevice::SimpleNetDevice ()
00038 : m_channel (0),
00039 m_node (0),
00040 m_mtu (0xffff),
00041 m_name (""),
00042 m_ifIndex (0)
00043 {}
00044
00045 void
00046 SimpleNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
00047 Mac48Address to, Mac48Address from)
00048 {
00049 NetDevice::PacketType packetType;
00050 if (to == m_address)
00051 {
00052 packetType = NetDevice::PACKET_HOST;
00053 }
00054 else if (to.IsBroadcast ())
00055 {
00056 packetType = NetDevice::PACKET_HOST;
00057 }
00058 else if (to.IsMulticast ())
00059 {
00060 packetType = NetDevice::PACKET_MULTICAST;
00061 }
00062 else
00063 {
00064 packetType = NetDevice::PACKET_OTHERHOST;
00065 }
00066 m_rxCallback (this, packet, protocol, from);
00067 if (!m_promiscCallback.IsNull ())
00068 {
00069 m_promiscCallback (this, packet, protocol, from, to, packetType);
00070 }
00071 }
00072
00073 void
00074 SimpleNetDevice::SetChannel (Ptr<SimpleChannel> channel)
00075 {
00076 m_channel = channel;
00077 m_channel->Add (this);
00078 }
00079
00080 void
00081 SimpleNetDevice::SetAddress (Mac48Address address)
00082 {
00083 m_address = address;
00084 }
00085
00086 void
00087 SimpleNetDevice::SetName(const std::string name)
00088 {
00089 m_name = name;
00090 }
00091 std::string
00092 SimpleNetDevice::GetName(void) const
00093 {
00094 return m_name;
00095 }
00096 void
00097 SimpleNetDevice::SetIfIndex(const uint32_t index)
00098 {
00099 m_ifIndex = index;
00100 }
00101 uint32_t
00102 SimpleNetDevice::GetIfIndex(void) const
00103 {
00104 return m_ifIndex;
00105 }
00106 Ptr<Channel>
00107 SimpleNetDevice::GetChannel (void) const
00108 {
00109 return m_channel;
00110 }
00111 Address
00112 SimpleNetDevice::GetAddress (void) const
00113 {
00114 return m_address;
00115 }
00116 bool
00117 SimpleNetDevice::SetMtu (const uint16_t mtu)
00118 {
00119 m_mtu = mtu;
00120 return true;
00121 }
00122 uint16_t
00123 SimpleNetDevice::GetMtu (void) const
00124 {
00125 return m_mtu;
00126 }
00127 bool
00128 SimpleNetDevice::IsLinkUp (void) const
00129 {
00130 return true;
00131 }
00132 void
00133 SimpleNetDevice::SetLinkChangeCallback (Callback<void> callback)
00134 {}
00135 bool
00136 SimpleNetDevice::IsBroadcast (void) const
00137 {
00138 return true;
00139 }
00140 Address
00141 SimpleNetDevice::GetBroadcast (void) const
00142 {
00143 return Mac48Address ("ff:ff:ff:ff:ff:ff");
00144 }
00145 bool
00146 SimpleNetDevice::IsMulticast (void) const
00147 {
00148 return false;
00149 }
00150 Address
00151 SimpleNetDevice::GetMulticast (Ipv4Address multicastGroup) const
00152 {
00153 return Mac48Address::GetMulticast (multicastGroup);
00154 }
00155
00156 Address SimpleNetDevice::GetMulticast (Ipv6Address addr) const
00157 {
00158 return Mac48Address::GetMulticast (addr);
00159 }
00160
00161 bool
00162 SimpleNetDevice::IsPointToPoint (void) const
00163 {
00164 return false;
00165 }
00166
00167 bool
00168 SimpleNetDevice::IsBridge (void) const
00169 {
00170 return false;
00171 }
00172
00173 bool
00174 SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
00175 {
00176 Mac48Address to = Mac48Address::ConvertFrom (dest);
00177 m_channel->Send (packet, protocolNumber, to, m_address, this);
00178 return true;
00179 }
00180 bool
00181 SimpleNetDevice::SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
00182 {
00183 Mac48Address to = Mac48Address::ConvertFrom (dest);
00184 Mac48Address from = Mac48Address::ConvertFrom (source);
00185 m_channel->Send (packet, protocolNumber, to, from, this);
00186 return true;
00187 }
00188
00189 Ptr<Node>
00190 SimpleNetDevice::GetNode (void) const
00191 {
00192 return m_node;
00193 }
00194 void
00195 SimpleNetDevice::SetNode (Ptr<Node> node)
00196 {
00197 m_node = node;
00198 }
00199 bool
00200 SimpleNetDevice::NeedsArp (void) const
00201 {
00202 return false;
00203 }
00204 void
00205 SimpleNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
00206 {
00207 m_rxCallback = cb;
00208 }
00209
00210 void
00211 SimpleNetDevice::DoDispose (void)
00212 {
00213 m_channel = 0;
00214 m_node = 0;
00215 NetDevice::DoDispose ();
00216 }
00217
00218
00219 void
00220 SimpleNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
00221 {
00222 m_promiscCallback = cb;
00223 }
00224
00225 bool
00226 SimpleNetDevice::SupportsSendFrom (void) const
00227 {
00228 return true;
00229 }
00230
00231 }