View | Details | Raw Unified | Return to bug 947
Collapse All | Expand All

(-)a/src/helper/ipv4-routing-helper.cc (+43 lines)
 Lines 18-27    Link Here 
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 */
19
 */
20
#include "ipv4-routing-helper.h"
20
#include "ipv4-routing-helper.h"
21
#include "ns3/node.h"
22
#include "ns3/node-list.h"
23
#include "ns3/simulator.h"
24
#include "ns3/ipv4-routing-protocol.h"
21
25
22
namespace ns3 {
26
namespace ns3 {
23
27
24
Ipv4RoutingHelper::~Ipv4RoutingHelper ()
28
Ipv4RoutingHelper::~Ipv4RoutingHelper ()
25
{}
29
{}
26
30
31
void
32
Ipv4RoutingHelper::PrintRoutingTableAllAt (Time printTime, Ptr<OutputStreamWrapper> stream)
33
{
34
  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
35
  {
36
    Ptr<Node> node = NodeList::GetNode (i);
37
    Ptr<Ipv4RoutingProtocol> rp = node->GetObject<Ipv4RoutingProtocol> ();
38
    Simulator::Schedule(printTime,&Ipv4RoutingProtocol::PrintRoutingTable,rp,stream);
39
  }
40
}
41
42
void
43
Ipv4RoutingHelper::PrintRoutingTableAllEvery (Time printTime, Ptr<OutputStreamWrapper> stream)
44
{
45
  for (uint32_t i = 0; i < NodeList::GetNNodes (); i++)
46
  {
47
    Ptr<Node> node = NodeList::GetNode (i);
48
    Ptr<Ipv4RoutingProtocol> rp = node->GetObject<Ipv4RoutingProtocol> ();
49
    Simulator::Schedule(printTime,&Ipv4RoutingProtocol::PrintRoutingTable,rp,stream);
50
  }
51
  Simulator::Schedule(printTime,&Ipv4RoutingHelper::PrintRoutingTableAllEvery,this,printTime,stream);
52
}
53
54
void
55
Ipv4RoutingHelper::PrintRoutingTableAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> stream)
56
{
57
  Ptr<Ipv4RoutingProtocol> rp = node->GetObject<Ipv4RoutingProtocol> ();
58
  Simulator::Schedule (printTime, &Ipv4RoutingProtocol::PrintRoutingTable, rp, stream);
59
}
60
61
void
62
Ipv4RoutingHelper::PrintRoutingTableEvery (Time printTime,Ptr<Node> node, Ptr<OutputStreamWrapper> stream)
63
{
64
  Ptr<Ipv4RoutingProtocol> rp = node->GetObject<Ipv4RoutingProtocol> ();
65
  Simulator::Schedule (printTime, &Ipv4RoutingProtocol::PrintRoutingTable, rp, stream);
66
  Simulator::Schedule(printTime,&Ipv4RoutingHelper::PrintRoutingTableEvery,this, printTime, node, stream);
67
}
68
69
27
} // namespace ns3
70
} // namespace ns3
(-)a/src/helper/ipv4-routing-helper.h (+32 lines)
 Lines 21-26    Link Here 
21
#define IPV4_ROUTING_HELPER_H
21
#define IPV4_ROUTING_HELPER_H
22
22
23
#include "ns3/ptr.h"
23
#include "ns3/ptr.h"
24
#include "ns3/nstime.h"
25
#include "ns3/output-stream-wrapper.h"
24
26
25
namespace ns3 {
27
namespace ns3 {
26
28
 Lines 58-63    Link Here 
58
   * \returns a newly-created routing protocol
60
   * \returns a newly-created routing protocol
59
   */
61
   */
60
  virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const = 0;
62
  virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const = 0;
63
64
  /**
65
   * \brief prints the routing tables of all nodes at a particular time.
66
   * \param printTime the time at which the routing table is supposed to be printed.
67
   * \param stream The output stream object to use when logging ascii traces.
68
   */
69
  void PrintRoutingTableAllAt (Time printTime, Ptr<OutputStreamWrapper> stream);
70
71
  /**
72
   * \brief prints the routing tables of all nodes at regular intervals specified by user.
73
   * \param printTime the time interval for which the routing table is supposed to be printed.
74
   * \param stream The output stream object to use when logging ascii traces.
75
   */
76
  void PrintRoutingTableAllEvery (Time printTime, Ptr<OutputStreamWrapper> stream);
77
78
  /**
79
   * \brief prints the routing tables of a node at a particular time.
80
   * \param printTime the time at which the routing table is supposed to be printed.
81
   * \param node The node ptr for which we need the routing table to be printed
82
   * \param stream The output stream object to use when logging ascii traces.
83
   */
84
  void PrintRoutingTableAt (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> stream);
85
86
  /**
87
   * \brief prints the routing tables of a node at regular intervals specified by user.
88
   * \param printTime the time interval for which the routing table is supposed to be printed.
89
   * \param node The node ptr for which we need the routing table to be printed
90
   * \param stream The output stream object to use when logging ascii traces.
91
   */
92
  void PrintRoutingTableEvery (Time printTime, Ptr<Node> node, Ptr<OutputStreamWrapper> stream);
61
};
93
};
62
94
63
} // namespace ns3
95
} // namespace ns3
(-)a/src/node/ipv4-routing-protocol.h (+3 lines)
 Lines 25-30    Link Here 
