提交 31c13b8d 编写于 作者: C calincerchez

dctdump ready without comment

上级 470d683a
version 2
run General-0-20120706-18:17:56-5680
run General-0-20120709-12:08:18-5632
attr configname General
attr datetime 20120706-18:17:56
attr datetime 20120709-12:08:18
attr experiment General
attr inifile omnetpp.ini
attr iterationvars ""
attr iterationvars2 $repetition=0
attr measurement ""
attr network Test
attr processid 5680
attr processid 5632
attr repetition 0
attr replication #0
attr resultdir results
......
file 13724 1341587879
file 13724 1341824901
version 2
run General-0-20120706-18:17:56-5680
run General-0-20120709-12:08:18-5632
attr configname General
attr datetime 20120706-18:17:56
attr datetime 20120709-12:08:18
attr experiment General
attr inifile omnetpp.ini
attr iterationvars ""
attr iterationvars2 $repetition=0
attr measurement ""
attr network Test
attr processid 5680
attr processid 5632
attr repetition 0
attr replication #0
attr resultdir results
......
version 2
run General-0-20120706-18:17:56-5680
run General-0-20120709-12:08:18-5632
attr configname General
attr datetime 20120706-18:17:56
attr datetime 20120709-12:08:18
attr experiment General
attr inifile omnetpp.ini
attr iterationvars ""
attr iterationvars2 $repetition=0
attr measurement ""
attr network Test
attr processid 5680
attr processid 5632
attr repetition 0
attr replication #0
attr resultdir results
......
......@@ -16,31 +16,26 @@
//
#include "DCTDump.h"
#include "IPSerializer.h"
#define MAXBUFLENGTH 65536
#define MAXDCTLENGTH 100
Define_Module(DCTDump)
DCTDump::DCTDump() {
// TODO Auto-generated constructor stub
}
DCTDump::~DCTDump() {
// TODO Auto-generated destructor stub
Define_Module(DCTDump);
DCTDump::DCTDump() {
// TODO Auto-generated constructor stub
}
DCTDump::~DCTDump() {
// TODO Auto-generated destructor stub
}
void DCTDump::initialize() {
const char* file = this->par("dumpFile");
char begin_hdr[] = { 0x53, 0x65, 0x73, 0x73, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x72, 0x61, 0x6E, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x20, 0x28, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x20, 0x33, 0x2E, 0x31, 0x2C, 0x20,
0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x20, 0x31, 0x30, 0x2E, 0x36, 0x20, 0x6F, 0x6E, 0x20,
0x75, 0x6B, 0x65, 0x6E, 0x67, 0x37, 0x2C, 0x20, 0x4C, 0x69, 0x6E, 0x75, 0x78, 0x20, 0x32, 0x2E,
0x36, 0x2E, 0x38, 0x2D, 0x32, 0x34, 0x2D, 0x73, 0x6D, 0x70, 0x20, 0x69, 0x36, 0x38, 0x36, 0x29,
0x0A, 0x46, 0x65, 0x62, 0x72, 0x75, 0x61, 0x72, 0x79, 0x20, 0x32, 0x31, 0x2C, 0x20, 0x32, 0x30,
0x30, 0x36, 0x20, 0x20, 0x20, 0x20, 0x20, 0x31, 0x36, 0x3A, 0x34, 0x35, 0x3A, 0x32, 0x30, 0x2E,
0x35, 0x31, 0x38, 0x35, 0x0A };
const char *file = this->par("dumpFile");
const char *first_line = "Session Transcript\n";
const char *second_line = "February 21, 2006 16:45:20.5186\n";
if (strcmp(file,"")!=0)
{
tcpdump.dumpfile = fopen(file, "wb");
......@@ -50,7 +45,8 @@ void DCTDump::initialize() {
exit(-1);
}
fwrite(&begin_hdr, sizeof(begin_hdr), 1, tcpdump.dumpfile);
fwrite(first_line, 19, 1, tcpdump.dumpfile);
fwrite(second_line, 36, 1, tcpdump.dumpfile);
}
else
tcpdump.dumpfile = NULL;
......@@ -64,67 +60,62 @@ void DCTDump::handleMessage(cMessage *msg) {
std::stringstream vers;
const char *time = timestamp(stime);
uint8 buf[MAXBUFLENGTH];
int32 buf_len = 0;
std::string ascii_buf;
char dh[MAXDCTLENGTH];
struct pcaprec_hdr ph;
char *p = dh;
// Write pcap header
ph.ts_sec = (int32)stime.dbl();
ph.ts_usec = (uint32)((stime.dbl() - ph.ts_sec)*1000000);
// Write dump
memset((void*)&buf, 0, sizeof(buf));
// Write dct2000 header
memset((void*)&dh, 0, sizeof(dh));
// context
// context name
IPDatagram *ipPacket = dynamic_cast<IPDatagram*>(msg);
if (ipPacket) {
if (ipPacket->getTransportProtocol()==IP_PROT_SCTP) {
strncpy(p, "SCTP", 4);
strncpy(p, "SCTP.", 5);
p += 5;
}
write = true;
}
// context port number
*p = 1;
p++;
buf_len = IPSerializer().serialize(ipPacket, buf, sizeof(buf));
}
// timestamp
strncpy(p, time, strlen(time));
p += strlen(time) + 1;
// context port number - always 1
strncpy(p, "1/", 5);
p += 2;
// protocol
if (ipPacket) {
vers << ipPacket->getVersion();
// protocol name
strncpy(p, "ip", 2);
strncpy(p, "ip/", 3);
p += 3;
//protocol version
strncpy(p, vers.str().c_str(), strlen(vers.str().c_str()));
p += strlen(vers.str().c_str()) + 1;
}
// direction
if (msg->getArrivalGate()->isName("ifIn"))
*p = RECEIVED;
else
*p = SENT;
p++;
// encapsulation
if (ipPacket) {
*p = RAW_IP;
p += strlen(vers.str().c_str());
*p = '/';
p++;
}
memset((void*)&buf, 0, sizeof(buf));
// direction
if (msg->getArrivalGate()->isName("ifIn")) {
strncpy(p, " r", 2);
} else
strncpy(p, " s", 2);
p += 2;
ph.incl_len = p - dh;
ph.orig_len = ph.incl_len;
// timestamp
strncpy(p, " tm ", 4);
p += 4;
strncpy(p, time, strlen(time));
p += strlen(time);
//fwrite(&ph, sizeof(ph), 1, tcpdump.dumpfile);
if (write) {
fwrite(&dh, p - dh, 1, tcpdump.dumpfile);
dumpPacket(buf, buf_len);
}
}
// forward
......@@ -146,18 +137,28 @@ const char *DCTDump::timestamp(simtime_t stime) {
return out.str().c_str();
}
void DCTDump::finish()
{
void DCTDump::finish() {
if (strcmp(this->par("dumpFile"),"")!=0) {
char end_hdr[] = {0x0A,
0x41, 0x2E, 0x31, 0x2F, 0x70, 0x70, 0x70, 0x2F, 0x31, 0x2F, 0x2F, 0x2F, 0x20, 0x73, 0x20, 0x74,
0x6D, 0x20, 0x32, 0x30, 0x2E, 0x31, 0x34, 0x31, 0x31, 0x20, 0x6C, 0x20, 0x24, 0x66, 0x66, 0x30,
};
fwrite(&end_hdr, sizeof(end_hdr), 1, tcpdump.dumpfile);
fclose(tcpdump.dumpfile);
}
}
void DCTDump::dumpPacket(uint8 *buf, int32 len) {
if (len > 0) {
std::string dump = " $3119022cba260012d8828128";
// int32 j = 0;
// for (int32 i = 0; i < len * 2; i++) {
// if (((buf[j]) >> (4 * ((i + 1) % 2)) & 0x0f) < 10)
// dump += ((buf[j]) >> (4 * ((i + 1) % 2)) & 0x0f) + 48;
// else
// dump += ((buf[j]) >> (4 * ((i + 1) % 2)) & 0x0f) + 87;
// j = j + i % 2;
// }
dump += "\n";
fwrite(dump.c_str(), dump.size(), 1, tcpdump.dumpfile);
}
}
......@@ -15,38 +15,57 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#ifndef DCTDUMP_H_
#ifndef DCTDUMP_H_
#define DCTDUMP_H_
#include <omnetpp.h>
#include "TCPDump.h"
#include "TCPDump.h"
#define RECEIVED 1
#define SENT 0
#define RAW_IP 7
//struct dct2000_hdr {
// const char *ctxt_name;
// uint8 port_nr;
// const char *timestamp;
// const char *prot_name;
// const char *prot_var;
// const char *out_hdr;
// uint8 direct;
// uint8 encap;
//};
#define MAX_FIRST_LINE_LENGTH 200
#define MAX_TIMESTAMP_LINE_LENGTH 100
#define MAX_LINE_LENGTH 65536
#define MAX_TIMESTAMP_LEN 32
#define MAX_SECONDS_CHARS 16
#define MAX_SUBSECOND_DECIMALS 4
#define MAX_CONTEXT_NAME 64
#define MAX_PROTOCOL_NAME 64
#define MAX_PORT_DIGITS 2
#define MAX_VARIANT_DIGITS 32
#define MAX_OUTHDR_NAME 256
#define AAL_HEADER_CHARS 12
/*
* out file:
* - first line at least "Session Transcript"
* - second line, timestamp "February 21, 2006 16:45:20.5186"
* - packet:
* - context name "test_ETSI" followed by '.'
* - port number "1" followed by '/'
* - protocol name "isdn_l3" followed by '/'
* - protocol variant "1" followed by ',' if outhdr is present else followed by '/'
* - direction " s"
* - timestamp " tm 17.1505 "
* - start of dump "$"
* - dump of packet in ascii format (0x03 -> 0x30 0x33)
* - new line after each dump
*/
class DCTDump : public TCPDump {
private:
const char *timestamp(simtime_t stime);
public:
DCTDump();
void dumpPacket(uint8 *buf, int32 len);
public:
DCTDump();
virtual ~DCTDump();
virtual void handleMessage(cMessage *msg);
virtual void initialize();
virtual void finish();
};
#endif /* DCTDUMP_H_ */
virtual void finish();
};
#endif /* DCTDUMP_H_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册