helper: Extending ndn::HeaderHelper with a call to obtain ndn::Name from the raw packet
As of right now, the call is a very heavy weight operations, as it
copies packet and de-serializes the packet
diff --git a/helper/ndn-header-helper.cc b/helper/ndn-header-helper.cc
index 97d282a..ee22b43 100644
--- a/helper/ndn-header-helper.cc
+++ b/helper/ndn-header-helper.cc
@@ -70,5 +70,51 @@
throw UnknownHeaderException();
}
+Ptr<const Name>
+HeaderHelper::GetName (Ptr<const Packet> p)
+{
+ Ptr<Packet> packet = p->Copy (); // give upper layers a rw copy of the packet
+ try
+ {
+ HeaderHelper::Type type = HeaderHelper::GetNdnHeaderType (p);
+ switch (type)
+ {
+ case HeaderHelper::INTEREST_NDNSIM:
+ {
+ Ptr<InterestHeader> header = Create<InterestHeader> ();
+
+ // Deserialization. Exception may be thrown
+ packet->RemoveHeader (*header);
+ NS_ASSERT_MSG (packet->GetSize () == 0, "Payload of Interests should be zero");
+
+ return header->GetNamePtr ();
+ break;
+ }
+ case HeaderHelper::CONTENT_OBJECT_NDNSIM:
+ {
+ Ptr<ContentObjectHeader> header = Create<ContentObjectHeader> ();
+
+ // Deserialization. Exception may be thrown
+ packet->RemoveHeader (*header);
+ return header->GetNamePtr ();
+ break;
+ }
+ case HeaderHelper::INTEREST_CCNB:
+ case HeaderHelper::CONTENT_OBJECT_CCNB:
+ NS_FATAL_ERROR ("ccnb support is broken in this implementation");
+ break;
+ }
+
+ // exception will be thrown if packet is not recognized
+ }
+ catch (UnknownHeaderException)
+ {
+ return 0;
+ }
+
+ return 0;
+}
+
+
} // namespace ndn
} // namespace ns3
diff --git a/helper/ndn-header-helper.h b/helper/ndn-header-helper.h
index d7ea296..a5a4d2f 100644
--- a/helper/ndn-header-helper.h
+++ b/helper/ndn-header-helper.h
@@ -30,6 +30,8 @@
namespace ndn {
+class Name;
+
/**
* \ingroup ndn-helpers
*
@@ -49,15 +51,15 @@
@brief enum for Ndn packet types
*/
enum Type {INTEREST_CCNB, CONTENT_OBJECT_CCNB,
- INTEREST_NDNSIM, CONTENT_OBJECT_NDNSIM};
+ INTEREST_NDNSIM, CONTENT_OBJECT_NDNSIM};
/**
- * Packet ::= Version
+ * Packet ::= Version
* PacketType
* (Interest | ContentObject)
*
- * 0 1
- * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
+ * 0 1
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Version | PacketType |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -70,12 +72,12 @@
*
* It peeks first 2 bytes of a packet.
*
- * All interests start with
+ * All interests start with
* +-----------------+ +---+---------+-------+
* | 0 0 0 0 0 0 0 1 | | 1 | 1 0 1 0 | 0 1 0 | (0x01 0xD2)
* +-----------------+ +---+---------+-------+
*
- * All content objects start with
+ * All content objects start with
* +-----------------+ +---+---------+-------+
* | 0 0 0 0 0 1 0 0 | | 1 | 0 0 0 0 | 0 1 0 | (0x04 0x82)
* +-----------------+ +---+---------+-------+
@@ -85,9 +87,17 @@
*
* \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
*/
-
+
static Type
GetNdnHeaderType (Ptr<const Packet> packet);
+
+ /**
+ * @brief A heavy-weight operation to get name of the packet
+ *
+ * This function returns name of the packet by deserializing a copy of the packet to a right header
+ */
+ static Ptr<const Name>
+ GetName (Ptr<const Packet> packet);
};
/**