Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 1 | /** -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 5 | * |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 6 | * GNU 3.0 license, See the LICENSE file for more information |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 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" |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 19 | #include "ns3/ndn-data.h" |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 20 | |
| 21 | NDN_NAMESPACE_BEGIN |
| 22 | |
| 23 | struct Wire |
| 24 | { |
| 25 | enum |
| 26 | { |
| 27 | WIRE_FORMAT_DEFAULT = -2, |
| 28 | WIRE_FORMAT_AUTODETECT = -1, |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 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> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 41 | FromData (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT); |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 43 | static Ptr<Data> |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 44 | ToData (Ptr<Packet> packet, int8_t type = WIRE_FORMAT_AUTODETECT); |
| 45 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 55 | FromDataStr (Ptr<const Data> data, int8_t wireFormat = WIRE_FORMAT_DEFAULT); |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 57 | static Ptr<Data> |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 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 Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 66 | /** |
| 67 | * @brief Convert name to wire format |
| 68 | */ |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 69 | static std::string |
| 70 | FromName (Ptr<const Name> name, int8_t wireFormat = WIRE_FORMAT_DEFAULT); |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * @brief Convert name from wire format |
| 74 | */ |
| 75 | static Ptr<Name> |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 76 | ToName (const std::string &wire, int8_t wireFormat = WIRE_FORMAT_DEFAULT); |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 7b923f3 | 2013-07-16 13:23:04 -0700 | [diff] [blame] | 96 | NDN_NAMESPACE_END |
| 97 | |
| 98 | #endif // NDN_WIRE_H |