Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 22 | #include "ccnx-face.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 31 | NS_LOG_COMPONENT_DEFINE ("CcnxFace"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ns3 { |
| 34 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 35 | NS_OBJECT_ENSURE_REGISTERED (CcnxFace); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 36 | |
| 37 | TypeId |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 38 | CcnxFace::GetTypeId (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 39 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 40 | static TypeId tid = TypeId ("ns3::CcnxFace") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | .SetParent<Object> () |
| 42 | ; |
| 43 | return tid; |
| 44 | } |
| 45 | |
| 46 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 47 | * By default, Ccnx face are created in the "down" state |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 48 | * with no IP addresses. Before becoming useable, the user must |
| 49 | * invoke SetUp on them once an Ccnx address and mask have been set. |
| 50 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 51 | CcnxFace::CcnxFace () |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 52 | : m_ifup (false) |
| 53 | , m_metric (1) |
| 54 | , m_node (0) |
| 55 | , m_device (0) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 56 | { |
| 57 | NS_LOG_FUNCTION (this); |
| 58 | } |
| 59 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 60 | CcnxFace::~CcnxFace () |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | { |
| 62 | NS_LOG_FUNCTION_NOARGS (); |
| 63 | } |
| 64 | |
| 65 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 66 | CcnxFace::DoDispose (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 67 | { |
| 68 | NS_LOG_FUNCTION_NOARGS (); |
| 69 | m_node = 0; |
| 70 | m_device = 0; |
| 71 | Object::DoDispose (); |
| 72 | } |
| 73 | |
| 74 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 75 | CcnxFace::SetNode (Ptr<Node> node) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | { |
| 77 | m_node = node; |
| 78 | } |
| 79 | |
| 80 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 81 | CcnxFace::SetDevice (Ptr<NetDevice> device) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 82 | { |
| 83 | m_device = device; |
| 84 | } |
| 85 | |
| 86 | Ptr<NetDevice> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 87 | CcnxFace::GetDevice (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 88 | { |
| 89 | return m_device; |
| 90 | } |
| 91 | |
| 92 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 93 | CcnxFace::SetMetric (uint16_t metric) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | { |
| 95 | NS_LOG_FUNCTION (metric); |
| 96 | m_metric = metric; |
| 97 | } |
| 98 | |
| 99 | uint16_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 100 | CcnxFace::GetMetric (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | { |
| 102 | NS_LOG_FUNCTION_NOARGS (); |
| 103 | return m_metric; |
| 104 | } |
| 105 | |
| 106 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 107 | * These are face states and may be distinct from |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 108 | * NetDevice states, such as found in real implementations |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 109 | * (where the device may be down but face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 110 | */ |
| 111 | bool |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 112 | CcnxFace::IsUp (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 113 | { |
| 114 | NS_LOG_FUNCTION_NOARGS (); |
| 115 | return m_ifup; |
| 116 | } |
| 117 | |
| 118 | bool |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 119 | CcnxFace::IsDown (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | { |
| 121 | NS_LOG_FUNCTION_NOARGS (); |
| 122 | return !m_ifup; |
| 123 | } |
| 124 | |
| 125 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 126 | CcnxFace::SetUp (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | { |
| 128 | NS_LOG_FUNCTION_NOARGS (); |
| 129 | m_ifup = true; |
| 130 | } |
| 131 | |
| 132 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 133 | CcnxFace::SetDown (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 134 | { |
| 135 | NS_LOG_FUNCTION_NOARGS (); |
| 136 | m_ifup = false; |
| 137 | } |
| 138 | |
| 139 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 140 | CcnxFace::Send (Ptr<Packet> packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 141 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 142 | NS_ASSERT_MSG (packet->GetSize () <= GetDevice ()->GetMtu (), |
| 143 | "Packet size " << packet->GetSize () << " exceeds device MTU " |
| 144 | << GetDevice ()->GetMtu () |
| 145 | << " for Ccnx; fragmentation not supported"); |
| 146 | |
| 147 | NS_LOG_FUNCTION (*packet); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 148 | if (!IsUp ()) |
| 149 | { |
| 150 | return; |
| 151 | } |
| 152 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 153 | m_device->Send (packet, m_device->GetBroadcast (), |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame^] | 154 | CcnxL3Protocol::ETHERNET_FRAME_TYPE); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 157 | std::ostream& operator<< (std::ostream& os, CcnxFace const& face) |
| 158 | { |
| 159 | os << "dev=" << face.GetDevice ()->GetIfIndex (); |
| 160 | return os; |
| 161 | } |
| 162 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | }; // namespace ns3 |
| 164 | |