ns-3 PLC model
model/plc-graph.h
00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
00002 /*
00003  * Copyright (c) 2012 University of British Columbia, Vancouver
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation;
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  * Author: Alexander Schloegl <alexander.schloegl@gmx.de>
00019  */
00020 
00021 #ifndef PLC_GRAPH_H_
00022 #define PLC_GRAPH_H_
00023 
00024 #include <map>
00025 
00026 #include <ns3/type-id.h>
00027 
00028 #include "plc-defs.h"
00029 #include "plc-node.h"
00030 #include "plc-channel.h"
00031 
00032 namespace ns3 {
00033 
00034 class PLC_Outlet;
00035 class PLC_BranchDiscoverVisitor;
00036 class PLC_TxInterface;
00037 class PLC_RxInterface;
00038 class PLC_Channel;
00039 
00051 class PLC_Graph : public Object
00052 {
00053         friend class PLC_TxInterface;
00054 
00055 public:
00056         static TypeId GetTypeId(void);
00057 
00058         PLC_Graph();
00059         ~PLC_Graph(void) {}
00060 
00066         void AddNode(Ptr<PLC_Node> node);
00067 
00072         void SetChannel(Ptr<PLC_Channel> channel) { this->m_channel = channel; }
00073 
00078         Ptr<PLC_Channel> GetChannel(void)
00079         {
00080                 NS_ASSERT_MSG(m_channel, "Channel for the graph has not been created yet");
00081                 return this->m_channel;
00082         }
00083 
00084         Ptr<PLC_Channel> GetChannel(void) const
00085         {
00086                 NS_ASSERT_MSG(m_channel, "Channel for the graph has not been created yet");
00087                 return this->m_channel;
00088         }
00089 
00094         std::vector<Ptr<PLC_RxInterface> > GetConnectedRxInterfaces();
00095         std::vector<PLC_RxInterface *> GetConnectedRxInterfacePeekPtrs(void);
00096 
00102         void CreatePLCGraph(void);
00103 
00109         Ptr<PLC_Node> GetNodePtr(unsigned int id);
00110         PLC_Node *GetNodePeekPtr(unsigned int id);
00111 
00112         std::vector<Ptr<PLC_Node> > GetNodes(void) { return m_nodes; }
00113 
00119         boost::UGraph *GetGraphPtr(void) { return &this->m_graph; }
00120 
00129         std::list<Ptr<PLC_Node> > GetShortestPath(Ptr<PLC_Node> from, Ptr<PLC_Node> to);
00130 
00138         double GetDistance(Ptr<PLC_Node> from, Ptr<PLC_Node> to);
00139 
00145         bool BackboneBranchExists(PLC_BackboneBranchKey key);
00146 
00152         void RegisterBackboneBranch(PLC_BackboneBranchKey bb_key, Ptr<PLC_BackboneBranch> bb_branch);
00153 
00159         Ptr<PLC_BackboneBranch> GetBackboneBranch(PLC_BackboneBranchKey bb_key);
00160 
00167         bool PathExists(Ptr<PLC_Node> from, Ptr<PLC_Node> to);
00168 
00172         void Lock() { m_graph_mutex.Lock(); }
00173 
00177         void Unlock() { m_graph_mutex.Unlock(); }
00178 
00179 protected:
00180         virtual void DoStart(void);
00181         virtual void DoDispose(void);
00182 
00183         void CalculateShortestPaths(void);
00184 
00185         boost::UGraph           m_graph;
00186         mutable PLC_Mutex       m_graph_mutex;
00187 
00188         Ptr<PLC_Channel>        m_channel;
00189 
00190         std::vector<Ptr<PLC_Node> > m_nodes;
00191 
00192         // key<from, to> => distance + node list
00193         std::map<std::pair<unsigned int, unsigned int>, std::pair<double, std::list<Ptr<PLC_Node> > > > m_shortest_paths;
00194         std::map<PLC_BackboneBranchKey, Ptr<PLC_BackboneBranch> > m_backbone_branches;
00195 };
00196 
00197 }
00198 
00199 #endif /* PLC_GRAPH_H_ */
 All Classes Functions Variables Enumerations