Newer
Older
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
#include "BTPLayerFactory.hh"
#include "BTPTypes.hh"
#include "loggers.hh"
BTPLayer::BTPLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsBtp__TestSystem::BtpPort>(p_type), _params(), _codec(), _device_mode{false} {
loggers::get_instance().log(">>> BTPLayer::BTPLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
Params::convert(_params, param);
// Sanity check
Params::const_iterator it = _params.find(Params::btp_type);
if (it == _params.cend()) {
_params[Params::btp_type] = std::string("btpA");
}
it = _params.find(Params::btp_destination_port);
if (it == _params.cend()) {
_params[Params::btp_destination_port] = std::to_string(2001);
}
it = _params.find(Params::btp_info);
if (it == _params.cend()) {
_params[Params::btp_info] = std::to_string(0);
}
it = _params.find(Params::device_mode);
if (it != _params.cend()) {
_device_mode = (0 == str2int(CHARSTRING(it->second.c_str())));
}
}
void BTPLayer::sendMsg(const LibItsBtp__TestSystem::BtpReq& p, Params& params){
loggers::get_instance().log(">>> BTPLayer::sendMsg");
//params.log();
// Encode BTP PDU
OCTETSTRING data;
_codec.encode(p.msgOut(), data);
sendData(data, params);
}
void BTPLayer::sendData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> BTPLayer::sendData: ", data);
params.log(); // TODO To be removed
if (_device_mode) {
LibItsBtp__TypesAndValues::BtpHeader header;
if (_params[Params::btp_type].compare("btpA") == 0) {
header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
} else {
header.btpBHeader() = LibItsBtp__TypesAndValues::BtpBHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
}
LibItsBtp__TypesAndValues::BtpPacket p(
header,
data
);
loggers::get_instance().log_msg("BTPLayer::sendData: ", p);
// Encode BTP PDU
OCTETSTRING os;
_codec.encode(p, os);
data = os;
}
sendToAllLayers(data, params);
}
void BTPLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> BTPLayer::receiveData: ", data);
params.log();
// Decode the payload
LibItsBtp__TestSystem::BtpInd p;
Params::const_iterator it = params.find(Params::gn_next_header);
if (it != params.cend()) {
_codec.set_btp_type((it->second.compare("02") == 0) ? BTPCodec::btpB : BTPCodec::btpA);
}
_codec.decode(data, p.msgIn(), ¶ms);
// Pass the BTP raw payload to the upper layers if any
it = params.find(Params::btp_payload);
if (it != params.cend()) {
loggers::get_instance().log("BTPLayer::receiveData: btp_payload=%s", it->second.c_str());
OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str())));
receiveToAllLayers(os, params);
} else {
loggers::get_instance().warning("BTPLayer::receiveData: No payload to pass to upper layers");
}
// Pass it to the ports if any
//params.log();
toAllUpperPorts(p, params);
}
BTPLayerFactory BTPLayerFactory::_f;