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
|
|
|
|
|
|
2007-03-18 14:06:51 -07:00
|
|
|
#include "ns3/composite-trace-resolver.h"
|
|
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
#include "net-device-list.h"
|
|
|
|
|
#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"
|
2007-02-12 19:28:48 +01:00
|
|
|
#include "ipv4-loopback-interface.h"
|
2007-02-08 15:37:48 +01:00
|
|
|
|
|
|
|
|
namespace ns3 {
|
|
|
|
|
|
|
|
|
|
InternetNode::InternetNode()
|
|
|
|
|
{
|
|
|
|
|
// Instantiate the capabilities
|
|
|
|
|
m_netDevices = new NetDeviceList();
|
2007-02-12 13:06:05 +01:00
|
|
|
m_l3Demux = new L3Demux(this);
|
|
|
|
|
m_ipv4L4Demux = new Ipv4L4Demux(this);
|
2007-02-17 09:28:02 +01:00
|
|
|
m_l3Demux->Insert (Ipv4 (this));
|
2007-02-17 09:35:50 +01:00
|
|
|
m_l3Demux->Insert (Arp (this));
|
2007-02-17 09:42:30 +01:00
|
|
|
m_ipv4L4Demux->Insert (Udp (this));
|
2007-02-12 19:28:48 +01:00
|
|
|
SetupLoopback ();
|
2007-02-12 15:55:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InternetNode::InternetNode (InternetNode const &o)
|
|
|
|
|
{
|
|
|
|
|
m_netDevices = new NetDeviceList ();
|
|
|
|
|
m_l3Demux = o.m_l3Demux->Copy (this);
|
|
|
|
|
m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
|
2007-02-26 10:28:57 +01:00
|
|
|
SetupLoopback ();
|
|
|
|
|
}
|
|
|
|
|
InternetNode const &
|
|
|
|
|
InternetNode::operator = (InternetNode const &o)
|
|
|
|
|
{
|
|
|
|
|
delete m_netDevices;
|
|
|
|
|
delete m_l3Demux;
|
|
|
|
|
delete m_ipv4L4Demux;
|
|
|
|
|
m_netDevices = new NetDeviceList ();
|
|
|
|
|
m_l3Demux = o.m_l3Demux->Copy (this);
|
|
|
|
|
m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
|
|
|
|
|
SetupLoopback ();
|
|
|
|
|
return *this;
|
2007-02-12 19:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
2007-02-12 19:32:42 +01:00
|
|
|
InternetNode::~InternetNode ()
|
|
|
|
|
{
|
|
|
|
|
delete m_netDevices;
|
|
|
|
|
delete m_l3Demux;
|
|
|
|
|
delete m_ipv4L4Demux;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-20 22:55:09 -08:00
|
|
|
void
|
|
|
|
|
InternetNode::SetName (std::string name)
|
|
|
|
|
{
|
|
|
|
|
m_name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 19:28:48 +01:00
|
|
|
void
|
|
|
|
|
InternetNode::SetupLoopback (void)
|
|
|
|
|
{
|
|
|
|
|
Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this);
|
|
|
|
|
interface->SetAddress (Ipv4Address::GetLoopback ());
|
|
|
|
|
interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
|
2007-02-17 09:28:02 +01:00
|
|
|
uint32_t index = GetIpv4 ()->AddInterface (interface);
|
|
|
|
|
GetIpv4 ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index);
|
2007-02-12 19:58:10 +01:00
|
|
|
interface->SetUp ();
|
2007-02-08 15:37:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy this node
|
|
|
|
|
InternetNode*
|
|
|
|
|
InternetNode::Copy() const
|
|
|
|
|
{
|
2007-02-12 15:55:49 +01:00
|
|
|
InternetNode *copy = new InternetNode (*this);
|
|
|
|
|
return copy;
|
2007-02-08 15:37:48 +01:00
|
|
|
}
|
|
|
|
|
|
2007-03-18 14:06:51 -07:00
|
|
|
TraceResolver *
|
|
|
|
|
InternetNode::CreateTraceResolver (TraceContext const &context)
|
|
|
|
|
{
|
|
|
|
|
CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
|
|
|
|
|
resolver->Add ("ipv4",
|
|
|
|
|
MakeCallback (&Ipv4::CreateTraceResolver, GetIpv4 ()),
|
|
|
|
|
InternetNode::IPV4);
|
|
|
|
|
resolver->Add ("arp",
|
|
|
|
|
MakeCallback (&Arp::CreateTraceResolver, GetArp ()),
|
|
|
|
|
InternetNode::ARP);
|
|
|
|
|
resolver->Add ("udp",
|
|
|
|
|
MakeCallback (&Udp::CreateTraceResolver, GetUdp ()),
|
|
|
|
|
InternetNode::UDP);
|
|
|
|
|
return resolver;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
|
|
|
|
|
NetDeviceList*
|
2007-03-15 13:26:30 +01:00
|
|
|
InternetNode::GetNetDeviceList() const
|
2007-02-08 15:37:48 +01:00
|
|
|
{
|
|
|
|
|
return m_netDevices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
L3Demux*
|
|
|
|
|
InternetNode::GetL3Demux() const
|
|
|
|
|
{
|
|
|
|
|
return m_l3Demux;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ipv4L4Demux*
|
|
|
|
|
InternetNode::GetIpv4L4Demux() const
|
|
|
|
|
{
|
|
|
|
|
return m_ipv4L4Demux;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 19:28:48 +01:00
|
|
|
Ipv4 *
|
|
|
|
|
InternetNode::GetIpv4 (void) const
|
|
|
|
|
{
|
2007-02-17 09:28:02 +01:00
|
|
|
return static_cast<Ipv4*> (m_l3Demux->Lookup (Ipv4::PROT_NUMBER));
|
2007-02-12 19:28:48 +01:00
|
|
|
}
|
|
|
|
|
Udp *
|
|
|
|
|
InternetNode::GetUdp (void) const
|
|
|
|
|
{
|
2007-02-17 09:42:30 +01:00
|
|
|
return static_cast<Udp*> (m_ipv4L4Demux->Lookup (Udp::PROT_NUMBER));
|
2007-02-12 19:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Arp *
|
|
|
|
|
InternetNode::GetArp (void) const
|
|
|
|
|
{
|
2007-02-17 09:35:50 +01:00
|
|
|
return static_cast<Arp*> (m_l3Demux->Lookup (Arp::PROT_NUMBER));
|
2007-02-12 19:28:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-08 15:37:48 +01:00
|
|
|
}//namespace ns3
|