25
#include "ipv4-header.h"
25
#include "ipv4-header.h"
26
#include "ipv4-interface-address.h"
26
#include "ipv4-interface-address.h"
27
#include "ipv4.h"
27
#include "ipv4.h"
28
#include "ns3/output-stream-wrapper.h"
28
29
29
namespace ns3 {
30
namespace ns3 {
30
31
 Lines 140-145    Link Here 
140
   * Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol
141
   * Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol
141
   */
142
   */
142
  virtual void SetIpv4 (Ptr<Ipv4> ipv4) = 0;
143
  virtual void SetIpv4 (Ptr<Ipv4> ipv4) = 0;
144
145
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) = 0;
143
};
146
};
144
147
145
} //namespace ns3
148
} //namespace ns3
(-)a/src/routing/aodv/aodv-routing-protocol.cc (+7 lines)
 Lines 246-251    Link Here 
246
}
246
}
247
247
248
void
248
void
249
RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream)
250
{
251
  *stream->GetStream () << "Node: " << m_ipv4->GetObject<Node> ()->GetId () << " Time: " << Simulator::Now().GetSeconds () << "s ";
252
  m_routingTable.Print (stream);
253
}
254
255
void
249
RoutingProtocol::Start ()
256
RoutingProtocol::Start ()
250
{
257
{
251
  NS_LOG_FUNCTION (this);
258
  NS_LOG_FUNCTION (this);
(-)a/src/routing/aodv/aodv-routing-protocol.h (+1 lines)
 Lines 70-75    Link Here 
70
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
70
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
71
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
71
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
72
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
72
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
73
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
73
  //\}
74
  //\}
74
  
75
  
75
  ///\name Handle protocol parameters
76
  ///\name Handle protocol parameters
(-)a/src/routing/aodv/aodv-rtable.cc (-10 / +11 lines)
 Lines 155-183    Link Here 
155
}
155
}
156
156
157
void
157
void
158
RoutingTableEntry::Print (std::ostream & os) const
158
RoutingTableEntry::Print (Ptr<OutputStreamWrapper> stream) const
159
{
159
{
160
  os << m_ipv4Route->GetDestination () << "\t" << m_ipv4Route->GetGateway ()
160
  std::ostream* os = stream->GetStream();
161
  *os << m_ipv4Route->GetDestination () << "\t" << m_ipv4Route->GetGateway ()
161
      << "\t" << m_iface.GetLocal () << "\t";
162
      << "\t" << m_iface.GetLocal () << "\t";
162
  switch (m_flag)
163
  switch (m_flag)
163
    {
164
    {
164
    case VALID:
165
    case VALID:
165
      {
166
      {
166
        os << "UP";
167
        *os << "UP";
167
        break;
168
        break;
168
      }
169
      }
169
    case INVALID:
170
    case INVALID:
170
      {
171
      {
171
        os << "DOWN";
172
        *os << "DOWN";
172
        break;
173
        break;
173
      }
174
      }
174
    case IN_SEARCH:
175
    case IN_SEARCH:
175
      {
176
      {
176
        os << "IN_SEARCH";
177
        *os << "IN_SEARCH";
177
        break;
178
        break;
178
      }
179
      }
179
    }
180
    }
180
  os << "\t" << (m_lifeTime - Simulator::Now ()).GetSeconds () << "\t"
181
  *os << "\t" << (m_lifeTime - Simulator::Now ()).GetSeconds () << "\t"
181
      << m_hops << "\n";
182
      << m_hops << "\n";
182
}
183
}
183
184
 Lines 397-413    Link Here 
