21 #include "ipv4-interface.h"
22 #include "loopback-net-device.h"
23 #include "ns3/ipv4-address.h"
24 #include "ipv4-l3-protocol.h"
25 #include "arp-l3-protocol.h"
26 #include "arp-cache.h"
27 #include "ns3/net-device.h"
29 #include "ns3/packet.h"
31 #include "ns3/pointer.h"
37 NS_OBJECT_ENSURE_REGISTERED (Ipv4Interface);
40 Ipv4Interface::GetTypeId (
void)
42 static TypeId tid = TypeId (
"ns3::Ipv4Interface")
44 .AddAttribute (
"ArpCache",
45 "The arp cache for this ipv4 interface",
47 MakePointerAccessor (&Ipv4Interface::SetArpCache,
49 MakePointerChecker<ArpCache> ())
71 Ipv4Interface::~Ipv4Interface ()
94 Ipv4Interface::SetDevice (Ptr<NetDevice> device)
102 Ipv4Interface::DoSetup (
void)
105 if (m_node == 0 || m_device == 0)
109 if (!m_device->NeedsArp ())
113 Ptr<ArpL3Protocol> arp = m_node->
GetObject<ArpL3Protocol> ();
114 m_cache = arp->CreateCache (m_device,
this);
208 if (DynamicCast<LoopbackNetDevice> (m_device))
212 m_device->Send (p, m_device->GetBroadcast (),
213 Ipv4L3Protocol::PROT_NUMBER);
217 for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
219 if (dest == (*i).GetLocal ())
223 ipv4->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER,
224 m_device->GetBroadcast (),
225 m_device->GetBroadcast (),
231 if (m_device->NeedsArp ())
240 hardwareDestination = m_device->GetBroadcast ();
247 "ArpIpv4Interface::SendTo (): Sending multicast packet over "
248 "non-multicast device");
250 hardwareDestination = m_device->GetMulticast (dest);
255 for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
260 hardwareDestination = m_device->GetBroadcast ();
268 found = arp->Lookup (p, dest, m_device, m_cache, &hardwareDestination);
279 if (!bytes && m_node->IsCognitiveRadio()) {
280 device = m_node->
GetDevice(TRANSMITTER_RADIO);
282 device->Send (p, hardwareDestination,
283 Ipv4L3Protocol::PROT_NUMBER);
289 m_device->Send (p, m_device->GetBroadcast (),
290 Ipv4L3Protocol::PROT_NUMBER);
298 return m_ifaddrs.size ();
305 m_ifaddrs.push_back (addr);
313 if (index < m_ifaddrs.size ())
316 for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i!= m_ifaddrs.end (); i++)
334 if (index >= m_ifaddrs.size ())
336 NS_ASSERT_MSG (
false,
"Bug in Ipv4Interface::RemoveAddress");
338 Ipv4InterfaceAddressListI i = m_ifaddrs.begin ();
340 while (i != m_ifaddrs.end ())
void SetForwarding(bool val)
#define NS_LOG_FUNCTION(parameters)
void Send(Ptr< Packet > p, Ipv4Address dest)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
Ptr< ArpCache > GetArpCache() const
bool IsMulticast(void) const
Ipv4InterfaceAddress RemoveAddress(uint32_t index)
virtual void DoDispose(void)
bool AddAddress(Ipv4InterfaceAddress address)
a polymophic address class
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
bool PeekPacketTag(Tag &tag) const
bool IsBroadcast(void) const
Ptr< NetDevice > GetDevice(uint32_t index) const
#define NS_LOG_LOGIC(msg)
Ipv4InterfaceAddress GetAddress(uint32_t index) const
Implement the Ipv4 layer.
uint16_t GetMetric(void) const
#define NS_ASSERT_MSG(condition, message)
Ipv4 addresses are stored in host order in this class.
a class to store IPv4 address information on an interface
Ptr< NetDevice > GetDevice(void) const
An implementation of the ARP protocol.
void SetMetric(uint16_t metric)
virtual void DoDispose(void)
Ptr< T > GetObject(void) const
uint32_t GetNAddresses(void) const
bool IsForwarding(void) const