blob: 417edba5a9b0c6b036e220964a306b1aeb4188f0 [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 *
Alexander Afanasyeva89bc102013-07-16 10:17:31 -07006 * GNU 3.0 license, See the LICENSE file for more information
Alexander Afanasyevb989b122013-07-10 17:15:46 -07007 *
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
Alexander Afanasyev79206512013-07-27 16:49:12 -070020/**
21 * @brief Namespace encapsulating wire operations
22 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -070023namespace wire {
Alexander Afanasyev79206512013-07-27 16:49:12 -070024
25/**
26 * @brief Namespace for ndnSIM wire format operations
27 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -070028namespace 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 */
74class Interest : public Header
75{
76public:
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
97private:
98 Ptr<ndn::Interest> m_interest;
99};
100
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -0700101/**
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 *
108 * ContentObject ::= Signature
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 Afanasyevfaa01f92013-07-10 18:34:31 -0700135class Data : public Header
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700136{
137public:
138 Data ();
139 Data (Ptr<ndn::ContentObject> data);
140
141 Ptr<ndn::ContentObject>
142 GetData ();
143
144 static Ptr<Packet>
145 ToWire (Ptr<const ndn::ContentObject> data);
146
147 static Ptr<ndn::ContentObject>
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
158private:
159 Ptr<ndn::ContentObject> m_data;
160};
161
162} // ndnSIM
163} // wire
164
165NDN_NAMESPACE_END
166
167#endif // NDN_WIRE_NDNSIM_H