View | Details | Raw Unified | Return to bug 1702
Collapse All | Expand All

(-)a/CHANGES.html (-1 / +6 lines)
 Lines 68-73    Link Here 
68
68
69
<h2>Changes to existing API:</h2>
69
<h2>Changes to existing API:</h2>
70
<ul>
70
<ul>
71
  <li> The Ipv6InterfaceContainer functions to set a node in forwarding state (i.e., a router) 
72
  and to install a default router in a group of nodes have been extensively changed.
73
  The old function "void Ipv6InterfaceContainer::SetRouter (uint32_t i, bool router)"
74
  is now DEPRECATED.
75
  </li>
71
  <li> The documentation's IPv6 addresses (2001:db8::/32, RFC 3849) are now
76
  <li> The documentation's IPv6 addresses (2001:db8::/32, RFC 3849) are now
72
  dropped by routers.
77
  dropped by routers.
73
  </li>
78
  </li>
 Lines 79-85    Link Here 
79
  include it from the core module.
84
  include it from the core module.
80
  </li>
85
  </li>
81
  <li> The Ipv6 UnicastForwardCallback and  MulticastForwardCallback 
86
  <li> The Ipv6 UnicastForwardCallback and  MulticastForwardCallback 
82
  have a new parmater, the NetDevice the packet has been received from.
87
  have a new parameter, the NetDevice the packet has been received from.
83
  Existing Ipv6RoutingProtocols should update their RouteInput function
88
  Existing Ipv6RoutingProtocols should update their RouteInput function
84
  accordingly. E.g., from ucb (rtentry, p, header); to ucb (idev, rtentry, p, header);
89
  accordingly. E.g., from ucb (rtentry, p, header); to ucb (idev, rtentry, p, header);
85
  </li>
90
  </li>
(-)a/RELEASE_NOTES (+1 lines)
 Lines 57-62    Link Here 
57
- Bug 1698 - mobility.SetPositionAllocator misses prefix "ns3::"
57
- Bug 1698 - mobility.SetPositionAllocator misses prefix "ns3::"
58
- Bug 1700 - Ipv6RawSocket does not honor the bound address when sending packets
58
- Bug 1700 - Ipv6RawSocket does not honor the bound address when sending packets
59
- Bug 1701 - Ipv6StaticRouting: the source address should match the destination scope
59
- Bug 1701 - Ipv6StaticRouting: the source address should match the destination scope
60
- Bug 1702 - Ipv6InterfaceContainer::SetRouter should not always add the router as the default router.
60
- Bug 1703 - Nodes don't react to a DAD
61
- Bug 1703 - Nodes don't react to a DAD
61
- Bug 1712 - The IP (v4 and v6) forwarding needs a test
62
- Bug 1712 - The IP (v4 and v6) forwarding needs a test
62
- Bug 1718 - Ipv4StaticRouting log component is misspelled
63
- Bug 1718 - Ipv4StaticRouting log component is misspelled
(-)a/examples/ipv6/fragmentation-ipv6.cc (-2 / +4 lines)
 Lines 129-138    Link Here 
129
  Ipv6AddressHelper ipv6;
129
  Ipv6AddressHelper ipv6;
130
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
130
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
131
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
131
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
132
  i1.SetRouter (1, true);
132
  i1.SetForwarding (1, true);
133
  i1.SetDefaultRouteInAllNodes (1);
133
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
134
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
134
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
135
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
135
  i2.SetRouter (0, true);
136
  i2.SetForwarding (0, true);
137
  i2.SetDefaultRouteInAllNodes (0);
136
138
137
  stackHelper.PrintRoutingTable (n0);
139
  stackHelper.PrintRoutingTable (n0);
138
140
(-)a/examples/ipv6/icmpv6-redirect.cc (-3 / +5 lines)
 Lines 148-159    Link Here 
148
148
149
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
149
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
150
  Ipv6InterfaceContainer iic1 = ipv6.Assign (ndc1);
