Files
unison/src/node/internet-node.cc

170 lines
4.0 KiB
C++
Raw Normal View History

2007-02-08 15:37:48 +01:00
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
//
// Copyright (c) 2006 Georgia Tech Research Corporation
// All rights reserved.
//
// 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
//
// Author: George F. Riley<riley@ece.gatech.edu>
//
// Implementation of the InternetNode class for ns3.
// George F. Riley, Georgia Tech, Fall 2006
#include "ns3/composite-trace-resolver.h"
2007-03-27 21:48:22 -07:00
#include "application-list.h"
2007-02-08 15:37:48 +01:00
#include "l3-demux.h"
#include "ipv4-l4-demux.h"
#include "internet-node.h"
2007-02-10 11:29:44 +01:00
#include "udp.h"
#include "ipv4.h"
2007-02-12 15:55:49 +01:00
#include "arp.h"
#include "net-device.h"
2007-02-08 15:37:48 +01:00
namespace ns3 {
2007-02-08 15:37:48 +01:00
InternetNode::InternetNode()
{
// Instantiate the capabilities
2007-05-02 15:14:27 +02:00
m_applicationList = new ApplicationList(this);
2007-05-03 12:33:08 +02:00
L3Demux *l3Demux = new L3Demux(this);
2007-05-03 12:46:50 +02:00
Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
2007-05-03 12:33:08 +02:00
NsUnknown::AddInterface (l3Demux);
2007-05-03 12:46:50 +02:00
NsUnknown::AddInterface (ipv4L4Demux);
Ipv4 *ipv4 = new Ipv4 (this);
Arp *arp = new Arp (this);
Udp *udp = new Udp (this);
2007-05-03 12:33:08 +02:00
l3Demux->Insert (ipv4);
l3Demux->Insert (arp);
2007-05-03 12:46:50 +02:00
ipv4L4Demux->Insert (udp);
2007-05-03 12:33:08 +02:00
l3Demux->Unref ();
2007-05-03 12:46:50 +02:00
ipv4L4Demux->Unref ();
ipv4->Unref ();
arp->Unref ();
udp->Unref ();
2007-02-12 15:55:49 +01:00
}
InternetNode::~InternetNode ()
2007-05-03 12:33:08 +02:00
{}
void
InternetNode::SetName (std::string name)
{
m_name = name;
}
TraceResolver *
InternetNode::CreateTraceResolver (TraceContext const &context)
{
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
Ipv4 *ipv4 = GetIpv4 ();
resolver->Add ("ipv4",
MakeCallback (&Ipv4::CreateTraceResolver, ipv4),
InternetNode::IPV4);
ipv4->Unref ();
Arp *arp = GetArp ();
resolver->Add ("arp",
MakeCallback (&Arp::CreateTraceResolver, arp),
InternetNode::ARP);
arp->Unref ();
Udp *udp = GetUdp ();
resolver->Add ("udp",
MakeCallback (&Udp::CreateTraceResolver, udp),
InternetNode::UDP);
udp->Unref ();
return resolver;
}
2007-05-03 12:33:08 +02:00
void
InternetNode::DoDispose()
2007-05-02 09:10:19 +02:00
{
if (m_applicationList != 0)
{
m_applicationList->Dispose ();
m_applicationList->Unref ();
m_applicationList = 0;
}
2007-05-02 22:32:25 +02:00
2007-05-03 12:33:08 +02:00
Node::DoDispose ();
2007-05-02 09:10:19 +02:00
}
2007-02-08 15:37:48 +01:00
2007-03-27 21:48:22 -07:00
ApplicationList*
InternetNode::GetApplicationList() const
{
m_applicationList->Ref ();
2007-03-27 21:48:22 -07:00
return m_applicationList;
}
2007-02-08 15:37:48 +01:00
2007-02-12 19:28:48 +01:00
Ipv4 *
InternetNode::GetIpv4 (void) const
{
2007-05-03 12:33:08 +02:00
L3Demux *l3Demux = QueryInterface<L3Demux> (L3Demux::iid);
Ipv4 *ipv4 = static_cast<Ipv4*> (l3Demux->PeekProtocol (Ipv4::PROT_NUMBER));
l3Demux->Unref ();
ipv4->Ref ();
return ipv4;
2007-02-12 19:28:48 +01:00
}
Udp *
InternetNode::GetUdp (void) const
{
2007-05-03 12:46:50 +02:00
Ipv4L4Demux *demux = QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
Udp *udp = static_cast<Udp*> (demux->PeekProtocol (Udp::PROT_NUMBER));
demux->Unref ();
udp->Ref ();
return udp;
2007-02-12 19:28:48 +01:00
}
Arp *
InternetNode::GetArp (void) const
{
2007-05-03 12:33:08 +02:00
L3Demux *l3Demux = QueryInterface<L3Demux> (L3Demux::iid);
Arp *arp = static_cast<Arp*> (l3Demux->PeekProtocol (Arp::PROT_NUMBER));
l3Demux->Unref ();
arp->Ref ();
return arp;
2007-02-12 19:28:48 +01:00
}
void
InternetNode::DoAddDevice (NetDevice *device) const
{
device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
}
bool
InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
{
2007-05-03 12:33:08 +02:00
L3Demux *demux = QueryInterface<L3Demux> (L3Demux::iid);
L3Protocol *target = demux->PeekProtocol (protocolNumber);
demux->Unref ();
if (target != 0)
{
Packet packet = p;
target->Receive(packet, device);
return true;
}
return false;
}
2007-02-12 19:28:48 +01:00
2007-02-08 15:37:48 +01:00
}//namespace ns3