Adding more documentation. Now CcnxFace defines an virtual interface to
protocol-dependant functionality
(Code is not working as of now)
diff --git a/model/ccnx-face.h b/model/ccnx-face.h
index 35f7dc1..121c146 100644
--- a/model/ccnx-face.h
+++ b/model/ccnx-face.h
@@ -33,88 +33,116 @@
class Node;
/**
- * \brief The Ccnx representation of a network face
+ * \ingroup ccnx
+ * \brief Virtual class defining CCNx face
*
- * This class roughly corresponds to the struct in_device
- * of Linux; the main purpose is to provide address-family
- * specific information (addresses) about an face.
+ * This class defines basic functionality of CCNx face. Face is core
+ * component responsible for actual delivery of data packet to and
+ * from CCNx stack
*
- * By default, Ccnx face are created in the "down" state
- * no IP addresses. Before becoming useable, the user must
- * add an address of some type and invoke Setup on them.
+ * \see CcnxLocalFace, CcnxNetDeviceFace, CcnxIpv4Face, CcnxUdpFace
*/
class CcnxFace : public Object
{
public:
+ /**
+ * \brief Ccnx protocol hanler
+ *
+ * \param face Face from which packet has been received
+ * \param packet Received packet
+ */
+ typedef Callback<void,Ptr<CcnxFace>,Ptr<Packet> > ProtocolHandler;
+
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
static TypeId GetTypeId (void);
+ /**
+ * \brief Default constructor
+ */
CcnxFace ();
virtual ~CcnxFace();
- virtual void SetNode (Ptr<Node> node);
- virtual void SetDevice (Ptr<NetDevice> device);
-
+ ////////////////////////////////////////////////////////////////////
+
/**
- * \returns the underlying NetDevice. This method cannot return zero.
- */
- virtual Ptr<NetDevice> GetDevice (void) const;
-
- /**
- * \param metric configured routing metric (cost) of this face
+ * \brief Register callback to call when new packet arrives on the face
*
- * Note: This is synonymous to the Metric value that ifconfig prints
- * out. It is used by ns-3 global routing, but other routing daemons
- * choose to ignore it.
+ * This method should call protocol-dependent registration function
+ */
+ void RegisterProtocolHandler (ProtocolHandler handler) = 0;
+
+ /**
+ * \brief Send packet on a face
+ *
+ * \param p smart pointer to a packet to send
+ */
+ virtual void Send (Ptr<Packet> p) = 0;
+
+ ////////////////////////////////////////////////////////////////////
+
+ /**
+ * \brief Associate Node object with face
+ *
+ * \param node smart pointer to a Node object
+ */
+ virtual void SetNode (Ptr<Node> node);
+
+ /**
+ * \brief Assign routing/forwarding metric with face
+ *
+ * \param metric configured routing metric (cost) of this face
*/
virtual void SetMetric (uint16_t metric);
/**
- * \returns configured routing metric (cost) of this face
+ * \brief Get routing/forwarding metric assigned to the face
*
- * Note: This is synonymous to the Metric value that ifconfig prints
- * out. It is used by ns-3 global routing, but other routing daemons
- * may choose to ignore it.
+ * \returns configured routing/forwarding metric (cost) of this face
*/
virtual uint16_t GetMetric (void) const;
/**
- * These are IP face states and may be distinct from
- * NetDevice states, such as found in real implementations
- * (where the device may be down but IP face state is still up).
+ * These are face states and may be distinct from actual lower-layer
+ * device states, such as found in real implementations (where the
+ * device may be down but ccnx face state is still up).
*/
+
/**
- * \returns true if this face is enabled, false otherwise.
+ * \brief Enable this face
*/
- virtual bool IsUp (void) const;
+ virtual void SetUp ();
/**
- * \returns true if this face is disabled, false otherwise.
- */
- virtual bool IsDown (void) const;
-
- /**
- * Enable this face
- */
- virtual void SetUp (void);
-
- /**
- * Disable this face
+ * \brief Disable this face
*/
virtual void SetDown (void);
/**
- * \param p packet to send
- */
- virtual void Send (Ptr<Packet> p);
+ * \brief Returns true if this face is enabled, false otherwise.
+ */
+ virtual bool IsUp () const;
+
+ /**
+ * \brief Returns true if this face is disabled, false otherwise.
+ */
+ virtual bool IsDown () const;
protected:
virtual void DoDispose (void);
private:
+ CcnxFace (const CcnxFace &) {} ///< Disabled copy constructor
+ CcnxFace& operator= (const CcnxFace &) {} ///< Disabled copy operator
+
+protected:
bool m_ifup;
+ uint32_t m_id; ///< id of the interface in the CCNx stack (per-node uniqueness)
uint16_t m_metric;
Ptr<Node> m_node;
- Ptr<NetDevice> m_device;
};
std::ostream& operator<< (std::ostream& os, CcnxFace const& face);
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 2a13f4c..d698356 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -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>
+ */
#include "ccnx-l3-protocol.h"
@@ -72,6 +72,7 @@
}
CcnxL3Protocol::CcnxL3Protocol()
+: m_faceCounter (0)
{
NS_LOG_FUNCTION (this);
}
@@ -141,18 +142,19 @@
{
NS_LOG_FUNCTION (this << *face);
- // Ptr<Node> node = GetObject<Node> (); ///< \todo not sure why this thing should be called...
face->SetNode (m_node);
+ face->SetId (m_faceCounter); // sets a unique ID of the face. This ID serves only informational purposes
- if (face->GetDevice() != 0)
- {
- m_node->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::ReceiveFromLower, this),
- CcnxL3Protocol::ETHERNET_FRAME_TYPE, face->GetDevice(), true/*promiscuous mode*/);
- }
+ face->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::ReceiveFromLower, this));
+ // if (face->GetDevice() != 0)
+ // {
+ // m_node->RegisterProtocolHandler (MakeCallback (&CcnxL3Protocol::ReceiveFromLower, this),
+ // CcnxL3Protocol::ETHERNET_FRAME_TYPE, face->GetDevice(), true/*promiscuous mode*/);
+ // }
- uint32_t index = m_faces.size ();
m_faces.push_back (face);
- return index;
+ m_faceCounter ++;
+ return m_faceCounter;
}
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index e8a0d22..28a8d06 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -104,7 +104,8 @@
void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const;
- virtual void Send (Ptr<Packet> packet, const Ptr<CcnxFace> &face);
+ virtual void Send (const Ptr<CcnxFace> &face, Ptr<Packet> packet);
+ virtual void ReceiveFromLower (const Ptr<Face> &device, Ptr<const Packet> p);
virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
virtual uint32_t GetNFaces (void) const;
@@ -119,21 +120,6 @@
protected:
/**
- * Lower layer calls this method after calling L3Demux::Lookup
- *
- * \param device network device
- * \param p the packet
- * \param protocol lower layer protocol value
- * \param from lower layer address of the correspondant
- * \param to lower layer address of the destination
- * \param packetType type of the packet (broadcast/multicast/unicast/otherhost)
- */
- void ReceiveFromLower (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol,
- const Address &from,
- const Address &to,
- NetDevice::PacketType packetType);
-
- /**
* Actual processing of incoming CCNx packets. Also processing packets coming from local apps
*
* Processing Interest packets
@@ -175,6 +161,7 @@
ReceiveAndProcess (Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
private:
+ uint32_t m_faceCounter; ///< counter of faces. Increased every time a new face is added to the stack
typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
CcnxFaceList m_faces;
diff --git a/model/ccnx.h b/model/ccnx.h
index c7627ab..3ec6058 100644
--- a/model/ccnx.h
+++ b/model/ccnx.h
@@ -109,13 +109,24 @@
/**
* \brief Send a packet to a specified face
*
- * \param packet fully prepared CCNx packet to send
* \param face face where to send this packet
+ * \param packet fully prepared CCNx packet to send
*
* 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, const Ptr<CcnxFace> &face) = 0;
+ virtual void Send (const Ptr<CcnxFace> &face, Ptr<Packet> packet) = 0;
+
+ /**
+ * \brief Lower layers calls this method after demultiplexing
+ *
+ * Lower-layer-dependent implementation of CcnxFace will do actual work
+ * to set up demultiplexing and call this function as a callback
+ *
+ * \param face face from which packet came from
+ * \param p the packet
+ */
+ void ReceiveFromLower (const Ptr<Face> &device, Ptr<const Packet> p);
/**
* \param face The face number of an Ccnx interface.