Merge remote-tracking branch 'git.irl/master'

diff --git a/examples/annotated-topology-read-example.cc b/examples/annotated-topology-read-example.cc
new file mode 100644
index 0000000..03258b1
--- /dev/null
+++ b/examples/annotated-topology-read-example.cc
@@ -0,0 +1,270 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include <ctime>
+#include <sstream>
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/applications-module.h"
+#include "ns3/ipv4-static-routing-helper.h"
+#include "ns3/ipv4-list-routing-helper.h"
+#include "ns3/annotated-topology-reader.h"
+#include <list>
+#include "ns3/visualizer-module.h"
+
+using namespace ns3;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReadingExample");
+
+int main (int argc, char *argv[])
+{
+    //Packet::EnablePrinting();
+    GlobalValue::Bind ("SimulatorImplementationType", StringValue
+                       ("ns3::VisualSimulatorImpl"));
+    
+    string input ("/Users/iliamo/ns3-abstract-ndn/ns-3.11/src/NDNabstraction/examples/simpletopology.txt");
+    
+    // Set up command line parameters used to control the experiment.
+    //CommandLine cmd;
+    //cmd.AddValue ("input", "Name of the input file.",
+    //              input);
+    //cmd.Parse (argc, argv);
+    
+    
+    // ------------------------------------------------------------
+    // -- Read topology data.
+    // --------------------------------------------
+    NodeContainer nodes;
+    
+    Ptr<AnnotatedTopologyReader> inFile = CreateObject<AnnotatedTopologyReader> ();
+    inFile->SetFileName (input);
+    
+    if (inFile != 0)
+    {
+        nodes = inFile->Read ();
+    }
+    
+    if (inFile->LinksSize () == 0)
+    {
+        NS_LOG_ERROR ("Problems reading the topology file. Failing.");
+        return -1;
+    }
+    
+    // ------------------------------------------------------------
+    // -- Create nodes and network stacks
+    // --------------------------------------------
+    NS_LOG_INFO ("creating internet stack");
+    InternetStackHelper stack;
+    
+    
+    //routing
+    Ipv4StaticRoutingHelper staticRouting;
+    Ipv4ListRoutingHelper listRH;
+    listRH.Add (staticRouting, 0);
+    stack.SetRoutingHelper (listRH);  // has effect on the next Install ()
+    stack.Install (nodes);
+    
+    NS_LOG_INFO ("creating ip4 addresses");
+    Ipv4AddressHelper address;
+    address.SetBase ("10.0.0.0", "255.255.255.252");
+    
+    int totlinks = inFile->LinksSize ();
+    
+    NS_LOG_INFO ("creating node containers");
+    NodeContainer* nc = new NodeContainer[totlinks];
+    TopologyReader::ConstLinksIterator iter;
+    int i = 0;
+    for ( iter = inFile->LinksBegin (); iter != inFile->LinksEnd (); iter++, i++ )
+    {
+        nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ());
+    }
+    
+    NS_LOG_INFO ("creating net device containers");
+    ObjectFactory m_queueFactory;
+    m_queueFactory.SetTypeId("ns3::DropTailQueue");
+    //m_queueFactory.Set("Mode",
+    NetDeviceContainer* ndc = new NetDeviceContainer[totlinks];
+    PointToPointHelper p2p;
+    TopologyReader::ConstLinksIterator iter2;
+    i = 0;
+    for ( iter2 = inFile->LinksBegin (); iter2 != inFile->LinksEnd (); iter2++, i++ )
+    {
+        std::string dataRate = iter2->GetAttribute("DataRate");
+        NS_LOG_INFO("dataRate = "<<dataRate);
+        dataRate += "Kbps";
+        std::string delay = iter2->GetAttribute("Delay");
+        NS_LOG_INFO("delay = "<<delay);
+        delay += "ms";
+        p2p.SetDeviceAttribute("DataRate", StringValue(dataRate));
+        p2p.SetChannelAttribute("Delay", StringValue(delay));
+        p2p.SetQueue("ns3::DropTailQueue","MaxPackets",StringValue("100"));
+        ndc[i] = p2p.Install(nc[i]);
+        
+        NodeContainer twoNodes = nc[i];
+        
+        
+        Ptr<Node> nd = twoNodes.Get(0);
+        if(nd==NULL)
+            NS_LOG_INFO("nd = null");
+        Ptr<Node> nd2 = twoNodes.Get(1);
+        if(nd2==NULL)
+            NS_LOG_INFO("nd2 = null");
+        //NS_LOG_INFO("1");
+        NS_LOG_INFO("#netdevices = " << nd->GetNDevices());
+        NS_LOG_INFO("#netdevices = " << nd2->GetNDevices());
+
+        Ptr<PointToPointNetDevice> device = nd->GetDevice(nd->GetNDevices()-1)->GetObject<PointToPointNetDevice> ();
+        if(device==NULL)
+            NS_LOG_INFO("device = 0");
+        
+        //NS_LOG_INFO("2");
+        
+        Ptr<PointToPointNetDevice> device2 = nd2->GetDevice(nd2->GetNDevices()-1)->GetObject<PointToPointNetDevice> ();
+`
+        if(device2==NULL)
+            NS_LOG_INFO("device2 = 0");
+        
+        PointerValue tmp1;
+        device->GetAttribute ("TxQueue", tmp1);
+        //NS_LOG_INFO("2.5");
+        Ptr<Object> txQueue1 = tmp1.GetObject ();
+        
+        PointerValue tmp2;
+        device2->GetAttribute ("TxQueue", tmp2);
+        Ptr<Object> txQueue2 = tmp2.GetObject ();
+        //NS_LOG_INFO("3");
+        Ptr<DropTailQueue> dtq1 = txQueue1->GetObject <DropTailQueue> ();
+        NS_ASSERT (dtq1 != 0);
+        
+        Ptr<DropTailQueue> dtq2 = txQueue2->GetObject <DropTailQueue> ();
+        NS_ASSERT (dtq2 != 0);
+        
+        std::string queuesize1 = iter2->GetAttribute("QueueSizeNode1");
+        std::string queuesize2 = iter2->GetAttribute("QueueSizeNode2");
+        //NS_LOG_INFO("4");
+        txQueue1->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize1.c_str())));
+        txQueue2->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize2.c_str())));
+        
+        UintegerValue limit;
+        txQueue1->GetAttribute ("MaxPackets", limit);
+        NS_LOG_INFO ("txQueue1 limit changed: " << limit.Get () << " packets");
+        
+        txQueue2->GetAttribute ("MaxPackets", limit);
+        NS_LOG_INFO ("txQueue2 limit changed: " << limit.Get () << " packets");
+        
+    
+        /* //bauman way of doing things
+        m_queueFactory.Set("MaxPackets",StringValue(iter2->GetAttribute("QueueSizeNode1")));
+        NS_LOG_INFO("2.5");
+        Ptr<DropTailQueue> queue = m_queueFactory.Create<DropTailQueue>();
+        queue->SetMode(ns3::DropTailQueue::PACKETS);
+        NS_LOG_INFO("2,8");
+        device->SetQueue(queue);
+        NS_LOG_INFO("3");
+        m_queueFactory.Set("MaxPackets", StringValue(iter2->GetAttribute("QueueSizeNode2")));
+        
+        Ptr<DropTailQueue> queue2 = m_queueFactory.Create<DropTailQueue>();
+        queue2->SetMode(ns3::DropTailQueue::PACKETS);
+        device2->SetQueue(queue2);
+        */
+    }
+    
+    // it creates little subnets, one for each couple of nodes.
+    NS_LOG_INFO ("creating ipv4 interfaces");
+    Ipv4InterfaceContainer* ipic = new Ipv4InterfaceContainer[totlinks];
+    for (int i = 0; i < totlinks; i++)
+    {
+        ipic[i] = address.Assign (ndc[i]);
+        address.NewNetwork ();
+    }
+    
+    
+    
+    
+    
+    
+    /*
+    NS_LOG_INFO ("Create Applications.");
+    uint16_t port = 9;   // Discard port (RFC 863)
+    
+    std::string sendsizeattr = "SendSize";
+    //flow2 7-->2
+    BulkSendHelper bulksend0 ("ns3::TcpSocketFactory", InetSocketAddress (ipic[1].GetAddress (0), port));
+    //bulksend0.SetAttribute(sendsizeattr, AttributeValue(ConstantVariable(2560)));
+    bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
+    ApplicationContainer apps = bulksend0.Install(nc[6]);
+    apps.Start(Seconds (1.0));
+    apps.Stop(Seconds (10.0));
+    
+    // Create a packet sink to receive these packets
+    PacketSinkHelper sink0 ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny (), port));
+    apps = sink0.Install(nc[1]);
+    apps.Start(Seconds(0.0));
+    apps.Stop(Seconds(20.0));
+    
+    //flow1 1-->6
+    BulkSendHelper bulksend ("ns3::TcpSocketFactory", InetSocketAddress (ipic[5].GetAddress (1), port));
+    //bulksend.SetAttribute(sendsizeattr, AttributeValue( ConstantVariable(2560)));
+    bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
+    apps = bulksend.Install (nc[0]);
+    apps.Start (Seconds (6.0));
+    apps.Stop (Seconds (20.0));
+    
+    // Create a packet sink to receive these packets
+    PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
+    apps = sink.Install (nc[5]);
+    apps.Start(Seconds(0.0));
+    apps.Stop(Seconds(20.0));
+    
+    AsciiTraceHelper ascii;
+    p2p.EnableAsciiAll (ascii.CreateFileStream ("annotated-topology-read.tr"));
+    p2p.EnablePcapAll ("annotated-topology-read");
+    
+    */
+    
+    
+    
+    
+    
+    
+    
+    
+    // ------------------------------------------------------------
+    // -- Run the simulation
+    // --------------------------------------------
+    NS_LOG_INFO ("Run Simulation.");
+    Simulator::Stop (Seconds (20));
+    Simulator::Run ();
+    Simulator::Destroy ();
+    
+    delete[] ipic;
+    delete[] ndc;
+    delete[] nc;
+    
+    NS_LOG_INFO ("Done.");
+    
+    return 0;
+    
+    // end main
+}
diff --git a/examples/simpletopology.txt b/examples/simpletopology.txt
new file mode 100644
index 0000000..8e39d06
--- /dev/null
+++ b/examples/simpletopology.txt
@@ -0,0 +1,8 @@
+7   7
+1   3   10000   1   80  120
+2   3   10000   1   110 150
+3   4   1000    1   40  30
+3   5   1000    50  55  50
+4   5   1000    1   10  20
+5   6   10000   1   15  35
+5   7   10000   50  25  45
diff --git a/model/annotated-topology-reader.cc b/model/annotated-topology-reader.cc
new file mode 100644
index 0000000..c1c597f
--- /dev/null
+++ b/model/annotated-topology-reader.cc
@@ -0,0 +1,165 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "annotated-topology-reader.h"
+#include <fstream>
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include "ns3/log.h"
+
+using namespace std;
+
+namespace ns3 
+{    
+    NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReader");
+    
+    NS_OBJECT_ENSURE_REGISTERED (AnnotatedTopologyReader);
+    
+    TypeId AnnotatedTopologyReader::GetTypeId (void)
+    {
+        static TypeId tid = TypeId ("ns3::AnnotatedTopologyReader")
+        .SetParent<Object> ()
+        ;
+        return tid;
+    }
+    
+    AnnotatedTopologyReader::AnnotatedTopologyReader ()
+    {
+        NS_LOG_FUNCTION (this);
+    }
+    
+    AnnotatedTopologyReader::~AnnotatedTopologyReader ()
+    {
+        NS_LOG_FUNCTION (this);
+    }
+    
+    NodeContainer
+    AnnotatedTopologyReader::Read (void)
+    {
+        ifstream topgen;
+        topgen.open (GetFileName ().c_str ());
+        map<string, Ptr<Node> > nodeMap;
+        NodeContainer nodes;
+        
+        if ( !topgen.is_open () )
+        {
+            return nodes;
+        }
+        
+        string from;
+        string to;
+        string linkAttr;
+        
+        int linksNumber = 0;
+        int nodesNumber = 0;
+        
+        int totnode = 0;
+        int totlink = 0;
+        
+        istringstream lineBuffer;
+        string line;
+        
+        getline (topgen,line);
+        lineBuffer.str (line);
+        
+        lineBuffer >> totnode;
+        lineBuffer >> totlink;
+        NS_LOG_INFO ("Annotated topology should have " << totnode << " nodes and " << totlink << " links");
+        
+        if(!topgen.eof ())
+            NS_LOG_INFO("!EOF");
+        
+        /*for (int i = 0; i <= totnode; i++)
+        {
+            getline (topgen,line);
+        }*/
+        
+        for (int i = 0; i < totlink && !topgen.eof (); i++)
+        {
+            //NS_LOG_INFO("Line #" <<i);
+            getline (topgen,line);
+            lineBuffer.clear ();
+            lineBuffer.str (line);
+            
+            lineBuffer >> from;
+            lineBuffer >> to;
+            
+            
+            if ( (!from.empty ()) && (!to.empty ()) )
+            {
+                NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to );
+                
+                if ( nodeMap[from] == 0 )
+                {
+                    Ptr<Node> tmpNode = CreateObject<Node> ();
+                    nodeMap[from] = tmpNode;
+                    nodes.Add (tmpNode);
+                    nodesNumber++;
+                }
+                
+                if (nodeMap[to] == 0)
+                {
+                    Ptr<Node> tmpNode = CreateObject<Node> ();
+                    nodeMap[to] = tmpNode;
+                    nodes.Add (tmpNode);
+                    nodesNumber++;
+                }
+                
+                Link link ( nodeMap[from], from, nodeMap[to], to );
+                
+                lineBuffer >> linkAttr;
+                if ( !linkAttr.empty () )
+                {
+                    link.SetAttribute ("DataRate", linkAttr);
+                }
+                
+                lineBuffer >> linkAttr;
+                if ( !linkAttr.empty () )
+                {
+                    link.SetAttribute ("Delay", linkAttr);
+                }
+                
+                lineBuffer >> linkAttr;
+                if ( !linkAttr.empty () )
+                {
+                    link.SetAttribute ("QueueSizeNode1", linkAttr);
+                }
+                
+                lineBuffer >> linkAttr;
+                if ( !linkAttr.empty () )
+                {
+                    link.SetAttribute ("QueueSizeNode2", linkAttr);
+                }
+                
+                AddLink (link);
+                
+                linksNumber++;
+            }
+        }
+        
+        NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links");
+        topgen.close ();
+        
+        return nodes;
+    }
+    
+} /* namespace ns3 */
+
diff --git a/model/annotated-topology-reader.h b/model/annotated-topology-reader.h
new file mode 100644
index 0000000..f979aba
--- /dev/null
+++ b/model/annotated-topology-reader.h
@@ -0,0 +1,65 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#ifndef __ANNOTATED_TOPOLOGY_READER_H__
+#define __ANNOTATED_TOPOLOGY_READER_H__
+
+#include "ns3/nstime.h"
+#include "ns3/topology-reader.h"
+
+namespace ns3 
+{
+    /**
+     * Input File Format
+     * 1st line is     NumberOfNodes    TAB     NumberofLinks
+     * Nth line is     NodeID1  TAB    NodeID2   TAB  DataRateKBPS    TAB    DelayMiliseconds   TAB   QueueSizeInPackets1     TAB    QueueSizeInPackets2 
+     *
+     */
+    class AnnotatedTopologyReader : public TopologyReader
+    {
+    public:
+        typedef std::list< Link >::iterator LinksIterator;
+        static TypeId GetTypeId (void);
+        
+        AnnotatedTopologyReader ();
+        virtual ~AnnotatedTopologyReader ();
+        
+        /**
+         * \brief Main topology reading function.
+         *
+         * This method opens an input stream and reads the Orbis-format file.
+         * Every row represents a topology link (the ids of a couple of nodes),
+         * so the input file is read line by line to figure out how many links
+         * and nodes are in the topology.
+         *
+         * \return the container of the nodes created (or empty container if there was an error)
+         */
+        virtual NodeContainer Read (void);
+        
+    private:
+        AnnotatedTopologyReader (const AnnotatedTopologyReader&);
+        AnnotatedTopologyReader& operator= (const AnnotatedTopologyReader&);
+    };
+}
+
+
+#endif
+
+
diff --git a/wscript b/wscript
index 8f210c6..0142dc2 100644
--- a/wscript
+++ b/wscript
@@ -22,7 +22,8 @@
 
 
 def build(bld):
-    module = bld.create_ns3_module ('NDNabstraction', ['applications', 'core', 'network', 'point-to-point'])
+    module = bld.create_ns3_module ('NDNabstraction', ['applications', 'core', 'network', 'point-to-point','topology-read','visualizer'])
+
     tests = bld.create_ns3_module_test_library('NDNabstraction')
     headers = bld.new_task_gen('ns3header')
     headers.module = 'NDNabstraction'