Skip to Main Content
Intel Threading Building Blocks
book

Intel Threading Building Blocks

by James Reinders
July 2007
Intermediate to advanced content levelIntermediate to advanced
332 pages
10h 4m
English
O'Reilly Media, Inc.
Content preview from Intel Threading Building Blocks

Class forwarding : public tbb::filter

The filter class forwarding (Example 11-48) performs a very simple packet forwarding operation. If the packet is inbound, it uses the network_table to select a NIC. Outbound packets can go to only one place, which is the NIC connected to the outbound Ethernet link. (In the NIC IP bindings in the input file, we made the simplifying assumption that the first pair was the outward link.) See Example 11-49 for the packet processing main program.

Example 11-48. Forwarding filter

class forwarding : public tbb::filter { const ip_t outgoing_ip; const nic_t outgoing_nic; network_table& network_config; public: forwarding (ip_t& _outgoing_ip, nic_t& _outgoing_nic, network_table& _network_config) : outgoing_ip(_outgoing_ip), outgoing_nic(_outgoing_nic), network_config(_network_config), filter (false /* is_serial*/) { } void* operator() (void* item) { packet_trace* packet = static_cast<packet_trace*> (item); if (packet->packetNic == outgoing_nic) { // packet is inbound, so translate it to the target Mac nic_t nextNic; if (find_next_hop (packet->packetDestIp, nextNic)) packet->packetNic = nextNic; else cerr << "No next hop found" << endl; } else { // packet is outbound, only one place it can go packet->packetSrcIp = outgoing_ip; packet->packetNic = outgoing_nic; } return packet; } bool find_next_hop (ip_t& ip, nic_t& nic) { network_table::const_accessor a; // acquires reader lock if (network_config.find (a, ip)) { nic = a->second; return true; } return false; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Intel® Xeon Phi™ Coprocessor Architecture and Tools: The Guide for Application Developers

Rezaur Rahman

Publisher Resources

ISBN: 9780596514808Errata Page