1 #include <fipa_acl/fipa_acl.h> 6 #include <numeric/Stats.hpp> 15 if (x->tv_usec < y->tv_usec)
17 int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
18 y->tv_usec -= 1000000 * nsec;
22 if (x->tv_usec - y->tv_usec > 1000000)
24 int nsec = (y->tv_usec - x->tv_usec) / 1000000;
25 y->tv_usec += 1000000 * nsec;
31 result->tv_sec = x->tv_sec - y->tv_sec;
32 result->tv_usec = x->tv_usec - y->tv_usec;
35 return x->tv_sec < y->tv_sec;
39 int main(
int argc,
char** argv)
43 printf(
"usage: %s <content-size-in-byte> <epochs>\n", argv[0]);
44 printf(
"output will be: <encoding> <content-size in byte> <encoded-msg-size in bytes > <overhead-percent> <encoding-time in ms/msg> <decoding-time in ms/msg> <epochs>\n");
50 uint32_t BUFFER_MAX = atoi(argv[1]);
51 int32_t epochs = atoi(argv[2]);
67 base::Time time = base::Time::fromString(
"20101223-12:00:37:980", base::Time::Milliseconds);
87 char* buffer = (
char*) calloc(1,BUFFER_MAX+1);
90 fprintf(stderr,
"Allocation of memory for test message failed\n");
94 for(
size_t i = 0; i < BUFFER_MAX; ++i)
96 buffer[i] = (char) 48 + rand() % 40;
100 buffer[BUFFER_MAX] =
'\0';
101 std::string content(buffer, BUFFER_MAX);
104 uint32_t payloadsize = info.size() + BUFFER_MAX + 8 + 1;
105 printf(
"# PAYLOAD SIZE: %d\n", payloadsize);
106 printf(
"# CONTENT SIZE: %lu\n", content.size());
107 printf(
"# MSG CONTENT SIZE: %lu\n", msg.
getContent().size());
112 std::string encodedMsg;
113 printf(
"#<encoding> <content-size in byte> <encoded-msg-size in bytes > <overhead-percent> <encoding-time in ms/msg> <decoding-time in ms/msg> <epochs>\n");
116 numeric::Stats<double> msgEncodingStats;
117 numeric::Stats<double> msgDecodingStats;
119 numeric::Stats<double> envEncodingStats;
120 numeric::Stats<double> envDecodingStats;
124 struct timeval start, stop, diff;
125 for(
int i = 0; i < epochs; ++i)
127 gettimeofday(&start, 0);
129 gettimeofday(&stop, 0);
131 double totaltime = diff.tv_sec*1000 + diff.tv_usec/1000.0;
132 msgEncodingStats.update(totaltime);
137 struct timeval start, stop, diff;
138 for(
int i = 0; i < epochs; ++i)
140 gettimeofday(&start, 0);
141 if(!inputParser.parseData(encodedMsg, msg, representationType))
145 gettimeofday(&stop, 0);
147 double totaltime = diff.tv_sec*1000 + diff.tv_usec/1000.0;
148 msgDecodingStats.update(totaltime);
152 double overheadInPercent = (encodedMsg.size() - payloadsize)*1.0/(1.0*encodedMsg.size());
154 printf(
"message %d %d %10.6f %10.6f %10.6f %10.6f %10.6f %d %s\n", BUFFER_MAX, (
int) encodedMsg.size(), overheadInPercent, msgEncodingStats.mean(), msgEncodingStats.stdev(), msgDecodingStats.mean(), msgDecodingStats.stdev(), epochs,
representation::TypeTxt[representationType].c_str());
158 std::string encodedEnvelope;
168 for(
int i = 0; i < epochs; ++i)
172 struct timeval start, stop, diff;
173 gettimeofday(&start, 0);
176 gettimeofday(&stop, 0);
179 double totaltime = diff.tv_sec*1000 + diff.tv_usec/1000.0;
180 envEncodingStats.update(totaltime);
185 struct timeval start, stop, diff;
186 gettimeofday(&start, 0);
192 gettimeofday(&stop, 0);
195 double totaltime = diff.tv_sec*1000 + diff.tv_usec/1000.0;
196 envDecodingStats.update(totaltime);
200 overheadInPercent = (encodedEnvelope.size() - encodedMsg.size())/(1.0*encodedEnvelope.size());
201 printf(
"envelope %d %d %10.6f %10.6f %10.6f %10.6f %10.6f %d %s %s\n", BUFFER_MAX, (
int) encodedEnvelope.size(), overheadInPercent, envEncodingStats.mean(), envEncodingStats.stdev(), envDecodingStats.mean(), envDecodingStats.stdev(), epochs,
representation::TypeTxt[envRepresentationType].c_str(),
representation::TypeTxt[representationType].c_str());
std::string getEncoding() const
static std::string create(const ACLEnvelope &msg, const representation::Type &acl_representation)
void setReplyWith(const std::string &str)
void setConversationID(const std::string &str)
ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields...
std::string getContent() const
void setLanguage(const std::string &str)
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
static bool parseData(const std::string &storage, ACLEnvelope &envelope, representation::Type type=fipa::acl::representation::BITEFFICIENT)
const std::string & getName() const
setter and getter methods for all fields; they do not result in deep-copies assignments/retreivals, but this can be easily changed if needed through the overloaded operator which do
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
std::string getReplyWith() const
std::string getOntology() const
void addReplyTo(const AgentID &aid)
void setContent(const std::string &content)
void setSender(const AgentID &sender)
const std::string TypeTxt[]
std::string getLanguage() const
This class provides a representation of a message conforming to the FIPA specification SC00061...
void setReplyBy(const base::Time &time)
int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
void addReceiver(const AgentID &aid)
void setPerformative(Performative perf)
Set performative.
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
void setEncoding(const std::string &str)
int main(int argc, char **argv)
void setProtocol(const std::string &str)
the method checks whether the passed protocol string is a word or not(according to the fipa spec) ...
std::string getConversationID() const
Agent Communication Language.
void setOntology(const std::string &str)