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 | /* |
Ilya Moiseenko | 956d054 | 2012-01-02 15:26:40 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 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 | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 41 | TypeId |
| 42 | CcnxLocalFace::GetTypeId () |
| 43 | { |
| 44 | static TypeId tid = TypeId ("ns3::CcnxLocalFace") |
| 45 | .SetParent<CcnxFace> () |
| 46 | .SetGroupName ("Ccnx") |
| 47 | ; |
| 48 | return tid; |
| 49 | } |
| 50 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 51 | CcnxLocalFace::CcnxLocalFace (Ptr<CcnxApp> app) |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 52 | : CcnxFace (app->GetNode ()) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 53 | , m_app (app) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 54 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 55 | NS_LOG_FUNCTION (this << app); |
| 56 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 57 | NS_ASSERT (m_app != 0); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | CcnxLocalFace::~CcnxLocalFace () |
| 61 | { |
| 62 | NS_LOG_FUNCTION_NOARGS (); |
| 63 | } |
| 64 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 65 | CcnxLocalFace::CcnxLocalFace () |
| 66 | : CcnxFace (0) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | CcnxLocalFace::CcnxLocalFace (const CcnxLocalFace &) |
| 71 | : CcnxFace (0) |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | CcnxLocalFace& CcnxLocalFace::operator= (const CcnxLocalFace &) |
| 76 | { |
| 77 | return *((CcnxLocalFace*)0); |
| 78 | } |
| 79 | |
| 80 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 81 | void |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 82 | CcnxLocalFace::RegisterProtocolHandler (ProtocolHandler handler) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 83 | { |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 84 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 86 | CcnxFace::RegisterProtocolHandler (handler); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 88 | m_app->RegisterProtocolHandler (MakeCallback (&CcnxFace::Receive, this)); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 89 | } |
Ilya Moiseenko | acac1ea | 2011-10-28 13:16:53 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 91 | void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 92 | CcnxLocalFace::SendImpl (Ptr<Packet> p) |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 93 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 94 | NS_LOG_FUNCTION (this << p); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 96 | try |
| 97 | { |
| 98 | CcnxHeaderHelper::Type type = CcnxHeaderHelper::GetCcnxHeaderType (p); |
| 99 | switch (type) |
| 100 | { |
| 101 | case CcnxHeaderHelper::INTEREST: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 102 | { |
| 103 | Ptr<CcnxInterestHeader> header = Create<CcnxInterestHeader> (); |
| 104 | p->RemoveHeader (*header); |
| 105 | |
| 106 | if (header->GetNack () > 0) |
| 107 | m_app->OnNack (header); |
| 108 | else |
| 109 | m_app->OnInterest (header); |
| 110 | |
| 111 | break; |
| 112 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 113 | case CcnxHeaderHelper::CONTENT_OBJECT: |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 114 | { |
| 115 | static CcnxContentObjectTail tail; |
| 116 | Ptr<CcnxContentObjectHeader> header = Create<CcnxContentObjectHeader> (); |
| 117 | p->RemoveHeader (*header); |
| 118 | p->RemoveTrailer (tail); |
| 119 | m_app->OnContentObject (header, p/*payload*/); |
| 120 | |
| 121 | break; |
| 122 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | catch (CcnxUnknownHeaderException) |
| 126 | { |
| 127 | NS_LOG_ERROR ("Unknown header type"); |
| 128 | } |
Ilya Moiseenko | 1cf6b0a | 2011-08-29 13:02:34 -0700 | [diff] [blame] | 129 | } |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 131 | std::ostream& CcnxLocalFace::Print (std::ostream& os) const |
| 132 | { |
| 133 | os << "dev=local(" << GetId() << ")"; |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 134 | return os; |
| 135 | } |
| 136 | |
| 137 | }; // namespace ns3 |
| 138 | |