diff --git a/SConstruct b/SConstruct index ff05f4afc..1f243a4a5 100644 --- a/SConstruct +++ b/SConstruct @@ -239,6 +239,7 @@ node.add_headers ([ 'header-utils.h', 'protocol.h', 'queue.h', + 'arp-ipv4-interface.h', ]) node.add_inst_headers ([ 'node.h', @@ -247,7 +248,6 @@ node.add_inst_headers ([ 'ipv4-address.h', 'net-device.h', 'net-device-list.h', - 'arp-ipv4-interface.h', 'ipv4-interface.h', 'mac-address.h', 'ipv4.h', @@ -275,7 +275,6 @@ p2p.add_sources ([ 'p2p-net-device.cc', 'p2p-channel.cc', 'p2p-topology.cc', - 'p2p-ipv4-interface.cc', ]) p2p.add_headers ([ 'propagator.h', @@ -284,7 +283,6 @@ p2p.add_inst_headers ([ 'p2p-net-device.h', 'p2p-channel.h', 'p2p-topology.h', - 'p2p-ipv4-interface.h', ]) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index d005b12e8..657e2a890 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -54,7 +54,6 @@ #include "ns3/p2p-net-device.h" #include "ns3/mac-address.h" #include "ns3/ipv4-address.h" -#include "ns3/arp-ipv4-interface.h" #include "ns3/ipv4.h" #include "ns3/datagram-socket.h" #include "ns3/ipv4-route.h" diff --git a/samples/main-p2p-net-device-if.cc b/samples/main-p2p-net-device-if.cc index 5dbc3a7d5..4fa3c6731 100644 --- a/samples/main-p2p-net-device-if.cc +++ b/samples/main-p2p-net-device-if.cc @@ -22,12 +22,10 @@ #include "ns3/debug.h" #include "ns3/internet-node.h" #include "ns3/packet.h" -#include "ns3/arp-ipv4-interface.h" #include "ns3/ipv4-address.h" #include "ns3/p2p-channel.h" #include "ns3/p2p-net-device.h" #include "ns3/drop-tail.h" -#include "ns3/arp-ipv4-interface.h" #include "ns3/ipv4.h" #include "ns3/trace-context.h" #include "ns3/datagram-socket.h" @@ -161,45 +159,43 @@ int main (int argc, char *argv[]) // vector of Ipv4Interfaces (keyed off of ifIndex) NS_DEBUG_UNCOND("Adding ARP Interface to InternetNode a"); - ArpIpv4Interface* arpipv4interfacep = new ArpIpv4Interface(&a, &neta); - uint32_t indexA; - indexA = (&a)->GetIpv4 ()->AddInterface (arpipv4interfacep); + Ipv4 *ipa = (&a)->GetIpv4 (); + uint32_t indexA = ipa->AddInterface (&neta); NS_DEBUG_UNCOND("Adding Interface " << indexA); // iii) give the interface an IP address NS_DEBUG_UNCOND("Giving IP address to ARP Interface"); - arpipv4interfacep->SetAddress(Ipv4Address("10.1.1.1")); - arpipv4interfacep->SetNetworkMask(Ipv4Mask("255.255.255.0")); + ipa->SetAddress(indexA, Ipv4Address("10.1.1.1")); + ipa->SetNetworkMask(indexA, Ipv4Mask("255.255.255.0")); // iv) set the interface's state to "UP" NS_DEBUG_UNCOND("Setting ARP interface to UP"); - arpipv4interfacep->SetUp(); + ipa->SetUp(indexA); - a.GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + ipa->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); NS_DEBUG_UNCOND("Adding ARP Interface to InternetNode b"); - ArpIpv4Interface* arpipv4interfacepb = new ArpIpv4Interface(&b, &netb); - uint32_t indexB; - indexB = (&b)->GetIpv4 ()->AddInterface (arpipv4interfacepb); + Ipv4 *ipb = (&b)->GetIpv4 (); + uint32_t indexB = ipb->AddInterface (&netb); NS_DEBUG_UNCOND("Adding Interface " << indexB); // iii) give the interface an IP address NS_DEBUG_UNCOND("Giving IP address to ARP Interface"); - arpipv4interfacepb->SetAddress(Ipv4Address("10.1.1.2")); - arpipv4interfacepb->SetNetworkMask(Ipv4Mask("255.255.255.0")); + ipb->SetAddress(indexB, Ipv4Address("10.1.1.2")); + ipb->SetNetworkMask(indexB, Ipv4Mask("255.255.255.0")); // iv) set the interface's state to "UP" NS_DEBUG_UNCOND("Setting ARP interface to UP"); - arpipv4interfacepb->SetUp(); + ipb->SetUp(indexB); - b.GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.1"), 1); + ipb->SetDefaultRoute (Ipv4Address ("10.1.1.1"), 1); DatagramSocket *source = new DatagramSocket (&a); diff --git a/src/devices/p2p/p2p-ipv4-interface.cc b/src/devices/p2p/p2p-ipv4-interface.cc deleted file mode 100644 index 0bf81288a..000000000 --- a/src/devices/p2p/p2p-ipv4-interface.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * 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 - * - * Authors: - * Mathieu Lacage , - */ -#include "p2p-ipv4-interface.h" - -#include "ns3/packet.h" -#include "ns3/net-device.h" -#include "ns3/composite-trace-resolver.h" -#include "ns3/ipv4.h" - -namespace ns3 { - -PointToPointIpv4Interface::PointToPointIpv4Interface (Node *node, NetDevice *device) - : Ipv4Interface (device), - m_node (node) -{} -PointToPointIpv4Interface::~PointToPointIpv4Interface () -{} - -void -PointToPointIpv4Interface::SendTo (Packet p, Ipv4Address dest) -{ - GetDevice ()->Send (p, GetDevice ()->GetBroadcast (), Ipv4::PROT_NUMBER); -} - -TraceResolver * -PointToPointIpv4Interface::DoCreateTraceResolver (TraceContext const &context) -{ - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - resolver->Add ("netdevice", - MakeCallback (&NetDevice::CreateTraceResolver, GetDevice ()), - PointToPointIpv4Interface::NETDEVICE); - return resolver; - -} - -}//namespace ns3 diff --git a/src/devices/p2p/p2p-ipv4-interface.h b/src/devices/p2p/p2p-ipv4-interface.h deleted file mode 100644 index 2b0ac0755..000000000 --- a/src/devices/p2p/p2p-ipv4-interface.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * 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 - * - * Authors: - * Mathieu Lacage , - */ -#ifndef POINT_TO_POINT_IPV4_INTERFACE_H -#define POINT_TO_POINT_IPV4_INTERFACE_H - -#include "ns3/ipv4-interface.h" - -namespace ns3 { - -class Node; - -class PointToPointIpv4Interface : public Ipv4Interface -{ - public: - enum TraceType { - NETDEVICE, - }; - PointToPointIpv4Interface (Node *node, NetDevice *device); - virtual ~PointToPointIpv4Interface (); - - private: - virtual void SendTo (Packet p, Ipv4Address dest); - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - Node *m_node; -}; - -}//namespace ns3 - - -#endif /* ARP_IPV4_INTERFACE_H */ diff --git a/src/devices/p2p/p2p-topology.cc b/src/devices/p2p/p2p-topology.cc index 16799f70d..02e116f5a 100644 --- a/src/devices/p2p/p2p-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -33,7 +33,6 @@ #include "ns3/ipv4.h" #include "ns3/net-device-list.h" -#include "p2p-ipv4-interface.h" #include "p2p-channel.h" #include "p2p-net-device.h" #include "p2p-topology.h" @@ -67,27 +66,27 @@ PointToPointTopology::AddPointToPointLink( PointToPointNetDevice* net1 = new PointToPointNetDevice(n1); net1->AddQueue(Queue::Default().Copy()); ndl1->Add(net1); - Ipv4Interface *interf1 = new PointToPointIpv4Interface (n1, net1); - uint32_t index1 = n1->GetIpv4 ()->AddInterface (interf1); + Ipv4 *ip1 = n1->GetIpv4 (); + uint32_t index1 = ip1->AddInterface (net1); net1->Attach (channel); - interf1->SetAddress (addr1); - interf1->SetNetworkMask (netmask); - interf1->SetUp (); + ip1->SetAddress (index1, addr1); + ip1->SetNetworkMask (index1, netmask); + ip1->SetUp (index1); PointToPointNetDevice* net2 = new PointToPointNetDevice(n2); net2->AddQueue(Queue::Default().Copy()); ndl2->Add(net2); - Ipv4Interface *interf2 = new PointToPointIpv4Interface (n2, net2); - uint32_t index2 = n2->GetIpv4 ()->AddInterface (interf2); + Ipv4 *ip2 = n2->GetIpv4 (); + uint32_t index2 = ip2->AddInterface (net2); net2->Attach (channel); - interf2->SetAddress (addr2); - interf2->SetNetworkMask (netmask); - interf2->SetUp (); + ip2->SetAddress (index2, addr2); + ip2->SetNetworkMask (index2, netmask); + ip2->SetUp (index2); - n1->GetIpv4 ()->AddHostRouteTo (addr2, index1); - n2->GetIpv4 ()->AddHostRouteTo (addr1, index2); + ip1->AddHostRouteTo (addr2, index1); + ip2->AddHostRouteTo (addr1, index2); return channel; } diff --git a/src/node/internet-node.cc b/src/node/internet-node.cc index cec474eec..4b4eed166 100644 --- a/src/node/internet-node.cc +++ b/src/node/internet-node.cc @@ -31,7 +31,6 @@ #include "udp.h" #include "ipv4.h" #include "arp.h" -#include "ipv4-loopback-interface.h" namespace ns3 { @@ -52,7 +51,6 @@ InternetNode::InternetNode() m_l3Demux->Insert (Ipv4 (this)); m_l3Demux->Insert (Arp (this)); m_ipv4L4Demux->Insert (Udp (this)); - SetupLoopback (); } InternetNode::InternetNode (InternetNode const &o) @@ -61,7 +59,6 @@ InternetNode::InternetNode (InternetNode const &o) m_applicationList = new ApplicationList(); m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); - SetupLoopback (); } InternetNode const & InternetNode::operator = (InternetNode const &o) @@ -73,7 +70,6 @@ InternetNode::operator = (InternetNode const &o) m_netDevices = new NetDeviceList (); m_l3Demux = o.m_l3Demux->Copy (this); m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this); - SetupLoopback (); return *this; } @@ -91,17 +87,6 @@ InternetNode::SetName (std::string name) m_name = name; } -void -InternetNode::SetupLoopback (void) -{ - Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this); - interface->SetAddress (Ipv4Address::GetLoopback ()); - interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); - uint32_t index = GetIpv4 ()->AddInterface (interface); - GetIpv4 ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index); - interface->SetUp (); -} - // Copy this node InternetNode* InternetNode::Copy() const diff --git a/src/node/internet-node.h b/src/node/internet-node.h index 3ef7b1ed8..5cb31702a 100644 --- a/src/node/internet-node.h +++ b/src/node/internet-node.h @@ -57,7 +57,6 @@ public: void SetName(std::string name); private: - void SetupLoopback (void); // Capabilities NetDeviceList* m_netDevices; ApplicationList* m_applicationList; diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 66b207641..d2eb66d40 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -31,6 +31,8 @@ #include "ipv4-header.h" #include "ipv4-interface.h" #include "ipv4-route.h" +#include "ipv4-loopback-interface.h" +#include "arp-ipv4-interface.h" // the two following headers are needed for Ipv4::ForwardUp #include "node.h" #include "ipv4-l4-demux.h" @@ -48,10 +50,11 @@ Ipv4::Ipv4(Node *node) m_identification (0), m_defaultRoute (0), m_node (node) -{} +{ + SetupLoopback (); +} Ipv4::~Ipv4 () { - // XXX I am not sure we are really allowed to do this here. for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) { delete (*i); @@ -71,6 +74,17 @@ Ipv4::~Ipv4 () delete m_defaultRoute; } +void +Ipv4::SetupLoopback (void) +{ + Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (m_node); + interface->SetAddress (Ipv4Address::GetLoopback ()); + interface->SetNetworkMask (Ipv4Mask::GetLoopback ()); + uint32_t index = AddIpv4Interface (interface); + AddHostRouteTo (Ipv4Address::GetLoopback (), index); + interface->SetUp (); +} + TraceResolver * Ipv4::CreateTraceResolver (TraceContext const &context) { @@ -85,7 +99,7 @@ Ipv4::CreateTraceResolver (TraceContext const &context) } TraceResolver * -Ipv4::InterfacesCreateTraceResolver (TraceContext const &context) +Ipv4::InterfacesCreateTraceResolver (TraceContext const &context) const { ArrayTraceResolver *resolver = new ArrayTraceResolver @@ -286,7 +300,13 @@ Ipv4::RemoveRoute (uint32_t index) uint32_t -Ipv4::AddInterface (Ipv4Interface *interface) +Ipv4::AddInterface (NetDevice *device) +{ + Ipv4Interface *interface = new ArpIpv4Interface (m_node, device); + return AddIpv4Interface (interface); +} +uint32_t +Ipv4::AddIpv4Interface (Ipv4Interface *interface) { uint32_t index = m_nInterfaces; m_interfaces.push_back (interface); @@ -294,7 +314,7 @@ Ipv4::AddInterface (Ipv4Interface *interface) return index; } Ipv4Interface * -Ipv4::GetInterface (uint32_t index) +Ipv4::GetInterface (uint32_t index) const { uint32_t tmp = 0; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++) @@ -308,7 +328,7 @@ Ipv4::GetInterface (uint32_t index) return 0; } uint32_t -Ipv4::GetNInterfaces (void) +Ipv4::GetNInterfaces (void) const { return m_nInterfaces; } @@ -477,4 +497,54 @@ Ipv4::ForwardUp (Packet p, Ipv4Header const&ip) protocol->Receive (p, ip.GetSource (), ip.GetDestination ()); } +void +Ipv4::SetAddress (uint32_t i, Ipv4Address address) +{ + Ipv4Interface *interface = GetInterface (i); + interface->SetAddress (address); +} +void +Ipv4::SetNetworkMask (uint32_t i, Ipv4Mask mask) +{ + Ipv4Interface *interface = GetInterface (i); + interface->SetNetworkMask (mask); +} +Ipv4Mask +Ipv4::GetNetworkMask (uint32_t i) const +{ + Ipv4Interface *interface = GetInterface (i); + return interface->GetNetworkMask (); +} +Ipv4Address +Ipv4::GetAddress (uint32_t i) const +{ + Ipv4Interface *interface = GetInterface (i); + return interface->GetAddress (); +} +uint16_t +Ipv4::GetMtu (uint32_t i) const +{ + Ipv4Interface *interface = GetInterface (i); + return interface->GetMtu (); +} +bool +Ipv4::IsUp (uint32_t i) const +{ + Ipv4Interface *interface = GetInterface (i); + return interface->IsUp (); +} +void +Ipv4::SetUp (uint32_t i) +{ + Ipv4Interface *interface = GetInterface (i); + interface->SetUp (); +} +void +Ipv4::SetDown (uint32_t i) +{ + Ipv4Interface *interface = GetInterface (i); + interface->SetDown (); +} + + }//namespace ns3 diff --git a/src/node/ipv4.h b/src/node/ipv4.h index 548dd2005..63a3272a6 100644 --- a/src/node/ipv4.h +++ b/src/node/ipv4.h @@ -164,16 +164,16 @@ public: * to disable it, you can invoke Ipv4Interface::SetDown which will * make sure that it is never used during packet forwarding. */ - uint32_t AddInterface (Ipv4Interface *interface); + uint32_t AddInterface (NetDevice *device); /** * \param i index of interface to return * \returns the requested interface */ - Ipv4Interface * GetInterface (uint32_t i); + Ipv4Interface * GetInterface (uint32_t i) const; /** * \returns the number of interfaces added by the user. */ - uint32_t GetNInterfaces (void); + uint32_t GetNInterfaces (void) const; /** * \param device the device to match * \returns the matching interface, zero if not found. @@ -207,11 +207,23 @@ public: void Send (Packet const &packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol); + void SetAddress (uint32_t i, Ipv4Address address); + void SetNetworkMask (uint32_t i, Ipv4Mask mask); + Ipv4Mask GetNetworkMask (uint32_t t) const; + Ipv4Address GetAddress (uint32_t i) const; + uint16_t GetMtu (uint32_t i) const; + bool IsUp (uint32_t i) const; + void SetUp (uint32_t i); + void SetDown (uint32_t i); + + private: void SendRealOut (Packet const &packet, Ipv4Header const &ip, Ipv4Route const &route); bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device); void ForwardUp (Packet p, Ipv4Header const&ip); - TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context); + uint32_t AddIpv4Interface (Ipv4Interface *interface); + void SetupLoopback (void); + TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const; typedef std::list Ipv4InterfaceList; typedef std::list HostRoutes; diff --git a/src/node/l3-demux.cc b/src/node/l3-demux.cc index 091674597..8dae35096 100644 --- a/src/node/l3-demux.cc +++ b/src/node/l3-demux.cc @@ -41,15 +41,15 @@ L3Demux::~L3Demux() } TraceResolver * -L3Demux::CreateTraceResolver (TraceContext const &context) +L3Demux::CreateTraceResolver (TraceContext const &context) const { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i) { std::string protValue; std::ostringstream oss (protValue); - oss << (i->second)->GetProtocolNumber (); - ProtocolTraceType context = (i->second)->GetProtocolNumber (); + oss << i->second->GetProtocolNumber (); + ProtocolTraceType context = i->second->GetProtocolNumber (); resolver->Add (protValue, MakeCallback (&L3Protocol::CreateTraceResolver, i->second), context); diff --git a/src/node/l3-demux.h b/src/node/l3-demux.h index 5b9ccdbaf..30384ca11 100644 --- a/src/node/l3-demux.h +++ b/src/node/l3-demux.h @@ -59,7 +59,7 @@ public: * performed in this object. The caller must * delete the returned object. */ - TraceResolver *CreateTraceResolver (TraceContext const &context); + TraceResolver *CreateTraceResolver (TraceContext const &context) const; /**