This repository has been archived by the owner on Oct 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LLTRUtils.h
87 lines (66 loc) · 1.96 KB
/
LLTRUtils.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
// LLTRUtils.h: Declares/Defines LLTR Utilities.
//
#ifndef __LLTR_UTILITIES_H
#define __LLTR_UTILITIES_H
#include <array>
#include "inet/common/INETDefs.h"
#include "inet/common/ModuleAccess.h"
#include "inet/transportlayer/contract/tcp/TCPSocket.h"
namespace LLTR {
using namespace inet;
const uint32 getHostsCount(cComponentType const *const hostType);
//Hosts path. Default path - "hostS"
//Define for fast copy/paste in the future.
class HostPath_defSuperHost_
{public:
//char path[15] = "hostS\0\0\0\0\0\0\0\0\0"; //not support //default "hostS"
//char path[15] = {'h','o','s','t','S','\0','\0','\0','\0','\0','\0','\0','\0','\0', '\0'}; //bad code gen //default "hostS"
std::array<char,15> path{"hostS\0\0\0\0\0\0\0\0\0"}; //default "hostS"
//default path - "hostS"
HostPath_defSuperHost_() = default;
HostPath_defSuperHost_(const uint32 hostId)
{
SetHost(hostId);
}
HostPath_defSuperHost_& SetSuperHost()
{
path[4]='S';
path[5]='\0';
return *this;
}
HostPath_defSuperHost_& SetHost(const uint32 hostId)
{
itoa10(hostId, &path[4]);
return *this;
}
const L3Address GetIp() const
{
IInterfaceTable *inet_ift = dynamic_cast<IInterfaceTable*>(getSimulation()->getModuleByPath(path.data())->getSubmodule("interfaceTable"));
return inet_ift->getInterfaceById( inet_ift->getBiggestInterfaceId() )->getNetworkAddress();
}
const L3Address operator() (const uint32 hostId)
{
SetHost(hostId);
return GetIp();
}
// http://www.jb.man.ac.uk/~slowe/cpp/itoa.html
char* itoa10(uint32 value, char* result) const
{
char* ptr = result, *ptr1 = result, tmp_char;
uint32 tmp_value;
do{
tmp_value = value;
value /= 10;
*ptr++ = '0' + (tmp_value - value*10);
}while(value);
*ptr-- = '\0';
while(ptr1 < ptr) {
tmp_char = *ptr;
*ptr-- = *ptr1;
*ptr1++ = tmp_char;
}
return result;
}
};
}
#endif // ifndef __LLTR_UTILITIES_H