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

(-)a/src/contrib/flow-monitor/ipv4-flow-probe.cc (-5 / +153 lines)
 Lines 25-40    Link Here 
25
#include "ns3/flow-monitor.h"
25
#include "ns3/flow-monitor.h"
26
#include "ns3/log.h"
26
#include "ns3/log.h"
27
#include "ns3/pointer.h"
27
#include "ns3/pointer.h"
28
#include "ns3/config.h"
29
#include "ns3/flow-id-tag.h"
30
#include <sstream>
28
31
29
namespace ns3 {
32
namespace ns3 {
30
33
34
using namespace std;
35
31
NS_LOG_COMPONENT_DEFINE ("Ipv4FlowProbe");
36
NS_LOG_COMPONENT_DEFINE ("Ipv4FlowProbe");
37
38
            //////////////////////////////////////
39
            // FlowProbeTag class implementation //
40
            //////////////////////////////////////
41
42
class FlowProbeTag : public Tag
43
{
44
public:
45
  static TypeId GetTypeId (void);
46
  virtual TypeId GetInstanceTypeId (void) const;
47
  virtual uint32_t GetSerializedSize (void) const;
48
  virtual void Serialize (TagBuffer buf) const;
49
  virtual void Deserialize (TagBuffer buf);
50
  virtual void Print (std::ostream &os) const;
51
  FlowProbeTag ();
52
  FlowProbeTag (uint32_t flowId, uint32_t packetId, uint32_t packetSize);
53
  void SetFlowId (uint32_t flowId);
54
  void SetPacketId (uint32_t packetId);
55
  void SetPacketSize (uint32_t packetSize);
56
  uint32_t GetFlowId (void) const;
57
  uint32_t GetPacketId (void) const;
58
  uint32_t GetPacketSize (void) const;
59
private:
60
  uint32_t m_flowId;
61
  uint32_t m_packetId;
62
  uint32_t m_packetSize;
32
  
63
  
64
};
33
65
34
Ipv4FlowProbe::~Ipv4FlowProbe ()
66
TypeId 
67
FlowProbeTag::GetTypeId (void)
35
{
68
{
69
  static TypeId tid = TypeId ("ns3::FlowProbeTag")
70
    .SetParent<Tag> ()
71
    .AddConstructor<FlowProbeTag> ()
72
    ;
73
  return tid;
36
}
74
}
37
  
75
TypeId 
76
FlowProbeTag::GetInstanceTypeId (void) const
77
{
78
  return GetTypeId ();
79
}
80
uint32_t 
81
FlowProbeTag::GetSerializedSize (void) const
82
{
83
  return 4 + 4 + 4;
84
}
85
void 
86
FlowProbeTag::Serialize (TagBuffer buf) const
87
{
88
  buf.WriteU32 (m_flowId);
89
  buf.WriteU32 (m_packetId);
90
  buf.WriteU32 (m_packetSize);
91
}
92
void 
93
FlowProbeTag::Deserialize (TagBuffer buf)
94
{
95
  m_flowId = buf.ReadU32 ();
96
  m_packetId = buf.ReadU32 ();
97
  m_packetSize = buf.ReadU32 ();
98
}
99
void 
100
FlowProbeTag::Print (std::ostream &os) const
101
{
102
  os << "FlowId=" << m_flowId;
103
  os << "PacketId=" << m_packetId;
104
  os << "PacketSize=" << m_packetSize;
105
}
106
FlowProbeTag::FlowProbeTag ()
107
  : Tag () 
108
{}
109
110
FlowProbeTag::FlowProbeTag (uint32_t flowId, uint32_t packetId, uint32_t packetSize)
111
  : Tag (), m_flowId (flowId), m_packetId (packetId), m_packetSize (packetSize)
112
{}
113
114
void
115
FlowProbeTag::SetFlowId (uint32_t id)
116
{
117
  m_flowId = id;
118
}
119
void
120
FlowProbeTag::SetPacketId (uint32_t id)
121
{
122
  m_packetId = id;
123
}
124
void
125
FlowProbeTag::SetPacketSize (uint32_t size)
126
{
127
  m_packetSize = size;
128
}
129
uint32_t
130
FlowProbeTag::GetFlowId (void) const
131
{
132
  return m_flowId;
133
}  
134
uint32_t
135
FlowProbeTag::GetPacketId (void) const
136
{
137
  return m_packetId;
138
} 
139
uint32_t
140
FlowProbeTag::GetPacketSize (void) const
141
{
142
  return m_packetSize;
143
} 
144
145
            ////////////////////////////////////////
146
            // Ipv4FlowProbe class implementation //
147
            ////////////////////////////////////////
38
148
39
Ipv4FlowProbe::Ipv4FlowProbe (Ptr<FlowMonitor> monitor,
149
Ipv4FlowProbe::Ipv4FlowProbe (Ptr<FlowMonitor> monitor,
40
                              Ptr<Ipv4FlowClassifier> classifier,
150
                              Ptr<Ipv4FlowClassifier> classifier,
 Lines 67-72    Link Here 
67
    {
177
    {
68
      NS_FATAL_ERROR ("trace fail");
178
      NS_FATAL_ERROR ("trace fail");
69
    }
179
    }
180
181
  // code copied from point-to-point-helper.cc
182
  std::ostringstream oss;
183
  oss << "/NodeList/" << node->GetId () << "/DeviceList/*/TxQueue/Drop";
184
  Config::ConnectWithoutContext (oss.str (), MakeCallback (&Ipv4FlowProbe::QueueDropLogger, Ptr<Ipv4FlowProbe> (this)));
70
}
185
}
71
186
72
void
187
void
 Lines 76-86    Link Here 
76
  FlowPacketId packetId;
191
  FlowPacketId packetId;
77
  
192
  
78
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
193
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
79
    {
194
    {      
80
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
195
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
81
      NS_LOG_DEBUG ("ReportFirstTx ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<"); "
196
      NS_LOG_DEBUG ("ReportFirstTx ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<"); "
82
                    << ipHeader << *ipPayload);
197
                    << ipHeader << *ipPayload);
83
      m_flowMonitor->ReportFirstTx (this, flowId, packetId, size);
198
      m_flowMonitor->ReportFirstTx (this, flowId, packetId, size);
199
200
      // tag the packet with the flow id and packet id, so that the packet can be identified even
201
      // when Ipv4Header is not accessible at some non-IPv4 protocol layer
202
      FlowProbeTag fTag (flowId, packetId, size);
203
      ipPayload->AddPacketTag (fTag);
84
    }
204
    }
