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 | |
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 | |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 32 | NS_LOG_COMPONENT_DEFINE ("CcnxFace"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 33 | |
| 34 | namespace ns3 { |
| 35 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 36 | NS_OBJECT_ENSURE_REGISTERED (CcnxFace); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 37 | |
| 38 | TypeId |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 39 | CcnxFace::GetTypeId (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 40 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 41 | static TypeId tid = TypeId ("ns3::CcnxFace") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | .SetParent<Object> () |
| 43 | ; |
| 44 | return tid; |
| 45 | } |
| 46 | |
| 47 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 48 | * By default, Ccnx face are created in the "down" state |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 52 | CcnxFace::CcnxFace () |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | : m_ifup (false), |
| 54 | m_metric (1), |
| 55 | m_node (0), |
| 56 | m_device (0), |
| 57 | { |
| 58 | NS_LOG_FUNCTION (this); |
| 59 | } |
| 60 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 61 | CcnxFace::~CcnxFace () |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 62 | { |
| 63 | NS_LOG_FUNCTION_NOARGS (); |
| 64 | } |
| 65 | |
| 66 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 67 | CcnxFace::DoDispose (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | { |
| 69 | NS_LOG_FUNCTION_NOARGS (); |
| 70 | m_node = 0; |
| 71 | m_device = 0; |
| 72 | Object::DoDispose (); |
| 73 | } |
| 74 | |
| 75 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 76 | CcnxFace::SetNode (Ptr<Node> node) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | { |
| 78 | m_node = node; |
| 79 | } |
| 80 | |
| 81 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 82 | CcnxFace::SetDevice (Ptr<NetDevice> device) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 83 | { |
| 84 | m_device = device; |
| 85 | } |
| 86 | |
| 87 | Ptr<NetDevice> |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 88 | CcnxFace::GetDevice (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 89 | { |
| 90 | return m_device; |
| 91 | } |
| 92 | |
| 93 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 94 | CcnxFace::SetMetric (uint16_t metric) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 95 | { |
| 96 | NS_LOG_FUNCTION (metric); |
| 97 | m_metric = metric; |
| 98 | } |
| 99 | |
| 100 | uint16_t |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 101 | CcnxFace::GetMetric (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 102 | { |
| 103 | NS_LOG_FUNCTION_NOARGS (); |
| 104 | return m_metric; |
| 105 | } |
| 106 | |
| 107 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 108 | * These are face states and may be distinct from |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 109 | * NetDevice states, such as found in real implementations |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 110 | * (where the device may be down but face state is still up). |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 111 | */ |
| 112 | bool |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 113 | CcnxFace::IsUp (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 114 | { |
| 115 | NS_LOG_FUNCTION_NOARGS (); |
| 116 | return m_ifup; |
| 117 | } |
| 118 | |
| 119 | bool |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 120 | CcnxFace::IsDown (void) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 121 | { |
| 122 | NS_LOG_FUNCTION_NOARGS (); |
| 123 | return !m_ifup; |
| 124 | } |
| 125 | |
| 126 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 127 | CcnxFace::SetUp (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | { |
| 129 | NS_LOG_FUNCTION_NOARGS (); |
| 130 | m_ifup = true; |
| 131 | } |
| 132 | |
| 133 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 134 | CcnxFace::SetDown (void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 135 | { |
| 136 | NS_LOG_FUNCTION_NOARGS (); |
| 137 | m_ifup = false; |
| 138 | } |
| 139 | |
| 140 | void |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 141 | CcnxFace::Send (Ptr<Packet> packet) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 142 | { |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 143 | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 149 | if (!IsUp ()) |
| 150 | { |
| 151 | return; |
| 152 | } |
| 153 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 154 | m_device->Send (packet, m_device->GetBroadcast (), |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 155 | CcnxL3Protocol::PROT_NUMBER); |
| 156 | } |
| 157 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame^] | 158 | std::ostream& operator<< (std::ostream& os, CcnxFace const& face) |
| 159 | { |
| 160 | os << "dev=" << face.GetDevice ()->GetIfIndex (); |
| 161 | return os; |
| 162 | } |
| 163 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 164 | }; // namespace ns3 |
| 165 | |