1.1 --- a/bindings/python/ns3_module_core.py Mon Oct 27 23:05:57 2008 -0700
1.2 +++ b/bindings/python/ns3_module_core.py Wed Oct 29 11:49:21 2008 -0700
1.3 @@ -2025,6 +2025,10 @@
1.4 module.add_function('MakeStringChecker',
1.5 'ns3::Ptr< ns3::AttributeChecker const >',
1.6 [])
1.7 + ## type-id.h: extern ns3::Ptr<ns3::AttributeChecker const> ns3::MakeTypeIdChecker() [free function]
1.8 + module.add_function('MakeTypeIdChecker',
1.9 + 'ns3::Ptr< ns3::AttributeChecker const >',
1.10 + [])
1.11 ## ptr.h: extern ns3::Ptr<ns3::PointerValue> ns3::Create() [free function]
1.12 module.add_function('Create',
1.13 'ns3::Ptr< ns3::PointerValue >',
1.14 @@ -2039,10 +2043,6 @@
1.15 module.add_function('LogComponentEnableAll',
1.16 'void',
1.17 [param('ns3::LogLevel', 'level')])
1.18 - ## type-id.h: extern ns3::Ptr<ns3::AttributeChecker const> ns3::MakeTypeIdChecker() [free function]
1.19 - module.add_function('MakeTypeIdChecker',
1.20 - 'ns3::Ptr< ns3::AttributeChecker const >',
1.21 - [])
1.22 ## object-factory.h: extern ns3::Ptr<ns3::AttributeChecker const> ns3::MakeObjectFactoryChecker() [free function]
1.23 module.add_function('MakeObjectFactoryChecker',
1.24 'ns3::Ptr< ns3::AttributeChecker const >',
2.1 --- a/bindings/python/ns3_module_internet_stack.py Mon Oct 27 23:05:57 2008 -0700
2.2 +++ b/bindings/python/ns3_module_internet_stack.py Wed Oct 29 11:49:21 2008 -0700
2.3 @@ -3,6 +3,20 @@
2.4 def register_types(module):
2.5 root_module = module.get_root()
2.6
2.7 + ## icmpv4.h: ns3::Icmpv4DestinationUnreachable [class]
2.8 + module.add_class('Icmpv4DestinationUnreachable', parent=root_module['ns3::Header'])
2.9 + ## icmpv4.h: ns3::Icmpv4DestinationUnreachable [enumeration]
2.10 + module.add_enum('', ['NET_UNREACHABLE', 'HOST_UNREACHABLE', 'PROTOCOL_UNREACHABLE', 'PORT_UNREACHABLE', 'FRAG_NEEDED', 'SOURCE_ROUTE_FAILED'], outer_class=root_module['ns3::Icmpv4DestinationUnreachable'])
2.11 + ## icmpv4.h: ns3::Icmpv4Echo [class]
2.12 + module.add_class('Icmpv4Echo', parent=root_module['ns3::Header'])
2.13 + ## icmpv4.h: ns3::Icmpv4Header [class]
2.14 + module.add_class('Icmpv4Header', parent=root_module['ns3::Header'])
2.15 + ## icmpv4.h: ns3::Icmpv4Header [enumeration]
2.16 + module.add_enum('', ['ECHO_REPLY', 'DEST_UNREACH', 'ECHO', 'TIME_EXCEEDED'], outer_class=root_module['ns3::Icmpv4Header'])
2.17 + ## icmpv4.h: ns3::Icmpv4TimeExceeded [class]
2.18 + module.add_class('Icmpv4TimeExceeded', parent=root_module['ns3::Header'])
2.19 + ## icmpv4.h: ns3::Icmpv4TimeExceeded [enumeration]
2.20 + module.add_enum('', ['TIME_TO_LIVE', 'FRAGMENT_REASSEMBLY'], outer_class=root_module['ns3::Icmpv4TimeExceeded'])
2.21 ## tcp-header.h: ns3::TcpHeader [class]
2.22 module.add_class('TcpHeader', parent=root_module['ns3::Header'])
2.23 ## tcp-header.h: ns3::TcpHeader::Flags_t [enumeration]
2.24 @@ -57,6 +71,10 @@
2.25
2.26
2.27 def register_methods(root_module):
2.28 + register_Ns3Icmpv4DestinationUnreachable_methods(root_module, root_module['ns3::Icmpv4DestinationUnreachable'])
2.29 + register_Ns3Icmpv4Echo_methods(root_module, root_module['ns3::Icmpv4Echo'])
2.30 + register_Ns3Icmpv4Header_methods(root_module, root_module['ns3::Icmpv4Header'])
2.31 + register_Ns3Icmpv4TimeExceeded_methods(root_module, root_module['ns3::Icmpv4TimeExceeded'])
2.32 register_Ns3TcpHeader_methods(root_module, root_module['ns3::TcpHeader'])
2.33 register_Ns3UdpHeader_methods(root_module, root_module['ns3::UdpHeader'])
2.34 register_Ns3Ipv4Interface_methods(root_module, root_module['ns3::Ipv4Interface'])
2.35 @@ -64,6 +82,248 @@
2.36 register_Ns3Ipv4StaticRouting_methods(root_module, root_module['ns3::Ipv4StaticRouting'])
2.37 return
2.38
2.39 +def register_Ns3Icmpv4DestinationUnreachable_methods(root_module, cls):
2.40 + ## icmpv4.h: ns3::Icmpv4DestinationUnreachable::Icmpv4DestinationUnreachable(ns3::Icmpv4DestinationUnreachable const & arg0) [copy constructor]
2.41 + cls.add_constructor([param('ns3::Icmpv4DestinationUnreachable const &', 'arg0')])
2.42 + ## icmpv4.h: static ns3::TypeId ns3::Icmpv4DestinationUnreachable::GetTypeId() [member function]
2.43 + cls.add_method('GetTypeId',
2.44 + 'ns3::TypeId',
2.45 + [],
2.46 + is_static=True)
2.47 + ## icmpv4.h: ns3::Icmpv4DestinationUnreachable::Icmpv4DestinationUnreachable() [constructor]
2.48 + cls.add_constructor([])
2.49 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::SetNextHopMtu(uint16_t mtu) [member function]
2.50 + cls.add_method('SetNextHopMtu',
2.51 + 'void',
2.52 + [param('uint16_t', 'mtu')])
2.53 + ## icmpv4.h: uint16_t ns3::Icmpv4DestinationUnreachable::GetNextHopMtu() const [member function]
2.54 + cls.add_method('GetNextHopMtu',
2.55 + 'uint16_t',
2.56 + [],
2.57 + is_const=True)
2.58 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::SetData(ns3::Ptr<const ns3::Packet> data) [member function]
2.59 + cls.add_method('SetData',
2.60 + 'void',
2.61 + [param('ns3::Ptr< ns3::Packet const >', 'data')])
2.62 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::SetHeader(ns3::Ipv4Header header) [member function]
2.63 + cls.add_method('SetHeader',
2.64 + 'void',
2.65 + [param('ns3::Ipv4Header', 'header')])
2.66 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::GetData(uint8_t * payload) const [member function]
2.67 + cls.add_method('GetData',
2.68 + 'void',
2.69 + [param('uint8_t *', 'payload')],
2.70 + is_const=True)
2.71 + ## icmpv4.h: ns3::Ipv4Header ns3::Icmpv4DestinationUnreachable::GetHeader() const [member function]
2.72 + cls.add_method('GetHeader',
2.73 + 'ns3::Ipv4Header',
2.74 + [],
2.75 + is_const=True)
2.76 + ## icmpv4.h: ns3::TypeId ns3::Icmpv4DestinationUnreachable::GetInstanceTypeId() const [member function]
2.77 + cls.add_method('GetInstanceTypeId',
2.78 + 'ns3::TypeId',
2.79 + [],
2.80 + is_const=True, visibility='private', is_virtual=True)
2.81 + ## icmpv4.h: uint32_t ns3::Icmpv4DestinationUnreachable::GetSerializedSize() const [member function]
2.82 + cls.add_method('GetSerializedSize',
2.83 + 'uint32_t',
2.84 + [],
2.85 + is_const=True, visibility='private', is_virtual=True)
2.86 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::Serialize(ns3::Buffer::Iterator start) const [member function]
2.87 + cls.add_method('Serialize',
2.88 + 'void',
2.89 + [param('ns3::Buffer::Iterator', 'start')],
2.90 + is_const=True, visibility='private', is_virtual=True)
2.91 + ## icmpv4.h: uint32_t ns3::Icmpv4DestinationUnreachable::Deserialize(ns3::Buffer::Iterator start) [member function]
2.92 + cls.add_method('Deserialize',
2.93 + 'uint32_t',
2.94 + [param('ns3::Buffer::Iterator', 'start')],
2.95 + visibility='private', is_virtual=True)
2.96 + ## icmpv4.h: void ns3::Icmpv4DestinationUnreachable::Print(std::ostream & os) const [member function]
2.97 + cls.add_method('Print',
2.98 + 'void',
2.99 + [param('std::ostream &', 'os')],
2.100 + is_const=True, visibility='private', is_virtual=True)
2.101 + return
2.102 +
2.103 +def register_Ns3Icmpv4Echo_methods(root_module, cls):
2.104 + ## icmpv4.h: ns3::Icmpv4Echo::Icmpv4Echo(ns3::Icmpv4Echo const & arg0) [copy constructor]
2.105 + cls.add_constructor([param('ns3::Icmpv4Echo const &', 'arg0')])
2.106 + ## icmpv4.h: void ns3::Icmpv4Echo::SetIdentifier(uint16_t id) [member function]
2.107 + cls.add_method('SetIdentifier',
2.108 + 'void',
2.109 + [param('uint16_t', 'id')])
2.110 + ## icmpv4.h: void ns3::Icmpv4Echo::SetSequenceNumber(uint16_t seq) [member function]
2.111 + cls.add_method('SetSequenceNumber',
2.112 + 'void',
2.113 + [param('uint16_t', 'seq')])
2.114 + ## icmpv4.h: void ns3::Icmpv4Echo::SetData(ns3::Ptr<const ns3::Packet> data) [member function]
2.115 + cls.add_method('SetData',
2.116 + 'void',
2.117 + [param('ns3::Ptr< ns3::Packet const >', 'data')])
2.118 + ## icmpv4.h: uint16_t ns3::Icmpv4Echo::GetIdentifier() const [member function]
2.119 + cls.add_method('GetIdentifier',
2.120 + 'uint16_t',
2.121 + [],
2.122 + is_const=True)
2.123 + ## icmpv4.h: uint16_t ns3::Icmpv4Echo::GetSequenceNumber() const [member function]
2.124 + cls.add_method('GetSequenceNumber',
2.125 + 'uint16_t',
2.126 + [],
2.127 + is_const=True)
2.128 + ## icmpv4.h: ns3::Ptr<const ns3::Packet> ns3::Icmpv4Echo::GetData() const [member function]
2.129 + cls.add_method('GetData',
2.130 + 'ns3::Ptr< ns3::Packet const >',
2.131 + [],
2.132 + is_const=True)
2.133 + ## icmpv4.h: static ns3::TypeId ns3::Icmpv4Echo::GetTypeId() [member function]
2.134 + cls.add_method('GetTypeId',
2.135 + 'ns3::TypeId',
2.136 + [],
2.137 + is_static=True)
2.138 + ## icmpv4.h: ns3::Icmpv4Echo::Icmpv4Echo() [constructor]
2.139 + cls.add_constructor([])
2.140 + ## icmpv4.h: ns3::TypeId ns3::Icmpv4Echo::GetInstanceTypeId() const [member function]
2.141 + cls.add_method('GetInstanceTypeId',
2.142 + 'ns3::TypeId',
2.143 + [],
2.144 + is_const=True, is_virtual=True)
2.145 + ## icmpv4.h: uint32_t ns3::Icmpv4Echo::GetSerializedSize() const [member function]
2.146 + cls.add_method('GetSerializedSize',
2.147 + 'uint32_t',
2.148 + [],
2.149 + is_const=True, is_virtual=True)
2.150 + ## icmpv4.h: void ns3::Icmpv4Echo::Serialize(ns3::Buffer::Iterator start) const [member function]
2.151 + cls.add_method('Serialize',
2.152 + 'void',
2.153 + [param('ns3::Buffer::Iterator', 'start')],
2.154 + is_const=True, is_virtual=True)
2.155 + ## icmpv4.h: uint32_t ns3::Icmpv4Echo::Deserialize(ns3::Buffer::Iterator start) [member function]
2.156 + cls.add_method('Deserialize',
2.157 + 'uint32_t',
2.158 + [param('ns3::Buffer::Iterator', 'start')],
2.159 + is_virtual=True)
2.160 + ## icmpv4.h: void ns3::Icmpv4Echo::Print(std::ostream & os) const [member function]
2.161 + cls.add_method('Print',
2.162 + 'void',
2.163 + [param('std::ostream &', 'os')],
2.164 + is_const=True, is_virtual=True)
2.165 + return
2.166 +
2.167 +def register_Ns3Icmpv4Header_methods(root_module, cls):
2.168 + ## icmpv4.h: ns3::Icmpv4Header::Icmpv4Header(ns3::Icmpv4Header const & arg0) [copy constructor]
2.169 + cls.add_constructor([param('ns3::Icmpv4Header const &', 'arg0')])
2.170 + ## icmpv4.h: void ns3::Icmpv4Header::EnableChecksum() [member function]
2.171 + cls.add_method('EnableChecksum',
2.172 + 'void',
2.173 + [])
2.174 + ## icmpv4.h: void ns3::Icmpv4Header::SetType(uint8_t type) [member function]
2.175 + cls.add_method('SetType',
2.176 + 'void',
2.177 + [param('uint8_t', 'type')])
2.178 + ## icmpv4.h: void ns3::Icmpv4Header::SetCode(uint8_t code) [member function]
2.179 + cls.add_method('SetCode',
2.180 + 'void',
2.181 + [param('uint8_t', 'code')])
2.182 + ## icmpv4.h: uint8_t ns3::Icmpv4Header::GetType() const [member function]
2.183 + cls.add_method('GetType',
2.184 + 'uint8_t',
2.185 + [],
2.186 + is_const=True)
2.187 + ## icmpv4.h: uint8_t ns3::Icmpv4Header::GetCode() const [member function]
2.188 + cls.add_method('GetCode',
2.189 + 'uint8_t',
2.190 + [],
2.191 + is_const=True)
2.192 + ## icmpv4.h: static ns3::TypeId ns3::Icmpv4Header::GetTypeId() [member function]
2.193 + cls.add_method('GetTypeId',
2.194 + 'ns3::TypeId',
2.195 + [],
2.196 + is_static=True)
2.197 + ## icmpv4.h: ns3::Icmpv4Header::Icmpv4Header() [constructor]
2.198 + cls.add_constructor([])
2.199 + ## icmpv4.h: ns3::TypeId ns3::Icmpv4Header::GetInstanceTypeId() const [member function]
2.200 + cls.add_method('GetInstanceTypeId',
2.201 + 'ns3::TypeId',
2.202 + [],
2.203 + is_const=True, is_virtual=True)
2.204 + ## icmpv4.h: uint32_t ns3::Icmpv4Header::GetSerializedSize() const [member function]
2.205 + cls.add_method('GetSerializedSize',
2.206 + 'uint32_t',
2.207 + [],
2.208 + is_const=True, is_virtual=True)
2.209 + ## icmpv4.h: void ns3::Icmpv4Header::Serialize(ns3::Buffer::Iterator start) const [member function]
2.210 + cls.add_method('Serialize',
2.211 + 'void',
2.212 + [param('ns3::Buffer::Iterator', 'start')],
2.213 + is_const=True, is_virtual=True)
2.214 + ## icmpv4.h: uint32_t ns3::Icmpv4Header::Deserialize(ns3::Buffer::Iterator start) [member function]
2.215 + cls.add_method('Deserialize',
2.216 + 'uint32_t',
2.217 + [param('ns3::Buffer::Iterator', 'start')],
2.218 + is_virtual=True)
2.219 + ## icmpv4.h: void ns3::Icmpv4Header::Print(std::ostream & os) const [member function]
2.220 + cls.add_method('Print',
2.221 + 'void',
2.222 + [param('std::ostream &', 'os')],
2.223 + is_const=True, is_virtual=True)
2.224 + return
2.225 +
2.226 +def register_Ns3Icmpv4TimeExceeded_methods(root_module, cls):
2.227 + ## icmpv4.h: ns3::Icmpv4TimeExceeded::Icmpv4TimeExceeded(ns3::Icmpv4TimeExceeded const & arg0) [copy constructor]
2.228 + cls.add_constructor([param('ns3::Icmpv4TimeExceeded const &', 'arg0')])
2.229 + ## icmpv4.h: void ns3::Icmpv4TimeExceeded::SetData(ns3::Ptr<const ns3::Packet> data) [member function]
2.230 + cls.add_method('SetData',
2.231 + 'void',
2.232 + [param('ns3::Ptr< ns3::Packet const >', 'data')])
2.233 + ## icmpv4.h: void ns3::Icmpv4TimeExceeded::SetHeader(ns3::Ipv4Header header) [member function]
2.234 + cls.add_method('SetHeader',
2.235 + 'void',
2.236 + [param('ns3::Ipv4Header', 'header')])
2.237 + ## icmpv4.h: void ns3::Icmpv4TimeExceeded::GetData(uint8_t * payload) const [member function]
2.238 + cls.add_method('GetData',
2.239 + 'void',
2.240 + [param('uint8_t *', 'payload')],
2.241 + is_const=True)
2.242 + ## icmpv4.h: ns3::Ipv4Header ns3::Icmpv4TimeExceeded::GetHeader() const [member function]
2.243 + cls.add_method('GetHeader',
2.244 + 'ns3::Ipv4Header',
2.245 + [],
2.246 + is_const=True)
2.247 + ## icmpv4.h: static ns3::TypeId ns3::Icmpv4TimeExceeded::GetTypeId() [member function]
2.248 + cls.add_method('GetTypeId',
2.249 + 'ns3::TypeId',
2.250 + [],
2.251 + is_static=True)
2.252 + ## icmpv4.h: ns3::Icmpv4TimeExceeded::Icmpv4TimeExceeded() [constructor]
2.253 + cls.add_constructor([])
2.254 + ## icmpv4.h: ns3::TypeId ns3::Icmpv4TimeExceeded::GetInstanceTypeId() const [member function]
2.255 + cls.add_method('GetInstanceTypeId',
2.256 + 'ns3::TypeId',
2.257 + [],
2.258 + is_const=True, is_virtual=True)
2.259 + ## icmpv4.h: uint32_t ns3::Icmpv4TimeExceeded::GetSerializedSize() const [member function]
2.260 + cls.add_method('GetSerializedSize',
2.261 + 'uint32_t',
2.262 + [],
2.263 + is_const=True, is_virtual=True)
2.264 + ## icmpv4.h: void ns3::Icmpv4TimeExceeded::Serialize(ns3::Buffer::Iterator start) const [member function]
2.265 + cls.add_method('Serialize',
2.266 + 'void',
2.267 + [param('ns3::Buffer::Iterator', 'start')],
2.268 + is_const=True, is_virtual=True)
2.269 + ## icmpv4.h: uint32_t ns3::Icmpv4TimeExceeded::Deserialize(ns3::Buffer::Iterator start) [member function]
2.270 + cls.add_method('Deserialize',
2.271 + 'uint32_t',
2.272 + [param('ns3::Buffer::Iterator', 'start')],
2.273 + is_virtual=True)
2.274 + ## icmpv4.h: void ns3::Icmpv4TimeExceeded::Print(std::ostream & os) const [member function]
2.275 + cls.add_method('Print',
2.276 + 'void',
2.277 + [param('std::ostream &', 'os')],
2.278 + is_const=True, is_virtual=True)
2.279 + return
2.280 +
2.281 def register_Ns3TcpHeader_methods(root_module, cls):
2.282 ## tcp-header.h: ns3::TcpHeader::TcpHeader(ns3::TcpHeader const & arg0) [copy constructor]
2.283 cls.add_constructor([param('ns3::TcpHeader const &', 'arg0')])
2.284 @@ -354,6 +614,14 @@
2.285 cls.add_method('SetNode',
2.286 'void',
2.287 [param('ns3::Ptr< ns3::Node >', 'node')])
2.288 + ## ipv4-l3-protocol.h: ns3::Ptr<ns3::Socket> ns3::Ipv4L3Protocol::CreateRawSocket() [member function]
2.289 + cls.add_method('CreateRawSocket',
2.290 + 'ns3::Ptr< ns3::Socket >',
2.291 + [])
2.292 + ## ipv4-l3-protocol.h: void ns3::Ipv4L3Protocol::DeleteRawSocket(ns3::Ptr<ns3::Socket> socket) [member function]
2.293 + cls.add_method('DeleteRawSocket',
2.294 + 'void',
2.295 + [param('ns3::Ptr< ns3::Socket >', 'socket')])
2.296 ## ipv4-l3-protocol.h: void ns3::Ipv4L3Protocol::Insert(ns3::Ptr<ns3::Ipv4L4Protocol> protocol) [member function]
2.297 cls.add_method('Insert',
2.298 'void',
3.1 --- a/bindings/python/ns3_module_node.py Mon Oct 27 23:05:57 2008 -0700
3.2 +++ b/bindings/python/ns3_module_node.py Wed Oct 29 11:49:21 2008 -0700
3.3 @@ -67,6 +67,8 @@
3.4 module.add_class('SocketFactory', parent=root_module['ns3::Object'])
3.5 ## socket.h: ns3::SocketIpTtlTag [class]
3.6 module.add_class('SocketIpTtlTag', parent=root_module['ns3::Tag'])
3.7 + ## socket.h: ns3::SocketSetDontFragmentTag [class]
3.8 + module.add_class('SocketSetDontFragmentTag', parent=root_module['ns3::Tag'])
3.9 ## tcp-socket.h: ns3::TcpSocket [class]
3.10 module.add_class('TcpSocket', parent=root_module['ns3::Socket'])
3.11 ## tcp-socket-factory.h: ns3::TcpSocketFactory [class]
3.12 @@ -91,6 +93,8 @@
3.13 module.add_class('EthernetTrailer', parent=root_module['ns3::Trailer'])
3.14 ## ipv4.h: ns3::Ipv4 [class]
3.15 module.add_class('Ipv4', parent=root_module['ns3::Object'])
3.16 + ## ipv4-raw-socket-factory.h: ns3::Ipv4RawSocketFactory [class]
3.17 + module.add_class('Ipv4RawSocketFactory', parent=root_module['ns3::SocketFactory'])
3.18 ## ipv4.h: ns3::Ipv4RoutingProtocol [class]
3.19 module.add_class('Ipv4RoutingProtocol', parent=root_module['ns3::Object'])
3.20 ## net-device.h: ns3::NetDevice [class]
3.21 @@ -172,6 +176,7 @@
3.22 register_Ns3SocketAddressTag_methods(root_module, root_module['ns3::SocketAddressTag'])
3.23 register_Ns3SocketFactory_methods(root_module, root_module['ns3::SocketFactory'])
3.24 register_Ns3SocketIpTtlTag_methods(root_module, root_module['ns3::SocketIpTtlTag'])
3.25 + register_Ns3SocketSetDontFragmentTag_methods(root_module, root_module['ns3::SocketSetDontFragmentTag'])
3.26 register_Ns3TcpSocket_methods(root_module, root_module['ns3::TcpSocket'])
3.27 register_Ns3TcpSocketFactory_methods(root_module, root_module['ns3::TcpSocketFactory'])
3.28 register_Ns3UdpSocket_methods(root_module, root_module['ns3::UdpSocket'])
3.29 @@ -184,6 +189,7 @@
3.30 register_Ns3EthernetHeader_methods(root_module, root_module['ns3::EthernetHeader'])
3.31 register_Ns3EthernetTrailer_methods(root_module, root_module['ns3::EthernetTrailer'])
3.32 register_Ns3Ipv4_methods(root_module, root_module['ns3::Ipv4'])
3.33 + register_Ns3Ipv4RawSocketFactory_methods(root_module, root_module['ns3::Ipv4RawSocketFactory'])
3.34 register_Ns3Ipv4RoutingProtocol_methods(root_module, root_module['ns3::Ipv4RoutingProtocol'])
3.35 register_Ns3NetDevice_methods(root_module, root_module['ns3::NetDevice'])
3.36 register_Ns3Node_methods(root_module, root_module['ns3::Node'])
3.37 @@ -1507,6 +1513,56 @@
3.38 is_const=True, is_virtual=True)
3.39 return
3.40
3.41 +def register_Ns3SocketSetDontFragmentTag_methods(root_module, cls):
3.42 + ## socket.h: ns3::SocketSetDontFragmentTag::SocketSetDontFragmentTag(ns3::SocketSetDontFragmentTag const & arg0) [copy constructor]
3.43 + cls.add_constructor([param('ns3::SocketSetDontFragmentTag const &', 'arg0')])
3.44 + ## socket.h: ns3::SocketSetDontFragmentTag::SocketSetDontFragmentTag() [constructor]
3.45 + cls.add_constructor([])
3.46 + ## socket.h: void ns3::SocketSetDontFragmentTag::Enable() [member function]
3.47 + cls.add_method('Enable',
3.48 + 'void',
3.49 + [])
3.50 + ## socket.h: void ns3::SocketSetDontFragmentTag::Disable() [member function]
3.51 + cls.add_method('Disable',
3.52 + 'void',
3.53 + [])
3.54 + ## socket.h: bool ns3::SocketSetDontFragmentTag::IsEnabled() const [member function]
3.55 + cls.add_method('IsEnabled',
3.56 + 'bool',
3.57 + [],
3.58 + is_const=True)
3.59 + ## socket.h: static ns3::TypeId ns3::SocketSetDontFragmentTag::GetTypeId() [member function]
3.60 + cls.add_method('GetTypeId',
3.61 + 'ns3::TypeId',
3.62 + [],
3.63 + is_static=True)
3.64 + ## socket.h: ns3::TypeId ns3::SocketSetDontFragmentTag::GetInstanceTypeId() const [member function]
3.65 + cls.add_method('GetInstanceTypeId',
3.66 + 'ns3::TypeId',
3.67 + [],
3.68 + is_const=True, is_virtual=True)
3.69 + ## socket.h: uint32_t ns3::SocketSetDontFragmentTag::GetSerializedSize() const [member function]
3.70 + cls.add_method('GetSerializedSize',
3.71 + 'uint32_t',
3.72 + [],
3.73 + is_const=True, is_virtual=True)
3.74 + ## socket.h: void ns3::SocketSetDontFragmentTag::Serialize(ns3::TagBuffer i) const [member function]
3.75 + cls.add_method('Serialize',
3.76 + 'void',
3.77 + [param('ns3::TagBuffer', 'i')],
3.78 + is_const=True, is_virtual=True)
3.79 + ## socket.h: void ns3::SocketSetDontFragmentTag::Deserialize(ns3::TagBuffer i) [member function]
3.80 + cls.add_method('Deserialize',
3.81 + 'void',
3.82 + [param('ns3::TagBuffer', 'i')],
3.83 + is_virtual=True)
3.84 + ## socket.h: void ns3::SocketSetDontFragmentTag::Print(std::ostream & os) const [member function]
3.85 + cls.add_method('Print',
3.86 + 'void',
3.87 + [param('std::ostream &', 'os')],
3.88 + is_const=True, is_virtual=True)
3.89 + return
3.90 +
3.91 def register_Ns3TcpSocket_methods(root_module, cls):
3.92 ## tcp-socket.h: ns3::TcpSocket::TcpSocket(ns3::TcpSocket const & arg0) [copy constructor]
3.93 cls.add_constructor([param('ns3::TcpSocket const &', 'arg0')])
3.94 @@ -1661,6 +1717,16 @@
3.95 'uint32_t',
3.96 [],
3.97 is_pure_virtual=True, is_const=True, visibility='private', is_virtual=True)
3.98 + ## udp-socket.h: void ns3::UdpSocket::SetMtuDiscover(bool discover) [member function]
3.99 + cls.add_method('SetMtuDiscover',
3.100 + 'void',
3.101 + [param('bool', 'discover')],
3.102 + is_pure_virtual=True, visibility='private', is_virtual=True)
3.103 + ## udp-socket.h: bool ns3::UdpSocket::GetMtuDiscover() const [member function]
3.104 + cls.add_method('GetMtuDiscover',
3.105 + 'bool',
3.106 + [],
3.107 + is_pure_virtual=True, is_const=True, visibility='private', is_virtual=True)
3.108 return
3.109
3.110 def register_Ns3UdpSocketFactory_methods(root_module, cls):
3.111 @@ -2167,6 +2233,18 @@
3.112 is_virtual=True)
3.113 return
3.114
3.115 +def register_Ns3Ipv4RawSocketFactory_methods(root_module, cls):
3.116 + ## ipv4-raw-socket-factory.h: ns3::Ipv4RawSocketFactory::Ipv4RawSocketFactory(ns3::Ipv4RawSocketFactory const & arg0) [copy constructor]
3.117 + cls.add_constructor([param('ns3::Ipv4RawSocketFactory const &', 'arg0')])
3.118 + ## ipv4-raw-socket-factory.h: ns3::Ipv4RawSocketFactory::Ipv4RawSocketFactory() [constructor]
3.119 + cls.add_constructor([])
3.120 + ## ipv4-raw-socket-factory.h: static ns3::TypeId ns3::Ipv4RawSocketFactory::GetTypeId() [member function]
3.121 + cls.add_method('GetTypeId',
3.122 + 'ns3::TypeId',
3.123 + [],
3.124 + is_static=True)
3.125 + return
3.126 +
3.127 def register_Ns3Ipv4RoutingProtocol_methods(root_module, cls):
3.128 ## ipv4.h: ns3::Ipv4RoutingProtocol::IF_INDEX_ANY [variable]
3.129 cls.add_static_attribute('IF_INDEX_ANY', 'uint32_t const', is_const=True)
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/examples/csma-ping.cc Wed Oct 29 11:49:21 2008 -0700
4.3 @@ -0,0 +1,140 @@
4.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4.5 +/*
4.6 + * This program is free software; you can redistribute it and/or modify
4.7 + * it under the terms of the GNU General Public License version 2 as
4.8 + * published by the Free Software Foundation;
4.9 + *
4.10 + * This program is distributed in the hope that it will be useful,
4.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.13 + * GNU General Public License for more details.
4.14 + *
4.15 + * You should have received a copy of the GNU General Public License
4.16 + * along with this program; if not, write to the Free Software
4.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4.18 + */
4.19 +
4.20 +// Port of ns-2/tcl/ex/simple.tcl to ns-3
4.21 +//
4.22 +// Network topology
4.23 +//
4.24 +// n0 n1 n2 n3
4.25 +// | | | |
4.26 +// =====================
4.27 +//
4.28 +// - CBR/UDP flows from n0 to n1, and from n3 to n0
4.29 +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
4.30 +// (i.e., DataRate of 448,000 bps)
4.31 +// - DropTail queues
4.32 +// - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
4.33 +
4.34 +#include <iostream>
4.35 +#include <fstream>
4.36 +#include <string>
4.37 +#include <cassert>
4.38 +
4.39 +#include "ns3/core-module.h"
4.40 +#include "ns3/simulator-module.h"
4.41 +#include "ns3/node-module.h"
4.42 +#include "ns3/helper-module.h"
4.43 +#include "ns3/global-route-manager.h"
4.44 +
4.45 +using namespace ns3;
4.46 +
4.47 +NS_LOG_COMPONENT_DEFINE ("CsmaPingExample");
4.48 +
4.49 +static void SinkRx (Ptr<const Packet> p, const Address &ad)
4.50 +{
4.51 + //std::cout << *p << std::endl;
4.52 +}
4.53 +
4.54 +static void PingRtt (std::string context, Time rtt)
4.55 +{
4.56 + //std::cout << context << " " << rtt << std::endl;
4.57 +}
4.58 +
4.59 +int
4.60 +main (int argc, char *argv[])
4.61 +{
4.62 + //
4.63 + // Make the random number generators generate reproducible results.
4.64 + //
4.65 + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
4.66 +
4.67 + CommandLine cmd;
4.68 + cmd.Parse (argc, argv);
4.69 +
4.70 + // Here, we will explicitly create four nodes.
4.71 + NS_LOG_INFO ("Create nodes.");
4.72 + NodeContainer c;
4.73 + c.Create (4);
4.74 +
4.75 + // connect all our nodes to a shared channel.
4.76 + NS_LOG_INFO ("Build Topology.");
4.77 + CsmaHelper csma;
4.78 + csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
4.79 + csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
4.80 + csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
4.81 + NetDeviceContainer devs = csma.Install (c);
4.82 +
4.83 + // add an ip stack to all nodes.
4.84 + NS_LOG_INFO ("Add ip stack.");
4.85 + InternetStackHelper ipStack;
4.86 + ipStack.Install (c);
4.87 +
4.88 + // assign ip addresses
4.89 + NS_LOG_INFO ("Assign ip addresses.");
4.90 + Ipv4AddressHelper ip;
4.91 + ip.SetBase ("192.168.1.0", "255.255.255.0");
4.92 + Ipv4InterfaceContainer addresses = ip.Assign (devs);
4.93 +
4.94 + // setup global router
4.95 + GlobalRouteManager::PopulateRoutingTables ();
4.96 + NS_LOG_INFO ("Create Source");
4.97 + Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
4.98 + InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
4.99 + OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
4.100 + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
4.101 + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
4.102 + onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000)));
4.103 + onoff.SetAttribute ("PacketSize", UintegerValue (1200));
4.104 +
4.105 +
4.106 + ApplicationContainer apps = onoff.Install (c.Get (0));
4.107 + apps.Start (Seconds (1.0));
4.108 + apps.Stop (Seconds (10.0));
4.109 +
4.110 + NS_LOG_INFO ("Create Sink.");
4.111 + PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
4.112 + apps = sink.Install (c.Get (3));
4.113 + apps.Start (Seconds (0.0));
4.114 + apps.Stop (Seconds (11.0));
4.115 +
4.116 + NS_LOG_INFO ("Create pinger");
4.117 + V4PingHelper ping = V4PingHelper (addresses.GetAddress (2));
4.118 + NodeContainer pingers;
4.119 + pingers.Add (c.Get (0));
4.120 + pingers.Add (c.Get (1));
4.121 + pingers.Add (c.Get (3));
4.122 + apps = ping.Install (pingers);
4.123 + apps.Start (Seconds (2.0));
4.124 + apps.Stop (Seconds (5.0));
4.125 +
4.126 + NS_LOG_INFO ("Configure Tracing.");
4.127 + // first, pcap tracing.
4.128 + csma.EnablePcapAll ("csma-ping");
4.129 + // then, print what the packet sink receives.
4.130 + Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
4.131 + MakeCallback (&SinkRx));
4.132 + // finally, print the ping rtts.
4.133 + Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
4.134 + MakeCallback (&PingRtt));
4.135 +
4.136 + Packet::EnablePrinting ();
4.137 +
4.138 +
4.139 + NS_LOG_INFO ("Run Simulation.");
4.140 + Simulator::Run ();
4.141 + Simulator::Destroy ();
4.142 + NS_LOG_INFO ("Done.");
4.143 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/examples/csma-raw-ip-socket.cc Wed Oct 29 11:49:21 2008 -0700
5.3 @@ -0,0 +1,122 @@
5.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5.5 +/*
5.6 + * This program is free software; you can redistribute it and/or modify
5.7 + * it under the terms of the GNU General Public License version 2 as
5.8 + * published by the Free Software Foundation;
5.9 + *
5.10 + * This program is distributed in the hope that it will be useful,
5.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.13 + * GNU General Public License for more details.
5.14 + *
5.15 + * You should have received a copy of the GNU General Public License
5.16 + * along with this program; if not, write to the Free Software
5.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5.18 + */
5.19 +
5.20 +// Port of ns-2/tcl/ex/simple.tcl to ns-3
5.21 +//
5.22 +// Network topology
5.23 +//
5.24 +// n0 n1 n2 n3
5.25 +// | | | |
5.26 +// =====================
5.27 +//
5.28 +// - CBR/UDP flows from n0 to n1, and from n3 to n0
5.29 +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
5.30 +// (i.e., DataRate of 448,000 bps)
5.31 +// - DropTail queues
5.32 +// - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
5.33 +
5.34 +#include <iostream>
5.35 +#include <fstream>
5.36 +#include <string>
5.37 +#include <cassert>
5.38 +
5.39 +#include "ns3/core-module.h"
5.40 +#include "ns3/simulator-module.h"
5.41 +#include "ns3/node-module.h"
5.42 +#include "ns3/helper-module.h"
5.43 +
5.44 +using namespace ns3;
5.45 +
5.46 +NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
5.47 +
5.48 +static void SinkRx (Ptr<const Packet> p, const Address &ad)
5.49 +{
5.50 + //std::cout << *p << std::endl;
5.51 +}
5.52 +
5.53 +int
5.54 +main (int argc, char *argv[])
5.55 +{
5.56 +#if 0
5.57 + LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
5.58 +#endif
5.59 +
5.60 + //
5.61 + // Make the random number generators generate reproducible results.
5.62 + //
5.63 + RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
5.64 +
5.65 + CommandLine cmd;
5.66 + cmd.Parse (argc, argv);
5.67 +
5.68 + // Here, we will explicitly create four nodes.
5.69 + NS_LOG_INFO ("Create nodes.");
5.70 + NodeContainer c;
5.71 + c.Create (4);
5.72 +
5.73 + // connect all our nodes to a shared channel.
5.74 + NS_LOG_INFO ("Build Topology.");
5.75 + CsmaHelper csma;
5.76 + csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
5.77 + csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
5.78 + csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
5.79 + NetDeviceContainer devs = csma.Install (c);
5.80 +
5.81 + // add an ip stack to all nodes.
5.82 + NS_LOG_INFO ("Add ip stack.");
5.83 + InternetStackHelper ipStack;
5.84 + ipStack.Install (c);
5.85 +
5.86 + // assign ip addresses
5.87 + NS_LOG_INFO ("Assign ip addresses.");
5.88 + Ipv4AddressHelper ip;
5.89 + ip.SetBase ("192.168.1.0", "255.255.255.0");
5.90 + Ipv4InterfaceContainer addresses = ip.Assign (devs);
5.91 +
5.92 + NS_LOG_INFO ("Create Source");
5.93 + Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
5.94 + InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
5.95 + OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
5.96 + onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
5.97 + onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
5.98 + onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
5.99 + onoff.SetAttribute ("PacketSize", UintegerValue (1200));
5.100 +
5.101 + ApplicationContainer apps = onoff.Install (c.Get (0));
5.102 + apps.Start (Seconds (1.0));
5.103 + apps.Stop (Seconds (10.0));
5.104 +
5.105 + NS_LOG_INFO ("Create Sink.");
5.106 + PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
5.107 + apps = sink.Install (c.Get (3));
5.108 + apps.Start (Seconds (0.0));
5.109 + apps.Stop (Seconds (11.0));
5.110 +
5.111 + NS_LOG_INFO ("Configure Tracing.");
5.112 + // first, pcap tracing.
5.113 + csma.EnablePcapAll ("csma-raw-ip-socket");
5.114 + // then, print what the packet sink receives.
5.115 + Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
5.116 + MakeCallback (&SinkRx));
5.117 +
5.118 + Packet::EnablePrinting ();
5.119 +
5.120 +
5.121 + NS_LOG_INFO ("Run Simulation.");
5.122 + Simulator::Run ();
5.123 + Simulator::Destroy ();
5.124 + NS_LOG_INFO ("Done.");
5.125 +}
6.1 --- a/examples/wscript Mon Oct 27 23:05:57 2008 -0700
6.2 +++ b/examples/wscript Wed Oct 29 11:49:21 2008 -0700
6.3 @@ -94,3 +94,11 @@
6.4 ['core', 'simulator', 'mobility', 'wifi',
6.5 'csma', 'helper', 'bridge'])
6.6 obj.source = 'wifi-wired-bridging.cc'
6.7 +
6.8 + obj = bld.create_ns3_program('csma-raw-ip-socket',
6.9 + ['csma', 'internet-stack'])
6.10 + obj.source = 'csma-raw-ip-socket.cc'
6.11 +
6.12 + obj = bld.create_ns3_program('csma-ping',
6.13 + ['csma', 'internet-stack', 'v4ping'])
6.14 + obj.source = 'csma-ping.cc'
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/regression/tests/test-csma-ping.py Wed Oct 29 11:49:21 2008 -0700
7.3 @@ -0,0 +1,12 @@
7.4 +#! /usr/bin/env python
7.5 +
7.6 +"""Generic trace-comparison-type regression test."""
7.7 +
7.8 +import os
7.9 +import shutil
7.10 +import tracediff
7.11 +
7.12 +def run(verbose, generate, refDirName):
7.13 + """Execute a test."""
7.14 +
7.15 + return tracediff.run_test(verbose, generate, refDirName, "csma-ping")
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/regression/tests/test-csma-raw-ip-socket.py Wed Oct 29 11:49:21 2008 -0700
8.3 @@ -0,0 +1,12 @@
8.4 +#! /usr/bin/env python
8.5 +
8.6 +"""Generic trace-comparison-type regression test."""
8.7 +
8.8 +import os
8.9 +import shutil
8.10 +import tracediff
8.11 +
8.12 +def run(verbose, generate, refDirName):
8.13 + """Execute a test."""
8.14 +
8.15 + return tracediff.run_test(verbose, generate, refDirName, "csma-raw-ip-socket")
9.1 --- a/src/applications/onoff/onoff-application.cc Mon Oct 27 23:05:57 2008 -0700
9.2 +++ b/src/applications/onoff/onoff-application.cc Wed Oct 29 11:49:21 2008 -0700
9.3 @@ -147,7 +147,14 @@
9.4 NS_LOG_FUNCTION_NOARGS ();
9.5
9.6 CancelEvents ();
9.7 - m_socket->Close ();
9.8 + if(m_socket != 0)
9.9 + {
9.10 + m_socket->Close ();
9.11 + }
9.12 + else
9.13 + {
9.14 + NS_LOG_WARN("OnOffApplication found null socket to close in StopApplication");
9.15 + }
9.16 }
9.17
9.18 void OnOffApplication::CancelEvents ()
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/src/applications/v4ping/v4ping.cc Wed Oct 29 11:49:21 2008 -0700
10.3 @@ -0,0 +1,155 @@
10.4 +#include "v4ping.h"
10.5 +#include "ns3/icmpv4.h"
10.6 +#include "ns3/assert.h"
10.7 +#include "ns3/log.h"
10.8 +#include "ns3/ipv4-address.h"
10.9 +#include "ns3/socket.h"
10.10 +#include "ns3/uinteger.h"
10.11 +#include "ns3/inet-socket-address.h"
10.12 +#include "ns3/packet.h"
10.13 +#include "ns3/trace-source-accessor.h"
10.14 +#include "ns3/simulator.h"
10.15 +
10.16 +namespace ns3 {
10.17 +
10.18 +NS_LOG_COMPONENT_DEFINE ("V4Ping");
10.19 +NS_OBJECT_ENSURE_REGISTERED (V4Ping);
10.20 +
10.21 +TypeId
10.22 +V4Ping::GetTypeId (void)
10.23 +{
10.24 + static TypeId tid = TypeId ("ns3::V4Ping")
10.25 + .SetParent<Application> ()
10.26 + .AddConstructor<V4Ping> ()
10.27 + .AddAttribute ("Remote",
10.28 + "The address of the machine we want to ping.",
10.29 + Ipv4AddressValue (),
10.30 + MakeIpv4AddressAccessor (&V4Ping::m_remote),
10.31 + MakeIpv4AddressChecker ())
10.32 + .AddTraceSource ("Rtt",
10.33 + "The rtt calculated by the ping.",
10.34 + MakeTraceSourceAccessor (&V4Ping::m_traceRtt));
10.35 + ;
10.36 + return tid;
10.37 +}
10.38 +
10.39 +V4Ping::V4Ping ()
10.40 + : m_socket (0),
10.41 + m_seq (0)
10.42 +{}
10.43 +V4Ping::~V4Ping ()
10.44 +{}
10.45 +
10.46 +void
10.47 +V4Ping::DoDispose (void)
10.48 +{
10.49 + NS_LOG_FUNCTION (this);
10.50 + m_socket = 0;
10.51 + Application::DoDispose ();
10.52 +}
10.53 +
10.54 +uint32_t
10.55 +V4Ping::GetApplicationId (void) const
10.56 +{
10.57 + Ptr<Node> node = GetNode ();
10.58 + for (uint32_t i = 0; i < node->GetNApplications (); ++i)
10.59 + {
10.60 + if (node->GetApplication (i) == this)
10.61 + {
10.62 + return i;
10.63 + }
10.64 + }
10.65 + NS_ASSERT_MSG (false, "forgot to add application to node");
10.66 + return 0; // quiet compiler
10.67 +}
10.68 +
10.69 +void
10.70 +V4Ping::Receive (Ptr<Socket> socket)
10.71 +{
10.72 + NS_LOG_FUNCTION (this << socket);
10.73 + while (m_socket->GetRxAvailable () > 0)
10.74 + {
10.75 + Address from;
10.76 + Ptr<Packet> p = m_socket->RecvFrom (0xffffffff, 0, from);
10.77 + NS_LOG_DEBUG ("recv " << p->GetSize () << " bytes");
10.78 + NS_ASSERT (InetSocketAddress::IsMatchingType (from));
10.79 + InetSocketAddress realFrom = InetSocketAddress::ConvertFrom (from);
10.80 + NS_ASSERT (realFrom.GetPort () == 1); // protocol should be icmp.
10.81 + Ipv4Header ipv4;
10.82 + p->RemoveHeader (ipv4);
10.83 + NS_ASSERT (ipv4.GetProtocol () == 1); // protocol should be icmp.
10.84 + Icmpv4Header icmp;
10.85 + p->RemoveHeader (icmp);
10.86 + if (icmp.GetType () == Icmpv4Header::ECHO_REPLY)
10.87 + {
10.88 + Icmpv4Echo echo;
10.89 + p->RemoveHeader (echo);
10.90 + if (echo.GetSequenceNumber () == (m_seq - 1) &&
10.91 + echo.GetIdentifier () == 0)
10.92 + {
10.93 + Ptr<const Packet> data = echo.GetData ();
10.94 + if (data->GetSize () == 16)
10.95 + {
10.96 + uint32_t *buf = (uint32_t *)data->PeekData ();
10.97 + if (buf[0] == GetNode ()->GetId () &&
10.98 + buf[1] == GetApplicationId ())
10.99 + {
10.100 + int64_t ts = buf[3];
10.101 + ts <<= 32;
10.102 + ts |= buf[2];
10.103 + Time sendTime = TimeStep (ts);
10.104 + NS_ASSERT (Simulator::Now () > sendTime);
10.105 + Time delta = Simulator::Now () - sendTime;
10.106 + m_traceRtt (delta);
10.107 + }
10.108 + }
10.109 + }
10.110 + }
10.111 + }
10.112 +}
10.113 +
10.114 +void
10.115 +V4Ping::StartApplication (void)
10.116 +{
10.117 + NS_LOG_FUNCTION (this);
10.118 + m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory"));
10.119 + NS_ASSERT (m_socket != 0);
10.120 + m_socket->SetAttribute ("Protocol", UintegerValue (1)); // icmp
10.121 + m_socket->SetRecvCallback (MakeCallback (&V4Ping::Receive, this));
10.122 + InetSocketAddress src = InetSocketAddress (Ipv4Address::GetAny (), 0);
10.123 + int status;
10.124 + status = m_socket->Bind (src);
10.125 + NS_ASSERT (status != -1);
10.126 + InetSocketAddress dst = InetSocketAddress (m_remote, 0);
10.127 + status = m_socket->Connect (dst);
10.128 + NS_ASSERT (status != -1);
10.129 + Ptr<Packet> p = Create<Packet> ();
10.130 + Icmpv4Echo echo;
10.131 + echo.SetSequenceNumber (m_seq);
10.132 + m_seq++;
10.133 + echo.SetIdentifier (0);
10.134 + uint32_t data[4];
10.135 + data[0] = GetNode ()->GetId ();
10.136 + data[1] = GetApplicationId ();
10.137 + int64_t now = Simulator::Now ().GetTimeStep ();
10.138 + data[2] = now & 0xffffffff;
10.139 + now >>= 32;
10.140 + data[3] = now & 0xffffffff;
10.141 + Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, 16);
10.142 + echo.SetData (dataPacket);
10.143 + p->AddHeader (echo);
10.144 + Icmpv4Header header;
10.145 + header.SetType (Icmpv4Header::ECHO);
10.146 + header.SetCode (0);
10.147 + p->AddHeader (header);
10.148 + m_socket->Send (p, 0);
10.149 +
10.150 +}
10.151 +void
10.152 +V4Ping::StopApplication (void)
10.153 +{
10.154 + NS_LOG_FUNCTION (this);
10.155 +}
10.156 +
10.157 +
10.158 +} // namespace ns3
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/src/applications/v4ping/v4ping.h Wed Oct 29 11:49:21 2008 -0700
11.3 @@ -0,0 +1,36 @@
11.4 +#ifndef V4PING_H
11.5 +#define V4PING_H
11.6 +
11.7 +#include "ns3/application.h"
11.8 +#include "ns3/traced-callback.h"
11.9 +#include "ns3/nstime.h"
11.10 +
11.11 +namespace ns3 {
11.12 +
11.13 +class Socket;
11.14 +
11.15 +class V4Ping : public Application
11.16 +{
11.17 +public:
11.18 + static TypeId GetTypeId (void);
11.19 +
11.20 + V4Ping ();
11.21 + virtual ~V4Ping ();
11.22 +
11.23 +private:
11.24 + // inherited from Application base class.
11.25 + virtual void StartApplication (void);
11.26 + virtual void StopApplication (void);
11.27 + virtual void DoDispose (void);
11.28 + uint32_t GetApplicationId (void) const;
11.29 + void Receive (Ptr<Socket> socket);
11.30 +
11.31 + Ipv4Address m_remote;
11.32 + Ptr<Socket> m_socket;
11.33 + uint16_t m_seq;
11.34 + TracedCallback<Time> m_traceRtt;
11.35 +};
11.36 +
11.37 +} // namespace ns3
11.38 +
11.39 +#endif /* V4PING_H */
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/src/applications/v4ping/wscript Wed Oct 29 11:49:21 2008 -0700
12.3 @@ -0,0 +1,13 @@
12.4 +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
12.5 +
12.6 +def build(bld):
12.7 + module = bld.create_ns3_module('v4ping', ['node'])
12.8 + module.source = [
12.9 + 'v4ping.cc',
12.10 + ]
12.11 + headers = bld.create_obj('ns3header')
12.12 + headers.module = 'v4ping'
12.13 + headers.source = [
12.14 + 'v4ping.h',
12.15 + ]
12.16 +
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/src/helper/v4ping-helper.cc Wed Oct 29 11:49:21 2008 -0700
13.3 @@ -0,0 +1,33 @@
13.4 +#include "v4ping-helper.h"
13.5 +#include "ns3/v4ping.h"
13.6 +
13.7 +namespace ns3 {
13.8 +
13.9 +V4PingHelper::V4PingHelper (Ipv4Address remote)
13.10 +{
13.11 + m_factory.SetTypeId ("ns3::V4Ping");
13.12 + m_factory.Set ("Remote", Ipv4AddressValue (remote));
13.13 +}
13.14 +
13.15 +void
13.16 +V4PingHelper::SetAttribute (std::string name, const AttributeValue &value)
13.17 +{
13.18 + m_factory.Set (name, value);
13.19 +}
13.20 +
13.21 +ApplicationContainer
13.22 +V4PingHelper::Install (NodeContainer nodes)
13.23 +{
13.24 + ApplicationContainer apps;
13.25 + for (NodeContainer::Iterator i = nodes.Begin (); i != nodes.End (); ++i)
13.26 + {
13.27 + Ptr<Node> node = *i;
13.28 + Ptr<V4Ping> ping = m_factory.Create<V4Ping> ();
13.29 + node->AddApplication (ping);
13.30 + apps.Add (ping);
13.31 + }
13.32 + return apps;
13.33 +}
13.34 +
13.35 +
13.36 +} // namespace ns3
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/src/helper/v4ping-helper.h Wed Oct 29 11:49:21 2008 -0700
14.3 @@ -0,0 +1,25 @@
14.4 +#ifndef V4PING_HELPER_H
14.5 +#define V4PING_HELPER_H
14.6 +
14.7 +#include "node-container.h"
14.8 +#include "application-container.h"
14.9 +#include "ns3/object-factory.h"
14.10 +
14.11 +namespace ns3 {
14.12 +
14.13 +class V4PingHelper
14.14 +{
14.15 +public:
14.16 + V4PingHelper (Ipv4Address remote);
14.17 +
14.18 + void SetAttribute (std::string name, const AttributeValue &value);
14.19 +
14.20 + ApplicationContainer Install (NodeContainer nodes);
14.21 +
14.22 +private:
14.23 + ObjectFactory m_factory;
14.24 +};
14.25 +
14.26 +} // namespace ns3
14.27 +
14.28 +#endif /* V4PING_HELPER_H */
15.1 --- a/src/helper/wscript Mon Oct 27 23:05:57 2008 -0700
15.2 +++ b/src/helper/wscript Wed Oct 29 11:49:21 2008 -0700
15.3 @@ -23,6 +23,7 @@
15.4 'ipv4-interface-container.cc',
15.5 'udp-echo-helper.cc',
15.6 'bridge-helper.cc',
15.7 + 'v4ping-helper.cc',
15.8 ]
15.9
15.10 headers = bld.create_obj('ns3header')
15.11 @@ -48,4 +49,5 @@
15.12 'ipv4-interface-container.h',
15.13 'udp-echo-helper.h',
15.14 'bridge-helper.h',
15.15 + 'v4ping-helper.h',
15.16 ]
16.1 --- a/src/internet-stack/arp-ipv4-interface.cc Mon Oct 27 23:05:57 2008 -0700
16.2 +++ b/src/internet-stack/arp-ipv4-interface.cc Wed Oct 29 11:49:21 2008 -0700
16.3 @@ -65,7 +65,6 @@
16.4 ArpIpv4Interface::DoDispose (void)
16.5 {
16.6 NS_LOG_FUNCTION (this);
16.7 - m_node = 0;
16.8 m_device = 0;
16.9 m_cache = 0;
16.10 Ipv4Interface::DoDispose ();
16.11 @@ -107,6 +106,17 @@
16.12 NS_LOG_FUNCTION (this << p << dest);
16.13
16.14 NS_ASSERT (GetDevice () != 0);
16.15 + if (dest == GetAddress ())
16.16 + {
16.17 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
16.18 +
16.19 + ipv4->Receive (0, p, Ipv4L3Protocol::PROT_NUMBER,
16.20 + GetDevice ()->GetBroadcast (),
16.21 + GetDevice ()->GetBroadcast (),
16.22 + NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here
16.23 + );
16.24 + return;
16.25 + }
16.26 if (m_device->NeedsArp ())
16.27 {
16.28 NS_LOG_LOGIC ("Needs ARP");
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/src/internet-stack/icmpv4-l4-protocol.cc Wed Oct 29 11:49:21 2008 -0700
17.3 @@ -0,0 +1,223 @@
17.4 +#include "icmpv4-l4-protocol.h"
17.5 +#include "ipv4-interface.h"
17.6 +#include "ipv4-l3-protocol.h"
17.7 +#include "ns3/assert.h"
17.8 +#include "ns3/log.h"
17.9 +#include "ns3/node.h"
17.10 +#include "ns3/packet.h"
17.11 +#include "ns3/boolean.h"
17.12 +
17.13 +namespace ns3 {
17.14 +
17.15 +NS_LOG_COMPONENT_DEFINE ("Icmpv4L4Protocol");
17.16 +
17.17 +NS_OBJECT_ENSURE_REGISTERED (Icmpv4L4Protocol);
17.18 +
17.19 + // see rfc 792
17.20 +enum {
17.21 + ICMP_PROTOCOL = 1
17.22 +};
17.23 +
17.24 +TypeId
17.25 +Icmpv4L4Protocol::GetTypeId (void)
17.26 +{
17.27 + static TypeId tid = TypeId ("ns3::Icmpv4L4Protocol")
17.28 + .SetParent<Ipv4L4Protocol> ()
17.29 + .AddConstructor<Icmpv4L4Protocol> ()
17.30 + .AddAttribute ("CalcChecksum",
17.31 + "Control whether the icmp header checksum is calculated and stored in outgoing icmpv4 headers",
17.32 + BooleanValue (false),
17.33 + MakeBooleanAccessor (&Icmpv4L4Protocol::m_calcChecksum),
17.34 + MakeBooleanChecker ())
17.35 + ;
17.36 + return tid;
17.37 +}
17.38 +
17.39 +Icmpv4L4Protocol::Icmpv4L4Protocol ()
17.40 + : m_node (0)
17.41 +{}
17.42 +Icmpv4L4Protocol::~Icmpv4L4Protocol ()
17.43 +{
17.44 + NS_ASSERT (m_node == 0);
17.45 +}
17.46 +
17.47 +void
17.48 +Icmpv4L4Protocol::SetNode (Ptr<Node> node)
17.49 +{
17.50 + m_node = node;
17.51 +}
17.52 +
17.53 +uint16_t
17.54 +Icmpv4L4Protocol::GetStaticProtocolNumber (void)
17.55 +{
17.56 + return ICMP_PROTOCOL;
17.57 +}
17.58 +
17.59 +int
17.60 +Icmpv4L4Protocol::GetProtocolNumber (void) const
17.61 +{
17.62 + return ICMP_PROTOCOL;
17.63 +}
17.64 +void
17.65 +Icmpv4L4Protocol::SendMessage (Ptr<Packet> packet, Ipv4Address dest, uint8_t type, uint8_t code)
17.66 +{
17.67 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
17.68 + uint32_t i;
17.69 + if (!ipv4->GetIfIndexForDestination (dest, i))
17.70 + {
17.71 + NS_LOG_WARN ("drop icmp message");
17.72 + return;
17.73 + }
17.74 + Ipv4Address source = ipv4->GetAddress (i);
17.75 + SendMessage (packet, source, dest, type, code);
17.76 +}
17.77 +
17.78 +void
17.79 +Icmpv4L4Protocol::SendMessage (Ptr<Packet> packet, Ipv4Address source, Ipv4Address dest, uint8_t type, uint8_t code)
17.80 +{
17.81 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
17.82 + Icmpv4Header icmp;
17.83 + icmp.SetType (type);
17.84 + icmp.SetCode (code);
17.85 + if (m_calcChecksum)
17.86 + {
17.87 + icmp.EnableChecksum ();
17.88 + }
17.89 + packet->AddHeader (icmp);
17.90 + ipv4->Send (packet, source, dest, ICMP_PROTOCOL);
17.91 +}
17.92 +void
17.93 +Icmpv4L4Protocol::SendDestUnreachFragNeeded (Ipv4Header header,
17.94 + Ptr<const Packet> orgData,
17.95 + uint16_t nextHopMtu)
17.96 +{
17.97 + NS_LOG_FUNCTION (this << header << *orgData << nextHopMtu);
17.98 + SendDestUnreach (header, orgData, Icmpv4DestinationUnreachable::FRAG_NEEDED, nextHopMtu);
17.99 +}
17.100 +void
17.101 +Icmpv4L4Protocol::SendDestUnreachPort (Ipv4Header header,
17.102 + Ptr<const Packet> orgData)
17.103 +{
17.104 + NS_LOG_FUNCTION (this << header << *orgData);
17.105 + SendDestUnreach (header, orgData, Icmpv4DestinationUnreachable::PORT_UNREACHABLE, 0);
17.106 +}
17.107 +void
17.108 +Icmpv4L4Protocol::SendDestUnreach (Ipv4Header header, Ptr<const Packet> orgData,
17.109 + uint8_t code, uint16_t nextHopMtu)
17.110 +{
17.111 + NS_LOG_FUNCTION (this << header << *orgData << (uint32_t) code << nextHopMtu);
17.112 + Ptr<Packet> p = Create<Packet> ();
17.113 + Icmpv4DestinationUnreachable unreach;
17.114 + unreach.SetNextHopMtu (nextHopMtu);
17.115 + unreach.SetHeader (header);
17.116 + unreach.SetData (orgData);
17.117 + p->AddHeader (unreach);
17.118 + SendMessage (p, header.GetSource (), Icmpv4Header::DEST_UNREACH, code);
17.119 +}
17.120 +
17.121 +void
17.122 +Icmpv4L4Protocol::SendTimeExceededTtl (Ipv4Header header, Ptr<const Packet> orgData)
17.123 +{
17.124 + NS_LOG_FUNCTION (this << header << *orgData);
17.125 + Ptr<Packet> p = Create<Packet> ();
17.126 + Icmpv4TimeExceeded time;
17.127 + time.SetHeader (header);
17.128 + time.SetData (orgData);
17.129 + p->AddHeader (time);
17.130 + SendMessage (p, header.GetSource (), Icmpv4Header::TIME_EXCEEDED, Icmpv4TimeExceeded::TIME_TO_LIVE);
17.131 +}
17.132 +
17.133 +void
17.134 +Icmpv4L4Protocol::HandleEcho (Ptr<Packet> p,
17.135 + Icmpv4Header header,
17.136 + Ipv4Address source,
17.137 + Ipv4Address destination)
17.138 +{
17.139 + NS_LOG_FUNCTION (this << p << header << source << destination);
17.140 +
17.141 + Ptr<Packet> reply = Create<Packet> ();
17.142 + Icmpv4Echo echo;
17.143 + p->RemoveHeader (echo);
17.144 + reply->AddHeader (echo);
17.145 + SendMessage (reply, destination, source, Icmpv4Header::ECHO_REPLY, 0);
17.146 +}
17.147 +void
17.148 +Icmpv4L4Protocol::Forward (Ipv4Address source, Icmpv4Header icmp,
17.149 + uint32_t info, Ipv4Header ipHeader,
17.150 + const uint8_t payload[8])
17.151 +{
17.152 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
17.153 + Ptr<Ipv4L4Protocol> l4 = ipv4->GetProtocol (ipHeader.GetProtocol ());
17.154 + if (l4 != 0)
17.155 + {
17.156 + l4->ReceiveIcmp (source, ipHeader.GetTtl (), icmp.GetType (), icmp.GetCode (),
17.157 + info, ipHeader.GetSource (), ipHeader.GetDestination (), payload);
17.158 + }
17.159 +}
17.160 +void
17.161 +Icmpv4L4Protocol::HandleDestUnreach (Ptr<Packet> p,
17.162 + Icmpv4Header icmp,
17.163 + Ipv4Address source,
17.164 + Ipv4Address destination)
17.165 +{
17.166 + NS_LOG_FUNCTION (this << p << icmp << source << destination);
17.167 +
17.168 + Icmpv4DestinationUnreachable unreach;
17.169 + p->PeekHeader (unreach);
17.170 + uint8_t payload[8];
17.171 + unreach.GetData (payload);
17.172 + Ipv4Header ipHeader = unreach.GetHeader ();
17.173 + Forward (source, icmp, unreach.GetNextHopMtu (), ipHeader, payload);
17.174 +}
17.175 +void
17.176 +Icmpv4L4Protocol::HandleTimeExceeded (Ptr<Packet> p,
17.177 + Icmpv4Header icmp,
17.178 + Ipv4Address source,
17.179 + Ipv4Address destination)
17.180 +{
17.181 + NS_LOG_FUNCTION (this << p << icmp << source << destination);
17.182 +
17.183 + Icmpv4TimeExceeded time;
17.184 + p->PeekHeader (time);
17.185 + uint8_t payload[8];
17.186 + time.GetData (payload);
17.187 + Ipv4Header ipHeader = time.GetHeader ();
17.188 + // info field is zero for TimeExceeded on linux
17.189 + Forward (source, icmp, 0, ipHeader, payload);
17.190 +}
17.191 +
17.192 +enum Ipv4L4Protocol::RxStatus
17.193 +Icmpv4L4Protocol::Receive(Ptr<Packet> p,
17.194 + Ipv4Address const &source,
17.195 + Ipv4Address const &destination,
17.196 + Ptr<Ipv4Interface> incomingInterface)
17.197 +{
17.198 + NS_LOG_FUNCTION (this << p << source << destination << incomingInterface);
17.199 +
17.200 + Icmpv4Header icmp;
17.201 + p->RemoveHeader (icmp);
17.202 + switch (icmp.GetType ()) {
17.203 + case Icmpv4Header::ECHO:
17.204 + HandleEcho (p, icmp, source, destination);
17.205 + break;
17.206 + case Icmpv4Header::DEST_UNREACH:
17.207 + HandleDestUnreach (p, icmp, source, destination);
17.208 + break;
17.209 + case Icmpv4Header::TIME_EXCEEDED:
17.210 + HandleTimeExceeded (p, icmp, source, destination);
17.211 + break;
17.212 + default:
17.213 + NS_LOG_DEBUG (icmp << " " << *p);
17.214 + break;
17.215 + }
17.216 + return Ipv4L4Protocol::RX_OK;
17.217 +}
17.218 +void
17.219 +Icmpv4L4Protocol::DoDispose (void)
17.220 +{
17.221 + NS_LOG_FUNCTION (this);
17.222 + m_node = 0;
17.223 + Ipv4L4Protocol::DoDispose ();
17.224 +}
17.225 +
17.226 +} // namespace ns3
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/src/internet-stack/icmpv4-l4-protocol.h Wed Oct 29 11:49:21 2008 -0700
18.3 @@ -0,0 +1,62 @@
18.4 +#ifndef ICMPV4_L4_PROTOCOL_H
18.5 +#define ICMPV4_L4_PROTOCOL_H
18.6 +
18.7 +#include "ipv4-l4-protocol.h"
18.8 +#include "icmpv4.h"
18.9 +#include "ns3/ipv4-address.h"
18.10 +
18.11 +namespace ns3 {
18.12 +
18.13 +class Node;
18.14 +class Ipv4Interface;
18.15 +
18.16 +class Icmpv4L4Protocol : public Ipv4L4Protocol
18.17 +{
18.18 +public:
18.19 + static TypeId GetTypeId (void);
18.20 + Icmpv4L4Protocol ();
18.21 + virtual ~Icmpv4L4Protocol ();
18.22 +
18.23 + void SetNode (Ptr<Node> node);
18.24 +
18.25 + static uint16_t GetStaticProtocolNumber (void);
18.26 + virtual int GetProtocolNumber (void) const;
18.27 + virtual enum Ipv4L4Protocol::RxStatus Receive(Ptr<Packet> p,
18.28 + const Ipv4Address &source,
18.29 + const Ipv4Address &destination,
18.30 + Ptr<Ipv4Interface> incomingInterface);
18.31 +
18.32 + void SendDestUnreachFragNeeded (Ipv4Header header, Ptr<const Packet> orgData, uint16_t nextHopMtu);
18.33 + void SendTimeExceededTtl (Ipv4Header header, Ptr<const Packet> orgData);
18.34 + void SendDestUnreachPort (Ipv4Header header, Ptr<const Packet> orgData);
18.35 +
18.36 +private:
18.37 + void HandleEcho (Ptr<Packet> p,
18.38 + Icmpv4Header header,
18.39 + Ipv4Address source,
18.40 + Ipv4Address destination);
18.41 + void HandleDestUnreach (Ptr<Packet> p,
18.42 + Icmpv4Header header,
18.43 + Ipv4Address source,
18.44 + Ipv4Address destination);
18.45 + void HandleTimeExceeded (Ptr<Packet> p,
18.46 + Icmpv4Header icmp,
18.47 + Ipv4Address source,
18.48 + Ipv4Address destination);
18.49 + void SendDestUnreach (Ipv4Header header, Ptr<const Packet> orgData,
18.50 + uint8_t code, uint16_t nextHopMtu);
18.51 + void SendMessage (Ptr<Packet> packet, Ipv4Address dest, uint8_t type, uint8_t code);
18.52 + void SendMessage (Ptr<Packet> packet, Ipv4Address source, Ipv4Address dest, uint8_t type, uint8_t code);
18.53 + void Forward (Ipv4Address source, Icmpv4Header icmp,
18.54 + uint32_t info, Ipv4Header ipHeader,
18.55 + const uint8_t payload[8]);
18.56 +
18.57 + virtual void DoDispose (void);
18.58 +
18.59 + Ptr<Node> m_node;
18.60 + bool m_calcChecksum;
18.61 +};
18.62 +
18.63 +} // namespace ns3
18.64 +
18.65 +#endif /* ICMPV4_L4_PROTOCOL_H */
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/src/internet-stack/icmpv4.cc Wed Oct 29 11:49:21 2008 -0700
19.3 @@ -0,0 +1,387 @@
19.4 +#include "icmpv4.h"
19.5 +#include "ns3/packet.h"
19.6 +
19.7 +namespace ns3 {
19.8 +
19.9 +/********************************************************
19.10 + * Icmpv4Header
19.11 + ********************************************************/
19.12 +
19.13 +TypeId
19.14 +Icmpv4Header::GetTypeId (void)
19.15 +{
19.16 + static TypeId tid = TypeId ("ns3::Icmpv4Header")
19.17 + .SetParent<Header> ()
19.18 + .AddConstructor<Icmpv4Header> ()
19.19 + ;
19.20 + return tid;
19.21 +}
19.22 +Icmpv4Header::Icmpv4Header ()
19.23 + : m_type (0),
19.24 + m_code (0),
19.25 + m_calcChecksum (false)
19.26 +{}
19.27 +Icmpv4Header::~Icmpv4Header ()
19.28 +{}
19.29 +void
19.30 +Icmpv4Header::EnableChecksum (void)
19.31 +{
19.32 + m_calcChecksum = true;
19.33 +}
19.34 +TypeId
19.35 +Icmpv4Header::GetInstanceTypeId (void) const
19.36 +{
19.37 + return GetTypeId ();
19.38 +}
19.39 +uint32_t
19.40 +Icmpv4Header::GetSerializedSize (void) const
19.41 +{
19.42 + return 4;
19.43 +}
19.44 +void
19.45 +Icmpv4Header::Serialize (Buffer::Iterator start) const
19.46 +{
19.47 + Buffer::Iterator i = start;
19.48 + i.WriteU8 (m_type);
19.49 + i.WriteU8 (m_code);
19.50 + i.WriteHtonU16 (0);
19.51 + if (m_calcChecksum)
19.52 + {
19.53 + i = start;
19.54 + uint16_t checksum = i.CalculateIpChecksum (i.GetSize ());
19.55 + i = start;
19.56 + i.Next (2);
19.57 + i.WriteU16 (checksum);
19.58 + }
19.59 +
19.60 +}
19.61 +uint32_t
19.62 +Icmpv4Header::Deserialize (Buffer::Iterator start)
19.63 +{
19.64 + m_type = start.ReadU8 ();
19.65 + m_code = start.ReadU8 ();
19.66 + uint16_t checksum;
19.67 + checksum = start.ReadNtohU16 ();
19.68 + return 4;
19.69 +}
19.70 +void
19.71 +Icmpv4Header::Print (std::ostream &os) const
19.72 +{
19.73 + os << "type=" << (uint32_t)m_type << ", code=" << (uint32_t)m_code;
19.74 +}
19.75 +
19.76 +void
19.77 +Icmpv4Header::SetType (uint8_t type)
19.78 +{
19.79 + m_type = type;
19.80 +}
19.81 +void
19.82 +Icmpv4Header::SetCode (uint8_t code)
19.83 +{
19.84 + m_code = code;
19.85 +}
19.86 +uint8_t
19.87 +Icmpv4Header::GetType (void) const
19.88 +{
19.89 + return m_type;
19.90 +}
19.91 +uint8_t
19.92 +Icmpv4Header::GetCode (void) const
19.93 +{
19.94 + return m_code;
19.95 +}
19.96 +
19.97 +/********************************************************
19.98 + * Icmpv4Echo
19.99 + ********************************************************/
19.100 +
19.101 +void
19.102 +Icmpv4Echo::SetIdentifier (uint16_t id)
19.103 +{
19.104 + m_identifier = id;
19.105 +}
19.106 +void
19.107 +Icmpv4Echo::SetSequenceNumber (uint16_t seq)
19.108 +{
19.109 + m_sequence = seq;
19.110 +}
19.111 +void
19.112 +Icmpv4Echo::SetData (Ptr<const Packet> data)
19.113 +{
19.114 + m_data = data->Copy ();
19.115 +}
19.116 +uint16_t
19.117 +Icmpv4Echo::GetIdentifier (void) const
19.118 +{
19.119 + return m_identifier;
19.120 +}
19.121 +uint16_t
19.122 +Icmpv4Echo::GetSequenceNumber (void) const
19.123 +{
19.124 + return m_sequence;
19.125 +}
19.126 +Ptr<const Packet>
19.127 +Icmpv4Echo::GetData (void) const
19.128 +{
19.129 + return m_data->Copy ();
19.130 +}
19.131 +
19.132 +
19.133 +TypeId
19.134 +Icmpv4Echo::GetTypeId (void)
19.135 +{
19.136 + static TypeId tid = TypeId ("ns3::Icmpv4Echo")
19.137 + .SetParent<Header> ()
19.138 + .AddConstructor<Icmpv4Echo> ()
19.139 + ;
19.140 + return tid;
19.141 +}
19.142 +Icmpv4Echo::Icmpv4Echo ()
19.143 + : m_identifier (0),
19.144 + m_sequence (0),
19.145 + m_data (0)
19.146 +{}
19.147 +Icmpv4Echo::~Icmpv4Echo ()
19.148 +{}
19.149 +TypeId
19.150 +Icmpv4Echo::GetInstanceTypeId (void) const
19.151 +{
19.152 + return GetTypeId ();
19.153 +}
19.154 +uint32_t
19.155 +Icmpv4Echo::GetSerializedSize (void) const
19.156 +{
19.157 + return 4 + m_data->GetSize ();
19.158 +}
19.159 +void
19.160 +Icmpv4Echo::Serialize (Buffer::Iterator start) const
19.161 +{
19.162 + start.WriteHtonU16 (m_identifier);
19.163 + start.WriteHtonU16 (m_sequence);
19.164 + start.Write (m_data->PeekData (), m_data->GetSize ());
19.165 +}
19.166 +uint32_t
19.167 +Icmpv4Echo::Deserialize (Buffer::Iterator start)
19.168 +{
19.169 + m_identifier = start.ReadNtohU16 ();
19.170 + m_sequence = start.ReadNtohU16 ();
19.171 + NS_ASSERT (start.GetSize () >= 4);
19.172 + uint32_t size = start.GetSize () - 4;
19.173 + uint8_t *buffer = new uint8_t[size] ();
19.174 + start.Read (buffer, size);
19.175 + m_data = Create<Packet> (buffer, size);
19.176 + delete[] buffer;
19.177 + return start.GetSize ();
19.178 +}
19.179 +void
19.180 +Icmpv4Echo::Print (std::ostream &os) const
19.181 +{
19.182 + os << "identifier=" << m_identifier << ", sequence=" << m_sequence;
19.183 +}
19.184 +
19.185 +
19.186 +/********************************************************
19.187 + * Icmpv4DestinationUnreachable
19.188 + ********************************************************/
19.189 +
19.190 +TypeId
19.191 +Icmpv4DestinationUnreachable::GetTypeId (void)
19.192 +{
19.193 + static TypeId tid = TypeId ("ns3::Icmpv4DestinationUnreachable")
19.194 + .SetParent<Header> ()
19.195 + .AddConstructor<Icmpv4DestinationUnreachable> ()
19.196 + ;
19.197 + return tid;
19.198 +}
19.199 +Icmpv4DestinationUnreachable::Icmpv4DestinationUnreachable ()
19.200 +{
19.201 + // make sure that thing is initialized to get initialized bytes
19.202 + // when the ip payload's size is smaller than 8 bytes.
19.203 + for (uint8_t j = 0; j < 8; j++)
19.204 + {
19.205 + m_data[j] = 0;
19.206 + }
19.207 +}
19.208 +
19.209 +void
19.210 +Icmpv4DestinationUnreachable::SetNextHopMtu (uint16_t mtu)
19.211 +{
19.212 + m_nextHopMtu = mtu;
19.213 +}
19.214 +uint16_t
19.215 +Icmpv4DestinationUnreachable::GetNextHopMtu (void) const
19.216 +{
19.217 + return m_nextHopMtu;
19.218 +}
19.219 +
19.220 +void
19.221 +Icmpv4DestinationUnreachable::SetData (Ptr<const Packet> data)
19.222 +{
19.223 + data->CopyData (m_data, 8);
19.224 +}
19.225 +void
19.226 +Icmpv4DestinationUnreachable::SetHeader (Ipv4Header header)
19.227 +{
19.228 + m_header = header;
19.229 +}
19.230 +void
19.231 +Icmpv4DestinationUnreachable::GetData (uint8_t payload[8]) const
19.232 +{
19.233 + memcpy (payload, m_data, 8);
19.234 +}
19.235 +Ipv4Header
19.236 +Icmpv4DestinationUnreachable::GetHeader (void) const
19.237 +{
19.238 + return m_header;
19.239 +}
19.240 +
19.241 +
19.242 +Icmpv4DestinationUnreachable::~Icmpv4DestinationUnreachable ()
19.243 +{}
19.244 +TypeId
19.245 +Icmpv4DestinationUnreachable::GetInstanceTypeId (void) const
19.246 +{
19.247 + return GetTypeId ();
19.248 +}
19.249 +uint32_t
19.250 +Icmpv4DestinationUnreachable::GetSerializedSize (void) const
19.251 +{
19.252 + return 4 + m_header.GetSerializedSize () + 8;
19.253 +}
19.254 +void
19.255 +Icmpv4DestinationUnreachable::Serialize (Buffer::Iterator start) const
19.256 +{
19.257 + start.WriteU16 (0);
19.258 + start.WriteHtonU16 (m_nextHopMtu);
19.259 + uint32_t size = m_header.GetSerializedSize ();
19.260 + m_header.Serialize (start);
19.261 + start.Next (size);
19.262 + start.Write (m_data, 8);
19.263 +}
19.264 +
19.265 +uint32_t
19.266 +Icmpv4DestinationUnreachable::Deserialize (Buffer::Iterator start)
19.267 +{
19.268 + Buffer::Iterator i = start;
19.269 + i.Next (2);
19.270 + m_nextHopMtu = i.ReadNtohU16 ();
19.271 + uint32_t read = m_header.Deserialize (i);
19.272 + i.Next (read);
19.273 + for (uint8_t j = 0; j < 8; j++)
19.274 + {
19.275 + m_data[j] = i.ReadU8 ();
19.276 + }
19.277 + return i.GetDistanceFrom (start);
19.278 +}
19.279 +void
19.280 +Icmpv4DestinationUnreachable::Print (std::ostream &os) const
19.281 +{
19.282 + m_header.Print (os);
19.283 + os << " org data=";
19.284 + for (uint8_t i = 0; i < 8; i++)
19.285 + {
19.286 + os << (uint32_t) m_data[i];
19.287 + if (i != 8)
19.288 + {
19.289 + os << " ";
19.290 + }
19.291 + }
19.292 +}
19.293 +
19.294 +/********************************************************
19.295 + * Icmpv4TimeExceeded
19.296 + ********************************************************/
19.297 +
19.298 +TypeId
19.299 +Icmpv4TimeExceeded::GetTypeId (void)
19.300 +{
19.301 + static TypeId tid = TypeId ("ns3::Icmpv4TimeExceeded")
19.302 + .SetParent<Header> ()
19.303 + .AddConstructor<Icmpv4TimeExceeded> ()
19.304 + ;
19.305 + return tid;
19.306 +}
19.307 +Icmpv4TimeExceeded::Icmpv4TimeExceeded ()
19.308 +{
19.309 + // make sure that thing is initialized to get initialized bytes
19.310 + // when the ip payload's size is smaller than 8 bytes.
19.311 + for (uint8_t j = 0; j < 8; j++)
19.312 + {
19.313 + m_data[j] = 0;
19.314 + }
19.315 +}
19.316 +
19.317 +
19.318 +void
19.319 +Icmpv4TimeExceeded::SetData (Ptr<const Packet> data)
19.320 +{
19.321 + data->CopyData (m_data, 8);
19.322 +}
19.323 +void
19.324 +Icmpv4TimeExceeded::SetHeader (Ipv4Header header)
19.325 +{
19.326 + m_header = header;
19.327 +}
19.328 +void
19.329 +Icmpv4TimeExceeded::GetData (uint8_t payload[8]) const
19.330 +{
19.331 + memcpy (payload, m_data, 8);
19.332 +}
19.333 +Ipv4Header
19.334 +Icmpv4TimeExceeded::GetHeader (void) const
19.335 +{
19.336 + return m_header;
19.337 +}
19.338 +
19.339 +
19.340 +Icmpv4TimeExceeded::~Icmpv4TimeExceeded ()
19.341 +{}
19.342 +TypeId
19.343 +Icmpv4TimeExceeded::GetInstanceTypeId (void) const
19.344 +{
19.345 + return GetTypeId ();
19.346 +}
19.347 +uint32_t
19.348 +Icmpv4TimeExceeded::GetSerializedSize (void) const
19.349 +{
19.350 + return 4 + m_header.GetSerializedSize () + 8;
19.351 +}
19.352 +void
19.353 +Icmpv4TimeExceeded::Serialize (Buffer::Iterator start) const
19.354 +{
19.355 + start.WriteU32 (0);
19.356 + uint32_t size = m_header.GetSerializedSize ();
19.357 + m_header.Serialize (start);
19.358 + start.Next (size);
19.359 + start.Write (m_data, 8);
19.360 +}
19.361 +
19.362 +uint32_t
19.363 +Icmpv4TimeExceeded::Deserialize (Buffer::Iterator start)
19.364 +{
19.365 + Buffer::Iterator i = start;
19.366 + i.Next (4);
19.367 + uint32_t read = m_header.Deserialize (i);
19.368 + i.Next (read);
19.369 + for (uint8_t j = 0; j < 8; j++)
19.370 + {
19.371 + m_data[j] = i.ReadU8 ();
19.372 + }
19.373 + return i.GetDistanceFrom (start);
19.374 +}
19.375 +void
19.376 +Icmpv4TimeExceeded::Print (std::ostream &os) const
19.377 +{
19.378 + m_header.Print (os);
19.379 + os << " org data=";
19.380 + for (uint8_t i = 0; i < 8; i++)
19.381 + {
19.382 + os << (uint32_t) m_data[i];
19.383 + if (i != 8)
19.384 + {
19.385 + os << " ";
19.386 + }
19.387 + }
19.388 +}
19.389 +
19.390 +} // namespace ns3
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/src/internet-stack/icmpv4.h Wed Oct 29 11:49:21 2008 -0700
20.3 @@ -0,0 +1,137 @@
20.4 +#ifndef ICMPV4_H
20.5 +#define ICMPV4_H
20.6 +
20.7 +#include "ns3/header.h"
20.8 +#include "ns3/ptr.h"
20.9 +#include "ns3/ipv4-header.h"
20.10 +#include <stdint.h>
20.11 +
20.12 +namespace ns3 {
20.13 +
20.14 +class Packet;
20.15 +
20.16 +class Icmpv4Header : public Header
20.17 +{
20.18 +public:
20.19 + enum {
20.20 + ECHO_REPLY = 0,
20.21 + DEST_UNREACH = 3,
20.22 + ECHO = 8,
20.23 + TIME_EXCEEDED = 11
20.24 + };
20.25 +
20.26 + void EnableChecksum (void);
20.27 + void SetType (uint8_t type);
20.28 + void SetCode (uint8_t code);
20.29 +
20.30 + uint8_t GetType (void) const;
20.31 + uint8_t GetCode (void) const;
20.32 +
20.33 + static TypeId GetTypeId (void);
20.34 + Icmpv4Header ();
20.35 + virtual ~Icmpv4Header ();
20.36 + virtual TypeId GetInstanceTypeId (void) const;
20.37 + virtual uint32_t GetSerializedSize (void) const;
20.38 + virtual void Serialize (Buffer::Iterator start) const;
20.39 + virtual uint32_t Deserialize (Buffer::Iterator start);
20.40 + virtual void Print (std::ostream &os) const;
20.41 +
20.42 +private:
20.43 + uint8_t m_type;
20.44 + uint8_t m_code;
20.45 + bool m_calcChecksum;
20.46 +};
20.47 +
20.48 +class Icmpv4Echo : public Header
20.49 +{
20.50 +public:
20.51 + void SetIdentifier (uint16_t id);
20.52 + void SetSequenceNumber (uint16_t seq);
20.53 + void SetData (Ptr<const Packet> data);
20.54 + uint16_t GetIdentifier (void) const;
20.55 + uint16_t GetSequenceNumber (void) const;
20.56 + Ptr<const Packet> GetData (void) const;
20.57 +
20.58 +
20.59 + static TypeId GetTypeId (void);
20.60 + Icmpv4Echo ();
20.61 + virtual ~Icmpv4Echo ();
20.62 + virtual TypeId GetInstanceTypeId (void) const;
20.63 + virtual uint32_t GetSerializedSize (void) const;
20.64 + virtual void Serialize (Buffer::Iterator start) const;
20.65 + virtual uint32_t Deserialize (Buffer::Iterator start);
20.66 + virtual void Print (std::ostream &os) const;
20.67 +private:
20.68 + uint16_t m_identifier;
20.69 + uint16_t m_sequence;
20.70 + Ptr<Packet> m_data;
20.71 +};
20.72 +
20.73 +class Icmpv4DestinationUnreachable : public Header
20.74 +{
20.75 +public:
20.76 + enum {
20.77 + NET_UNREACHABLE = 0,
20.78 + HOST_UNREACHABLE = 1,
20.79 + PROTOCOL_UNREACHABLE = 2,
20.80 + PORT_UNREACHABLE = 3,
20.81 + FRAG_NEEDED = 4,
20.82 + SOURCE_ROUTE_FAILED = 5
20.83 + };
20.84 + static TypeId GetTypeId (void);
20.85 + Icmpv4DestinationUnreachable ();
20.86 + virtual ~Icmpv4DestinationUnreachable ();
20.87 +
20.88 + void SetNextHopMtu (uint16_t mtu);
20.89 + uint16_t GetNextHopMtu (void) const;
20.90 +
20.91 + void SetData (Ptr<const Packet> data);
20.92 + void SetHeader (Ipv4Header header);
20.93 +
20.94 + void GetData (uint8_t payload[8]) const;
20.95 + Ipv4Header GetHeader (void) const;
20.96 +
20.97 +private:
20.98 + virtual TypeId GetInstanceTypeId (void) const;
20.99 + virtual uint32_t GetSerializedSize (void) const;
20.100 + virtual void Serialize (Buffer::Iterator start) const;
20.101 + virtual uint32_t Deserialize (Buffer::Iterator start);
20.102 + virtual void Print (std::ostream &os) const;
20.103 +private:
20.104 + uint16_t m_nextHopMtu;
20.105 + Ipv4Header m_header;
20.106 + uint8_t m_data[8];
20.107 +};
20.108 +
20.109 +
20.110 +class Icmpv4TimeExceeded : public Header
20.111 +{
20.112 +public:
20.113 + enum {
20.114 + TIME_TO_LIVE = 0,
20.115 + FRAGMENT_REASSEMBLY = 1
20.116 + };
20.117 +
20.118 + void SetData (Ptr<const Packet> data);
20.119 + void SetHeader (Ipv4Header header);
20.120 +
20.121 + void GetData (uint8_t payload[8]) const;
20.122 + Ipv4Header GetHeader (void) const;
20.123 +
20.124 + static TypeId GetTypeId (void);
20.125 + Icmpv4TimeExceeded ();
20.126 + virtual ~Icmpv4TimeExceeded ();
20.127 + virtual TypeId GetInstanceTypeId (void) const;
20.128 + virtual uint32_t GetSerializedSize (void) const;
20.129 + virtual void Serialize (Buffer::Iterator start) const;
20.130 + virtual uint32_t Deserialize (Buffer::Iterator start);
20.131 + virtual void Print (std::ostream &os) const;
20.132 +
20.133 +private:
20.134 + Ipv4Header m_header;
20.135 + uint8_t m_data[8];
20.136 +};
20.137 +
20.138 +} // namespace ns3
20.139 +
20.140 +#endif /* ICMPV4_H */
21.1 --- a/src/internet-stack/internet-stack.cc Mon Oct 27 23:05:57 2008 -0700
21.2 +++ b/src/internet-stack/internet-stack.cc Wed Oct 29 11:49:21 2008 -0700
21.3 @@ -30,6 +30,8 @@
21.4 #include "udp-socket-factory-impl.h"
21.5 #include "tcp-socket-factory-impl.h"
21.6 #include "ipv4-impl.h"
21.7 +#include "ipv4-raw-socket-factory-impl.h"
21.8 +#include "icmpv4-l4-protocol.h"
21.9 #ifdef NETWORK_SIMULATION_CRADLE
21.10 #include "nsc-tcp-socket-factory-impl.h"
21.11 #include "nsc-tcp-l4-protocol.h"
21.12 @@ -58,12 +60,25 @@
21.13 }
21.14
21.15 static void
21.16 +AddIcmpStack (Ptr<Node> node)
21.17 +{
21.18 + Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
21.19 + Ptr<Icmpv4L4Protocol> icmp = CreateObject<Icmpv4L4Protocol> ();
21.20 + icmp->SetNode (node);
21.21 + ipv4->Insert (icmp);
21.22 + Ptr<Ipv4RawSocketFactoryImpl> rawFactory = CreateObject<Ipv4RawSocketFactoryImpl> ();
21.23 + node->AggregateObject (rawFactory);
21.24 +}
21.25 +
21.26 +static void
21.27 AddTcpStack(Ptr<Node> node)
21.28 {
21.29 Ptr<Ipv4L3Protocol> ipv4 = node->GetObject<Ipv4L3Protocol> ();
21.30 Ptr<TcpL4Protocol> tcp = CreateObject<TcpL4Protocol> ();
21.31 tcp->SetNode (node);
21.32 +
21.33 ipv4->Insert (tcp);
21.34 +
21.35 Ptr<TcpSocketFactoryImpl> tcpFactory = CreateObject<TcpSocketFactoryImpl> ();
21.36 tcpFactory->SetTcp (tcp);
21.37 node->AggregateObject (tcpFactory);
21.38 @@ -85,6 +100,7 @@
21.39 {
21.40 AddArpStack (node);
21.41 AddIpv4Stack (node);
21.42 + AddIcmpStack (node);
21.43 AddUdpStack (node);
21.44 AddTcpStack (node);
21.45 }
21.46 @@ -109,7 +125,7 @@
21.47 {
21.48 AddArpStack (node);
21.49 AddIpv4Stack (node);
21.50 -
21.51 + AddIcmpStack (node);
21.52 AddUdpStack (node);
21.53 AddNscStack (node, soname);
21.54 }
22.1 --- a/src/internet-stack/ipv4-end-point-demux.cc Mon Oct 27 23:05:57 2008 -0700
22.2 +++ b/src/internet-stack/ipv4-end-point-demux.cc Wed Oct 29 11:49:21 2008 -0700
22.3 @@ -287,6 +287,47 @@
22.4 return retval1; // might be empty if no matches
22.5 }
22.6
22.7 +Ipv4EndPoint *
22.8 +Ipv4EndPointDemux::SimpleLookup (Ipv4Address daddr,
22.9 + uint16_t dport,
22.10 + Ipv4Address saddr,
22.11 + uint16_t sport)
22.12 +{
22.13 + // this code is a copy/paste version of an old BSD ip stack lookup
22.14 + // function.
22.15 + uint32_t genericity = 3;
22.16 + Ipv4EndPoint *generic = 0;
22.17 + for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
22.18 + {
22.19 + if ((*i)->GetLocalPort () != dport)
22.20 + {
22.21 + continue;
22.22 + }
22.23 + if ((*i)->GetLocalAddress () == daddr &&
22.24 + (*i)->GetPeerPort () == sport &&
22.25 + (*i)->GetPeerAddress () == saddr)
22.26 + {
22.27 + /* this is an exact match. */
22.28 + return *i;
22.29 + }
22.30 + uint32_t tmp = 0;
22.31 + if ((*i)->GetLocalAddress () == Ipv4Address::GetAny ())
22.32 + {
22.33 + tmp ++;
22.34 + }
22.35 + if ((*i)->GetPeerAddress () == Ipv4Address::GetAny ())
22.36 + {
22.37 + tmp ++;
22.38 + }
22.39 + if (tmp < genericity)
22.40 + {
22.41 + generic = (*i);
22.42 + genericity = tmp;
22.43 + }
22.44 + }
22.45 + return generic;
22.46 +}
22.47 +
22.48 uint16_t
22.49 Ipv4EndPointDemux::AllocateEphemeralPort (void)
22.50 {
23.1 --- a/src/internet-stack/ipv4-end-point-demux.h Mon Oct 27 23:05:57 2008 -0700
23.2 +++ b/src/internet-stack/ipv4-end-point-demux.h Wed Oct 29 11:49:21 2008 -0700
23.3 @@ -57,6 +57,11 @@
23.4 uint16_t sport,
23.5 Ptr<Ipv4Interface> incomingInterface);
23.6
23.7 + Ipv4EndPoint *SimpleLookup (Ipv4Address daddr,
23.8 + uint16_t dport,
23.9 + Ipv4Address saddr,
23.10 + uint16_t sport);
23.11 +
23.12 Ipv4EndPoint *Allocate (void);
23.13 Ipv4EndPoint *Allocate (Ipv4Address address);
23.14 Ipv4EndPoint *Allocate (uint16_t port);
24.1 --- a/src/internet-stack/ipv4-end-point.cc Mon Oct 27 23:05:57 2008 -0700
24.2 +++ b/src/internet-stack/ipv4-end-point.cc Wed Oct 29 11:49:21 2008 -0700
24.3 @@ -20,6 +20,9 @@
24.4
24.5 #include "ipv4-end-point.h"
24.6 #include "ns3/packet.h"
24.7 +#include "ns3/log.h"
24.8 +
24.9 +NS_LOG_COMPONENT_DEFINE ("Ipv4EndPoint");
24.10
24.11 namespace ns3 {
24.12
24.13 @@ -76,6 +79,11 @@
24.14 {
24.15 m_rxCallback = callback;
24.16 }
24.17 +void
24.18 +Ipv4EndPoint::SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback)
24.19 +{
24.20 + m_icmpCallback = callback;
24.21 +}
24.22
24.23 void
24.24 Ipv4EndPoint::SetDestroyCallback (Callback<void> callback)
24.25 @@ -92,6 +100,17 @@
24.26 }
24.27 }
24.28
24.29 -
24.30 +void
24.31 +Ipv4EndPoint::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
24.32 + uint8_t icmpType, uint8_t icmpCode,
24.33 + uint32_t icmpInfo)
24.34 +{
24.35 + NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
24.36 + (uint32_t)icmpCode << icmpInfo);
24.37 + if (!m_icmpCallback.IsNull ())
24.38 + {
24.39 + m_icmpCallback (icmpSource,icmpTtl,icmpType,icmpCode,icmpInfo);
24.40 + }
24.41 +}
24.42
24.43 }; // namespace ns3
25.1 --- a/src/internet-stack/ipv4-end-point.h Mon Oct 27 23:05:57 2008 -0700
25.2 +++ b/src/internet-stack/ipv4-end-point.h Wed Oct 29 11:49:21 2008 -0700
25.3 @@ -54,10 +54,19 @@
25.4
25.5 void SetPeer (Ipv4Address address, uint16_t port);
25.6
25.7 + // Called from socket implementations to get notified about important events.
25.8 void SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback);
25.9 + void SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback);
25.10 void SetDestroyCallback (Callback<void> callback);
25.11
25.12 + // Called from an L4Protocol implementation to notify an endpoint of a
25.13 + // packet reception.
25.14 void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport);
25.15 + // Called from an L4Protocol implementation to notify an endpoint of
25.16 + // an icmp message reception.
25.17 + void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
25.18 + uint8_t icmpType, uint8_t icmpCode,
25.19 + uint32_t icmpInfo);
25.20
25.21 private:
25.22 Ipv4Address m_localAddr;
25.23 @@ -65,6 +74,7 @@
25.24 Ipv4Address m_peerAddr;
25.25 uint16_t m_peerPort;
25.26 Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> m_rxCallback;
25.27 + Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
25.28 Callback<void> m_destroyCallback;
25.29 };
25.30
26.1 --- a/src/internet-stack/ipv4-l3-protocol.cc Mon Oct 27 23:05:57 2008 -0700
26.2 +++ b/src/internet-stack/ipv4-l3-protocol.cc Wed Oct 29 11:49:21 2008 -0700
26.3 @@ -35,9 +35,11 @@
26.4
26.5 #include "ipv4-l3-protocol.h"
26.6 #include "ipv4-l4-protocol.h"
26.7 +#include "icmpv4-l4-protocol.h"
26.8 #include "ipv4-interface.h"
26.9 #include "ipv4-loopback-interface.h"
26.10 #include "arp-ipv4-interface.h"
26.11 +#include "ipv4-raw-socket-impl.h"
26.12
26.13 NS_LOG_COMPONENT_DEFINE ("Ipv4L3Protocol");
26.14
26.15 @@ -120,6 +122,30 @@
26.16 SetupLoopback ();
26.17 }
26.18
26.19 +Ptr<Socket>
26.20 +Ipv4L3Protocol::CreateRawSocket (void)
26.21 +{
26.22 + NS_LOG_FUNCTION (this);
26.23 + Ptr<Ipv4RawSocketImpl> socket = CreateObject<Ipv4RawSocketImpl> ();
26.24 + socket->SetNode (m_node);
26.25 + m_sockets.push_back (socket);
26.26 + return socket;
26.27 +}
26.28 +void
26.29 +Ipv4L3Protocol::DeleteRawSocket (Ptr<Socket> socket)
26.30 +{
26.31 + NS_LOG_FUNCTION (this << socket);
26.32 + for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
26.33 + {
26.34 + if ((*i) == socket)
26.35 + {
26.36 + m_sockets.erase (i);
26.37 + return;
26.38 + }
26.39 + }
26.40 + return;
26.41 +}
26.42 +
26.43 void
26.44 Ipv4L3Protocol::DoDispose (void)
26.45 {
26.46 @@ -514,6 +540,12 @@
26.47 return;
26.48 }
26.49
26.50 + for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
26.51 + {
26.52 + Ptr<Ipv4RawSocketImpl> socket = *i;
26.53 + socket->ForwardUp (packet, ipHeader, device);
26.54 + }
26.55 +
26.56 if (Forwarding (index, packet, ipHeader, device))
26.57 {
26.58 return;
26.59 @@ -522,6 +554,25 @@
26.60 ForwardUp (packet, ipHeader, ipv4Interface);
26.61 }
26.62
26.63 +Ptr<Icmpv4L4Protocol>
26.64 +Ipv4L3Protocol::GetIcmp (void) const
26.65 +{
26.66 + Ptr<Ipv4L4Protocol> prot = GetProtocol (Icmpv4L4Protocol::GetStaticProtocolNumber ());
26.67 + if (prot != 0)
26.68 + {
26.69 + return prot->GetObject<Icmpv4L4Protocol> ();
26.70 + }
26.71 + else
26.72 + {
26.73 + return 0;
26.74 + }
26.75 +}
26.76 +
26.77 +bool
26.78 +Ipv4L3Protocol::IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const
26.79 +{
26.80 + return !ad.IsMulticast () && !ad.IsSubnetDirectedBroadcast (interfaceMask);
26.81 +}
26.82
26.83 void
26.84 Ipv4L3Protocol::Send (Ptr<Packet> packet,
26.85 @@ -542,16 +593,29 @@
26.86 ipHeader.SetDestination (destination);
26.87 ipHeader.SetProtocol (protocol);
26.88 ipHeader.SetPayloadSize (packet->GetSize ());
26.89 - ipHeader.SetTtl (m_defaultTtl);
26.90 - ipHeader.SetMayFragment ();
26.91 ipHeader.SetIdentification (m_identification);
26.92
26.93 m_identification ++;
26.94
26.95 + SocketSetDontFragmentTag dfTag;
26.96 + bool found = packet->FindFirstMatchingTag (dfTag);
26.97 + if (found)
26.98 + {
26.99 + if (dfTag.IsEnabled ())
26.100 + {
26.101 + ipHeader.SetDontFragment ();
26.102 + }
26.103 + else
26.104 + {
26.105 + ipHeader.SetMayFragment ();
26.106 + }
26.107 + }
26.108 +
26.109 +
26.110 // Set TTL to 1 if it is a broadcast packet of any type. Otherwise,
26.111 // possibly override the default TTL if the packet is tagged
26.112 SocketIpTtlTag tag;
26.113 - bool found = packet->FindFirstMatchingTag (tag);
26.114 + found = packet->FindFirstMatchingTag (tag);
26.115
26.116 if (destination.IsBroadcast ())
26.117 {
26.118 @@ -564,6 +628,7 @@
26.119 }
26.120 else
26.121 {
26.122 + ipHeader.SetTtl (m_defaultTtl);
26.123 uint32_t ifaceIndex = 0;
26.124 for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
26.125 ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
26.126 @@ -585,10 +650,28 @@
26.127 Ptr<Ipv4Interface> outInterface = *ifaceIter;
26.128 Ptr<Packet> packetCopy = packet->Copy ();
26.129
26.130 - NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
26.131 packetCopy->AddHeader (ipHeader);
26.132 - m_txTrace (packetCopy, ifaceIndex);
26.133 - outInterface->Send (packetCopy, destination);
26.134 + if (packetCopy->GetSize () > outInterface->GetMtu () &&
26.135 + ipHeader.IsDontFragment () &&
26.136 + IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
26.137 + {
26.138 + Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
26.139 + NS_ASSERT (icmp != 0);
26.140 + icmp->SendDestUnreachFragNeeded (ipHeader, packet, outInterface->GetMtu ());
26.141 + m_dropTrace (packetCopy);
26.142 + }
26.143 + else if (packet->GetSize () > outInterface->GetMtu () &&
26.144 + !ipHeader.IsDontFragment ())
26.145 + {
26.146 + NS_LOG_LOGIC ("Too big: need fragmentation but no frag support.");
26.147 + m_dropTrace (packet);
26.148 + }
26.149 + else
26.150 + {
26.151 + NS_ASSERT (packetCopy->GetSize () <= outInterface->GetMtu ());
26.152 + m_txTrace (packetCopy, ifaceIndex);
26.153 + outInterface->Send (packetCopy, destination);
26.154 + }
26.155 }
26.156 }
26.157 else
26.158 @@ -625,17 +708,38 @@
26.159 NS_LOG_LOGIC ("Send via interface " << route.GetInterface ());
26.160
26.161 Ptr<Ipv4Interface> outInterface = GetInterface (route.GetInterface ());
26.162 - NS_ASSERT (packet->GetSize () <= outInterface->GetMtu ());
26.163 - m_txTrace (packet, route.GetInterface ());
26.164 - if (route.IsGateway ())
26.165 + if (packet->GetSize () > outInterface->GetMtu () &&
26.166 + ipHeader.IsDontFragment () &&
26.167 + IsUnicast (ipHeader.GetDestination (), outInterface->GetNetworkMask ()))
26.168 {
26.169 - NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
26.170 - outInterface->Send (packet, route.GetGateway ());
26.171 - }
26.172 - else
26.173 + NS_LOG_LOGIC ("Too big: need fragmentation but not allowed");
26.174 + Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
26.175 + NS_ASSERT (icmp != 0);
26.176 + Ptr<Packet> copyNoHeader = packet->Copy ();
26.177 + Ipv4Header tmp;
26.178 + copyNoHeader->RemoveHeader (tmp);
26.179 + icmp->SendDestUnreachFragNeeded (ipHeader, copyNoHeader, outInterface->GetMtu ());
26.180 + m_dropTrace (packet);
26.181 + }
26.182 + else if (packet->GetSize () > outInterface->GetMtu () &&
26.183 + !ipHeader.IsDontFragment ())
26.184 {
26.185 - NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
26.186 - outInterface->Send (packet, ipHeader.GetDestination ());
26.187 + NS_LOG_LOGIC ("Too big: need fragmentation but no frag support.");
26.188 + m_dropTrace (packet);
26.189 + }
26.190 + else
26.191 + {
26.192 + m_txTrace (packet, route.GetInterface ());
26.193 + if (route.IsGateway ())
26.194 + {
26.195 + NS_LOG_LOGIC ("Send to gateway " << route.GetGateway ());
26.196 + outInterface->Send (packet, route.GetGateway ());
26.197 + }
26.198 + else
26.199 + {
26.200 + NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestination ());
26.201 + outInterface->Send (packet, ipHeader.GetDestination ());
26.202 + }
26.203 }
26.204 }
26.205
26.206 @@ -685,17 +789,6 @@
26.207 NS_LOG_LOGIC ("For me (Ipv4Addr any address)");
26.208 return false;
26.209 }
26.210 -
26.211 - if (ipHeader.GetTtl () == 1)
26.212 - {
26.213 - // Should send ttl expired here
26.214 - // XXX
26.215 - NS_LOG_LOGIC ("Not for me (TTL expired). Drop");
26.216 - m_dropTrace (packet);
26.217 - return true;
26.218 - }
26.219 - ipHeader.SetTtl (ipHeader.GetTtl () - 1);
26.220 -
26.221 //
26.222 // If this is a to a multicast address and this node is a member of the
26.223 // indicated group we need to return false so the multicast is forwarded up.
26.224 @@ -710,18 +803,39 @@
26.225 // We forward with a packet copy, since forwarding may change
26.226 // the packet, affecting our local delivery
26.227 NS_LOG_LOGIC ("Forwarding (multicast).");
26.228 - Lookup (ifIndex, ipHeader, packet->Copy (),
26.229 - MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
26.230 + DoForward (ifIndex, packet->Copy (), ipHeader);
26.231 return false;
26.232 }
26.233 - }
26.234 + }
26.235 +
26.236 + DoForward (ifIndex, packet, ipHeader);
26.237 + return true;
26.238 +}
26.239 +
26.240 +void
26.241 +Ipv4L3Protocol::DoForward (uint32_t ifIndex,
26.242 + Ptr<Packet> packet,
26.243 + Ipv4Header ipHeader)
26.244 +{
26.245 + NS_LOG_FUNCTION (this << ifIndex << packet << ipHeader);
26.246 +
26.247 + ipHeader.SetTtl (ipHeader.GetTtl () - 1);
26.248 + if (ipHeader.GetTtl () == 0)
26.249 + {
26.250 + if (IsUnicast (ipHeader.GetDestination (), GetInterface (ifIndex)->GetNetworkMask ()))
26.251 + {
26.252 + Ptr<Icmpv4L4Protocol> icmp = GetIcmp ();
26.253 + icmp->SendTimeExceededTtl (ipHeader, packet);
26.254 + }
26.255 + m_dropTrace (packet);
26.256 + return;
26.257 + }
26.258 NS_LOG_LOGIC ("Not for me, forwarding.");
26.259 Lookup (ifIndex, ipHeader, packet,
26.260 - MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
26.261 -
26.262 - return true;
26.263 + MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
26.264 }
26.265
26.266 +
26.267 void
26.268 Ipv4L3Protocol::ForwardUp (Ptr<Packet> p, Ipv4Header const&ip,
26.269 Ptr<Ipv4Interface> incomingInterface)
26.270 @@ -729,7 +843,26 @@
26.271 NS_LOG_FUNCTION (this << p << &ip);
26.272
26.273 Ptr<Ipv4L4Protocol> protocol = GetProtocol (ip.GetProtocol ());
26.274 - protocol->Receive (p, ip.GetSource (), ip.GetDestination (), incomingInterface);
26.275 + if (protocol != 0)
26.276 + {
26.277 + // we need to make a copy in the unlikely event we hit the
26.278 + // RX_ENDPOINT_UNREACH codepath
26.279 + Ptr<Packet> copy = p->Copy ();
26.280 + enum Ipv4L4Protocol::RxStatus status =
26.281 + protocol->Receive (p, ip.GetSource (), ip.GetDestination (), incomingInterface);
26.282 + switch (status) {
26.283 + case Ipv4L4Protocol::RX_OK:
26.284 + // fall through
26.285 + case Ipv4L4Protocol::RX_CSUM_FAILED:
26.286 + break;
26.287 + case Ipv4L4Protocol::RX_ENDPOINT_UNREACH:
26.288 + if (IsUnicast (ip.GetDestination (), incomingInterface->GetNetworkMask ()))
26.289 + {
26.290 + GetIcmp ()->SendDestUnreachPort (ip, copy);
26.291 + }
26.292 + break;
26.293 + }
26.294 + }
26.295 }
26.296
26.297 void
27.1 --- a/src/internet-stack/ipv4-l3-protocol.h Mon Oct 27 23:05:57 2008 -0700
27.2 +++ b/src/internet-stack/ipv4-l3-protocol.h Wed Oct 29 11:49:21 2008 -0700
27.3 @@ -40,7 +40,11 @@
27.4 class Ipv4Header;
27.5 class Ipv4Route;
27.6 class Node;
27.7 +class Socket;
27.8 +class Ipv4RawSocketImpl;
27.9 class Ipv4L4Protocol;
27.10 +class Ipv4L4Protocol;
27.11 +class Icmpv4L4Protocol;
27.12
27.13
27.14 /**
27.15 @@ -60,6 +64,9 @@
27.16
27.17 void SetNode (Ptr<Node> node);
27.18
27.19 + Ptr<Socket> CreateRawSocket (void);
27.20 + void DeleteRawSocket (Ptr<Socket> socket);
27.21 +
27.22 /**
27.23 * \param protocol a template for the protocol to add to this L4 Demux.
27.24 * \returns the L4Protocol effectively added.
27.25 @@ -201,6 +208,8 @@
27.26 virtual void DoDispose (void);
27.27
27.28 private:
27.29 + Ipv4L3Protocol(const Ipv4L3Protocol &);
27.30 + Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
27.31 void Lookup (uint32_t ifIndex,
27.32 Ipv4Header const &ipHeader,
27.33 Ptr<Packet> packet,
27.34 @@ -217,15 +226,19 @@
27.35 void ForwardUp (Ptr<Packet> p, Ipv4Header const&ip, Ptr<Ipv4Interface> incomingInterface);
27.36 uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
27.37 void SetupLoopback (void);
27.38 - Ipv4L3Protocol(const Ipv4L3Protocol &);
27.39 - Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
27.40 + Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
27.41 + bool IsUnicast (Ipv4Address ad, Ipv4Mask interfaceMask) const;
27.42 + void DoForward (uint32_t ifIndex,
27.43 + Ptr<Packet> packet,
27.44 + Ipv4Header ipHeader);
27.45 +
27.46
27.47 typedef std::list<Ptr<Ipv4Interface> > Ipv4InterfaceList;
27.48 - typedef std::list<std::pair<Ipv4Address, Ipv4Address> >
27.49 - Ipv4MulticastGroupList;
27.50 + typedef std::list<std::pair<Ipv4Address, Ipv4Address> > Ipv4MulticastGroupList;
27.51 typedef std::list< std::pair< int, Ptr<Ipv4RoutingProtocol> > > Ipv4RoutingProtocolList;
27.52 + typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
27.53 + typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
27.54
27.55 - typedef std::list<Ptr<Ipv4L4Protocol> > L4List_t;
27.56 L4List_t m_protocols;
27.57 Ipv4InterfaceList m_interfaces;
27.58 uint32_t m_nInterfaces;
27.59 @@ -241,6 +254,8 @@
27.60
27.61 Ptr<Ipv4StaticRouting> m_staticRouting;
27.62 Ipv4MulticastGroupList m_multicastGroups;
27.63 +
27.64 + SocketList m_sockets;
27.65 };
27.66
27.67 } // Namespace ns3
28.1 --- a/src/internet-stack/ipv4-l4-protocol.cc Mon Oct 27 23:05:57 2008 -0700
28.2 +++ b/src/internet-stack/ipv4-l4-protocol.cc Wed Oct 29 11:49:21 2008 -0700
28.3 @@ -44,4 +44,11 @@
28.4 Ipv4L4Protocol::~Ipv4L4Protocol ()
28.5 {}
28.6
28.7 +void
28.8 +Ipv4L4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
28.9 + uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
28.10 + Ipv4Address payloadSource,Ipv4Address payloadDestination,
28.11 + const uint8_t payload[8])
28.12 +{}
28.13 +
28.14 }//namespace ns3
29.1 --- a/src/internet-stack/ipv4-l4-protocol.h Mon Oct 27 23:05:57 2008 -0700
29.2 +++ b/src/internet-stack/ipv4-l4-protocol.h Wed Oct 29 11:49:21 2008 -0700
29.3 @@ -25,12 +25,13 @@
29.4 #define IPV4_L4_PROTOCOL_H
29.5
29.6 #include "ns3/object.h"
29.7 -#include "ipv4-interface.h"
29.8 +#include "ns3/ipv4-header.h"
29.9
29.10 namespace ns3 {
29.11
29.12 class Packet;
29.13 class Ipv4Address;
29.14 +class Ipv4Interface;
29.15
29.16 /**
29.17 * \brief L4 Protocol abstract base class
29.18 @@ -41,6 +42,12 @@
29.19 class Ipv4L4Protocol : public Object
29.20 {
29.21 public:
29.22 + enum RxStatus {
29.23 + RX_OK,
29.24 + RX_CSUM_FAILED,
29.25 + RX_ENDPOINT_UNREACH
29.26 + };
29.27 +
29.28 static TypeId GetTypeId (void);
29.29
29.30 virtual ~Ipv4L4Protocol ();
29.31 @@ -59,10 +66,29 @@
29.32 * Called from lower-level layers to send the packet up
29.33 * in the stack.
29.34 */
29.35 - virtual void Receive(Ptr<Packet> p,
29.36 - Ipv4Address const &source,
29.37 - Ipv4Address const &destination,
29.38 - Ptr<Ipv4Interface> incomingInterface) = 0;
29.39 + virtual enum RxStatus Receive(Ptr<Packet> p,
29.40 + Ipv4Address const &source,
29.41 + Ipv4Address const &destination,
29.42 + Ptr<Ipv4Interface> incomingInterface) = 0;
29.43 +
29.44 + /**
29.45 + * \param icmpSouce the source address of the icmp message
29.46 + * \param icmpTtl the ttl of the icmp message
29.47 + * \param icmpType the 'type' field of the icmp message
29.48 + * \param icmpCode the 'code' field of the icmp message
29.49 + * \param icmpInfo extra information dependent on the icmp message
29.50 + * generated by Icmpv4L4Protocol
29.51 + * \param payloadSource the source address of the packet which triggered
29.52 + * the icmp message
29.53 + * \param payloadDestination the destination address of the packet which
29.54 + * triggered the icmp message.
29.55 + * \param payload the first 8 bytes of the udp header of the packet
29.56 + * which triggered the icmp message.
29.57 + */
29.58 + virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
29.59 + uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
29.60 + Ipv4Address payloadSource, Ipv4Address payloadDestination,
29.61 + const uint8_t payload[8]);
29.62 };
29.63
29.64 } // Namespace ns3
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/src/internet-stack/ipv4-raw-socket-factory-impl.cc Wed Oct 29 11:49:21 2008 -0700
30.3 @@ -0,0 +1,16 @@
30.4 +#include "ipv4-raw-socket-factory-impl.h"
30.5 +#include "ipv4-l3-protocol.h"
30.6 +#include "ns3/socket.h"
30.7 +
30.8 +namespace ns3 {
30.9 +
30.10 +
30.11 +Ptr<Socket>
30.12 +Ipv4RawSocketFactoryImpl::CreateSocket (void)
30.13 +{
30.14 + Ptr<Ipv4L3Protocol> ipv4 = GetObject<Ipv4L3Protocol> ();
30.15 + Ptr<Socket> socket = ipv4->CreateRawSocket ();
30.16 + return socket;
30.17 +}
30.18 +
30.19 +} // namespace ns3
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/src/internet-stack/ipv4-raw-socket-factory-impl.h Wed Oct 29 11:49:21 2008 -0700
31.3 @@ -0,0 +1,17 @@
31.4 +#ifndef IPV4_RAW_SOCKET_FACTORY_IMPL_H
31.5 +#define IPV4_RAW_SOCKET_FACTORY_IMPL_H
31.6 +
31.7 +#include "ns3/ipv4-raw-socket-factory.h"
31.8 +
31.9 +namespace ns3 {
31.10 +
31.11 +class Ipv4RawSocketFactoryImpl : public Ipv4RawSocketFactory
31.12 +{
31.13 +public:
31.14 + virtual Ptr<Socket> CreateSocket (void);
31.15 +};
31.16 +
31.17 +
31.18 +} // namespace ns3
31.19 +
31.20 +#endif /* IPV4_RAW_SOCKET_FACTORY_IMPL_H */
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/src/internet-stack/ipv4-raw-socket-impl.cc Wed Oct 29 11:49:21 2008 -0700
32.3 @@ -0,0 +1,269 @@
32.4 +#include "ipv4-raw-socket-impl.h"
32.5 +#include "ipv4-l3-protocol.h"
32.6 +#include "icmpv4.h"
32.7 +#include "ns3/inet-socket-address.h"
32.8 +#include "ns3/node.h"
32.9 +#include "ns3/packet.h"
32.10 +#include "ns3/uinteger.h"
32.11 +#include "ns3/log.h"
32.12 +
32.13 +NS_LOG_COMPONENT_DEFINE ("Ipv4RawSocketImpl");
32.14 +
32.15 +namespace ns3 {
32.16 +
32.17 +NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketImpl);
32.18 +
32.19 +TypeId
32.20 +Ipv4RawSocketImpl::GetTypeId (void)
32.21 +{
32.22 + static TypeId tid = TypeId ("ns3::Ipv4RawSocketImpl")
32.23 + .SetParent<Socket> ()
32.24 + .AddAttribute ("Protocol", "Protocol number to match.",
32.25 + UintegerValue (0),
32.26 + MakeUintegerAccessor (&Ipv4RawSocketImpl::m_protocol),
32.27 + MakeUintegerChecker<uint16_t> ())
32.28 + .AddAttribute ("IcmpFilter",
32.29 + "Any icmp header whose type field matches a bit in this filter is dropped.",
32.30 + UintegerValue (0),
32.31 + MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter),
32.32 + MakeUintegerChecker<uint32_t> ())
32.33 + ;
32.34 + return tid;
32.35 +}
32.36 +
32.37 +Ipv4RawSocketImpl::Ipv4RawSocketImpl ()
32.38 +{
32.39 + NS_LOG_FUNCTION (this);
32.40 + m_err = Socket::ERROR_NOTERROR;
32.41 + m_node = 0;
32.42 + m_src = Ipv4Address::GetAny ();
32.43 + m_dst = Ipv4Address::GetAny ();
32.44 + m_protocol = 0;
32.45 + m_shutdownSend = false;
32.46 + m_shutdownRecv = false;
32.47 +}
32.48 +
32.49 +void
32.50 +Ipv4RawSocketImpl::SetNode (Ptr<Node> node)
32.51 +{
32.52 + m_node = node;
32.53 +}
32.54 +
32.55 +void
32.56 +Ipv4RawSocketImpl::DoDispose (void)
32.57 +{
32.58 + NS_LOG_FUNCTION (this);
32.59 + m_node = 0;
32.60 + Socket::DoDispose ();
32.61 +}
32.62 +
32.63 +enum Socket::SocketErrno
32.64 +Ipv4RawSocketImpl::GetErrno (void) const
32.65 +{
32.66 + NS_LOG_FUNCTION (this);
32.67 + return m_err;
32.68 +}
32.69 +Ptr<Node>
32.70 +Ipv4RawSocketImpl::GetNode (void) const
32.71 +{
32.72 + NS_LOG_FUNCTION (this);
32.73 + return m_node;
32.74 +}
32.75 +int
32.76 +Ipv4RawSocketImpl::Bind (const Address &address)
32.77 +{
32.78 + NS_LOG_FUNCTION (this << address);
32.79 + if (!InetSocketAddress::IsMatchingType (address))
32.80 + {
32.81 + m_err = Socket::ERROR_INVAL;
32.82 + return -1;
32.83 + }
32.84 + InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
32.85 + m_src = ad.GetIpv4 ();
32.86 + return 0;
32.87 +}
32.88 +int
32.89 +Ipv4RawSocketImpl::Bind (void)
32.90 +{
32.91 + NS_LOG_FUNCTION (this);
32.92 + m_src = Ipv4Address::GetAny ();
32.93 + return 0;
32.94 +}
32.95 +int
32.96 +Ipv4RawSocketImpl::GetSockName (Address &address) const
32.97 +{
32.98 + address = InetSocketAddress (m_src, 0);
32.99 + return 0;
32.100 +}
32.101 +int
32.102 +Ipv4RawSocketImpl::Close (void)
32.103 +{
32.104 + NS_LOG_FUNCTION (this);
32.105 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
32.106 + if (ipv4 != 0)
32.107 + {
32.108 + ipv4->DeleteRawSocket (this);
32.109 + }
32.110 + return 0;
32.111 +}
32.112 +int
32.113 +Ipv4RawSocketImpl::ShutdownSend (void)
32.114 +{
32.115 + NS_LOG_FUNCTION (this);
32.116 + m_shutdownSend = true;
32.117 + return 0;
32.118 +}
32.119 +int
32.120 +Ipv4RawSocketImpl::ShutdownRecv (void)
32.121 +{
32.122 + NS_LOG_FUNCTION (this);
32.123 + m_shutdownRecv = true;
32.124 + return 0;
32.125 +}
32.126 +int
32.127 +Ipv4RawSocketImpl::Connect (const Address &address)
32.128 +{
32.129 + NS_LOG_FUNCTION (this << address);
32.130 + if (!InetSocketAddress::IsMatchingType (address))
32.131 + {
32.132 + m_err = Socket::ERROR_INVAL;
32.133 + return -1;
32.134 + }
32.135 + InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
32.136 + m_dst = ad.GetIpv4 ();
32.137 + return 0;
32.138 +}
32.139 +int
32.140 +Ipv4RawSocketImpl::Listen (void)
32.141 +{
32.142 + NS_LOG_FUNCTION (this);
32.143 + m_err = Socket::ERROR_OPNOTSUPP;
32.144 + return -1;
32.145 +}
32.146 +uint32_t
32.147 +Ipv4RawSocketImpl::GetTxAvailable (void) const
32.148 +{
32.149 + NS_LOG_FUNCTION (this);
32.150 + return 0xffffffff;
32.151 +}
32.152 +int
32.153 +Ipv4RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
32.154 +{
32.155 + NS_LOG_FUNCTION (this << p << flags);
32.156 + InetSocketAddress to = InetSocketAddress (m_dst, m_protocol);
32.157 + return SendTo (p, flags, to);
32.158 +}
32.159 +int
32.160 +Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags,
32.161 + const Address &toAddress)
32.162 +{
32.163 + NS_LOG_FUNCTION (this << p << flags << toAddress);
32.164 + if (!InetSocketAddress::IsMatchingType (toAddress))
32.165 + {
32.166 + m_err = Socket::ERROR_INVAL;
32.167 + return -1;
32.168 + }
32.169 + if (m_shutdownSend)
32.170 + {
32.171 + return 0;
32.172 + }
32.173 + InetSocketAddress ad = InetSocketAddress::ConvertFrom (toAddress);
32.174 + Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
32.175 + Ipv4Address dst = ad.GetIpv4 ();
32.176 + uint32_t localIfIndex;
32.177 + if (ipv4->GetIfIndexForDestination(dst, localIfIndex))
32.178 + {
32.179 + ipv4->Send (p, ipv4->GetAddress (localIfIndex), dst, m_protocol);
32.180 + }
32.181 + else
32.182 + {
32.183 + NS_LOG_DEBUG ("dropped because no outgoing route.");
32.184 + }
32.185 + return 0;
32.186 +}
32.187 +uint32_t
32.188 +Ipv4RawSocketImpl::GetRxAvailable (void) const
32.189 +{
32.190 + NS_LOG_FUNCTION (this);
32.191 + uint32_t rx = 0;
32.192 + for (std::list<Data>::const_iterator i = m_recv.begin (); i != m_recv.end (); ++i)
32.193 + {
32.194 + rx += (i->packet)->GetSize ();
32.195 + }
32.196 + return rx;
32.197 +}
32.198 +Ptr<Packet>
32.199 +Ipv4RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
32.200 +{
32.201 + NS_LOG_FUNCTION (this << maxSize << flags);
32.202 + Address tmp;
32.203 + return RecvFrom (maxSize, flags, tmp);
32.204 +}
32.205 +Ptr<Packet>
32.206 +Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
32.207 + Address &fromAddress)
32.208 +{
32.209 + NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
32.210 + if (m_recv.empty ())
32.211 + {
32.212 + return 0;
32.213 + }
32.214 + struct Data data = m_recv.front ();
32.215 + m_recv.pop_front ();
32.216 + if (data.packet->GetSize () > maxSize)
32.217 + {
32.218 + Ptr<Packet> first = data.packet->CreateFragment (0, maxSize);
32.219 + data.packet->RemoveAtStart (maxSize);
32.220 + m_recv.push_front (data);
32.221 + return first;
32.222 + }
32.223 + InetSocketAddress inet = InetSocketAddress (data.fromIp, data.fromProtocol);
32.224 + fromAddress = inet;
32.225 + return data.packet;
32.226 +}
32.227 +
32.228 +void
32.229 +Ipv4RawSocketImpl::SetProtocol (uint16_t protocol)
32.230 +{
32.231 + NS_LOG_FUNCTION (this << protocol);
32.232 + m_protocol = protocol;
32.233 +}
32.234 +
32.235 +bool
32.236 +Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<NetDevice> device)
32.237 +{
32.238 + NS_LOG_FUNCTION (this << *p << ipHeader << device);
32.239 + if (m_shutdownRecv)
32.240 + {
32.241 + return false;
32.242 + }
32.243 + if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
32.244 + (m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) &&
32.245 + ipHeader.GetProtocol () == m_protocol)
32.246 + {
32.247 + Ptr<Packet> copy = p->Copy ();
32.248 + if (m_protocol == 1)
32.249 + {
32.250 + Icmpv4Header icmpHeader;
32.251 + copy->PeekHeader (icmpHeader);
32.252 + uint8_t type = icmpHeader.GetType ();
32.253 + if (type < 32 &&
32.254 + ((1 << type) & m_icmpFilter))
32.255 + {
32.256 + // filter out icmp packet.
32.257 + return false;
32.258 + }
32.259 + }
32.260 + copy->AddHeader (ipHeader);
32.261 + struct Data data;
32.262 + data.packet = copy;
32.263 + data.fromIp = ipHeader.GetSource ();
32.264 + data.fromProtocol = ipHeader.GetProtocol ();
32.265 + m_recv.push_back (data);
32.266 + NotifyDataRecv ();
32.267 + return true;
32.268 + }
32.269 + return false;
32.270 +}
32.271 +
32.272 +} // namespace ns3
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/src/internet-stack/ipv4-raw-socket-impl.h Wed Oct 29 11:49:21 2008 -0700
33.3 @@ -0,0 +1,65 @@
33.4 +#ifndef IPV4_RAW_SOCKET_IMPL_H
33.5 +#define IPV4_RAW_SOCKET_IMPL_H
33.6 +
33.7 +#include "ns3/socket.h"
33.8 +#include "ns3/ipv4-header.h"
33.9 +#include <list>
33.10 +
33.11 +namespace ns3 {
33.12 +
33.13 +class NetDevice;
33.14 +class Node;
33.15 +
33.16 +class Ipv4RawSocketImpl : public Socket
33.17 +{
33.18 +public:
33.19 + static TypeId GetTypeId (void);
33.20 +
33.21 + Ipv4RawSocketImpl ();
33.22 +
33.23 + void SetNode (Ptr<Node> node);
33.24 +
33.25 + virtual enum Socket::SocketErrno GetErrno (void) const;
33.26 + virtual Ptr<Node> GetNode (void) const;
33.27 + virtual int Bind (const Address &address);
33.28 + virtual int Bind ();
33.29 + virtual int GetSockName (Address &address) const;
33.30 + virtual int Close (void);
33.31 + virtual int ShutdownSend (void);
33.32 + virtual int ShutdownRecv (void);
33.33 + virtual int Connect (const Address &address);
33.34 + virtual int Listen (void);
33.35 + virtual uint32_t GetTxAvailable (void) const;
33.36 + virtual int Send (Ptr<Packet> p, uint32_t flags);
33.37 + virtual int SendTo (Ptr<Packet> p, uint32_t flags,
33.38 + const Address &toAddress);
33.39 + virtual uint32_t GetRxAvailable (void) const;
33.40 + virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
33.41 + virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
33.42 + Address &fromAddress);
33.43 +
33.44 + void SetProtocol (uint16_t protocol);
33.45 + bool ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<NetDevice> device);
33.46 +private:
33.47 + virtual void DoDispose (void);
33.48 +
33.49 + struct Data {
33.50 + Ptr<Packet> packet;
33.51 + Ipv4Address fromIp;
33.52 + uint16_t fromProtocol;
33.53 + };
33.54 +
33.55 + enum Socket::SocketErrno m_err;
33.56 + Ptr<Node> m_node;
33.57 + Ipv4Address m_src;
33.58 + Ipv4Address m_dst;
33.59 + uint16_t m_protocol;
33.60 + std::list<struct Data> m_recv;
33.61 + bool m_shutdownSend;
33.62 + bool m_shutdownRecv;
33.63 + uint32_t m_icmpFilter;
33.64 +};
33.65 +
33.66 +} // namespace ns3
33.67 +
33.68 +#endif /* IPV4_RAW_SOCKET_IMPL_H */
34.1 --- a/src/internet-stack/nsc-tcp-l4-protocol.cc Mon Oct 27 23:05:57 2008 -0700
34.2 +++ b/src/internet-stack/nsc-tcp-l4-protocol.cc Wed Oct 29 11:49:21 2008 -0700
34.3 @@ -220,7 +220,7 @@
34.4 // NSC m_endPoints->DeAllocate (endPoint);
34.5 }
34.6
34.7 -void
34.8 +Ipv4L4Protocol::RxStatus
34.9 NscTcpL4Protocol::Receive (Ptr<Packet> packet,
34.10 Ipv4Address const &source,
34.11 Ipv4Address const &destination,
34.12 @@ -251,6 +251,7 @@
34.13 // deliver complete packet to the NSC network stack
34.14 m_nscStack->if_receive_packet(0, data, packetSize);
34.15 wakeup ();
34.16 + return Ipv4L4Protocol::RX_OK;
34.17 }
34.18
34.19 void NscTcpL4Protocol::SoftInterrupt (void)
35.1 --- a/src/internet-stack/nsc-tcp-l4-protocol.h Mon Oct 27 23:05:57 2008 -0700
35.2 +++ b/src/internet-stack/nsc-tcp-l4-protocol.h Wed Oct 29 11:49:21 2008 -0700
35.3 @@ -80,10 +80,10 @@
35.4 * \param destination The destinations Ipv4Address
35.5 * \param incomingInterface The Ipv4Interface it was received on
35.6 */
35.7 - virtual void Receive (Ptr<Packet> p,
35.8 - Ipv4Address const &source,
35.9 - Ipv4Address const &destination,
35.10 - Ptr<Ipv4Interface> incomingInterface);
35.11 + virtual Ipv4L4Protocol::RxStatus Receive (Ptr<Packet> p,
35.12 + Ipv4Address const &source,
35.13 + Ipv4Address const &destination,
35.14 + Ptr<Ipv4Interface> incomingInterface);
35.15
35.16 // NSC callbacks.
35.17 // NSC invokes these hooks to interact with the simulator.
36.1 --- a/src/internet-stack/tcp-l4-protocol.cc Mon Oct 27 23:05:57 2008 -0700
36.2 +++ b/src/internet-stack/tcp-l4-protocol.cc Wed Oct 29 11:49:21 2008 -0700
36.3 @@ -431,7 +431,7 @@
36.4 m_endPoints->DeAllocate (endPoint);
36.5 }
36.6
36.7 -void
36.8 +enum Ipv4L4Protocol::RxStatus
36.9 TcpL4Protocol::Receive (Ptr<Packet> packet,
36.10 Ipv4Address const &source,
36.11 Ipv4Address const &destination,
36.12 @@ -457,7 +457,7 @@
36.13 if(!tcpHeader.IsChecksumOk ())
36.14 {
36.15 NS_LOG_INFO("Bad checksum, dropping packet!");
36.16 - return;
36.17 + return Ipv4L4Protocol::RX_CSUM_FAILED;
36.18 }
36.19
36.20 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" received a packet");
36.21 @@ -474,11 +474,12 @@
36.22 source.Print (oss);
36.23 oss<<" source port: "<<tcpHeader.GetSourcePort ();
36.24 NS_LOG_LOGIC (oss.str ());
36.25 - return;
36.26 + return Ipv4L4Protocol::RX_ENDPOINT_UNREACH;
36.27 }
36.28 NS_ASSERT_MSG (endPoints.size() == 1 , "Demux returned more than one endpoint");
36.29 NS_LOG_LOGIC ("TcpL4Protocol "<<this<<" forwarding up to endpoint/socket");
36.30 (*endPoints.begin ())->ForwardUp (packet, source, tcpHeader.GetSourcePort ());
36.31 + return Ipv4L4Protocol::RX_OK;
36.32 }
36.33
36.34 void
37.1 --- a/src/internet-stack/tcp-l4-protocol.h Mon Oct 27 23:05:57 2008 -0700
37.2 +++ b/src/internet-stack/tcp-l4-protocol.h Wed Oct 29 11:49:21 2008 -0700
37.3 @@ -101,10 +101,10 @@
37.4 * \param destination The destinations Ipv4Address
37.5 * \param incomingInterface The Ipv4Interface it was received on
37.6 */
37.7 - virtual void Receive (Ptr<Packet> p,
37.8 - Ipv4Address const &source,
37.9 - Ipv4Address const &destination,
37.10 - Ptr<Ipv4Interface> incomingInterface);
37.11 + virtual enum Ipv4L4Protocol::RxStatus Receive (Ptr<Packet> p,
37.12 + Ipv4Address const &source,
37.13 + Ipv4Address const &destination,
37.14 + Ptr<Ipv4Interface> incomingInterface);
37.15
37.16 protected:
37.17 virtual void DoDispose (void);
38.1 --- a/src/internet-stack/tcp-socket-impl.cc Mon Oct 27 23:05:57 2008 -0700
38.2 +++ b/src/internet-stack/tcp-socket-impl.cc Wed Oct 29 11:49:21 2008 -0700
38.3 @@ -298,10 +298,6 @@
38.4 TcpSocketImpl::Close (void)
38.5 {
38.6 NS_LOG_FUNCTION_NOARGS ();
38.7 - if (m_state == CLOSED)
38.8 - {
38.9 - return -1;
38.10 - }
38.11 if (m_pendingData && m_pendingData->Size() != 0)
38.12 { // App close with pending data must wait until all data transmitted
38.13 m_closeOnEmpty = true;
39.1 --- a/src/internet-stack/udp-l4-protocol.cc Mon Oct 27 23:05:57 2008 -0700
39.2 +++ b/src/internet-stack/udp-l4-protocol.cc Wed Oct 29 11:49:21 2008 -0700
39.3 @@ -146,6 +146,33 @@
39.4 }
39.5
39.6 void
39.7 +UdpL4Protocol::ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
39.8 + uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
39.9 + Ipv4Address payloadSource,Ipv4Address payloadDestination,
39.10 + const uint8_t payload[8])
39.11 +{
39.12 + NS_LOG_FUNCTION (this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
39.13 + << payloadSource << payloadDestination);
39.14 + uint16_t src, dst;
39.15 + src = payload[0] << 8;
39.16 + src |= payload[1];
39.17 + dst = payload[2] << 8;
39.18 + dst |= payload[3];
39.19 +
39.20 + Ipv4EndPoint *endPoint = m_endPoints->SimpleLookup (payloadSource, src, payloadDestination, dst);
39.21 + if (endPoint != 0)
39.22 + {
39.23 + endPoint->ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
39.24 + }
39.25 + else
39.26 + {
39.27 + NS_LOG_DEBUG ("no endpoint found source=" << payloadSource <<
39.28 + ", destination="<<payloadDestination<<
39.29 + ", src=" << src << ", dst=" << dst);
39.30 + }
39.31 +}
39.32 +
39.33 +enum Ipv4L4Protocol::RxStatus
39.34 UdpL4Protocol::Receive(Ptr<Packet> packet,
39.35 Ipv4Address const &source,
39.36 Ipv4Address const &destination,
39.37 @@ -165,17 +192,22 @@
39.38 if(!udpHeader.IsChecksumOk ())
39.39 {
39.40 NS_LOG_INFO("Bad checksum : dropping packet!");
39.41 - return;
39.42 + return Ipv4L4Protocol::RX_CSUM_FAILED;
39.43 }
39.44
39.45 Ipv4EndPointDemux::EndPoints endPoints =
39.46 m_endPoints->Lookup (destination, udpHeader.GetDestinationPort (),
39.47 source, udpHeader.GetSourcePort (), interface);
39.48 + if (endPoints.empty ())
39.49 + {
39.50 + return Ipv4L4Protocol::RX_ENDPOINT_UNREACH;
39.51 + }
39.52 for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
39.53 endPoint != endPoints.end (); endPoint++)
39.54 {
39.55 (*endPoint)->ForwardUp (packet->Copy (), source, udpHeader.GetSourcePort ());
39.56 }
39.57 + return Ipv4L4Protocol::RX_OK;
39.58 }
39.59
39.60 void
40.1 --- a/src/internet-stack/udp-l4-protocol.h Mon Oct 27 23:05:57 2008 -0700
40.2 +++ b/src/internet-stack/udp-l4-protocol.h Wed Oct 29 11:49:21 2008 -0700
40.3 @@ -84,10 +84,15 @@
40.4 * \param interface the interface from which the packet is coming.
40.5 */
40.6 // inherited from Ipv4L4Protocol
40.7 - virtual void Receive(Ptr<Packet> p,
40.8 - Ipv4Address const &source,
40.9 - Ipv4Address const &destination,
40.10 + virtual enum Ipv4L4Protocol::RxStatus Receive(Ptr<Packet> p,
40.11 + Ipv4Address const &source,
40.12 + Ipv4Address const &destination,
40.13 Ptr<Ipv4Interface> interface);
40.14 +
40.15 + virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
40.16 + uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
40.17 + Ipv4Address payloadSource,Ipv4Address payloadDestination,
40.18 + const uint8_t payload[8]);
40.19 protected:
40.20 virtual void DoDispose (void);
40.21 private:
41.1 --- a/src/internet-stack/udp-socket-impl.cc Mon Oct 27 23:05:57 2008 -0700
41.2 +++ b/src/internet-stack/udp-socket-impl.cc Wed Oct 29 11:49:21 2008 -0700
41.3 @@ -25,8 +25,6 @@
41.4 #include "ns3/ipv4.h"
41.5 #include "ns3/udp-socket-factory.h"
41.6 #include "ns3/trace-source-accessor.h"
41.7 -#include "ns3/uinteger.h"
41.8 -#include "ns3/boolean.h"
41.9 #include "udp-socket-impl.h"
41.10 #include "udp-l4-protocol.h"
41.11 #include "ipv4-end-point.h"
41.12 @@ -47,6 +45,10 @@
41.13 .AddConstructor<UdpSocketImpl> ()
41.14 .AddTraceSource ("Drop", "Drop UDP packet due to receive buffer overflow",
41.15 MakeTraceSourceAccessor (&UdpSocketImpl::m_dropTrace))
41.16 + .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
41.17 + CallbackValue (),
41.18 + MakeCallbackAccessor (&UdpSocketImpl::m_icmpCallback),
41.19 + MakeCallbackChecker ())
41.20 ;
41.21 return tid;
41.22 }
41.23 @@ -134,6 +136,7 @@
41.24 return -1;
41.25 }
41.26 m_endPoint->SetRxCallback (MakeCallback (&UdpSocketImpl::ForwardUp, Ptr<UdpSocketImpl> (this)));
41.27 + m_endPoint->SetIcmpCallback (MakeCallback (&UdpSocketImpl::ForwardIcmp, Ptr<UdpSocketImpl> (this)));
41.28 m_endPoint->SetDestroyCallback (MakeCallback (&UdpSocketImpl::Destroy, Ptr<UdpSocketImpl> (this)));
41.29 return 0;
41.30 }
41.31 @@ -328,6 +331,22 @@
41.32 tag.SetTtl (m_ipTtl);
41.33 p->AddTag (tag);
41.34 }
41.35 + {
41.36 + SocketSetDontFragmentTag tag;
41.37 + bool found = p->FindFirstMatchingTag (tag);
41.38 + if (!found)
41.39 + {
41.40 + if (m_mtuDiscover)
41.41 + {
41.42 + tag.Enable ();
41.43 + }
41.44 + else
41.45 + {
41.46 + tag.Disable ();
41.47 + }
41.48 + p->AddTag (tag);
41.49 + }
41.50 + }
41.51 //
41.52 // If dest is sent to the limited broadcast address (all ones),
41.53 // convert it to send a copy of the packet out of every interface
41.54 @@ -405,6 +424,7 @@
41.55 NS_LOG_FUNCTION (this << maxSize << flags);
41.56 if (m_deliveryQueue.empty() )
41.57 {
41.58 + m_errno = ERROR_AGAIN;
41.59 return 0;
41.60 }
41.61 Ptr<Packet> p = m_deliveryQueue.front ();
41.62 @@ -483,6 +503,19 @@
41.63 }
41.64 }
41.65
41.66 +void
41.67 +UdpSocketImpl::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
41.68 + uint8_t icmpType, uint8_t icmpCode,
41.69 + uint32_t icmpInfo)
41.70 +{
41.71 + NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
41.72 + (uint32_t)icmpCode << icmpInfo);
41.73 + if (!m_icmpCallback.IsNull ())
41.74 + {
41.75 + m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
41.76 + }
41.77 +}
41.78 +
41.79
41.80 void
41.81 UdpSocketImpl::SetRcvBufSize (uint32_t size)
41.82 @@ -520,6 +553,18 @@
41.83 return m_ipMulticastTtl;
41.84 }
41.85
41.86 +void
41.87 +UdpSocketImpl::SetMtuDiscover (bool discover)
41.88 +{
41.89 + m_mtuDiscover = discover;
41.90 +}
41.91 +bool
41.92 +UdpSocketImpl::GetMtuDiscover (void) const
41.93 +{
41.94 + return m_mtuDiscover;
41.95 +}
41.96 +
41.97 +
41.98 } //namespace ns3
41.99
41.100
42.1 --- a/src/internet-stack/udp-socket-impl.h Mon Oct 27 23:05:57 2008 -0700
42.2 +++ b/src/internet-stack/udp-socket-impl.h Wed Oct 29 11:49:21 2008 -0700
42.3 @@ -28,6 +28,7 @@
42.4 #include "ns3/ptr.h"
42.5 #include "ns3/ipv4-address.h"
42.6 #include "ns3/udp-socket.h"
42.7 +#include "icmpv4.h"
42.8
42.9 namespace ns3 {
42.10
42.11 @@ -83,6 +84,9 @@
42.12 virtual uint32_t GetIpTtl (void) const;
42.13 virtual void SetIpMulticastTtl (uint32_t ipTtl);
42.14 virtual uint32_t GetIpMulticastTtl (void) const;
42.15 + virtual void SetMtuDiscover (bool discover);
42.16 + virtual bool GetMtuDiscover (void) const;
42.17 +
42.18
42.19 friend class UdpSocketFactory;
42.20 // invoked by Udp class
42.21 @@ -92,6 +96,9 @@
42.22 int DoSend (Ptr<Packet> p);
42.23 int DoSendTo (Ptr<Packet> p, const Address &daddr);
42.24 int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
42.25 + void ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
42.26 + uint8_t icmpType, uint8_t icmpCode,
42.27 + uint32_t icmpInfo);
42.28
42.29 Ipv4EndPoint *m_endPoint;
42.30 Ptr<Node> m_node;
42.31 @@ -114,7 +121,8 @@
42.32 uint32_t m_rcvBufSize;
42.33 uint32_t m_ipTtl;
42.34 uint32_t m_ipMulticastTtl;
42.35 -
42.36 + bool m_mtuDiscover;
42.37 + Callback<void, Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> m_icmpCallback;
42.38 };
42.39
42.40 }//namespace ns3
43.1 --- a/src/internet-stack/wscript Mon Oct 27 23:05:57 2008 -0700
43.2 +++ b/src/internet-stack/wscript Wed Oct 29 11:49:21 2008 -0700
43.3 @@ -148,6 +148,10 @@
43.4 'pending-data.cc',
43.5 'sequence-number.cc',
43.6 'rtt-estimator.cc',
43.7 + 'ipv4-raw-socket-factory-impl.cc',
43.8 + 'ipv4-raw-socket-impl.cc',
43.9 + 'icmpv4.cc',
43.10 + 'icmpv4-l4-protocol.cc',
43.11 ]
43.12
43.13 headers = bld.create_obj('ns3header')
43.14 @@ -160,6 +164,7 @@
43.15 'ipv4-interface.h',
43.16 'ipv4-l3-protocol.h',
43.17 'ipv4-static-routing.h',
43.18 + 'icmpv4.h',
43.19 ]
43.20
43.21 if bld.env()['NSC_ENABLED']:
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/src/node/ipv4-raw-socket-factory.cc Wed Oct 29 11:49:21 2008 -0700
44.3 @@ -0,0 +1,35 @@
44.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
44.5 +/*
44.6 + * Copyright (c) 2007 INRIA
44.7 + *
44.8 + * This program is free software; you can redistribute it and/or modify
44.9 + * it under the terms of the GNU General Public License version 2 as
44.10 + * published by the Free Software Foundation;
44.11 + *
44.12 + * This program is distributed in the hope that it will be useful,
44.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44.15 + * GNU General Public License for more details.
44.16 + *
44.17 + * You should have received a copy of the GNU General Public License
44.18 + * along with this program; if not, write to the Free Software
44.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44.20 + *
44.21 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
44.22 + */
44.23 +#include "ipv4-raw-socket-factory.h"
44.24 +#include "ns3/uinteger.h"
44.25 +
44.26 +namespace ns3 {
44.27 +
44.28 +NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketFactory);
44.29 +
44.30 +TypeId Ipv4RawSocketFactory::GetTypeId (void)
44.31 +{
44.32 + static TypeId tid = TypeId ("ns3::Ipv4RawSocketFactory")
44.33 + .SetParent<SocketFactory> ()
44.34 + ;
44.35 + return tid;
44.36 +}
44.37 +
44.38 +} // namespace ns3
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
45.2 +++ b/src/node/ipv4-raw-socket-factory.h Wed Oct 29 11:49:21 2008 -0700
45.3 @@ -0,0 +1,46 @@
45.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
45.5 +/*
45.6 + * Copyright (c) 2007 INRIA
45.7 + *
45.8 + * This program is free software; you can redistribute it and/or modify
45.9 + * it under the terms of the GNU General Public License version 2 as
45.10 + * published by the Free Software Foundation;
45.11 + *
45.12 + * This program is distributed in the hope that it will be useful,
45.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
45.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45.15 + * GNU General Public License for more details.
45.16 + *
45.17 + * You should have received a copy of the GNU General Public License
45.18 + * along with this program; if not, write to the Free Software
45.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
45.20 + *
45.21 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
45.22 + */
45.23 +#ifndef IPV4_RAW_SOCKET_FACTORY_H
45.24 +#define IPV4_RAW_SOCKET_FACTORY_H
45.25 +
45.26 +#include "socket-factory.h"
45.27 +
45.28 +namespace ns3 {
45.29 +
45.30 +class Socket;
45.31 +
45.32 +/**
45.33 + * \ingroup socket
45.34 + *
45.35 + * \brief API to create RAW socket instances
45.36 + *
45.37 + * This abstract class defines the API for RAW socket factory.
45.38 + *
45.39 + */
45.40 +class Ipv4RawSocketFactory : public SocketFactory
45.41 +{
45.42 +public:
45.43 + static TypeId GetTypeId (void);
45.44 +
45.45 +};
45.46 +
45.47 +} // namespace ns3
45.48 +
45.49 +#endif /* IPV4_RAW_SOCKET_FACTORY_H */
46.1 --- a/src/node/socket.cc Mon Oct 27 23:05:57 2008 -0700
46.2 +++ b/src/node/socket.cc Wed Oct 29 11:49:21 2008 -0700
46.3 @@ -362,4 +362,57 @@
46.4 }
46.5
46.6
46.7 +SocketSetDontFragmentTag::SocketSetDontFragmentTag ()
46.8 +{}
46.9 +void
46.10 +SocketSetDontFragmentTag::Enable (void)
46.11 +{
46.12 + m_dontFragment = true;
46.13 +}
46.14 +void
46.15 +SocketSetDontFragmentTag::Disable (void)
46.16 +{
46.17 + m_dontFragment = false;
46.18 +}
46.19 +bool
46.20 +SocketSetDontFragmentTag::IsEnabled (void) const
46.21 +{
46.22 + return m_dontFragment;
46.23 +}
46.24 +
46.25 +TypeId
46.26 +SocketSetDontFragmentTag::GetTypeId (void)
46.27 +{
46.28 + static TypeId tid = TypeId ("ns3::SocketSetDontFragmentTag")
46.29 + .SetParent<Tag> ()
46.30 + .AddConstructor<SocketSetDontFragmentTag> ()
46.31 + ;
46.32 + return tid;
46.33 +}
46.34 +TypeId
46.35 +SocketSetDontFragmentTag::GetInstanceTypeId (void) const
46.36 +{
46.37 + return GetTypeId ();
46.38 +}
46.39 +uint32_t
46.40 +SocketSetDontFragmentTag::GetSerializedSize (void) const
46.41 +{
46.42 + return 1;
46.43 +}
46.44 +void
46.45 +SocketSetDontFragmentTag::Serialize (TagBuffer i) const
46.46 +{
46.47 + i.WriteU8 (m_dontFragment?1:0);
46.48 +}
46.49 +void
46.50 +SocketSetDontFragmentTag::Deserialize (TagBuffer i)
46.51 +{
46.52 + m_dontFragment = (i.ReadU8 () == 1)?true:false;
46.53 +}
46.54 +void
46.55 +SocketSetDontFragmentTag::Print (std::ostream &os) const
46.56 +{
46.57 + os << (m_dontFragment?"true":"false");
46.58 +}
46.59 +
46.60 }//namespace ns3
47.1 --- a/src/node/socket.h Mon Oct 27 23:05:57 2008 -0700
47.2 +++ b/src/node/socket.h Wed Oct 29 11:49:21 2008 -0700
47.3 @@ -336,9 +336,9 @@
47.4 * not preserved.
47.5 *
47.6 * The flags argument is formed by or'ing one or more of the values:
47.7 - * MSG_OOB process out-of-band data
47.8 - * MSG_PEEK peek at incoming message
47.9 - * These flags are _unsupported_ as of ns-3.1.
47.10 + * MSG_OOB process out-of-band data
47.11 + * MSG_PEEK peek at incoming message
47.12 + * None of these flags are supported for now.
47.13 *
47.14 * Some variants of Recv() are supported as additional API,
47.15 * including RecvFrom(), overloaded Recv() without arguments,
47.16 @@ -555,6 +555,29 @@
47.17 uint8_t m_ttl;
47.18 };
47.19
47.20 +
47.21 +/**
47.22 + * \brief indicated whether packets should be sent out with
47.23 + * the DF flag set.
47.24 + */
47.25 +class SocketSetDontFragmentTag : public Tag
47.26 +{
47.27 +public:
47.28 + SocketSetDontFragmentTag ();
47.29 + void Enable (void);
47.30 + void Disable (void);
47.31 + bool IsEnabled (void) const;
47.32 +
47.33 + static TypeId GetTypeId (void);
47.34 + virtual TypeId GetInstanceTypeId (void) const;
47.35 + virtual uint32_t GetSerializedSize (void) const;
47.36 + virtual void Serialize (TagBuffer i) const;
47.37 + virtual void Deserialize (TagBuffer i);
47.38 + virtual void Print (std::ostream &os) const;
47.39 +private:
47.40 + bool m_dontFragment;
47.41 +};
47.42 +
47.43 } //namespace ns3
47.44
47.45 #endif /* SOCKET_H */
48.1 --- a/src/node/udp-socket.cc Mon Oct 27 23:05:57 2008 -0700
48.2 +++ b/src/node/udp-socket.cc Wed Oct 29 11:49:21 2008 -0700
48.3 @@ -21,6 +21,7 @@
48.4 #include "ns3/object.h"
48.5 #include "ns3/log.h"
48.6 #include "ns3/uinteger.h"
48.7 +#include "ns3/boolean.h"
48.8 #include "ns3/trace-source-accessor.h"
48.9 #include "udp-socket.h"
48.10
48.11 @@ -53,6 +54,11 @@
48.12 MakeUintegerAccessor (&UdpSocket::GetIpMulticastTtl,
48.13 &UdpSocket::SetIpMulticastTtl),
48.14 MakeUintegerChecker<uint32_t> ())
48.15 + .AddAttribute ("MtuDiscover", "If enabled, every outgoing ip packet will have the DF flag set.",
48.16 + BooleanValue (false),
48.17 + MakeBooleanAccessor (&UdpSocket::SetMtuDiscover,
48.18 + &UdpSocket::GetMtuDiscover),
48.19 + MakeBooleanChecker ())
48.20 ;
48.21 return tid;
48.22 }
49.1 --- a/src/node/udp-socket.h Mon Oct 27 23:05:57 2008 -0700
49.2 +++ b/src/node/udp-socket.h Wed Oct 29 11:49:21 2008 -0700
49.3 @@ -58,7 +58,8 @@
49.4 virtual uint32_t GetIpTtl (void) const = 0;
49.5 virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0;
49.6 virtual uint32_t GetIpMulticastTtl (void) const = 0;
49.7 -
49.8 + virtual void SetMtuDiscover (bool discover) = 0;
49.9 + virtual bool GetMtuDiscover (void) const = 0;
49.10 };
49.11
49.12 } //namespace ns3
50.1 --- a/src/node/wscript Mon Oct 27 23:05:57 2008 -0700
50.2 +++ b/src/node/wscript Wed Oct 29 11:49:21 2008 -0700
50.3 @@ -34,6 +34,7 @@
50.4 'application.cc',
50.5 'simple-channel.cc',
50.6 'simple-net-device.cc',
50.7 + 'ipv4-raw-socket-factory.cc',
50.8 ]
50.9
50.10 headers = bld.create_obj('ns3header')
50.11 @@ -69,4 +70,5 @@
50.12 'application.h',
50.13 'simple-channel.h',
50.14 'simple-net-device.h',
50.15 + 'ipv4-raw-socket-factory.h',
50.16 ]
51.1 --- a/src/wscript Mon Oct 27 23:05:57 2008 -0700
51.2 +++ b/src/wscript Wed Oct 29 11:49:21 2008 -0700
51.3 @@ -31,6 +31,7 @@
51.4 'devices/wifi',
51.5 'helper',
51.6 'contrib/stats',
51.7 + 'applications/v4ping',
51.8 )
51.9
51.10 def set_options(opt):