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

dctdump ready without comment

上级 470d683a
version 2 version 2
run General-0-20120706-18:17:56-5680 run General-0-20120709-12:08:18-5632
attr configname General attr configname General
attr datetime 20120706-18:17:56 attr datetime 20120709-12:08:18
attr experiment General attr experiment General
attr inifile omnetpp.ini attr inifile omnetpp.ini
attr iterationvars "" attr iterationvars ""
attr iterationvars2 $repetition=0 attr iterationvars2 $repetition=0
attr measurement "" attr measurement ""
attr network Test attr network Test
attr processid 5680 attr processid 5632
attr repetition 0 attr repetition 0
attr replication #0 attr replication #0
attr resultdir results attr resultdir results
......
file 13724 1341587879 file 13724 1341824901
version 2 version 2
run General-0-20120706-18:17:56-5680 run General-0-20120709-12:08:18-5632
attr configname General attr configname General
attr datetime 20120706-18:17:56 attr datetime 20120709-12:08:18
attr experiment General attr experiment General
attr inifile omnetpp.ini attr inifile omnetpp.ini
attr iterationvars "" attr iterationvars ""
attr iterationvars2 $repetition=0 attr iterationvars2 $repetition=0
attr measurement "" attr measurement ""
attr network Test attr network Test
attr processid 5680 attr processid 5632
attr repetition 0 attr repetition 0
attr replication #0 attr replication #0
attr resultdir results attr resultdir results
......
version 2 version 2
run General-0-20120706-18:17:56-5680 run General-0-20120709-12:08:18-5632
attr configname General attr configname General
attr datetime 20120706-18:17:56 attr datetime 20120709-12:08:18
attr experiment General attr experiment General
attr inifile omnetpp.ini attr inifile omnetpp.ini
attr iterationvars "" attr iterationvars ""
attr iterationvars2 $repetition=0 attr iterationvars2 $repetition=0
attr measurement "" attr measurement ""
attr network Test attr network Test
attr processid 5680 attr processid 5632
attr repetition 0 attr repetition 0
attr replication #0 attr replication #0
attr resultdir results attr resultdir results
......
...@@ -16,31 +16,26 @@ ...@@ -16,31 +16,26 @@
// //
#include "DCTDump.h" #include "DCTDump.h"
#include "IPSerializer.h"
#define MAXBUFLENGTH 65536 #define MAXBUFLENGTH 65536
#define MAXDCTLENGTH 100 #define MAXDCTLENGTH 100
Define_Module(DCTDump) Define_Module(DCTDump);
DCTDump::DCTDump() { DCTDump::DCTDump() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
DCTDump::~DCTDump() { DCTDump::~DCTDump() {
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void DCTDump::initialize() { void DCTDump::initialize() {
const char* file = this->par("dumpFile"); 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, const char *first_line = "Session Transcript\n";
0x70, 0x74, 0x20, 0x28, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x20, 0x33, 0x2E, 0x31, 0x2C, 0x20, const char *second_line = "February 21, 2006 16:45:20.5186\n";
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 };
if (strcmp(file,"")!=0) if (strcmp(file,"")!=0)
{ {
tcpdump.dumpfile = fopen(file, "wb"); tcpdump.dumpfile = fopen(file, "wb");
...@@ -50,7 +45,8 @@ void DCTDump::initialize() { ...@@ -50,7 +45,8 @@ void DCTDump::initialize() {
exit(-1); 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 else
tcpdump.dumpfile = NULL; tcpdump.dumpfile = NULL;
...@@ -64,67 +60,62 @@ void DCTDump::handleMessage(cMessage *msg) { ...@@ -64,67 +60,62 @@ void DCTDump::handleMessage(cMessage *msg) {
std::stringstream vers; std::stringstream vers;
const char *time = timestamp(stime); const char *time = timestamp(stime);
uint8 buf[MAXBUFLENGTH]; uint8 buf[MAXBUFLENGTH];
int32 buf_len = 0;
std::string ascii_buf;
char dh[MAXDCTLENGTH]; char dh[MAXDCTLENGTH];
struct pcaprec_hdr ph;
char *p = dh; char *p = dh;
// Write pcap header // Write dump
ph.ts_sec = (int32)stime.dbl(); memset((void*)&buf, 0, sizeof(buf));
ph.ts_usec = (uint32)((stime.dbl() - ph.ts_sec)*1000000);
// Write dct2000 header // Write dct2000 header
memset((void*)&dh, 0, sizeof(dh)); memset((void*)&dh, 0, sizeof(dh));
// context // context name
IPDatagram *ipPacket = dynamic_cast<IPDatagram*>(msg); IPDatagram *ipPacket = dynamic_cast<IPDatagram*>(msg);
if (ipPacket) { if (ipPacket) {
if (ipPacket->getTransportProtocol()==IP_PROT_SCTP) { if (ipPacket->getTransportProtocol()==IP_PROT_SCTP) {
strncpy(p, "SCTP", 4); strncpy(p, "SCTP.", 5);
p += 5; p += 5;
} }
write = true; write = true;
}
// context port number buf_len = IPSerializer().serialize(ipPacket, buf, sizeof(buf));
*p = 1; }
p++;
// timestamp // context port number - always 1
strncpy(p, time, strlen(time)); strncpy(p, "1/", 5);
p += strlen(time) + 1; p += 2;
// protocol // protocol
if (ipPacket) { if (ipPacket) {
vers << ipPacket->getVersion(); vers << ipPacket->getVersion();
// protocol name // protocol name
strncpy(p, "ip", 2); strncpy(p, "ip/", 3);
p += 3; p += 3;
//protocol version //protocol version
strncpy(p, vers.str().c_str(), strlen(vers.str().c_str())); strncpy(p, vers.str().c_str(), strlen(vers.str().c_str()));
p += strlen(vers.str().c_str()) + 1; p += strlen(vers.str().c_str());
} *p = '/';
// direction
if (msg->getArrivalGate()->isName("ifIn"))
*p = RECEIVED;
else
*p = SENT;
p++;
// encapsulation
if (ipPacket) {
*p = RAW_IP;
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; // timestamp
ph.orig_len = ph.incl_len; strncpy(p, " tm ", 4);
p += 4;
strncpy(p, time, strlen(time));
p += strlen(time);
//fwrite(&ph, sizeof(ph), 1, tcpdump.dumpfile);
if (write) { if (write) {
fwrite(&dh, p - dh, 1, tcpdump.dumpfile); fwrite(&dh, p - dh, 1, tcpdump.dumpfile);
dumpPacket(buf, buf_len);
} }
} }
// forward // forward
...@@ -146,18 +137,28 @@ const char *DCTDump::timestamp(simtime_t stime) { ...@@ -146,18 +137,28 @@ const char *DCTDump::timestamp(simtime_t stime) {
return out.str().c_str(); return out.str().c_str();
} }
void DCTDump::finish() void DCTDump::finish() {
{
if (strcmp(this->par("dumpFile"),"")!=0) { 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); 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 @@ ...@@ -15,38 +15,57 @@
// along with this program. If not, see http://www.gnu.org/licenses/. // along with this program. If not, see http://www.gnu.org/licenses/.
// //
#ifndef DCTDUMP_H_ #ifndef DCTDUMP_H_
#define DCTDUMP_H_ #define DCTDUMP_H_
#include <omnetpp.h> #include <omnetpp.h>
#include "TCPDump.h" #include "TCPDump.h"
#define RECEIVED 1 #define RECEIVED 1
#define SENT 0 #define SENT 0
#define RAW_IP 7 #define RAW_IP 7
//struct dct2000_hdr { #define MAX_FIRST_LINE_LENGTH 200
// const char *ctxt_name; #define MAX_TIMESTAMP_LINE_LENGTH 100
// uint8 port_nr; #define MAX_LINE_LENGTH 65536
// const char *timestamp; #define MAX_TIMESTAMP_LEN 32
// const char *prot_name; #define MAX_SECONDS_CHARS 16
// const char *prot_var; #define MAX_SUBSECOND_DECIMALS 4
// const char *out_hdr; #define MAX_CONTEXT_NAME 64
// uint8 direct; #define MAX_PROTOCOL_NAME 64
// uint8 encap; #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 { class DCTDump : public TCPDump {
private: private:
const char *timestamp(simtime_t stime); const char *timestamp(simtime_t stime);
public: void dumpPacket(uint8 *buf, int32 len);
DCTDump(); public:
DCTDump();
virtual ~DCTDump(); virtual ~DCTDump();
virtual void handleMessage(cMessage *msg); virtual void handleMessage(cMessage *msg);
virtual void initialize(); virtual void initialize();
virtual void finish(); virtual void finish();
}; };
#endif /* DCTDUMP_H_ */ #endif /* DCTDUMP_H_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册