author | Craig Dowell <craigdo@ee.washington.edu> |
Wed, 29 Oct 2008 11:18:39 -0700 | |
changeset 3820 | c04ecfdce1ef |
parent 3260 | 8c0ab08144e6 |
child 4022 | 142c13a3975f |
permissions | -rw-r--r-- |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005 INRIA |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
*/ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#include "ipv4-end-point.h" |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1317
diff
changeset
|
22 |
#include "ns3/packet.h" |
3820 | 23 |
#include "ns3/log.h" |
24 |
||
25 |
NS_LOG_COMPONENT_DEFINE ("Ipv4EndPoint"); |
|
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
namespace ns3 { |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
|
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
29 |
Ipv4EndPoint::Ipv4EndPoint (Ipv4Address address, uint16_t port) |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
: m_localAddr (address), |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
m_localPort (port), |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
m_peerAddr (Ipv4Address::GetAny ()), |
2365
89da0ca7c55e
undoes 2326:eec07777d1a2 because localInterface is no longer needed (see bug 136)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2326
diff
changeset
|
33 |
m_peerPort (0) |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
{} |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
Ipv4EndPoint::~Ipv4EndPoint () |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
36 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
37 |
if (!m_destroyCallback.IsNull ()) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
38 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
39 |
m_destroyCallback (); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
40 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
41 |
} |
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
Ipv4Address |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
Ipv4EndPoint::GetLocalAddress (void) |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
{ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
return m_localAddr; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
} |
1317
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
48 |
|
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
49 |
void |
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
50 |
Ipv4EndPoint::SetLocalAddress (Ipv4Address address) |
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
51 |
{ |
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
52 |
m_localAddr = address; |
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
53 |
} |
82629189efff
Fold the two patches for bu6 69 together, building on the bug 65 patch
Tom Henderson <tomh@tomh.org>
parents:
1308
diff
changeset
|
54 |
|
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
55 |
uint16_t |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
56 |
Ipv4EndPoint::GetLocalPort (void) |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
57 |
{ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
return m_localPort; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
59 |
} |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
Ipv4Address |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
Ipv4EndPoint::GetPeerAddress (void) |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
{ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
return m_peerAddr; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
} |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
uint16_t |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
Ipv4EndPoint::GetPeerPort (void) |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
{ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
return m_peerPort; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
} |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
void |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
Ipv4EndPoint::SetPeer (Ipv4Address address, uint16_t port) |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
72 |
{ |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
m_peerAddr = address; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
m_peerPort = port; |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
75 |
} |
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
77 |
void |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1317
diff
changeset
|
78 |
Ipv4EndPoint::SetRxCallback (Callback<void,Ptr<Packet>, Ipv4Address, uint16_t> callback) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
79 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
80 |
m_rxCallback = callback; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
81 |
} |
3820 | 82 |
void |
83 |
Ipv4EndPoint::SetIcmpCallback (Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t> callback) |
|
84 |
{ |
|
85 |
m_icmpCallback = callback; |
|
86 |
} |
|
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
87 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
88 |
void |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
89 |
Ipv4EndPoint::SetDestroyCallback (Callback<void> callback) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
90 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
91 |
m_destroyCallback = callback; |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
92 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
93 |
|
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
94 |
void |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1317
diff
changeset
|
95 |
Ipv4EndPoint::ForwardUp (Ptr<Packet> p, Ipv4Address saddr, uint16_t sport) |
495
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
96 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
97 |
if (!m_rxCallback.IsNull ()) |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
98 |
{ |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
99 |
m_rxCallback (p, saddr, sport); |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
100 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
101 |
} |
a839408950b9
rework the socket/udp layer to remove the Ipv4EndPointDemux template
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
238
diff
changeset
|
102 |
|
3820 | 103 |
void |
104 |
Ipv4EndPoint::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl, |
|
105 |
uint8_t icmpType, uint8_t icmpCode, |
|
106 |
uint32_t icmpInfo) |
|
107 |
{ |
|
108 |
NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType << |
|
109 |
(uint32_t)icmpCode << icmpInfo); |
|
110 |
if (!m_icmpCallback.IsNull ()) |
|
111 |
{ |
|
112 |
m_icmpCallback (icmpSource,icmpTtl,icmpType,icmpCode,icmpInfo); |
|
113 |
} |
|
114 |
} |
|
238
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
115 |
|
2f09fd9cf32e
add start of udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
}; // namespace ns3 |