Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 1 | /** -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 6 | * GNU 3.0 license, See the LICENSE file for more information |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 7 | * |
| 8 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #ifndef NDN_WIRE_NDNSIM_H |
| 12 | #define NDN_WIRE_NDNSIM_H |
| 13 | |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 14 | #include "ns3/ndn-common.h" |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 15 | #include "ns3/ndn-interest.h" |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 16 | #include "ns3/ndn-data.h" |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 17 | |
| 18 | NDN_NAMESPACE_BEGIN |
| 19 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 20 | /** |
| 21 | * @brief Namespace encapsulating wire operations |
| 22 | */ |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 23 | namespace wire { |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * @brief Namespace for ndnSIM wire format operations |
| 27 | */ |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 28 | namespace ndnSIM { |
| 29 | |
| 30 | /** |
| 31 | * @brief Routines to serialize/deserialize Interest packet in ndnSIM format |
| 32 | * |
| 33 | * Optimized and simplified formatting of Interest packets |
| 34 | * |
| 35 | * Interest ::= Nonce |
| 36 | * Scope |
| 37 | * InterestLifetime |
| 38 | * Name |
| 39 | * Selectors |
| 40 | * Options |
| 41 | * |
| 42 | * Minumum size of the Interest packet: 1 + 4 + 2 + 1 + (2 + 0) + (2 + 0) + (2 + 0) = 14 |
| 43 | * |
| 44 | * Maximum size of the Interest packet: 1 + 4 + 2 + 1 + (2 + 65535) + (2 + 65535) + (2 + 65535) = 196619 |
| 45 | * |
| 46 | * :: |
| 47 | * |
| 48 | * 0 1 2 3 |
| 49 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 50 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 51 | * | Nonce | |
| 52 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 53 | * | Scope | Reserved | InterestLifetime | |
| 54 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 55 | * | Length | | |
| 56 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 57 | * ~ ~ |
| 58 | * ~ Name ~ |
| 59 | * | | |
| 60 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 61 | * | Length | | |
| 62 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 63 | * ~ ~ |
| 64 | * ~ Selectors ~ |
| 65 | * | | |
| 66 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 67 | * | Length | | |
| 68 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 69 | * ~ ~ |
| 70 | * ~ Options ~ |
| 71 | * | | |
| 72 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 73 | */ |
| 74 | class Interest : public Header |
| 75 | { |
| 76 | public: |
| 77 | Interest (); |
| 78 | Interest (Ptr<ndn::Interest> interest); |
| 79 | |
| 80 | Ptr<ndn::Interest> |
| 81 | GetInterest (); |
| 82 | |
| 83 | static Ptr<Packet> |
| 84 | ToWire (Ptr<const ndn::Interest> interest); |
| 85 | |
| 86 | static Ptr<ndn::Interest> |
| 87 | FromWire (Ptr<Packet> packet); |
| 88 | |
| 89 | // from Header |
| 90 | static TypeId GetTypeId (void); |
| 91 | virtual TypeId GetInstanceTypeId (void) const; |
| 92 | virtual void Print (std::ostream &os) const; |
| 93 | virtual uint32_t GetSerializedSize (void) const; |
| 94 | virtual void Serialize (Buffer::Iterator start) const; |
| 95 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 96 | |
| 97 | private: |
| 98 | Ptr<ndn::Interest> m_interest; |
| 99 | }; |
| 100 | |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @brief Routines to serialize/deserialize Data packet in ndnSIM format |
| 103 | * |
| 104 | * Only few important fields are actually implemented in the simulation |
| 105 | * |
| 106 | * @see http://ndnsim.net/new-packet-formats.html |
| 107 | * |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 108 | * Data ::= Signature |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 109 | * Name |
| 110 | * Content |
| 111 | * |
| 112 | * 0 1 2 3 |
| 113 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 114 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 115 | * | Length | | |
| 116 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |
| 117 | * ~ ~ |
| 118 | * ~ Signature ~ |
| 119 | * | | |
| 120 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 121 | * | Length | | |
| 122 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 123 | * ~ ~ |
| 124 | * ~ Name ~ |
| 125 | * | | |
| 126 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 127 | * | Length | | |
| 128 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 129 | * ~ ~ |
| 130 | * ~ Content ~ |
| 131 | * | | |
| 132 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 133 | * |
| 134 | */ |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 135 | class Data : public Header |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 136 | { |
| 137 | public: |
| 138 | Data (); |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 139 | Data (Ptr<ndn::Data> data); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 141 | Ptr<ndn::Data> |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 142 | GetData (); |
| 143 | |
| 144 | static Ptr<Packet> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 145 | ToWire (Ptr<const ndn::Data> data); |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 147 | static Ptr<ndn::Data> |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 148 | FromWire (Ptr<Packet> packet); |
| 149 | |
| 150 | // from Header |
| 151 | static TypeId GetTypeId (void); |
| 152 | virtual TypeId GetInstanceTypeId (void) const; |
| 153 | virtual void Print (std::ostream &os) const; |
| 154 | virtual uint32_t GetSerializedSize (void) const; |
| 155 | virtual void Serialize (Buffer::Iterator start) const; |
| 156 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 157 | |
| 158 | private: |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 159 | Ptr<ndn::Data> m_data; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | } // ndnSIM |
| 163 | } // wire |
| 164 | |
| 165 | NDN_NAMESPACE_END |
| 166 | |
| 167 | #endif // NDN_WIRE_NDNSIM_H |