src/node/simple-net-device.cc
author vincent@clarinet.u-strasbg.fr
Fri Nov 07 11:36:15 2008 -0800 (2008-11-07)
changeset 3852 9cf7ad0cac85
parent 3841 1e7abf5fca79
child 3936 e525995ce5dc
permissions -rw-r--r--
Initial IPv6 capability
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2008 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #include "simple-net-device.h"
    21 #include "simple-channel.h"
    22 #include "node.h"
    23 #include "ns3/packet.h"
    24 
    25 namespace ns3 {
    26 
    27 TypeId 
    28 SimpleNetDevice::GetTypeId (void)
    29 {
    30   static TypeId tid = TypeId ("ns3::SimpleNetDevice")
    31     .SetParent<NetDevice> ()
    32     .AddConstructor<SimpleNetDevice> ()
    33     ;
    34   return tid;
    35 }
    36 
    37 SimpleNetDevice::SimpleNetDevice ()
    38   : m_channel (0),
    39     m_node (0),
    40     m_mtu (0xffff),
    41     m_name (""),
    42     m_ifIndex (0)
    43 {}
    44 
    45 void 
    46 SimpleNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol, 
    47 			  Mac48Address to, Mac48Address from)
    48 {
    49   NetDevice::PacketType packetType;
    50   if (to == m_address)
    51     {
    52       packetType = NetDevice::PACKET_HOST;
    53     }
    54   else if (to.IsBroadcast ())
    55     {
    56       packetType = NetDevice::PACKET_HOST;
    57     }
    58   else if (to.IsMulticast ())
    59     {
    60       packetType = NetDevice::PACKET_MULTICAST;
    61     }
    62   else 
    63     {
    64       packetType = NetDevice::PACKET_OTHERHOST;
    65     }
    66   m_rxCallback (this, packet, protocol, from);
    67   if (!m_promiscCallback.IsNull ())
    68     {
    69       m_promiscCallback (this, packet, protocol, from, to, packetType);
    70     }
    71 }
    72 
    73 void 
    74 SimpleNetDevice::SetChannel (Ptr<SimpleChannel> channel)
    75 {
    76   m_channel = channel;
    77   m_channel->Add (this);
    78 }
    79 
    80 void 
    81 SimpleNetDevice::SetAddress (Mac48Address address)
    82 {
    83   m_address = address;
    84 }
    85 
    86 void 
    87 SimpleNetDevice::SetName(const std::string name)
    88 {
    89   m_name = name;
    90 }
    91 std::string 
    92 SimpleNetDevice::GetName(void) const
    93 {
    94   return m_name;
    95 }
    96 void 
    97 SimpleNetDevice::SetIfIndex(const uint32_t index)
    98 {
    99   m_ifIndex = index;
   100 }
   101 uint32_t 
   102 SimpleNetDevice::GetIfIndex(void) const
   103 {
   104   return m_ifIndex;
   105 }
   106 Ptr<Channel> 
   107 SimpleNetDevice::GetChannel (void) const
   108 {
   109   return m_channel;
   110 }
   111 Address 
   112 SimpleNetDevice::GetAddress (void) const
   113 {
   114   return m_address;
   115 }
   116 bool 
   117 SimpleNetDevice::SetMtu (const uint16_t mtu)
   118 {
   119   m_mtu = mtu;
   120   return true;
   121 }
   122 uint16_t 
   123 SimpleNetDevice::GetMtu (void) const
   124 {
   125   return m_mtu;
   126 }
   127 bool 
   128 SimpleNetDevice::IsLinkUp (void) const
   129 {
   130   return true;
   131 }
   132 void 
   133 SimpleNetDevice::SetLinkChangeCallback (Callback<void> callback)
   134 {}
   135 bool 
   136 SimpleNetDevice::IsBroadcast (void) const
   137 {
   138   return true;
   139 }
   140 Address
   141 SimpleNetDevice::GetBroadcast (void) const
   142 {
   143   return Mac48Address ("ff:ff:ff:ff:ff:ff");
   144 }
   145 bool 
   146 SimpleNetDevice::IsMulticast (void) const
   147 {
   148   return false;
   149 }
   150 Address 
   151 SimpleNetDevice::GetMulticast (Ipv4Address multicastGroup) const
   152 {
   153   return Mac48Address::GetMulticast (multicastGroup);
   154 }
   155 
   156 Address SimpleNetDevice::GetMulticast (Ipv6Address addr) const
   157 {
   158 	return Mac48Address::GetMulticast (addr);
   159 }
   160 
   161 bool 
   162 SimpleNetDevice::IsPointToPoint (void) const
   163 {
   164   return false;
   165 }
   166 bool 
   167 SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
   168 {
   169   Mac48Address to = Mac48Address::ConvertFrom (dest);
   170   m_channel->Send (packet, protocolNumber, to, m_address, this);
   171   return true;
   172 }
   173 bool 
   174 SimpleNetDevice::SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
   175 {
   176   Mac48Address to = Mac48Address::ConvertFrom (dest);
   177   Mac48Address from = Mac48Address::ConvertFrom (source);
   178   m_channel->Send (packet, protocolNumber, to, from, this);
   179   return true;
   180 }
   181 
   182 Ptr<Node> 
   183 SimpleNetDevice::GetNode (void) const
   184 {
   185   return m_node;
   186 }
   187 void 
   188 SimpleNetDevice::SetNode (Ptr<Node> node)
   189 {
   190   m_node = node;
   191 }
   192 bool 
   193 SimpleNetDevice::NeedsArp (void) const
   194 {
   195   return false;
   196 }
   197 void 
   198 SimpleNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
   199 {
   200   m_rxCallback = cb;
   201 }
   202 
   203 void
   204 SimpleNetDevice::DoDispose (void)
   205 {
   206   m_channel = 0;
   207   m_node = 0;
   208   NetDevice::DoDispose ();
   209 }
   210 
   211 
   212 void
   213 SimpleNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
   214 {
   215   m_promiscCallback = cb;
   216 }
   217 
   218 bool
   219 SimpleNetDevice::SupportsSendFrom (void) const
   220 {
   221   return true;
   222 }
   223 
   224 } // namespace ns3