diff --git a/SConstruct b/SConstruct index b89015f4c..db7883eff 100644 --- a/SConstruct +++ b/SConstruct @@ -256,6 +256,7 @@ node.add_sources ([ 'random-rectangle-topology.cc', 'random-walk-mobility-model.cc', 'random-direction-mobility-model.cc', + 'hierarchical-mobility-model.cc', ]) node.add_inst_headers ([ 'node.h', @@ -281,6 +282,7 @@ node.add_inst_headers ([ 'random-rectangle-topology.h', 'random-walk-mobility-model.h', 'random-direction-mobility-model.h', + 'hierarchical-mobility-model.h', ]) applications = build.Ns3Module ('applications', 'src/applications') diff --git a/src/node/hierarchical-mobility-model.cc b/src/node/hierarchical-mobility-model.cc new file mode 100644 index 000000000..2c2e84f21 --- /dev/null +++ b/src/node/hierarchical-mobility-model.cc @@ -0,0 +1,95 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#include "hierarchical-mobility-model.h" +#include "mobility-model-notifier.h" + +namespace ns3 { + +HierarchicalMobilityModel::HierarchicalMobilityModel (Ptr child, Ptr parent) + : m_child (child), + m_parent (parent) +{ + Ptr childNotifier = + m_child->QueryInterface (MobilityModelNotifier::iid); + Ptr parentNotifier = + m_parent->QueryInterface (MobilityModelNotifier::iid); + if (childNotifier == 0) + { + childNotifier = Create (); + child->AddInterface (childNotifier); + } + if (parentNotifier == 0) + { + parentNotifier = Create (); + parent->AddInterface (parentNotifier); + } + childNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ChildChanged, this)); + parentNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ParentChanged, this)); +} + +Ptr +HierarchicalMobilityModel::GetChild (void) const +{ + return m_child; +} + +Ptr +HierarchicalMobilityModel::GetParent (void) const +{ + return m_parent; +} + +Position +HierarchicalMobilityModel::DoGet (void) const +{ + Position parentPosition = m_parent->Get (); + Position childPosition = m_child->Get (); + return Position (parentPosition.x + childPosition.x, + parentPosition.y + childPosition.y, + parentPosition.z + childPosition.z); +} +void +HierarchicalMobilityModel::DoSet (const Position &position) +{ + // This implementation of DoSet is really an arbitraty choice. + // anything else would have been ok. + Position parentPosition = m_parent->Get (); + Position childPosition (position.x - parentPosition.x, + position.y - parentPosition.y, + position.z - parentPosition.z); + m_child->Set (childPosition); +} + +void +HierarchicalMobilityModel::ParentChanged (Ptr model) +{ + MobilityModel::NotifyCourseChange (); +} + +void +HierarchicalMobilityModel::ChildChanged (Ptr model) +{ + MobilityModel::NotifyCourseChange (); +} + + + +} // namespace ns3 diff --git a/src/node/hierarchical-mobility-model.h b/src/node/hierarchical-mobility-model.h new file mode 100644 index 000000000..a1bb61713 --- /dev/null +++ b/src/node/hierarchical-mobility-model.h @@ -0,0 +1,52 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#ifndef HIERARCHICAL_MOBILITY_MODEL_H +#define HIERARCHICAL_MOBILITY_MODEL_H + +#include "mobility-model.h" + +namespace ns3 { + +class HierarchicalMobilityModel : public MobilityModel +{ +public: + static const InterfaceId iid; + + HierarchicalMobilityModel (Ptr child, Ptr parent); + + Ptr GetChild (void) const; + Ptr GetParent (void) const; + +private: + virtual Position DoGet (void) const; + virtual void DoSet (const Position &position); + + void ParentChanged (Ptr model); + void ChildChanged (Ptr model); + + Ptr m_child; + Ptr m_parent; +}; + + +} // namespace ns3 + +#endif /* HIERARCHICAL_MOBILITY_MODEL_H */