C++ Implementation of Flow-Based Programming (FBP)
In computer programming, flow-based programming (FBP) is a programming paradigm that defines applications as networks of "black box" processes, which exchange data across predefined connections by message passing, where the connections are specified externally to the processes. These black box processes can be reconnected endlessly to form different applications without having to be changed internally. FBP is thus naturally component-oriented.
FBP is a particular form of dataflow programming based on bounded buffers, information packets with defined lifetimes, named ports, and separate definition of connections.
One interesting aspect of this implementation is that it supports the scripting language Lua
, so large parts of your networks can be written in a scripting language if desired.
Web sites for FBP:
Sample Component, Component API and Network Definitions
Services supported by Lua interface, and some sample CppFBP/Lua scripts
Download and install Visual C++ 2010 Express (or higher version)
Download and install Boost
- http://www.boost.org/
Download and install Lua
- http://www.lua.org/
Update following macros with correct version numbers: BOOST_INCLUDE
, BOOST_LIB
, LUA_INCLUDE
, LUA_LIB
, as follows:
- Go to
View/Other Windows/Property Manager/SolutionSettings
- Expand, showing
Debug
- Expand, showing
UserMacros
- Select
UserMacros
- Go to
UserMacros
underCommon Properties
- Click on that, revealing the 4 macros; change version numbers if necessary
- Leave the
set this macro as an environment variable in the build environment
option set to selected
or, more simply, in Windows Explorer, just go to SolutionSettings
, open it, open UserMacros.props
, and make, apply and save your changes.
Create empty cppfbp
directory in your local GitHub directory
Do git clone https://github.com/jpaulm/cppfbp
Now go into Visual C++, and Open/Project/Solution
CppFBP.sln
(in the just cloned directory)
There will be a "solution" line, followed by a number of "projects" - two of which are CppFBPCore
and CppFBPComponents
.
Do these builds in this order:
- Right click on
CppFBPCore
and do aBuild
- Right click on
CppFBPComponents
and do aBuild
- Right click on
TestSubnets
and do aBuild
Right click on the "solution" line, and do Build Solution
If you get errors, you may have to build individual projects (sometimes this will require more than one try); if you only get warnings, you can proceed
The projects whose names are of the form xxxDyn
are "dynamic" versions of the projects named xxx
- they start by scanning off the .fbp
network definitions (via the CppFBP
module with the DYNAM
parameter set to true
), and then run the resulting network structures.
This test case has 5 Generate/Drop process pairs, over each of which 1,000,000 IPs travel concurrently.
To run it, right click on TimingTest1
in Solution Explorer; Debug/Start new instance
You should see something like
Elapsed time in seconds: 35.000
Press any key to continue . . .
The elapsed time will of course depend on your machine processing speed, number of cores, etc.
This runs a simple network, where every process is a Lua script being executed by the general ThLua
component.
This test case only has 1,000,000 IPs travelling through the network, where half are generated by each Generate process. The network in free-form notation is as follows:
Gen(ThLua), Gen2(ThLua),
Concat(ThLua), Repl(ThLua), Drop(ThLua),
Gen OUT -> IN[0] Concat, Gen2 OUT -> IN[1] Concat,
Concat OUT -> IN Repl OUT -> IN Drop,
'500000' -> COUNT Gen,
'500000' -> COUNT Gen2,
'gen.lua' -> PROG Gen,
'gen.lua' -> PROG Gen2,
'concat.lua' -> PROG Concat,
'repl.lua' -> PROG Repl,
'drop.lua' -> PROG Drop;
To run it, right click on TryLua
in Solution Explorer; Debug/Start new instance
You should see something like
500000
500000
1000000
Elapsed time in seconds: 43.000
Press any key to continue . . .
(where the 1000000 is generated by drop.lua
for debugging purposes)