22 #include "ndn-l3-protocol.h" 
   24 #include "ns3/packet.h" 
   27 #include "ns3/callback.h" 
   28 #include "ns3/uinteger.h" 
   29 #include "ns3/trace-source-accessor.h" 
   30 #include "ns3/object-vector.h" 
   31 #include "ns3/pointer.h" 
   32 #include "ns3/simulator.h" 
   33 #include "ns3/random-variable.h" 
   35 #include "ns3/ndn-pit.h" 
   36 #include "ns3/ndn-interest.h" 
   37 #include "ns3/ndn-data.h" 
   39 #include "ns3/ndn-face.h" 
   40 #include "ns3/ndn-forwarding-strategy.h" 
   42 #include "ndn-net-device-face.h" 
   44 #include <boost/foreach.hpp> 
   46 NS_LOG_COMPONENT_DEFINE (
"ndn.L3Protocol");
 
   54 NS_OBJECT_ENSURE_REGISTERED (L3Protocol);
 
   59   static TypeId tid = TypeId (
"ns3::ndn::L3Protocol")
 
   62     .AddConstructor<L3Protocol> ()
 
   63     .AddAttribute (
"FaceList", 
"List of faces associated with ndn stack",
 
   65                    MakeObjectVectorAccessor (&L3Protocol::m_faces),
 
   66                    MakeObjectVectorChecker<Face> ())
 
   74   NS_LOG_FUNCTION (
this);
 
   77 L3Protocol::~L3Protocol ()
 
   79   NS_LOG_FUNCTION (
this);
 
   92       m_node = GetObject<Node> ();
 
   95           NS_ASSERT_MSG (m_forwardingStrategy != 0,
 
   96                          "Forwarding strategy should be aggregated before L3Protocol");
 
   99   if (m_forwardingStrategy == 0)
 
  101       m_forwardingStrategy = GetObject<ForwardingStrategy> ();
 
  104   Object::NotifyNewAggregate ();
 
  110   NS_LOG_FUNCTION (
this);
 
  120   m_forwardingStrategy = 0; 
 
  122   Object::DoDispose ();
 
  128   NS_LOG_FUNCTION (
this << &face);
 
  130   face->SetId (m_faceCounter); 
 
  136   m_faces.push_back (face);
 
  139   m_forwardingStrategy->AddFace (face); 
 
  140   return face->GetId ();
 
  146   NS_LOG_FUNCTION (
this << boost::cref (*face));
 
  148   face->UnRegisterProtocolHandlers ();
 
  149   Ptr<Pit> pit = GetObject<Pit> ();
 
  152   std::list< Ptr<pit::Entry> > entriesToRemoves;
 
  153   for (Ptr<pit::Entry> pitEntry = pit->Begin (); pitEntry != 0; pitEntry = pit->Next (pitEntry))
 
  155       pitEntry->RemoveAllReferencesToFace (face);
 
  159       if (pitEntry->GetFibEntry ()->m_faces.size () == 1 &&
 
  160           pitEntry->GetFibEntry ()->m_faces.begin ()->GetFace () == face)
 
  162           entriesToRemoves.push_back (pitEntry);
 
  165   BOOST_FOREACH (Ptr<pit::Entry> removedEntry, entriesToRemoves)
 
  167       pit->MarkErased (removedEntry);
 
  170   FaceList::iterator face_it = find (m_faces.begin(), m_faces.end(), face);
 
  171   if (face_it == m_faces.end ())
 
  175   m_faces.erase (face_it);
 
  177   GetObject<Fib> ()->RemoveFromAll (face);
 
  178   m_forwardingStrategy->RemoveFace (face); 
 
  184   NS_ASSERT (0 <= index && index < m_faces.size ());
 
  185   return m_faces[index];
 
  191   BOOST_FOREACH (
const Ptr<Face> &face, m_faces) 
 
  193       if (face->GetId () == index)
 
  202   BOOST_FOREACH (
const Ptr<Face> &face, m_faces) 
 
  204       Ptr<NetDeviceFace> netDeviceFace = DynamicCast<NetDeviceFace> (face);
 
  205       if (netDeviceFace == 0) 
continue;
 
  207       if (netDeviceFace->GetNetDevice () == netDevice)
 
  216   return m_faces.size ();
 
virtual uint32_t AddFace(const Ptr< Face > &face)
Add face to Ndn stack. 
 
virtual Ptr< Face > GetFace(uint32_t face) const 
Get face by face index. 
 
virtual void OnInterest(Ptr< Face > face, Ptr< Interest > interest)
Actual processing of incoming Ndn interests. 
 
virtual uint32_t GetNFaces() const 
Get current number of faces added to Ndn stack. 
 
virtual void RemoveFace(Ptr< Face > face)
Remove face from ndn stack (remove callbacks) 
 
static TypeId GetTypeId()
Interface ID. 
 
static const uint16_t ETHERNET_FRAME_TYPE
Ethernet Frame Type of Ndn. 
 
static const uint16_t IP_STACK_PORT
TCP/UDP port for NDN stack. 
 
virtual Ptr< Face > GetFaceByNetDevice(Ptr< NetDevice > netDevice) const 
Get face for NetDevice. 
 
virtual void OnData(Ptr< Face > face, Ptr< Data > data)
Actual processing of incoming Ndn content objects. 
 
L3Protocol()
Default constructor. 
 
virtual void NotifyNewAggregate()
This function will notify other components connected to the node that a new stack member is now conne...
 
virtual void DoDispose(void)
Do cleanup. 
 
virtual Ptr< Face > GetFaceById(uint32_t face) const 
Get face by face ID.