Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Clock epoch_debug() , timestamp in micros #189

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tools/socktap/link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "udp_link.hpp"
#include <vanetza/access/ethertype.hpp>
#include <boost/asio/generic/raw_protocol.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

#ifdef SOCKTAP_WITH_COHDA_LLC
# include "cohda_link.hpp"
Expand Down Expand Up @@ -30,6 +32,42 @@ create_link_layer(boost::asio::io_service& io_service, const EthernetDevice& dev
ip::udp::endpoint multicast(ip::address::from_string("239.118.122.97"), 8947);
link_layer.reset(new UdpLink { io_service, multicast });
}
else if (name.find("udp-io") != std::string::npos ) { //Input-Output Unicast UDP
namespace ip = boost::asio::ip;
boost::system::error_code error_code;

ip::address ip_address = ip::make_address("127.0.0.1", error_code);
uint16_t udp_port_tx = 8947;
uint16_t udp_port_rx = udp_port_tx;

// TODO: It's time to have a configuration file as input.. yalm?
// Use: -l udp-io:<ip_dest>:<port_tx>:<port_rx>
std::vector<std::string> udp_unicast_split_data;
boost::algorithm::split(udp_unicast_split_data, name, boost::is_any_of(":"));
if(udp_unicast_split_data.size() == 4) {

auto ip_address_str = udp_unicast_split_data[1];
ip_address = ip::make_address(ip_address_str, error_code);
if (error_code)
{
auto error = std::string("Error parsing ip when using link-layer udp-io");
throw std::invalid_argument(error);
}

try {
udp_port_tx = std::stoi(udp_unicast_split_data[2]);
udp_port_rx = std::stoi(udp_unicast_split_data[3]);

}catch(...){
auto error = std::string("Error parsing ports when using link-layer udp-io");
throw std::invalid_argument(error);
}
}

ip::udp::endpoint unicast_tx(ip_address, udp_port_tx);
ip::udp::endpoint unicast_rx(ip::address::from_string("0.0.0.0"), udp_port_rx);
link_layer.reset(new UdpLink{io_service, unicast_tx, unicast_rx});
}

return link_layer;
}
3 changes: 2 additions & 1 deletion tools/socktap/router_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void RouterContext::set_link_layer(LinkLayer* link_layer)
void RouterContext::indicate(CohesivePacket&& packet, const EthernetHeader& hdr)
{
if (hdr.source != mib_.itsGnLocalGnAddr.mid() && hdr.type == access::ethertype::GeoNetworking) {
std::cout << "received packet from " << hdr.source << " (" << packet.size() << " bytes)\n";
auto time_of_day = Clock::at(trigger_.runtime().now());
std::cout << time_of_day<<" | "<<"received packet from " << hdr.source << " (" << packet.size() << " bytes)\n";
std::unique_ptr<PacketVariant> up { new PacketVariant(std::move(packet)) };
trigger_.schedule(); // ensure the clock is up-to-date for the security entity
router_.indicate(std::move(up), hdr.source, hdr.destination);
Expand Down
17 changes: 17 additions & 0 deletions tools/socktap/udp_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ UdpLink::UdpLink(boost::asio::io_service& io_service, const ip::udp::endpoint& e
do_receive();
}


UdpLink::UdpLink(boost::asio::io_service &io_service , const ip::udp::endpoint& endpoint_tx,
const boost::asio::ip::udp::endpoint& endpoint_rx):
multicast_endpoint_(endpoint_tx),
rx_endpoint_(endpoint_rx),
tx_socket_(io_service), rx_socket_(io_service),
rx_buffer_(2560, 0x00)
{
tx_socket_.open(multicast_endpoint_.protocol());

rx_socket_.open(rx_endpoint_.protocol());
rx_socket_.set_option(ip::udp::socket::reuse_address(true));
rx_socket_.bind(rx_endpoint_);

do_receive();
}

void UdpLink::indicate(IndicationCallback cb)
{
callback_ = cb;
Expand Down
1 change: 1 addition & 0 deletions tools/socktap/udp_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class UdpLink : public LinkLayer
{
public:
UdpLink(boost::asio::io_service&, const boost::asio::ip::udp::endpoint&);
UdpLink(boost::asio::io_service&, const boost::asio::ip::udp::endpoint&, const boost::asio::ip::udp::endpoint&);

void indicate(IndicationCallback) override;
void request(const vanetza::access::DataRequest&, std::unique_ptr<vanetza::ChunkPacket>) override;
Expand Down
5 changes: 5 additions & 0 deletions vanetza/common/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ Clock::time_point Clock::at(const std::string& at)
return Clock::at(boost::posix_time::time_from_string(at));
}

Clock::time_of_day Clock::time_at(const Clock::time_point& t){

return Clock::at(t).time_of_day();
}

} // namespace vanetza
9 changes: 8 additions & 1 deletion vanetza/common/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ class Clock
typedef std::chrono::duration<rep, period> duration;
typedef std::chrono::time_point<Clock> time_point;
typedef boost::posix_time::ptime date_time;
typedef boost::posix_time::time_duration time_of_day;

static constexpr bool is_steady() { return true; }
static time_point at(const date_time&);
static date_time at(const time_point&);
static const date_time& epoch();

/**
* \brief create time point
* \param at time string formatted like 2016-07-15 09:48:32
* \return time point
*/
static time_point at(const std::string& at);
/**
* \brief create time of day
* \param at time string formatted like 09:48:32.0000000
* \return time of day
*/
static time_of_day time_at(const Clock::time_point &t);

};

} // namespace vanetza
Expand Down