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