Recently, I had some time to spend and wanted to work on the plipbox project’s Amiga driver. Unfortunately, I only had my MacBook Pro with me and noÂ Amiga or plipbox hardware.
What does a SW developer do if the real hardware is not at hand?
Yes, you write an emulator that represents the missing HW in SW on a machineÂ you have access to…
Adding a Virtual Parallel Port Protocol in FS-UAE
That said, I installed all required Amiga SW in a virtual environment inÂ FS-UAE on my Mac and soon I had my plipbox.device SANA II driverÂ talking with the virtual parallel port in FS-UAE. What was missing now is aÂ protocol that communicates the complete I/O state from FS-UAE to anotherÂ process. Then I could write a standalone application that does emulate theÂ plipbox firmware and plipbox.device in FS-UAE would be operational.
I defined a simple two-byte bi-directional protocol called vpar thatÂ communicates any change in the emulation of FS-UAE’s Amiga parallel port to anÂ external process and also receives external changes for input lines from theÂ process and realizes them in FS-UAE’s emulated parallel port.
Having a POSIX compatible system with pseudo-terminals (ptys) I devised theÂ link between both processes as a simple file-open interface in FS-UAE and a ptyÂ in the plipbox emulator (Note: any other interprocess mechanism works here alsoÂ but this one was very easy to add in FS-UAE).
The setup looks like this:
+----------+ +---------+ | plipbox | | patched | | emulator |--(opens)--> [PTY] <--(file I/O)--| FS-UAE | +----------+ +---------+ <--------- vpar protocol -------->
All required changes to FS-UAE are available in my clone of the FS-UAEÂ repository on GitHub in the `chris-devel` branch.
For the plipbox emulator application I chose my favorite script languageÂ Python. With it setting up the pty for inter-process communication andÂ implementing the vpar protocol peer was done in a few hours.
Setting up the Network
Ok, the plipbox emulator in Python can now talk PLIP via vpar’s virtualÂ parallel port. The next step is to add access to an Ethernet device on theÂ lowest frame level for our plipbox emulator.
I had a look at the pcap library that allows injecting packets intoÂ an existing adapter, but the Python bindings often lacked the inject featureÂ of the library and so I dropped this idea.
Then I found a setup using a TAP device to easily create and receiveÂ ethernet packets from a user space application. Combine this with a realÂ ethernet adapter via an interface bridge and you have access to real ethernetÂ with a simple TAP file I/O interface (opening /dev/tap0) from yourÂ application.
The setup looks like this:
+----------+ +---------+ +----------+ | Real Eth | | TAP | | plipbox | | Adapter |<-- Bridge -->| Adapter |<-- File I/O -->| emulator | +----------+ +---------+ +----------+ en1 bridge0 tap0 +----- OS net interfaces ----+
For the real ethernet adapter I use a second USB ethernet adapter on my MacÂ that is not configured (IP: 0.0.0.0) but active (up) in Mac OS X. This way OS XÂ does not use it and my emulator can use it exclusively.
Creating the TAP device and building the bridge with the real adapter is doneÂ with some sudo’ed system command right in the startup of the emulator.
Note: the TAP driver is not shipped with Mac OS X itself, but you can add it byÂ installing the ones from the TUN TAP OSX project.
Putting it all together
On top of the vpar Python module I implemented the magPLIP protocol layer inÂ an own Python class. Now all pieces to create the plipbox were available.
The plipbox main script sets up the vpar, magplip, and ethernet with TAP andÂ interface bridge. In the main loop it does I/O multi-plexing with select() onÂ the file descriptor for the vpar PTY and for the TAP file.
A packet arriving from TAP is filtered (i.e. multicast and unknown broadcastsÂ are removed) similar to the real plipbox firmware and then delivered to theÂ emulated Amiga via the vpar connection.
A packet incoming via PLIP is directly delivered to the local network and thusÂ written to the TAP file.
That’s it! A working plipbox running as a Python script on my Mac…Â Similar to the firmware I added some optional debugging output to see theÂ packet contents and to measure the timing and latency. Now I can develop and test the plipbox.device driver with the emulated environment…
Sneak a Peek?
The plipbox emulator will be shipped with the upcoming version 0.3 of plipbox. If you want to have a look already then head over to my GitHub repository where all development takes place… Have a look in the python and doc dirs 🙂