Files
ns-3-dev/src/node/ipv4-routing-protocol.h
T

97 lines
4.0 KiB
C++

/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef IPV4_ROUTING_PROTOCOL_H
#define IPV4_ROUTING_PROTOCOL_H
#include "ns3/packet.h"
#include "ns3/callback.h"
#include "ns3/object.h"
#include "ns3/socket.h"
#include "ipv4-header.h"
namespace ns3 {
class Ipv4MulticastRoute;
class Ipv4Route;
class NetDevice;
/**
* \ingroup ipv4
* Abstract base class for Ipv4 routing protocols. Defines two
* virtual functions for packet routing and forwarding. The first,
* RouteOutput(), is used for locally originated packets, and the second,
* RouteInput(), is used for forwarding and/or delivering received packets.
* Also defines the signatures of four callbacks used in RouteInput().
*
*/
class Ipv4RoutingProtocol : public Object
{
public:
static TypeId GetTypeId (void);
typedef Callback<void, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
typedef Callback<void, Ptr<Ipv4MulticastRoute>, Ptr<const Packet>, const Ipv4Header &> MulticastForwardCallback;
typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > LocalDeliverCallback;
typedef Callback<void, Ptr<const Packet>, const Ipv4Header &> ErrorCallback;
/**
* \brief Query routing cache for an existing route, for an outbound packet
*
* This lookup is used by transport protocols. It does not cause any
* packet to be forwarded, and is synchronous. Can be used for
* multicast or unicast. The Linux equivalent is ip_route_output()
*
* \param header input parameter (used to form key to search for the route)
* \param oif Output interface index. May be zero, or may be bound via
* socket options to a particular output interface.
* \param sockerr Output parameter; socket errno
*
* \returns a code that indicates what happened in the lookup
*/
virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr) = 0;
/**
* \brief Route an input packet (to be forwarded or locally delivered)
*
* This lookup is used in the forwarding process. The packet is
* handed over to the Ipv4RoutingProtocol, and will get forwarded onward
* by one of the callbacks. The Linux equivalent is ip_route_input().
* There are four valid outcomes, and a matching callbacks to handle each.
*
* \param p received packet
* \param header input parameter used to form a search key for a route
* \param idev Pointer to ingress network device
* \param ucb Callback for the case in which the packet is to be forwarded
* as unicast
* \param mcb Callback for the case in which the packet is to be forwarded
* as multicast
* \param lcb Callback for the case in which the packet is to be locally
* delivered
* \param ecb Callback to call if there is an error in forwarding
* \returns true if the Ipv4RoutingProtocol takes responsibility for
* forwarding or delivering the packet, false otherwise
*/
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
LocalDeliverCallback lcb, ErrorCallback ecb) = 0;
};
} //namespace ns3
#endif /* IPV4_ROUTING_PROTOCOL_H */