diff --git a/SConstruct b/SConstruct index 1982bb3de..810826eaf 100644 --- a/SConstruct +++ b/SConstruct @@ -141,7 +141,7 @@ common.add_inst_headers([ node = build.Ns3Module ('node', 'src/node') ns3.add (node) -node.add_deps (['core']) +node.add_deps (['core', 'common', 'simulator']) node.add_sources ([ 'node.cc', 'l3-demux.cc', @@ -170,7 +170,11 @@ node.add_sources ([ 'arp-ipv4-interface.cc', 'arp.cc', 'p2p-net-device.cc', - 'p2p-channel.cc' + 'p2p-channel.cc', + 'ipv4-loopback-interface.cc', + 'llc-snap-header.cc', + 'header-utils.cc', + 'net-device-list.cc' ]) node.add_headers ([ 'ipv4-address.h', @@ -188,20 +192,23 @@ node.add_headers ([ 'arp-ipv4-interface.h', 'arp.h', 'p2p-net-device.h', - 'p2p-channel.h' - ]) -node.add_inst_headers ([ - 'node.h', + 'p2p-channel.h', + 'ipv4-loopback-interface.h', 'l3-demux.h', 'l3-protocol.h', 'ipv4-l4-demux.h', 'net-device-list.h', - 'internet-node.h', 'net-device.h', 'mac-address.h', 'ipv4-route.h', 'ipv4-interface.h', 'udp-socket.h', + 'llc-snap-header.h', + 'header-utils.h', + ]) +node.add_inst_headers ([ + 'node.h', + 'internet-node.h', ]) @@ -268,5 +275,12 @@ ns3.add(sample_test) sample_test.add_dep('core') sample_test.add_source('main-test.cc') +sample_simple = build.Ns3Module('sample-simple', 'samples') +sample_simple.set_executable() +ns3.add(sample_simple) +sample_simple.add_deps(['core', 'simulator', 'node']) +sample_simple.add_source('main-simple.cc') + + ns3.generate_dependencies() diff --git a/samples/main-simple.cc b/samples/main-simple.cc new file mode 100644 index 000000000..42d8bd249 --- /dev/null +++ b/samples/main-simple.cc @@ -0,0 +1,17 @@ +#include "ns3/internet-node.h" +#include "ns3/simulator.h" + +using namespace ns3; + +int main (int argc, char *argv[]) +{ + InternetNode *a = new InternetNode (); + + Simulator::Run (); + + Simulator::Destroy (); + + delete a; + + return 0; +} diff --git a/src/node/header-utils.cc b/src/node/header-utils.cc index 9d8e1203e..f918c15a5 100644 --- a/src/node/header-utils.cc +++ b/src/node/header-utils.cc @@ -18,7 +18,7 @@ * * Author: Mathieu Lacage */ -#include "chunk-utils.h" +#include "header-utils.h" namespace ns3 { @@ -30,7 +30,7 @@ void WriteTo (Buffer::Iterator &i, MacAddress ad) { uint8_t mac[MacAddress::MAX_LEN]; ad.Peek (mac); - i.Write (mac, ad.GetLen ()); + i.Write (mac, ad.GetLength ()); } void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad) diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index 6fa45227b..540118ba0 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -31,6 +31,7 @@ #include "arp.h" #include "udp-ipv4-l4-protocol.h" #include "arp-l3-protocol.h" +#include "ipv4-loopback-interface.h" namespace ns3 { @@ -46,6 +47,7 @@ InternetNode::InternetNode() m_l3Demux->Insert (Ipv4L3Protocol (this)); m_l3Demux->Insert (ArpL3Protocol (this)); m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this)); + SetupLoopback (); } InternetNode::InternetNode (InternetNode const &o) @@ -56,6 +58,17 @@ InternetNode::InternetNode (InternetNode const &o) m_udp = o.m_udp->Copy (this); m_ipv4 = o.m_ipv4->Copy (this); m_arp = o.m_arp->Copy (this); + SetupLoopback (); +} + +void +InternetNode::SetupLoopback (void) +{ + Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this); + interface->SetAddress (Ipv4Address::GetLoopback ()); + interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); + uint32_t index = m_ipv4->AddInterface (interface); + m_ipv4->AddHostRouteTo (Ipv4Address::GetLoopback (), index); } // Copy this node @@ -85,4 +98,22 @@ InternetNode::GetIpv4L4Demux() const return m_ipv4L4Demux; } +Ipv4 * +InternetNode::GetIpv4 (void) const +{ + return m_ipv4; +} +Udp * +InternetNode::GetUdp (void) const +{ + return m_udp; +} + +Arp * +InternetNode::GetArp (void) const +{ + return m_arp; +} + + }//namespace ns3 diff --git a/src/node/internet-node.h b/src/node/internet-node.h index c1827962d..12d74666a 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -46,6 +46,7 @@ public: virtual Arp * GetArp (void) const; private: + void SetupLoopback (void); // Capabilities NetDeviceList* m_netDevices; L3Demux* m_l3Demux; diff --git a/src/node/net-device-list.cc b/src/node/net-device-list.cc new file mode 100644 index 000000000..0d4e6d3e5 --- /dev/null +++ b/src/node/net-device-list.cc @@ -0,0 +1,50 @@ +// -*- 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 +// +// Manages the list of network device interfaces associated with a node. +// George F. Riley, Georgia Tech, Spring 2007 + +#include "net-device-list.h" + +namespace ns3 { + +NetDeviceList::NetDeviceList() +{} +NetDeviceList::~NetDeviceList() +{ + // XXX shall I delete each NetDevice ? +} +void +NetDeviceList::Add(NetDevice *device) +{ + m_netdevices.push_back (device); +} +NetDeviceList::Iterator +NetDeviceList::Begin () const +{ + return m_netdevices.begin (); +} +NetDeviceList::Iterator +NetDeviceList::End () const +{ + return m_netdevices.end (); +} + +}//namespace ns3 diff --git a/src/node/net-device-list.h b/src/node/net-device-list.h index 7adf4fb1e..7a1583893 100644 --- a/src/node/net-device-list.h +++ b/src/node/net-device-list.h @@ -1,4 +1,4 @@ -// -*- Mode:NS3 -*- +// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- // // Copyright (c) 2006 Georgia Tech Research Corporation // All rights reserved. @@ -32,16 +32,16 @@ class NetDevice; class NetDeviceList { public: - typedef std::vector::iterator Iterator; + typedef std::vector::const_iterator Iterator; NetDeviceList(); ~NetDeviceList(); // Manage the list - NetDevice* Add(const NetDevice&); // Add a new netdevice + void Add(NetDevice *device); NetDeviceList::Iterator Begin () const; NetDeviceList::Iterator End () const; public: - typedef std::vector::iterator NetDevices_t; + typedef std::vector NetDevices_t; NetDevices_t m_netdevices; }; diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 5c0f6a250..f351b1065 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -30,7 +30,7 @@ namespace ns3 { -NetDevice::NetDevice(Node& node, const MacAddress& addr) : +NetDevice::NetDevice(Node *node, const MacAddress& addr) : m_node (node), m_name(""), m_ifIndex (0), @@ -40,8 +40,7 @@ NetDevice::NetDevice(Node& node, const MacAddress& addr) : m_isBroadcast (false), m_isMulticast (false), m_isPointToPoint (false) -{ -} +{} MacAddress NetDevice::GetAddress (void) const @@ -172,9 +171,9 @@ NetDevice::ForwardUp (Packet& packet) LlcSnapHeader llc; packet.Peek (llc); packet.Remove (llc); - if (GetNode().GetL3Demux() != 0) + if (GetNode()->GetL3Demux() != 0) { - L3Protocol *target = GetNode().GetL3Demux()->Lookup(llc.GetType ()); + L3Protocol *target = GetNode()->GetL3Demux()->Lookup(llc.GetType ()); if (target != 0) { target->Receive(packet, *this); @@ -204,7 +203,7 @@ NetDevice::NotifyLinkDown (void) } } -Node& +Node * NetDevice::GetNode (void) const { return m_node; diff --git a/src/node/net-device.h b/src/node/net-device.h index 34ffb8c3b..ee05f972d 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -56,7 +56,7 @@ class NetDevice { /** * \param node base class node pointer of device's node */ - NetDevice(Node& node, const MacAddress& addr); + NetDevice(Node* node, const MacAddress& addr); virtual ~NetDevice() {} /** * \return the current MacAddress of this interface. @@ -177,7 +177,7 @@ class NetDevice { * base class to print the nodeid for example, it can invoke * this method. */ - Node& GetNode (void) const; + Node* GetNode (void) const; /** * \param p packet sent from below up to Network Device @@ -204,7 +204,7 @@ class NetDevice { * MUST override this method. */ virtual bool SendTo (Packet& p, const MacAddress& dest) = 0; - Node& m_node; + Node* m_node; std::string m_name; uint16_t m_ifIndex; MacAddress m_address; diff --git a/src/node/p2p-channel.cc b/src/node/p2p-channel.cc index 04eec9c90..57236b56b 100644 --- a/src/node/p2p-channel.cc +++ b/src/node/p2p-channel.cc @@ -37,8 +37,11 @@ P2PChannel::P2PChannel(const Time& delay, double maxRate) { } +P2PChannel::~P2PChannel () +{} + // Channels create compatible net devices -P2PNetDevice* P2PChannel::CreateNetDevice(Node &node, MacAddress address) +P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address) { // Create a new point-to-point network device P2PNetDevice* nd = new P2PNetDevice(node, address); diff --git a/src/node/p2p-channel.h b/src/node/p2p-channel.h index 3e04d4617..1b5d2e303 100644 --- a/src/node/p2p-channel.h +++ b/src/node/p2p-channel.h @@ -40,7 +40,7 @@ public: P2PChannel(const Time& delay, double maxRate /* bits/s */); ~P2PChannel(); - P2PNetDevice* CreateNetDevice(Node &node, MacAddress address); + P2PNetDevice* CreateNetDevice(Node *node, MacAddress address); void RemoveNetDevice (NetDevice *device); void Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */); private: diff --git a/src/node/p2p-net-device.cc b/src/node/p2p-net-device.cc index f9733cbea..e4e379205 100644 --- a/src/node/p2p-net-device.cc +++ b/src/node/p2p-net-device.cc @@ -27,7 +27,7 @@ namespace ns3 { -P2PNetDevice::P2PNetDevice (Node &node, MacAddress const &addr) +P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr) : NetDevice (node, addr) {} diff --git a/src/node/p2p-net-device.h b/src/node/p2p-net-device.h index 21b4d0557..e636028e7 100644 --- a/src/node/p2p-net-device.h +++ b/src/node/p2p-net-device.h @@ -33,7 +33,7 @@ class P2PChannel; class P2PNetDevice : public NetDevice { public: - P2PNetDevice(Node &node, MacAddress const &addr); + P2PNetDevice(Node *node, MacAddress const &addr); virtual ~P2PNetDevice(); void SetRate (double Rate);