gwsystems / cFE

Composite fork of the cFE
0 stars 2 forks source link

how to run cfe on a linux environment #3

Open ryuxin opened 2 years ago

ryuxin commented 2 years ago

Is there any tutorial I can learn how to run cFE on linux? especially to replay the experiments on Chaos paper? I tried OpenSatKit, but it has too many dependencies and is heavyweight. @phanikishoreg

Thanks Yuxin

phanikishoreg commented 2 years ago

Hey Yuxin,

How are you? I'd suggest start from here: https://github.com/gwsystems/OpenSatKit

Yes, OpenSatKit has dependencies, sure, and a 42 simulator that runs with UI, so you'd need to get that. I remember us playing traces instead of using the 42 simulator, but I hate to say that my email.gwu.edu mail has been disabled abruptly (before I could backup, without notice I guess) a while back, and lost all of my mails from that mailbox, to even dig and help. I remember writing up some email on how to set this up (tracing infra) and use (especially using the Composite + cFE + OSK) and sharing with an external collaborator if that's something you'd be interested in playing with. Perhaps ping Gabe to see if he can dig some of the emails that we shared with the external collaborators that were using the infra for using ML etc for offline training and online failure detection etc. So I vaguely remember all of these details but worst part, I have no emails that I could dig for you.

ryuxin commented 2 years ago

Thanks a lot for your quick response @phanikishoreg I have looked at OpenSatKit, and I compiled the cFE and 42 code from its source. However, I cannot run cosmos component in OpenSatKit due to lack of GUI environment. I guess cosmos is not necessary in some sense, as it is possible to write a simple app to issues command to cFE. I guess the telemetry app in composite act as a simple ground system (https://github.com/gwsystems/composite/tree/rump_cfe_integration/src/components/implementation/no_interface/tele). So I have some concrete questions in Linux.

@gparmer do you have some instructions or scripts to run cFE system on Linux? Complete instructions is not necessary, and it is enough to just boot me up.

Thanks! Yuxin

gparmer commented 2 years ago

Here's some instructions for running in the stale composite branch from Phani. Couldn't find any others. @phanikishoreg are these what you were thinking about?

Following are the code changes you'd have to make to get 42 simulator and cFE in Composite to talk directly to each other:

  1. Uncomment code in cFE/apps/i42/fsw/src/netif.c and cFE/apps/i42/fsw/src/i42_app.c to use networking in i42.

  2. Update cFE/apps/i42/fsw/platform_inc/i42_platform_cfg.h to use the correct IP and HOST-name of the host running 42 simulator.

  3. Add "i42stub" in to that array and update array size macro!

  4. Link to posix_rk.c in src/components/implementation/no_interface/i42/ instead of posix_common.c and call posix_rk_init(0); in init.c like in kit_to and kit_ci apps do.

  5. Comment out code that spawns a HPET sensor emulation thread here, https://github.com/gwsystems/composite/blob/rump_cfe_recovery/src/components/implementation/no_interface/cFE_booter/cFE_entrypoint.c#L125-L135

  6. Make a copy of one of the script files, like kittostub_kitcistub_udptrace_rumpboot.sh into a kittostub_kitcistub_i42stub_udptrace_rumpboot.sh and update the copy to have similar dependencies like kitcistub and kittostub for i42stub.

  7. In 42 simulator, update this file to use the ip address of the cFS (composite) instance: https://github.com/gwsystems/OpenSatKit/blob/custom_level/42/InOut/Inp_IPC.txt#L4 Note: This will be the first time that i42 in cFE composite port is actually talking to 42 simulator as we had previously captured the sensor traces from a linux instance and replayed that for composite cFE.

I don't think we'd need any changes in cosmos though. Please let me know if you need more information.

Phani

Some additional resources:


COSMOS And CFS On Remote Hosts

The purpose of this document is to share the steps I followed to have CFS and COSMOS run on different machines (remote hosts) and talk to each other over the wire.

Basic steps:

  1. Have OpenSatKit installed on both the machines.
  2. Connect the machines directly (peer to peer) through the ethernet.
  3. Set unique hostnames on both systems if not already set. (hostname -s command)
  4. I preferred to use static IPs on both the system. On the system that runs COSMOS, set the IP address to 192.168.0.1, subnet as 24 and gateway as 192.168.0.1.
  5. On the machine that runs CFS, set the IP address as 192.168.0.2, subnet as 24 and gateway as 192.168.0.1.
  6. Edit the hosts file, /etc/hosts on COSMOS and add an entry for hostname resolution for the CFS target. Similarly, edit it on the CFS machine and add COSMOS's hostname in there.
  7. To make sure all ports are accessible and nothing is blocked by firewall or iptables on either systems: (I remember having some trouble in connecting both systems, so I did this. But you may not want to do this unless you have some connection problems like "connection refused" or something.)

    1. Remove apparmor in ubuntu. See here to disable it: https://help.ubuntu.com/community/AppArmor
    2. Disable iptables if it isn't already. sudo ufw status; sudo ufw disable.

    You've to do these on both host and target PCs.

    NOTE:
    I've run into a problem where the Ubuntu GUI just crashed after removing apparmor on one of the machines. If this happens to you, you'll need to follow the below steps to recover (not so easy):
    
    1. ctrl + alt + f2 when you see that error that says cannot start GUI for login on Ubuntu so you can login using cmdline.
    2. if you're not on network, you'd need to get that up.
       => ifdown eth0; ifup eth0
       This may not work if you're using network manager.
       Well, add to /etc/network/interfaces your interface name (like "eth0"). 
       Look up online, and make sure you've configured or editted /etc/network/interfaces to correctly use dhcp or static depending on your network policies. You need to be online to use apt-get. (or have the ubuntu-desktop and unity packages downloaded)
      => ifup eth0
      This should connect now.
    3. mv ~/.config ~/.config.bak
    4. reinstall ubuntu-desktop and unity packages
    5. Reboot. This should fix it. :) It did for me.

