Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adds linux cooked header export
When prepended to netlink packets, wireshark can dissect the netlink
protocol; useful to debug DCE netlink messages.
  • Loading branch information
teto committed Jan 18, 2016
commit 4833442de132a8c1e168b3735d913f55e5d1883c
18 changes: 1 addition & 17 deletions src/network/helper/trace-helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "ns3/names.h"
#include "ns3/net-device.h"
#include "ns3/pcap-file-wrapper.h"
#include "ns3/sll-header.h"

#include "trace-helper.h"

Expand Down Expand Up @@ -168,22 +167,7 @@ void
PcapHelper::DefaultSink (Ptr<PcapFileWrapper> file, Ptr<const Packet> p)
{
NS_LOG_FUNCTION (file << p);

// TODO addition matt
if(file->GetDataLinkType() == PcapHelper::DLT_NETLINK)
{
NS_LOG_DEBUG("Prepending a cooked header");

SllHeader sll = SllHeader ();
sll.SetArpType(ARPHRD_NETLINK);
sll.SetPacketType(SllHeader::UNICAST_FROM_PEER_TO_ME);
// p2->AddHeader(sll);
// + sll.GetSerializedSize()
file->Write (Simulator::Now (), sll, p);
}
else {
file->Write (Simulator::Now (), p);
}
file->Write (Simulator::Now (), p);
}

void
Expand Down
41 changes: 20 additions & 21 deletions src/network/model/sll-header.cc → src/network/utils/sll-header.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 Georgia Tech Research Corporation
* Copyright (c) 2015 Université Pierre et Marie Curie
*
* 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
Expand All @@ -21,26 +21,25 @@
#include "ns3/log.h"