150
  Ipv6InterfaceContainer iic1 = ipv6.Assign (ndc1);
151
  iic1.SetRouter (2, true);
151
  iic1.SetForwarding (2, true);
152
  iic1.SetRouter (1, true);
152
  iic1.SetForwarding (1, true);
153
  iic1.SetDefaultRouteInAllNodes (1);
153
154
154
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
155
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
155
  Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
156
  Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
156
  iic2.SetRouter (0, true);
157
  iic2.SetForwarding (0, true);
158
  iic2.SetDefaultRouteInAllNodes (0);
157
159
158
  stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 0), iic1.GetInterfaceIndex (1));
160
  stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 0), iic1.GetInterfaceIndex (1));
159
161
(-)a/examples/ipv6/loose-routing-ipv6.cc (-10 / +20 lines)
 Lines 106-136    Link Here 
106
106
107
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
107
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
108
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
108
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
109
  i1.SetRouter (1, true);
109
  i1.SetForwarding (1, true);
110
  i1.SetDefaultRouteInAllNodes (1);
110
111
111
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
112
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
112
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
113
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
113
  i2.SetRouter (1, true);
114
  i2.SetForwarding (1, true);
115
  i2.SetDefaultRouteInAllNodes (1);
114
116
115
  ipv6.SetBase (Ipv6Address ("2001:3::"), Ipv6Prefix (64));
117
  ipv6.SetBase (Ipv6Address ("2001:3::"), Ipv6Prefix (64));
116
  Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
118
  Ipv6InterfaceContainer i3 = ipv6.Assign (d3);
117
  i3.SetRouter (0, true);
119
  i3.SetForwarding (0, true);
118
  i3.SetRouter (1, true);
120
  i3.SetDefaultRouteInAllNodes (0);
121
  i3.SetForwarding (1, true);
122
  i3.SetDefaultRouteInAllNodes (1);
119
123
120
  ipv6.SetBase (Ipv6Address ("2001:4::"), Ipv6Prefix (64));
124
  ipv6.SetBase (Ipv6Address ("2001:4::"), Ipv6Prefix (64));
121
  Ipv6InterfaceContainer i4 = ipv6.Assign (d4);
125
  Ipv6InterfaceContainer i4 = ipv6.Assign (d4);
122
  i4.SetRouter (0, true);
126
  i4.SetForwarding (0, true);
123
  i4.SetRouter (1, true);
127
  i4.SetDefaultRouteInAllNodes (0);
128
  i4.SetForwarding (1, true);
129
  i4.SetDefaultRouteInAllNodes (1);
124
130
125
  ipv6.SetBase (Ipv6Address ("2001:5::"), Ipv6Prefix (64));
131
  ipv6.SetBase (Ipv6Address ("2001:5::"), Ipv6Prefix (64));
126
  Ipv6InterfaceContainer i5 = ipv6.Assign (d5);
132
  Ipv6InterfaceContainer i5 = ipv6.Assign (d5);
127
  i5.SetRouter (0, true);
133
  i5.SetForwarding (0, true);
128
  i5.SetRouter (1, true);
134
  i5.SetDefaultRouteInAllNodes (0);
135
  i5.SetForwarding (1, true);
136
  i5.SetDefaultRouteInAllNodes (1);
129
137
130
  ipv6.SetBase (Ipv6Address ("2001:6::"), Ipv6Prefix (64));
138
  ipv6.SetBase (Ipv6Address ("2001:6::"), Ipv6Prefix (64));
131
  Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
139
  Ipv6InterfaceContainer i6 = ipv6.Assign (d6);
132
  i6.SetRouter (0, true);
140
  i6.SetForwarding (0, true);
133
  i6.SetRouter (1, true);
141
  i6.SetDefaultRouteInAllNodes (0);
142
  i6.SetForwarding (1, true);
143
  i6.SetDefaultRouteInAllNodes (1);
