User Tools

Site Tools


let_s_get_started:hello_world

Hello, World!

Hello, World! is the the type of program that is used to demonstrate the basic syntax of a programming language. In the context of Netualizer, the Hello, World! project shows the basic functionality of Netualizer. Because Netualizer is a Protocol Stack Virtualization framework, and not just a programming language, the Hello, World! project sets two full stacks that send a single Hello, World! packet from one stack to the other.

A Netualizer controller typically includes a built-in agent that can be used for traffic generation on the same system. For sake of simplicity, in this example the controller interacts with its built-in agent to send a packet from one stack to the other. Moreover, since traffic is internal to the agent, it is possible to use the virtual ethernet interface installed by Netualizer. This interface, called VPS, carries IPv4 and IPv6 addresses 192.168.21.5 and 2001::21:5 respectively.

Having said this, let's start the project. Start the controller and create a new project by selecting File ⇒ New ⇒ Project:

Enter the project name as Hello and click the Attach local agent option:

This will create a basic empty configuration and an empty LUA script. When the configuration is shown, click the physical layer block phy and select the local interface that has 192.168.21.5 as main address:

Next, create an ethernet layer and set it on top of the physical layer. Call it eth:

Now, create an IP layer, name it ip and put it on top of the ethernet layer:

Create a UDP layer, call it udp and set it on top of the IP layer:

These layers end up making the full stack:

As shown below, Netualizer assigns a static IPv4 address. The address can be changed and, alternatively, DHCP can be used instead:

Moreover, Netualizer also assigns an ethernet MAC address. This address can also be changed:

Note that the UDP port (no shown) is also assigned automatically by VPS, and yes, it can be changed too. For now, let's leave the defaults.

Now, let's repeat the same steps and build another similar stack. Netualizer will assign contiguous MAC and IPv4 addresses as well as UDP ports:

Note that the IP layer of the second stack has IP address 192.168.21.11:

The UDP layer has port 4001:

Now let's double click on the script:

And write a simple script:

The code is the following:

function main()
	clearOutput();

	waitForIpUp(ip);
	waitForIpUp(ip2);

	setUdpDestPort(udp, 4001);
	setIpDestAddress(ip, "192.168.21.11");

	send(udp, "Hello, World!");
end

The main function calls clearOutput() to clear the output screen. The program then waits for both IP layers to come up. Note that the arguments of the waitForIpUp functions are the names of the IP layers. Next, the setUdpDestPort(udp, 4001) function sets the destination UDP address of the messages sent from the source UDP layer. The destination IP address is set by means of the setIpDestAddress(ip, “192.168.21.11”) function call. Again, this is executed on the IP layer named ip and specifies 192.168.21.11 as destination IP address. Finally, the program executes send(udp, “Hello, World!”) in order to send a small datagram with a UDP payload Hello World! to the destination.

Next thing, let's run the suite by clicking on Scripts ⇒ Run Suite:

How do we know if the datagram went from 192.168.21.10:4000 to 192.168.21.11:4001 ? Right click on the UDP layer, select Statistics ⇒ Upstream Last Packet:

This shows the last received UDP message:

Alternatively, Wireshark can be used to verify the transmission:

Note that for simpler cases, like this one, there is no need to write any code. It is possible to directly specify the destination IPv4 address in the stack:

And the destination UDP port too:

Then click Inject Raw Data:

And enter the Hello World! text in the edit box:

And click OK to send it. Then, as before, check on the destination UDP layer to see if the packet was received.

Note this is a simple proof-of-concept example, not very useful, but good enough to show how Netualizer works. Pretty utilitarian like any other Hello, World! example.

let_s_get_started/hello_world.txt · Last modified: 2022/01/29 04:13 by vps