A Discrete-Event Network Simulator
API
ipv6-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) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "ns3/packet.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 
25 #include "ipv6-end-point.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv6EndPoint");
31 
33  : m_localAddr (addr),
34  m_localPort (port),
35  m_peerAddr (Ipv6Address::GetAny ()),
36  m_peerPort (0),
37  m_rxEnabled (true)
38 {
39 }
40 
42 {
43  if (!m_destroyCallback.IsNull ())
44  {
46  }
47  m_rxCallback.Nullify ();
48  m_icmpCallback.Nullify ();
50 }
51 
53 {
54  return m_localAddr;
55 }
56 
58 {
59  m_localAddr = addr;
60 }
61 
63 {
64  return m_localPort;
65 }
66 
68 {
69  m_localPort = port;
70 }
71 
73 {
74  return m_peerAddr;
75 }
76 
78 {
79  return m_peerPort;
80 }
81 
83 {
84  m_boundnetdevice = netdevice;
85  return;
86 }
87 
89 {
90  return m_boundnetdevice;
91 }
92 
93 void Ipv6EndPoint::SetPeer (Ipv6Address addr, uint16_t port)
94 {
95  m_peerAddr = addr;
96  m_peerPort = port;
97 }
98 
100 {
101  m_rxCallback = callback;
102 }
103 
105 {
106  m_icmpCallback = callback;
107 }
108 
110 {
111  m_destroyCallback = callback;
112 }
113 
114 void Ipv6EndPoint::ForwardUp (Ptr<Packet> p, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
115 {
116  if (!m_rxCallback.IsNull ())
117  {
118  m_rxCallback (p, header, port, incomingInterface);
119  }
120 }
121 
122 void Ipv6EndPoint::ForwardIcmp (Ipv6Address src, uint8_t ttl, uint8_t type,
123  uint8_t code, uint32_t info)
124 {
125  if (!m_icmpCallback.IsNull ())
126  {
127  m_icmpCallback (src, ttl, type, code, info);
128  }
129 }
130 
131 void Ipv6EndPoint::SetRxEnabled (bool enabled)
132 {
133  m_rxEnabled = enabled;
134 }
135 
137 {
138  return m_rxEnabled;
139 }
140 
141 
142 } /* namespace ns3 */
143 
Ipv6Address GetLocalAddress()
Get the local address.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
Packet header for IPv6.
Definition: ipv6-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1273
Ipv6Address m_peerAddr
The peer address.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void ForwardUp(Ptr< Packet > p, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Forward the packet to the upper level.
uint16_t port
Definition: dsdv-manet.cc:45
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
uint16_t GetPeerPort()
Get the peer port.
void SetLocalAddress(Ipv6Address addr)
Set the local address.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
uint16_t GetLocalPort()
Get the local port.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
The ICMPv6 callback.
Ipv6Address m_localAddr
The local address.
Ipv6EndPoint(Ipv6Address addr, uint16_t port)
Constructor.
Callback< void > m_destroyCallback
The destroy callback.
uint16_t m_peerPort
The peer port.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsRxEnabled(void)
Checks if the endpoint can receive packets.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > m_rxCallback
The RX callback.
Ipv6Address GetPeerAddress()
Get the peer address.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1377
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
void SetLocalPort(uint16_t port)
Set the local port.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1372
bool m_rxEnabled
true if the endpoint can receive packets.
Ptr< NetDevice > GetBoundNetDevice(void)
Returns socket&#39;s bound netdevice, if any.
uint16_t m_localPort
The local port.
void SetPeer(Ipv6Address addr, uint16_t port)
Set the peer information (address and port).