A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
38 }
39 
41 {
42  if (!m_destroyCallback.IsNull ())
43  {
45  }
46  m_rxCallback.Nullify ();
47  m_icmpCallback.Nullify ();
49 }
50 
52 {
53  return m_localAddr;
54 }
55 
57 {
58  m_localAddr = addr;
59 }
60 
62 {
63  return m_localPort;
64 }
65 
67 {
68  m_localPort = port;
69 }
70 
72 {
73  return m_peerAddr;
74 }
75 
77 {
78  return m_peerPort;
79 }
80 
82 {
83  m_boundnetdevice = netdevice;
84  return;
85 }
86 
88 {
89  return m_boundnetdevice;
90 }
91 
92 void Ipv6EndPoint::SetPeer (Ipv6Address addr, uint16_t port)
93 {
94  m_peerAddr = addr;
95  m_peerPort = port;
96 }
97 
99 {
100  m_rxCallback = callback;
101 }
102 
104 {
105  m_icmpCallback = callback;
106 }
107 
109 {
110  m_destroyCallback = callback;
111 }
112 
113 void Ipv6EndPoint::ForwardUp (Ptr<Packet> p, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
114 {
115  if (!m_rxCallback.IsNull ())
116  {
117  Simulator::ScheduleNow (&Ipv6EndPoint::DoForwardUp, this, p, header, port,
118  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  {
128  src, ttl, type, code, info);
129  }
130 }
131 
132 void Ipv6EndPoint::DoForwardUp (Ptr<Packet> p, Ipv6Header header, uint16_t sport, Ptr<Ipv6Interface> incomingInterface)
133 {
134  m_rxCallback (p, header, sport, incomingInterface);
135 }
136 
137 void Ipv6EndPoint::DoForwardIcmp (Ipv6Address src, uint8_t ttl, uint8_t type,
138  uint8_t code, uint32_t info)
139 {
140  m_icmpCallback (src, ttl, type, code, info);
141 }
142 
143 } /* namespace ns3 */
144 
Ipv6Address GetLocalAddress()
Get the local address.
Ptr< NetDevice > m_boundnetdevice
The NetDevice the EndPoint is bound to (if any).
Doxygen introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
Callback template class.
Definition: callback.h:924
Ipv6Address m_peerAddr
The peer address.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1018
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void ForwardUp(Ptr< Packet > p, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Forward the packet to the upper level.
void DoForwardUp(Ptr< Packet > p, Ipv6Header header, uint16_t sport, Ptr< Ipv6Interface > incomingInterface)
ForwardUp wrapper.
uint16_t port
Definition: dsdv-manet.cc:44
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.
void DoForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
ForwardIcmp wrapper.
Ipv6EndPoint(Ipv6Address addr, uint16_t port)
Constructor.
Callback< void > m_destroyCallback
The destroy callback.
uint16_t m_peerPort
The peer port.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:986
Describes an IPv6 address.
Definition: ipv6-address.h:46
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:1022
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.
Ptr< NetDevice > GetBoundNetDevice(void)
Returns socket's bound netdevice, if any.
uint16_t m_localPort
The local port.
void SetPeer(Ipv6Address addr, uint16_t port)
Set the peer informations (address and port).