Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 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 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "ccnx-net-device-face.h" |
| 23 | |
| 24 | #include "ns3/ccnx-l3-protocol.h" |
| 25 | #include "ns3/net-device.h" |
| 26 | #include "ns3/log.h" |
| 27 | #include "ns3/packet.h" |
| 28 | #include "ns3/node.h" |
| 29 | #include "ns3/pointer.h" |
| 30 | |
| 31 | NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace"); |
| 32 | |
| 33 | namespace ns3 { |
| 34 | |
| 35 | NS_OBJECT_ENSURE_REGISTERED (CcnxNetDeviceFace); |
| 36 | |
| 37 | TypeId |
| 38 | CcnxNetDeviceFace::GetTypeId () |
| 39 | { |
| 40 | static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace") |
| 41 | .SetParent<CcnxFace> () |
| 42 | ; |
| 43 | return tid; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * By default, Ccnx face are created in the "down" state |
| 48 | * with no IP addresses. Before becoming useable, the user must |
| 49 | * invoke SetUp on them once an Ccnx address and mask have been set. |
| 50 | */ |
| 51 | CcnxNetDeviceFace::CcnxNetDeviceFace () |
| 52 | : m_netDevice (0) |
| 53 | { |
| 54 | NS_LOG_FUNCTION (this); |
| 55 | } |
| 56 | |
| 57 | CcnxNetDeviceFace::~CcnxNetDeviceFace () |
| 58 | { |
| 59 | NS_LOG_FUNCTION_NOARGS (); |
| 60 | } |
| 61 | |
| 62 | CcnxNetDeviceFace::CcnxNetDeviceFace (const CcnxNetDeviceFace &) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &) |
| 67 | { |
| 68 | return *this; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | void |
| 73 | CcnxNetDeviceFace::DoDispose (void) |
| 74 | { |
| 75 | NS_LOG_FUNCTION_NOARGS (); |
| 76 | m_netDevice = 0; |
| 77 | Object::DoDispose (); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | CcnxNetDeviceFace::SetNetDevice (Ptr<NetDevice> netDevice) |
| 82 | { |
| 83 | m_netDevice = netDevice; |
| 84 | } |
| 85 | |
| 86 | Ptr<NetDevice> |
| 87 | CcnxNetDeviceFace::GetNetDevice () const |
| 88 | { |
| 89 | return m_netDevice; |
| 90 | } |
| 91 | |
| 92 | void |
| 93 | CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler) |
| 94 | { |
| 95 | NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned NetDevice first"); |
| 96 | |
| 97 | m_protocolHandler = handler; |
| 98 | |
| 99 | m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this), |
| 100 | CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/); |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | CcnxNetDeviceFace::Send (Ptr<Packet> packet) |
| 105 | { |
| 106 | NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (), |
| 107 | "Packet size " << packet->GetSize () << " exceeds device MTU " |
| 108 | << m_netDevice->GetMtu () |
| 109 | << " for Ccnx; fragmentation not supported"); |
| 110 | |
| 111 | NS_LOG_FUNCTION (*packet); |
| 112 | if (!IsUp ()) |
| 113 | { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | m_netDevice->Send (packet, m_netDevice->GetBroadcast (), |
| 118 | CcnxL3Protocol::ETHERNET_FRAME_TYPE); |
| 119 | } |
| 120 | |
| 121 | // callback |
| 122 | void |
| 123 | CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device, |
| 124 | Ptr<const Packet> p, |
| 125 | uint16_t protocol, |
| 126 | const Address &from, |
| 127 | const Address &to, |
| 128 | NetDevice::PacketType packetType) |
| 129 | { |
| 130 | // bla bla bla |
| 131 | } |
| 132 | |
| 133 | |
| 134 | std::ostream& operator<< (std::ostream& os, const CcnxNetDeviceFace &face) |
| 135 | { |
| 136 | return operator<< (os, static_cast<const CcnxFace&> (face)); // just call parent class for now |
| 137 | // os << "id=" << face.GetId (); |
| 138 | // return os; |
| 139 | } |
| 140 | |
| 141 | }; // namespace ns3 |
| 142 | |