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

(-)ba8c1944fb6d (+82 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 INRIA
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
19
#include <iostream>
20
#include "ns3/abort.h"
21
#include "ns3/assert.h"
22
#include "ns3/log.h"
23
#include "ns3/header.h"
24
#include "etherip-header.h"
25
26
NS_LOG_COMPONENT_DEFINE ("EtheripHeader");
27
28
namespace ns3 {
29
30
NS_OBJECT_ENSURE_REGISTERED (EtheripHeader);
31
32
EtheripHeader::EtheripHeader ()
33
{
34
}
35
36
EtheripHeader::~EtheripHeader ()
37
{
38
}
39
40
  TypeId 
41
EtheripHeader::GetTypeId (void)
42
{
43
  static TypeId tid = TypeId ("ns3::EtheripHeader")
44
    .SetParent<Header> ()
45
    .AddConstructor<EtheripHeader> ()
46
    ;
47
  return tid;
48
}
49
50
  TypeId 
51
EtheripHeader::GetInstanceTypeId (void) const
52
{
53
  return GetTypeId ();
54
}
55
56
void 
57
EtheripHeader::Print (std::ostream &os) const
58
{}
59
60
uint32_t
61
EtheripHeader::GetSerializedSize (void) const
62
{
63
  return 2;
64
}
65
66
void
67
EtheripHeader::Serialize (Buffer::Iterator start) const
68
{
69
  uint16_t header = 0x3;
70
  start.WriteHtonU16 (header);
71
}
72
73
uint32_t
74
EtheripHeader::Deserialize (Buffer::Iterator start)
75
{
76
  uint16_t header;
77
  header = start.ReadNtohU16 ();
78
  return GetSerializedSize();
79
}
80
81
82
} // namespace ns3
(-)ba8c1944fb6d (+57 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 INRIA
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 */
18
19
#ifndef ETHERIP_HEADER_H
20
#define ETHERIP_HEADER_H
21
22
#include "ns3/header.h"
23
24
namespace ns3 {
25
26
/**
27
 * \brief Packet header for ETHERIP
28
 *
29
 * See rfc 3378
30
 */
31
class EtheripHeader : public Header 
32
{
33
public:
34
35
  /**
36
   * \brief Construct a ETHERIP header.
37
   */
38
  EtheripHeader ();
39
40
  /**
41
   * \brief Destroy a ETHERIP header.
42
   */
43
  virtual ~EtheripHeader ();
44
45
  static TypeId GetTypeId (void);
46
  virtual TypeId GetInstanceTypeId (void) const;
47
  virtual void Print (std::ostream &os) const;
48
  virtual void Serialize (Buffer::Iterator start) const;
49
  virtual uint32_t Deserialize (Buffer::Iterator start);
50
  virtual uint32_t GetSerializedSize (void) const;
51
52
};
53
54
}; // namespace ns3
55
56
57
#endif /* ETHERIP_HEADER_H */
(-)a/src/devices/point-to-point/point-to-point-net-device.cc (-13 / +34 lines)
 Lines 25-33    Link Here 
25
#include "ns3/trace-source-accessor.h"
25
#include "ns3/trace-source-accessor.h"
26
#include "ns3/uinteger.h"
26
#include "ns3/uinteger.h"
27
#include "ns3/pointer.h"
27
#include "ns3/pointer.h"
28
#include "ns3/ipv4-header.h"
28
#include "point-to-point-net-device.h"
29
#include "point-to-point-net-device.h"
29
#include "point-to-point-channel.h"
30
#include "point-to-point-channel.h"
30
#include "ppp-header.h"
31
#include "ppp-header.h"
32
#include "etherip-header.h"
31
33
32
NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice");
34
NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice");
33
35
 Lines 158-180    Link Here 
158
  NS_LOG_FUNCTION_NOARGS ();
160
  NS_LOG_FUNCTION_NOARGS ();
159
}
161
}
160
162
161
  void 
163
void 
162
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
164
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber, Mac48Address dest)
163
{
165
{
164
  NS_LOG_FUNCTION_NOARGS ();
166
  NS_LOG_FUNCTION_NOARGS ();
167
  EthernetHeader eth;
168
  eth.SetSource (m_address);
169
  eth.SetDestination (dest);
170
  eth.SetLengthType (protocolNumber);
171
  p->AddHeader (eth);
172
  EtheripHeader ethIp;
173
  p->AddHeader (ethIp);
174
  Ipv4Header ipv4;
175
  ipv4.SetSource (Ipv4Address::GetZero ());
176
  ipv4.SetDestination (Ipv4Address::GetZero ());
177
  ipv4.SetPayloadSize (p->GetSize ());
178
  ipv4.SetProtocol (0x61); // ETHERip over IPV4
179
  p->AddHeader (ipv4);
165
  PppHeader ppp;
180
  PppHeader ppp;
166
  ppp.SetProtocol(EtherToPpp(protocolNumber));
181
  ppp.SetProtocol(0x0021); // ipv4
167
  p->AddHeader (ppp);
182
  p->AddHeader (ppp);
168
}
183
}
169
184
170
  bool 