134
144
135
  NS_LOG_INFO ("Create Applications.");
145
  NS_LOG_INFO ("Create Applications.");
136
146
(-)a/examples/ipv6/radvd-two-prefix.cc (-2 / +4 lines)
 Lines 145-151    Link Here 
145
  NetDeviceContainer tmp2;
145
  NetDeviceContainer tmp2;
146
  tmp2.Add (d1.Get (1)); /* R */
146
  tmp2.Add (d1.Get (1)); /* R */
147
  Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
147
  Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
148
  iicr1.SetRouter (0, true);
148
  iicr1.SetForwarding (0, true);
149
  iicr1.SetDefaultRouteInAllNodes (0);
149
  iic1.Add (iicr1);
150
  iic1.Add (iicr1);
150
151
151
  /* add another IPv6 address for second prefix advertised on first subnet */
152
  /* add another IPv6 address for second prefix advertised on first subnet */
 Lines 156-162    Link Here 
156
  NetDeviceContainer tmp3;
157
  NetDeviceContainer tmp3;
157
  tmp3.Add (d2.Get (0)); /* R */
158
  tmp3.Add (d2.Get (0)); /* R */
158
  Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
159
  Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
159
  iicr2.SetRouter (0, true);
160
  iicr2.SetForwarding (0, true);
161
  iicr2.SetDefaultRouteInAllNodes (0);
160
162
161
  NetDeviceContainer tmp4;
163
  NetDeviceContainer tmp4;
162
  tmp4.Add (d2.Get (1)); /* n1 */
164
  tmp4.Add (d2.Get (1)); /* n1 */
(-)a/examples/ipv6/radvd.cc (-2 / +4 lines)
 Lines 92-98    Link Here 
92
  NetDeviceContainer tmp2;
92
  NetDeviceContainer tmp2;
93
  tmp2.Add (d1.Get (1)); /* R */
93
  tmp2.Add (d1.Get (1)); /* R */
94
  Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
94
  Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
95
  iicr1.SetRouter (0, true);
95
  iicr1.SetForwarding (0, true);
96
  iicr1.SetDefaultRouteInAllNodes (0);
96
  iic1.Add (iicr1);
97
  iic1.Add (iicr1);
97
98
98
  /* second subnet R - n1 */
99
  /* second subnet R - n1 */
 Lines 100-106    Link Here 
100
  NetDeviceContainer tmp3;
101
  NetDeviceContainer tmp3;
101
  tmp3.Add (d2.Get (0)); /* R */
102
  tmp3.Add (d2.Get (0)); /* R */
102
  Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
103
  Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
103
  iicr2.SetRouter (0, true);
104
  iicr2.SetForwarding (0, true);
105
  iicr2.SetDefaultRouteInAllNodes (0);
104
106
105
  NetDeviceContainer tmp4;
107
  NetDeviceContainer tmp4;
106
  tmp4.Add (d2.Get (1)); /* n1 */
108
  tmp4.Add (d2.Get (1)); /* n1 */
(-)a/examples/routing/simple-routing-ping6.cc (-2 / +4 lines)
 Lines 130-139    Link Here 
130
  Ipv6AddressHelper ipv6;
130
  Ipv6AddressHelper ipv6;
131
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
131
  ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
132
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
132
  Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
133
  i1.SetRouter (1, true);
133
  i1.SetForwarding (1, true);
134
  i1.SetDefaultRouteInAllNodes (1);
134
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
135
  ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
135
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
136
  Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
136
  i2.SetRouter (0, true);
137
  i2.SetForwarding (0, true);
138
  i2.SetDefaultRouteInAllNodes (0);
137
139
138
  stackHelper.PrintRoutingTable (n0);
140
  stackHelper.PrintRoutingTable (n0);
139
141
(-)a/src/fd-net-device/examples/fd-tap-ping6.cc (-2 / +4 lines)
 Lines 102-108    Link Here 
102
 
102
 
