NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-wire.h
1 
2 /*
3  * Copyright (c) 2013, Regents of the University of California
4  * Alexander Afanasyev
5  *
6  * GNU 3.0 license, See the LICENSE file for more information
7  *
8  * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9  */
10 
11 #ifndef NDN_WIRE_H
12 #define NDN_WIRE_H
13 
14 #include "ns3/buffer.h"
15 
16 #include "ns3/ndn-common.h"
17 #include "ns3/ndn-name.h"
18 #include "ns3/ndn-interest.h"
19 #include "ns3/ndn-data.h"
20 
21 NDN_NAMESPACE_BEGIN
22 
23 struct Wire
24 {
25  enum
26  {
27  WIRE_FORMAT_DEFAULT = -2,
28  WIRE_FORMAT_AUTODETECT = -1,
29 
30  WIRE_FORMAT_NDNSIM = 0,
31  WIRE_FORMAT_CCNB = 1
32  };
33 
34  static Ptr<Packet>
35  FromInterest (Ptr<const Interest> interest, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
36 
37  static Ptr<Interest>
38  ToInterest (Ptr<Packet> packet, int8_t type = WIRE_FORMAT_AUTODETECT);
39 
40  static Ptr<Packet>
41  FromData (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
42 
43  static Ptr<Data>
44  ToData (Ptr<Packet> packet, int8_t type = WIRE_FORMAT_AUTODETECT);
45 
46 
47  // Helper methods for Python
48  static std::string
49  FromInterestStr (Ptr<const Interest> interest, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
50 
51  static Ptr<Interest>
52  ToInterestStr (const std::string &wire, int8_t type = WIRE_FORMAT_AUTODETECT);
53 
54  static std::string
55  FromDataStr (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
56 
57  static Ptr<Data>
58  ToDataStr (const std::string &wire, int8_t type = WIRE_FORMAT_AUTODETECT);
59 
60  // /*
61  // * @brief Get size of buffer to fit wire-formatted name object
62  // */
63  // static uint32_t
64  // FromNameSize (Ptr<const Name> name, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
65 
69  static std::string
70  FromName (Ptr<const Name> name, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
71 
75  static Ptr<Name>
76  ToName (const std::string &wire, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
77 };
78 
79 inline std::string
80 PacketToBuffer (Ptr<const Packet> pkt)
81 {
82  std::string buffer;
83  buffer.resize (pkt->GetSize ());
84  pkt->CopyData (reinterpret_cast<uint8_t*> (&buffer[0]), buffer.size ());
85 
86  return buffer;
87 }
88 
89 inline Ptr<Packet>
90 BufferToPacket (const std::string &buffer)
91 {
92  return Create<Packet> (reinterpret_cast<const uint8_t*> (&buffer[0]), buffer.size ());
93 }
94 
95 
96 NDN_NAMESPACE_END
97 
98 #endif // NDN_WIRE_H