blob: 8304711898cae63eb4129c15c70fc8bf3cd2eefc [file] [log] [blame]
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -07001/* -*- 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
31NS_LOG_COMPONENT_DEFINE ("CcnxNetDeviceFace");
32
33namespace ns3 {
34
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070035// NS_OBJECT_ENSURE_REGISTERED (CcnxNetDeviceFace);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070036
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070037// TypeId
38// CcnxNetDeviceFace::GetTypeId ()
39// {
40// static TypeId tid = TypeId ("ns3::CcnxNetDeviceFace")
41// .SetGroupName ("Ccnx")
42// .SetParent<CcnxFace> ()
43// ;
44// return tid;
45// }
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070046
47/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070048 * By default, Ccnx face are created in the "down" state. Before
49 * becoming useable, the user must invoke SetUp on the face
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070050 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070051CcnxNetDeviceFace::CcnxNetDeviceFace (const Ptr<NetDevice> &netDevice)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070052{
53 NS_LOG_FUNCTION (this);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070054
55 m_netDevice = netDevice;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070056}
57
58CcnxNetDeviceFace::~CcnxNetDeviceFace ()
59{
60 NS_LOG_FUNCTION_NOARGS ();
61}
62
63CcnxNetDeviceFace::CcnxNetDeviceFace (const CcnxNetDeviceFace &)
64{
65}
66
67CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &)
68{
69 return *this;
70}
71
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070072Ptr<NetDevice>
73CcnxNetDeviceFace::GetNetDevice () const
74{
75 return m_netDevice;
76}
77
78void
79CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler)
80{
81 NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned NetDevice first");
82
83 m_protocolHandler = handler;
84
85 m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this),
86 CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/);
87}
88
89void
90CcnxNetDeviceFace::Send (Ptr<Packet> packet)
91{
92 NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (),
93 "Packet size " << packet->GetSize () << " exceeds device MTU "
94 << m_netDevice->GetMtu ()
95 << " for Ccnx; fragmentation not supported");
96
97 NS_LOG_FUNCTION (*packet);
98 if (!IsUp ())
99 {
100 return;
101 }
102
103 m_netDevice->Send (packet, m_netDevice->GetBroadcast (),
104 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
105}
106
107// callback
108void
109CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device,
110 Ptr<const Packet> p,
111 uint16_t protocol,
112 const Address &from,
113 const Address &to,
114 NetDevice::PacketType packetType)
115{
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700116 m_protocolHandler (Ptr<CcnxFace>(this), p);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700117}
118
119
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700120std::ostream&
121CcnxNetDeviceFace::Print (std::ostream& os) const
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700122{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700123 os << "dev=net(" << GetId () << ")";
124 return os;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700125}
126
127}; // namespace ns3
128