blob: 27483b0d16daeaf6a7e80f38b771e43564efdd4e [file] [log] [blame]
Alexander Afanasyev08d984e2011-08-13 19:20:22 -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:
19 *
20 */
21
Alexander Afanasyev98256102011-08-14 01:00:02 -070022#include "ccnx-face.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
24#include "ns3/ccnx-address.h"
25#include "ns3/ccnx-l3-protocol.h"
26#include "ns3/net-device.h"
27#include "ns3/log.h"
28#include "ns3/packet.h"
29#include "ns3/node.h"
30#include "ns3/pointer.h"
31
Alexander Afanasyev98256102011-08-14 01:00:02 -070032NS_LOG_COMPONENT_DEFINE ("CcnxFace");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033
34namespace ns3 {
35
Alexander Afanasyev98256102011-08-14 01:00:02 -070036NS_OBJECT_ENSURE_REGISTERED (CcnxFace);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037
38TypeId
Alexander Afanasyev98256102011-08-14 01:00:02 -070039CcnxFace::GetTypeId (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070040{
Alexander Afanasyev98256102011-08-14 01:00:02 -070041 static TypeId tid = TypeId ("ns3::CcnxFace")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042 .SetParent<Object> ()
43 ;
44 return tid;
45}
46
47/**
Alexander Afanasyev98256102011-08-14 01:00:02 -070048 * By default, Ccnx face are created in the "down" state
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070049 * with no IP addresses. Before becoming useable, the user must
50 * invoke SetUp on them once an Ccnx address and mask have been set.
51 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070052CcnxFace::CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053 : m_ifup (false),
54 m_metric (1),
55 m_node (0),
56 m_device (0),
57{
58 NS_LOG_FUNCTION (this);
59}
60
Alexander Afanasyev98256102011-08-14 01:00:02 -070061CcnxFace::~CcnxFace ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070062{
63 NS_LOG_FUNCTION_NOARGS ();
64}
65
66void
Alexander Afanasyev98256102011-08-14 01:00:02 -070067CcnxFace::DoDispose (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068{
69 NS_LOG_FUNCTION_NOARGS ();
70 m_node = 0;
71 m_device = 0;
72 Object::DoDispose ();
73}
74
75void
Alexander Afanasyev98256102011-08-14 01:00:02 -070076CcnxFace::SetNode (Ptr<Node> node)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077{
78 m_node = node;
79}
80
81void
Alexander Afanasyev98256102011-08-14 01:00:02 -070082CcnxFace::SetDevice (Ptr<NetDevice> device)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083{
84 m_device = device;
85}
86
87Ptr<NetDevice>
Alexander Afanasyev98256102011-08-14 01:00:02 -070088CcnxFace::GetDevice (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070089{
90 return m_device;
91}
92
93void
Alexander Afanasyev98256102011-08-14 01:00:02 -070094CcnxFace::SetMetric (uint16_t metric)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070095{
96 NS_LOG_FUNCTION (metric);
97 m_metric = metric;
98}
99
100uint16_t
Alexander Afanasyev98256102011-08-14 01:00:02 -0700101CcnxFace::GetMetric (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102{
103 NS_LOG_FUNCTION_NOARGS ();
104 return m_metric;
105}
106
107/**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700108 * These are face states and may be distinct from
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 * NetDevice states, such as found in real implementations
Alexander Afanasyev98256102011-08-14 01:00:02 -0700110 * (where the device may be down but face state is still up).
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700111 */
112bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700113CcnxFace::IsUp (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114{
115 NS_LOG_FUNCTION_NOARGS ();
116 return m_ifup;
117}
118
119bool
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120CcnxFace::IsDown (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121{
122 NS_LOG_FUNCTION_NOARGS ();
123 return !m_ifup;
124}
125
126void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700127CcnxFace::SetUp (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128{
129 NS_LOG_FUNCTION_NOARGS ();
130 m_ifup = true;
131}
132
133void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700134CcnxFace::SetDown (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135{
136 NS_LOG_FUNCTION_NOARGS ();
137 m_ifup = false;
138}
139
140void
Alexander Afanasyev98256102011-08-14 01:00:02 -0700141CcnxFace::Send (Ptr<Packet> packet)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142{
Alexander Afanasyev98256102011-08-14 01:00:02 -0700143 NS_ASSERT_MSG (packet->GetSize () <= GetDevice ()->GetMtu (),
144 "Packet size " << packet->GetSize () << " exceeds device MTU "
145 << GetDevice ()->GetMtu ()
146 << " for Ccnx; fragmentation not supported");
147
148 NS_LOG_FUNCTION (*packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149 if (!IsUp ())
150 {
151 return;
152 }
153
Alexander Afanasyev98256102011-08-14 01:00:02 -0700154 m_device->Send (packet, m_device->GetBroadcast (),
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700155 CcnxL3Protocol::PROT_NUMBER);
156}
157
Alexander Afanasyev98256102011-08-14 01:00:02 -0700158std::ostream& operator<< (std::ostream& os, CcnxFace const& face)
159{
160 os << "dev=" << face.GetDevice ()->GetIfIndex ();
161 return os;
162}
163
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700164}; // namespace ns3
165