85
}
205
}
86
206
 Lines 107-112    Link Here 
107
  
227
  
108
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
228
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
109
    {
229
    {
230
      // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger ()
231
      FlowProbeTag fTag;
232
      bool tagFound = ConstCast<Packet> (ipPayload)->RemovePacketTag (fTag);
233
      NS_ASSERT_MSG (tagFound, "FlowProbeTag is missing");
234
110
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
235
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
111
      NS_LOG_DEBUG ("ReportLastRx ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<");");
236
      NS_LOG_DEBUG ("ReportLastRx ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<");");
112
      m_flowMonitor->ReportLastRx (this, flowId, packetId, size);
237
      m_flowMonitor->ReportLastRx (this, flowId, packetId, size);
 Lines 140-148    Link Here 
140
265
141
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
266
  if (m_classifier->Classify (ipHeader, ipPayload, &flowId, &packetId))
142
    {
267
    {
268
      // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger ()
269
      FlowProbeTag fTag;
270
      bool tagFound = ConstCast<Packet> (ipPayload)->RemovePacketTag (fTag);
271
      NS_ASSERT_MSG (tagFound, "FlowProbeTag is missing");
272
143
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
273
      uint32_t size = (ipPayload->GetSize () + ipHeader.GetSerializedSize ());
144
      NS_LOG_DEBUG ("Drop ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<", " << reason
274
      NS_LOG_DEBUG ("Drop ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<", " << reason 
145
                    << ", destIp=" << ipHeader.GetDestination () << "); "
275
                    << ", destIp=" << ipHeader.GetDestination () << "); " 
146
                    << "HDR: " << ipHeader << " PKT: " << *ipPayload);
276
                    << "HDR: " << ipHeader << " PKT: " << *ipPayload);
147
277
148
      DropReason myReason;
278
      DropReason myReason;
 Lines 171-177    Link Here 
171
    }
301
    }
172
}
302
}
173
303
304
void 
305
Ipv4FlowProbe::QueueDropLogger (Ptr<const Packet> ipPayload)
306
{
307
  // remove the tags that are added by Ipv4FlowProbe::SendOutgoingLogger ()
308
  FlowProbeTag fTag;
309
  bool tagFound = ConstCast<Packet> (ipPayload)->RemovePacketTag (fTag);
310
  
311
  if (tagFound)
312
  {
313
    FlowId flowId = fTag.GetFlowId ();
314
    FlowPacketId packetId = fTag.GetPacketId ();
315
    uint32_t size = fTag.GetPacketSize ();
174
316
317
    NS_LOG_DEBUG ("Drop ("<<this<<", "<<flowId<<", "<<packetId<<", "<<size<<", " << DROP_QUEUE 
318
                  << "); ");
319
320
    m_flowMonitor->ReportDrop (this, flowId, packetId, size, DROP_QUEUE);
321
  }
322
}
175
323
176
} // namespace ns3
324
} // namespace ns3
177
325
(-)a/src/contrib/flow-monitor/ipv4-flow-probe.h (-3 / +4 lines)
 Lines 41-47    Link Here 