397
}
398
}
398
399
399
void
400
void
400
RoutingTable::Print (std::ostream &os)
401
RoutingTable::Print (Ptr<OutputStreamWrapper> stream)
401
{
402
{
402
  Purge ();
403
  Purge ();
403
  os << "\nAODV Routing table\n"
404
  *stream->GetStream () << "\nAODV Routing table\n"
404
      << "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n";
405
      << "Destination\tGateway\t\tInterface\tFlag\tExpire\tHops\n";
405
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
406
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
406
      m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i)
407
      m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i)
407
    {
408
    {
408
      i->second.Print (os);
409
      i->second.Print (stream);
409
    }
410
    }
410
  os << "\n";
411
  *stream->GetStream () << "\n";
411
}
412
}
412
413
413
}
414
}
(-)a/src/routing/aodv/aodv-rtable.h (-2 / +3 lines)
 Lines 36-41    Link Here 
36
#include "ns3/ipv4-route.h"
36
#include "ns3/ipv4-route.h"
37
#include "ns3/timer.h"
37
#include "ns3/timer.h"
38
#include "ns3/net-device.h"
38
#include "ns3/net-device.h"
39
#include "ns3/output-stream-wrapper.h"
39
40
40
namespace ns3 {
41
namespace ns3 {
41
namespace aodv {
42
namespace aodv {
 Lines 140-146    Link Here 
140
  {
141
  {
141
    return (m_ipv4Route->GetDestination () == dst);
142
    return (m_ipv4Route->GetDestination () == dst);
142
  }
143
  }
143
  void Print(std::ostream & os) const;
144
  void Print(Ptr<OutputStreamWrapper> stream) const;
144
145
145
private:
146
private:
146
  /// Valid Destination Sequence Number flag
147
  /// Valid Destination Sequence Number flag
 Lines 242-248    Link Here 
242
   */
243
   */
243
  bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
244
  bool MarkLinkAsUnidirectional(Ipv4Address neighbor, Time blacklistTimeout);
244
  /// Print routing table
245
  /// Print routing table
245
  void Print(std::ostream &os);
246
  void Print(Ptr<OutputStreamWrapper> stream);
246
247
247
private:
248
private:
248
  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
249
  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
(-)a/src/routing/global-routing/ipv4-global-routing.cc (+6 lines)
 Lines 382-387    Link Here 
382
  Ipv4RoutingProtocol::DoDispose ();
382
  Ipv4RoutingProtocol::DoDispose ();
383
}
383
}
384
384
385
void
386
Ipv4GlobalRouting::PrintRoutingTable(Ptr<OutputStreamWrapper> stream)
387
{
388
 //use this method to print the routing tables to output.
389
}
390
385
Ptr<Ipv4Route>
391
Ptr<Ipv4Route>
386
Ipv4GlobalRouting::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr)
392
Ipv4GlobalRouting::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr)
387
{      
393
{      
(-)a/src/routing/global-routing/ipv4-global-routing.h (+1 lines)
 Lines 92-97    Link Here 
92
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
92
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
93
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
93
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
94
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
94
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
95
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
95
96
96
/**
97
/**
97
 * \brief Add a host route to the global routing table.
98
 * \brief Add a host route to the global routing table.
(-)a/src/routing/list-routing/ipv4-list-routing.cc (+13 lines)
 Lines 69-74    Link Here 
69
}
69
}
70
70
71
void
71
void
72
Ipv4ListRouting::PrintRoutingTable (Ptr<OutputStreamWrapper> stream)
73
{
74
  for (Ipv4RoutingProtocolList::const_iterator i = m_routingProtocols.begin ();
75
      i != m_routingProtocols.end (); i++)
76
  {
77
    *stream->GetStream () << "Printing for protocol " << (*i).second->GetInstanceTypeId () << " with priority " << (*i).first;
78
    (*i).second->PrintRoutingTable (stream);
79
  }
80
}
81
82
void
72
Ipv4ListRouting::DoStart (void)
83
Ipv4ListRouting::DoStart (void)
73
{
84
{
74
  for (Ipv4RoutingProtocolList::iterator rprotoIter = m_routingProtocols.begin ();
85
  for (Ipv4RoutingProtocolList::iterator rprotoIter = m_routingProtocols.begin ();
 Lines 297-302    Link Here 
297
  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
308
  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
298
  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
309
  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
299
  void SetIpv4 (Ptr<Ipv4> ipv4) {}
310
  void SetIpv4 (Ptr<Ipv4> ipv4) {}
311
  void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) {}
300
};
312
};
301
313
302
class Ipv4BRouting : public Ipv4RoutingProtocol {
314
class Ipv4BRouting : public Ipv4RoutingProtocol {
 Lines 310-315    Link Here 
310
  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
322
  void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
311
  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
323
  void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {}
312
  void SetIpv4 (Ptr<Ipv4> ipv4) {}
324
  void SetIpv4 (Ptr<Ipv4> ipv4) {}
325
  void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) {}
313
};
326
};
314
327
315
class Ipv4ListRoutingNegativeTestCase : public TestCase
328
class Ipv4ListRoutingNegativeTestCase : public TestCase
(-)a/src/routing/list-routing/ipv4-list-routing.h (+1 lines)
 Lines 85-90    Link Here 
85
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
85
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
86
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
86
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
87
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
87
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
88
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
88
89
89
protected:
90
protected:
90
  void DoDispose (void);
91
  void DoDispose (void);
(-)a/src/routing/nix-vector-routing/ipv4-nix-vector-routing.cc (+6 lines)
 Lines 657-662    Link Here 
657
  return true;
657
  return true;
658
}
658
}
659
659
660
void
661
Ipv4NixVectorRouting::PrintRoutingTable(Ptr<OutputStreamWrapper> stream)
662
{
663
 //use this method to print the routing tables to output.
664
}
665
660
// virtual functions from Ipv4RoutingProtocol 
666
// virtual functions from Ipv4RoutingProtocol 
661
void
667
void
662
Ipv4NixVectorRouting::NotifyInterfaceUp (uint32_t i)
668
Ipv4NixVectorRouting::NotifyInterfaceUp (uint32_t i)
(-)a/src/routing/nix-vector-routing/ipv4-nix-vector-routing.h (+1 lines)
 Lines 149-154    Link Here 
149
    virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); 
149
    virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address); 
150
    virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); 
150
    virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address); 
151
    virtual void SetIpv4 (Ptr<Ipv4> ipv4); 
151
    virtual void SetIpv4 (Ptr<Ipv4> ipv4); 
152
    virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
152
153
153
154
154
    /* cache stores nix-vectors based on destination ip */
155
    /* cache stores nix-vectors based on destination ip */
(-)a/src/routing/olsr/olsr-routing-protocol.cc (+6 lines)
 Lines 244-249    Link Here 
244
  Ipv4RoutingProtocol::DoDispose ();
244
  Ipv4RoutingProtocol::DoDispose ();
245
}
245
}
246
246
247
void
248
RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream)
249
{
250
  *stream->GetStream () << "Node: " << m_ipv4->GetObject<Node> ()->GetId () << " Time: " << Simulator::Now().GetSeconds () << "s ";
251
}
252
247
void RoutingProtocol::DoStart ()
253
void RoutingProtocol::DoStart ()
248
{
254
{
249
  if (m_mainAddress == Ipv4Address ())
255
  if (m_mainAddress == Ipv4Address ())
(-)a/src/routing/olsr/olsr-routing-protocol.h (+1 lines)
 Lines 184-189    Link Here 
184
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
184
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
185
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
185
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
186
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
186
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
187
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
187
188
188
189
189
  void DoDispose ();
190
  void DoDispose ();
(-)a/src/routing/static-routing/ipv4-static-routing.cc (+6 lines)
 Lines 699-704    Link Here 
699
    }
699
    }
700
}
700
}
701
701
702
void
703
Ipv4StaticRouting::PrintRoutingTable(Ptr<OutputStreamWrapper> stream)
704
{
705
 //use this method to print the routing tables to output.
706
}
707
702
Ipv4Address
708
Ipv4Address
703
Ipv4StaticRouting::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
709
Ipv4StaticRouting::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
704
{
710
{
(-)a/src/routing/static-routing/ipv4-static-routing.h (+1 lines)
 Lines 85-90    Link Here 
85
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
85
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
86
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
86
  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
87
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
87
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
88
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream);
88
89
89
/**
90
/**
90
 * \brief Add a network route to the static routing table.
91
 * \brief Add a network route to the static routing table.

Return to bug 947