Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 161a5c4 | 2012-04-17 15:14:04 -0700 | [diff] [blame] | 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 161a5c4 | 2012-04-17 15:14:04 -0700 | [diff] [blame] | 22 | #include "weights-path-stretch-tag.h" |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 23 | #include "ns3/node.h" |
| 24 | #include "ns3/names.h" |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ns3 { |
| 27 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 28 | WeightsPathStretchTag::WeightsPathStretchTag () |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 32 | void |
| 33 | WeightsPathStretchTag::AddPathInfo (Ptr<Node> node, uint32_t weight) |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 34 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 35 | m_infos.push_back (NodeWeightPair (node, weight)); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 39 | TypeId WeightsPathStretchTag::GetTypeId () |
| 40 | { |
| 41 | static TypeId tid = TypeId("ns3::WeightsPathStretchTag") |
| 42 | .SetParent<Tag>() |
| 43 | .AddConstructor<WeightsPathStretchTag>() |
| 44 | ; |
| 45 | return tid; |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 48 | // TypeId |
| 49 | // WeightsPathStretchTag::GetInstanceTypeId () const |
| 50 | // { |
| 51 | // return GetTypeId (); |
| 52 | // } |
| 53 | |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 54 | uint64_t |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 55 | WeightsPathStretchTag::GetTotalWeight () const |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 56 | { |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 57 | uint64_t total = 0; |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 58 | for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin (); info != m_infos.end (); info++) |
| 59 | { |
| 60 | total += info->weight; |
| 61 | } |
| 62 | return total; |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 65 | Ptr<Node> |
| 66 | WeightsPathStretchTag::GetSourceNode () const |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 67 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 68 | NS_ASSERT (m_infos.size () > 0); |
| 69 | return m_infos.front ().node; |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 72 | Ptr<Node> |
| 73 | WeightsPathStretchTag::GetDestinationNode () const |
| 74 | { |
| 75 | NS_ASSERT (m_infos.size () > 0); |
| 76 | return m_infos.back ().node; |
| 77 | } |
| 78 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 79 | uint32_t WeightsPathStretchTag::GetSerializedSize (void) const |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 80 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 81 | return 0; |
| 82 | // return sizeof (GetPointer (m_value.node)) + sizeof (m_value.weight); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 85 | void WeightsPathStretchTag::Serialize (TagBuffer i) const |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 86 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 87 | NS_FATAL_ERROR ("Serialization is not supported for this tag"); |
| 88 | // m_value.node->Ref (); |
| 89 | // i.WriteU64 (reinterpret_cast<uint64_t> (GetPointer (m_value.node))); |
| 90 | // i.WriteU32 (m_value.weight); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 93 | void WeightsPathStretchTag::Deserialize (TagBuffer i) |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 94 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 95 | NS_FATAL_ERROR ("Deserialization is not supported for this tag"); |
| 96 | // m_value.node = Ptr<Node> (reinterpret_cast<Node*> (i.ReadU64 ()), false); |
| 97 | // m_value.weight = i.ReadU32 (); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 100 | void WeightsPathStretchTag::Print (std::ostream &os) const |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 101 | { |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 102 | for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin (); |
| 103 | info != m_infos.end (); |
| 104 | info ++) |
| 105 | { |
| 106 | if (info != m_infos.begin ()) os << ","; |
| 107 | NS_ASSERT (info->node != 0); |
| 108 | |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 109 | os << info->node->GetId () << "(" << Names::FindName (info->node) << ")"; |
| 110 | // std::string name = Names::FindName (info->node); |
| 111 | // if (!name.empty ()) |
| 112 | // os << name; |
| 113 | // else |
| 114 | // os << info->node->GetId (); |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 115 | os << ":" << info->weight; |
| 116 | } |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 119 | } // namespace ns3 |
| 120 | |