-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.h
119 lines (105 loc) · 2.45 KB
/
tools.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef TOOLS_H
#define TOOLS_H
#include <fstream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
# include <vector>
#include "ns3/tag.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
using namespace std;
using namespace ns3;
enum ProtocolType {TCP, UDP};
enum FairType {NATURAL, PERSENDER}; // Fairness type
// tool function
vector<int> getPktSizes(Ptr <const Packet> p, ProtocolType pt) // get [p2p size, ip size, tcp size, data size]
{
Ptr<Packet> pktCopy = p->Copy();
vector<int> res;
PppHeader pppH;
Ipv4Header ipH;
TcpHeader tcpH;
UdpHeader udpH;
res.push_back((int)pktCopy->GetSize());
pktCopy->RemoveHeader(pppH);
res.push_back((int)pktCopy->GetSize());
pktCopy->RemoveHeader(ipH);
res.push_back((int)pktCopy->GetSize());
if(pt == TCP) pktCopy->RemoveHeader(tcpH);
else pktCopy->RemoveHeader(udpH);
res.push_back((int)pktCopy->GetSize());
return res;
}
uint32_t getTcpSize(Ptr <const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy();
PppHeader pppH;
Ipv4Header ipH;
TcpHeader tcpH;
pktCopy->RemoveHeader(pppH);
pktCopy->RemoveHeader(ipH);
pktCopy->RemoveHeader(tcpH);
return pktCopy->GetSize();
}
string
printPkt(Ptr <const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy();
stringstream ss;
pktCopy->Print(ss);
return ss.str();
}
string
logIpv4Header (Ptr<const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy ();
PppHeader pppH;
Ipv4Header ipH;
pktCopy->RemoveHeader (pppH);
pktCopy->PeekHeader (ipH); /// need to know the exact structure of header
stringstream ss;
ipH.Print (ss);
return ss.str ();
}
string
logPppHeader (Ptr<const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy ();
PppHeader pppH;
pktCopy->PeekHeader (pppH);
stringstream ss;
pppH.Print (ss);
return ss.str ();
}
string
logTcpHeader (Ptr<const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy ();
PppHeader pppH;
Ipv4Header ipH;
TcpHeader tcpH;
pktCopy->RemoveHeader (pppH);
pktCopy->RemoveHeader (ipH);
pktCopy->PeekHeader (tcpH);
stringstream ss;
tcpH.Print (ss);
return ss.str ();
}
string
logPktIpv4Address (Ptr<const Packet> p)
{
Ptr<Packet> pktCopy = p->Copy ();
PppHeader pppH;
Ipv4Header ipH;
pktCopy->RemoveHeader (pppH);
pktCopy->PeekHeader (ipH);
stringstream ss;
ipH.GetSource ().Print (ss);
ss << " > ";
ipH.GetDestination ().Print (ss);
return ss.str ();
}
# endif