blob: 38420e94a35beba14f114da7a1a5c0d6f352712a [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"
Alexander Afanasyev6eba36f2013-08-07 17:42:54 -070019#include "ns3/ndn-data.h"
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070020
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>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070041 FromData (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070042
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070043 static Ptr<Data>
Alexander Afanasyev7b923f32013-07-16 13:23:04 -070044 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
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070055 FromDataStr (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT);
Alexander Afanasyev76b11572013-07-16 21:49:50 -070056
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070057 static Ptr<Data>
Alexander Afanasyev76b11572013-07-16 21:49:50 -070058 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