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