blob: 5e50a32dcfdb5cae84ed753e03dd85fb284a6bc8 [file] [log] [blame]
Alexander Afanasyevb989b122013-07-10 17:15:46 -07001/** -*- 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 *
6 * BSD license, See the doc/LICENSE file for more information
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 Afanasyev1043c702013-07-15 16:21:09 -070014#include "ns3/ndn-common.h"
Alexander Afanasyevb989b122013-07-10 17:15:46 -070015#include "ns3/ndn-interest.h"
16#include "ns3/ndn-content-object.h"
17
18NDN_NAMESPACE_BEGIN
19
20namespace wire {
21namespace 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 */
67class Interest : public Header
68{
69public:
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
90private:
91 Ptr<ndn::Interest> m_interest;
92};
93
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070094/**
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 Afanasyevfaa01f92013-07-10 18:34:31 -0700128class Data : public Header
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700129{
130public:
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
151private:
152 Ptr<ndn::ContentObject> m_data;
153};
154
155} // ndnSIM
156} // wire
157
158NDN_NAMESPACE_END
159
160#endif // NDN_WIRE_NDNSIM_H