Run WCPS In Docker Container Guide
From Cyber-Physical Systems Laboratory
Revision as of 04:08, 17 January 2017 by YehanMa (talk | contribs) (→Run the Simulink model with Docker container)
Contents
The Advantage of Using Docker for WCPS
- Docker container efficiently wraps and organizes the code, runtime, system tools, system libraries that enable WCPS to run smoothly. Regardless of operating systems of the host computer, the Docker container will always run the same. This feature enables users of WCPS from all backgrounds to utilize the tool without modifying the configurations and system files in their computers.
- For more detailed explanation of Docker, please visit:
- https://www.docker.com/what-docker
Materials needed:
Docker:
- For Linux/Mac OSX 10.9 and below/Windows 8 and below:
- Please install Docker toolbox at: https://www.docker.com/products/overview
- For Mac OSX 10.10 and above/Windows 10:
- Please install a newer version of Docker: https://www.docker.com/products/overview
Refer to the “Getting Started Guide” for a more detailed introduction to Docker and make sure that Docker machine and container are working properly.
Matlab r2013a:
- For Mac Users:
- please refer to "Installing Matlab r2013a" part in Run_WCPS_On_Mac_Guide for installation and trouble shooting guides.
- Windows Users:
- 1. Download the installer and the packages from: http://www.mathworks.com/downloads/web_downloads/select_platform?dl_action=choose_products&tab=f
- 2. Please refer to http://www.mathworks.com/support/sysreq/files/SystemRequirements-Release2013a_SupportedCompilers.pdf for details on required compiler from running R2013a on Windows. :Typically, Microsoft Windows SDK or Visual Studio would work.
- 3. After successfully start Matlab user interface, please type “mex -setup” in the command window and choose the compiler you want Matlab to use.
- Linux Users:
- 1. Download and install Matlab from:
- http://www.mathworks.com/downloads/web_downloads/select_products?dl_action=choose_products&platform_id=57&release_name=R2013a&tab=f
- 2. Please refer to http://www.mathworks.com/support/sysreq/files/SystemRequirements-Release2013a_SupportedCompilers.pdf for details on required compiler from running R2013a on 64-bit Linux machine. Recommended compiler would be the GNU gcc/g++ 4.4.x series.
- 3. From the terminal, edit the file ~/.matlab/R2013b/mexopts.sh, so that CC=’gcc’ is changed to –> CC=’gcc-4.7_ and CCX=’g++’ is changed to –> CCX=’g++-4.7_. Then in Matlab terminal type “mex –setup” and choose compiler to be gcc/g++.
- For all users:
- please refer to: http://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html for more details on changing and setting Matlab default compiler.
Download the image of WCPS components
- The already built WCPS Docker image contains the following components:
- Operating system: Ubuntu 14.04 (distributed from Docker hub)
- GCC compiler: gcc 4.4.7 (used as default), gcc 4.8.4
- JDK: java version “1.8.0_91”, Java(TM) SE Runtime Environment (build 1.8.0_91-b14), java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
- Msp430: msp430mcu, msp430-libc, mspdebug, gcc-msp430, gdb-msp430
- Nesc: nesc-1.3.4, ncc 1.2.4
- TinyOS: TinyOS 2.x
- TOSSIM library: micaz TOSSIM library
- Python: Python 2.7.6
- The /TinyOS-Harry directory contains source code for: TinyOS, nesc, msp430.
- The /wcps directory contains source code for: python server.
- The image has been pushed to Docker hub and is made public. The link to the image is:
- https://hub.docker.com/r/yehan/wcpsv3/
- Search the image in Docker Quickstart Terminal using:
- docker search yehan/wcpsv3
- To pull the image from Docker hub use the command:
- docker pull yehan/wcpsv3
Run the Simulink model with Docker container
- We want to run the Matlab model: Copy_of_CoupledTanks_WCPS_v2_DoubleSD
- Download the project folder from: https://github.com/WU-CPSL/WCPSv3_docker
- 1. Run the image yehan/wcpsv3 in a Docker container:
- In Docker Quickstart terminal use the command:
- docker run -it -p 55000:10032 yehan/wcpsv3 bash
- This binds the 10032 port of the newly created container to 55000 port of the docker-machine that hosts the containers, and all incoming connections to 55000 port of the docker-machine (IP address:192.168.99.100) will be routed to 10032 port of the container. (Note that these two port numbers are fairly random and are used as examples in this case)
- 2. Type ifconfig in Docker container to know its IP address (in eth0: inet addr), in our case it’s 172.17.0.2
- In the docker container, cd to /LinearSystemWCPS_publish directory and type command:
- vim tossim-event-server.py
- This opens the python server file, type :85 to go to line 85, type i to enter write mode, and change the ‘localhost’ to ‘container IP’ (in our case it’s ‘172.17.0.2’). The press escape and type :wq to save the file.
- Use command: python tossim-event-server.py
- To start the python server in the container.
- 3. Open tossim-event-client.py in project folder in Matlab, change line 23 to:
- server_address = ('192.168.99.100', 55000)
- Then save the file, this line creates a socket between Matlab and Docker container.
- After this step,Run: Linear_WCS_main.m to run simulation and everything should be working.
- Successful run in terminal should look like:
Notes for Windows/Linux Users:
- Linux:
- In the file “ps_aggregation.m” line 7, “str2num” should be abandoned. Instead “str2double” should be used to prevent dimension mismatch error.
- Windows:
- 1. In the file “ps_aggregation.m” line 7, “str2num” should be abandoned. Instead “str2double” should be used to prevent dimension mismatch error.
- 2. In the file “python.m”, where python function call used in Matlab is defined, change line 63 and 64 to the correct Path and name of the Python “.exe” file one chooses to uses. That file is typically in the “C:\cygwin\bin” folder.