blob: d42515fef25e4f820e95c6195397988244bf2ec9 [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"
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080023#include "ccnx-l3-protocol.h"
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070024
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070025#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 Afanasyev09c7deb2011-11-23 14:50:10 -080039CcnxNetDeviceFace::CcnxNetDeviceFace (Ptr<Node> node, const Ptr<NetDevice> &netDevice)
40 : CcnxFace (node)
41 , m_netDevice (netDevice)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070042{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080043 NS_LOG_FUNCTION (this << netDevice);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070044
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080045 NS_ASSERT_MSG (m_netDevice != 0, "CcnxNetDeviceFace needs to be assigned a valid NetDevice");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070046}
47
48CcnxNetDeviceFace::~CcnxNetDeviceFace ()
49{
50 NS_LOG_FUNCTION_NOARGS ();
51}
52
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070053CcnxNetDeviceFace& CcnxNetDeviceFace::operator= (const CcnxNetDeviceFace &)
54{
55 return *this;
56}
57
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070058Ptr<NetDevice>
59CcnxNetDeviceFace::GetNetDevice () const
60{
61 return m_netDevice;
62}
63
64void
65CcnxNetDeviceFace::RegisterProtocolHandler (ProtocolHandler handler)
66{
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080067 NS_LOG_FUNCTION (this);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070068
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080069 CcnxFace::RegisterProtocolHandler (handler);
70
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070071 m_node->RegisterProtocolHandler (MakeCallback (&CcnxNetDeviceFace::ReceiveFromNetDevice, this),
72 CcnxL3Protocol::ETHERNET_FRAME_TYPE, m_netDevice, true/*promiscuous mode*/);
73}
74
75void
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080076CcnxNetDeviceFace::SendImpl (Ptr<Packet> packet)
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070077{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080078 NS_LOG_FUNCTION (this << packet);
79
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070080 NS_ASSERT_MSG (packet->GetSize () <= m_netDevice->GetMtu (),
81 "Packet size " << packet->GetSize () << " exceeds device MTU "
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080082 << m_netDevice->GetMtu ()
83 << " for Ccnx; fragmentation not supported");
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070084
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070085 m_netDevice->Send (packet, m_netDevice->GetBroadcast (),
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080086 CcnxL3Protocol::ETHERNET_FRAME_TYPE);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070087}
88
89// callback
90void
91CcnxNetDeviceFace::ReceiveFromNetDevice (Ptr<NetDevice> device,
92 Ptr<const Packet> p,
93 uint16_t protocol,
94 const Address &from,
95 const Address &to,
96 NetDevice::PacketType packetType)
97{
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080098 NS_LOG_FUNCTION (device << p << protocol << from << to << packetType);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080099 Receive (p);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700100}
101
102
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103std::ostream&
104CcnxNetDeviceFace::Print (std::ostream& os) const
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700105{
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700106 os << "dev=net(" << GetId () << ")";
107 return os;
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700108}
109
110}; // namespace ns3
111