A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-end-point.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#include "ipv6-end-point.h"
21
22#include "ns3/log.h"
23#include "ns3/packet.h"
24#include "ns3/simulator.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("Ipv6EndPoint");
30
32 : m_localAddr(addr),
33 m_localPort(port),
34 m_peerAddr(Ipv6Address::GetAny()),
35 m_peerPort(0),
36 m_rxEnabled(true)
37{
38}
39
41{
43 {
45 }
46 m_rxCallback.Nullify();
47 m_icmpCallback.Nullify();
49}
50
53{
54 return m_localAddr;
55}
56
57void
59{
60 m_localAddr = addr;
61}
62
63uint16_t
65{
66 return m_localPort;
67}
68
69void
71{
73}
74
77{
78 return m_peerAddr;
79}
80
81uint16_t
83{
84 return m_peerPort;
85}
86
87void
89{
90 m_boundnetdevice = netdevice;
91}
92
95{
96 return m_boundnetdevice;
97}
98
99void
101{
102 m_peerAddr = addr;
104}
105
106void
108 Callback<void, Ptr<Packet>, Ipv6Header, uint16_t, Ptr<Ipv6Interface>> callback)
109{
110 m_rxCallback = callback;
111}
112
113void
116{
117 m_icmpCallback = callback;
118}
119
120void
122{
123 m_destroyCallback = callback;
124}
125
126void
128 Ipv6Header header,
129 uint16_t port,
130 Ptr<Ipv6Interface> incomingInterface)
131{
132 if (!m_rxCallback.IsNull())
133 {
134 m_rxCallback(p, header, port, incomingInterface);
135 }
136}
137
138void
139Ipv6EndPoint::ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
140{
141 if (!m_icmpCallback.IsNull())
142 {
143 m_icmpCallback(src, ttl, type, code, info);
144 }
145}
146
147void
149{
150 m_rxEnabled = enabled;
151}
152
153bool
155{
156 return m_rxEnabled;
157}
158
159} /* namespace ns3 */
Callback template class.
Definition: callback.h:438
void Nullify()
Discard the implementation, set it to null.
Definition: callback.h:575
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
Describes an IPv6 address.
Definition: ipv6-address.h:49
uint16_t m_peerPort
The peer port.
void ForwardUp(Ptr< Packet > p, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Forward the packet to the upper level.
uint16_t GetLocalPort() const
Get the local port.
void SetPeer(Ipv6Address addr, uint16_t port)
Set the peer information (address and port).
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
Ipv6Address GetPeerAddress() const
Get the peer address.
Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > m_rxCallback
The RX callback.
Ipv6Address m_peerAddr
The peer address.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void SetLocalPort(uint16_t port)
Set the local port.
bool m_rxEnabled
true if the endpoint can receive packets.
Ipv6Address GetLocalAddress() const
Get the local address.
Callback< void > m_destroyCallback
The destroy callback.
Ipv6EndPoint(Ipv6Address addr, uint16_t port)
Constructor.
Ipv6Address m_localAddr
The local address.
void SetLocalAddress(Ipv6Address addr)
Set the local address.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
uint16_t m_localPort
The local port.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
bool IsRxEnabled() const
Checks if the endpoint can receive packets.
Ptr< NetDevice > GetBoundNetDevice() const
Returns socket's bound netdevice, if any.
uint16_t GetPeerPort() const
Get the peer port.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Packet header for IPv6.
Definition: ipv6-header.h:35
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
uint16_t port
Definition: dsdv-manet.cc:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.