namespace ns3
{
namespace ns3 {

NS_LOG_COMPONENT_DEFINE ("SllHeader");

NS_OBJECT_ENSURE_REGISTERED (SllHeader);

SllHeader::SllHeader() :
m_packetType(UNICAST_FROM_PEER_TO_ME),
m_arphdType(0),
m_addressLength(0),
m_address(0),
m_protocolType(0)
SllHeader::SllHeader ()
: m_packetType (UNICAST_FROM_PEER_TO_ME),
m_arphdType (0),
m_addressLength (0),
m_address (0),
m_protocolType (0)
{
NS_LOG_FUNCTION(this);
NS_LOG_FUNCTION (this);
}

SllHeader::~SllHeader()
SllHeader::~SllHeader ()
{
NS_LOG_FUNCTION(this);
NS_LOG_FUNCTION (this);
}


Expand All @@ -62,23 +61,23 @@ SllHeader::GetInstanceTypeId (void) const
}

uint16_t
SllHeader::GetArpType() const
SllHeader::GetArpType () const
{
return m_arphdType;
return m_arphdType;
}

void
SllHeader::SetArpType(uint16_t arphdType)
SllHeader::SetArpType (uint16_t arphdType)
{
NS_LOG_FUNCTION(arphdType);
m_arphdType = arphdType;
NS_LOG_FUNCTION (arphdType);
m_arphdType = arphdType;
}

void
SllHeader::SetPacketType(PacketType type)
SllHeader::SetPacketType (PacketType type)
{
NS_LOG_FUNCTION(type);
m_packetType = type;
NS_LOG_FUNCTION (type);
m_packetType = type;
}

void
Expand Down Expand Up @@ -108,7 +107,7 @@ uint32_t
SllHeader::Deserialize (Buffer::Iterator start)
{
Buffer::Iterator i = start;
m_packetType = static_cast<PacketType>(i.ReadNtohU16 ());
m_packetType = static_cast<PacketType> (i.ReadNtohU16 ());
m_arphdType = i.ReadNtohU16 ();
m_addressLength = i.ReadNtohU16 ();
m_address = i.ReadNtohU64 ();
Expand Down
118 changes: 58 additions & 60 deletions src/network/model/sll-header.h → src/network/utils/sll-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,45 @@
namespace ns3 {

/**
\ingroup packet

\brief Protocol header serialization and deserialization.

Libpcap sometimes add an additional header to provide information that would be
lost otherwise due to the link-layer/capture mechanism, for instance when capturing from
"nlmon" device on linux

\see http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html

\verbatim
+---------------------------+
| Packet type |
| (2 Octets) |
+---------------------------+
| ARPHRD_ type |
| (2 Octets) |
+---------------------------+
| Link-layer address length |
| (2 Octets) |
+---------------------------+
| Link-layer address |
| (8 Octets) |
+---------------------------+
| Protocol type |
| (2 Octets) |
+---------------------------+
| Payload |
. .
. .
. .
\endverbatim
*/
* \ingroup packet
*
* \brief Protocol header serialization and deserialization.
*
* Libpcap sometimes add an additional header to provide information that would be
* lost otherwise due to the link-layer/capture mechanism, for instance when capturing from
* "nlmon" device on linux
*
* \see http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html
* \see https://wiki.wireshark.org/SLL
*
* \verbatim
* +---------------------------+
* | Packet type |
* | (2 Octets) |
* +---------------------------+
* | ARPHRD_ type |
* | (2 Octets) |
* +---------------------------+
* | Link-layer address length |
* | (2 Octets) |
* +---------------------------+
* | Link-layer address |
* | (8 Octets) |
* +---------------------------+
* | Protocol type |
* | (2 Octets) |
* +---------------------------+
* | Payload |
* . .
* . .
* . .
* \endverbatim
*/
class SllHeader : public Header
{
public:

enum PacketType {
enum PacketType
{
UNICAST_FROM_PEER_TO_ME = 0, /**< the packet was specifically sent to us by somebody else */
BROADCAST_BY_PEER = 1, /**< packet was broadcast by somebody else */
MULTICAST_BY_PEER = 2, /**< packet was multicast, but not broadcast, by somebody else */
Expand All @@ -73,36 +74,34 @@ class SllHeader : public Header
};

/**
* \brief Get the type ID.
* \return the object TypeId
*/
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);
TypeId GetInstanceTypeId (void) const;


SllHeader();
SllHeader ();
virtual ~SllHeader ();

/**
* The ARPHRD_ type field is in network byte order; it contains a Linux ARPHRD_ value for the link-layer device type.
*
*/
uint16_t GetArpType() const;
* The ARPHRD_ type field is in network byte order; it contains a Linux ARPHRD_ value for the link-layer device type.
*/
uint16_t GetArpType () const;

/**
\return Packet type
*/
PacketType GetPacketType() const;
* \return Packet type
*/
PacketType GetPacketType () const;

/**
\param arphw ARP protocol hardware identifier
*/
void SetArpType(uint16_t arphdType);
* \param arphw ARP protocol hardware identifier
*/
void SetArpType (uint16_t arphdType);

/**
\param type Depends on source and address of the packet
*/
void SetPacketType(PacketType type);
* \param type Depends on source and address of the packet
*/
void SetPacketType (PacketType type);

//! Inherited
virtual uint32_t GetSerializedSize (void) const;
Expand All @@ -111,14 +110,13 @@ class SllHeader : public Header

virtual void Print (std::ostream &os) const;


protected:
// declared in packet order
PacketType m_packetType;
uint16_t m_arphdType; /**< ARP protocol hardware identifier */
uint16_t m_addressLength;
uint64_t m_address;
uint16_t m_protocolType;
// declared in packet order
PacketType m_packetType;
uint16_t m_arphdType; /**< ARP protocol hardware identifier */
uint16_t m_addressLength;
uint64_t m_address;
uint16_t m_protocolType;
};


Expand Down
4 changes: 2 additions & 2 deletions src/network/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def build(bld):
'model/packet.cc',
'model/packet-metadata.cc',
'model/packet-tag-list.cc',
'model/sll-header.cc',
'model/socket.cc',
'model/socket-factory.cc',
'model/tag.cc',
Expand Down Expand Up @@ -54,6 +53,7 @@ def build(bld):
'utils/red-queue.cc',
'utils/simple-channel.cc',
'utils/simple-net-device.cc',
'utils/sll-header.cc',
'utils/packet-socket-client.cc',
'utils/packet-socket-server.cc',
'utils/packet-data-calculators.cc',
Expand Down Expand Up @@ -100,7 +100,6 @@ def build(bld):
'model/packet.h',
'model/packet-metadata.h',
'model/packet-tag-list.h',
'model/sll-header.h',
'model/socket.h',
'model/socket-factory.h',
'model/tag.h',
Expand Down Expand Up @@ -140,6 +139,7 @@ def build(bld):
'utils/sgi-hashmap.h',
'utils/simple-channel.h',
'utils/simple-net-device.h',
'utils/sll-header.h',
'utils/packet-socket-client.h',
'utils/packet-socket-server.h',
'utils/pcap-test.h',
Expand Down