This commit is contained in:
Deepthi Gunasekara 2026-06-20 21:28:03 +00:00 • committed by GitHub
commit 68501d3bd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 415 additions and 0 deletions

View file

@ -0,0 +1,91 @@
#include <fstream>
/* #include "core-module.h"
#include "internet-module.h"
#include "csma-module.h"
#include "internet-apps-module.h" */
#include "ipv6-static-routing-helper.h"
// #include "ipv6-routing-table-entry.h"
NS_LOG_COMPONENT_DEFINE ("FragmentationIpv6TwoMtuExample");
int main (int argc, char** argv)
{
bool connection = false;
CommandLine cmd;
cmd.AddValue ("connection", "turn on log components", connection);
cmd.Parse (argc, argv);
if (connection)
{
LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
}
/* NS_LOG_INFO ("Create nodes.");
Ptr<Node> n0 = CreateObject<Node> ();
Ptr<Node> r = CreateObject<Node> ();
Ptr<Node> n1 = CreateObject<Node> ();
NodeContainer net1 (n0, r);
NodeContainer net2 (r, n1);
NodeContainer all (n0, r, n1);
NS_LOG_INFO ("Create IPv6 Internet Stack");
InternetStackHelper internetv6;
internetv6.Install (all);
NS_LOG_INFO ("Create channels.");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
NetDeviceContainer d2 = csma.Install (net2);
csma.SetDeviceAttribute ("Mtu", UintegerValue (5000));
NetDeviceContainer d1 = csma.Install (net1);
NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
Ipv6AddressHelper ipv6;
ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
i1.SetForwarding (1, true);
i1.SetDefaultRouteInAllNodes (1);
ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
i2.SetForwarding (0, true);
i2.SetDefaultRouteInAllNodes (0);
Ipv6StaticRoutingHelper routingHelper;
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> (&std::cout);
routingHelper.PrintRoutingTableAt (Seconds (0), n0, routingStream);*/
/* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
uint32_t packetSize = 4096;
uint32_t maxPacketCount = 5;
Time interPacketInterval = Seconds (1.0);
Ping6Helper ping6;
ping6.SetLocal (i1.GetAddress (0, 1));
ping6.SetRemote (i2.GetAddress (1, 1));
ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
ApplicationContainer apps = ping6.Install (net1.Get (0));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (20.0));
AsciiTraceHelper ascii;
csma.EnableAsciiAll (ascii.CreateFileStream ("fragmentation-ipv6-two-mtu.tr"));
csma.EnablePcapAll (std::string ("fragmentation-ipv6-two-mtu"), true);
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}

215
ipv6-address-helper.cc Normal file
View file

@ -0,0 +1,215 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008-2009 Strasbourg University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
*/
#include "assert.h"
#include "log.h"
#include "ptr.h"
#include "node.h"
#include "net-device.h"
#include "loopback-net-device.h"
#include "mac16-address.h"
#include "mac48-address.h"
#include "mac64-address.h"
#include "ipv6.h"
#include "ipv6-address-generator.h"
#include "traffic-control-helper.h"
#include "traffic-control-layer.h"
#include "ipv6-address-helper.h"
NS_LOG_COMPONENT_DEFINE ("Ipv6AddressHelper");
Ipv6AddressHelper::Ipv6AddressHelper ()
{
NS_LOG_FUNCTION (this);
Ipv6AddressGenerator::Init (Ipv6Address ("2001:db8::"), Ipv6Prefix (64));
}
Ipv6AddressHelper::Ipv6AddressHelper (Ipv6Address network, Ipv6Prefix prefix,
Ipv6Address base)
{
NS_LOG_FUNCTION (this << network << prefix << base);
Ipv6AddressGenerator::Init (network, prefix, base);
}
void Ipv6AddressHelper::SetBase (Ipv6Address network, Ipv6Prefix prefix,
Ipv6Address base)
{
NS_LOG_FUNCTION (this << network << prefix << base);
Ipv6AddressGenerator::Init (network, Ipv6Prefix (64), base);
}
Ipv6Address Ipv6AddressHelper::NewAddress (Address addr)
{
NS_LOG_FUNCTION (this << addr);
if (Mac64Address::IsMatchingType (addr))
{
Ipv6Address network = Ipv6AddressGenerator::GetNetwork (Ipv6Prefix (64));
Ipv6Address address = Ipv6Address::MakeAutoconfiguredAddress (Mac64Address::ConvertFrom (addr), network);
Ipv6AddressGenerator::AddAllocated (address);
return address;
}
else if (Mac48Address::IsMatchingType (addr))
{
Ipv6Address network = Ipv6AddressGenerator::GetNetwork (Ipv6Prefix (64));
Ipv6Address address = Ipv6Address::MakeAutoconfiguredAddress (Mac48Address::ConvertFrom (addr), network);
Ipv6AddressGenerator::AddAllocated (address);
return address;
}
else if (Mac16Address::IsMatchingType (addr))
{
Ipv6Address network = Ipv6AddressGenerator::GetNetwork (Ipv6Prefix (64));
Ipv6Address address = Ipv6Address::MakeAutoconfiguredAddress (Mac16Address::ConvertFrom (addr), network);
Ipv6AddressGenerator::AddAllocated (address);
return address;
}
else
{
NS_FATAL_ERROR ("Did not pass in a valid Mac Address (16, 48 or 64 bits)");
}
/* never reached */
return Ipv6Address ("::");
}
Ipv6Address Ipv6AddressHelper::NewAddress (void)
{
NS_LOG_FUNCTION (this);
//
// The way this is expected to be used is that an address and network number
// are initialized, and then NewAddress() is called repeatedly to allocate and
// get new addresses on a given subnet. The client will expect that the first
// address she gets back is the one she used to initialize the generator with.
// This implies that this operation is a post-increment.
//
return Ipv6AddressGenerator::NextAddress (Ipv6Prefix (64));
}
void Ipv6AddressHelper::NewNetwork (void)
{
NS_LOG_FUNCTION (this);
Ipv6AddressGenerator::NextNetwork (Ipv6Prefix (64));
}
Ipv6InterfaceContainer Ipv6AddressHelper::Assign (const NetDeviceContainer &c)
{
NS_LOG_FUNCTION (this);
Ipv6InterfaceContainer retval;
for (uint32_t i = 0; i < c.GetN (); ++i)
{
Ptr<NetDevice> device = c.Get (i);
Ptr<Node> node = device->GetNode ();
NS_ASSERT_MSG (node, "Ipv6AddressHelper::Allocate (): Bad node");
Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
NS_ASSERT_MSG (ipv6, "Ipv6AddressHelper::Allocate (): Bad ipv6");
int32_t ifIndex = 0;
ifIndex = ipv6->GetInterfaceForDevice (device);
if (ifIndex == -1)
{
ifIndex = ipv6->AddInterface (device);
}
NS_ASSERT_MSG (ifIndex >= 0, "Ipv6AddressHelper::Allocate (): "
"Interface index not found");
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (NewAddress (device->GetAddress ()), Ipv6Prefix (64));
ipv6->SetMetric (ifIndex, 1);
ipv6->AddAddress (ifIndex, ipv6Addr);
ipv6->SetUp (ifIndex);
retval.Add (ipv6, ifIndex);
// Install the default traffic control configuration if the traffic
// control layer has been aggregated, if this is not
// a loopback interface, and there is no queue disc installed already
Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer> ();
if (tc && DynamicCast<LoopbackNetDevice> (device) == 0 && tc->GetRootQueueDiscOnDevice (device) == 0)
{
NS_LOG_LOGIC ("Installing default traffic control configuration");
TrafficControlHelper tcHelper = TrafficControlHelper::Default ();
tcHelper.Install (device);
}
}
return retval;
}
Ipv6InterfaceContainer Ipv6AddressHelper::Assign (const NetDeviceContainer &c, std::vector<bool> withConfiguration)
{
NS_LOG_FUNCTION (this);
Ipv6InterfaceContainer retval;
for (uint32_t i = 0; i < c.GetN (); ++i)
{
Ptr<NetDevice> device = c.Get (i);
Ptr<Node> node = device->GetNode ();
NS_ASSERT_MSG (node, "Ipv6AddressHelper::Allocate (): Bad node");
Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
NS_ASSERT_MSG (ipv6, "Ipv6AddressHelper::Allocate (): Bad ipv6");
int32_t ifIndex = ipv6->GetInterfaceForDevice (device);
if (ifIndex == -1)
{
ifIndex = ipv6->AddInterface (device);
}
NS_ASSERT_MSG (ifIndex >= 0, "Ipv6AddressHelper::Allocate (): "
"Interface index not found");
ipv6->SetMetric (ifIndex, 1);
if (withConfiguration.at (i))
{
Ipv6InterfaceAddress ipv6Addr = Ipv6InterfaceAddress (NewAddress (device->GetAddress ()), Ipv6Prefix (64));
ipv6->AddAddress (ifIndex, ipv6Addr);
}
ipv6->SetUp (ifIndex);
retval.Add (ipv6, ifIndex);
// Install the default traffic control configuration if the traffic
// control layer has been aggregated, if this is not
// a loopback interface, and there is no queue disc installed already
Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer> ();
if (tc && DynamicCast<LoopbackNetDevice> (device) == 0 && tc->GetRootQueueDiscOnDevice (device) == 0)
{
NS_LOG_LOGIC ("Installing default traffic control configuration");
TrafficControlHelper tcHelper = TrafficControlHelper::Default ();
tcHelper.Install (device);
}
}
return retval;
}
// Helper API that is redundant with Assign (c, false);
Ipv6InterfaceContainer Ipv6AddressHelper::AssignWithoutAddress (const NetDeviceContainer &c)
{
NS_LOG_FUNCTION (this);
std::vector<bool> withConfiguration;
for (uint32_t i = 0; i < c.GetN (); ++i)
{
withConfiguration.push_back (false);
}
return Assign (c, withConfiguration);
}

58
ipv6-address-helper.h Normal file
View file

@ -0,0 +1,58 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008-2009 Strasbourg University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
* modified by Tom Henderson for ns-3.14 release
*/
#ifndef IPV6_ADDRESS_HELPER_H
#define IPV6_ADDRESS_HELPER_H
#include <vector>
#include "ipv6-address.h"
#include "net-device-container.h"
#include "ipv6-interface-container.h"
class Ipv6AddressHelper
{
public:
Ipv6AddressHelper ();
Ipv6AddressHelper (Ipv6Address network, Ipv6Prefix prefix,
Ipv6Address base = Ipv6Address ("::1"));
void SetBase (Ipv6Address network, Ipv6Prefix prefix,
Ipv6Address base = Ipv6Address ("::1"));
void NewNetwork (void);
Ipv6Address NewAddress (Address addr);
Ipv6Address NewAddress (void);
Ipv6InterfaceContainer Assign (const NetDeviceContainer &c);
Ipv6InterfaceContainer Assign (const NetDeviceContainer &c, std::vector<bool> withConfiguration);
Ipv6InterfaceContainer AssignWithoutAddress (const NetDeviceContainer &c);
};
#endif /* IPV6_ADDRESS_STATIC_H */

View file

@ -0,0 +1,51 @@
#define IPV6_STATIC_ROUTING_HELPER_H
#include "ipv6.h"
#include "ipv6-static-routing.h"
#include "ptr.h"
#include "ipv6-address.h"
#include "node.h"
#include "net-device.h"
#include "node-container.h"
#include "net-device-container.h"
#include "ipv6-routing-helper.h"
class Ipv6StaticRoutingHelper : public Ipv6RoutingHelper
{
public:
Ipv6StaticRoutingHelper ();
Ipv6StaticRoutingHelper (const Ipv6StaticRoutingHelper &);
Ipv6StaticRoutingHelper* Copy (void) const;
virtual Ptr<Ipv6RoutingProtocol> Create (Ptr<Node> node) const;
Ptr<Ipv6StaticRouting> GetStaticRouting (Ptr<Ipv6> ipv6) const;
/*
void AddMulticastRoute (Ptr<Node> n, Ipv6Address source, Ipv6Address group,
Ptr<NetDevice> input, NetDeviceContainer output);
void AddMulticastRoute (std::string n, Ipv6Address source, Ipv6Address group,
Ptr<NetDevice> input, NetDeviceContainer output);
void AddMulticastRoute (Ptr<Node> n, Ipv6Address source, Ipv6Address group,
std::string inputName, NetDeviceContainer output);
void AddMulticastRoute (std::string nName, Ipv6Address source, Ipv6Address group,
std::string inputName, NetDeviceContainer output);
*/
#if 0
void SetDefaultMulticastRoute (Ptr<Node> n, Ptr<NetDevice> nd);
void SetDefaultMulticastRoute (Ptr<Node> n, std::string ndName);
void SetDefaultMulticastRoute (std::string nName, Ptr<NetDevice> nd);
void SetDefaultMulticastRoute (std::string nName, std::string ndName);
#endif
private:
Ipv6StaticRoutingHelper &operator = (const Ipv6StaticRoutingHelper &o);
};