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 * Copyright (c) 2011 Universita' di Firenze, Italy | 3 * Copyright (c) 2011 Universita' di Firenze, Italy |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> | 18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
19 */ | 19 */ |
20 | 20 |
21 #include "sixlowpan-helper.h" | 21 #include "sixlowpan-helper.h" |
22 #include "ns3/log.h" | 22 #include "ns3/log.h" |
23 #include "ns3/sixlowpan-net-device.h" | 23 #include "ns3/sixlowpan-net-device.h" |
24 #include "ns3/node.h" | 24 #include "ns3/node.h" |
25 #include "ns3/names.h" | 25 #include "ns3/names.h" |
26 | 26 |
27 NS_LOG_COMPONENT_DEFINE ("SixLowPanHelper"); | 27 NS_LOG_COMPONENT_DEFINE ("SixLowPanHelper") |
| 28 ; |
28 | 29 |
29 namespace ns3 { | 30 namespace ns3 { |
30 | 31 |
31 SixLowPanHelper::SixLowPanHelper () | 32 SixLowPanHelper::SixLowPanHelper () |
32 { | 33 { |
33 NS_LOG_FUNCTION (this); | 34 NS_LOG_FUNCTION (this); |
34 m_deviceFactory.SetTypeId ("ns3::sixlowpan::SixLowPanNetDevice"); | 35 m_deviceFactory.SetTypeId ("ns3::SixLowPanNetDevice"); |
35 } | 36 } |
36 | 37 |
37 void SixLowPanHelper::SetDeviceAttribute (std::string n1, | 38 void SixLowPanHelper::SetDeviceAttribute (std::string n1, |
38 const AttributeValue &v1) | 39 const AttributeValue &v1) |
39 { | 40 { |
40 NS_LOG_FUNCTION (this); | 41 NS_LOG_FUNCTION (this); |
41 m_deviceFactory.Set (n1, v1); | 42 m_deviceFactory.Set (n1, v1); |
42 } | 43 } |
43 | 44 |
44 NetDeviceContainer SixLowPanHelper::Install (const NetDeviceContainer c) | 45 NetDeviceContainer SixLowPanHelper::Install (const NetDeviceContainer c) |
45 { | 46 { |
46 NS_LOG_FUNCTION (this); | 47 NS_LOG_FUNCTION (this); |
47 | 48 |
48 NetDeviceContainer devs; | 49 NetDeviceContainer devs; |
49 | 50 |
50 for (uint32_t i = 0; i < c.GetN (); ++i) | 51 for (uint32_t i = 0; i < c.GetN (); ++i) |
51 { | 52 { |
52 Ptr<NetDevice> device = c.Get (i); | 53 Ptr<NetDevice> device = c.Get (i); |
| 54 NS_ASSERT_MSG (device != 0, "No NetDevice found in the node " << int(i) ); |
53 | 55 |
54 Ptr<Node> node = device->GetNode (); | 56 Ptr<Node> node = device->GetNode (); |
55 NS_LOG_LOGIC ("**** Install 6LoWPAN on node " << node->GetId ()); | 57 NS_LOG_LOGIC ("**** Install 6LoWPAN on node " << node->GetId ()); |
56 | 58 |
57 Ptr<sixlowpan::SixLowPanNetDevice> dev = m_deviceFactory.Create<sixlowpan:
:SixLowPanNetDevice> (); | 59 Ptr<SixLowPanNetDevice> dev = m_deviceFactory.Create<SixLowPanNetDevice> (
); |
58 devs.Add (dev); | 60 devs.Add (dev); |
59 node->AddDevice (dev); | 61 node->AddDevice (dev); |
60 dev->SetPort (device); | 62 dev->SetNetDevice (device); |
61 } | 63 } |
62 return devs; | 64 return devs; |
63 } | 65 } |
64 | 66 |
| 67 int64_t SixLowPanHelper::AssignStreams (NetDeviceContainer c, int64_t stream) |
| 68 { |
| 69 int64_t currentStream = stream; |
| 70 Ptr<NetDevice> netDevice; |
| 71 for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 72 { |
| 73 netDevice = (*i); |
| 74 Ptr<SixLowPanNetDevice> dev = DynamicCast<SixLowPanNetDevice> (netDevice); |
| 75 if (dev) |
| 76 { |
| 77 currentStream += dev->AssignStreams (currentStream); |
| 78 } |
| 79 } |
| 80 return (currentStream - stream); |
| 81 } |
| 82 |
65 } // namespace ns3 | 83 } // namespace ns3 |
LEFT | RIGHT |