OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2013 Universita' di Firenze, Italy |
| 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: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
| 19 */ |
| 20 #include "error-channel-sixlow.h" |
| 21 #include "ns3/simple-net-device.h" |
| 22 #include "ns3/simulator.h" |
| 23 #include "ns3/packet.h" |
| 24 #include "ns3/node.h" |
| 25 #include "ns3/log.h" |
| 26 |
| 27 NS_LOG_COMPONENT_DEFINE ("ErrorChannelSixlow") |
| 28 ; |
| 29 |
| 30 namespace ns3 { |
| 31 |
| 32 NS_OBJECT_ENSURE_REGISTERED (ErrorChannelSixlow) |
| 33 ; |
| 34 |
| 35 TypeId |
| 36 ErrorChannelSixlow::GetTypeId (void) |
| 37 { |
| 38 static TypeId tid = TypeId ("ns3::ErrorChannelSixlow") |
| 39 .SetParent<Channel> () |
| 40 .AddConstructor<ErrorChannelSixlow> () |
| 41 ; |
| 42 return tid; |
| 43 } |
| 44 |
| 45 ErrorChannelSixlow::ErrorChannelSixlow () |
| 46 { |
| 47 m_jumpingTime = Seconds (0.5); |
| 48 m_jumping = false; |
| 49 m_jumpingState = 0; |
| 50 m_duplicateTime = Seconds (0.1); |
| 51 m_duplicate = false; |
| 52 } |
| 53 |
| 54 void |
| 55 ErrorChannelSixlow::SetJumpingTime (Time delay) |
| 56 { |
| 57 m_jumpingTime = delay; |
| 58 } |
| 59 |
| 60 void |
| 61 ErrorChannelSixlow::SetJumpingMode (bool mode) |
| 62 { |
| 63 m_jumping = mode; |
| 64 m_jumpingState = 0; |
| 65 } |
| 66 |
| 67 void |
| 68 ErrorChannelSixlow::SetDuplicateTime (Time delay) |
| 69 { |
| 70 m_duplicateTime = delay; |
| 71 } |
| 72 |
| 73 void |
| 74 ErrorChannelSixlow::SetDuplicateMode (bool mode) |
| 75 { |
| 76 m_duplicate = mode; |
| 77 m_duplicateState = 0; |
| 78 } |
| 79 |
| 80 |
| 81 void |
| 82 ErrorChannelSixlow::Send (Ptr<Packet> p, uint16_t protocol, |
| 83 Mac48Address to, Mac48Address from, |
| 84 Ptr<SimpleNetDevice> sender) |
| 85 { |
| 86 NS_LOG_FUNCTION (p << protocol << to << from << sender); |
| 87 for (std::vector<Ptr<SimpleNetDevice> >::const_iterator i = m_devices.begin ()
; i != m_devices.end (); ++i) |
| 88 { |
| 89 Ptr<SimpleNetDevice> tmp = *i; |
| 90 if (tmp == sender) |
| 91 { |
| 92 continue; |
| 93 } |
| 94 if (m_jumping) |
| 95 { |
| 96 if (m_jumpingState % 2) |
| 97 { |
| 98 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds
(0), |
| 99 &SimpleNetDevice::Receive, tmp, p-
>Copy (), protocol, to, from); |
| 100 } |
| 101 else |
| 102 { |
| 103 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), m_jumpi
ngTime, |
| 104 &SimpleNetDevice::Receive, tmp, p-
>Copy (), protocol, to, from); |
| 105 } |
| 106 m_jumpingState++; |
| 107 } |
| 108 else if (m_duplicate) |
| 109 { |
| 110 if (m_duplicateState % 2) |
| 111 { |
| 112 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds
(0), |
| 113 &SimpleNetDevice::Receive, tmp, p-
>Copy (), protocol, to, from); |
| 114 } |
| 115 else |
| 116 { |
| 117 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds
(0), |
| 118 &SimpleNetDevice::Receive, tmp, p-
>Copy (), protocol, to, from); |
| 119 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), m_dupli
cateTime, |
| 120 &SimpleNetDevice::Receive, tmp, p-
>Copy (), protocol, to, from); |
| 121 } |
| 122 m_duplicateState++; |
| 123 } |
| 124 else |
| 125 { |
| 126 Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0)
, |
| 127 &SimpleNetDevice::Receive, tmp, p->Cop
y (), protocol, to, from); |
| 128 } |
| 129 } |
| 130 } |
| 131 |
| 132 void |
| 133 ErrorChannelSixlow::Add (Ptr<SimpleNetDevice> device) |
| 134 { |
| 135 m_devices.push_back (device); |
| 136 } |
| 137 |
| 138 uint32_t |
| 139 ErrorChannelSixlow::GetNDevices (void) const |
| 140 { |
| 141 return m_devices.size (); |
| 142 } |
| 143 Ptr<NetDevice> |
| 144 ErrorChannelSixlow::GetDevice (uint32_t i) const |
| 145 { |
| 146 return m_devices[i]; |
| 147 } |
| 148 |
| 149 NS_OBJECT_ENSURE_REGISTERED (BinaryErrorSixlowModel) |
| 150 ; |
| 151 |
| 152 TypeId BinaryErrorSixlowModel::GetTypeId (void) |
| 153 { |
| 154 static TypeId tid = TypeId ("ns3::BinaryErrorSixlowModel") |
| 155 .SetParent<ErrorModel> () |
| 156 .AddConstructor<BinaryErrorSixlowModel> () |
| 157 ; |
| 158 return tid; |
| 159 } |
| 160 |
| 161 BinaryErrorSixlowModel::BinaryErrorSixlowModel () |
| 162 { |
| 163 m_counter = 0; |
| 164 } |
| 165 |
| 166 BinaryErrorSixlowModel::~BinaryErrorSixlowModel () |
| 167 { |
| 168 } |
| 169 |
| 170 |
| 171 bool |
| 172 BinaryErrorSixlowModel::DoCorrupt (Ptr<Packet> p) |
| 173 { |
| 174 if (!IsEnabled ()) |
| 175 { |
| 176 return false; |
| 177 } |
| 178 bool ret = m_counter % 2; |
| 179 m_counter++; |
| 180 return ret; |
| 181 } |
| 182 |
| 183 void |
| 184 BinaryErrorSixlowModel::Reset (void) |
| 185 { |
| 186 DoReset (); |
| 187 } |
| 188 |
| 189 void |
| 190 BinaryErrorSixlowModel::DoReset (void) |
| 191 { |
| 192 m_counter = 0; |
| 193 } |
| 194 |
| 195 |
| 196 } // namespace ns3 |
OLD | NEW |