41
  
41
  
42
public:
42
public:
43
  Ipv4FlowProbe (Ptr<FlowMonitor> monitor, Ptr<Ipv4FlowClassifier> classifier, Ptr<Node> node);
43
  Ipv4FlowProbe (Ptr<FlowMonitor> monitor, Ptr<Ipv4FlowClassifier> classifier, Ptr<Node> node);
44
  virtual ~Ipv4FlowProbe ();
44
  //virtual ~Ipv4FlowProbe ();
45
45
46
  /// \brief enumeration of possible reasons why a packet may be dropped
46
  /// \brief enumeration of possible reasons why a packet may be dropped
47
  enum DropReason 
47
  enum DropReason 
 Lines 52-59    Link Here 
52
      DROP_TTL_EXPIRE,      
52
      DROP_TTL_EXPIRE,      
53
      /// Packet dropped due to invalid checksum in the IPv4 header
53
      /// Packet dropped due to invalid checksum in the IPv4 header
54
      DROP_BAD_CHECKSUM,
54
      DROP_BAD_CHECKSUM,
55
55
      /// Packet dropped due to queue overflow
56
      // DROP_QUEUE, // TODO: this is not easy to do
56
      DROP_QUEUE, // TODO: this is not easy to do
57
      DROP_INVALID_REASON,
57
      DROP_INVALID_REASON,
58
    };
58
    };
59
59
 Lines 64-69    Link Here 
64
  void ForwardUpLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface);
64
  void ForwardUpLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload, uint32_t interface);
65
  void DropLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload,
65
  void DropLogger (const Ipv4Header &ipHeader, Ptr<const Packet> ipPayload,
66
                   Ipv4L3Protocol::DropReason reason, uint32_t ifIndex);
66
                   Ipv4L3Protocol::DropReason reason, uint32_t ifIndex);
67
  void QueueDropLogger (Ptr<const Packet> ipPayload);
67
68
68
  Ptr<Ipv4FlowClassifier> m_classifier;
69
  Ptr<Ipv4FlowClassifier> m_classifier;
69
};
70
};

Return to bug 854