Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2005,2006,2007 INRIA |
| 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 | * |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "ccnx-local-face.h" |
| 24 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 25 | #include "ns3/log.h" |
| 26 | #include "ns3/packet.h" |
| 27 | #include "ns3/node.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 28 | #include "ns3/assert.h" |
| 29 | |
| 30 | #include "ns3/ccnx-header-helper.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 31 | #include "ns3/ccnx-app.h" |
| 32 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 33 | #include "ccnx-interest-header.h" |
| 34 | #include "ccnx-content-object-header.h" |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("CcnxLocalFace"); |
| 37 | |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 38 | namespace ns3 |
| 39 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 41 | CcnxLocalFace::CcnxLocalFace (Ptr<CcnxApp> app) |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 42 | : CcnxFace (app->GetNode ()) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 43 | , m_app (app) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 44 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 45 | NS_LOG_FUNCTION (this << app); |
| 46 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 47 | NS_ASSERT (m_app != 0); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | CcnxLocalFace::~CcnxLocalFace () |
| 51 | { |
| 52 | NS_LOG_FUNCTION_NOARGS (); |
| 53 | } |
| 54 | |
| 55 | void |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 56 | CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 57 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 58 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 60 | CcnxFace::RegisterProtocolHandler (handler); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 62 | m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this)); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 63 | } |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 65 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 66 | CcnxLocalFace::SendImpl (Ptr<Packet> p) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 67 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 68 | NS_LOG_FUNCTION (this << p); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 70 | try |
| 71 | { |
| 72 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
| 73 | switch (type) |
| 74 | { |
| 75 | case CcnxHeaderHelper::INTEREST: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 76 | { |
| 77 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
| 78 | p->RemoveHeader (*header); |
| 79 | |
| 80 | if (header->GetNack () > 0) |
| 81 | m_app->OnNack (header); |
| 82 | else |
| 83 | m_app->OnInterest (header); |
| 84 | |
| 85 | break; |
| 86 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 87 | case CcnxHeaderHelper::CONTENT_OBJECT: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 88 | { |
| 89 | static CcnxContentObjectTail tail; |
| 90 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 91 | p->RemoveHeader (*header); |
| 92 | p->RemoveTrailer (tail); |
| 93 | m_app->OnContentObject (header, p/*payload*/); |
| 94 | |
| 95 | break; |
| 96 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | catch (CcnxUnknownHeaderException) |
| 100 | { |
| 101 | NS_LOG_ERROR ("Unknown header type"); |
| 102 | } |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 103 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 105 | std::ostream& CcnxLocalFace::Print (std::ostream& os) const |
| 106 | { |
| 107 | os << "dev=local(" << GetId() << ")"; |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 108 | return os; |
| 109 | } |
| 110 | |
| 111 | }; // namespace ns3 |
| 112 | |