blob: bc711dceb3db9a620851f4ed4e25d25b4a77ed9a [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
14#include "ns3/ndn-common.h"
15#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
94class Data : Header
95{
96public:
97 Data ();
98 Data (Ptr<ndn::ContentObject> data);
99
100 Ptr<ndn::ContentObject>
101 GetData ();
102
103 static Ptr<Packet>
104 ToWire (Ptr<const ndn::ContentObject> data);
105
106 static Ptr<ndn::ContentObject>
107 FromWire (Ptr<Packet> packet);
108
109 // from Header
110 static TypeId GetTypeId (void);
111 virtual TypeId GetInstanceTypeId (void) const;
112 virtual void Print (std::ostream &os) const;
113 virtual uint32_t GetSerializedSize (void) const;
114 virtual void Serialize (Buffer::Iterator start) const;
115 virtual uint32_t Deserialize (Buffer::Iterator start);
116
117private:
118 Ptr<ndn::ContentObject> m_data;
119};
120
121} // ndnSIM
122} // wire
123
124NDN_NAMESPACE_END
125
126#endif // NDN_WIRE_NDNSIM_H