A Discrete-Event Network Simulator
API
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
26namespace ns3 {
27
28NS_LOG_COMPONENT_DEFINE ("Ipv4EndPoint");
29
31 : m_localAddr (address),
32 m_localPort (port),
33 m_peerAddr (Ipv4Address::GetAny ()),
34 m_peerPort (0),
35 m_rxEnabled (true)
36{
37 NS_LOG_FUNCTION (this << address << port);
38}
39
41{
42 NS_LOG_FUNCTION (this);
44 {
46 }
47 m_rxCallback.Nullify ();
48 m_icmpCallback.Nullify ();
50}
51
54{
55 NS_LOG_FUNCTION (this);
56 return m_localAddr;
57}
58
59void
61{
62 NS_LOG_FUNCTION (this << address);
64}
65
66uint16_t
68{
69 NS_LOG_FUNCTION (this);
70 return m_localPort;
71}
72
75{
76 NS_LOG_FUNCTION (this);
77 return m_peerAddr;
78}
79
80uint16_t
82{
83 NS_LOG_FUNCTION (this);
84 return m_peerPort;
85}
86
87void
89{
90 NS_LOG_FUNCTION (this << address << port);
93}
94
95void
97{
98 NS_LOG_FUNCTION (this << netdevice);
99 m_boundnetdevice = netdevice;
100}
101
104{
105 NS_LOG_FUNCTION (this);
106 return m_boundnetdevice;
107}
108
109void
111{
112 NS_LOG_FUNCTION (this << &callback);
113 m_rxCallback = callback;
114}
115
116void
118{
119 NS_LOG_FUNCTION (this << &callback);
120 m_icmpCallback = callback;
121}
122
123void
125{
126 NS_LOG_FUNCTION (this << &callback);
127 m_destroyCallback = callback;
128}
129
130void
131Ipv4EndPoint::ForwardUp (Ptr<Packet> p, const Ipv4Header& header, uint16_t sport,
132 Ptr<Ipv4Interface> incomingInterface)
133{
134 NS_LOG_FUNCTION (this << p << &header << sport << incomingInterface);
135
136 if (!m_rxCallback.IsNull ())
137 {
138 m_rxCallback (p, header, sport, incomingInterface);
139 }
140}
141
142void
143Ipv4EndPoint::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
144 uint8_t icmpType, uint8_t icmpCode,
145 uint32_t icmpInfo)
146{
147 NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
148 (uint32_t)icmpCode << icmpInfo);
149 if (!m_icmpCallback.IsNull ())
150 {
151 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
152 }
153}
154
155void
157{
158 m_rxEnabled = enabled;
159}
160
161bool
163{
164 return m_rxEnabled;
165}
166
167} // namespace ns3
Callback template class.
Definition: callback.h:422
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:537
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:532
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
uint16_t GetPeerPort(void)
Get the peer port.
bool m_rxEnabled
true if the endpoint can receive packets.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
void SetLocalAddress(Ipv4Address address)
Set the local address.
void ForwardUp(Ptr< Packet > p, const Ipv4Header &header, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
Forward the packet to the upper level.
Ipv4Address GetPeerAddress(void)
Get the peer address.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
uint16_t m_localPort
The local port.
Ipv4EndPoint(Ipv4Address address, uint16_t port)
Constructor.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
Ptr< NetDevice > GetBoundNetDevice(void)
Returns socket's bound netdevice, if any.
Ipv4Address m_peerAddr
The peer address.
uint16_t m_peerPort
The peer port.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void SetPeer(Ipv4Address address, uint16_t port)
Set the peer information (address and port).
uint16_t GetLocalPort(void)
Get the local port.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ipv4Address m_localAddr
The local address.
bool IsRxEnabled(void)
Checks if the endpoint can receive packets.
Callback< void > m_destroyCallback
The destroy callback.
Ipv4Address GetLocalAddress(void)
Get the local address.
Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > m_rxCallback
The RX callback.
Packet header for IPv4.
Definition: ipv4-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
uint16_t port
Definition: dsdv-manet.cc:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.