mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 18:13:57 +02:00
Prime ND cache
This commit is contained in:
parent
603d8ccf70
commit
efa52f8e51
1 changed files with 45 additions and 6 deletions
|
@ -12,6 +12,43 @@ using namespace ns3;
|
|||
|
||||
NS_LOG_COMPONENT_DEFINE ("IslExample");
|
||||
|
||||
void PrepareNds (NodeContainer &nodes, Ipv6InterfaceContainer &interfaces)
|
||||
{
|
||||
// prepare NDS cache
|
||||
for (uint32_t i = 0; i < nodes.GetN (); i++)
|
||||
{
|
||||
Ptr<Node> node = nodes.Get (i);
|
||||
Ptr<NetDevice> dev = node->GetDevice (1); // TODO right index?
|
||||
uint32_t ifIndex = dev->GetIfIndex ();
|
||||
Ptr<Ipv6L3Protocol> ipv6 = node->GetObject<Ipv6L3Protocol> ();
|
||||
Ptr<Ipv6Interface> interface = ipv6->GetInterface (ifIndex);
|
||||
Ptr<NdiscCache> cache = interface->GetNdiscCache ();
|
||||
for (uint32_t j = 0; j < nodes.GetN (); j++)
|
||||
{
|
||||
// every other device
|
||||
if (i == j)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Ptr<NetDevice> otherDevice = nodes.Get (j)->GetDevice (1);
|
||||
Address address = otherDevice->GetAddress (); // MAC
|
||||
|
||||
// and associated address
|
||||
uint32_t otherIfIndex = otherDevice->GetIfIndex ();
|
||||
// TODO which address to use? site-local, global, link?
|
||||
Ipv6Address ipaddr = interfaces.GetAddress (otherIfIndex, 1); // IP
|
||||
|
||||
// update cache
|
||||
NdiscCache::Entry* entry = cache->Lookup (ipaddr);
|
||||
if (entry == 0)
|
||||
{
|
||||
entry = cache->Add (ipaddr);
|
||||
}
|
||||
entry->SetMacAddress (address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
|
@ -21,7 +58,7 @@ main (int argc, char *argv[])
|
|||
Time::SetResolution (Time::NS);
|
||||
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
||||
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
|
||||
LogComponentEnable ("UdpEchoClient", LOG_LEVEL_INFO);
|
||||
LogComponentEnable ("IslExample", LOG_LEVEL_DEBUG);
|
||||
|
||||
NodeContainer nodes;
|
||||
nodes.Create (3);
|
||||
|
@ -42,6 +79,8 @@ main (int argc, char *argv[])
|
|||
|
||||
Ipv6InterfaceContainer interfaces = address.Assign (devices);
|
||||
|
||||
PrepareNds (nodes, interfaces);
|
||||
|
||||
UdpEchoServerHelper echoServer (9);
|
||||
ApplicationContainer serverApps = echoServer.Install (nodes);
|
||||
|
||||
|
@ -52,12 +91,12 @@ main (int argc, char *argv[])
|
|||
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
|
||||
|
||||
for (uint32_t i = 1; i < nodes.GetN (); i++)
|
||||
{
|
||||
Address destAddress = interfaces.GetAddress (i, 0);
|
||||
echoClient.SetAttribute ("RemoteAddress", AddressValue (destAddress));
|
||||
{
|
||||
Address destAddress = interfaces.GetAddress (i, 0);
|
||||
echoClient.SetAttribute ("RemoteAddress", AddressValue (destAddress));
|
||||
|
||||
clientApps.Add (echoClient.Install (nodes.Get (i-1)));
|
||||
}
|
||||
clientApps.Add (echoClient.Install (nodes.Get (i-1)));
|
||||
}
|
||||
|
||||
clientApps.Start (Seconds (2.0));
|
||||
clientApps.Stop (Seconds (10.0));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue