author | Craig Dowell <craigdo@ee.washington.edu> |
Tue, 02 Dec 2008 12:15:18 -0800 | |
changeset 3972 | a84f2ab246e6 |
parent 2834 | 1aab57845b07 |
permissions | -rw-r--r-- |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
2 |
/* |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
3 |
* Copyright (c) 2006,2007 INRIA |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
4 |
* |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
7 |
* published by the Free Software Foundation; |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
8 |
* |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
12 |
* GNU General Public License for more details. |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
13 |
* |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
17 |
* |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
18 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
19 |
*/ |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
20 |
|
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#include "ns3/packet.h" |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
#include "ns3/header.h" |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
#include "ns3/packet-printer.h" |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
24 |
#include "ns3/ipv4-header.h" |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
25 |
#include "ns3/udp-header.h" |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
using namespace ns3; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
|
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
29 |
// This sample file shows how to use the Packet metadata facility |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
30 |
// |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
31 |
// Packets are stored as ``packed'' data structures, to facilitate |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
32 |
// fragmentation and network emulation. However, when debugging a program, |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
33 |
// or for certain tracing applications, it may be convenient to dump out |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
34 |
// the contents of a packet header in a human-friendly form. |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
35 |
// |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
36 |
// To do this, a few things are needed: |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
37 |
// i) enable the metadata facility (disabled by default, because it causes |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
38 |
// a small performance hit |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
39 |
// ii) decide on whether you want to use a default or customized (you |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
40 |
// provide your own) routine to dump a particular header |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
41 |
// |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
42 |
// This sample steps through two routines; one to use the default |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
43 |
// printing of IPv4 and UDP headers, and one to show a non-default case. |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
44 |
// There is a lot of emphasis in this sample of how this facility |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
45 |
// interacts with packet fragmentation. |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
void DefaultPrint (void) |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
{ |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
49 |
// We create a packet with 1000 bytes of zero payload |
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
50 |
// and add 3 headers to this packet. |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
51 |
Ptr<Packet> p = Create<Packet> (1000); |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
52 |
Ipv4Header ipv4; |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
53 |
UdpHeader udp; |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
54 |
ipv4.SetSource (Ipv4Address ("192.168.0.1")); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
55 |
ipv4.SetDestination (Ipv4Address ("192.168.0.2")); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
56 |
udp.SetSource (1025); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
57 |
udp.SetDestination (80); |
914
a23c5c2fb713
Add payload size to UDP
tomh@ns-regression.ee.washington.edu
parents:
913
diff
changeset
|
58 |
udp.SetPayloadSize (1000); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
59 |
p->AddHeader (udp); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
60 |
p->AddHeader (ipv4); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
|
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
62 |
std::cout << "full packet size=" << p->GetSize () << std::endl; |
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
63 |
// Here, invoke the default Print routine, directed to std out |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
64 |
p->Print (std::cout); |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
65 |
std::cout << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
|
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
68 |
// Now, we fragment our packet in 3 consecutive pieces. |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
69 |
Ptr<Packet> p1 = p->CreateFragment (0, 2); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
70 |
Ptr<Packet> p2 = p->CreateFragment (2, 1000); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
71 |
Ptr<Packet> p3 = p->CreateFragment (1002, 26); |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
72 |
|
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
std::cout << "fragment1" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
74 |
p1->Print (std::cout); |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
75 |
std::cout << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
std::cout << "fragment2" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
77 |
p2->Print (std::cout); |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
78 |
std::cout << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
std::cout << "fragment3" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
80 |
p3->Print (std::cout); |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
81 |
std::cout << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
|
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
83 |
// And, finally, we re-aggregate the 3 consecutive pieces. |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
84 |
Ptr<Packet> aggregate = p1->Copy (); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
85 |
aggregate->AddAtEnd (p2); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
86 |
aggregate->AddAtEnd (p3); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
std::cout << "aggregated" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
88 |
aggregate->Print (std::cout); |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
89 |
std::cout << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
90 |
} |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
91 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
void |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
93 |
DoPrintPayload (std::ostream & os,uint32_t packetUid,uint32_t size, |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
struct PacketPrinter::FragmentInformation info) |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
{ |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
96 |
os << "PAYLOAD (size " << size << " trim_start " << info.start << " trim_end " << info.end << ")"; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
97 |
} |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
98 |
void |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
99 |
DoPrintIpv4Header (std::ostream &os, uint32_t packetUid, uint32_t size, const Ipv4Header *ipv4) |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
100 |
{ |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
101 |
os << "IPV4 " << ipv4->GetSource () << " > " << ipv4->GetDestination (); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
102 |
} |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
103 |
void |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
104 |
DoPrintIpv4HeaderFragment (std::ostream &os, uint32_t packetUid, uint32_t size, |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
105 |
std::string &name, struct PacketPrinter::FragmentInformation info) |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
{ |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
107 |
os << "IPV4 fragment"; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
108 |
} |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
109 |
|
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
110 |
// This function walks through a non-default case. A few features of |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
111 |
// the API (defined in common/packet-printer.h) are shown. |
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
112 |
// |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
113 |
void NonDefaultPrint (void) |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
{ |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
115 |
// create an adhoc packet printer. |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
PacketPrinter printer; |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
117 |
// print from first header to last trailer |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
118 |
printer.PrintForward (); |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
119 |
// set a string separator automatically inserted |
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
120 |
// between each call to a printing function. |
892
b3f73643c055
add separator support to PacketPrinter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
891
diff
changeset
|
121 |
printer.SetSeparator (" - "); |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
122 |
// set the payload print function |
1141
a75fc1741700
rework the PacketPrinter API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
914
diff
changeset
|
123 |
printer.SetPayloadPrinter (MakeCallback (&DoPrintPayload)); |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
124 |
// set the print function for the header type Ipv4Header. |
1141
a75fc1741700
rework the PacketPrinter API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
914
diff
changeset
|
125 |
printer.SetHeaderPrinter (MakeCallback (&DoPrintIpv4Header), |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
126 |
MakeCallback (&DoPrintIpv4HeaderFragment)); |
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
127 |
|
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
128 |
|
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
129 |
// We create a packet with 1000 bytes of zero payload |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
130 |
Ptr<Packet> p = Create<Packet> (1000); |
901
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
131 |
Ipv4Header ipv4; |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
132 |
UdpHeader udp; |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
133 |
ipv4.SetSource (Ipv4Address ("192.168.0.1")); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
134 |
ipv4.SetDestination (Ipv4Address ("192.168.0.2")); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
135 |
udp.SetSource (1025); |
454dbce6dc4e
modify sample packet printer to use ipv4 and udp headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
893
diff
changeset
|
136 |
udp.SetDestination (80); |
914
a23c5c2fb713
Add payload size to UDP
tomh@ns-regression.ee.washington.edu
parents:
913
diff
changeset
|
137 |
udp.SetPayloadSize (1000); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
138 |
p->AddHeader (udp); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
139 |
p->AddHeader (ipv4); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
140 |
|
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
141 |
std::cout << "full packet size=" << p->GetSize () << std::endl; |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
142 |
p->Print (std::cout, printer); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
143 |
std::cout << std::endl; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
144 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
145 |
|
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
146 |
// fragment our packet in 3 pieces |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
147 |
Ptr<Packet> p1 = p->CreateFragment (0, 2); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
148 |
Ptr<Packet> p2 = p->CreateFragment (2, 1000); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
149 |
Ptr<Packet> p3 = p->CreateFragment (1002, 26); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
150 |
std::cout << "fragment1" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
151 |
p1->Print (std::cout, printer); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
152 |
std::cout << std::endl; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
153 |
std::cout << "fragment2" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
154 |
p2->Print (std::cout, printer); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
155 |
std::cout << std::endl; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
156 |
std::cout << "fragment3" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
157 |
p3->Print (std::cout, printer); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
158 |
std::cout << std::endl; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
159 |
|
893
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
160 |
// aggregate all 3 fragments of the original packet |
9d50280ae588
comment the sample code a little bit
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
892
diff
changeset
|
161 |
// to reconstruct a copy of the original packet. |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
162 |
Ptr<Packet> aggregate = p1->Copy (); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
163 |
aggregate->AddAtEnd (p2); |
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
164 |
aggregate->AddAtEnd (p3); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
165 |
std::cout << "aggregated" << std::endl; |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1141
diff
changeset
|
166 |
aggregate->Print (std::cout, printer); |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
167 |
std::cout << std::endl; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
168 |
} |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
169 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
170 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
171 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
172 |
int main (int argc, char *argv[]) |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
173 |
{ |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
174 |
Packet::EnableMetadata (); |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
175 |
|
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
176 |
std::cout << "DefaultPrint()" << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
177 |
DefaultPrint (); |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
178 |
|
913
f1a5508f155e
more verbose commenting of the sample
tomh@ns-regression.ee.washington.edu
parents:
901
diff
changeset
|
179 |
std::cout << std::endl << "NonDefaultPrint()" << std::endl; |
891
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
180 |
NonDefaultPrint (); |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
181 |
|
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
182 |
return 0; |
83fb0d5f7038
sample code for pretty printing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
183 |
} |