185
EthernetHeader
171
PointToPointNetDevice::ProcessHeader(Ptr<Packet> p, uint16_t& param)
186
PointToPointNetDevice::ProcessHeader(Ptr<Packet> p)
172
{
187
{
173
  NS_LOG_FUNCTION_NOARGS ();
188
  NS_LOG_FUNCTION_NOARGS ();
174
  PppHeader ppp;
189
  PppHeader ppp;
175
  p->RemoveHeader (ppp);
190
  p->RemoveHeader (ppp);
176
  param = PppToEther(ppp.GetProtocol());
191
  Ipv4Header ipv4;
177
  return true;
192
  p->RemoveHeader (ipv4);
193
  EtheripHeader ethIp;
194
  p->RemoveHeader (ethIp);
195
  EthernetHeader eth;
196
  p->RemoveHeader (eth);
197
  return eth;
178
}
198
}
179
199
180
  void 
200
  void 
 Lines 304-311    Link Here 
304
PointToPointNetDevice::Receive (Ptr<Packet> packet)
324
PointToPointNetDevice::Receive (Ptr<Packet> packet)
305
{
325
{
306
  NS_LOG_FUNCTION (this << packet);
326
  NS_LOG_FUNCTION (this << packet);
307
  uint16_t protocol = 0;
308
309
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) 
327
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) 
310
    {
328
    {
311
      // 
329
      // 
 Lines 331-346    Link Here 
331
      // there is no difference in what the promisc callback sees and what the
349
      // there is no difference in what the promisc callback sees and what the
332
      // normal receive callback sees.
350
      // normal receive callback sees.
333
      //
351
      //
334
      ProcessHeader(packet, protocol);
352
      EthernetHeader eth = ProcessHeader(packet);
335
353
336
      if (!m_promiscCallback.IsNull ())
354
      if (!m_promiscCallback.IsNull ())
337
        {
355
        {
338
          m_macPromiscRxTrace (packet);
356
          m_macPromiscRxTrace (packet);
339
          m_promiscCallback (this, packet, protocol, GetRemote (), GetAddress (), NetDevice::PACKET_HOST);
357
          m_promiscCallback (this, packet, eth.GetLengthType (), 
358
                             eth.GetSource (), eth.GetDestination (), 
359
                             NetDevice::PACKET_HOST);
340
        }
360
        }
341
361
342
      m_macRxTrace (packet);
362
      m_macRxTrace (packet);
343
      m_rxCallback (this, packet, protocol, GetRemote ());
363
      m_rxCallback (this, packet, eth.GetLengthType (), eth.GetSource ());
344
    }
364
    }
345
}
365
}
346
366
 Lines 471-476    Link Here 
471
  NS_LOG_FUNCTION_NOARGS ();
491
  NS_LOG_FUNCTION_NOARGS ();
472
  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
492
  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
473
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
493
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
494
  Mac48Address realDest = Mac48Address::ConvertFrom (dest);
474
495
475
  //
496
  //
476
  // If IsLinkUp() is false it means there is no channel to send any packet 
497
  // If IsLinkUp() is false it means there is no channel to send any packet 
 Lines 486-492    Link Here 
486
  // Stick a point to point protocol header on the packet in preparation for
507
  // Stick a point to point protocol header on the packet in preparation for
487
  // shoving it out the door.
508
  // shoving it out the door.
488
  //
509
  //
489
  AddHeader(packet, protocolNumber);
510
  AddHeader(packet, protocolNumber, realDest);
490
511
491
  m_macTxTrace (packet);
512
  m_macTxTrace (packet);
492
513
(-)a/src/devices/point-to-point/point-to-point-net-device.h (-5 / +3 lines)
 Lines 30-35    Link Here 
30
#include "ns3/data-rate.h"
30
#include "ns3/data-rate.h"
31
#include "ns3/ptr.h"
31
#include "ns3/ptr.h"
32
#include "ns3/mac48-address.h"
32
#include "ns3/mac48-address.h"
33
#include "ns3/ethernet-header.h"
33
34
34
namespace ns3 {
35
namespace ns3 {
35
36
 Lines 197-213    Link Here 
197
   * \param p packet
198
   * \param p packet
198
   * \param protocolNumber protocol number
199
   * \param protocolNumber protocol number
199
   */
200
   */
200
  void AddHeader(Ptr<Packet> p, uint16_t protocolNumber);
201
  void AddHeader(Ptr<Packet> p, uint16_t protocolNumber, Mac48Address dest);
201
202
202
  /**
203
  /**
203
   * Removes, from a packet of data, all headers and trailers that
204
   * Removes, from a packet of data, all headers and trailers that
204
   * relate to the protocol implemented by the agent
205
   * relate to the protocol implemented by the agent
205
   * \param p Packet whose headers need to be processed
206
   * \param p Packet whose headers need to be processed
206
   * \param param An integer parameter that can be set by the function
207
   * \return Returns true if the packet should be forwarded up the
208
   * protocol stack.
209
   */
207
   */
210
  bool ProcessHeader(Ptr<Packet> p, uint16_t& param);
208
  EthernetHeader ProcessHeader(Ptr<Packet> p);
211
209
212
  /**
210
  /**
213
   * Start Sending a Packet Down the Wire.
211
   * Start Sending a Packet Down the Wire.
(-)a/src/devices/point-to-point/wscript (+1 lines)
 Lines 9-14    Link Here 
9
        'point-to-point-remote-channel.cc',
9
        'point-to-point-remote-channel.cc',
10
        'point-to-point-test.cc',
10
        'point-to-point-test.cc',
11
        'ppp-header.cc',
11
        'ppp-header.cc',
12
        'etherip-header.cc',
12
        ]
13
        ]
13
    headers = bld.new_task_gen('ns3header')
14
    headers = bld.new_task_gen('ns3header')
14
    headers.module = 'point-to-point'
15
    headers.module = 'point-to-point'

Return to bug 948