Skip to content

Commit

Permalink
update includes redaction with random identifiers; updated the unit t…
Browse files Browse the repository at this point in the history
…ests; added support for logging -- all appears to work.
  • Loading branch information
jmcarter9t committed Jun 13, 2017
1 parent d7a8815 commit b8cd965
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 169 deletions.
5 changes: 2 additions & 3 deletions config/example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ privacy.filter.velocity.max=35.763

# Configuration details for privacy ID redaction.
privacy.redaction.id=ON
privacy.redaction.id.value=FFFFFFFF
privacy.redaction.id.inclusions=ON
privacy.redaction.id.inclusions=OFF
privacy.redaction.id.included=BEA10000,BEA10001,ON-VG-99

# Configuration details for geofencing.
Expand All @@ -26,7 +25,7 @@ privacy.topic.producer=j2735BsmFilteredJson
# Amount of time to wait when no message is available (milliseconds)
# This is a Kafka configuration parameter that we are using for the
# intended purpose.
privacy.consumer.timeout.ms=1000
privacy.consumer.timeout.ms=5000

group.id=0

Expand Down
9 changes: 6 additions & 3 deletions cv-lib/include/osm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define CVDP_DI_OSM_HPP

#include "names.hpp"
#include <exception>
#include <sstream>

namespace osm {

Expand Down Expand Up @@ -114,8 +116,9 @@ extern HighwayWidthMap highway_width_map; ///< A l
class invalid_way_exception : public std::runtime_error
{
private:
Highway type; ///< The Highway type that triggered the exception.
static int count; ///< The number of times the exception was triggered during a run.
static int count_; ///< The number of times the exception was triggered during a run.
std::string message_; ///< The exception message;
Highway type_; ///< The Highway type that triggered the exception.

public:

Expand All @@ -127,7 +130,7 @@ class invalid_way_exception : public std::runtime_error
invalid_way_exception( const Highway& way_type );

/**
* @brief Generate and return the exception message string.
* @brief Return the exception message string.
*
* @return The exception message as a constant pointer to a character string.
*/
Expand Down
19 changes: 11 additions & 8 deletions cv-lib/src/osm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* Oak Ridge National Laboratory, Center for Trustworthy Embedded Systems, UT Battelle.
*/

#include <iostream>
#include "osm.hpp"

namespace std {
Expand Down Expand Up @@ -175,25 +176,27 @@ namespace osm {
HighwaySet highway_blacklist{ Highway::PEDESTRIAN, Highway::SERVICE };

invalid_way_exception::invalid_way_exception( const Highway& way_type ) :
runtime_error{ "way type excluded from use in quad map" },
type{way_type}
runtime_error{"way type excluded from use in quad map"},
type_{way_type},
message_{ runtime_error::what() }
{
// count up the number of blacklisted ways found.
++count;
++count_;
message_ += " [" + std::to_string(count_) + "] : ";
message_ += std::to_string(static_cast<int>(type_));
}

const char* invalid_way_exception::what() const noexcept
{
std::string r{ runtime_error::what() };
r = r + " [" + std::to_string(count) + "] : " + std::to_string(static_cast<int>(type));
return r.c_str();
// CANNOT CONSTRUCT THE ERROR MESSAGE HERE!!
return message_.c_str();
}

int invalid_way_exception::count = 0;
int invalid_way_exception::count_ = 0;

int invalid_way_exception::occurrences() const
{
return count;
return count_;
}
}

Expand Down
2 changes: 1 addition & 1 deletion cv-lib/src/shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void CSVInputFactory::make_edge(const StrVector& line_parts) {
auto blacklist_item = osm::highway_blacklist.find( way_type );
if (blacklist_item != osm::highway_blacklist.end()) {
// this edge type should be ignored since it is in the blacklist.
throw osm::invalid_way_exception( way_type );
throw osm::invalid_way_exception{ way_type };
}
}

Expand Down
38 changes: 19 additions & 19 deletions data/bsm.wy.test.json

Large diffs are not rendered by default.

63 changes: 55 additions & 8 deletions include/bsmfilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <string>
#include <stack>
#include <vector>
#include <random>
#include "rapidjson/reader.h"
#include "cvlib.hpp"

Expand Down Expand Up @@ -162,6 +163,13 @@ class IdRedactor {
*/
bool RemoveIdInclusion( const std::string& id );

/**
* @brief Build and return a new randomly generated unsigned 32-bit identifier in hex to replace the current identifier.
*
* @return a hexidecimal string of a random unsigned 32-bit integer (based on the J2735 specification).
*/
std::string GetRandomId();

/**
* @brief Operator to redact (or retain) an id.
*
Expand All @@ -178,7 +186,10 @@ class IdRedactor {
*/
const std::string& redaction_value() const;


private:
std::mt19937 rgen_; ///< random number generator (mersenne twister).
std::uniform_int_distribution<uint32_t> dist_;
InclusionSetType inclusion_set_; ///< The set of ids on which to perform redaction.
std::string redacted_value_; ///< The value to assign to those ids that require redaction.
bool inclusions_; ///< Flag indicating whether this redactor will use the inclusion_set.
Expand Down Expand Up @@ -314,20 +325,55 @@ class BSM : public geo::Point {
*/
void set_longitude( double longitude );

/**
* @brief Set the BSM's secMark.
*
* @param dsec the secMark (DSeconds) field of the BSM.
*/
void set_secmark( uint16_t dsec );

/**
* @brief Get the BSM's secMark.
*
* @return the BSM's current secMark value.
*/
uint16_t get_secmark() const;

/**
* @brief Set the temporary ID field for the BSM
*
* @param id the temporary id for the BSM.
*/
void set_id( const std::string& s );

/**
* @brief Set the original id field for the BSM; for unit testing.
*
* @param the original id in the BSM.
*/
void set_original_id( const std::string& s );

/**
* @brief Get the temporary ID field for the BSM
*
* @return a const reference to the temporary id for the BSM.
*/
const std::string& get_id() const;

/**
* @brief Get the original ID field for the BSM; for unit testing.
*
* @return a const reference to the original id for the BSM.
*/
const std::string& get_original_id() const;

/**
* @brief Get a string representation of this BSM for the log.
*
* @return a string for the log that characterizes this BSM.
*/
std::string logString();

/**
* @brief Write the BSM in readable form to the provided output stream.
*
Expand All @@ -337,9 +383,12 @@ class BSM : public geo::Point {
friend std::ostream& operator<<( std::ostream& os, const BSM& bsm );

private:
double velocity_; ///< the velocity of the BSM.
std::string id_; ///< the id of the BSM.
char* end_; ///< pointer to the last character parsed.
double velocity_; ///< the velocity of the BSM.
uint16_t dsec_; ///< the dsecond field if it exists.
std::string id_; ///< the id of the BSM.
std::string oid_; ///< the original id of the BSM.
char* end_; ///< pointer to the last character parsed.
std::string logstring_; ///< a string to build for logging about the BSM.
};

/**
Expand Down Expand Up @@ -385,7 +434,7 @@ class BSMHandler : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, BSMHan
* @param quad_ptr the quad tree containing the map elements.
* @param conf the user-specified configuration.
*/
BSMHandler(Quad::Ptr quad_ptr, const ConfigMap& conf);
BSMHandler(Quad::Ptr quad_ptr, const ConfigMap& conf );

/**
* @brief Predicate indicating whether the BSM's position is within the prescribed geofence.
Expand Down Expand Up @@ -426,9 +475,9 @@ class BSMHandler : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, BSMHan
/**
* @brief Return a reference to the BSM instance generated during processing of a JSON string.
*
* @return a constant reference to the BSM instance.
* @return a reference to the BSM instance.
*/
const BSM& get_bsm() const;
BSM& get_bsm();

/**
* @brief Return the processed BSM as a JSON string including any changes made due to redaction of fields. This string
Expand Down Expand Up @@ -606,8 +655,6 @@ class BSMHandler : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, BSMHan
IdRedactor idr_; ///< The ID Redactor to use during parsing of BSMs.

double box_extension_; ///< The number of meters to extend the boxes that surround edges and define the geofence.

char* end_; ///< A temporary pointer to the end of a string.
};

#endif
15 changes: 13 additions & 2 deletions include/ppm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ class PPM : public tool::Tool {
bool configure();
bool launch_consumer();
bool launch_producer();
//RdKafka::ErrorCode msg_consume(RdKafka::Message* message, void* opaque, BSMHandler& handler);
bool msg_consume(RdKafka::Message* message, void* opaque, BSMHandler& handler);
Quad::Ptr BuildGeofence( const std::string& mapfile );
int operator()(void);
bool make_loggers();

/**
* @brief Create and setup the two loggers used for the PPM. The locations and filenames for the logs can be specified
* using command line parameters. The CANNOT be set via the configuration file, since these loggers are setup
* prior to the configuration file being read.
*
* If the log directory does not exist it will be created.
*
* Log files will be appended to, unless specified by a command line option.
*
* @return true upon success; false if some failure occurred during logger setup.
*/
bool make_loggers( bool remove_files );

private:

Expand Down
Loading

0 comments on commit b8cd965

Please sign in to comment.