Add ARP cache helper

This commit is contained in:
Tim Schubert 2020-07-18 11:55:21 +02:00
parent 4628af9511
commit bbf9269a14
5 changed files with 95 additions and 1 deletions

View file

@ -0,0 +1,54 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "../model/leo-mock-net-device.h"
#include "arp-cache-helper.h"
namespace ns3
{
void
ArpCacheHelper::Install (NetDeviceContainer &devices, Ipv4InterfaceContainer &interfaces) const
{
for (size_t i = 0; i < devices.GetN (); i ++)
{
Ptr<NetDevice> dev = devices.Get (i);
Ptr<Node> node = dev->GetNode ();
Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
int32_t ifIndex = ipv4->GetInterfaceForDevice (dev);
Ptr<Ipv4Interface> interface = ipv4->GetInterface (ifIndex);
Ptr<ArpCache> cache = interface->GetArpCache ();
for (uint32_t j = 0; j < devices.GetN (); j++)
{
// every other device, that is not of same "type"
Ptr<NetDevice> otherDevice = devices.Get (j);
Ptr<LeoMockNetDevice> leoDev = DynamicCast<LeoMockNetDevice> (dev);
Ptr<LeoMockNetDevice> otherLeoDev = DynamicCast<LeoMockNetDevice> (otherDevice);
if (i == j || (leoDev != 0
&& otherLeoDev != 0
&& leoDev->GetDeviceType () == otherLeoDev->GetDeviceType ()))
{
continue;
}
Address address = otherDevice->GetAddress (); // MAC
// and associated address
uint32_t otherIfIndex = otherDevice->GetIfIndex ();
Ipv4Address ipaddr = interfaces.GetAddress (otherIfIndex, 1); // IP
// update cache
ArpCache::Entry* entry = cache->Lookup (ipaddr);
if (entry == 0)
{
entry = cache->Add (ipaddr);
}
entry->SetMacAddress (address);
}
}
}
};

23
helper/arp-cache-helper.h Normal file
View file

@ -0,0 +1,23 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#ifndef ARP_CACHE_HELPER_H
#define ARP_CACHE_HELPER_H
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/node-container.h"
namespace ns3 {
class ArpCacheHelper
{
public:
void Install (NetDeviceContainer &devices, Ipv4InterfaceContainer &interfaces) const;
void Install (NetDeviceContainer &devicesSrc, NetDeviceContainer &devicesDst, Ipv4InterfaceContainer &interfaces) const;
};
}; /* namespace ns3 */
#endif /* ARP_CACHE_HELPER */

View file

@ -1,7 +1,9 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "nd-cache-helper.h"
#include "arp-cache-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/ipv4-interface-container.h"
#include "leo-helper.h"
namespace ns3 {
@ -40,6 +42,17 @@ LeoHelper::Install (NodeContainer &satellites, NodeContainer &gateways, NodeCont
ndCache.Install (gwNet, gwAddrs);
ndCache.Install (utNet, utAddrs);
// Make all networks addressable for legacy protocol
Ipv4AddressHelper legacy;
Ipv4InterfaceContainer islLegacy = legacy.Assign (islNet);
Ipv4InterfaceContainer gwLegacy = legacy.Assign (gwNet);
Ipv4InterfaceContainer utLegacy = legacy.Assign (utNet);
ArpCacheHelper arpCache;
arpCache.Install (islNet, islLegacy);
arpCache.Install (gwNet, gwLegacy);
arpCache.Install (utNet, utLegacy);
// Add to resulting container of net devices
container.Add (islNet);
container.Add (gwNet);

View file

@ -1,3 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"

View file

@ -9,6 +9,7 @@
def build(bld):
module = bld.create_ns3_module('leo', ['core','internet', 'propagation', 'stats', 'traffic', 'flow-monitor', 'applications'])
module.source = [
'helper/arp-cache-helper.cc',
'helper/isl-helper.cc',
'helper/leo-channel-helper.cc',
'helper/leo-helper.cc',
@ -41,6 +42,7 @@ def build(bld):
headers = bld(features='ns3header')
headers.module = 'leo'
headers.source = [
'helper/arp-cache-helper.h',
'helper/isl-helper.h',
'helper/leo-channel-helper.h',
'helper/leo-helper.h',