1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2015 Université Pierre et Marie Curie 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 * Author: Matthieu Coudron <matthieu.coudron@lip6.fr> 19 */ 20 #ifndef SLL_HEADER_H 21 #define SLL_HEADER_H 22 23 #include "ns3/buffer.h" 24 #include "ns3/header.h" 25 #include <stdint.h> 26 27 namespace ns3 { 28 29 /** 30 * \ingroup packet 31 * 32 * \brief Protocol header serialization and deserialization. 33 * 34 * Libpcap sometimes add an additional header to provide information that would be 35 * lost otherwise due to the link-layer/capture mechanism, for instance when capturing from 36 * "nlmon" device on linux 37 * 38 * \see http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html 39 * \see https://wiki.wireshark.org/SLL 40 * 41 \verbatim 42 +---------------------------+ 43 | Packet type | 44 | (2 Octets) | 45 +---------------------------+ 46 | ARPHRD_ type | 47 | (2 Octets) | 48 +---------------------------+ 49 | Link-layer address length | 50 | (2 Octets) | 51 +---------------------------+ 52 | Link-layer address | 53 | (8 Octets) | 54 +---------------------------+ 55 | Protocol type | 56 | (2 Octets) | 57 +---------------------------+ 58 | Payload | 59 . . 60 . . 61 . . 62 \endverbatim 63 */ 64 class SllHeader : public Header 65 { 66 public: 67 68 /** 69 * Type of the packet. 70 */ 71 enum PacketType 72 { 73 UNICAST_FROM_PEER_TO_ME = 0, /**< the packet was specifically sent to us by somebody else */ 74 BROADCAST_BY_PEER = 1, /**< packet was broadcast by somebody else */ 75 MULTICAST_BY_PEER = 2, /**< packet was multicast, but not broadcast, by somebody else */ 76 INTERCEPTED_PACKET = 3, /**< packet was sent to somebody else by somebody else **/ 77 SENT_BY_US /**< the packet was sent by us */ 78 }; 79 80 /** 81 * \brief Get the type ID. 82 * \return the object TypeId 83 */ 84 static TypeId GetTypeId (void); 85 86 SllHeader (); 87 virtual ~SllHeader (); 88 89 /** 90 * \return ARP header type field in network byte order 91 * The ARPHRD_ type field is in network byte order; it contains a Linux ARPHRD_ value for the link-layer device type. 92 */ 93 uint16_t GetArpType () const; 94 95 /** 96 * \param arphdType ARP protocol hardware identifier 97 */ 98 void SetArpType (uint16_t arphdType); 99 100 /** 101 * \return Packet type 102 */ 103 enum PacketType GetPacketType () const; 104 105 /** 106 * \param type Depends on source and address of the packet 107 */ 108 void SetPacketType (PacketType type); 109 110 // Inherited from ObjectBase 111 virtual TypeId GetInstanceTypeId (void) const; 112 // Inherited from Header 113 virtual uint32_t GetSerializedSize (void) const; 114 virtual void Serialize (Buffer::Iterator start) const; 115 virtual uint32_t Deserialize (Buffer::Iterator start); 116 virtual void Print (std::ostream &os) const; 117 118 protected: 119 // declared in packet order 120 PacketType m_packetType; /**< Packet type */ 121 uint16_t m_arphdType; /**< ARP protocol hardware identifier */ 122 uint16_t m_addressLength; /**< Address length */ 123 uint64_t m_address; /**< Address */ 124 uint16_t m_protocolType; /**< protocol type */ 125 }; 126 127 } // namespace ns3 128 129 #endif /* SLL_HEADER_H */ 130