# HG changeset patch # User Emmanuelle Laprise # Date 1183424380 18000 # Node ID fc8942ceaef1a83d4b0ee29922df08bc4d412e87 # Parent 1f600c2aec771b7fce96bb4014be3d49c2efb6ce Removed the const after the DoAddDevice function because it is used to add a callback on the packet receive function. But, in some cases (ie ethernet learning), it is going to be needed to have a non-const function that is called on packet reception. diff -r 1f600c2aec77 -r fc8942ceaef1 src/node/node.h --- a/src/node/node.h Mon Jul 02 19:47:03 2007 +0200 +++ b/src/node/node.h Mon Jul 02 19:59:40 2007 -0500 @@ -160,7 +160,7 @@ private: * at this point to setup the node's receive function for * the NetDevice packets. */ - virtual void DoAddDevice (Ptr device) const = 0; + virtual void DoAddDevice (Ptr device) = 0; uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node # HG changeset patch # User Emmanuelle Laprise # Date 1183519542 18000 # Node ID 67ab6d8b3711058491ee74afbebc5f9d5ee035ba # Parent fc8942ceaef1a83d4b0ee29922df08bc4d412e87 Remove the const after the DoAddDevice function diff -r fc8942ceaef1 -r 67ab6d8b3711 src/internet-node/internet-node.cc --- a/src/internet-node/internet-node.cc Mon Jul 02 19:59:40 2007 -0500 +++ b/src/internet-node/internet-node.cc Tue Jul 03 22:25:42 2007 -0500 @@ -98,7 +98,7 @@ InternetNode::DoDispose() } void -InternetNode::DoAddDevice (Ptr device) const +InternetNode::DoAddDevice (Ptr device) { device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this)); } diff -r fc8942ceaef1 -r 67ab6d8b3711 src/internet-node/internet-node.h --- a/src/internet-node/internet-node.h Mon Jul 02 19:59:40 2007 -0500 +++ b/src/internet-node/internet-node.h Tue Jul 03 22:25:42 2007 -0500 @@ -46,7 +46,7 @@ protected: protected: virtual void DoDispose(void); private: - virtual void DoAddDevice (Ptr device) const; + virtual void DoAddDevice (Ptr device); virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); bool ReceiveFromDevice (Ptr device, const Packet &p, uint16_t protocolNumber) const; void Construct (void); # HG changeset patch # User Emmanuelle Laprise # Date 1183519725 18000 # Node ID 0ad45bb86c11c41b290f49eb38766242d59ffe36 # Parent 67ab6d8b3711058491ee74afbebc5f9d5ee035ba # Parent a23c5c2fb713256347a7554364bc59f72fa465ff Needed to push const changes diff -r 67ab6d8b3711 -r 0ad45bb86c11 samples/main-packet-printer.cc --- a/samples/main-packet-printer.cc Tue Jul 03 22:25:42 2007 -0500 +++ b/samples/main-packet-printer.cc Tue Jul 03 22:28:45 2007 -0500 @@ -1,4 +1,24 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006,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 + * + * Author: Mathieu Lacage + */ + #include "ns3/packet.h" #include "ns3/header.h" #include "ns3/packet-printer.h" @@ -7,6 +27,23 @@ using namespace ns3; +// This sample file shows how to use the Packet metadata facility +// +// Packets are stored as ``packed'' data structures, to facilitate +// fragmentation and network emulation. However, when debugging a program, +// or for certain tracing applications, it may be convenient to dump out +// the contents of a packet header in a human-friendly form. +// +// To do this, a few things are needed: +// i) enable the metadata facility (disabled by default, because it causes +// a small performance hit +// ii) decide on whether you want to use a default or customized (you +// provide your own) routine to dump a particular header +// +// This sample steps through two routines; one to use the default +// printing of IPv4 and UDP headers, and one to show a non-default case. +// There is a lot of emphasis in this sample of how this facility +// interacts with packet fragmentation. void DefaultPrint (void) { @@ -19,10 +56,12 @@ void DefaultPrint (void) ipv4.SetDestination (Ipv4Address ("192.168.0.2")); udp.SetSource (1025); udp.SetDestination (80); + udp.SetPayloadSize (1000); p.AddHeader (udp); p.AddHeader (ipv4); std::cout << "full packet size=" << p.GetSize () << std::endl; + // Here, invoke the default Print routine, directed to std out p.Print (std::cout); std::cout << std::endl; @@ -51,6 +90,9 @@ void DefaultPrint (void) std::cout << std::endl; } +// The below functions are used in place of default versions, in the +// non-default case below. For instance, DoPrintIpv4Header will print +// out less IPv4 header information than the default print function void DoPrintDefault (std::ostream &os,uint32_t packetUid, uint32_t size, std::string &name, struct PacketPrinter::FragmentInformation info) @@ -75,6 +117,9 @@ DoPrintIpv4HeaderFragment (std::ostream os << "IPV4 fragment"; } +// This function walks through a non-default case. A few features of +// the API (defined in common/packet-printer.h) are shown. +// void NonDefaultPrint (void) { // create an adhoc packet printer. @@ -103,6 +148,7 @@ void NonDefaultPrint (void) ipv4.SetDestination (Ipv4Address ("192.168.0.2")); udp.SetSource (1025); udp.SetDestination (80); + udp.SetPayloadSize (1000); p.AddHeader (udp); p.AddHeader (ipv4); @@ -141,8 +187,10 @@ int main (int argc, char *argv[]) { Packet::EnableMetadata (); + std::cout << "DefaultPrint()" << std::endl; DefaultPrint (); + std::cout << std::endl << "NonDefaultPrint()" << std::endl; NonDefaultPrint (); return 0;