A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
udp-l4-protocol.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 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 #ifndef UDP_L4_PROTOCOL_H
22 #define UDP_L4_PROTOCOL_H
23 
24 #include <stdint.h>
25 
26 #include "ns3/packet.h"
27 #include "ns3/ipv4-address.h"
28 #include "ns3/ipv6-address.h"
29 #include "ns3/ptr.h"
30 #include "ns3/ip-l4-protocol.h"
31 #include "ipv6-interface.h"
32 #include "ipv6-header.h"
33 
34 namespace ns3 {
35 
36 class Node;
37 class Socket;
38 class Ipv4EndPointDemux;
39 class Ipv4EndPoint;
40 class Ipv6EndPointDemux;
41 class Ipv6EndPoint;
42 class UdpSocketImpl;
43 
48 class UdpL4Protocol : public IpL4Protocol {
49 public:
50  static TypeId GetTypeId (void);
51  static const uint8_t PROT_NUMBER;
52 
53  UdpL4Protocol ();
54  virtual ~UdpL4Protocol ();
55 
56  void SetNode (Ptr<Node> node);
57 
58  virtual int GetProtocolNumber (void) const;
59 
65 
66  Ipv4EndPoint *Allocate (void);
67  Ipv4EndPoint *Allocate (Ipv4Address address);
68  Ipv4EndPoint *Allocate (uint16_t port);
69  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
70  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
71  Ipv4Address peerAddress, uint16_t peerPort);
72  Ipv6EndPoint *Allocate6 (void);
73  Ipv6EndPoint *Allocate6 (Ipv6Address address);
74  Ipv6EndPoint *Allocate6 (uint16_t port);
75  Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port);
76  Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort,
77  Ipv6Address peerAddress, uint16_t peerPort);
78 
79  void DeAllocate (Ipv4EndPoint *endPoint);
80  void DeAllocate (Ipv6EndPoint *endPoint);
81 
82  // called by UdpSocket.
91  void Send (Ptr<Packet> packet,
92  Ipv4Address saddr, Ipv4Address daddr,
93  uint16_t sport, uint16_t dport);
94  void Send (Ptr<Packet> packet,
95  Ipv4Address saddr, Ipv4Address daddr,
96  uint16_t sport, uint16_t dport, Ptr<Ipv4Route> route);
97  void Send (Ptr<Packet> packet,
98  Ipv6Address saddr, Ipv6Address daddr,
99  uint16_t sport, uint16_t dport);
100  void Send (Ptr<Packet> packet,
101  Ipv6Address saddr, Ipv6Address daddr,
102  uint16_t sport, uint16_t dport, Ptr<Ipv6Route> route);
109  // inherited from Ipv4L4Protocol
110  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
111  Ipv4Header const &header,
112  Ptr<Ipv4Interface> interface);
113  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
114  Ipv6Header const &header,
115  Ptr<Ipv6Interface> interface);
116 
128  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
129  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
130  Ipv4Address payloadSource,Ipv4Address payloadDestination,
131  const uint8_t payload[8]);
132  virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
133  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
134  Ipv6Address payloadSource,Ipv6Address payloadDestination,
135  const uint8_t payload[8]);
136 
137  // From IpL4Protocol
139  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
140  // From IpL4Protocol
141  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
142  virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6 (void) const;
143 
144 protected:
145  virtual void DoDispose (void);
146  /*
147  * This function will notify other components connected to the node that a new stack member is now connected
148  * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
149  */
150  virtual void NotifyNewAggregate ();
151 private:
152  Ptr<Node> m_node;
153  Ipv4EndPointDemux *m_endPoints;
154  Ipv6EndPointDemux *m_endPoints6;
155  UdpL4Protocol (const UdpL4Protocol &o);
156  UdpL4Protocol &operator = (const UdpL4Protocol &o);
157  std::vector<Ptr<UdpSocketImpl> > m_sockets;
159  IpL4Protocol::DownTargetCallback6 m_downTarget6;
160 };
161 
162 } // namespace ns3
163 
164 #endif /* UDP_L4_PROTOCOL_H */
Packet header for IPv6.
Definition: ipv6-header.h:33
Ptr< Socket > CreateSocket(void)
virtual void DoDispose(void)
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
Demultiplexes packets to various transport layer endpoints.
virtual int GetProtocolNumber(void) const
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > interface)
Receive a packet up the protocol stack.
virtual void ReceiveIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8])
Receive an ICMP packet.
L4 Protocol abstract base class.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual void NotifyNewAggregate()
Implementation of the UDP protocol.
Demultiplexor for end points.
An IPv6 end point, four tuples identification.
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport)
Send a packet via UDP.
a unique identifier for an interface.
Definition: type-id.h:44
A representation of an internet endpoint/connection.