blob: 4ea8189a0dd57c815239b17a7ac87bcd45550edd [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevab1d5602011-08-17 19:17:18 -07002/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko172763c2011-10-28 13:21:53 -070019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyevab1d5602011-08-17 19:17:18 -070020 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070021
Alexander Afanasyev0c395372014-12-20 15:54:02 -080022#include "ndn-l3-protocol.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070023
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070024#include "ns3/packet.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/node.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070026#include "ns3/log.h"
27#include "ns3/callback.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070028#include "ns3/uinteger.h"
29#include "ns3/trace-source-accessor.h"
30#include "ns3/object-vector.h"
Alexander Afanasyevcbe92ae2011-12-16 13:06:18 -080031#include "ns3/pointer.h"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080032#include "ns3/simulator.h"
Alexander Afanasyevff8c5d62012-04-25 15:14:51 -070033#include "ns3/random-variable.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070034
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070035#include "ndn-face.hpp"
Alexander Afanasyev0c395372014-12-20 15:54:02 -080036#include "ndn-net-device-face.hpp"
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -080037
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070038#include <boost/foreach.hpp>
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041
42namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043namespace ndn {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777;
Alexander Afanasyev016a5d82013-07-15 10:41:29 -070046const uint16_t L3Protocol::IP_STACK_PORT = 9695;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070047
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048NS_OBJECT_ENSURE_REGISTERED(L3Protocol);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070049
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080050TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051L3Protocol::GetTypeId(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070052{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 static TypeId tid =
54 TypeId("ns3::ndn::L3Protocol")
55 .SetGroupName("ndn")
56 .SetParent<Object>()
57 .AddConstructor<L3Protocol>()
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070058 ;
59 // .AddAttribute("FaceList", "List of faces associated with ndn stack", ObjectVectorValue(),
60 // MakeObjectVectorAccessor(&L3Protocol::m_faces),
61 // MakeObjectVectorChecker<Face>());
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070062 return tid;
63}
64
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065L3Protocol::L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068}
69
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070L3Protocol::~L3Protocol()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073}
74
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075/*
76 * This method is called by AddAgregate and completes the aggregation
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070077 * by setting the node in the ndn stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078 */
79void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080L3Protocol::NotifyNewAggregate()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081{
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070082 // not really efficient, but this will work only once
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 if (m_node == 0) {
84 m_node = GetObject<Node>();
85 if (m_node != 0) {
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 }
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070088
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070089 Object::NotifyNewAggregate ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090}
91
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080092void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093L3Protocol::DoDispose(void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 NS_LOG_FUNCTION(this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070096
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070097 m_node = 0;
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080098
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080099 Object::DoDispose();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100}
101
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800102uint32_t
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700103L3Protocol::AddFace(const shared_ptr<Face>& face)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700104{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 NS_LOG_FUNCTION(this << &face);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700106
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700107 return 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108}
109
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700110void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700111L3Protocol::RemoveFace(shared_ptr<Face> face)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700112{
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700113 NS_LOG_FUNCTION(this << std::cref(*face));
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700114}
115
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700116shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117L3Protocol::GetFace(uint32_t index) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700118{
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700119 return nullptr;
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700120}
121
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700122shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123L3Protocol::GetFaceById(uint32_t index) const
Alexander Afanasyevaebf5cf2012-08-28 17:32:17 -0700124{
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700125 return nullptr;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700126}
127
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700128shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129L3Protocol::GetFaceByNetDevice(Ptr<NetDevice> netDevice) const
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800130{
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700131 return nullptr;
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800132}
133
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800134uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135L3Protocol::GetNFaces(void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136{
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700137 return 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700138}
139
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140} // namespace ndn
141} // namespace ns3