blob: 768ccea99e1364c633d347e25cbf411c49702a66 [file] [log] [blame]
Alexander Afanasyev7b923f32013-07-16 13:23:04 -07001/** -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev76b11572013-07-16 21:49:50 -07002/*
Alexander Afanasyev7b923f32013-07-16 13:23:04 -07003 * Copyright (c) 2013, Regents of the University of California
4 * Alexander Afanasyev
Alexander Afanasyev76b11572013-07-16 21:49:50 -07005 *
Alexander Afanasyev7b923f32013-07-16 13:23:04 -07006 * GNU 3.0 license, See the LICENSE file for more information
Alexander Afanasyev76b11572013-07-16 21:49:50 -07007 *
Alexander Afanasyev7b923f32013-07-16 13:23:04 -07008 * 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-content-object.h"
20
21NDN_NAMESPACE_BEGIN
22
23struct Wire
24{
25 enum
26 {
27 WIRE_FORMAT_DEFAULT = -2,
28 WIRE_FORMAT_AUTODETECT = -1,
Alexander Afanasyev76b11572013-07-16 21:49:50 -070029
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070030 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 ContentObject> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
42
43 static Ptr<ContentObject>
44 ToData (Ptr<Packet> packet, int8_t type = WIRE_FORMAT_AUTODETECT);
45
Alexander Afanasyev76b11572013-07-16 21:49:50 -070046
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 ContentObject> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
56
57 static Ptr<ContentObject>
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
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070066 /**
67 * @brief Convert name to wire format
68 */
Alexander Afanasyev76b11572013-07-16 21:49:50 -070069 static std::string
70 FromName (Ptr<const Name> name, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070071
72 /**
73 * @brief Convert name from wire format
74 */
75 static Ptr<Name>
Alexander Afanasyev76b11572013-07-16 21:49:50 -070076 ToName (const std::string &wire, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070077};
78
Alexander Afanasyev76b11572013-07-16 21:49:50 -070079inline std::string
80PacketToBuffer (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
89inline Ptr<Packet>
90BufferToPacket (const std::string &buffer)
91{
92 return Create<Packet> (reinterpret_cast<const uint8_t*> (&buffer[0]), buffer.size ());
93}
94
95
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070096NDN_NAMESPACE_END
97
98#endif // NDN_WIRE_H