103
  ipv6.SetBase (Ipv6Address ("2001:0DB8:1::"), Ipv6Prefix (64));
103
  ipv6.SetBase (Ipv6Address ("2001:0DB8:1::"), Ipv6Prefix (64));
104
  Ipv6InterfaceContainer i1 = ipv6.Assign (devs);
104
  Ipv6InterfaceContainer i1 = ipv6.Assign (devs);
105
  i1.SetRouter (1, true);
105
  i1.SetForwarding (1, true);
106
  i1.SetDefaultRouteInAllNodes (1);
106
  
107
  
107
  ipv6.SetBase (Ipv6Address ("2001:0DB8:2::"), Ipv6Prefix (64));
108
  ipv6.SetBase (Ipv6Address ("2001:0DB8:2::"), Ipv6Prefix (64));
108
  Ipv6Address tapAddr = ipv6.NewAddress ();
109
  Ipv6Address tapAddr = ipv6.NewAddress ();
 Lines 124-130    Link Here 
124
  Ptr<FdNetDevice> fdevice = device->GetObject<FdNetDevice> ();
125
  Ptr<FdNetDevice> fdevice = device->GetObject<FdNetDevice> ();
125
  fdevice-> SetIsMulticast (true);
126
  fdevice-> SetIsMulticast (true);
126
  Ipv6InterfaceContainer i2 = ipv6.Assign (fdevs);
127
  Ipv6InterfaceContainer i2 = ipv6.Assign (fdevs);
127
  i2.SetRouter (0, true);
128
  i2.SetForwarding (0, true);
129
  i2.SetDefaultRouteInAllNodes (0);
128
130
129
  //
131
  //
130
  // Create the Ping6 application.
132
  // Create the Ping6 application.
(-)a/src/internet/helper/ipv6-interface-container.cc (-6 / +177 lines)
 Lines 1-6    Link Here 
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) 2008-2009 Strasbourg University
3
 * Copyright (c) 2008-2009 Strasbourg University
4
 *               2013 Universita' di Firenze
4
 *
5
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * 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
 * it under the terms of the GNU General Public License version 2 as
 Lines 16-21    Link Here 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 *
18
 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
20
 *         Tommaso Pecorella <tommaso.pecorella@unifi.it>
19
 */
21
 */
20
22
21
#include "ns3/node-list.h"
23
#include "ns3/node-list.h"
 Lines 24-43    Link Here 
