LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
11 * | 11 * |
12 * You should have received a copy of the GNU General Public License | 12 * You should have received a copy of the GNU General Public License |
13 * along with this program; if not, write to the Free Software | 13 * along with this program; if not, write to the Free Software |
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 * | 15 * |
16 * Author: Josh Pelkey <jpelkey@gatech.edu> | 16 * Author: Josh Pelkey <jpelkey@gatech.edu> |
17 */ | 17 */ |
18 | 18 |
19 #include "ns3/point-to-point-grid-helper.h" | 19 #include "ns3/point-to-point-grid-helper.h" |
20 #include "ns3/animation-interface.h" | 20 #include "ns3/animation-interface.h" |
21 #include "ns3/internet-stack-helper.h" | 21 #include "ns3/internet-stack-helper.h" |
22 #include "ns3/point-to-point-helper.h" | 22 #include "ns3/point-to-point-helper.h" |
23 #include "ns3/node-location.h" | 23 #include "ns3/canvas-location.h" |
24 #include "ns3/string.h" | 24 #include "ns3/string.h" |
25 #include "ns3/vector.h" | 25 #include "ns3/vector.h" |
26 #include "ns3/log.h" | 26 #include "ns3/log.h" |
27 | 27 |
28 NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper"); | 28 NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper"); |
29 | 29 |
30 namespace ns3 { | 30 namespace ns3 { |
31 ·· | 31 ·· |
32 PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,· | 32 PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,· |
33 uint32_t nCols,· | 33 uint32_t nCols,· |
34 PointToPointHelper pointToPoint) | 34 PointToPointHelper pointToPoint) |
35 : m_xSize (nCols), m_ySize (nRows) | 35 : m_xSize (nCols), m_ySize (nRows) |
36 { | 36 { |
| 37 // Bounds check |
| 38 if (m_xSize < 1 || m_ySize < 1 || (m_xSize < 2 && m_ySize < 2)) |
| 39 { |
| 40 NS_FATAL_ERROR ("Need more nodes for grid."); |
| 41 } |
| 42 |
37 InternetStackHelper stack; | 43 InternetStackHelper stack; |
38 | 44 |
39 for (uint32_t y = 0; y < nRows; ++y) | 45 for (uint32_t y = 0; y < nRows; ++y) |
40 { | 46 { |
41 NodeContainer rowNodes; | 47 NodeContainer rowNodes; |
42 NetDeviceContainer rowDevices; | 48 NetDeviceContainer rowDevices; |
43 NetDeviceContainer colDevices; | 49 NetDeviceContainer colDevices; |
44 | 50 |
45 for (uint32_t x = 0; x < nCols; ++x) | 51 for (uint32_t x = 0; x < nCols; ++x) |
46 { | 52 { |
47 rowNodes.Create(1); | 53 rowNodes.Create (1); |
48 | 54 |
49 // install p2p links across the row | 55 // install p2p links across the row |
50 if (x > 0) | 56 if (x > 0) |
51 { | 57 { |
52 rowDevices.Add (pointToPoint. | 58 rowDevices.Add (pointToPoint. |
53 Install (rowNodes.Get (x-1), rowNodes.Get (x))); | 59 Install (rowNodes.Get (x-1), rowNodes.Get (x))); |
54 } | 60 } |
55 | 61 |
56 // install vertical p2p links | 62 // install vertical p2p links |
57 if (y > 0) | 63 if (y > 0) |
58 { | 64 { |
59 colDevices.Add(pointToPoint. | 65 colDevices.Add(pointToPoint. |
60 Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x))); | 66 Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x))); |
61 } | 67 } |
62 } | 68 } |
63 | 69 |
64 m_nodes.push_back(rowNodes); | 70 m_nodes.push_back (rowNodes); |
65 m_rowDevices.push_back (rowDevices); | 71 m_rowDevices.push_back (rowDevices); |
66 | 72 |
67 if (y > 0) | 73 if (y > 0) |
68 m_colDevices.push_back (colDevices); | 74 m_colDevices.push_back (colDevices); |
69 } | 75 } |
70 } | 76 } |
| 77 |
| 78 PointToPointGridHelper::~PointToPointGridHelper () |
| 79 {} |
71 | 80 |
72 void | 81 void |
73 PointToPointGridHelper::InstallStack (InternetStackHelper stack) | 82 PointToPointGridHelper::InstallStack (InternetStackHelper stack) |
74 { | 83 { |
75 for (uint32_t i = 0; i < m_nodes.size (); ++i) | 84 for (uint32_t i = 0; i < m_nodes.size (); ++i) |
76 { | 85 { |
77 NodeContainer rowNodes = m_nodes[i]; | 86 NodeContainer rowNodes = m_nodes[i]; |
78 for (uint32_t j = 0; j < rowNodes.GetN (); ++j) | 87 for (uint32_t j = 0; j < rowNodes.GetN (); ++j) |
79 { | 88 { |
80 stack.Install (rowNodes.Get (j)); | 89 stack.Install (rowNodes.Get (j)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 153 } |
145 double xAdder = xDist / m_xSize; | 154 double xAdder = xDist / m_xSize; |
146 double yAdder = yDist / m_ySize; | 155 double yAdder = yDist / m_ySize; |
147 double yLoc = yDist / 2; | 156 double yLoc = yDist / 2; |
148 for (uint32_t i = 0; i < m_ySize; ++i) | 157 for (uint32_t i = 0; i < m_ySize; ++i) |
149 { | 158 { |
150 double xLoc = xDist / 2; | 159 double xLoc = xDist / 2; |
151 for (uint32_t j = 0; j < m_xSize; ++j) | 160 for (uint32_t j = 0; j < m_xSize; ++j) |
152 { | 161 { |
153 Ptr<Node> node = GetNode (i, j); | 162 Ptr<Node> node = GetNode (i, j); |
154 Ptr<NodeLocation> loc = node->GetObject<NodeLocation> (); | 163 Ptr<CanvasLocation> loc = node->GetObject<CanvasLocation> (); |
155 if (loc ==0) | 164 if (loc ==0) |
156 { | 165 { |
157 loc = CreateObject<NodeLocation> (); | 166 loc = CreateObject<CanvasLocation> (); |
158 node->AggregateObject (loc); | 167 node->AggregateObject (loc); |
159 } | 168 } |
160 Vector locVec (xLoc, yLoc, 0); | 169 Vector locVec (xLoc, yLoc, 0); |
161 loc->SetLocation (locVec); | 170 loc->SetLocation (locVec); |
162 | 171 |
163 xLoc += xAdder; | 172 xLoc += xAdder; |
164 } | 173 } |
165 yLoc += yAdder; | 174 yLoc += yAdder; |
166 } | 175 } |
167 } | 176 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 { | 209 { |
201 return (m_rowInterfaces.at (row)).GetAddress (0); | 210 return (m_rowInterfaces.at (row)).GetAddress (0); |
202 } | 211 } |
203 else | 212 else |
204 { | 213 { |
205 return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1); | 214 return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1); |
206 } | 215 } |
207 } | 216 } |
208 | 217 |
209 } // namespace ns3 | 218 } // namespace ns3 |
LEFT | RIGHT |