Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ITS - Intelligent Transport Systems
ITS
Commits
0ff22dff
Commit
0ff22dff
authored
Mar 22, 2018
by
garciay
Browse files
STF538: Start validation
parent
54dd2aa9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
346 additions
and
44 deletions
+346
-44
ccsrc/Framework/Params.hh
ccsrc/Framework/Params.hh
+9
-0
ccsrc/Framework/src/Params.cc
ccsrc/Framework/src/Params.cc
+8
-0
ccsrc/Ports/LibIts_ports/GN_ports/AdapterControlPort_GN.partC
...c/Ports/LibIts_ports/GN_ports/AdapterControlPort_GN.partC
+5
-0
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.cc
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.cc
+14
-4
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.hh
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.hh
+2
-0
ccsrc/Protocols/Security/security_services.cc
ccsrc/Protocols/Security/security_services.cc
+19
-11
ccsrc/Protocols/Security/security_services.hh
ccsrc/Protocols/Security/security_services.hh
+4
-4
ccsrc/Protocols/Tcp/TcpLayer_socketFactory.hh
ccsrc/Protocols/Tcp/TcpLayer_socketFactory.hh
+28
-0
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.cc
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.cc
+146
-0
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.hh
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.hh
+58
-0
ccsrc/Protocols/UpperTester/UpperTesterGnFactory.hh
ccsrc/Protocols/UpperTester/UpperTesterGnFactory.hh
+1
-1
ccsrc/Protocols/UpperTester/UpperTesterGnLayer.cc
ccsrc/Protocols/UpperTester/UpperTesterGnLayer.cc
+52
-24
No files found.
ccsrc/Framework/Params.hh
View file @
0ff22dff
...
...
@@ -21,6 +21,10 @@
class
Params
:
public
std
::
map
<
std
::
string
,
std
::
string
>
{
public:
//! \publicsection
// TODO Use static constexpr (see CommsigniaLayer.hh)
static
const
std
::
string
&
debug
;
//! Set to 1 to enable the debug mode
static
const
std
::
string
&
loopback
;
static
const
std
::
string
&
mac_src
;
//! Source MAC address parameter name
static
const
std
::
string
&
mac_dst
;
//! Destination MAC address parameter name
static
const
std
::
string
&
mac_bc
;
//! Broadcast MAC address parameter name
...
...
@@ -69,6 +73,11 @@ public: //! \publicsection
static
const
std
::
string
&
interface_id
;
//! Commsignia antenna selector
static
const
std
::
string
&
server
;
//! HTTP server address (e.g. www.etsi.org)
static
const
std
::
string
&
port
;
//! Commsignia HTTP server port. Default: 80
static
const
std
::
string
&
use_ssl
;
//! Set to 1 to use SSL to communicate with the HTTP server. Default: false
/*!
* \brief Default constructor
* Create a new instance of the Params class
...
...
ccsrc/Framework/src/Params.cc
View file @
0ff22dff
...
...
@@ -14,6 +14,10 @@
#include "Params.hh"
#include "loggers.hh"
const
std
::
string
&
Params
::
debug
=
std
::
string
(
"debug"
);
const
std
::
string
&
Params
::
loopback
=
std
::
string
(
"loopback"
);
const
std
::
string
&
Params
::
mac_src
=
std
::
string
(
"mac_src"
);
const
std
::
string
&
Params
::
mac_dst
=
std
::
string
(
"mac_dst"
);
const
std
::
string
&
Params
::
mac_bc
=
std
::
string
(
"mac_bc"
);
...
...
@@ -62,6 +66,10 @@ const std::string& Params::header_sub_type = std::string("header_sub_type");
const
std
::
string
&
Params
::
interface_id
=
std
::
string
(
"interface_id"
);
const
std
::
string
&
Params
::
server
=
std
::
string
(
"server"
);
const
std
::
string
&
Params
::
port
=
std
::
string
(
"port"
);
const
std
::
string
&
Params
::
use_ssl
=
std
::
string
(
"use_ssl"
);
void
Params
::
convert
(
Params
&
p_param
,
const
std
::
string
p_parameters
)
{
// Sanity checks
if
(
p_parameters
.
length
()
==
0
)
{
...
...
ccsrc/Ports/LibIts_ports/GN_ports/AdapterControlPort_GN.partC
View file @
0ff22dff
...
...
@@ -137,6 +137,11 @@ namespace LibItsGeoNetworking__TestSystem {
if (p->enable_secured_mode(str, send_par.acEnableSecurity().enforceSecurity()) == -1) {
response.acSecResponse() = BOOLEAN(false);
}
} else if (send_par.ischosen(LibItsCommon__TypesAndValues::AcSecPrimitive::ALT_acDisableSecurity)) {
loggers::get_instance().log("AdapterControlPort::outgoing_send: Disable secured mode");
if (p->disable_secured_mode() == -1) {
response.acSecResponse() = BOOLEAN(false);
}
} else {
response.acSecResponse() = BOOLEAN(false);
}
...
...
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.cc
View file @
0ff22dff
...
...
@@ -180,6 +180,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
loggers
::
get_instance
().
log_msg
(
">>> GeoNetworkingLayer::receiveData: "
,
data
);
// Check security mode
IEEE1609dot2
::
Ieee1609Dot2Data
ieee_1609dot2_data
;
LibItsGeoNetworking__TypesAndValues
::
BasicHeader
basic_header
;
decode_basic_header
(
data
,
basic_header
);
if
((
int
)
basic_header
.
nextHeader
()
==
2
)
{
// Verify and extract the GeoNetworking Secured Packet as specified in ETSI EN 302 636-4-1 V1.3.1 (2017-08) Clause 9.6.1 Composition of the Basic Header
...
...
@@ -195,7 +196,7 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
return
;
}
///////////////////
if
(
security_services
::
get_instance
().
verify_and_extract_gn_payload
(
secured_data
,
_enable_security_checks
,
unsecured_gn_payload
,
params
)
!=
0
)
{
if
(
security_services
::
get_instance
().
verify_and_extract_gn_payload
(
secured_data
,
_enable_security_checks
,
ieee_1609dot2_data
,
unsecured_gn_payload
,
params
)
!=
0
)
{
loggers
::
get_instance
().
warning
(
"GeoNetworkingLayer::receiveData: Security error"
);
if
(
_enable_security_checks
)
{
return
;
...
...
@@ -211,6 +212,11 @@ void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
LibItsGeoNetworking__TestSystem
::
GeoNetworkingInd
ind
;
_codec
.
decode
(
data
,
ind
.
msgIn
(),
&
params
);
if
(
ind
.
msgIn
().
is_bound
())
{
// Update optional securedMsg field if required
if
(
ieee_1609dot2_data
.
is_bound
())
{
ind
.
msgIn
().
gnPacket
().
securedMsg
()
=
OPTIONAL
<
IEEE1609dot2
::
Ieee1609Dot2Data
>
(
ieee_1609dot2_data
);
}
// else, nothing to do
// Update context
const
LibItsGeoNetworking__TypesAndValues
::
LongPosVector
*
sopv
=
nullptr
;
const
LibItsGeoNetworking__TypesAndValues
::
GnNonSecuredPacket
&
p
=
ind
.
msgIn
().
gnPacket
().
packet
();
const
LibItsGeoNetworking__TypesAndValues
::
HeaderTST
&
htst
=
p
.
commonHeader
().
headerTST
();
...
...
@@ -480,12 +486,9 @@ void GeoNetworkingLayer::stop_pass_beaconing() {
_pass_beacon_table
.
reset
();
}
// End of stop_pass_beaconing method
int
GeoNetworkingLayer
::
enable_secured_mode
(
const
std
::
string
&
p_certificate_id
,
const
boolean
p_enforce_security
)
{
loggers
::
get_instance
().
log
(
">>> GeoNetworkingLayer::enable_secured_mode: '%s' - %x"
,
p_certificate_id
.
c_str
(),
p_enforce_security
);
loggers
::
get_instance
().
log
(
"GeoNetworkingLayer::enable_secured_mode: GN Layer address = %p"
,
this
);
loggers
::
get_instance
().
log
(
"GeoNetworkingLayer::enable_secured_mode: _secured_mode = %x"
,
_secured_mode
);
if
(
!
_secured_mode
)
{
loggers
::
get_instance
().
log
(
"GeoNetworkingLayer::enable_secured_mode: Setup secured mode"
);
...
...
@@ -504,6 +507,13 @@ int GeoNetworkingLayer::enable_secured_mode(const std::string& p_certificate_id,
return
0
;
}
int
GeoNetworkingLayer
::
disable_secured_mode
()
{
loggers
::
get_instance
().
log
(
">>> GeoNetworkingLayer::disable_secured_mode"
);
_secured_mode
=
false
;
_enable_security_checks
=
false
;
return
0
;
}
const
LongPosVector
*
GeoNetworkingLayer
::
get_lpv
(
const
GN__Address
&
p_gn_address
)
{
loggers
::
get_instance
().
log_msg
(
">>> GeoNetworkingLayer::get_lpv"
,
p_gn_address
);
...
...
ccsrc/Protocols/GeoNetworking/GeoNetworkingLayer.hh
View file @
0ff22dff
...
...
@@ -126,7 +126,9 @@ public:
void
stop_beaconing
();
void
start_pass_beaconing
(
const
LibItsGeoNetworking__TypesAndValues
::
BeaconHeader
&
p_beacon
);
void
stop_pass_beaconing
();
int
enable_secured_mode
(
const
std
::
string
&
p_certificate_id
,
const
boolean
p_enforce_security
=
false
);
int
disable_secured_mode
();
private:
void
send_beacon
();
...
...
ccsrc/Protocols/Security/security_services.cc
View file @
0ff22dff
...
...
@@ -70,7 +70,7 @@ int security_services::store_certificate(const CHARSTRING& p_cert_id, const OCTE
return
_security_db
.
get
()
->
store_certificate
(
p_cert_id
,
p_cert
,
p_private_key
,
p_public_key_x
,
p_public_key_y
,
p_hashid8
,
p_issuer
,
p_private_enc_key
,
p_public_enc_key_x
,
p_public_enc_key_y
);
}
int
security_services
::
verify_and_extract_gn_payload
(
const
OCTETSTRING
&
p_secured_gn_payload
,
const
bool
p_verify
,
OCTETSTRING
&
p_unsecured_gn_payload
,
Params
&
p_params
)
{
int
security_services
::
verify_and_extract_gn_payload
(
const
OCTETSTRING
&
p_secured_gn_payload
,
const
bool
p_verify
,
IEEE1609dot2
::
Ieee1609Dot2Data
&
p_ieee_1609dot2_data
,
OCTETSTRING
&
p_unsecured_gn_payload
,
Params
&
p_params
)
{
loggers
::
get_instance
().
log_msg
(
">>> security_services::verify_and_extract_gn_payload: "
,
p_secured_gn_payload
);
// Sanity checks
...
...
@@ -79,20 +79,19 @@ int security_services::verify_and_extract_gn_payload(const OCTETSTRING& p_secure
}
// Decode the secured message (OER encoding)
IEEE1609dot2
::
Ieee1609Dot2Data
ieee_1609dot2_data
;
EtsiTs103097Codec_Data
codec
;
codec
.
decode
(
p_secured_gn_payload
,
ieee_1609dot2_data
,
&
p_params
);
codec
.
decode
(
p_secured_gn_payload
,
p_
ieee_1609dot2_data
,
&
p_params
);
// Sanity checks
if
(
!
ieee_1609dot2_data
.
is_bound
())
{
if
(
!
p_
ieee_1609dot2_data
.
is_bound
())
{
loggers
::
get_instance
().
warning
(
"security_services::verify_and_extract_gn_payload: Unbound value, discard it"
);
return
-
1
;
}
if
(
p_verify
&&
((
unsigned
int
)(
int
)
ieee_1609dot2_data
.
protocolVersion
()
!=
security_services
::
ProtocolVersion
))
{
if
(
p_verify
&&
((
unsigned
int
)(
int
)
p_
ieee_1609dot2_data
.
protocolVersion
()
!=
security_services
::
ProtocolVersion
))
{
loggers
::
get_instance
().
warning
(
"security_services::verify_and_extract_gn_payload: Wrong version protocol, discard it"
);
return
-
1
;
}
return
process_ieee_1609_dot2_content
(
ieee_1609dot2_data
.
content
(),
p_verify
,
p_unsecured_gn_payload
,
p_params
);
return
process_ieee_1609_dot2_content
(
p_
ieee_1609dot2_data
.
content
(),
p_verify
,
p_unsecured_gn_payload
,
p_params
);
}
// End of method verify_and_extract_gn_payload
int
security_services
::
process_ieee_1609_dot2_content
(
const
IEEE1609dot2
::
Ieee1609Dot2Content
&
p_ieee_1609_dot2_content
,
const
bool
p_verify
,
OCTETSTRING
&
p_unsecured_payload
,
Params
&
p_params
)
{
...
...
@@ -103,17 +102,24 @@ int security_services::process_ieee_1609_dot2_content(const IEEE1609dot2::Ieee16
}
else
if
(
p_ieee_1609_dot2_content
.
ischosen
(
IEEE1609dot2
::
Ieee1609Dot2Content
::
ALT_signedData
))
{
const
IEEE1609dot2
::
SignedData
&
signedData
=
p_ieee_1609_dot2_content
.
signedData
();
if
(
process_ieee_1609_dot2_signed_data
(
signedData
,
p_verify
,
p_unsecured_payload
,
p_params
)
!=
0
)
{
return
-
1
;
if
(
p_verify
)
{
return
-
1
;
}
}
}
else
if
(
p_ieee_1609_dot2_content
.
ischosen
(
IEEE1609dot2
::
Ieee1609Dot2Content
::
ALT_encryptedData
))
{
const
IEEE1609dot2
::
EncryptedData
&
encrypted_data
=
p_ieee_1609_dot2_content
.
encryptedData
();
OCTETSTRING
signed_payload
;
if
(
security_services
::
process_ieee_1609_dot2_encrypted_data
(
encrypted_data
,
p_verify
,
signed_payload
,
p_params
)
!=
0
)
{
return
-
1
;
if
(
p_verify
)
{
return
-
1
;
}
}
loggers
::
get_instance
().
log_msg
(
"security_services::process_ieee_1609_dot2_content: Decrypted payload: "
,
signed_payload
);
if
(
verify_and_extract_gn_payload
(
signed_payload
,
p_verify
,
p_unsecured_payload
,
p_params
)
!=
0
)
{
return
-
1
;
IEEE1609dot2
::
Ieee1609Dot2Data
ieee_1609dot2_data
;
// TODO Check if it could be reused
if
(
verify_and_extract_gn_payload
(
signed_payload
,
p_verify
,
ieee_1609dot2_data
,
p_unsecured_payload
,
p_params
)
!=
0
)
{
if
(
p_verify
)
{
return
-
1
;
}
}
}
else
if
(
p_ieee_1609_dot2_content
.
ischosen
(
IEEE1609dot2
::
Ieee1609Dot2Content
::
ALT_signedCertificateRequest
))
{
// Reset certificate timer
...
...
@@ -122,7 +128,9 @@ int security_services::process_ieee_1609_dot2_content(const IEEE1609dot2::Ieee16
return
0
;
}
else
{
// Shall never be reached
loggers
::
get_instance
().
warning
(
"security_services::process_ieee_1609_dot2_content: Undefined IEEE 1609.2 Content, discard it"
);
return
-
1
;
if
(
p_verify
)
{
return
-
1
;
}
}
loggers
::
get_instance
().
log_msg
(
"<<< security_services::process_ieee_1609_dot2_content: "
,
p_unsecured_payload
);
...
...
ccsrc/Protocols/Security/security_services.hh
View file @
0ff22dff
...
...
@@ -80,12 +80,12 @@ public: /*! \publicsection */
* The secured payload could signed only, encryted only or signed and encrypted
* \param[in] p_secured_gn_payload The secured payload to be processed
* \param[in] p_verify Set to true if security checks shall be applied
* \param[in] p_unsecured_gn_payload The extracted payload
* \param[in] p_params The Test System parameters
* \param[out] p_unsecured_gn_payload The extracted payload
* \param[out] p_ieee_1609dot2_data The secured message
* \param[inout] p_params The Test System parameters
* \return 0 on success, negative value otherwise
*/
int
verify_and_extract_gn_payload
(
const
OCTETSTRING
&
p_secured_gn_payload
,
const
bool
p_verify
,
OCTETSTRING
&
p_unsecured_gn_payload
,
Params
&
p_params
);
int
verify_and_extract_gn_payload
(
const
OCTETSTRING
&
p_secured_gn_payload
,
const
bool
p_verify
,
IEEE1609dot2
::
Ieee1609Dot2Data
&
p_ieee_1609dot2_data
,
OCTETSTRING
&
p_unsecured_gn_payload
,
Params
&
p_params
);
/*!
* \fn int secure_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_secured_gn_payload, Params& p_params);
* \brief Apply security to the provided unsecured payload
...
...
ccsrc/Protocols/Tcp/TcpLayer_socketFactory.hh
0 → 100644
View file @
0ff22dff
/*!
* \file TcpLayer_socketFactory.hh
* \brief Header file for ITS TcpLayer_socket protocol layer factory.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include "LayerStackBuilder.hh"
#include "TcpLayer_socketLayer.hh"
class
TcpLayer_socketFactory
:
public
LayerFactory
{
static
TcpLayer_socketFactory
_f
;
public:
TcpLayer_socketFactory
()
{
// Register factory
LayerStackBuilder
::
register_layer_factory
(
"TCP"
,
this
);
};
inline
virtual
Layer
*
create_layer
(
const
std
::
string
&
p_type
,
const
std
::
string
&
p_param
){
return
new
TcpLayer_socketLayer
(
p_type
,
p_param
);
};
};
// End of class TcpLayer_socketFactory
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.cc
0 → 100644
View file @
0ff22dff
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <chrono>
#include "Port.hh"
#include "TcpLayer_socketFactory.hh"
#include "loggers.hh"
TcpLayer_socketLayer
::
TcpLayer_socketLayer
(
const
std
::
string
&
p_type
,
const
std
::
string
&
param
)
:
SSL_Socket
(),
Layer
(
p_type
),
PORT
(
p_type
.
c_str
()),
_params
(),
_client_id
{
-
1
},
_time_key
(
"TcpLayer_socketLayer::Handle_Fd_Event_Readable"
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::TcpLayer_socketLayer: %s, %s"
,
to_string
().
c_str
(),
param
.
c_str
());
// Setup parameters
Params
::
convert
(
_params
,
param
);
_params
.
log
();
set_socket_debugging
(
false
);
Params
::
const_iterator
it
=
_params
.
find
(
Params
::
debug
);
if
(
it
==
_params
.
cend
())
{
_params
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
std
::
string
(
"debug"
),
"0"
));
}
else
if
(
it
->
second
.
compare
(
"1"
)
==
0
)
{
set_socket_debugging
(
true
);
}
it
=
_params
.
find
(
Params
::
server
);
if
(
it
==
_params
.
cend
())
{
_params
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
std
::
string
(
"server"
),
"127.0.0.1"
));
}
if
(
!
parameter_set
(
Params
::
server
.
c_str
(),
_params
[
Params
::
server
].
c_str
()))
{
loggers
::
get_instance
().
warning
(
"TcpLayer_socketLayer::set_parameter: Unprocessed parameter: %s"
,
Params
::
server
.
c_str
());
}
it
=
_params
.
find
(
Params
::
port
);
if
(
it
==
_params
.
cend
())
{
_params
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
std
::
string
(
"port"
),
"80"
));
}
if
(
!
parameter_set
(
Params
::
port
.
c_str
(),
_params
[
Params
::
port
].
c_str
()))
{
loggers
::
get_instance
().
warning
(
"TcpLayer_socketLayer::set_parameter: Unprocessed parameter: %s"
,
Params
::
server
.
c_str
());
}
set_ssl_use_ssl
(
false
);
it
=
_params
.
find
(
Params
::
use_ssl
);
if
(
it
==
_params
.
cend
())
{
_params
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
std
::
string
(
"use_ssl"
),
"0"
));
}
else
if
(
it
->
second
.
compare
(
"1"
)
==
0
)
{
set_ssl_use_ssl
(
true
);
}
parameter_set
(
use_connection_ASPs_name
(),
"no"
);
parameter_set
(
server_backlog_name
(),
"1024"
);
set_server_mode
(
false
);
set_ttcn_buffer_usercontrol
(
true
);
set_handle_half_close
(
true
);
set_ssl_use_ssl
(
false
);
map_user
();
_client_id
=
open_client_connection
(
_params
[
Params
::
server
].
c_str
(),
_params
[
Params
::
port
].
c_str
(),
NULL
,
NULL
);
}
TcpLayer_socketLayer
::~
TcpLayer_socketLayer
()
{
if
(
_client_id
!=
-
1
)
{
remove_client
(
_client_id
);
}
unmap_user
();
}
void
TcpLayer_socketLayer
::
Handle_Fd_Event
(
int
fd
,
boolean
is_readable
,
boolean
is_writable
,
boolean
is_error
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::Handle_Fd_Event: %d"
,
fd
);
Handle_Socket_Event
(
fd
,
is_readable
,
is_writable
,
is_error
);
log_debug
(
"<<< TcpLayer_socketLayer::Handle_Fd_Event"
);
}
void
TcpLayer_socketLayer
::
Handle_Timeout
(
double
time_since_last_call
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::Handle_Timeout: %f"
,
time_since_last_call
);
Handle_Timeout_Event
(
time_since_last_call
);
loggers
::
get_instance
().
log
(
"<<< TcpLayer_socketLayer::Handle_Timeout"
);
}
void
TcpLayer_socketLayer
::
sendData
(
OCTETSTRING
&
data
,
Params
&
params
)
{
loggers
::
get_instance
().
log_msg
(
">>> TcpLayer_socketLayer::sendData: "
,
data
);
send_message_on_fd
(
_client_id
,
static_cast
<
const
unsigned
char
*>
(
data
),
data
.
lengthof
());
}
void
TcpLayer_socketLayer
::
receiveData
(
OCTETSTRING
&
data
,
Params
&
params
)
{
loggers
::
get_instance
().
log_msg
(
">>> TcpLayer_socketLayer::receiveData: "
,
data
);
//
// float duration;
// loggers::get_instance().set_start_time(_time_key);
// this->receiveData(os, params); // TODO Check execution time for decoding operation
// loggers::get_instance().set_stop_time(_time_key, duration);
receiveToAllLayers
(
data
,
params
);
}
void
TcpLayer_socketLayer
::
message_incoming
(
const
unsigned
char
*
message_buffer
,
int
length
,
int
client_id
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::message_incoming"
);
loggers
::
get_instance
().
log_to_hexa
(
"TcpLayer_socketLayer::message_incoming: "
,
message_buffer
,
length
);
float
duration
;
loggers
::
get_instance
().
set_start_time
(
_time_key
);
OCTETSTRING
data
(
length
,
message_buffer
);
Params
params
;
this
->
receiveData
(
data
,
params
);
// TODO Check execution time for decoding operation
loggers
::
get_instance
().
set_stop_time
(
_time_key
,
duration
);
}
void
TcpLayer_socketLayer
::
client_connection_opened
(
int
p_client_id
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::client_connection_opened: %d"
,
p_client_id
);
}
int
TcpLayer_socketLayer
::
receive_message_on_fd
(
int
p_client_id
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::receive_message_on_fd: %d"
,
p_client_id
);
if
(
get_user_data
(
p_client_id
))
{
// INFO: it is assumed that only SSL_Socket assigns user data to each peer
loggers
::
get_instance
().
log
(
"TcpLayer_socketLayer::receive_message_on_fd: Call SSL_Socket::receive_message_on_fd"
);
return
SSL_Socket
::
receive_message_on_fd
(
p_client_id
);
}
loggers
::
get_instance
().
log
(
"TcpLayer_socketLayer::receive_message_on_fd: Call Abstract_Socket::receive_message_on_fd"
);
return
Abstract_Socket
::
receive_message_on_fd
(
p_client_id
);
}
void
TcpLayer_socketLayer
::
peer_half_closed
(
int
p_client_id
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::peer_half_closed: %d"
,
p_client_id
);
Abstract_Socket
::
peer_half_closed
(
p_client_id
);
}
void
TcpLayer_socketLayer
::
peer_disconnected
(
int
p_client_id
)
{
loggers
::
get_instance
().
log
(
">>> TcpLayer_socketLayer::peer_disconnected: %d"
,
p_client_id
);
Abstract_Socket
::
peer_disconnected
(
p_client_id
);
}
TcpLayer_socketFactory
TcpLayer_socketFactory
::
_f
;
ccsrc/Protocols/Tcp/TcpLayer_socketLayer.hh
0 → 100644
View file @
0ff22dff
/*!
* \file TcpLayer_socketLayer.hh
* \brief Header file for ITS TcpLayer_socket protocol layer.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include "TLayer.hh"
#include "Abstract_Socket.hh"
class
PORT
;
class
TcpLayer_socketLayer
:
public
SSL_Socket
,
public
Layer
,
public
PORT
{
Params
_params
;
int
_client_id
;
std
::
string
_time_key
;
public:
TcpLayer_socketLayer
(
const
std
::
string
&
p_type
,
const
std
::
string
&
param
);
virtual
~
TcpLayer_socketLayer
();
virtual
void
sendData
(
OCTETSTRING
&
data
,
Params
&
params
);
virtual
void
receiveData
(
OCTETSTRING
&
data
,
Params
&
info
);
virtual
void
message_incoming
(
const
unsigned
char
*
message_buffer
,
int
length
,
int
client_id
=
-
1
);
protected:
void
Add_Fd_Read_Handler
(
int
fd
)
{
Handler_Add_Fd_Read
(
fd
);
};
void
Add_Fd_Write_Handler
(
int
fd
)
{
Handler_Add_Fd_Write
(
fd
);
};
void
Remove_Fd_Read_Handler
(
int
fd
)
{
Handler_Remove_Fd_Read
(
fd
);
};
void
Remove_Fd_Write_Handler
(
int
fd
)
{
Handler_Remove_Fd_Write
(
fd
);
};
void
Remove_Fd_All_Handlers
(
int
fd
)
{
Handler_Remove_Fd
(
fd
);
};
void
Handler_Uninstall
()
{
Uninstall_Handler
();
}
void
Timer_Set_Handler
(
double
call_interval
,
boolean
is_timeout
=
TRUE
,
boolean
call_anyway
=
TRUE
,
boolean
is_periodic
=
TRUE
)
{
Handler_Set_Timer
(
call_interval
,
is_timeout
,
call_anyway
,
is_periodic
);
};
const
char
*
remote_address_name
()
{
return
Params
::
server
.
c_str
();
};
const
char
*
remote_port_name
()
{
return
Params
::
port
.
c_str
();
};
const
char
*
socket_debugging_name
()
{
return
Params
::
debug
.
c_str
();
};
void
client_connection_opened
(
int
p_client_id
);
int
receive_message_on_fd
(
int
p_client_id
);
void
peer_disconnected
(
int
p_client_id
);
void
peer_half_closed
(
int
p_client_id
);
private:
void
Handle_Fd_Event
(
int
fd
,
boolean
is_readable
,
boolean
is_writable
,
boolean
is_error
);
void
Handle_Timeout
(
double
time_since_last_call
);
};
// End of class TcpLayer_socketLayer
ccsrc/Protocols/UpperTester/UpperTesterGnFactory.hh
View file @
0ff22dff
/*!
* \file UpperTesterGnFactory.hh
* \brief Header file for ITS
DENM
Upper Tester protocol layer factory.
* \brief Header file for ITS
GeoNetworking
Upper Tester protocol layer factory.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
...
...
ccsrc/Protocols/UpperTester/UpperTesterGnLayer.cc
View file @
0ff22dff
...
...
@@ -8,53 +8,81 @@ UpperTesterGnLayer::UpperTesterGnLayer(const std::string & p_type, const std::st
loggers
::
get_instance
().
log
(
">>> UpperTesterGnLayer::UpperTesterGnLayer: %s, %s"
,
to_string
().
c_str
(),
param
.
c_str
());
// Setup parameters
Params
::
convert
(
_params
,
param
);
Params
::
const_iterator
it
=
_params
.
find
(
Params
::
loopback
);
if
(
it
==
_params
.
cend
())
{
_params
.
insert
(
std
::
pair
<
std
::
string
,
std
::
string
>
(
Params
::
loopback
,
"0"
));
}
}
void
UpperTesterGnLayer
::
sendMsg
(
const
LibItsGeoNetworking__TypesAndValues
::
UtGnInitialize
&
send_par
,
Params
&
params
){
loggers
::
get_instance
().
log_msg
(
">>> UpperTesterGnLayer::sendMsg"
,
send_par
);
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
(
static_cast
<
const
Record_Type
&>
(
send_par
),
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
if
(
_params
[
Params
::
loopback
].
compare
(
"1"
)
==
0
)
{
LibItsGeoNetworking__TypesAndValues
::
UtGnResults
ut_gn_results
;
ut_gn_results
.
utGnInitializeResult
()
=
BOOLEAN
(
true
);
toAllUpperPorts
(
ut_gn_results
,
params
);
}
else
{
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
(
static_cast
<
const
Record_Type
&>
(
send_par
),
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
}
}
void
UpperTesterGnLayer
::
sendMsg
(
const
LibItsGeoNetworking__TypesAndValues
::
UtGnChangePosition
&
send_par
,
Params
&
params
)
{
loggers
::
get_instance
().
log_msg
(
">>> UpperTesterGnLayer::sendMsg"
,
send_par
);
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
(
static_cast
<
const
Record_Type
&>
(
send_par
),
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
if
(
_params
[
Params
::
loopback
].
compare
(
"1"
)
==
0
)
{
LibItsGeoNetworking__TypesAndValues
::
UtGnResults
ut_gn_results
;
ut_gn_results
.
utGnChangePositionResult
()
=
BOOLEAN
(
true
);
toAllUpperPorts
(
ut_gn_results
,
params
);
}
else
{
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
(
static_cast
<
const
Record_Type
&>
(
send_par
),
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
}
}
void
UpperTesterGnLayer
::
sendMsg
(
const
LibItsGeoNetworking__TypesAndValues
::
UtGnTrigger
&
send_par
,
Params
&
params
)
{
loggers
::
get_instance
().
log_msg
(
">>> UpperTesterGnLayer::sendMsg"
,
send_par
);
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
((
const
Record_Type
&
)
send_par
,
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
if
(
_params
[
Params
::
loopback
].
compare
(
"1"
)
==
0
)
{
LibItsGeoNetworking__TypesAndValues
::
UtGnResults
ut_gn_results
;
ut_gn_results
.
utGnTriggerResult
()
=
BOOLEAN
(
true
);
toAllUpperPorts
(
ut_gn_results
,
params
);
}
else
{
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
((
const
Record_Type
&
)
send_par
,
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
}
}
void
UpperTesterGnLayer
::
sendMsg
(
const
LibItsGeoNetworking__TypesAndValues
::
UtAutoInteropTrigger
&
send_par
,
Params
&
params
)
{
loggers
::
get_instance
().
log_msg
(
">>> UpperTesterGnLayer::sendMsg"
,
send_par
);
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
((
const
Record_Type
&
)
send_par
,
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
if
(
_params
[
Params
::
loopback
].
compare
(
"1"
)
==
0
)
{
LibItsGeoNetworking__TypesAndValues
::
UtGnResults
ut_gn_results
;
ut_gn_results
.
utGnTriggerResult
()
=
BOOLEAN
(
true
);
toAllUpperPorts
(
ut_gn_results
,
params
);
}
else
{
// Encode UpperTester PDU
OCTETSTRING
data
;
_codec
.
encode
((
const
Record_Type
&
)
send_par
,
data
);
// Update parameters
Params
par
(
params
);
// FIXME Review all const Param& in method declarations
sendData
(
data
,
params
);
}
}
void
UpperTesterGnLayer
::
sendData
(
OCTETSTRING
&
data
,
Params
&
params
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment