-
Notifications
You must be signed in to change notification settings - Fork 0
/
Packet_m.cc
548 lines (484 loc) · 16.2 KB
/
Packet_m.cc
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
//
// Generated file, do not edit! Created by nedtool 5.6 from Packet.msg.
//
// Disable warnings about unused variables, empty switch stmts, etc:
#ifdef _MSC_VER
# pragma warning(disable:4101)
# pragma warning(disable:4065)
#endif
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wshadow"
# pragma clang diagnostic ignored "-Wconversion"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wc++98-compat"
# pragma clang diagnostic ignored "-Wunreachable-code-break"
# pragma clang diagnostic ignored "-Wold-style-cast"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
# pragma GCC diagnostic ignored "-Wfloat-conversion"
#endif
#include <iostream>
#include <sstream>
#include "Packet_m.h"
namespace omnetpp {
// Template pack/unpack rules. They are declared *after* a1l type-specific pack functions for multiple reasons.
// They are in the omnetpp namespace, to allow them to be found by argument-dependent lookup via the cCommBuffer argument
// Packing/unpacking an std::vector
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::vector<T,A>& v)
{
int n = v.size();
doParsimPacking(buffer, n);
for (int i = 0; i < n; i++)
doParsimPacking(buffer, v[i]);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::vector<T,A>& v)
{
int n;
doParsimUnpacking(buffer, n);
v.resize(n);
for (int i = 0; i < n; i++)
doParsimUnpacking(buffer, v[i]);
}
// Packing/unpacking an std::list
template<typename T, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::list<T,A>& l)
{
doParsimPacking(buffer, (int)l.size());
for (typename std::list<T,A>::const_iterator it = l.begin(); it != l.end(); ++it)
doParsimPacking(buffer, (T&)*it);
}
template<typename T, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::list<T,A>& l)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
l.push_back(T());
doParsimUnpacking(buffer, l.back());
}
}
// Packing/unpacking an std::set
template<typename T, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::set<T,Tr,A>& s)
{
doParsimPacking(buffer, (int)s.size());
for (typename std::set<T,Tr,A>::const_iterator it = s.begin(); it != s.end(); ++it)
doParsimPacking(buffer, *it);
}
template<typename T, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::set<T,Tr,A>& s)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
T x;
doParsimUnpacking(buffer, x);
s.insert(x);
}
}
// Packing/unpacking an std::map
template<typename K, typename V, typename Tr, typename A>
void doParsimPacking(omnetpp::cCommBuffer *buffer, const std::map<K,V,Tr,A>& m)
{
doParsimPacking(buffer, (int)m.size());
for (typename std::map<K,V,Tr,A>::const_iterator it = m.begin(); it != m.end(); ++it) {
doParsimPacking(buffer, it->first);
doParsimPacking(buffer, it->second);
}
}
template<typename K, typename V, typename Tr, typename A>
void doParsimUnpacking(omnetpp::cCommBuffer *buffer, std::map<K,V,Tr,A>& m)
{
int n;
doParsimUnpacking(buffer, n);
for (int i=0; i<n; i++) {
K k; V v;
doParsimUnpacking(buffer, k);
doParsimUnpacking(buffer, v);
m[k] = v;
}
}
// Default pack/unpack function for arrays
template<typename T>
void doParsimArrayPacking(omnetpp::cCommBuffer *b, const T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimPacking(b, t[i]);
}
template<typename T>
void doParsimArrayUnpacking(omnetpp::cCommBuffer *b, T *t, int n)
{
for (int i = 0; i < n; i++)
doParsimUnpacking(b, t[i]);
}
// Default rule to prevent compiler from choosing base class' doParsimPacking() function
template<typename T>
void doParsimPacking(omnetpp::cCommBuffer *, const T& t)
{
throw omnetpp::cRuntimeError("Parsim error: No doParsimPacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
template<typename T>
void doParsimUnpacking(omnetpp::cCommBuffer *, T& t)
{
throw omnetpp::cRuntimeError("Parsim error: No doParsimUnpacking() function for type %s", omnetpp::opp_typename(typeid(t)));
}
} // namespace omnetpp
// forward
template<typename T, typename A>
std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec);
// Template rule which fires if a struct or class doesn't have operator<<
template<typename T>
inline std::ostream& operator<<(std::ostream& out,const T&) {return out;}
// operator<< for std::vector<T>
template<typename T, typename A>
inline std::ostream& operator<<(std::ostream& out, const std::vector<T,A>& vec)
{
out.put('{');
for(typename std::vector<T,A>::const_iterator it = vec.begin(); it != vec.end(); ++it)
{
if (it != vec.begin()) {
out.put(','); out.put(' ');
}
out << *it;
}
out.put('}');
char buf[32];
sprintf(buf, " (size=%u)", (unsigned int)vec.size());
out.write(buf, strlen(buf));
return out;
}
Register_Class(Packet)
Packet::Packet(const char *name, short kind) : ::omnetpp::cPacket(name,kind)
{
this->srcAddr = 0;
this->destAddr = 0;
this->hopCount = 0;
this->packet_id = 0;
}
Packet::Packet(const Packet& other) : ::omnetpp::cPacket(other)
{
copy(other);
}
Packet::~Packet()
{
}
Packet& Packet::operator=(const Packet& other)
{
if (this==&other) return *this;
::omnetpp::cPacket::operator=(other);
copy(other);
return *this;
}
void Packet::copy(const Packet& other)
{
this->srcAddr = other.srcAddr;
this->destAddr = other.destAddr;
this->hopCount = other.hopCount;
this->packet_id = other.packet_id;
}
void Packet::parsimPack(omnetpp::cCommBuffer *b) const
{
::omnetpp::cPacket::parsimPack(b);
doParsimPacking(b,this->srcAddr);
doParsimPacking(b,this->destAddr);
doParsimPacking(b,this->hopCount);
doParsimPacking(b,this->packet_id);
}
void Packet::parsimUnpack(omnetpp::cCommBuffer *b)
{
::omnetpp::cPacket::parsimUnpack(b);
doParsimUnpacking(b,this->srcAddr);
doParsimUnpacking(b,this->destAddr);
doParsimUnpacking(b,this->hopCount);
doParsimUnpacking(b,this->packet_id);
}
int Packet::getSrcAddr() const
{
return this->srcAddr;
}
void Packet::setSrcAddr(int srcAddr)
{
this->srcAddr = srcAddr;
}
int Packet::getDestAddr() const
{
return this->destAddr;
}
void Packet::setDestAddr(int destAddr)
{
this->destAddr = destAddr;
}
int Packet::getHopCount() const
{
return this->hopCount;
}
void Packet::setHopCount(int hopCount)
{
this->hopCount = hopCount;
}
int Packet::getPacket_id() const
{
return this->packet_id;
}
void Packet::setPacket_id(int packet_id)
{
this->packet_id = packet_id;
}
class PacketDescriptor : public omnetpp::cClassDescriptor
{
private:
mutable const char **propertynames;
public:
PacketDescriptor();
virtual ~PacketDescriptor();
virtual bool doesSupport(omnetpp::cObject *obj) const override;
virtual const char **getPropertyNames() const override;
virtual const char *getProperty(const char *propertyname) const override;
virtual int getFieldCount() const override;
virtual const char *getFieldName(int field) const override;
virtual int findField(const char *fieldName) const override;
virtual unsigned int getFieldTypeFlags(int field) const override;
virtual const char *getFieldTypeString(int field) const override;
virtual const char **getFieldPropertyNames(int field) const override;
virtual const char *getFieldProperty(int field, const char *propertyname) const override;
virtual int getFieldArraySize(void *object, int field) const override;
virtual const char *getFieldDynamicTypeString(void *object, int field, int i) const override;
virtual std::string getFieldValueAsString(void *object, int field, int i) const override;
virtual bool setFieldValueAsString(void *object, int field, int i, const char *value) const override;
virtual const char *getFieldStructName(int field) const override;
virtual void *getFieldStructValuePointer(void *object, int field, int i) const override;
};
Register_ClassDescriptor(PacketDescriptor)
PacketDescriptor::PacketDescriptor() : omnetpp::cClassDescriptor("Packet", "omnetpp::cPacket")
{
propertynames = nullptr;
}
PacketDescriptor::~PacketDescriptor()
{
delete[] propertynames;
}
bool PacketDescriptor::doesSupport(omnetpp::cObject *obj) const
{
return dynamic_cast<Packet *>(obj)!=nullptr;
}
const char **PacketDescriptor::getPropertyNames() const
{
if (!propertynames) {
static const char *names[] = { nullptr };
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
const char **basenames = basedesc ? basedesc->getPropertyNames() : nullptr;
propertynames = mergeLists(basenames, names);
}
return propertynames;
}
const char *PacketDescriptor::getProperty(const char *propertyname) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? basedesc->getProperty(propertyname) : nullptr;
}
int PacketDescriptor::getFieldCount() const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
return basedesc ? 4+basedesc->getFieldCount() : 4;
}
unsigned int PacketDescriptor::getFieldTypeFlags(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldTypeFlags(field);
field -= basedesc->getFieldCount();
}
static unsigned int fieldTypeFlags[] = {
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
FD_ISEDITABLE,
};
return (field>=0 && field<4) ? fieldTypeFlags[field] : 0;
}
const char *PacketDescriptor::getFieldName(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldName(field);
field -= basedesc->getFieldCount();
}
static const char *fieldNames[] = {
"srcAddr",
"destAddr",
"hopCount",
"packet_id",
};
return (field>=0 && field<4) ? fieldNames[field] : nullptr;
}
int PacketDescriptor::findField(const char *fieldName) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
int base = basedesc ? basedesc->getFieldCount() : 0;
if (fieldName[0]=='s' && strcmp(fieldName, "srcAddr")==0) return base+0;
if (fieldName[0]=='d' && strcmp(fieldName, "destAddr")==0) return base+1;
if (fieldName[0]=='h' && strcmp(fieldName, "hopCount")==0) return base+2;
if (fieldName[0]=='p' && strcmp(fieldName, "packet_id")==0) return base+3;
return basedesc ? basedesc->findField(fieldName) : -1;
}
const char *PacketDescriptor::getFieldTypeString(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldTypeString(field);
field -= basedesc->getFieldCount();
}
static const char *fieldTypeStrings[] = {
"int",
"int",
"int",
"int",
};
return (field>=0 && field<4) ? fieldTypeStrings[field] : nullptr;
}
const char **PacketDescriptor::getFieldPropertyNames(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldPropertyNames(field);
field -= basedesc->getFieldCount();
}
switch (field) {
case 0: {
static const char *names[] = { "packetData", nullptr };
return names;
}
case 1: {
static const char *names[] = { "packetData", nullptr };
return names;
}
case 2: {
static const char *names[] = { "packetData", nullptr };
return names;
}
case 3: {
static const char *names[] = { "packetData", nullptr };
return names;
}
default: return nullptr;
}
}
const char *PacketDescriptor::getFieldProperty(int field, const char *propertyname) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldProperty(field, propertyname);
field -= basedesc->getFieldCount();
}
switch (field) {
case 0:
if (!strcmp(propertyname,"packetData")) return "";
return nullptr;
case 1:
if (!strcmp(propertyname,"packetData")) return "";
return nullptr;
case 2:
if (!strcmp(propertyname,"packetData")) return "";
return nullptr;
case 3:
if (!strcmp(propertyname,"packetData")) return "";
return nullptr;
default: return nullptr;
}
}
int PacketDescriptor::getFieldArraySize(void *object, int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldArraySize(object, field);
field -= basedesc->getFieldCount();
}
Packet *pp = (Packet *)object; (void)pp;
switch (field) {
default: return 0;
}
}
const char *PacketDescriptor::getFieldDynamicTypeString(void *object, int field, int i) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldDynamicTypeString(object,field,i);
field -= basedesc->getFieldCount();
}
Packet *pp = (Packet *)object; (void)pp;
switch (field) {
default: return nullptr;
}
}
std::string PacketDescriptor::getFieldValueAsString(void *object, int field, int i) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldValueAsString(object,field,i);
field -= basedesc->getFieldCount();
}
Packet *pp = (Packet *)object; (void)pp;
switch (field) {
case 0: return long2string(pp->getSrcAddr());
case 1: return long2string(pp->getDestAddr());
case 2: return long2string(pp->getHopCount());
case 3: return long2string(pp->getPacket_id());
default: return "";
}
}
bool PacketDescriptor::setFieldValueAsString(void *object, int field, int i, const char *value) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->setFieldValueAsString(object,field,i,value);
field -= basedesc->getFieldCount();
}
Packet *pp = (Packet *)object; (void)pp;
switch (field) {
case 0: pp->setSrcAddr(string2long(value)); return true;
case 1: pp->setDestAddr(string2long(value)); return true;
case 2: pp->setHopCount(string2long(value)); return true;
case 3: pp->setPacket_id(string2long(value)); return true;
default: return false;
}
}
const char *PacketDescriptor::getFieldStructName(int field) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldStructName(field);
field -= basedesc->getFieldCount();
}
switch (field) {
default: return nullptr;
};
}
void *PacketDescriptor::getFieldStructValuePointer(void *object, int field, int i) const
{
omnetpp::cClassDescriptor *basedesc = getBaseClassDescriptor();
if (basedesc) {
if (field < basedesc->getFieldCount())
return basedesc->getFieldStructValuePointer(object, field, i);
field -= basedesc->getFieldCount();
}
Packet *pp = (Packet *)object; (void)pp;
switch (field) {
default: return nullptr;
}
}