Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d42986
HELICS module skeleton and waf script to specify helics location
nightlark Oct 5, 2017
6ec1cda
Move HELICS module from src to contrib folder
nightlark Oct 9, 2017
b8ddc1d
ns-3 bake module config for helics
nightlark Oct 13, 2017
5d76b3a
Find boost and zmq in waf script
nightlark Oct 25, 2017
8d41ac1
HelicsSimulatorImpl using MessageFederate -- possible hanging issue w…
nightlark Oct 25, 2017
cbe067f
Fix static global federate variable
nightlark Oct 25, 2017
ee184f5
add command line parsing to helics example
Oct 25, 2017
f3eb9ed
event loop logic changed to nextTime <= grantedTime, from <.
Oct 26, 2017
d0e8932
add helics application
Oct 27, 2017
1f0c3aa
update helics example
Oct 27, 2017
55268ee
add comment to helics example
Nov 2, 2017
cd6eb2a
Change optional feature name to helics integration for failed to find…
nightlark Nov 30, 2017
80f02bb
Merge branch 'helics' of https://github.com/GMLC-TDC/ns-3-dev-git int…
nightlark Nov 30, 2017
c2e4661
move simple federate code into separate executable
Dec 7, 2017
fff9b6d
add helics examples for using messages directly
Dec 8, 2017
151dca3
Merge branch 'master' into helics
nightlark Dec 12, 2017
2fe4f69
Updated helics header includes and federate type for version 0.9
nightlark Dec 12, 2017
87b1977
Update to use HELICS 0.9 filter API
nightlark Jan 2, 2018
07dc920
Update examples with HELICS 0.9 headers
nightlark Jan 2, 2018
f7005d9
Updated HELICS lib name from helics to helics-static
nightlark Jan 5, 2018
a2a4f06
Change lib for helics conf check to helics-static
nightlark Jan 5, 2018
ddf2ce7
Search lib64 directory for helics library if not in lib directory
nightlark Jan 17, 2018
d2dd8f0
Update to build with helics 1.0 alpha
nightlark Jan 17, 2018
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
Prev Previous commit
Next Next commit
Update to use HELICS 0.9 filter API
  • Loading branch information
nightlark committed Jan 2, 2018
commit 87b197759546433a1bc428c47ac38dc999849ad7
42 changes: 29 additions & 13 deletions contrib/helics/model/helics-application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ HelicsApplication::SetFilterName (const std::string &name)
Names::Add("helics_filter_"+name, this);
m_filter_id = helics_federate->registerSourceFilter ("ns3_"+name, name);
using std::placeholders::_1;
using std::placeholders::_2;
std::function<void(helics::filter_id_t,helics::Time)> func;
func = std::bind (&HelicsApplication::FilterCallback, this, _1, _2);
helics_federate->registerFilterCallback(m_filter_id, func);
std::function<void(std::unique_ptr<helics::Message>)> func;
func = std::bind (&HelicsApplication::FilterCallback, this, _1);
m_filterOp = std::make_shared<Ns3Operator> (func);
helics_federate->setFilterOperator (m_filter_id, m_filterOp);
}

void
Expand Down Expand Up @@ -251,26 +251,23 @@ HelicsApplication::NewTag ()
}

void
HelicsApplication::FilterCallback (helics::filter_id_t id, helics::Time time)
HelicsApplication::FilterCallback (std::unique_ptr<helics::Message> message)
{
NS_LOG_FUNCTION (this << "Helics filter callback");

Ptr<Packet> p;

// Get the helics Message.
auto m = helics_federate->getMessageToFilter (id);

// Find the HelicsApplication for the destination.
Ptr<HelicsApplication> to = Names::Find<HelicsApplication>("helics_"+m->dest);
Ptr<HelicsApplication> to = Names::Find<HelicsApplication>("helics_"+message->dest);
if (!to) {
NS_FATAL_ERROR("failed HelicsApplication lookup to '" << m->dest << "'");
NS_FATAL_ERROR("failed HelicsApplication lookup to '" << message->dest << "'");
}

// Convert given Message into a Packet.
size_t total_size = m->data.size();
size_t total_size = message->data.size();
uint8_t *buffer = new uint8_t[total_size];
uint8_t *buffer_ptr = buffer;
std::transform (m->data.begin(), m->data.end(), buffer_ptr, char_to_uint8_t);
std::transform (message->data.begin(), message->data.end(), buffer_ptr, char_to_uint8_t);
p = Create<Packet> (buffer, total_size);
NS_LOG_INFO("buffer='" << p << "'");
delete [] buffer;
Expand All @@ -282,7 +279,7 @@ HelicsApplication::FilterCallback (helics::filter_id_t id, helics::Time time)
p->AddPacketTag(tag);

// Store the Message at the destination application for later sending.
to->m_messages.insert(std::make_pair(tag, std::move (m)));
to->m_messages.insert(std::make_pair(tag, std::move (message)));

// call to the trace sinks before the packet is actually sent,
// so that tags added to the packet can be sent as well
Expand Down Expand Up @@ -473,4 +470,23 @@ HelicsApplication::HandleRead (Ptr<Socket> socket)
}
}

/** HELICS message FilterOperator for ns3 */

HelicsApplication::Ns3Operator::Ns3Operator (std::function<void(std::unique_ptr<helics::Message> message)> cb)
{
setFilterCallback (cb);
}

void
HelicsApplication::Ns3Operator::setFilterCallback (std::function<void(std::unique_ptr<helics::Message> message)> cb)
{
filterCallback = cb;
}

std::unique_ptr<helics::Message>
HelicsApplication::Ns3Operator::process (std::unique_ptr<helics::Message> message)
{
return nullptr;
}

} // Namespace ns3
20 changes: 18 additions & 2 deletions contrib/helics/model/helics-application.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Inet6SocketAddress;
*
* Every packet sent should be returned by the server and received here.
*/
class HelicsApplication : public Application
class HelicsApplication : public Application
{
public:
/**
Expand Down Expand Up @@ -103,7 +103,7 @@ class HelicsApplication : public Application
*
* This function is called internally by HELICS.
*/
void FilterCallback (helics::filter_id_t id, helics::Time time);
void FilterCallback (std::unique_ptr<helics::Message> message);

/**
* \brief Receive a HELICS message.
Expand Down Expand Up @@ -151,6 +151,22 @@ class HelicsApplication : public Application
helics::filter_id_t m_filter_id;
helics::endpoint_id_t m_endpoint_id;
std::map<uint32_t,std::unique_ptr<helics::Message> > m_messages;

class Ns3Operator : public helics::FilterOperator
{
public:
/** default constructor */
Ns3Operator () = default;
/** set the filter callback function in the constructor */
Ns3Operator (std::function<void(std::unique_ptr<helics::Message> message)> cb);
/** set the filter callback function */
void setFilterCallback (std::function<void(std::unique_ptr<helics::Message> message)> cb);
private:
std::function<void(std::unique_ptr<helics::Message> message)> filterCallback; //!<the filter callback function
virtual std::unique_ptr<helics::Message> process (std::unique_ptr<helics::Message> message) override;
};

std::shared_ptr<Ns3Operator> m_filterOp; //!< the filter operator for this application
};

} // namespace ns3
Expand Down