A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ipv4-end-point.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
21
#include "
ipv4-end-point.h
"
22
#include "ns3/packet.h"
23
#include "ns3/log.h"
24
#include "ns3/simulator.h"
25
26
NS_LOG_COMPONENT_DEFINE
(
"Ipv4EndPoint"
);
27
28
namespace
ns3 {
29
30
Ipv4EndPoint::Ipv4EndPoint
(
Ipv4Address
address
, uint16_t
port
)
31
: m_localAddr (address),
32
m_localPort (port),
33
m_peerAddr (
Ipv4Address
::GetAny ()),
34
m_peerPort (0)
35
{
36
NS_LOG_FUNCTION
(
this
<< address << port);
37
}
38
Ipv4EndPoint::~Ipv4EndPoint
()
39
{
40
NS_LOG_FUNCTION
(
this
);
41
if
(!
m_destroyCallback
.
IsNull
())
42
{
43
m_destroyCallback
();
44
}
45
m_rxCallback
.
Nullify
();
46
m_icmpCallback
.
Nullify
();
47
m_destroyCallback
.
Nullify
();
48
}
49
50
Ipv4Address
51
Ipv4EndPoint::GetLocalAddress
(
void
)
52
{
53
NS_LOG_FUNCTION
(
this
);
54
return
m_localAddr
;
55
}
56
57
void
58
Ipv4EndPoint::SetLocalAddress
(
Ipv4Address
address
)
59
{
60
NS_LOG_FUNCTION
(
this
<< address);
61
m_localAddr
=
address
;
62
}
63
64
uint16_t
65
Ipv4EndPoint::GetLocalPort
(
void
)
66
{
67
NS_LOG_FUNCTION
(
this
);
68
return
m_localPort
;
69
}
70
Ipv4Address
71
Ipv4EndPoint::GetPeerAddress
(
void
)
72
{
73
NS_LOG_FUNCTION
(
this
);
74
return
m_peerAddr
;
75
}
76
uint16_t
77
Ipv4EndPoint::GetPeerPort
(
void
)
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_peerPort
;
81
}
82
void
83
Ipv4EndPoint::SetPeer
(
Ipv4Address
address
, uint16_t
port
)
84
{
85
NS_LOG_FUNCTION
(
this
<< address << port);
86
m_peerAddr
=
address
;
87
m_peerPort
=
port
;
88
}
89
90
void
91
Ipv4EndPoint::BindToNetDevice
(
Ptr<NetDevice>
netdevice)
92
{
93
NS_LOG_FUNCTION
(
this
<< netdevice);
94
m_boundnetdevice
= netdevice;
95
return
;
96
}
97
98
Ptr<NetDevice>
99
Ipv4EndPoint::GetBoundNetDevice
(
void
)
100
{
101
NS_LOG_FUNCTION
(
this
);
102
return
m_boundnetdevice
;
103
}
104
105
void
106
Ipv4EndPoint::SetRxCallback
(
Callback
<
void
,
Ptr<Packet>
,
Ipv4Header
, uint16_t,
Ptr<Ipv4Interface>
> callback)
107
{
108
NS_LOG_FUNCTION
(
this
<< &callback);
109
m_rxCallback
= callback;
110
}
111
void
112
Ipv4EndPoint::SetIcmpCallback
(
Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t>
callback)
113
{
114
NS_LOG_FUNCTION
(
this
<< &callback);
115
m_icmpCallback
= callback;
116
}
117
118
void
119
Ipv4EndPoint::SetDestroyCallback
(
Callback<void>
callback)
120
{
121
NS_LOG_FUNCTION
(
this
<< &callback);
122
m_destroyCallback
= callback;
123
}
124
125
void
126
Ipv4EndPoint::ForwardUp
(
Ptr<Packet>
p,
const
Ipv4Header
& header, uint16_t sport,
127
Ptr<Ipv4Interface>
incomingInterface)
128
{
129
NS_LOG_FUNCTION
(
this
<< p << &header << sport << incomingInterface);
130
131
if
(!
m_rxCallback
.
IsNull
())
132
{
133
Simulator::ScheduleNow
(&
Ipv4EndPoint::DoForwardUp
,
this
, p, header, sport,
134
incomingInterface);
135
}
136
}
137
void
138
Ipv4EndPoint::DoForwardUp
(
Ptr<Packet>
p,
const
Ipv4Header
& header, uint16_t sport,
139
Ptr<Ipv4Interface>
incomingInterface)
140
{
141
NS_LOG_FUNCTION
(
this
<< p << &header << sport << incomingInterface);
142
143
if
(!
m_rxCallback
.
IsNull
())
144
{
145
m_rxCallback
(p, header, sport, incomingInterface);
146
}
147
}
148
149
void
150
Ipv4EndPoint::ForwardIcmp
(
Ipv4Address
icmpSource, uint8_t icmpTtl,
151
uint8_t icmpType, uint8_t icmpCode,
152
uint32_t icmpInfo)
153
{
154
NS_LOG_FUNCTION
(
this
<< icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
155
(uint32_t)icmpCode << icmpInfo);
156
if
(!
m_icmpCallback
.
IsNull
())
157
{
158
Simulator::ScheduleNow
(&
Ipv4EndPoint::DoForwardIcmp
,
this
,
159
icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
160
}
161
}
162
void
163
Ipv4EndPoint::DoForwardIcmp
(
Ipv4Address
icmpSource, uint8_t icmpTtl,
164
uint8_t icmpType, uint8_t icmpCode,
165
uint32_t icmpInfo)
166
{
167
NS_LOG_FUNCTION
(
this
<< icmpSource << static_cast<uint32_t> (icmpTtl) << static_cast<uint32_t> (icmpType) << static_cast<uint32_t> (icmpCode) << icmpInfo);
168
169
if
(!
m_icmpCallback
.
IsNull
())
170
{
171
m_icmpCallback
(icmpSource,icmpTtl,icmpType,icmpCode,icmpInfo);
172
}
173
}
174
175
}
// namespace ns3
src
internet
model
ipv4-end-point.cc
Generated on Fri Aug 30 2013 01:42:51 for ns-3 by
1.8.1.2