aodv::RoutingProtocol just added
This commit is contained in:
194
src/routing/aodv/aodv-routing-protocol.cc
Normal file
194
src/routing/aodv/aodv-routing-protocol.cc
Normal file
@@ -0,0 +1,194 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 1997, 1998 Carnegie Mellon University.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Authors: The AODV code developed by the CMU/MONARCH group was optimized and
|
||||
* tuned by Samir Das and Mahesh Marina, University of Cincinnati.
|
||||
* The work was partially done in Sun Microsystems.
|
||||
*
|
||||
* Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru>
|
||||
*/
|
||||
#include "aodv-routing-protocol.h"
|
||||
#include "ns3/socket-factory.h"
|
||||
#include "ns3/udp-socket-factory.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/inet-socket-address.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
#include "ns3/ipv4-route.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/enum.h"
|
||||
#include "ns3/trace-source-accessor.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
|
||||
/// UDP Port for AODV control traffic
|
||||
#define AODV_PORT 654
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("AodvRoutingProtocol");
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
|
||||
|
||||
RoutingProtocol::RoutingProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
TypeId
|
||||
RoutingProtocol::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::aodv::RoutingProtocol")
|
||||
.SetParent<Ipv4RoutingProtocol> ()
|
||||
.AddConstructor<RoutingProtocol> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
RoutingProtocol::~RoutingProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::DoDispose ()
|
||||
{
|
||||
m_ipv4 = 0;
|
||||
for (std::map< Ptr<Socket>, Ipv4Address >::iterator iter = m_socketAddresses.begin ();
|
||||
iter != m_socketAddresses.end (); iter++)
|
||||
{
|
||||
iter->first->Close ();
|
||||
}
|
||||
m_socketAddresses.clear ();
|
||||
Ipv4RoutingProtocol::DoDispose ();
|
||||
}
|
||||
|
||||
Ptr<Ipv4Route>
|
||||
RoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
|
||||
{
|
||||
Ptr<Ipv4Route> rtentry;
|
||||
sockerr = Socket::ERROR_NOROUTETOHOST;
|
||||
// TODO resolve route
|
||||
return rtentry;
|
||||
}
|
||||
|
||||
bool
|
||||
RoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
|
||||
{
|
||||
NS_ASSERT (ipv4 != 0);
|
||||
NS_ASSERT (m_ipv4 == 0);
|
||||
/*
|
||||
m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
|
||||
*/
|
||||
|
||||
m_ipv4 = ipv4;
|
||||
Simulator::ScheduleNow (&RoutingProtocol::Start, this);
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::Start ()
|
||||
{
|
||||
// Open UDP sockets for control traffic on each IP interface
|
||||
const Ipv4Address loopback ("127.0.0.1");
|
||||
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
|
||||
{
|
||||
Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
|
||||
if (addr == loopback)
|
||||
continue;
|
||||
|
||||
// Create a socket to listen only on this interface
|
||||
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),
|
||||
UdpSocketFactory::GetTypeId());
|
||||
socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvAodv, this));
|
||||
if (socket->Bind (InetSocketAddress (addr, AODV_PORT)))
|
||||
{
|
||||
NS_FATAL_ERROR ("Failed to bind() AODV receive socket");
|
||||
}
|
||||
socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), AODV_PORT));
|
||||
m_socketAddresses.insert(std::make_pair(socket, addr));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::NotifyInterfaceUp (uint32_t interface)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::NotifyInterfaceDown (uint32_t interface)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvAodv (Ptr<Socket> socket)
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
Address sourceAddress;
|
||||
packet = socket->RecvFrom (sourceAddress);
|
||||
|
||||
InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
|
||||
Ipv4Address senderIfaceAddr = inetSourceAddr.GetIpv4 ();
|
||||
Ipv4Address receiverIfaceAddr = m_socketAddresses[socket];
|
||||
|
||||
NS_ASSERT (receiverIfaceAddr != Ipv4Address ());
|
||||
NS_LOG_DEBUG ("AODV node " << this << " received a AODV packet from " << senderIfaceAddr << " to " << receiverIfaceAddr);
|
||||
NS_ASSERT (inetSourceAddr.GetPort () == AODV_PORT);
|
||||
|
||||
// TODO check packet type and call RecvSmth
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvRequest (Ptr<Packet> p)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvReply (Ptr<Packet> p)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvError (Ptr<Packet> p)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
}}
|
||||
88
src/routing/aodv/aodv-routing-protocol.h
Normal file
88
src/routing/aodv/aodv-routing-protocol.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 1997, 1998 Carnegie Mellon University.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Authors: The AODV code developed by the CMU/MONARCH group was optimized and
|
||||
* tuned by Samir Das and Mahesh Marina, University of Cincinnati.
|
||||
* The work was partially done in Sun Microsystems.
|
||||
*
|
||||
* Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru>
|
||||
*/
|
||||
#ifndef AODVROUTINGPROTOCOL_H_
|
||||
#define AODVROUTINGPROTOCOL_H_
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/timer.h"
|
||||
#include "ns3/ipv4.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
#include <map>
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
|
||||
/**
|
||||
* \ingroup aodv
|
||||
* \brief AODV routing protocol
|
||||
*/
|
||||
class RoutingProtocol : public Ipv4RoutingProtocol
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
RoutingProtocol();
|
||||
virtual ~RoutingProtocol();
|
||||
virtual void DoDispose ();
|
||||
|
||||
///\name From Ipv4RoutingProtocol
|
||||
//\{
|
||||
Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
|
||||
bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb);
|
||||
virtual void NotifyInterfaceUp (uint32_t interface);
|
||||
virtual void NotifyInterfaceDown (uint32_t interface);
|
||||
virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
|
||||
virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
|
||||
virtual void SetIpv4 (Ptr<Ipv4> ipv4);
|
||||
//\}
|
||||
|
||||
private:
|
||||
/// IP protocol
|
||||
Ptr<Ipv4> m_ipv4;
|
||||
/// UDP socket per each IP interface, map socket -> iface
|
||||
std::map< Ptr<Socket>, Ipv4Address > m_socketAddresses;
|
||||
|
||||
private:
|
||||
/// Start protocol operation
|
||||
void Start ();
|
||||
|
||||
/// Receive and process control packet
|
||||
void RecvAodv (Ptr<Socket> s);
|
||||
/// Receive RREQ
|
||||
void RecvRequest (Ptr<Packet> p);
|
||||
/// Receive RREP
|
||||
void RecvReply (Ptr<Packet> p);
|
||||
/// Receive RERR
|
||||
void RecvError (Ptr<Packet> p);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* AODVROUTINGPROTOCOL_H_ */
|
||||
@@ -7,13 +7,12 @@ def build(bld):
|
||||
'aodv-rtable.cc',
|
||||
'aodv-rqueue.cc',
|
||||
'aodv-packet.cc',
|
||||
'aodv-routing-protocol.cc',
|
||||
]
|
||||
|
||||
headers = bld.new_task_gen('ns3header')
|
||||
headers.module = 'aodv'
|
||||
headers.source = [
|
||||
'aodv-rtable.h',
|
||||
'aodv-rqueue.h',
|
||||
'aodv-packet.h',
|
||||
'aodv-routing-protocol.h',
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user