blob: aca2dcdda862811084406114fb911c751ba0545c [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
22#include "ccnx-interface.h"
23
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
32NS_LOG_COMPONENT_DEFINE ("CcnxInterface");
33
34namespace ns3 {
35
36NS_OBJECT_ENSURE_REGISTERED (CcnxInterface);
37
38TypeId
39CcnxInterface::GetTypeId (void)
40{
41 static TypeId tid = TypeId ("ns3::CcnxInterface")
42 .SetParent<Object> ()
43 ;
44 return tid;
45}
46
47/**
48 * By default, Ccnx interface are created in the "down" state
49 * 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 */
52CcnxInterface::CcnxInterface ()
53 : m_ifup (false),
54 m_metric (1),
55 m_node (0),
56 m_device (0),
57{
58 NS_LOG_FUNCTION (this);
59}
60
61CcnxInterface::~CcnxInterface ()
62{
63 NS_LOG_FUNCTION_NOARGS ();
64}
65
66void
67CcnxInterface::DoDispose (void)
68{
69 NS_LOG_FUNCTION_NOARGS ();
70 m_node = 0;
71 m_device = 0;
72 Object::DoDispose ();
73}
74
75void
76CcnxInterface::SetNode (Ptr<Node> node)
77{
78 m_node = node;
79}
80
81void
82CcnxInterface::SetDevice (Ptr<NetDevice> device)
83{
84 m_device = device;
85}
86
87Ptr<NetDevice>
88CcnxInterface::GetDevice (void) const
89{
90 return m_device;
91}
92
93void
94CcnxInterface::SetMetric (uint16_t metric)
95{
96 NS_LOG_FUNCTION (metric);
97 m_metric = metric;
98}
99
100uint16_t
101CcnxInterface::GetMetric (void) const
102{
103 NS_LOG_FUNCTION_NOARGS ();
104 return m_metric;
105}
106
107/**
108 * These are interface states and may be distinct from
109 * NetDevice states, such as found in real implementations
110 * (where the device may be down but interface state is still up).
111 */
112bool
113CcnxInterface::IsUp (void) const
114{
115 NS_LOG_FUNCTION_NOARGS ();
116 return m_ifup;
117}
118
119bool
120CcnxInterface::IsDown (void) const
121{
122 NS_LOG_FUNCTION_NOARGS ();
123 return !m_ifup;
124}
125
126void
127CcnxInterface::SetUp (void)
128{
129 NS_LOG_FUNCTION_NOARGS ();
130 m_ifup = true;
131}
132
133void
134CcnxInterface::SetDown (void)
135{
136 NS_LOG_FUNCTION_NOARGS ();
137 m_ifup = false;
138}
139
140void
141CcnxInterface::Send (Ptr<Packet> p)
142{
143 NS_LOG_FUNCTION (*p);
144 if (!IsUp ())
145 {
146 return;
147 }
148
149 // Check if Local Delivery
150 // if (DynamicCast<LoopbackNetDevice> (m_device))
151 // {
152 // // XXX additional checks needed here (such as whether multicast
153 // // goes to loopback)?
154 // m_device->Send (p, m_device->GetBroadcast (),
155 // CcnxL3Protocol::PROT_NUMBER);
156 // return;
157 // }
158
159 NS_LOG_LOGIC ("Doesn't need ARP");
160 m_device->Send (p, m_device->GetBroadcast (),
161 CcnxL3Protocol::PROT_NUMBER);
162}
163
164}; // namespace ns3
165