27 namespace ns3 { |
27 namespace ns3 { |
28 |
28 |
29 Ipv4StaticRouting::Ipv4StaticRouting () |
29 Ipv4StaticRouting::Ipv4StaticRouting () |
30 : m_defaultRoute (0), m_defaultMulticastRoute (0) |
30 : m_defaultRoute (0), m_defaultMulticastRoute (0) |
31 { |
31 { |
32 NS_LOG_FUNCTION; |
32 NS_LOG_FUNCTION_NOARGS (); |
33 } |
33 } |
34 |
34 |
35 void |
35 void |
36 Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, |
36 Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, |
37 Ipv4Address nextHop, |
37 Ipv4Address nextHop, |
38 uint32_t interface) |
38 uint32_t interface) |
39 { |
39 { |
40 NS_LOG_FUNCTION; |
40 NS_LOG_FUNCTION_NOARGS (); |
41 Ipv4Route *route = new Ipv4Route (); |
41 Ipv4Route *route = new Ipv4Route (); |
42 *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface); |
42 *route = Ipv4Route::CreateHostRouteTo (dest, nextHop, interface); |
43 m_hostRoutes.push_back (route); |
43 m_hostRoutes.push_back (route); |
44 } |
44 } |
45 |
45 |
46 void |
46 void |
47 Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, |
47 Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, |
48 uint32_t interface) |
48 uint32_t interface) |
49 { |
49 { |
50 NS_LOG_FUNCTION; |
50 NS_LOG_FUNCTION_NOARGS (); |
51 Ipv4Route *route = new Ipv4Route (); |
51 Ipv4Route *route = new Ipv4Route (); |
52 *route = Ipv4Route::CreateHostRouteTo (dest, interface); |
52 *route = Ipv4Route::CreateHostRouteTo (dest, interface); |
53 m_hostRoutes.push_back (route); |
53 m_hostRoutes.push_back (route); |
54 } |
54 } |
55 |
55 |
71 void |
71 void |
72 Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, |
72 Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, |
73 Ipv4Mask networkMask, |
73 Ipv4Mask networkMask, |
74 uint32_t interface) |
74 uint32_t interface) |
75 { |
75 { |
76 NS_LOG_FUNCTION; |
76 NS_LOG_FUNCTION_NOARGS (); |
77 Ipv4Route *route = new Ipv4Route (); |
77 Ipv4Route *route = new Ipv4Route (); |
78 *route = Ipv4Route::CreateNetworkRouteTo (network, |
78 *route = Ipv4Route::CreateNetworkRouteTo (network, |
79 networkMask, |
79 networkMask, |
80 interface); |
80 interface); |
81 m_networkRoutes.push_back (route); |
81 m_networkRoutes.push_back (route); |
83 |
83 |
84 void |
84 void |
85 Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, |
85 Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, |
86 uint32_t interface) |
86 uint32_t interface) |
87 { |
87 { |
88 NS_LOG_FUNCTION; |
88 NS_LOG_FUNCTION_NOARGS (); |
89 Ipv4Route *route = new Ipv4Route (); |
89 Ipv4Route *route = new Ipv4Route (); |
90 *route = Ipv4Route::CreateDefaultRoute (nextHop, interface); |
90 *route = Ipv4Route::CreateDefaultRoute (nextHop, interface); |
91 delete m_defaultRoute; |
91 delete m_defaultRoute; |
92 m_defaultRoute = route; |
92 m_defaultRoute = route; |
93 } |
93 } |
96 Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, |
96 Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin, |
97 Ipv4Address group, |
97 Ipv4Address group, |
98 uint32_t inputInterface, |
98 uint32_t inputInterface, |
99 std::vector<uint32_t> outputInterfaces) |
99 std::vector<uint32_t> outputInterfaces) |
100 { |
100 { |
101 NS_LOG_FUNCTION; |
101 NS_LOG_FUNCTION_NOARGS (); |
102 Ipv4MulticastRoute *route = new Ipv4MulticastRoute (); |
102 Ipv4MulticastRoute *route = new Ipv4MulticastRoute (); |
103 *route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group, |
103 *route = Ipv4MulticastRoute::CreateMulticastRoute (origin, group, |
104 inputInterface, outputInterfaces); |
104 inputInterface, outputInterfaces); |
105 m_multicastRoutes.push_back (route); |
105 m_multicastRoutes.push_back (route); |
106 } |
106 } |
107 |
107 |
108 void |
108 void |
109 Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface) |
109 Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface) |
110 { |
110 { |
111 NS_LOG_FUNCTION; |
111 NS_LOG_FUNCTION_NOARGS (); |
112 Ipv4Address origin = Ipv4Address::GetAny (); |
112 Ipv4Address origin = Ipv4Address::GetAny (); |
113 Ipv4Address group = Ipv4Address::GetAny (); |
113 Ipv4Address group = Ipv4Address::GetAny (); |
114 uint32_t inputInterface = Ipv4RoutingProtocol::IF_INDEX_ANY; |
114 uint32_t inputInterface = Ipv4RoutingProtocol::IF_INDEX_ANY; |
115 |
115 |
116 std::vector<uint32_t> outputInterfaces (1); |
116 std::vector<uint32_t> outputInterfaces (1); |
125 } |
125 } |
126 |
126 |
127 uint32_t |
127 uint32_t |
128 Ipv4StaticRouting::GetNMulticastRoutes (void) const |
128 Ipv4StaticRouting::GetNMulticastRoutes (void) const |
129 { |
129 { |
130 NS_LOG_FUNCTION; |
130 NS_LOG_FUNCTION_NOARGS (); |
131 return m_multicastRoutes.size () + m_defaultMulticastRoute ? 1 : 0; |
131 return m_multicastRoutes.size () + m_defaultMulticastRoute ? 1 : 0; |
132 } |
132 } |
133 |
133 |
134 Ipv4MulticastRoute * |
134 Ipv4MulticastRoute * |
135 Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const |
135 Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const |
136 { |
136 { |
137 NS_LOG_FUNCTION; |
137 NS_LOG_FUNCTION_NOARGS (); |
138 NS_ASSERT_MSG(index < m_multicastRoutes.size (), |
138 NS_ASSERT_MSG(index < m_multicastRoutes.size (), |
139 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range"); |
139 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range"); |
140 // |
140 // |
141 // From an external point of view the default route appears to be in slot 0 |
141 // From an external point of view the default route appears to be in slot 0 |
142 // of the routing table. The implementation, however, puts it in a separate |
142 // of the routing table. The implementation, however, puts it in a separate |
193 bool |
193 bool |
194 Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, |
194 Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin, |
195 Ipv4Address group, |
195 Ipv4Address group, |
196 uint32_t inputInterface) |
196 uint32_t inputInterface) |
197 { |
197 { |
198 NS_LOG_FUNCTION; |
198 NS_LOG_FUNCTION_NOARGS (); |
199 for (MulticastRoutesI i = m_multicastRoutes.begin (); |
199 for (MulticastRoutesI i = m_multicastRoutes.begin (); |
200 i != m_multicastRoutes.end (); |
200 i != m_multicastRoutes.end (); |
201 i++) |
201 i++) |
202 { |
202 { |
203 Ipv4MulticastRoute *route = *i; |
203 Ipv4MulticastRoute *route = *i; |
214 } |
214 } |
215 |
215 |
216 void |
216 void |
217 Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index) |
217 Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index) |
218 { |
218 { |
219 NS_LOG_FUNCTION; |
219 NS_LOG_FUNCTION_NOARGS (); |
220 // |
220 // |
221 // From an external point of view the default route appears to be in slot 0 |
221 // From an external point of view the default route appears to be in slot 0 |
222 // of the routing table. The implementation, however, puts it in a separate |
222 // of the routing table. The implementation, however, puts it in a separate |
223 // place. So, if a client asks to delete index 0 and we have a default |
223 // place. So, if a client asks to delete index 0 and we have a default |
224 // multicast route set, we have to delete it from that different place |
224 // multicast route set, we have to delete it from that different place |
518 uint32_t ifIndex, |
518 uint32_t ifIndex, |
519 Ipv4Header const &ipHeader, |
519 Ipv4Header const &ipHeader, |
520 Ptr<Packet> packet, |
520 Ptr<Packet> packet, |
521 RouteReplyCallback routeReply) |
521 RouteReplyCallback routeReply) |
522 { |
522 { |
523 NS_LOG_FUNCTION; |
523 NS_LOG_FUNCTION (this << ifIndex << &ipHeader << packet << &routeReply); |
524 NS_LOG_PARAMS (this << ifIndex << &ipHeader << packet << &routeReply); |
|
525 |
524 |
526 NS_LOG_LOGIC ("source = " << ipHeader.GetSource ()); |
525 NS_LOG_LOGIC ("source = " << ipHeader.GetSource ()); |
527 |
526 |
528 NS_LOG_LOGIC ("destination = " << ipHeader.GetDestination ()); |
527 NS_LOG_LOGIC ("destination = " << ipHeader.GetDestination ()); |
529 |
528 |
571 } |
570 } |
572 |
571 |
573 bool |
572 bool |
574 Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) |
573 Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex) |
575 { |
574 { |
576 NS_LOG_FUNCTION; |
575 NS_LOG_FUNCTION (this << destination << &ifIndex); |
577 NS_LOG_PARAMS (this << destination << &ifIndex); |
|
578 // |
576 // |
579 // First, see if this is a multicast packet we have a route for. If we |
577 // First, see if this is a multicast packet we have a route for. If we |
580 // have a route, then send the packet down each of the specified interfaces. |
578 // have a route, then send the packet down each of the specified interfaces. |
581 // |
579 // |
582 if (destination.IsMulticast ()) |
580 if (destination.IsMulticast ()) |