24
#include "ipv6-interface-container.h"
26
#include "ipv6-interface-container.h"
25
#include "ns3/ipv6-static-routing-helper.h"
27
#include "ns3/ipv6-static-routing-helper.h"
26
28
27
namespace ns3 
29
namespace ns3 {
28
{
29
30
30
Ipv6InterfaceContainer::Ipv6InterfaceContainer ()
31
Ipv6InterfaceContainer::Ipv6InterfaceContainer ()
31
{
32
{
32
}
33
}
33
34
34
Ipv6InterfaceContainer::Iterator 
35
Ipv6InterfaceContainer::Iterator
35
Ipv6InterfaceContainer::Begin (void) const
36
Ipv6InterfaceContainer::Begin (void) const
36
{
37
{
37
  return m_interfaces.begin ();
38
  return m_interfaces.begin ();
38
}
39
}
39
40
40
Ipv6InterfaceContainer::Iterator 
41
Ipv6InterfaceContainer::Iterator
41
Ipv6InterfaceContainer::End (void) const
42
Ipv6InterfaceContainer::End (void) const
42
{
43
{
43
  return m_interfaces.end ();
44
  return m_interfaces.end ();
 Lines 81-86    Link Here 
81
82
82
void Ipv6InterfaceContainer::SetRouter (uint32_t i, bool router)
83
void Ipv6InterfaceContainer::SetRouter (uint32_t i, bool router)
83
{
84
{
85
  // This function is deprecated and should be substituted by:
86
  // SetForwarding (RouterInterfaceIndex, true);
87
  // SetDefaultRouteInAllNodes (RouterInterfaceIndex);
88
84
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
89
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
85
  ipv6->SetForwarding (m_interfaces[i].second, router);
90
  ipv6->SetForwarding (m_interfaces[i].second, router);
86
91
 Lines 105-115    Link Here 
105
    }
110
    }
106
}
111
}
107
112
113
void Ipv6InterfaceContainer::SetForwarding (uint32_t i, bool router)
114
{
115
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
116
  ipv6->SetForwarding (m_interfaces[i].second, router);
117
}
118
119
void Ipv6InterfaceContainer::SetDefaultRouteInAllNodes (uint32_t router)
120
{
121
  Ptr<Ipv6> ipv6 = m_interfaces[router].first;
122
  uint32_t other;
123
124
  Ipv6Address routerAddress = GetLinkLocalAddress (router);
125
  NS_ASSERT_MSG (routerAddress != Ipv6Address::GetAny (), "No link-local address found on router, aborting");
126
127
  for (other = 0; other < m_interfaces.size (); other++)
128
    {
129
      if (other != router)
130
        {
131
          Ptr<Ipv6StaticRouting> routing = 0;
132
          Ipv6StaticRoutingHelper routingHelper;
133
134
          ipv6 = m_interfaces[other].first;
135
          routing = routingHelper.GetStaticRouting (ipv6);
136
          routing->SetDefaultRoute (routerAddress, m_interfaces[other].second);
137
        }
138
    }
139
}
140
141
void Ipv6InterfaceContainer::SetDefaultRouteInAllNodes (Ipv6Address routerAddress)
142
{
143
  uint32_t routerIndex;
144
  bool found = false;
145
  for (uint32_t index = 0; index < m_interfaces.size (); index++)
146
    {
147
      Ptr<Ipv6> ipv6 = m_interfaces[index].first;
148
      for (uint32_t i = 0; i < ipv6->GetNAddresses (m_interfaces[index].second); i++)
149
        {
150
          Ipv6Address addr = ipv6->GetAddress (m_interfaces[index].second, i).GetAddress ();
151
          if (addr == routerAddress)
152
            {
153
              routerIndex = index;
154
              found = true;
155
              break;
156
            }
157
        }
158
      if (found)
159
        {
160
          break;
161
        }
162
    }
163
  NS_ASSERT_MSG (found != true, "No such address in the interfaces. Aborting.");
164
165
  for (uint32_t other = 0; other < m_interfaces.size (); other++)
166
    {
167
      if (other != routerIndex)
168
        {
169
          Ptr<Ipv6StaticRouting> routing = 0;
170
          Ipv6StaticRoutingHelper routingHelper;
171
172
          Ptr<Ipv6> ipv6 = m_interfaces[other].first;
173
          routing = routingHelper.GetStaticRouting (ipv6);
174
          routing->SetDefaultRoute (routerAddress, m_interfaces[other].second);
175
        }
176
    }
177
}
178
179
108
void Ipv6InterfaceContainer::SetDefaultRoute (uint32_t i, uint32_t router)
180
void Ipv6InterfaceContainer::SetDefaultRoute (uint32_t i, uint32_t router)
109
{
181
{
182
  NS_ASSERT_MSG (i != router, "A node shouldn't set itself as the default router, isn't it? Aborting.");
183
110
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
184
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
111
  Ptr<Ipv6> ipv6Router = m_interfaces[router].first;
185
112
  Ipv6Address routerAddress = ipv6Router->GetAddress (m_interfaces[router].second, 0).GetAddress ();
186
  Ipv6Address routerAddress = GetLinkLocalAddress (router);
187
  NS_ASSERT_MSG (routerAddress != Ipv6Address::GetAny (), "No link-local address found on router, aborting");
188
113
  Ptr<Ipv6StaticRouting> routing = 0;
189
  Ptr<Ipv6StaticRouting> routing = 0;
114
  Ipv6StaticRoutingHelper routingHelper;
190
  Ipv6StaticRoutingHelper routingHelper;
115
191
 Lines 117-121    Link Here 
117
  routing->SetDefaultRoute (routerAddress, m_interfaces[i].second);
193
  routing->SetDefaultRoute (routerAddress, m_interfaces[i].second);
118
}
194
}
119
195
196
197
void Ipv6InterfaceContainer::SetDefaultRoute (uint32_t i, Ipv6Address routerAddr)
198
{
199
  uint32_t routerIndex;
200
  bool found = false;
201
  for (uint32_t index = 0; index < m_interfaces.size (); index++)
202
    {
203
      Ptr<Ipv6> ipv6 = m_interfaces[index].first;
204
      for (uint32_t i = 0; i < ipv6->GetNAddresses (m_interfaces[index].second); i++)
205
        {
206
          Ipv6Address addr = ipv6->GetAddress (m_interfaces[index].second, i).GetAddress ();
207
          if (addr == routerAddr)
208
            {
209
              routerIndex = index;
210
              found = true;
211
              break;
212
            }
213
        }
214
      if (found)
215
        {
216
          break;
217
        }
218
    }
219
  NS_ASSERT_MSG (found != true, "No such address in the interfaces. Aborting.");
220
221
  NS_ASSERT_MSG (i != routerIndex, "A node shouldn't set itself as the default router, isn't it? Aborting.");
222
223
  Ptr<Ipv6> ipv6 = m_interfaces[i].first;
224
  Ipv6Address routerLinkLocalAddress = GetLinkLocalAddress (routerIndex);
225
  Ptr<Ipv6StaticRouting> routing = 0;
226
  Ipv6StaticRoutingHelper routingHelper;
227
228
  routing = routingHelper.GetStaticRouting (ipv6);
229
  routing->SetDefaultRoute (routerLinkLocalAddress, m_interfaces[i].second);
230
}
231
232
233
Ipv6Address Ipv6InterfaceContainer::GetLinkLocalAddress (uint32_t index)
234
{
235
  Ptr<Ipv6> ipv6 = m_interfaces[index].first;
236
  for (uint32_t i = 0; i < ipv6->GetNAddresses (m_interfaces[index].second); i++)
237
    {
238
      Ipv6InterfaceAddress iAddress;
239
      iAddress = ipv6->GetAddress (m_interfaces[index].second, i);
240
      if (iAddress.GetScope () == Ipv6InterfaceAddress::LINKLOCAL)
241
        {
242
          return iAddress.GetAddress ();
243
        }
244
    }
245
  return Ipv6Address::GetAny ();
246
}
247
248
Ipv6Address Ipv6InterfaceContainer::GetLinkLocalAddress (Ipv6Address address)
249
{
250
  if (address.IsLinkLocal ())
251
    {
252
      return address;
253
    }
254
255
  uint32_t nodeIndex;
256
  bool found = false;
257
  for (uint32_t index = 0; index < m_interfaces.size (); index++)
258
    {
259
      Ptr<Ipv6> ipv6 = m_interfaces[index].first;
260
      for (uint32_t i = 0; i < ipv6->GetNAddresses (m_interfaces[index].second); i++)
261
        {
262
          Ipv6Address addr = ipv6->GetAddress (m_interfaces[index].second, i).GetAddress ();
263
          if (addr == address)
264
            {
265
              nodeIndex = index;
266
              found = true;
267
              break;
268
            }
269
        }
270
      if (found)
271
        {
272
          break;
273
        }
274
    }
275
  NS_ASSERT_MSG (found != true, "No such address in the interfaces. Aborting.");
276
277
  Ptr<Ipv6> ipv6 = m_interfaces[nodeIndex].first;
278
  for (uint32_t i = 0; i < ipv6->GetNAddresses (m_interfaces[nodeIndex].second); i++)
279
    {
280
      Ipv6InterfaceAddress iAddress;
281
      iAddress = ipv6->GetAddress (m_interfaces[nodeIndex].second, i);
282
      if (iAddress.GetScope () == Ipv6InterfaceAddress::LINKLOCAL)
283
        {
284
          return iAddress.GetAddress ();
285
        }
286
    }
287
  return Ipv6Address::GetAny ();
288
}
289
290
120
} /* namespace ns3 */
291
} /* namespace ns3 */
121
292
(-)a/src/internet/helper/ipv6-interface-container.h (-1 / +47 lines)
 Lines 1-6    Link Here 
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) 2008-2009 Strasbourg University
3
 * Copyright (c) 2008-2009 Strasbourg University
