blob: 12cb272aa0101692c88aa2f0e850fca6fd3cb966 [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 Afanasyev56f79ea2011-08-17 23:54:27 -070035/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070036 * By default, Ccnx face are created in the "down" state. Before
37 * becoming useable, the user must invoke SetUp on the face
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070038 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070039CcnxNetDeviceFace::CcnxNetDeviceFace (const Ptr<NetDevice> &netDevice)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070040{
41 NS_LOG_FUNCTION (this);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070042
43 m_netDevice = netDevice;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070044}
45
46CcnxNetDeviceFace::~CcnxNetDeviceFace ()
47{
48 NS_LOG_FUNCTION_NOARGS ();
49}
50
51CcnxNetDeviceFace::CcnxNetDeviceFace (const CcnxNetDeviceFace &)
52{
53}
54
55CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &)
56{
57 return *this;
58}
59
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070060Ptr<NetDevice>
61CcnxNetDeviceFace::GetNetDevice () const
62{
63 return m_netDevice;
64}
65
66void
67CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler)
68{
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070069 NS_LOG_FUNCTION(this);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070070 NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned NetDevice first");
71
72 m_protocolHandler = handler;
73
74 m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this),
75 CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/);
76}
77
78void
79CcnxNetDeviceFace::Send (Ptr<Packet> packet)
80{
81 NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (),
82 "Packet size " << packet->GetSize () << " exceeds device MTU "
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080083 << m_netDevice->GetMtu ()
84 << " for Ccnx; fragmentation not supported");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070085
86 NS_LOG_FUNCTION (*packet);
87 if (!IsUp ())
88 {
89 return;
90 }
91
92 m_netDevice->Send (packet, m_netDevice->GetBroadcast (),
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080093 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070094}
95
96// callback
97void
98CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device,
99 Ptr<const Packet> p,
100 uint16_t protocol,
101 const Address &from,
102 const Address &to,
103 NetDevice::PacketType packetType)
104{
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700105 m_protocolHandler (Ptr<CcnxFace>(this), p);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700106}
107
108
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700109std::ostream&
110CcnxNetDeviceFace::Print (std::ostream& os) const
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700111{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700112 os << "dev=net(" << GetId () << ")";
113 return os;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700114}
115
116}; // namespace ns3
117