NetAnim: Add link update XML tag
This commit is contained in:
132
src/netanim/examples/dynamic_linknode.cc
Normal file
132
src/netanim/examples/dynamic_linknode.cc
Normal file
@@ -0,0 +1,132 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* 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: John Abraham <john.abraham.in@gmail.com>
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/network-module.h"
|
||||
#include "ns3/internet-module.h"
|
||||
#include "ns3/point-to-point-module.h"
|
||||
#include "ns3/netanim-module.h"
|
||||
#include "ns3/applications-module.h"
|
||||
#include "ns3/point-to-point-layout-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
AnimationInterface * pAnim = 0;
|
||||
|
||||
void modify ()
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Update:" << Simulator::Now ().GetSeconds ();
|
||||
pAnim->UpdateLinkDescription (0, 1, oss.str ());
|
||||
pAnim->UpdateLinkDescription (0, 2, oss.str ());
|
||||
pAnim->UpdateLinkDescription (0, 3, oss.str ());
|
||||
pAnim->UpdateLinkDescription (0, 4, oss.str ());
|
||||
pAnim->UpdateLinkDescription (0, 5, oss.str ());
|
||||
pAnim->UpdateLinkDescription (0, 6, oss.str ());
|
||||
pAnim->UpdateLinkDescription (1, 7, oss.str ());
|
||||
pAnim->UpdateLinkDescription (1, 8, oss.str ());
|
||||
pAnim->UpdateLinkDescription (1, 9, oss.str ());
|
||||
pAnim->UpdateLinkDescription (1, 10, oss.str ());
|
||||
pAnim->UpdateLinkDescription (1, 11, oss.str ());
|
||||
if (Simulator::Now ().GetSeconds () < 10) // This is important or the simulation
|
||||
// will run endlessly
|
||||
Simulator::Schedule (Seconds (1), modify);
|
||||
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
|
||||
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
|
||||
|
||||
uint32_t nLeftLeaf = 5;
|
||||
uint32_t nRightLeaf = 5;
|
||||
uint32_t nLeaf = 0; // If non-zero, number of both left and right
|
||||
std::string animFile = "dynamic_linknode.xml" ; // Name of file for animation output
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
|
||||
cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
|
||||
cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
|
||||
cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
|
||||
|
||||
cmd.Parse (argc,argv);
|
||||
if (nLeaf > 0)
|
||||
{
|
||||
nLeftLeaf = nLeaf;
|
||||
nRightLeaf = nLeaf;
|
||||
}
|
||||
|
||||
// Create the point-to-point link helpers
|
||||
PointToPointHelper pointToPointRouter;
|
||||
pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
|
||||
pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
|
||||
PointToPointHelper pointToPointLeaf;
|
||||
pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
|
||||
pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
|
||||
|
||||
PointToPointDumbbellHelper d (nLeftLeaf, pointToPointLeaf,
|
||||
nRightLeaf, pointToPointLeaf,
|
||||
pointToPointRouter);
|
||||
|
||||
// Install Stack
|
||||
InternetStackHelper stack;
|
||||
d.InstallStack (stack);
|
||||
|
||||
// Assign IP Addresses
|
||||
d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
|
||||
Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
|
||||
Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
|
||||
|
||||
// Install on/off app on all right side nodes
|
||||
OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
|
||||
clientHelper.SetAttribute
|
||||
("OnTime", RandomVariableValue (UniformVariable (0, 1)));
|
||||
clientHelper.SetAttribute
|
||||
("OffTime", RandomVariableValue (UniformVariable (0, 1)));
|
||||
ApplicationContainer clientApps;
|
||||
|
||||
for (uint32_t i = 0; i < d.RightCount (); ++i)
|
||||
{
|
||||
// Create an on/off app sending packets to the same leaf right side
|
||||
AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
|
||||
clientHelper.SetAttribute ("Remote", remoteAddress);
|
||||
clientApps.Add (clientHelper.Install (d.GetRight (i)));
|
||||
}
|
||||
|
||||
clientApps.Start (Seconds (0.0));
|
||||
clientApps.Stop (Seconds (10.0));
|
||||
|
||||
// Set the bounding box for animation
|
||||
d.BoundingBox (1, 1, 100, 100);
|
||||
|
||||
// Create the animation object and configure for specified output
|
||||
pAnim = new AnimationInterface (animFile);
|
||||
Simulator::Schedule (Seconds (1), modify);
|
||||
|
||||
// Set up the acutal simulation
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
Simulator::Run ();
|
||||
std::cout << "Animation Trace file created:" << animFile.c_str ()<< std::endl;
|
||||
Simulator::Destroy ();
|
||||
delete pAnim;
|
||||
return 0;
|
||||
}
|
||||
@@ -20,3 +20,7 @@ def build(bld):
|
||||
obj = bld.create_ns3_program('uan-animation',
|
||||
['netanim', 'internet', 'mobility', 'tools', 'applications', 'uan'])
|
||||
obj.source = 'uan-animation.cc'
|
||||
|
||||
obj = bld.create_ns3_program('dynamic_linknode',
|
||||
['netanim', 'applications', 'point-to-point-layout'])
|
||||
obj.source = 'dynamic_linknode.cc'
|
||||
|
||||
@@ -1321,7 +1321,10 @@ std::string AnimationInterface::GetPreamble ()
|
||||
* toId = To Node Id\n\
|
||||
* fd = From Node description (for IP Address)\n\
|
||||
* td = To Node description (for IP Address)\n\
|
||||
* ld = Link description (for Bandwidth,delay etc)\n\
|
||||
* ld = Link description (for Bandwidth, delay etc)\n\
|
||||
linkupdate\n\
|
||||
* t = Simulation time\n\
|
||||
* ld = Link description (for Bandwidth, delay etc)\n\
|
||||
packet\n\
|
||||
* fbTx = First bit transmit time\n\
|
||||
* lbTx = Last bit transmit time\n\
|
||||
@@ -1418,6 +1421,14 @@ void AnimationInterface::SetNodeColor (NodeContainer nc, uint8_t r, uint8_t g, u
|
||||
}
|
||||
|
||||
|
||||
void AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
|
||||
std::string linkDescription)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << GetXMLOpenClose_linkupdate (fromNode, toNode, linkDescription);
|
||||
WriteN (oss.str ());
|
||||
}
|
||||
|
||||
void AnimationInterface::SetLinkDescription (uint32_t fromNode, uint32_t toNode,
|
||||
std::string fromNodeDescription,
|
||||
std::string toNodeDescription,
|
||||
@@ -1517,7 +1528,31 @@ std::string AnimationInterface::GetXMLOpenClose_node (uint32_t lp, uint32_t id,
|
||||
return oss.str ();
|
||||
}
|
||||
|
||||
std::string AnimationInterface::GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string linkDescription)
|
||||
{
|
||||
bool linkFound = false;
|
||||
std::ostringstream oss;
|
||||
oss << "<linkupdate t=\"" << Simulator::Now ().GetSeconds () << "\""
|
||||
<< " fromId=\"" << fromId
|
||||
<< "\" toId=\"" << toId
|
||||
<< "\" ";
|
||||
|
||||
P2pLinkNodeIdPair p1 = { fromId, toId };
|
||||
P2pLinkNodeIdPair p2 = { toId, fromId };
|
||||
if (linkProperties.find (p1) != linkProperties.end())
|
||||
{
|
||||
linkFound = true;
|
||||
}
|
||||
else if (linkProperties.find (p2) != linkProperties.end())
|
||||
{
|
||||
linkFound = true;
|
||||
}
|
||||
|
||||
oss << " ld=\"" << linkDescription << "\""
|
||||
<< " />\n";
|
||||
return oss.str ();
|
||||
|
||||
}
|
||||
|
||||
std::string AnimationInterface::GetXMLOpenClose_link (uint32_t fromLp, uint32_t fromId, uint32_t toLp, uint32_t toId)
|
||||
{
|
||||
|
||||
@@ -280,6 +280,18 @@ public:
|
||||
std::string toNodeDescription = "");
|
||||
|
||||
|
||||
/**
|
||||
* \brief Helper function to update the description for a link
|
||||
* \param fromNode Node Id of the "from Node" of the p2p link
|
||||
* \param toNode Node Id of the "to Node" of the p2p link
|
||||
* \param linkDescription Description of the link such as link bandwidth
|
||||
*
|
||||
*/
|
||||
void UpdateLinkDescription (uint32_t fromNode, uint32_t toNode,
|
||||
std::string linkDescription);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Is AnimationInterface started
|
||||
* \returns true if AnimationInterface was started
|
||||
@@ -469,6 +481,7 @@ private:
|
||||
std::string GetXMLOpenClose_node (uint32_t lp,uint32_t id,double locX,double locY);
|
||||
std::string GetXMLOpenClose_node (uint32_t lp,uint32_t id,double locX,double locY, struct Rgb rgb);
|
||||
std::string GetXMLOpenClose_link (uint32_t fromLp,uint32_t fromId, uint32_t toLp, uint32_t toId);
|
||||
std::string GetXMLOpenClose_linkupdate (uint32_t fromId, uint32_t toId, std::string);
|
||||
std::string GetXMLOpen_packet (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, std::string auxInfo = "");
|
||||
std::string GetXMLOpenClose_rx (uint32_t toLp, uint32_t toId, double fbRx, double lbRx);
|
||||
std::string GetXMLOpen_wpacket (uint32_t fromLp,uint32_t fromId, double fbTx, double lbTx, double range);
|
||||
|
||||
Reference in New Issue
Block a user