Merge remote-tracking branch 'git.irl/master'
diff --git a/examples/ccnx-test.cc b/examples/ccnx-test.cc
index 4f4205c..626a2f5 100644
--- a/examples/ccnx-test.cc
+++ b/examples/ccnx-test.cc
@@ -14,6 +14,8 @@
int
main (int argc, char *argv[])
{
+ LogComponentEnable ("CcnxTest", LOG_ALL);
+
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
@@ -31,24 +33,27 @@
// Ipv4ListRoutingHelper list;
// list.Add (staticRouting, 1);
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
+ NetDeviceContainer nd = p2p.Install (n);
+
+ NS_LOG_INFO ("Installing NDN stack");
CcnxStackHelper ccnx;
- ccnx.Install (c);
+
+ // ? set up forwarding
+
+ // ccnx.Install (c);
//Add static routing
// InternetStackHelper internet;
// internet.SetRoutingHelper (list); // has effect on the next Install ()
// internet.Install (c);
- // We create the channels first without any IP addressing information
- // NS_LOG_INFO ("Create channels.");
- // PointToPointHelper p2p;
- // p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
- // p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
- // NetDeviceContainer nd = p2p.Install (n);
-
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s from n0 to n4
- NS_LOG_INFO ("Create Applications.");
+ // NS_LOG_INFO ("Create Applications.");
// std::string sendsizeattr = "SendSize";
// //flow2 7-->2
@@ -70,5 +75,5 @@
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
- return 0;
+ return 0;
}
diff --git a/helper/ccnx-coding-helper.cc b/helper/ccnx-coding-helper.cc
deleted file mode 100644
index 6899543..0000000
--- a/helper/ccnx-coding-helper.cc
+++ /dev/null
@@ -1,223 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2011 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author:
- */
-
-#include "ccnx-coding-helper.h"
-
-#include "ns3/name-components.h"
-#include "ns3/ccnx-interest-header.h"
-#include "ns3/ccnx-content-object-header.h"
-
-#include <sstream>
-
-namespace ns3 {
-
-#define CCN_TT_BITS 3
-#define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
-#define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
-#define CCN_TT_HBIT ((unsigned char)(1 << 7))
-
-size_t
-CcnxCodingHelper::AppendBlockHeader (Buffer::Iterator start, size_t val, enum ccn_tt tt)
-{
- unsigned char buf[1+8*((sizeof(val)+6)/7)];
- unsigned char *p = &(buf[sizeof(buf)-1]);
- size_t n = 1;
- p[0] = (CCN_TT_HBIT & ~CCN_CLOSE) |
- ((val & CCN_MAX_TINY) << CCN_TT_BITS) |
- (CCN_TT_MASK & tt);
- val >>= (7-CCN_TT_BITS);
- while (val != 0) {
- (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | CCN_CLOSE;
- n++;
- val >>= 7;
- }
- start.Write (p,n);
- return n;
-}
-
-size_t
-CcnxCodingHelper::AppendNumber (Buffer::Iterator start, uint32_t number)
-{
- std::ostringstream os;
- os << number;
-
- size_t written = 0;
- written += AppendBlockHeader (start, os.str().size(), CCN_UDATA);
- written += os.str().size();
- start.Write (reinterpret_cast<const unsigned char*>(os.str().c_str()), os.str().size());
-
- return written;
-}
-
-
-size_t
-CcnxCodingHelper::CcnxCodingHelper::AppendCloser (Buffer::Iterator start)
-{
- start.WriteU8 (CCN_CLOSE);
- return 1;
-}
-
-size_t
-CcnxCodingHelper::AppendName (Buffer::Iterator start, const Name::Components &name)
-{
- return 0;
-}
-
-size_t
-CcnxCodingHelper::AppendTimestampBlob (Buffer::Iterator start, Time time)
-{
- // the original function implements Markers... thought not sure what are these markers for...
-
- // Determine miminal number of bytes required to store the timestamp
- int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
- intmax_t ts = time.ToInteger (Time::S) >> 4;
- for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
- required_bytes++;
-
- size_t len = AppendBlockHeader(start, required_bytes, CCN_BLOB);
-
- // write part with seconds
- ts = time.ToInteger (Time::S) >> 4;
- for (int i = 0; i < required_bytes - 2; i++)
- start.WriteU8 ( ts >> (8 * (required_bytes - 3 - i)) );
-
- /* arithmetic contortions are to avoid overflowing 31 bits */
- ts = ((time.ToInteger (Time::S) & 15) << 12) + ((time.ToInteger (Time::NS) / 5 * 8 + 195312) / 390625);
- for (int i = required_bytes - 2; i < required_bytes; i++)
- start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) );
-
- return len + required_bytes;
-}
-
-size_t
-CcnxCodingHelper::AppendTaggedBlob (Buffer::Iterator start, ccn_dtag dtag,
- const uint8_t *data, size_t size)
-{
- size_t written = AppendBlockHeader (start, dtag, CCN_DTAG);
- if (size>0)
- {
- written += AppendBlockHeader (start, size, CCN_BLOB);
- start.Write (data, size);
- written += size;
- }
- written += AppendCloser (start);
-
- return written;
-}
-
-
-size_t
-CcnxCodingHelper::Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
-{
- size_t written = 0;
- written += AppendBlockHeader (start, CCN_DTAG_Interest, CCN_DTAG); // <Interest>
-
- written += AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
- written += AppendName (start, interest.GetName()); // <Component>...</Component>...
- written += AppendCloser (start); // </Name>
-
- if (interest.GetMinSuffixComponents() >= 0)
- {
- written += AppendBlockHeader (start, CCN_DTAG_MinSuffixComponents, CCN_DTAG);
- written += AppendNumber (start, interest.GetMinSuffixComponents ());
- written += AppendCloser (start);
- }
- if (interest.GetMaxSuffixComponents() >= 0)
- {
- written += AppendBlockHeader (start, CCN_DTAG_MaxSuffixComponents, CCN_DTAG);
- written += AppendNumber (start, interest.GetMaxSuffixComponents ());
- written += AppendCloser (start);
- }
- if (interest.GetExclude().size() > 0)
- {
- written += AppendBlockHeader (start, CCN_DTAG_Exclude, CCN_DTAG); // <Exclude>
- written += AppendName (start, interest.GetExclude()); // <Component>...</Component>...
- written += AppendCloser (start); // </Exclude>
- }
- if (interest.IsEnabledChildSelector())
- {
- written += AppendBlockHeader (start, CCN_DTAG_ChildSelector, CCN_DTAG);
- written += AppendNumber (start, 1);
- written += AppendCloser (start);
- }
- if (interest.IsEnabledAnswerOriginKind())
- {
- written += AppendBlockHeader (start, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
- written += AppendNumber (start, 1);
- written += AppendCloser (start);
- }
- if (interest.GetScope() >= 0)
- {
- written += AppendBlockHeader (start, CCN_DTAG_Scope, CCN_DTAG);
- written += AppendNumber (start, interest.GetScope ());
- written += AppendCloser (start);
- }
- if (!interest.GetInterestLifetime().IsZero())
- {
- written += AppendBlockHeader (start, CCN_DTAG_InterestLifetime, CCN_DTAG);
- written += AppendTimestampBlob (start, interest.GetInterestLifetime());
- written += AppendCloser (start);
- }
- if (interest.GetNonce()>0)
- {
- uint32_t nonce = interest.GetNonce();
- written += AppendTaggedBlob (start, CCN_DTAG_Nonce,
- reinterpret_cast<const uint8_t*>(&nonce),
- sizeof(nonce));
- }
- written += AppendCloser (start); // </Interest>
-
- return written;
-}
-
-size_t
-CcnxCodingHelper::Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
-{
- size_t written = 0;
- written += AppendBlockHeader (start, CCN_DTAG_ContentObject, CCN_DTAG); // <ContentObject>
-
- // fake signature
- written += AppendBlockHeader (start, CCN_DTAG_Signature, CCN_DTAG); // <Signature>
- // Signature ::= DigestAlgorithm?
- // Witness?
- // SignatureBits
- written += AppendTaggedBlob (start, CCN_DTAG_SignatureBits, 0, 0); // <SignatureBits />
- written += AppendCloser (start); // </Signature>
-
- written += AppendName (start, contentObject.GetName()); // <Name><Component>...</Component>...</Name>
-
- // fake signature
- written += AppendBlockHeader (start, CCN_DTAG_SignedInfo, CCN_DTAG); // <SignedInfo>
- // SignedInfo ::= PublisherPublicKeyDigest
- // Timestamp
- // Type?
- // FreshnessSeconds?
- // FinalBlockID?
- // KeyLocator?
- written += AppendTaggedBlob (start, CCN_DTAG_PublisherPublicKeyDigest, 0, 0); // <PublisherPublicKeyDigest />
- written += AppendCloser (start); // </SignedInfo>
-
- written += AppendBlockHeader (start, CCN_DTAG_Content, CCN_DTAG); // <Content>
-
- // there is no closing tag !!!
- return written;
-}
-
-} // namespace ns3
diff --git a/helper/ccnx-coding-helper.h b/helper/ccnx-coding-helper.h
deleted file mode 100644
index 3cafcbc..0000000
--- a/helper/ccnx-coding-helper.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2011 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
- */
-
-#ifndef _CCNX_CODING_HELPER_H_
-#define _CCNX_CODING_HELPER_H_
-
-#include <sys/types.h>
-#include "ns3/ptr.h"
-#include "ns3/nstime.h"
-#include "ns3/buffer.h"
-
-namespace ns3 {
-
-namespace Name{ class Components; }
-
-class CcnxInterestHeader;
-class CcnxContentObjectHeader;
-
-/**
- * Helper to encode/decode ccnb formatted CCNx message
- *
- */
-class CcnxCodingHelper
-{
-public:
- static size_t
- Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
-
- static size_t
- Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
-
-private:
- /**
- * Type tag for a ccnb start marker.
- *
- * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
- */
- enum ccn_tt {
- CCN_EXT, /**< starts composite extension - numval is subtype */
- CCN_TAG, /**< starts composite - numval is tagnamelen-1 */
- CCN_DTAG, /**< starts composite - numval is tagdict index (enum ccn_dtag) */
- CCN_ATTR, /**< attribute - numval is attrnamelen-1, value follows */
- CCN_DATTR, /**< attribute numval is attrdict index */
- CCN_BLOB, /**< opaque binary data - numval is byte count */
- CCN_UDATA, /**< UTF-8 encoded character data - numval is byte count */
- CCN_NO_TOKEN /**< should not occur in encoding */
- };
-
- /** CCN_CLOSE terminates composites */
- enum {CCN_CLOSE = 0};
-
- // enum ccn_ext_subtype {
- // /* skip smallest values for now */
- // CCN_PROCESSING_INSTRUCTIONS = 16 /* <?name:U value:U?> */
- // };
-
- /**
- * DTAG identifies ccnb-encoded elements.
- *
- * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
- */
- enum ccn_dtag {
- CCN_DTAG_Any = 13,
- CCN_DTAG_Name = 14,
- CCN_DTAG_Component = 15,
- CCN_DTAG_Certificate = 16,
- CCN_DTAG_Collection = 17,
- CCN_DTAG_CompleteName = 18,
- CCN_DTAG_Content = 19,
- CCN_DTAG_SignedInfo = 20,
- CCN_DTAG_ContentDigest = 21,
- CCN_DTAG_ContentHash = 22,
- CCN_DTAG_Count = 24,
- CCN_DTAG_Header = 25,
- CCN_DTAG_Interest = 26, /* 20090915 */
- CCN_DTAG_Key = 27,
- CCN_DTAG_KeyLocator = 28,
- CCN_DTAG_KeyName = 29,
- CCN_DTAG_Length = 30,
- CCN_DTAG_Link = 31,
- CCN_DTAG_LinkAuthenticator = 32,
- CCN_DTAG_NameComponentCount = 33, /* DeprecatedInInterest */
- CCN_DTAG_RootDigest = 36,
- CCN_DTAG_Signature = 37,
- CCN_DTAG_Start = 38,
- CCN_DTAG_Timestamp = 39,
- CCN_DTAG_Type = 40,
- CCN_DTAG_Nonce = 41,
- CCN_DTAG_Scope = 42,
- CCN_DTAG_Exclude = 43,
- CCN_DTAG_Bloom = 44,
- CCN_DTAG_BloomSeed = 45,
- CCN_DTAG_AnswerOriginKind = 47,
- CCN_DTAG_InterestLifetime = 48,
- CCN_DTAG_Witness = 53,
- CCN_DTAG_SignatureBits = 54,
- CCN_DTAG_DigestAlgorithm = 55,
- CCN_DTAG_BlockSize = 56,
- CCN_DTAG_FreshnessSeconds = 58,
- CCN_DTAG_FinalBlockID = 59,
- CCN_DTAG_PublisherPublicKeyDigest = 60,
- CCN_DTAG_PublisherCertificateDigest = 61,
- CCN_DTAG_PublisherIssuerKeyDigest = 62,
- CCN_DTAG_PublisherIssuerCertificateDigest = 63,
- CCN_DTAG_ContentObject = 64, /* 20090915 */
- CCN_DTAG_WrappedKey = 65,
- CCN_DTAG_WrappingKeyIdentifier = 66,
- CCN_DTAG_WrapAlgorithm = 67,
- CCN_DTAG_KeyAlgorithm = 68,
- CCN_DTAG_Label = 69,
- CCN_DTAG_EncryptedKey = 70,
- CCN_DTAG_EncryptedNonceKey = 71,
- CCN_DTAG_WrappingKeyName = 72,
- CCN_DTAG_Action = 73,
- CCN_DTAG_FaceID = 74,
- CCN_DTAG_IPProto = 75,
- CCN_DTAG_Host = 76,
- CCN_DTAG_Port = 77,
- CCN_DTAG_MulticastInterface = 78,
- CCN_DTAG_ForwardingFlags = 79,
- CCN_DTAG_FaceInstance = 80,
- CCN_DTAG_ForwardingEntry = 81,
- CCN_DTAG_MulticastTTL = 82,
- CCN_DTAG_MinSuffixComponents = 83,
- CCN_DTAG_MaxSuffixComponents = 84,
- CCN_DTAG_ChildSelector = 85,
- CCN_DTAG_RepositoryInfo = 86,
- CCN_DTAG_Version = 87,
- CCN_DTAG_RepositoryVersion = 88,
- CCN_DTAG_GlobalPrefix = 89,
- CCN_DTAG_LocalName = 90,
- CCN_DTAG_Policy = 91,
- CCN_DTAG_Namespace = 92,
- CCN_DTAG_GlobalPrefixName = 93,
- CCN_DTAG_PolicyVersion = 94,
- CCN_DTAG_KeyValueSet = 95,
- CCN_DTAG_KeyValuePair = 96,
- CCN_DTAG_IntegerValue = 97,
- CCN_DTAG_DecimalValue = 98,
- CCN_DTAG_StringValue = 99,
- CCN_DTAG_BinaryValue = 100,
- CCN_DTAG_NameValue = 101,
- CCN_DTAG_Entry = 102,
- CCN_DTAG_ACL = 103,
- CCN_DTAG_ParameterizedName = 104,
- CCN_DTAG_Prefix = 105,
- CCN_DTAG_Suffix = 106,
- CCN_DTAG_Root = 107,
- CCN_DTAG_ProfileName = 108,
- CCN_DTAG_Parameters = 109,
- CCN_DTAG_InfoString = 110,
- CCN_DTAG_StatusResponse = 112,
- CCN_DTAG_StatusCode = 113,
- CCN_DTAG_StatusText = 114,
- CCN_DTAG_SequenceNumber = 256,
- CCN_DTAG_CCNProtocolDataUnit = 17702112
- };
-
- /**
- * The decoder state is one of these, possibly with some
- * additional bits set for internal use. A complete parse
- * ends up in state 0 or an error state. Not all possible
- * error states are listed here.
- */
- enum ccn_decoder_state {
- CCN_DSTATE_INITIAL = 0,
- CCN_DSTATE_NEWTOKEN,
- CCN_DSTATE_NUMVAL,
- CCN_DSTATE_UDATA,
- CCN_DSTATE_TAGNAME,
- CCN_DSTATE_ATTRNAME,
- CCN_DSTATE_BLOB,
- /* All error states are negative */
- CCN_DSTATE_ERR_OVERFLOW = -1,
- CCN_DSTATE_ERR_ATTR = -2,
- CCN_DSTATE_ERR_CODING = -3,
- CCN_DSTATE_ERR_NEST = -4,
- CCN_DSTATE_ERR_BUG = -5
- };
-
-
-private:
- static size_t
- AppendBlockHeader (Buffer::Iterator start, size_t value, ccn_tt block_type);
-
- static size_t
- AppendNumber (Buffer::Iterator start, uint32_t number);
-
- static size_t
- AppendCloser (Buffer::Iterator start);
-
- static size_t
- AppendName (Buffer::Iterator start, const Name::Components &name);
-
- /**
- * Append a binary timestamp as a BLOB using the ccn binary
- * Timestamp representation (12-bit fraction).
- *
- * @param start start iterator of the buffer to append to.
- * @param time - Time object
- *
- * @returns written length
- */
- static size_t
- AppendTimestampBlob (Buffer::Iterator start, Time time);
-
- /**
- * Append a tagged BLOB
- *
- * This is a ccnb-encoded element with containing the BLOB as content
- *
- * @param start start iterator of the buffer to append to.
- * @param dtag is the element's dtab
- * @param data points to the binary data
- * @param size is the size of the data, in bytes
- *
- * @returns written length
- */
- static size_t
- AppendTaggedBlob (Buffer::Iterator start, ccn_dtag dtag,
- const uint8_t *data, size_t size);
-
-};
-
-} // namespace ns3
-
-#endif // _CCNX_CODING_HELPER_H_
-
diff --git a/helper/ccnx-decoding-helper.cc b/helper/ccnx-decoding-helper.cc
new file mode 100644
index 0000000..0dabb66
--- /dev/null
+++ b/helper/ccnx-decoding-helper.cc
@@ -0,0 +1,667 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author:
+ */
+
+#include "ccnx-decoding-helper.h"
+
+#include "ns3/ccnx.h"
+#include "ns3/name-components.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+#include <sstream>
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+
+CcnxParser::InterestVisitor CcnxDecodingHelper::m_interestVisitor;
+CcnxParser::ContentObjectVisitor CcnxDecodingHelper::m_contentObjectVisitor;
+
+size_t
+CcnxDecodingHelper::Deserialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
+{
+ Buffer::Iterator i = start;
+ Ptr<CcnxParser::Block> root = CcnxParser::Block::ParseBlock (i);
+ root->accept (m_interestVisitor, interest);
+
+ return i.GetDistanceFrom (start);
+}
+
+size_t
+CcnxDecodingHelper::Deserialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
+{
+ Buffer::Iterator i = start;
+ Ptr<CcnxParser::Block> root = CcnxParser::Block::ParseBlock (i);
+ root->accept (m_contentObjectVisitor, contentObject);
+
+ return i.GetDistanceFrom (start);
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+const uint8_t CCN_TT_BITS = 3;
+const uint8_t CCN_TT_MASK = ((1 << CCN_TT_BITS) - 1);
+const uint8_t CCN_MAX_TINY= ((1 << (7-CCN_TT_BITS)) - 1);
+const uint8_t CCN_TT_HBIT = ((uint8_t)(1 << 7));
+
+namespace CcnxParser {
+
+Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
+{
+ uint32_t value = 0;
+
+ // We will have problems if length field is more than 32 bits. Though it's really impossible
+ uint8_t byte = 0;
+ while (!(byte & CCN_TT_HBIT))
+ {
+ value <<= 8;
+ value += byte;
+ byte = start.ReadU8 ();
+ }
+ value <<= 4;
+ value += ( (byte&(~CCN_TT_HBIT)) >> 3);
+
+ switch (byte & CCN_TT_MASK)
+ {
+ case Ccnx::CCN_BLOB:
+ return Create<Blob> (start, value);
+ case Ccnx::CCN_UDATA:
+ return Create<Udata> (start, value);
+ case Ccnx::CCN_TAG:
+ return Create<Tag> (start, value);
+ case Ccnx::CCN_ATTR:
+ return Create<Attr> (start, value);
+ case Ccnx::CCN_DTAG:
+ return Create<Dtag> (start, value);
+ case Ccnx::CCN_DATTR:
+ return Create<Dattr> (start, value);
+ case Ccnx::CCN_EXT:
+ return Create<Ext> (start, value);
+ default:
+ throw CcnxDecodingException ();
+ }
+}
+
+Blob::Blob (Buffer::Iterator &start, uint32_t length)
+{
+ start.Read (m_blob.Begin (), length);
+}
+
+Udata::Udata (Buffer::Iterator &start, uint32_t length)
+{
+ // Ideally, the code should look like this. Unfortunately, we don't have normal compatible iterators
+ // Buffer::Iterator realStart = start;
+ // start.Next (length); // advancing forward
+ // m_udata.assign (realStart, start/*actually, it is the end*/);
+
+ m_udata.reserve (length+1); //just in case we will need \0 at the end later
+ // this is actually the way Read method is implemented in network/src/buffer.cc
+ for (uint32_t i = 0; i < length; i++)
+ {
+ m_udata.push_back (start.ReadU8 ());
+ }
+}
+
+// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1)
+Tag::Tag (Buffer::Iterator &start, uint32_t length)
+{
+ m_tag.reserve (length+2); // extra byte for potential \0 at the end
+ for (uint32_t i = 0; i < (length+1); i++)
+ {
+ m_tag.push_back (start.ReadU8 ());
+ }
+
+ while (!start.IsEnd () && start.PeekU8 ()!=Ccnx::CCN_CLOSE)
+ {
+ m_nestedBlocks.push_back (Block::ParseBlock (start));
+ }
+ if (start.IsEnd ())
+ throw CcnxDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+}
+
+// length length in octets of UTF-8 encoding of tag name - 1 (minimum tag name length is 1)
+Attr::Attr (Buffer::Iterator &start, uint32_t length)
+{
+ m_attr.reserve (length+2); // extra byte for potential \0 at the end
+ for (uint32_t i = 0; i < (length+1); i++)
+ {
+ m_attr.push_back (start.ReadU8 ());
+ }
+ m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+ if (m_value == 0)
+ throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
+{
+ m_dtag = dtag;
+
+ /**
+ * Hack
+ *
+ * Stop processing after encountering <Content> dtag. Actual
+ * content (including virtual payload) will be stored in Packet
+ * buffer
+ */
+ if (dtag == Ccnx::CCN_DTAG_Content)
+ return; // hack #1. Do not process nesting block for <Content>
+
+ while (!start.IsEnd () && start.PeekU8 ()!=Ccnx::CCN_CLOSE)
+ {
+ m_nestedBlocks.push_back (Block::ParseBlock (start));
+
+ // hack #2. Stop processing nested blocks if last block was <Content>
+ if (m_dtag == Ccnx::CCN_DTAG_ContentObject && // we are in <ContentObject>
+ DynamicCast<Dtag> (m_nestedBlocks.back())!=0 && // last block is DTAG
+ DynamicCast<Dtag> (m_nestedBlocks.back())->m_dtag == Ccnx::CCN_DTAG_Content)
+ {
+ return;
+ }
+ }
+ if (start.IsEnd ())
+ throw CcnxDecodingException ();
+
+ start.ReadU8 (); // read CCN_CLOSE
+}
+
+// dictionary attributes are not used (yet?) in CCNx
+Dattr::Dattr (Buffer::Iterator &start, uint32_t dattr)
+{
+ m_dattr = dattr;
+ m_value = DynamicCast<Udata> (Block::ParseBlock (start));
+ if (m_value == 0)
+ throw CcnxDecodingException (); // "ATTR must be followed by UDATA field"
+}
+
+Ext::Ext (Buffer::Iterator &start, uint32_t extSubtype)
+{
+ m_extSubtype = extSubtype;
+}
+
+void
+DepthFirstVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+}
+
+void
+DepthFirstVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+}
+
+void
+DepthFirstVisitor::visit (Tag &n)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this);
+ }
+}
+
+void
+DepthFirstVisitor::visit (Attr &n)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+DepthFirstVisitor::visit (Dtag &n)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this);
+ }
+}
+
+void
+DepthFirstVisitor::visit (Dattr &n)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+DepthFirstVisitor::visit (Ext &n)
+{
+ // uint64_t n.m_extSubtype;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Blob &n)
+{
+ // Buffer n.m_blob;
+ return n.m_blob;
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Tag &n)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this);
+ }
+ return boost::any();
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Attr &n)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+ return boost::any(
+ std::pair<std::string,std::string> (
+ n.m_attr,
+ boost::any_cast<std::string> (n.m_value->accept (*this))
+ ));
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Dtag &n)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this);
+ }
+ return boost::any();
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Dattr &n)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+ return boost::any(
+ std::pair<uint32_t,std::string> (
+ n.m_dattr,
+ boost::any_cast<std::string> (n.m_value->accept (*this))
+ ));
+}
+
+boost::any
+GJNoArguDepthFirstVisitor::visit (Ext &n)
+{
+ // uint64_t n.m_extSubtype;
+ return n.m_extSubtype;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+void
+GJVoidDepthFirstVisitor::visit (Blob &n, boost::any param)
+{
+ // Buffer n.m_blob;
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Udata &n, boost::any param)
+{
+ // std::string n.m_udata;
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Tag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Attr &n, boost::any param)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Dtag &n, boost::any param)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Dattr &n, boost::any param)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+}
+
+void
+GJVoidDepthFirstVisitor::visit (Ext &n, boost::any param)
+{
+ // uint64_t n.m_extSubtype;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+boost::any
+GJDepthFirstVisitor::visit (Blob &n, boost::any param)
+{
+ // Buffer n.m_blob;
+ return n.m_blob;
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Udata &n, boost::any param)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Tag &n, boost::any param)
+{
+ // std::string n.m_tag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+ return boost::any();
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Attr &n, boost::any param)
+{
+ // std::string n.m_attr;
+ // Ptr<Udata> n.m_value;
+ return boost::any(
+ std::pair<std::string,std::string> (
+ n.m_attr,
+ boost::any_cast<std::string> (n.m_value->accept (*this,param))
+ ));
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Dtag &n, boost::any param)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+ return boost::any();
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Dattr &n, boost::any param)
+{
+ // uint32_t n.m_dattr;
+ // Ptr<Udata> n.m_value;
+ return boost::any(
+ std::pair<uint32_t,std::string> (
+ n.m_dattr,
+ boost::any_cast<std::string> (n.m_value->accept (*this,param))
+ ));
+}
+
+boost::any
+GJDepthFirstVisitor::visit (Ext &n, boost::any param)
+{
+ // uint64_t n.m_extSubtype;
+ return n.m_extSubtype;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+boost::any
+NonNegativeIntegerVisitor::visit (Blob &n) //to throw parsing error
+{
+ // Buffer n.m_blob;
+ throw CcnxDecodingException ();
+}
+
+boost::any
+NonNegativeIntegerVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ std::istringstream is (n.m_udata);
+ int32_t value;
+ is >> value;
+ if (value<0) // value should be non-negative
+ throw CcnxDecodingException ();
+
+ return static_cast<uint32_t> (value);
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+boost::any
+StringVisitor::visit (Blob &n) //to throw parsing error
+{
+ // Buffer n.m_blob;
+ throw CcnxDecodingException ();
+}
+
+boost::any
+StringVisitor::visit (Udata &n)
+{
+ // std::string n.m_udata;
+ return n.m_udata;
+}
+
+//////////////////////////////////////////////////////////////////////
+
+StringVisitor NameComponentsVisitor::m_stringVisitor;
+
+void
+NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be Name::Components&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ Name::Components &components = boost::any_cast<Name::Components&> (param);
+
+ switch (n.m_dtag)
+ {
+ case Ccnx::CCN_DTAG_Component:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ components.Add (
+ boost::any_cast<std::string> ((*n.m_nestedBlocks.begin())->accept(
+ m_stringVisitor
+ )));
+ break;
+ default:
+ // ignore any other components
+ // when parsing Exclude, there could be <Any /> and <Bloom /> tags
+ break;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////
+
+NonNegativeIntegerVisitor InterestVisitor::m_nonNegativeIntegerVisitor;
+NameComponentsVisitor InterestVisitor::m_nameComponentsVisitor;
+
+// We don't really care about any other fields
+void
+InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
+
+ switch (n.m_dtag)
+ {
+ case Ccnx::CCN_DTAG_Interest:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+ break;
+ case Ccnx::CCN_DTAG_Name:
+ {
+ // process name components
+ Ptr<Name::Components> name = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (m_nameComponentsVisitor, *name);
+ }
+ interest.SetName (name);
+ break;
+ }
+ case Ccnx::CCN_DTAG_MinSuffixComponents:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ interest.SetMinSuffixComponents (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedBlocks.begin())->accept(
+ m_nonNegativeIntegerVisitor
+ )));
+ break;
+ case Ccnx::CCN_DTAG_MaxSuffixComponents:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ interest.SetMaxSuffixComponents (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedBlocks.begin())->accept(
+ m_nonNegativeIntegerVisitor
+ )));
+ break;
+ case Ccnx::CCN_DTAG_Exclude:
+ {
+ // process exclude components
+ Ptr<Name::Components> exclude = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (m_nameComponentsVisitor, *exclude);
+ }
+ interest.SetExclude (exclude);
+ break;
+ }
+ case Ccnx::CCN_DTAG_ChildSelector:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+
+ interest.SetChildSelector (
+ 1 == boost::any_cast<uint32_t> (
+ (*n.m_nestedBlocks.begin())->accept(
+ m_nonNegativeIntegerVisitor
+ )));
+ break;
+ case Ccnx::CCN_DTAG_AnswerOriginKind:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ interest.SetAnswerOriginKind (
+ 1 == boost::any_cast<uint32_t> (
+ (*n.m_nestedBlocks.begin())->accept(
+ m_nonNegativeIntegerVisitor
+ )));
+ break;
+ case Ccnx::CCN_DTAG_Scope:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ interest.SetScope (
+ boost::any_cast<uint32_t> (
+ (*n.m_nestedBlocks.begin())->accept(
+ m_nonNegativeIntegerVisitor
+ )));
+ break;
+ case Ccnx::CCN_DTAG_InterestLifetime:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ break;
+ case Ccnx::CCN_DTAG_Nonce:
+ if (n.m_nestedBlocks.size()!=1) // should be exactly one UDATA inside this tag
+ throw CcnxDecodingException ();
+ break;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////
+
+NameComponentsVisitor ContentObjectVisitor::m_nameComponentsVisitor;
+
+// We don't really care about any other fields
+void
+ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/)
+{
+ // uint32_t n.m_dtag;
+ // std::list<Ptr<Block> > n.m_nestedBlocks;
+ CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (param);
+
+ switch (n.m_dtag)
+ {
+ case Ccnx::CCN_DTAG_ContentObject:
+ // process nested blocks
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (*this, param);
+ }
+ break;
+ case Ccnx::CCN_DTAG_Name:
+ {
+ // process name components
+ Ptr<Name::Components> name = Create<Name::Components> ();
+
+ BOOST_FOREACH (Ptr<Block> block, n.m_nestedBlocks)
+ {
+ block->accept (m_nameComponentsVisitor, *name);
+ }
+ contentObject.SetName (name);
+ break;
+ }
+ case Ccnx::CCN_DTAG_Signature: // ignoring
+ break;
+ case Ccnx::CCN_DTAG_SignedInfo: // ignoring
+ break;
+ case Ccnx::CCN_DTAG_Content: // !!! HACK
+ // This hack was necessary for memory optimizations (i.e., content is virtual payload)
+ NS_ASSERT_MSG (n.m_nestedBlocks.size() == 0, "Parser should have stopped just after processing <Content> tag");
+ break;
+ }
+}
+
+} // namespace CcnxParser
+} // namespace ns3
diff --git a/helper/ccnx-decoding-helper.h b/helper/ccnx-decoding-helper.h
new file mode 100644
index 0000000..e89766c
--- /dev/null
+++ b/helper/ccnx-decoding-helper.h
@@ -0,0 +1,332 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author:
+ */
+
+#ifndef _CCNX_DECODING_HELPER_H_
+#define _CCNX_DECODING_HELPER_H_
+
+#include <sys/types.h>
+#include <boost/any.hpp>
+#include <list>
+
+#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+#include "ns3/simple-ref-count.h"
+
+
+namespace ns3 {
+
+namespace Name{ class Components; }
+
+class CcnxInterestHeader;
+class CcnxContentObjectHeader;
+
+namespace CcnxParser {
+class InterestVisitor;
+class ContentObjectVisitor;
+}
+
+/**
+ * Helper to encode/decode ccnb formatted CCNx message
+ *
+ */
+class CcnxDecodingHelper
+{
+public:
+ static size_t
+ Deserialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
+
+ static size_t
+ Deserialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
+
+private:
+ static CcnxParser::InterestVisitor m_interestVisitor;
+ static CcnxParser::ContentObjectVisitor m_contentObjectVisitor;
+};
+
+namespace CcnxParser {
+
+class Block;
+class Blob;
+class Udata;
+class Tag;
+class Attr;
+class Dtag;
+class Dattr;
+class Ext;
+
+class Visitor
+{
+public:
+ virtual void visit (Blob& )=0;
+ virtual void visit (Udata&)=0;
+ virtual void visit (Tag& )=0;
+ virtual void visit (Attr& )=0;
+ virtual void visit (Dtag& )=0;
+ virtual void visit (Dattr&)=0;
+ virtual void visit (Ext& )=0;
+};
+
+class GJVisitor
+{
+public:
+ virtual boost::any visit (Blob&, boost::any)=0;
+ virtual boost::any visit (Udata&, boost::any)=0;
+ virtual boost::any visit (Tag&, boost::any)=0;
+ virtual boost::any visit (Attr&, boost::any)=0;
+ virtual boost::any visit (Dtag&, boost::any)=0;
+ virtual boost::any visit (Dattr&, boost::any)=0;
+ virtual boost::any visit (Ext&, boost::any)=0;
+};
+
+class GJNoArguVisitor
+{
+public:
+ virtual boost::any visit (Blob& )=0;
+ virtual boost::any visit (Udata&)=0;
+ virtual boost::any visit (Tag& )=0;
+ virtual boost::any visit (Attr& )=0;
+ virtual boost::any visit (Dtag& )=0;
+ virtual boost::any visit (Dattr&)=0;
+ virtual boost::any visit (Ext& )=0;
+};
+
+class GJVoidVisitor
+{
+public:
+ virtual void visit (Blob&, boost::any)=0;
+ virtual void visit (Udata&, boost::any)=0;
+ virtual void visit (Tag&, boost::any)=0;
+ virtual void visit (Attr&, boost::any)=0;
+ virtual void visit (Dtag&, boost::any)=0;
+ virtual void visit (Dattr&, boost::any)=0;
+ virtual void visit (Ext&, boost::any)=0;
+};
+
+class Block : public SimpleRefCount<Block>
+{
+public:
+ /**
+ * Parsing block header and creating an appropriate object
+ */
+ static Ptr<Block>
+ ParseBlock (Buffer::Iterator &start);
+
+ virtual void accept( Visitor &v ) =0;
+ virtual void accept (GJVoidVisitor &v, boost::any param) =0;
+ virtual boost::any accept( GJNoArguVisitor &v ) =0;
+ virtual boost::any accept( GJVisitor &v, boost::any param ) =0;
+};
+
+class Blob : public Block
+{
+public:
+ Blob (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ Buffer m_blob;
+};
+
+class Udata : public Block
+{
+public:
+ Udata (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_udata;
+};
+
+class Tag : public Block
+{
+public:
+ Tag (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_tag;
+ std::list<Ptr<Block> > m_nestedBlocks;
+};
+
+class Attr : public Block
+{
+public:
+ Attr (Buffer::Iterator &start, uint32_t length);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ std::string m_attr;
+ Ptr<Udata> m_value;
+};
+
+class Dtag : public Block
+{
+public:
+ Dtag (Buffer::Iterator &start, uint32_t dtag);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint32_t m_dtag;
+ std::list<Ptr<Block> > m_nestedBlocks;
+};
+
+class Dattr : public Block
+{
+public:
+ Dattr (Buffer::Iterator &start, uint32_t dattr);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint32_t m_dattr;
+ Ptr<Udata> m_value;
+};
+
+class Ext : public Block
+{
+public:
+ Ext (Buffer::Iterator &start, uint32_t extSubtype);
+
+ virtual void accept( Visitor &v ) { v.visit( *this ); }
+ virtual void accept( GJVoidVisitor &v, boost::any param ) { v.visit( *this, param ); }
+ virtual boost::any accept( GJNoArguVisitor &v ) { return v.visit( *this ); }
+ virtual boost::any accept( GJVisitor &v, boost::any param ) { return v.visit( *this, param ); }
+
+ uint64_t m_extSubtype;
+};
+
+class DepthFirstVisitor : public Visitor
+{
+public:
+ virtual void visit (Blob& );
+ virtual void visit (Udata&);
+ virtual void visit (Tag& );
+ virtual void visit (Attr& );
+ virtual void visit (Dtag& );
+ virtual void visit (Dattr&);
+ virtual void visit (Ext& );
+};
+
+class GJDepthFirstVisitor : public GJVisitor
+{
+public:
+ virtual boost::any visit (Blob&, boost::any);
+ virtual boost::any visit (Udata&, boost::any);
+ virtual boost::any visit (Tag&, boost::any);
+ virtual boost::any visit (Attr&, boost::any);
+ virtual boost::any visit (Dtag&, boost::any);
+ virtual boost::any visit (Dattr&, boost::any);
+ virtual boost::any visit (Ext&, boost::any);
+};
+
+class GJNoArguDepthFirstVisitor : public GJNoArguVisitor
+{
+public:
+ virtual boost::any visit (Blob& );
+ virtual boost::any visit (Udata&);
+ virtual boost::any visit (Tag& );
+ virtual boost::any visit (Attr& );
+ virtual boost::any visit (Dtag& );
+ virtual boost::any visit (Dattr&);
+ virtual boost::any visit (Ext& );
+};
+
+class GJVoidDepthFirstVisitor : public GJVoidVisitor
+{
+public:
+ virtual void visit (Blob&, boost::any);
+ virtual void visit (Udata&, boost::any);
+ virtual void visit (Tag&, boost::any);
+ virtual void visit (Attr&, boost::any);
+ virtual void visit (Dtag&, boost::any);
+ virtual void visit (Dattr&, boost::any);
+ virtual void visit (Ext&, boost::any);
+};
+
+// class NameComponentsVisitor : public
+
+class NonNegativeIntegerVisitor : public GJNoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n); //to throw parsing error
+ virtual boost::any visit (Udata &n);
+};
+
+class StringVisitor : public GJNoArguDepthFirstVisitor
+{
+public:
+ virtual boost::any visit (Blob &n); //to throw parsing error
+ virtual boost::any visit (Udata &n);
+};
+
+class NameComponentsVisitor : public GJVoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be Name::Components*/);
+private:
+ static StringVisitor m_stringVisitor;
+};
+
+class InterestVisitor : public GJVoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/);
+
+private:
+ static NonNegativeIntegerVisitor m_nonNegativeIntegerVisitor;
+ static NameComponentsVisitor m_nameComponentsVisitor;
+};
+
+class ContentObjectVisitor : public GJVoidDepthFirstVisitor
+{
+public:
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/);
+
+private:
+ static NameComponentsVisitor m_nameComponentsVisitor;
+};
+
+
+class CcnxDecodingException {};
+
+} // namespace CcnxParser
+
+} // namespace ns3
+
+#endif // _CCNX_DECODING_HELPER_H_
+
diff --git a/helper/ccnx-encoding-helper.cc b/helper/ccnx-encoding-helper.cc
new file mode 100644
index 0000000..21ca9ae
--- /dev/null
+++ b/helper/ccnx-encoding-helper.cc
@@ -0,0 +1,232 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author:
+ */
+
+#include "ccnx-encoding-helper.h"
+
+#include "ns3/name-components.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+
+#include <sstream>
+#include <boost/foreach.hpp>
+
+namespace ns3 {
+
+#define CCN_TT_BITS 3
+#define CCN_TT_MASK ((1 << CCN_TT_BITS) - 1)
+#define CCN_MAX_TINY ((1 << (7-CCN_TT_BITS)) - 1)
+#define CCN_TT_HBIT ((unsigned char)(1 << 7))
+
+size_t
+CcnxEncodingHelper::AppendBlockHeader (Buffer::Iterator start, size_t val, Ccnx::ccn_tt tt)
+{
+ unsigned char buf[1+8*((sizeof(val)+6)/7)];
+ unsigned char *p = &(buf[sizeof(buf)-1]);
+ size_t n = 1;
+ p[0] = (CCN_TT_HBIT & ~Ccnx::CCN_CLOSE) |
+ ((val & CCN_MAX_TINY) << CCN_TT_BITS) |
+ (CCN_TT_MASK & tt);
+ val >>= (7-CCN_TT_BITS);
+ while (val != 0) {
+ (--p)[0] = (((unsigned char)val) & ~CCN_TT_HBIT) | Ccnx::CCN_CLOSE;
+ n++;
+ val >>= 7;
+ }
+ start.Write (p,n);
+ return n;
+}
+
+size_t
+CcnxEncodingHelper::AppendNumber (Buffer::Iterator start, uint32_t number)
+{
+ std::ostringstream os;
+ os << number;
+
+ size_t written = 0;
+ written += AppendBlockHeader (start, os.str().size(), Ccnx::CCN_UDATA);
+ written += os.str().size();
+ start.Write (reinterpret_cast<const unsigned char*>(os.str().c_str()), os.str().size());
+
+ return written;
+}
+
+
+size_t
+CcnxEncodingHelper::CcnxEncodingHelper::AppendCloser (Buffer::Iterator start)
+{
+ start.WriteU8 (Ccnx::CCN_CLOSE);
+ return 1;
+}
+
+size_t
+CcnxEncodingHelper::AppendNameComponents (Buffer::Iterator start, const Name::Components &name)
+{
+ size_t written = 0;
+ BOOST_FOREACH (const std::string &component, name.GetComponents())
+ {
+ written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_Component,
+ reinterpret_cast<const uint8_t*>(component.c_str()), component.size());
+ }
+ return written;
+}
+
+size_t
+CcnxEncodingHelper::AppendTimestampBlob (Buffer::Iterator start, Time time)
+{
+ // the original function implements Markers... thought not sure what are these markers for...
+
+ // Determine miminal number of bytes required to store the timestamp
+ int required_bytes = 2; // 12 bits for fractions of a second, 4 bits left for seconds. Sometimes it is enough
+ intmax_t ts = time.ToInteger (Time::S) >> 4;
+ for (; required_bytes < 7 && ts != 0; ts >>= 8) // not more than 6 bytes?
+ required_bytes++;
+
+ size_t len = AppendBlockHeader(start, required_bytes, Ccnx::CCN_BLOB);
+
+ // write part with seconds
+ ts = time.ToInteger (Time::S) >> 4;
+ for (int i = 0; i < required_bytes - 2; i++)
+ start.WriteU8 ( ts >> (8 * (required_bytes - 3 - i)) );
+
+ /* arithmetic contortions are to avoid overflowing 31 bits */
+ ts = ((time.ToInteger (Time::S) & 15) << 12) + ((time.ToInteger (Time::NS) / 5 * 8 + 195312) / 390625);
+ for (int i = required_bytes - 2; i < required_bytes; i++)
+ start.WriteU8 ( ts >> (8 * (required_bytes - 1 - i)) );
+
+ return len + required_bytes;
+}
+
+size_t
+CcnxEncodingHelper::AppendTaggedBlob (Buffer::Iterator start, Ccnx::ccn_dtag dtag,
+ const uint8_t *data, size_t size)
+{
+ size_t written = AppendBlockHeader (start, dtag, Ccnx::CCN_DTAG);
+ if (size>0)
+ {
+ written += AppendBlockHeader (start, size, Ccnx::CCN_BLOB);
+ start.Write (data, size);
+ written += size;
+ }
+ written += AppendCloser (start);
+
+ return written;
+}
+
+
+size_t
+CcnxEncodingHelper::Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest)
+{
+ size_t written = 0;
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Interest, Ccnx::CCN_DTAG); // <Interest>
+
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Name, Ccnx::CCN_DTAG); // <Name>
+ written += AppendNameComponents (start, interest.GetName()); // <Component>...</Component>...
+ written += AppendCloser (start); // </Name>
+
+ if (interest.GetMinSuffixComponents() >= 0)
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_MinSuffixComponents, Ccnx::CCN_DTAG);
+ written += AppendNumber (start, interest.GetMinSuffixComponents ());
+ written += AppendCloser (start);
+ }
+ if (interest.GetMaxSuffixComponents() >= 0)
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_MaxSuffixComponents, Ccnx::CCN_DTAG);
+ written += AppendNumber (start, interest.GetMaxSuffixComponents ());
+ written += AppendCloser (start);
+ }
+ if (interest.GetExclude().size() > 0)
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Exclude, Ccnx::CCN_DTAG); // <Exclude>
+ written += AppendNameComponents (start, interest.GetExclude()); // <Component>...</Component>...
+ written += AppendCloser (start); // </Exclude>
+ }
+ if (interest.IsEnabledChildSelector())
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_ChildSelector, Ccnx::CCN_DTAG);
+ written += AppendNumber (start, 1);
+ written += AppendCloser (start);
+ }
+ if (interest.IsEnabledAnswerOriginKind())
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_AnswerOriginKind, Ccnx::CCN_DTAG);
+ written += AppendNumber (start, 1);
+ written += AppendCloser (start);
+ }
+ if (interest.GetScope() >= 0)
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Scope, Ccnx::CCN_DTAG);
+ written += AppendNumber (start, interest.GetScope ());
+ written += AppendCloser (start);
+ }
+ if (!interest.GetInterestLifetime().IsZero())
+ {
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_InterestLifetime, Ccnx::CCN_DTAG);
+ written += AppendTimestampBlob (start, interest.GetInterestLifetime());
+ written += AppendCloser (start);
+ }
+ if (interest.GetNonce()>0)
+ {
+ uint32_t nonce = interest.GetNonce();
+ written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_Nonce,
+ reinterpret_cast<const uint8_t*>(&nonce),
+ sizeof(nonce));
+ }
+ written += AppendCloser (start); // </Interest>
+
+ return written;
+}
+
+size_t
+CcnxEncodingHelper::Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject)
+{
+ size_t written = 0;
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_ContentObject, Ccnx::CCN_DTAG); // <ContentObject>
+
+ // fake signature
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Signature, Ccnx::CCN_DTAG); // <Signature>
+ // Signature ::= DigestAlgorithm?
+ // Witness?
+ // SignatureBits
+ written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_SignatureBits, 0, 0); // <SignatureBits />
+ written += AppendCloser (start); // </Signature>
+
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Name, Ccnx::CCN_DTAG); // <Name>
+ written += AppendNameComponents (start, contentObject.GetName()); // <Component>...</Component>...
+ written += AppendCloser (start); // </Name>
+
+ // fake signature
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_SignedInfo, Ccnx::CCN_DTAG); // <SignedInfo>
+ // SignedInfo ::= PublisherPublicKeyDigest
+ // Timestamp
+ // Type?
+ // FreshnessSeconds?
+ // FinalBlockID?
+ // KeyLocator?
+ written += AppendTaggedBlob (start, Ccnx::CCN_DTAG_PublisherPublicKeyDigest, 0, 0); // <PublisherPublicKeyDigest />
+ written += AppendCloser (start); // </SignedInfo>
+
+ written += AppendBlockHeader (start, Ccnx::CCN_DTAG_Content, Ccnx::CCN_DTAG); // <Content>
+
+ // there is no closing tag !!!
+ return written;
+}
+
+} // namespace ns3
diff --git a/helper/ccnx-encoding-helper.h b/helper/ccnx-encoding-helper.h
new file mode 100644
index 0000000..90fad22
--- /dev/null
+++ b/helper/ccnx-encoding-helper.h
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author:
+ */
+
+#ifndef _CCNX_ENCODING_HELPER_H_
+#define _CCNX_ENCODING_HELPER_H_
+
+#include <sys/types.h>
+
+#include "ns3/ccnx.h"
+#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+
+namespace ns3 {
+
+namespace Name{ class Components; }
+
+class CcnxInterestHeader;
+class CcnxContentObjectHeader;
+
+/**
+ * Helper to encode/decode ccnb formatted CCNx message
+ *
+ */
+class CcnxEncodingHelper
+{
+public:
+ static size_t
+ Serialize (Buffer::Iterator start, const CcnxInterestHeader &interest);
+
+ static size_t
+ Serialize (Buffer::Iterator start, const CcnxContentObjectHeader &contentObject);
+
+private:
+ static size_t
+ AppendBlockHeader (Buffer::Iterator start, size_t value, Ccnx::ccn_tt block_type);
+
+ static size_t
+ AppendNumber (Buffer::Iterator start, uint32_t number);
+
+ static size_t
+ AppendCloser (Buffer::Iterator start);
+
+ static size_t
+ AppendNameComponents (Buffer::Iterator start, const Name::Components &name);
+
+ /**
+ * Append a binary timestamp as a BLOB using the ccn binary
+ * Timestamp representation (12-bit fraction).
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param time - Time object
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendTimestampBlob (Buffer::Iterator start, Time time);
+
+ /**
+ * Append a tagged BLOB
+ *
+ * This is a ccnb-encoded element with containing the BLOB as content
+ *
+ * @param start start iterator of the buffer to append to.
+ * @param dtag is the element's dtab
+ * @param data points to the binary data
+ * @param size is the size of the data, in bytes
+ *
+ * @returns written length
+ */
+ static size_t
+ AppendTaggedBlob (Buffer::Iterator start, Ccnx::ccn_dtag dtag,
+ const uint8_t *data, size_t size);
+
+};
+
+} // namespace ns3
+
+#endif // _CCNX_ENCODING_HELPER_H_
+
diff --git a/helper/ccnx-face-container.cc b/helper/ccnx-face-container.cc
index f25ea5e..956614d 100644
--- a/helper/ccnx-face-container.cc
+++ b/helper/ccnx-face-container.cc
@@ -1,8 +1,29 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
#include "ccnx-face-container.h"
-#include "ns3/node-list.h"
-#include "ns3/names.h"
+// #include "ns3/node-list.h"
+// #include "ns3/names.h"
+#include <algorithm>
+
+#include "ns3/ccnx-face.h"
namespace ns3 {
@@ -10,13 +31,26 @@
{
}
-void
-CcnxFaceContainer::Add (CcnxFaceContainer other)
+CcnxFaceContainer::CcnxFaceContainer (const CcnxFaceContainer &other)
{
- for (FaceVector::const_iterator i = other.m_faces.begin (); i != other.m_faces.end (); i++)
- {
- m_faces.push_back (*i);
- }
+ AddAll (other);
+}
+
+CcnxFaceContainer&
+CcnxFaceContainer::operator= (const CcnxFaceContainer &other)
+{
+ m_faces.clear ();
+ AddAll (other);
+
+ return *this;
+}
+
+
+void
+CcnxFaceContainer::AddAll (const CcnxFaceContainer &other)
+{
+ m_faces.insert (m_faces.end (),
+ other.m_faces.begin (), other.m_faces.end ());
}
CcnxFaceContainer::Iterator
@@ -37,44 +71,27 @@
return m_faces.size ();
}
-// CcnxAddress
-// CcnxFaceContainer::GetAddress (uint32_t i, uint32_t j) const
-// {
-// Ptr<Ccnx> ccnx = m_faces[i].first;
-// uint32_t face = m_faces[i].second;
-// return ccnx->GetAddress (face, j).GetLocal ();
-// }
-
void
-CcnxFaceContainer::SetMetric (uint32_t i, uint16_t metric)
+CcnxFaceContainer::SetMetricToAll (uint16_t metric)
{
- Ptr<Ccnx> ccnx = m_faces[i].first;
- uint32_t face = m_faces[i].second;
- ccnx->SetMetric (face, metric);
+ for (FaceContainer::iterator it=m_faces.begin ();
+ it != m_faces.end ();
+ it++)
+ {
+ (*it)->SetMetric (metric);
+ }
}
void
-CcnxFaceContainer::Add (Ptr<Ccnx> ccnx, uint32_t face)
+CcnxFaceContainer::Add (const Ptr<CcnxFace> &face)
{
- m_faces.push_back (std::make_pair (ccnx, face));
+ m_faces.push_back (face);
}
-void CcnxFaceContainer::Add (std::pair<Ptr<Ccnx>, uint32_t> a)
+Ptr<CcnxFace>
+CcnxFaceContainer::Get (CcnxFaceContainer::Iterator i) const
{
- Add (a.first, a.second);
-}
-
-void
-CcnxFaceContainer::Add (std::string ccnxName, uint32_t face)
-{
- Ptr<Ccnx> ccnx = Names::Find<Ccnx> (ccnxName);
- m_faces.push_back (std::make_pair (ccnx, face));
-}
-
-std::pair<Ptr<Ccnx>, uint32_t>
-CcnxFaceContainer::Get (uint32_t i) const
-{
- return m_faces[i];
+ return *i;
}
diff --git a/helper/ccnx-face-container.h b/helper/ccnx-face-container.h
index 8bbbbc3..4426449 100644
--- a/helper/ccnx-face-container.h
+++ b/helper/ccnx-face-container.h
@@ -1,4 +1,22 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
#ifndef CCNX_FACE_CONTAINER_H
#define CCNX_FACE_CONTAINER_H
@@ -10,170 +28,101 @@
namespace ns3 {
/**
- * \brief holds a vector of std::pair of Ptr<Ccnx> and face index.
+ * \ingroup ccnx
+ * \brief A pool for CCNx faces
+ *
+ * Provides tools to perform basic manipulation on faces, such as
+ * setting metrics and states on faces
*
- * Typically ns-3 CcnxFaces are installed on devices using an Ccnx address
- * helper. The helper's Assign() method takes a NetDeviceContainer which holds
- * some number of Ptr<NetDevice>. For each of the NetDevices in the
- * NetDeviceContainer the helper will find the associated Ptr<Node> and
- * Ptr<Ccnx>. It makes sure that an face exists on the node for the
- * device and then adds an CcnxAddress according to the address helper settings
- * (incrementing the CcnxAddress somehow as it goes). The helper then converts
- * the Ptr<Ccnx> and the face index to a std::pair and adds them to a
- * container -- a container of this type.
- *
- * The point is then to be able to implicitly associate an index into the
- * original NetDeviceContainer (that identifies a particular net device) with
- * an identical index into the CcnxFaceContainer that has a std::pair with
- * the Ptr<Ccnx> and face index you need to play with the face.
- *
- * @see CcnxAddressHelper
- * @see Ccnx
+ * \see Ccnx
*/
class CcnxFaceContainer
{
+private:
+ typedef std::vector<Ptr<CcnxFace> > FaceContainer;
public:
- typedef std::vector<std::pair<Ptr<Ccnx>, uint32_t> >::const_iterator Iterator;
+ typedef FaceContainer::const_iterator Iterator; ///< \brief Iterator over CcnxFaceContainer
/**
- * Create an empty CcnxFaceContainer.
+ * \brief Create an empty CcnxFaceContainer.
*/
CcnxFaceContainer ();
/**
- * Concatenate the entries in the other container with ours.
- * \param other container
+ * \brief Copy constructor for CcnxFaceContainer. Calls AddAll method
+ *
+ * \see CcnxFaceContainer::AddAll
*/
- void Add (CcnxFaceContainer other);
+ CcnxFaceContainer (const CcnxFaceContainer &other);
/**
- * \brief Get an iterator which refers to the first pair in the
+ * \brief Copy operator for CcnxFaceContainer. Empties vector and calls AddAll method
+ *
+ * All previously obtained iterators (Begin() and End()) will be invalidated
+ *
+ * \see CcnxFaceContainer::AddAll
+ */
+ CcnxFaceContainer& operator= (const CcnxFaceContainer &other);
+
+ /**
+ * \brief Add all entries from other container
+ *
+ * \param other container
+ */
+ void AddAll (const CcnxFaceContainer &other);
+
+ /**
+ * \brief Get an iterator which refers to the first pair in the
* container.
*
- * Pairs can be retrieved from the container in two ways. First,
- * directly by an index into the container, and second, using an iterator.
- * This method is used in the iterator method and is typically used in a
- * for-loop to run through the pairs
- *
- * \code
- * ccnxFaceContainer::Iterator i;
- * for (i = container.Begin (); i != container.End (); ++i)
- * {
- * std::pair<Ptr<Ccnx>, uint32_t> pair = *i;
- * method (pair.first, pair.second); // use the pair
- * }
- * \endcode
- *
* \returns an iterator which refers to the first pair in the container.
*/
- Iterator Begin (void) const;
+ Iterator Begin () const;
/**
* \brief Get an iterator which indicates past-the-last Node in the
* container.
*
- * Nodes can be retrieved from the container in two ways. First,
- * directly by an index into the container, and second, using an iterator.
- * This method is used in the iterator method and is typically used in a
- * for-loop to run through the Nodes
- *
- * \code
- * NodeContainer::Iterator i;
- * for (i = container.Begin (); i != container.End (); ++i)
- * {
- * std::pair<Ptr<Ccnx>, uint32_t> pair = *i;
- * method (pair.first, pair.second); // use the pair
- * }
- * \endcode
- *
* \returns an iterator which indicates an ending condition for a loop.
*/
- Iterator End (void) const;
+ Iterator End () const;
/**
- * \returns the number of Ptr<Ccnx> and face pairs stored in this
- * ccnxFaceContainer.
+ * \brief Get the number of faces stored in this container
*
- * Pairs can be retrieved from the container in two ways. First,
- * directly by an index into the container, and second, using an iterator.
- * This method is used in the direct method and is typically used to
- * define an ending condition in a for-loop that runs through the stored
- * Nodes
- *
- * \code
- * uint32_t nNodes = container.GetN ();
- * for (uint32_t i = 0 i < nNodes; ++i)
- * {
- * std::pair<Ptr<Ccnx>, uint32_t> pair = container.Get (i);
- * method (pair.first, pair.second); // use the pair
- * }
- * \endcode
- *
- * \returns the number of Ptr<Node> stored in this container.
+ * \returns the number of faces stored in this container
*/
- uint32_t GetN (void) const;
+ uint32_t GetN () const;
/**
- * \param i index of ipfacePair in container
- * \param j face address index (if face has multiple addresses)
- * \returns the ccnx address of the j'th address of the face
- * corresponding to index i.
- *
- * If the second parameter is omitted, the zeroth indexed address of
- * the face is returned. Unless IP aliasing is being used on
- * the face, the second parameter may typically be omitted.
+ * \brief Set a metric for all faces in the container
+ *
+ * \param metric value of metric to assign to all faces in the container
*/
- // ccnxAddress GetAddress (uint32_t i, uint32_t j = 0) const;
-
- void SetMetric (uint32_t i, uint16_t metric);
+ void SetMetricToAll (uint16_t metric);
/**
- * Manually add an entry to the container consisting of the individual parts
- * of an entry std::pair.
+ * Add an entry to the container
*
- * \param ccnx pointer to ccnx object
- * \param face face index of the ccnxface to add to the container
+ * \param face a smart pointer to a CcnxFace-derived object
*
- * @see ccnxfaceContainer
+ * @see CcnxFace
*/
- void Add (Ptr<Ccnx> ccnx, uint32_t face);
+ void Add (const Ptr<CcnxFace> &face);
/**
- * Manually add an entry to the container consisting of a previously composed
- * entry std::pair.
+ * Get a smart pointer to CcnxFace-derived object stored in the container
*
- * \param ipfacePair the pair of a pointer to ccnx object and face index of the ccnxface to add to the container
+ * \param i the iterator corresponding to the requested object
*
- * @see ccnxfaceContainer
+ * This method is redundant and simple dereferencing of the iterator should be used instead
+ *
+ * @see CcnxFace
*/
- void Add (std::pair<Ptr<Ccnx>, uint32_t> ipFacePair);
-
- /**
- * Manually add an entry to the container consisting of the individual parts
- * of an entry std::pair.
- *
- * \param ccnxName std:string referring to the saved name of an ccnx Object that
- * has been previously named using the Object Name Service.
- * \param face face index of the ccnxface to add to the container
- *
- * @see ccnxfaceContainer
- */
- void Add (std::string ccnxName, uint32_t face);
-
- /**
- * Get the std::pair of an Ptr<Ccnx> and face stored at the location
- * specified by the index.
- *
- * \param i the index of the entery to retrieve.
- *
- * @see ccnxfaceContainer
- */
- std::pair<Ptr<Ccnx>, uint32_t> Get (uint32_t i) const;
+ Ptr<CcnxFace> Get (Iterator i) const;
private:
-
- typedef std::vector<std::pair<Ptr<Ccnx>,uint32_t> > FaceVector;
- FaceVector m_faces;
+ FaceContainer m_faces;
};
} // namespace ns3
diff --git a/model/ccn/README b/in-progress/ccn/README
similarity index 100%
rename from model/ccn/README
rename to in-progress/ccn/README
diff --git a/model/ccn/ccn.h b/in-progress/ccn/ccn.h
similarity index 100%
rename from model/ccn/ccn.h
rename to in-progress/ccn/ccn.h
diff --git a/model/ccn/ccn_buf_decoder.cc b/in-progress/ccn/ccn_buf_decoder.cc
similarity index 100%
rename from model/ccn/ccn_buf_decoder.cc
rename to in-progress/ccn/ccn_buf_decoder.cc
diff --git a/model/ccn/ccn_buf_encoder.cc b/in-progress/ccn/ccn_buf_encoder.cc
similarity index 100%
rename from model/ccn/ccn_buf_encoder.cc
rename to in-progress/ccn/ccn_buf_encoder.cc
diff --git a/model/ccn/ccn_charbuf.cc b/in-progress/ccn/ccn_charbuf.cc
similarity index 100%
rename from model/ccn/ccn_charbuf.cc
rename to in-progress/ccn/ccn_charbuf.cc
diff --git a/model/ccn/ccn_charbuf.h b/in-progress/ccn/ccn_charbuf.h
similarity index 100%
rename from model/ccn/ccn_charbuf.h
rename to in-progress/ccn/ccn_charbuf.h
diff --git a/model/ccn/ccn_indexbuf.cc b/in-progress/ccn/ccn_indexbuf.cc
similarity index 100%
rename from model/ccn/ccn_indexbuf.cc
rename to in-progress/ccn/ccn_indexbuf.cc
diff --git a/model/ccn/ccn_indexbuf.h b/in-progress/ccn/ccn_indexbuf.h
similarity index 100%
rename from model/ccn/ccn_indexbuf.h
rename to in-progress/ccn/ccn_indexbuf.h
diff --git a/model/ccn/ccn_name_util.cc b/in-progress/ccn/ccn_name_util.cc
similarity index 100%
rename from model/ccn/ccn_name_util.cc
rename to in-progress/ccn/ccn_name_util.cc
diff --git a/model/ccn/ccn_name_util.h b/in-progress/ccn/ccn_name_util.h
similarity index 100%
rename from model/ccn/ccn_name_util.h
rename to in-progress/ccn/ccn_name_util.h
diff --git a/model/ccn/ccn_random.cc b/in-progress/ccn/ccn_random.cc
similarity index 100%
rename from model/ccn/ccn_random.cc
rename to in-progress/ccn/ccn_random.cc
diff --git a/model/ccn/ccn_random.h b/in-progress/ccn/ccn_random.h
similarity index 100%
rename from model/ccn/ccn_random.h
rename to in-progress/ccn/ccn_random.h
diff --git a/model/ccnx-content-object-header.cc b/model/ccnx-content-object-header.cc
index 8da3b84..e567207 100644
--- a/model/ccnx-content-object-header.cc
+++ b/model/ccnx-content-object-header.cc
@@ -22,6 +22,8 @@
#include "ccnx-content-object-header.h"
#include "ns3/log.h"
+#include "ns3/ccnx-encoding-helper.h"
+#include "ns3/ccnx-decoding-helper.h"
NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader");
@@ -60,19 +62,22 @@
uint32_t
CcnxContentObjectHeader::GetSerializedSize (void) const
{
- return 0;
+ // Unfortunately, two serializations are required, unless we can pre-calculate header length... which is not trivial
+ Buffer tmp;
+
+ return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
}
void
CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const
{
- return;
+ CcnxEncodingHelper::Serialize (start, *this);
}
uint32_t
CcnxContentObjectHeader::Deserialize (Buffer::Iterator start)
{
- return 0;
+ return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
}
TypeId
@@ -135,10 +140,10 @@
{
Buffer::Iterator i = start;
uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
- NS_ASSERT_MSG (closing_tag_content==0, "Should be closing tag </Content> (0x00)");
+ NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
- NS_ASSERT_MSG (closing_tag_content_object==0, "Should be closing tag </ContentObject> (0x00)");
+ NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
return 2;
}
diff --git a/model/ccnx-face.cc b/model/ccnx-face.cc
index 15ddb84..6ce6b92 100644
--- a/model/ccnx-face.cc
+++ b/model/ccnx-face.cc
@@ -151,7 +151,7 @@
}
m_device->Send (packet, m_device->GetBroadcast (),
- CcnxL3Protocol::PROT_NUMBER);
+ CcnxL3Protocol::ETHERNET_FRAME_TYPE);
}
std::ostream& operator<< (std::ostream& os, CcnxFace const& face)
diff --git a/model/ccnx-interest-header.cc b/model/ccnx-interest-header.cc
index 627946c..02ad9af 100644
--- a/model/ccnx-interest-header.cc
+++ b/model/ccnx-interest-header.cc
@@ -26,6 +26,8 @@
#include "ccnx-interest-header.h"
#include "ns3/log.h"
+#include "ns3/ccnx-encoding-helper.h"
+#include "ns3/ccnx-decoding-helper.h"
NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader");
@@ -167,19 +169,22 @@
uint32_t
CcnxInterestHeader::GetSerializedSize (void) const
{
- return 0;
+ // unfortunately, 2 serialization required...
+ Buffer tmp;
+
+ return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
}
void
CcnxInterestHeader::Serialize (Buffer::Iterator start) const
{
- return;
+ CcnxEncodingHelper::Serialize (start, *this);
}
uint32_t
CcnxInterestHeader::Deserialize (Buffer::Iterator start)
{
- return 0;
+ return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
}
TypeId
@@ -191,7 +196,23 @@
void
CcnxInterestHeader::Print (std::ostream &os) const
{
- os << "Interest: " << *m_name;
+ os << "<Interest><Name>" << *m_name << "</Name>";
+ if (m_minSuffixComponents>=0)
+ os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>";
+ if (m_maxSuffixComponents>=0)
+ os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>";
+ if (m_exclude->size()>0)
+ os << "<Exclude>" << *m_exclude << "</Exclude>";
+ if (m_childSelector)
+ os << "<ChildSelector />";
+ if (m_answerOriginKind)
+ os << "<AnswerOriginKind />";
+ if (m_scope>=0)
+ os << "<Scope>" << m_scope << "</Scope>";
+ if (!m_interestLifetime.IsZero())
+ os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>";
+ if (m_nonce>0)
+ os << "<Nonce>" << m_nonce << "</Nonce>";
}
}
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 2ea1414..2a13f4c 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -43,7 +43,7 @@
namespace ns3 {
-const uint16_t CcnxL3Protocol::PROT_NUMBER = 0x7777;
+const uint16_t CcnxL3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
NS_OBJECT_ENSURE_REGISTERED (CcnxL3Protocol);
@@ -53,19 +53,19 @@
static TypeId tid = TypeId ("ns3::CcnxL3Protocol")
.SetParent<Ccnx> ()
.AddConstructor<CcnxL3Protocol> ()
- .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.",
- MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace))
- .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.",
- MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace))
- .AddTraceSource ("Drop", "Drop ccnx packet",
- MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace))
+ // .AddTraceSource ("Tx", "Send ccnx packet to outgoing interface.",
+ // MakeTraceSourceAccessor (&CcnxL3Protocol::m_txTrace))
+ // .AddTraceSource ("Rx", "Receive ccnx packet from incoming interface.",
+ // MakeTraceSourceAccessor (&CcnxL3Protocol::m_rxTrace))
+ // .AddTraceSource ("Drop", "Drop ccnx packet",
+ // MakeTraceSourceAccessor (&CcnxL3Protocol::m_dropTrace))
.AddAttribute ("InterfaceList", "The set of Ccnx interfaces associated to this Ccnx stack.",
ObjectVectorValue (),
MakeObjectVectorAccessor (&CcnxL3Protocol::m_faces),
MakeObjectVectorChecker<CcnxFace> ())
- .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission",
- MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace))
+ // .AddTraceSource ("SendOutgoing", "A newly-generated packet by this node is about to be queued for transmission",
+ // MakeTraceSourceAccessor (&CcnxL3Protocol::m_sendOutgoingTrace))
;
return tid;
@@ -137,7 +137,7 @@
}
uint32_t
-CcnxL3Protocol::AddFace (Ptr<CcnxFace> face)
+CcnxL3Protocol::AddFace (const Ptr<CcnxFace> &face)
{
NS_LOG_FUNCTION (this << *face);
@@ -147,7 +147,7 @@
if (face->GetDevice() != 0)
{
m_node->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::ReceiveFromLower, this),
- CcnxL3Protocol::PROT_NUMBER, face->GetDevice(), true/*promiscuous mode*/);
+ CcnxL3Protocol::ETHERNET_FRAME_TYPE, face->GetDevice(), true/*promiscuous mode*/);
}
uint32_t index = m_faces.size ();
@@ -218,7 +218,7 @@
if (incomingFace->IsUp ())
{
NS_LOG_LOGIC ("Dropping received packet -- interface is down");
- m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
+ // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
return;
}
@@ -242,7 +242,7 @@
if (incomingFace->IsUp ())
{
NS_LOG_LOGIC ("Dropping received packet -- interface is down");
- m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
+ // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), incomingFace);
return;
}
@@ -258,29 +258,29 @@
void
-CcnxL3Protocol::Send (Ptr<Packet> packet, Ptr<CcnxRoute> route)
+CcnxL3Protocol::Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face)
{
- NS_LOG_FUNCTION (this << "packet: " << packet << ", route: "<< route);
+ // NS_LOG_FUNCTION (this << "packet: " << packet << ", route: "<< route);
- if (route == 0)
- {
- NS_LOG_WARN ("No route to host. Drop.");
- m_dropTrace (packet, DROP_NO_ROUTE, m_node->GetObject<Ccnx> (), 0);
- return;
- }
- Ptr<CcnxFace> outFace = route->GetOutputFace ();
+ // if (route == 0)
+ // {
+ // NS_LOG_WARN ("No route to host. Drop.");
+ // // m_dropTrace (packet, DROP_NO_ROUTE, m_node->GetObject<Ccnx> (), 0);
+ // return;
+ // }
+ // Ptr<CcnxFace> outFace = route->GetOutputFace ();
- if (outFace->IsUp ())
- {
- NS_LOG_LOGIC ("Sending via face " << *outFace);
- m_txTrace (packet, m_node->GetObject<Ccnx> (), outFace);
- outFace->Send (packet);
- }
- else
- {
- NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << *outFace);
- m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), outFace);
- }
+ // if (outFace->IsUp ())
+ // {
+ // NS_LOG_LOGIC ("Sending via face " << *outFace);
+ // // m_txTrace (packet, m_node->GetObject<Ccnx> (), outFace);
+ // outFace->Send (packet);
+ // }
+ // else
+ // {
+ // NS_LOG_LOGIC ("Dropping -- outgoing interface is down: " << *outFace);
+ // // m_dropTrace (packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ccnx> (), outFace);
+ // }
}
@@ -339,12 +339,4 @@
}
}
-void
-CcnxL3Protocol::RouteInputError (Ptr<Packet> p)//, Socket::SocketErrno sockErrno)
-{
- // NS_LOG_FUNCTION (this << p << ipHeader << sockErrno);
- // NS_LOG_LOGIC ("Route input failure-- dropping packet to " << ipHeader << " with errno " << sockErrno);
- m_dropTrace (p, DROP_ROUTE_ERROR, m_node->GetObject<Ccnx> (), 0);
-}
-
} //namespace ns3
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index 32425c4..e8a0d22 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -1,22 +1,22 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-//
-// Copyright (c) 2006 Georgia Tech Research Corporation
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation;
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// Author:
-//
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
#ifndef CCNX_L3_PROTOCOL_H
#define CCNX_L3_PROTOCOL_H
@@ -43,10 +43,10 @@
class CcnxContentObjectHeader;
/**
- * \brief Implement the Ccnx layer.
+ * \ingroup ccnx
+ * \brief Actual implementation of the Ccnx network layer
*
- * This is the actual implementation of IP. It contains APIs to send and
- * receive packets at the IP layer, as well as APIs for IP routing.
+ * \todo This description is incorrect. Should be changed accordingly
*
* This class contains two distinct groups of trace sources. The
* trace sources 'Rx' and 'Tx' are called, respectively, immediately
@@ -61,9 +61,20 @@
class CcnxL3Protocol : public Ccnx
{
public:
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
static TypeId GetTypeId (void);
- static const uint16_t PROT_NUMBER;
+ static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
+ static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
+ static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
+
+ /**
+ * \brief Default constructor. Creates an empty stack without forwarding strategy set
+ */
CcnxL3Protocol();
virtual ~CcnxL3Protocol ();
@@ -78,16 +89,35 @@
DROP_CONGESTION, /**< Congestion detected */
DROP_NO_ROUTE, /**< No route to host */
DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
- DROP_ROUTE_ERROR, /**< Route error */
};
+ /**
+ * \brief Assigns node to the CCNx stack
+ *
+ * \param node Simulation node
+ */
void SetNode (Ptr<Node> node);
+ ////////////////////////////////////////////////////////////////////
// functions defined in base class Ccnx
void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const;
+ virtual void Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face);
+
+ virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
+ virtual uint32_t GetNFaces (void) const;
+ virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
+
+ virtual void SetMetric (uint32_t i, uint16_t metric);
+ virtual uint16_t GetMetric (uint32_t i) const;
+ virtual uint16_t GetMtu (uint32_t i) const;
+ virtual bool IsUp (uint32_t i) const;
+ virtual void SetUp (uint32_t i);
+ virtual void SetDown (uint32_t i);
+
+protected:
/**
* Lower layer calls this method after calling L3Demux::Lookup
*
@@ -119,29 +149,10 @@
*/
virtual void
ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<CcnxContentObjectHeader> header, Ptr<Packet> p);
-
- /**
- * \param packet packet to send
- * \param route route entry
- *
- * Higher-level layers call this method to send a packet
- * down the stack to the MAC and PHY layers.
- */
- virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route);
-
- virtual uint32_t AddFace (Ptr<CcnxFace> face);
- virtual uint32_t GetNFaces (void) const;
- virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
-
- virtual void SetMetric (uint32_t i, uint16_t metric);
- virtual uint16_t GetMetric (uint32_t i) const;
- virtual uint16_t GetMtu (uint32_t i) const;
- virtual bool IsUp (uint32_t i) const;
- virtual void SetUp (uint32_t i);
- virtual void SetDown (uint32_t i);
protected:
virtual void DoDispose (void);
+
/**
* This function will notify other components connected to the node that a new stack member is now connected
* This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
@@ -149,20 +160,16 @@
virtual void NotifyNewAggregate ();
private:
- // friend class CcnxL3ProtocolTestCase;
- CcnxL3Protocol(const CcnxL3Protocol &);
- CcnxL3Protocol &operator = (const CcnxL3Protocol &);
+ CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
+ CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
/**
* Helper function to get CcnxFace from NetDevice
*/
Ptr<CcnxFace> GetFaceForDevice (Ptr<const NetDevice> device) const;
-
- void RouteInputError (Ptr<Packet> p);
- //, Socket::SocketErrno sockErrno);
/**
- * false function. should never be called. Just to trick C++ to compile
+ * \brief Fake function. should never be called. Just to trick C++ to compile
*/
virtual void
ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
@@ -174,15 +181,15 @@
Ptr<Node> m_node;
Ptr<CcnxForwardingStrategy> m_forwardingStrategy;
- TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
- TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
- TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
+ // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_sendOutgoingTrace;
+ // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_unicastForwardTrace;
+ // TracedCallback<Ptr<const Packet>, Ptr<const CcnxFace> > m_localDeliverTrace;
- // The following two traces pass a packet with an IP header
- TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
- TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
- // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
- TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
+ // // The following two traces pass a packet with an IP header
+ // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_txTrace;
+ // TracedCallback<Ptr<const Packet>, Ptr<Ccnx>, Ptr<const CcnxFace> > m_rxTrace;
+ // // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
+ // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
};
} // Namespace ns3
diff --git a/model/ccnx.cc b/model/ccnx.cc
index 7716366..a940c36 100644
--- a/model/ccnx.cc
+++ b/model/ccnx.cc
@@ -37,12 +37,4 @@
return tid;
}
-Ccnx::Ccnx ()
-{
-}
-
-Ccnx::~Ccnx ()
-{
-}
-
} // namespace ns3
diff --git a/model/ccnx.h b/model/ccnx.h
index 12c45d2..c7627ab 100644
--- a/model/ccnx.h
+++ b/model/ccnx.h
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2007 INRIA
+ * Copyright (c) 2011 University of California, Los Angeles
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -15,17 +15,17 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Author:
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
-#ifndef CCNX_H
-#define CCNX_H
-#include <stdint.h>
+#ifndef _CCNX_H_
+#define _CCNX_H_
+
#include "ns3/object.h"
#include "ns3/socket.h"
#include "ns3/callback.h"
-#include "ccnx-route.h"
+#include "ccnx-face.h"
namespace ns3 {
@@ -35,76 +35,87 @@
class CcnxForwardingStrategy;
/**
- * \ingroup internet
- * \defgroup ccnx Ccnx
+ * \defgroup ccnx NDN abstraction
+ *
+ * This is an abstract implementation of NDN protocol
*/
/**
* \ingroup ccnx
- * \brief Access to the Ccnx forwarding table, interfaces, and configuration
+ * \brief Interface to manage Ccnx stack
*
* This class defines the API to manipulate the following aspects of
- * the Ccnx implementation:
- * -# register a NetDevice for use by the Ccnx layer (basically, to
- * create Ccnx-related state such as addressing and neighbor cache that
- * is associated with a NetDevice)
- * -# manipulate the status of the NetDevice from the Ccnx perspective,
- * such as marking it as Up or Down,
- // * -# adding, deleting, and getting addresses associated to the Ccnx
- // * interfaces.
- * -# exporting Ccnx configuration attributes
+ * the Ccnx stack implementation:
+ * -# register a face (CcnxFace-derived object) for use by the Ccnx
+ * layer
+ * -# register forwarding strategy (CcnxForwardingStrategy-derived
+ * object) to use by Ccnx stack
+ * -# export Ccnx configuration attributes
*
- * Each NetDevice has conceptually a single Ccnx interface associated
- * with it.
+ * Each CcnxFace-derived object has conceptually a single Ccnx
+ * interface associated with it.
+ *
+ * In addition, this class defines CCNx packet coding constants
+ *
+ * \see CcnxFace, CcnxForwardingStrategy
*/
class Ccnx : public Object
{
public:
- static TypeId GetTypeId (void);
- Ccnx ();
- virtual ~Ccnx ();
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
+ static TypeId GetTypeId ();
/**
- * \brief Register a new forwarding protocol to be used by this Ccnx stack
+ * \brief Register a new forwarding strategy to be used by this Ccnx
+ * stack
*
- * This call will replace any forwarding protocol that has been previously
- * registered. If you want to add multiple forwarding protocols, you must
- * add them to a CcnxListForwardingStrategy directly.
+ * This call will replace any forwarding strategy that has been
+ * previously registered.
*
- * \param forwardingStrategy smart pointer to CcnxForwardingStrategy object
+ * \param forwardingStrategy smart pointer to CcnxForwardingStrategy
+ * object
*/
virtual void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) = 0;
/**
- * \brief Get the forwarding protocol to be used by this Ccnx stack
+ * \brief Get the forwarding strategy being used by this Ccnx stack
*
- * \returns smart pointer to CcnxForwardingStrategy object, or null pointer if none
+ * \returns smart pointer to CcnxForwardingStrategy object, or null
+ * pointer if none
*/
virtual Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const = 0;
/**
- * \param device device to add to the list of Ccnx interfaces
- * which can be used as output interfaces during packet forwarding.
- * \returns the index of the Ccnx interface added.
+ * \brief Add face to CCNx stack
*
- * Once a device has been added, it can never be removed: if you want
- * to disable it, you can invoke Ccnx::SetDown which will
- * make sure that it is never used during packet forwarding.
+ * \param face smart pointer to CcnxFace-derived object
+ * (CcnxLocalFace, CcnxNetDeviceFace, CcnxUdpFace) \returns the
+ * index of the Ccnx interface added.
+ *
+ * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxUdpFace
*/
- virtual uint32_t AddFace (Ptr<CcnxFace> face) = 0;
+ virtual uint32_t AddFace (const Ptr<CcnxFace> &face) = 0;
/**
- * \returns the number of interfaces added by the user.
+ * \brief Get current number of faces added to CCNx stack
+ *
+ * \returns the number of faces
*/
virtual uint32_t GetNFaces (void) const = 0;
/**
- * \param packet packet to send
- * \param route route entry
+ * \brief Send a packet to a specified face
*
- * Higher-level layers call this method to send a packet
- * down the stack to the MAC and PHY layers.
+ * \param packet fully prepared CCNx packet to send
+ * \param face face where to send this packet
+ *
+ * Higher-level layers (forwarding strategy in particular) call this
+ * method to send a packet down the stack to the MAC and PHY layers.
*/
- // virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route) = 0;
+ virtual void Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face) = 0;
/**
* \param face The face number of an Ccnx interface.
@@ -112,57 +123,129 @@
*/
virtual Ptr<CcnxFace> GetFace (uint32_t face) const = 0;
- // /**
- // * \param face CcnxFace object pointer
- // * \returns The interface number of an Ccnx face or -1 if not found.
- // */
- // virtual int32_t GetFaceForDevice (Ptr<const CcnxFace> face) const = 0;
-
- /**
- * \param face The face number of an Ccnx face
- * \param metric forwarding metric (cost) associated to the underlying
- * Ccnx interface
- */
- virtual void SetMetric (uint32_t face, uint16_t metric) = 0;
-
- /**
- * \param face The interface number of an Ccnx interface
- * \returns forwarding metric (cost) associated to the underlying
- * Ccnx interface
- */
- virtual uint16_t GetMetric (uint32_t face) const = 0;
-
- /**
- * \param face Interface number of Ccnx interface
- * \returns the Maximum Transmission Unit (in bytes) associated
- * to the underlying Ccnx interface
- */
- virtual uint16_t GetMtu (uint32_t face) const = 0;
-
- /**
- * \param face Interface number of Ccnx interface
- * \returns true if the underlying interface is in the "up" state,
- * false otherwise.
- */
- virtual bool IsUp (uint32_t face) const = 0;
-
- /**
- * \param face Interface number of Ccnx interface
- *
- * Set the interface into the "up" state. In this state, it is
- * considered valid during Ccnx forwarding.
- */
- virtual void SetUp (uint32_t face) = 0;
-
- /**
- * \param face Interface number of Ccnx interface
+public:
+ /**
+ * \brief Type tag for a ccnb start marker.
*
- * Set the interface into the "down" state. In this state, it is
- * ignored during Ccnx forwarding.
+ * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
*/
- virtual void SetDown (uint32_t face) = 0;
+ enum ccn_tt {
+ CCN_EXT, /**< starts composite extension - numval is subtype */
+ CCN_TAG, /**< starts composite - numval is tagnamelen-1 */
+ CCN_DTAG, /**< starts composite - numval is tagdict index (enum ccn_dtag) */
+ CCN_ATTR, /**< attribute - numval is attrnamelen-1, value follows */
+ CCN_DATTR, /**< attribute numval is attrdict index */
+ CCN_BLOB, /**< opaque binary data - numval is byte count */
+ CCN_UDATA, /**< UTF-8 encoded character data - numval is byte count */
+ CCN_NO_TOKEN /**< should not occur in encoding */
+ };
+
+ /** \brief CCN_CLOSE terminates composites */
+ enum {CCN_CLOSE = 0};
+
+ /**
+ * \brief DTAG identifies ccnb-encoded elements.
+ *
+ * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
+ */
+ enum ccn_dtag {
+ CCN_DTAG_Any = 13,
+ CCN_DTAG_Name = 14,
+ CCN_DTAG_Component = 15,
+ CCN_DTAG_Certificate = 16,
+ CCN_DTAG_Collection = 17,
+ CCN_DTAG_CompleteName = 18,
+ CCN_DTAG_Content = 19,
+ CCN_DTAG_SignedInfo = 20,
+ CCN_DTAG_ContentDigest = 21,
+ CCN_DTAG_ContentHash = 22,
+ CCN_DTAG_Count = 24,
+ CCN_DTAG_Header = 25,
+ CCN_DTAG_Interest = 26, /* 20090915 */
+ CCN_DTAG_Key = 27,
+ CCN_DTAG_KeyLocator = 28,
+ CCN_DTAG_KeyName = 29,
+ CCN_DTAG_Length = 30,
+ CCN_DTAG_Link = 31,
+ CCN_DTAG_LinkAuthenticator = 32,
+ CCN_DTAG_NameComponentCount = 33, /* DeprecatedInInterest */
+ CCN_DTAG_RootDigest = 36,
+ CCN_DTAG_Signature = 37,
+ CCN_DTAG_Start = 38,
+ CCN_DTAG_Timestamp = 39,
+ CCN_DTAG_Type = 40,
+ CCN_DTAG_Nonce = 41,
+ CCN_DTAG_Scope = 42,
+ CCN_DTAG_Exclude = 43,
+ CCN_DTAG_Bloom = 44,
+ CCN_DTAG_BloomSeed = 45,
+ CCN_DTAG_AnswerOriginKind = 47,
+ CCN_DTAG_InterestLifetime = 48,
+ CCN_DTAG_Witness = 53,
+ CCN_DTAG_SignatureBits = 54,
+ CCN_DTAG_DigestAlgorithm = 55,
+ CCN_DTAG_BlockSize = 56,
+ CCN_DTAG_FreshnessSeconds = 58,
+ CCN_DTAG_FinalBlockID = 59,
+ CCN_DTAG_PublisherPublicKeyDigest = 60,
+ CCN_DTAG_PublisherCertificateDigest = 61,
+ CCN_DTAG_PublisherIssuerKeyDigest = 62,
+ CCN_DTAG_PublisherIssuerCertificateDigest = 63,
+ CCN_DTAG_ContentObject = 64, /* 20090915 */
+ CCN_DTAG_WrappedKey = 65,
+ CCN_DTAG_WrappingKeyIdentifier = 66,
+ CCN_DTAG_WrapAlgorithm = 67,
+ CCN_DTAG_KeyAlgorithm = 68,
+ CCN_DTAG_Label = 69,
+ CCN_DTAG_EncryptedKey = 70,
+ CCN_DTAG_EncryptedNonceKey = 71,
+ CCN_DTAG_WrappingKeyName = 72,
+ CCN_DTAG_Action = 73,
+ CCN_DTAG_FaceID = 74,
+ CCN_DTAG_IPProto = 75,
+ CCN_DTAG_Host = 76,
+ CCN_DTAG_Port = 77,
+ CCN_DTAG_MulticastInterface = 78,
+ CCN_DTAG_ForwardingFlags = 79,
+ CCN_DTAG_FaceInstance = 80,
+ CCN_DTAG_ForwardingEntry = 81,
+ CCN_DTAG_MulticastTTL = 82,
+ CCN_DTAG_MinSuffixComponents = 83,
+ CCN_DTAG_MaxSuffixComponents = 84,
+ CCN_DTAG_ChildSelector = 85,
+ CCN_DTAG_RepositoryInfo = 86,
+ CCN_DTAG_Version = 87,
+ CCN_DTAG_RepositoryVersion = 88,
+ CCN_DTAG_GlobalPrefix = 89,
+ CCN_DTAG_LocalName = 90,
+ CCN_DTAG_Policy = 91,
+ CCN_DTAG_Namespace = 92,
+ CCN_DTAG_GlobalPrefixName = 93,
+ CCN_DTAG_PolicyVersion = 94,
+ CCN_DTAG_KeyValueSet = 95,
+ CCN_DTAG_KeyValuePair = 96,
+ CCN_DTAG_IntegerValue = 97,
+ CCN_DTAG_DecimalValue = 98,
+ CCN_DTAG_StringValue = 99,
+ CCN_DTAG_BinaryValue = 100,
+ CCN_DTAG_NameValue = 101,
+ CCN_DTAG_Entry = 102,
+ CCN_DTAG_ACL = 103,
+ CCN_DTAG_ParameterizedName = 104,
+ CCN_DTAG_Prefix = 105,
+ CCN_DTAG_Suffix = 106,
+ CCN_DTAG_Root = 107,
+ CCN_DTAG_ProfileName = 108,
+ CCN_DTAG_Parameters = 109,
+ CCN_DTAG_InfoString = 110,
+ CCN_DTAG_StatusResponse = 112,
+ CCN_DTAG_StatusCode = 113,
+ CCN_DTAG_StatusText = 114,
+ CCN_DTAG_SequenceNumber = 256,
+ CCN_DTAG_CCNProtocolDataUnit = 17702112
+ };
};
} // namespace ns3
-#endif /* CCNX_H */
+#endif /* _CCNX_H_ */
diff --git a/model/name-components.cc b/model/name-components.cc
index 55e57c4..e1af1ee 100644
--- a/model/name-components.cc
+++ b/model/name-components.cc
@@ -20,9 +20,6 @@
#include "name-components.h"
-#include "ns3/ccn.h"
-#include "ns3/ccn_charbuf.h"
-
#include <iostream>
using namespace std;
@@ -49,6 +46,13 @@
// ccn_charbuf_destroy(&m_value);
}
+const std::list<std::string> &
+Components::GetComponents () const
+{
+ return m_prefix;
+}
+
+
// const ccn_charbuf*
// Components::GetName () const
// {
diff --git a/model/name-components.h b/model/name-components.h
index 8c124f8..0ea4821 100644
--- a/model/name-components.h
+++ b/model/name-components.h
@@ -36,7 +36,14 @@
Components (const std::string &s);
~Components ();
- Components& operator () (const std::string &s);
+ inline void
+ Add (const std::string &s);
+
+ Components&
+ operator () (const std::string &s);
+
+ const std::list<std::string> &
+ GetComponents () const;
// virtual uint32_t
// GetSerializedSize (void) const;
@@ -67,6 +74,12 @@
return m_prefix.size ();
}
+void
+Components::Add (const std::string &s)
+{
+ (*this) (s);
+}
+
} // Namespace Name
} // namespace ns3
diff --git a/wscript b/wscript
index c67b81d..0142dc2 100644
--- a/wscript
+++ b/wscript
@@ -3,18 +3,39 @@
import os
import Logs
import Utils
+import Options
+
+def set_options(opt):
+ opt.tool_options('boost')
+
+def configure(conf):
+ conf.check_tool('boost')
+ conf.env['BOOST'] = conf.check_boost(lib = '', # need only base
+ min_version='1.40.0' )
+ if not conf.env['BOOST']:
+ conf.report_optional_feature("ndn-abstract", "NDN abstraction", False,
+ "Required boost libraries not found")
+ conf.env['ENABLE_NDN_ABSTRACT']=False;
+ return
+
+ conf.env['ENABLE_NDN_ABSTRACT']=True;
+
def build(bld):
module = bld.create_ns3_module ('NDNabstraction', ['applications', 'core', 'network', 'point-to-point','topology-read','visualizer'])
- module.find_sources_in_dirs (['model', 'apps', 'helper'],[],['.cc']);
tests = bld.create_ns3_module_test_library('NDNabstraction')
- tests.find_sources_in_dirs( ['test'], [], ['.cc'] );
-
headers = bld.new_task_gen('ns3header')
headers.module = 'NDNabstraction'
+
+ if not bld.env['ENABLE_NDN_ABSTRACT']:
+ return
+
+ module.find_sources_in_dirs (['model', 'apps', 'helper'],[],['.cc']);
+ tests.find_sources_in_dirs( ['test'], [], ['.cc'] );
headers.find_sources_in_dirs( ['model', 'apps', 'helper'], [], ['.h'] );
+
for path in ["examples"]:
anode = bld.path.find_dir (path)
if not anode or not anode.is_child_of(bld.srcnode):