OLD | NEW |
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 2007 University of Washington | 3 * Copyright 2007 University of Washington |
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 | 18 |
19 #include "ns3/log.h" | 19 #include "ns3/log.h" |
20 #include "ns3/ipv4-address.h" | 20 #include "ns3/ipv4-address.h" |
| 21 #include "ns3/ipv6-address.h" |
21 #include "ns3/address-utils.h" | 22 #include "ns3/address-utils.h" |
22 #include "ns3/nstime.h" | 23 #include "ns3/nstime.h" |
23 #include "ns3/inet-socket-address.h" | 24 #include "ns3/inet-socket-address.h" |
| 25 #include "ns3/inet6-socket-address.h" |
24 #include "ns3/socket.h" | 26 #include "ns3/socket.h" |
25 #include "ns3/udp-socket.h" | 27 #include "ns3/udp-socket.h" |
26 #include "ns3/simulator.h" | 28 #include "ns3/simulator.h" |
27 #include "ns3/socket-factory.h" | 29 #include "ns3/socket-factory.h" |
28 #include "ns3/packet.h" | 30 #include "ns3/packet.h" |
29 #include "ns3/uinteger.h" | 31 #include "ns3/uinteger.h" |
30 | 32 |
31 #include "udp-echo-server.h" | 33 #include "udp-echo-server.h" |
32 | 34 |
33 namespace ns3 { | 35 namespace ns3 { |
(...skipping 17 matching lines...) Expand all Loading... |
51 | 53 |
52 UdpEchoServer::UdpEchoServer () | 54 UdpEchoServer::UdpEchoServer () |
53 { | 55 { |
54 NS_LOG_FUNCTION_NOARGS (); | 56 NS_LOG_FUNCTION_NOARGS (); |
55 } | 57 } |
56 | 58 |
57 UdpEchoServer::~UdpEchoServer() | 59 UdpEchoServer::~UdpEchoServer() |
58 { | 60 { |
59 NS_LOG_FUNCTION_NOARGS (); | 61 NS_LOG_FUNCTION_NOARGS (); |
60 m_socket = 0; | 62 m_socket = 0; |
| 63 m_socket6 = 0; |
61 } | 64 } |
62 | 65 |
63 void | 66 void |
64 UdpEchoServer::DoDispose (void) | 67 UdpEchoServer::DoDispose (void) |
65 { | 68 { |
66 NS_LOG_FUNCTION_NOARGS (); | 69 NS_LOG_FUNCTION_NOARGS (); |
67 Application::DoDispose (); | 70 Application::DoDispose (); |
68 } | 71 } |
69 | 72 |
70 void· | 73 void· |
(...skipping 10 matching lines...) Expand all Loading... |
81 if (addressUtils::IsMulticast (m_local)) | 84 if (addressUtils::IsMulticast (m_local)) |
82 { | 85 { |
83 Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket); | 86 Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket); |
84 if (udpSocket) | 87 if (udpSocket) |
85 { | 88 { |
86 // equivalent to setsockopt (MCAST_JOIN_GROUP) | 89 // equivalent to setsockopt (MCAST_JOIN_GROUP) |
87 udpSocket->MulticastJoinGroup (0, m_local); | 90 udpSocket->MulticastJoinGroup (0, m_local); |
88 } | 91 } |
89 else | 92 else |
90 { | 93 { |
91 NS_FATAL_ERROR ("Error: joining multicast on a non-UDP socket"); | 94 NS_FATAL_ERROR ("Error: Failed to join multicast group"); |
| 95 } |
| 96 } |
| 97 } |
| 98 |
| 99 if (m_socket6 == 0) |
| 100 { |
| 101 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); |
| 102 m_socket6 = Socket::CreateSocket (GetNode (), tid); |
| 103 Inet6SocketAddress local6 = Inet6SocketAddress (Ipv6Address::GetAny (), m_
port); |
| 104 m_socket6->Bind (local6); |
| 105 if (addressUtils::IsMulticast (local6)) |
| 106 { |
| 107 Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket6); |
| 108 if (udpSocket) |
| 109 { |
| 110 // equivalent to setsockopt (MCAST_JOIN_GROUP) |
| 111 udpSocket->MulticastJoinGroup (0, local6); |
| 112 } |
| 113 else |
| 114 { |
| 115 NS_FATAL_ERROR ("Error: Failed to join multicast group"); |
92 } | 116 } |
93 } | 117 } |
94 } | 118 } |
95 | 119 |
96 m_socket->SetRecvCallback (MakeCallback (&UdpEchoServer::HandleRead, this)); | 120 m_socket->SetRecvCallback (MakeCallback (&UdpEchoServer::HandleRead, this)); |
| 121 m_socket6->SetRecvCallback (MakeCallback (&UdpEchoServer::HandleRead, this)); |
97 } | 122 } |
98 | 123 |
99 void· | 124 void· |
100 UdpEchoServer::StopApplication () | 125 UdpEchoServer::StopApplication () |
101 { | 126 { |
102 NS_LOG_FUNCTION_NOARGS (); | 127 NS_LOG_FUNCTION_NOARGS (); |
103 | 128 |
104 if (m_socket != 0)· | 129 if (m_socket != 0)· |
105 { | 130 { |
106 m_socket->Close (); | 131 m_socket->Close (); |
107 m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); | 132 m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); |
108 } | 133 } |
| 134 if (m_socket6 != 0)· |
| 135 { |
| 136 m_socket6->Close (); |
| 137 m_socket6->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); |
| 138 } |
109 } | 139 } |
110 | 140 |
111 void· | 141 void· |
112 UdpEchoServer::HandleRead (Ptr<Socket> socket) | 142 UdpEchoServer::HandleRead (Ptr<Socket> socket) |
113 { | 143 { |
114 Ptr<Packet> packet; | 144 Ptr<Packet> packet; |
115 Address from; | 145 Address from; |
116 while (packet = socket->RecvFrom (from)) | 146 while (packet = socket->RecvFrom (from)) |
117 { | 147 { |
118 if (InetSocketAddress::IsMatchingType (from)) | 148 if (InetSocketAddress::IsMatchingType (from)) |
119 { | 149 { |
120 NS_LOG_INFO ("Received " << packet->GetSize () << " bytes from " << | 150 NS_LOG_INFO ("Received " << packet->GetSize () << " bytes from " << |
121 InetSocketAddress::ConvertFrom (from).GetIpv4 ()); | 151 InetSocketAddress::ConvertFrom (from).GetIpv4 ()); |
122 | 152 |
123 packet->RemoveAllPacketTags (); | 153 packet->RemoveAllPacketTags (); |
124 packet->RemoveAllByteTags (); | 154 packet->RemoveAllByteTags (); |
125 | 155 |
126 NS_LOG_LOGIC ("Echoing packet"); | 156 NS_LOG_LOGIC ("Echoing packet"); |
127 socket->SendTo (packet, 0, from); | 157 socket->SendTo (packet, 0, from); |
128 } | 158 } |
| 159 else if (Inet6SocketAddress::IsMatchingType (from)) |
| 160 { |
| 161 NS_LOG_INFO ("Received " << packet->GetSize () << " bytes from " << |
| 162 Inet6SocketAddress::ConvertFrom (from).GetIpv6 ()); |
| 163 |
| 164 packet->RemoveAllPacketTags (); |
| 165 packet->RemoveAllByteTags (); |
| 166 |
| 167 NS_LOG_LOGIC ("Echoing packet"); |
| 168 socket->SendTo (packet, 0, from); |
| 169 } |
129 } | 170 } |
130 } | 171 } |
131 | 172 |
132 } // Namespace ns3 | 173 } // Namespace ns3 |
OLD | NEW |