CFS and 42

If you like to connect to 42 simulator running on the COSMOS host machine, you'll need to follow the below seps.

CFS steps
  1. Open OpenSatKit-master/cfs/apps/i42/fsw/platform_inc/i42_platform_cfg.h
  2. Change I42_LOCAL_HOST_STR to use the hostname of the COSMOS machine
  3. Change I42_SOCKET_ADDR_STR to use the IP address of the COSMOS machine. (Use the fixed length IP format. In my case it was, "192.168.000.001").
  4. Recompile and reinstall. -> make; make install
42 steps
  1. Open the OpenSatKit-master/42/InOut/Inp_IPC.txt and edit the hostname there to point to the hostname of the CFS target.
NOTE:
* These steps are not necessary if you don't want to run the 42 simulator for this test.
* Because we're going to replace the 42 simulator with a 42 sensor trace replay application for most of our tests on both systems so you may not want to try this step.
* Because that is our goal (to use sensor trace replay), I've not really verified if this communication works correctly.

CFS and COSMOS

For this, all modifications you need to make are local to COSMOS directory in the OpenSatKit of the COSMOS machine.

Steps:

  1. It would be easier or useful for reference if you have a set of files and lines you need to modify. To get that, grep for "127.0.0.1" and "localhost" in the OpenSatKit-master/cosmos directory. -> grep -e "127.0.0.1" -e "localhost" * -rn
  2. Edit config/tools/cmd_tlm_server/cmd_tlm_server.txt to replace 127.0.0.1 to use the IP address of the CFS target.
  3. Edit config/targets/KIT_TO/cmd_tlm/kit_to_cmd.txt to replace 127.0.0.1 to use the IP address of the COSMOS machine. This IP address is passed to CFS through KIT_CI and the KIT_TO app in CFS connects to that IP address to send out the telemetry data.
  4. Edit lib/cfs_kit_global.rb, LOCAL_IP_ADDR to use CFS IP address.
  5. Edit lib/osk_global.rb, COSMOS_IP_ADDR to use the COSMOS machine's external IP address and not the loopback address.
  6. Edit lib/osk_system.rb, in the function def connect_to_local_cfs() to pass the second parameter to be the IP address of the CFS target machine.
  7. Edit config/targets/CFS_KIT/lib/cfs_kit_screen.rb and comment out the lines that spawn and enable telemetry to the CFS. (Lines #61-106). This means, you'll have to manually run CFS on the CFS target machine and click on Enable Telemetry on COSMOS GUI after the CFS is up.
  8. ruby Launcher on COSMOS to bring up the GUI.

CFS Steps:

  1. Go to cfs/build/exe/cpu1 in the OpenSatKit on the CFS target machine.
  2. Run CFS using sudo ./core-cpu1.

Go back to the COSMOS machine and click on Enable Telemetry. This should show a log in CFS console saying Telemetry output enabled for <XXXXXXXXXXXXXX> and the same log should appear on the COSMOS GUI.

gparmer commented 2 years ago

Hope that helps! Awesome that you're using CFS!

phanikishoreg commented 2 years ago

Yes, that's what I was looking for. Hope that helps @ryuxin! Thanks for digging that up, @gparmer!!

ryuxin commented 2 years ago

Thank you so much for the detailed instructions! I will follow this and ask more question if necessary.