Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("CcnxInterface"); |
| 33 | |
| 34 | namespace ns3 { |
| 35 | |
| 36 | NS_OBJECT_ENSURE_REGISTERED (CcnxInterface); |
| 37 | |
| 38 | TypeId |
| 39 | CcnxInterface::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 | */ |
| 52 | CcnxInterface::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 | |
| 61 | CcnxInterface::~CcnxInterface () |
| 62 | { |
| 63 | NS_LOG_FUNCTION_NOARGS (); |
| 64 | } |
| 65 | |
| 66 | void |
| 67 | CcnxInterface::DoDispose (void) |
| 68 | { |
| 69 | NS_LOG_FUNCTION_NOARGS (); |
| 70 | m_node = 0; |
| 71 | m_device = 0; |
| 72 | Object::DoDispose (); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | CcnxInterface::SetNode (Ptr<Node> node) |
| 77 | { |
| 78 | m_node = node; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | CcnxInterface::SetDevice (Ptr<NetDevice> device) |
| 83 | { |
| 84 | m_device = device; |
| 85 | } |
| 86 | |
| 87 | Ptr<NetDevice> |
| 88 | CcnxInterface::GetDevice (void) const |
| 89 | { |
| 90 | return m_device; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | CcnxInterface::SetMetric (uint16_t metric) |
| 95 | { |
| 96 | NS_LOG_FUNCTION (metric); |
| 97 | m_metric = metric; |
| 98 | } |
| 99 | |
| 100 | uint16_t |
| 101 | CcnxInterface::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 | */ |
| 112 | bool |
| 113 | CcnxInterface::IsUp (void) const |
| 114 | { |
| 115 | NS_LOG_FUNCTION_NOARGS (); |
| 116 | return m_ifup; |
| 117 | } |
| 118 | |
| 119 | bool |
| 120 | CcnxInterface::IsDown (void) const |
| 121 | { |
| 122 | NS_LOG_FUNCTION_NOARGS (); |
| 123 | return !m_ifup; |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | CcnxInterface::SetUp (void) |
| 128 | { |
| 129 | NS_LOG_FUNCTION_NOARGS (); |
| 130 | m_ifup = true; |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | CcnxInterface::SetDown (void) |
| 135 | { |
| 136 | NS_LOG_FUNCTION_NOARGS (); |
| 137 | m_ifup = false; |
| 138 | } |
| 139 | |
| 140 | void |
| 141 | CcnxInterface::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 | |