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
}
37
Ipv4EndPoint::~Ipv4EndPoint
()
38
{
39
if
(!
m_destroyCallback
.
IsNull
())
40
{
41
m_destroyCallback
();
42
}
43
m_rxCallback
.
Nullify
();
44
m_icmpCallback
.
Nullify
();
45
m_destroyCallback
.
Nullify
();
46
}
47
48
Ipv4Address
49
Ipv4EndPoint::GetLocalAddress
(
void
)
50
{
51
return
m_localAddr
;
52
}
53
54
void
55
Ipv4EndPoint::SetLocalAddress
(
Ipv4Address
address)
56
{
57
m_localAddr
= address;
58
}
59
60
uint16_t
61
Ipv4EndPoint::GetLocalPort
(
void
)
62
{
63
return
m_localPort
;
64
}
65
Ipv4Address
66
Ipv4EndPoint::GetPeerAddress
(
void
)
67
{
68
return
m_peerAddr
;
69
}
70
uint16_t
71
Ipv4EndPoint::GetPeerPort
(
void
)
72
{
73
return
m_peerPort
;
74
}
75
void
76
Ipv4EndPoint::SetPeer
(
Ipv4Address
address, uint16_t
port
)
77
{
78
m_peerAddr
= address;
79
m_peerPort
=
port
;
80
}
81
82
void
83
Ipv4EndPoint::BindToNetDevice
(
Ptr<NetDevice>
netdevice)
84
{
85
m_boundnetdevice
= netdevice;
86
return
;
87
}
88
89
Ptr<NetDevice>
90
Ipv4EndPoint::GetBoundNetDevice
(
void
)
91
{
92
return
m_boundnetdevice
;
93
}
94
95
void
96
Ipv4EndPoint::SetRxCallback
(
Callback
<
void
,
Ptr<Packet>
,
Ipv4Header
, uint16_t,
Ptr<Ipv4Interface>
> callback)
97
{
98
m_rxCallback
= callback;
99
}
100
void
101
Ipv4EndPoint::SetIcmpCallback
(
Callback<void,Ipv4Address,uint8_t,uint8_t,uint8_t,uint32_t>
callback)
102
{
103
m_icmpCallback
= callback;
104
}
105
106
void
107
Ipv4EndPoint::SetDestroyCallback
(
Callback<void>
callback)
108
{
109
m_destroyCallback
= callback;
110
}
111
112
void
113
Ipv4EndPoint::ForwardUp
(
Ptr<Packet>
p,
const
Ipv4Header
& header, uint16_t sport,
114
Ptr<Ipv4Interface>
incomingInterface)
115
{
116
if
(!
m_rxCallback
.
IsNull
())
117
{
118
Simulator::ScheduleNow
(&
Ipv4EndPoint::DoForwardUp
,
this
, p, header, sport,
119
incomingInterface);
120
}
121
}
122
void
123
Ipv4EndPoint::DoForwardUp
(
Ptr<Packet>
p,
const
Ipv4Header
& header, uint16_t sport,
124
Ptr<Ipv4Interface>
incomingInterface)
125
{
126
m_rxCallback
(p, header, sport, incomingInterface);
127
}
128
129
void
130
Ipv4EndPoint::ForwardIcmp
(
Ipv4Address
icmpSource, uint8_t icmpTtl,
131
uint8_t icmpType, uint8_t icmpCode,
132
uint32_t icmpInfo)
133
{
134
NS_LOG_FUNCTION
(
this
<< icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
135
(uint32_t)icmpCode << icmpInfo);
136
if
(!
m_icmpCallback
.
IsNull
())
137
{
138
Simulator::ScheduleNow
(&
Ipv4EndPoint::DoForwardIcmp
,
this
,
139
icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
140
}
141
}
142
void
143
Ipv4EndPoint::DoForwardIcmp
(
Ipv4Address
icmpSource, uint8_t icmpTtl,
144
uint8_t icmpType, uint8_t icmpCode,
145
uint32_t icmpInfo)
146
{
147
m_icmpCallback
(icmpSource,icmpTtl,icmpType,icmpCode,icmpInfo);
148
}
149
150
}
// namespace ns3
src
internet
model
ipv4-end-point.cc
Generated on Fri Dec 21 2012 19:00:36 for ns-3 by
1.8.1.2