4
 *               2013 Universita' di Firenze
4
 *
5
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * 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
 * it under the terms of the GNU General Public License version 2 as
 Lines 16-21    Link Here 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 *
18
 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
20
 *         Tommaso Pecorella <tommaso.pecorella@unifi.it>
19
 */
21
 */
20
22
21
#ifndef IPV6_INTERFACE_CONTAINER_H
23
#ifndef IPV6_INTERFACE_CONTAINER_H
 Lines 27-32    Link Here 
27
29
28
#include "ns3/ipv6.h"
30
#include "ns3/ipv6.h"
29
#include "ns3/ipv6-address.h"
31
#include "ns3/ipv6-address.h"
32
#include "ns3/deprecated.h"
30
33
31
namespace ns3
34
namespace ns3
32
{
35
{
 Lines 81-86    Link Here 
81
  Ipv6Address GetAddress (uint32_t i, uint32_t j) const;
84
  Ipv6Address GetAddress (uint32_t i, uint32_t j) const;
82
85
83
  /**
86
  /**
87
   * \brief Get the link-local address for the specified index.
88
   * \param i index
89
   * \return the link-local address, or "::" if the interface has no link local address.
90
   */
91
  Ipv6Address GetLinkLocalAddress (uint32_t i);
92
93
  /**
94
   * \brief Get the link-local address for the node with the specified global address.
95
   * \param address the address to find.
96
   * \return the link-local address, or "::" if the interface has no link local address.
97
   */
98
  Ipv6Address GetLinkLocalAddress (Ipv6Address address);
99
100
  /**
84
   * \brief Add a couple IPv6/interface.
101
   * \brief Add a couple IPv6/interface.
85
   * \param ipv6 IPv6 address
102
   * \param ipv6 IPv6 address
86
   * \param interface interface index
103
   * \param interface interface index
 Lines 149-155    Link Here 
149
   * \param i index
166
   * \param i index
150
   * \param router true : is a router, false : is an host
167
   * \param router true : is a router, false : is an host
151
   */
168
   */
152
  void SetRouter (uint32_t i, bool router);
169
  void SetRouter (uint32_t i, bool router) NS_DEPRECATED;
170
171
  /**
172
   * \brief Set the state of the stack (act as a router or as an host) for the specified index.
173
   * This automatically sets all the node's interfaces to the same forwarding state.
174
   * \param i index
175
   * \param state true : is a router, false : is an host
176
   */
177
  void SetForwarding (uint32_t i, bool state);
178
179
  /**
180
   * \brief Set the default route for all the devices (except the router itself).
181
   * \param router the default router index
182
   */
183
  void SetDefaultRouteInAllNodes (uint32_t router);
184
185
  /**
186
   * \brief Set the default route for all the devices (except the router itself).
187
   * Note that the route will be set to the link-local address of the node with the specified address.
188
   * \param routerAddr the default router address
189
   */
190
  void SetDefaultRouteInAllNodes (Ipv6Address routerAddr);
153
191
154
  /**
192
  /**
155
   * \brief Set the default route for the specified index.
193
   * \brief Set the default route for the specified index.
 Lines 158-163    Link Here 
158
   */
196
   */
159
  void SetDefaultRoute (uint32_t i, uint32_t router);
197
  void SetDefaultRoute (uint32_t i, uint32_t router);
160
198
199
  /**
200
   * \brief Set the default route for the specified index.
201
   * Note that the route will be set to the link-local address of the node with the specified address.
202
   * \param i index
203
   * \param routerAddr the default router address
204
   */
205
  void SetDefaultRoute (uint32_t i, Ipv6Address routerAddr);
206
161
private:
207
private:
162
  typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t> > InterfaceVector;
208
  typedef std::vector<std::pair<Ptr<Ipv6>, uint32_t> > InterfaceVector;
163
209
(-)a/src/internet/model/ipv6-static-routing.cc (-2 / +8 lines)
 Lines 97-103    Link Here 
97
void Ipv6StaticRouting::AddHostRouteTo (Ipv6Address dst, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
97
void Ipv6StaticRouting::AddHostRouteTo (Ipv6Address dst, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
98
{
98
{
99
  NS_LOG_FUNCTION (this << dst << nextHop << interface << prefixToUse << metric);
99
  NS_LOG_FUNCTION (this << dst << nextHop << interface << prefixToUse << metric);
100
  NS_ASSERT_MSG(nextHop.IsLinkLocal(), "Ipv6StaticRouting::AddHostRouteTo - Next hop must be link-local");
100
  if (nextHop.IsLinkLocal())
101
    {
102
      NS_LOG_WARN ("Ipv6StaticRouting::AddHostRouteTo - Next hop should be link-local");
103
    }
101
104
102
  AddNetworkRouteTo (dst, Ipv6Prefix::GetOnes (), nextHop, interface, prefixToUse, metric);
105
  AddNetworkRouteTo (dst, Ipv6Prefix::GetOnes (), nextHop, interface, prefixToUse, metric);
103
}
106
}
 Lines 119-125    Link Here 
119
void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
122
void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse, uint32_t metric)
120
{
123
{
121
  NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << prefixToUse << metric);
124
  NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << prefixToUse << metric);
122
  NS_ASSERT_MSG(nextHop.IsLinkLocal(), "Ipv6StaticRouting::AddNetworkRouteTo - Next hop must be link-local");
125
  if (nextHop.IsLinkLocal())
126
    {
127
      NS_LOG_WARN ("Ipv6StaticRouting::AddNetworkRouteTo - Next hop should be link-local");
128
    }
123
129
124
  Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
130
  Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry ();
125
  *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse);
131
  *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse);
(-)a/src/internet/model/ipv6-static-routing.h (-2 / +2 lines)
 Lines 74-80    Link Here 
74
  /**
74
  /**
75
   * \brief Add route to host.
75
   * \brief Add route to host.
76
   * \param dest destination address
76
   * \param dest destination address
77
   * \param nextHop next hop address to route the packet. Must be a link-local address
77
   * \param nextHop next hop address to route the packet.
78
   * \param interface interface index
78
   * \param interface interface index
79
   * \param prefixToUse prefix that should be used for source address for this destination
79
   * \param prefixToUse prefix that should be used for source address for this destination
80
   * \param metric metric of route in case of multiple routes to same destination
80
   * \param metric metric of route in case of multiple routes to same destination
 Lines 103-109    Link Here 
103
   * \brief Add route to network.
103
   * \brief Add route to network.
104
   * \param network network address
104
   * \param network network address
105
   * \param networkPrefix network prefix*
105
   * \param networkPrefix network prefix*
106
   * \param nextHop next hop address to route the packet. Must be a link-local address
106
   * \param nextHop next hop address to route the packet.
107
   * \param interface interface index
107
   * \param interface interface index
108
   * \param prefixToUse prefix that should be used for source address for this destination
108
   * \param prefixToUse prefix that should be used for source address for this destination
109
   * \param metric metric of route in case of multiple routes to same destination
109
   * \param metric metric of route in case of multiple routes to same destination

Return to bug 1702