Skip to content

NetSP-KAIST/Klaytn_CN_monitoring

Repository files navigation

Klaytn_vm_setting

1. Introduction

This document is to reproduce the Klaytn consensus message monitoring experiment environment. Let us describe briefly our experimental setup for the simple controlled experiment involving seven CNs. Each CN operates on separate virtual machines (VMs) and all of their peer-to-peer sessions go over the common software Open vSwitch (OvS). One POX controller is connected to the software switch. Then we captured all packets per network interface we defined (tap1, tap2 and so on).

figure1

Figure1. Overview of our SDN-based Klaytn network analysis framework

2. Consensus message monitoring

consensus message

Consensus node(CN) of Klaytn is built atop the Istanbul Byzantine Fault Tolerance(IBFT) protocol. IBFT is a consensus protocol for blockchain that guarantees immediate finality. There are four distinct types of consensus messages in IBFT: pre-prepare, prepare, commit, and roundchange. In terms of implementation, several types of messages are used to maintain the Klaytn system, including transaction msg, messages for the rlpx protocol, and consensus message. Consensus message refers to a message type utilized by CNs to achieve consensus. Each consensus message contains consensus message type, sender’s address, sender’s signature, message including round number and so on. All of these messages are encrypted with keys that are unique to each TCP session. To obtain the round number and message type, I extracted keys and decrypted the data.

consensus message monitoring

Monitoring consensus messages represents the list of messages received per round for each CN. If one of the CNs becomes the proposer at a particular round number, it will not receive a preprepare message. I utilized Grafana's dashboard to represent the number of messages received from each CN.

figure2

Figure 2. Grafana dashboard example

3. File description

/klaytn_CN_monitoring/data_processing.py

This file does many things as described below: creating a txt file from a pcap file that contains every packet sent during a tcp session. identifying a secret key for every tcp session. decrypt each RLPx frame. record the outcome in a MySQL database. This python file uses Crypto, sha3, snappy, rlp library to decode each frame. You need to modify this file based on your system. This file is used in your host machine.

/klaytn_CN_monitoring/data_processing_header.py

This file describes some useful functions for data_processing.py. You need to modify this file based on your system. This file is used in your host machine.

/klaytn_CN_monitoring/VM_script/rlpx.go

The Klaytn kcn file is created using this file. I slightly altered the code in order to obtain the secret key. Don't forget to run "make" once the original Klaytn rlpx has been converted to this. Your virtual machine uses this file. Also, make a SecData directory and you need to modify some code based on your system.

/klaytn_CN_monitoring/VM_ script/script.sh

This file transmits the secret key extracted from rlpx.go to the host machine. You need to make a ‘secrets’ directory in your host machine and modify this code based on your system.

4. Data processing

Data Structure

We decrypt and decode the received RLPx messages. Figure 3 shows the RLPx message structure. We use the counter-mode symmetric key decryption with AES. And the Snappy compression is used to decompress messages.

figure3

Figure3. RLPx message structure

Data collection

I used the open-source PacketSorter library to gather data. It sorts packets ordered by sequence number and any duplicated and empty messages are eliminated from the output pcap file. Also, this program attaches to each network interface. In order to capture all incoming and outgoing packets, I run PacketSorter at tap1. I used the Scapy package to read pcap files in Python.

Data decryption

The data processing.py file handles data decryption. The frame is decrypted using Crypto and the sha3 library. And the frame is decompressed using Snappy.

5. Software Prerequisites

This project can run only on Ubuntu.

6. Software Installation

Things that you should keep in mind before the installment. There are many things that must be installed manually, so it will take some time to handle everything. The intended reader is Klaytn developers, so simple steps may be omitted. If you are familiar with Klaytn node implementation using virtual machines (VMs), it may be of great assistance. Additionally, I just figured I'd run 7 CNs. As a result, numerous variables are set to 7. This is something you should keep in mind and adjust for your project. Above all, Google is our best friend.

Installation process

1. Kernel-based Virtual Machine(KVM)

Klaytn CN is constructed using Virtual Machine.

2. POX

Without POX, the source and destination mac addresses of each path had to be hardcoded. This is accomplished automatically by POX, which is very convenient.

3. Open vSwitch(OVS)

Virtual switch for inter-VM communication.

4. Go(Installed in VM)

The implementation of Klaytn is based on GO.

5. Klaytn CN(Installed in VM)

6. make(Installed in VM)

7. PacketSorter application

It is an open-source library that records each TCP flow and has a number of options for customizing the pcap file, including the ability to filter packets by sequence number and delete empty packets.

8. MySQL

Database

I used Grafana, which is simple to connect to MySQL and utilized for visualization.

Detailed steps

1. KVM installation

2. OVS installation

apt-get install openvswitch-switch

3. Configure the OVS

  • x represents the vm number.

sudo ovs-vsctl add-br br0

sudo ovs-vsctl add-port br0 tap{x} -- set Interface tap{x} type=internal ofport={x}

sudo ip link set tap{x} up

  • Verify

sudo ovs-vsctl show

sudo ovs-ofctl show br0

4. Connect to VMs

  • VM{x} connects to Bridged Network, tap{x}. Configure the two VMs as follow
  • On VM{x} (use ifconfig to see VM’s network interface):

sudo nano /etc/network/interfaces

edit this file as below:

auto enp0s3
iface enp0s3 inet static
address 10.0.0.1
netmask 255.0.0.0
network 10.0.0.0
broadcast 10.255.255.255

Then, restart the networking.

sudo ip addr flush enp0s3
sudo systemctl restart networkings

Two network interfaces may be connected to the VM. One should be connected to the tap, and the other should be connected to the NAT, enabling Internet communication.

5. Pox Installation

  • Download the POX folder from the git
  • Need to open taps

sudo ip link set tap{x} up

  • Update openflow rule in the OVS automatically.

cd pox

./pox.py --verbose forwarding.l2_learning

  • Now, you can ping between VMs. Inside the VM, ping to each other so that you make sure that you installed correctly.

6. PacketSorter application

  • Installation:
  • Save pcap file(remember {x} always stands for the VM number). This code captures packets passing through tap1, meaning the source or destination address is CN{x}.

cd ~

mkdir tcpflow{x}

sudo ~/PacketSorter/build/bin/PacketSorter -i tap{1} -o ~/tcpflow{x} -x

7. What host machine needs to do

  • Make directories

mkdir ~/data_collection

mkdir ~/secrets

  • run data_processing

// you need to modify something in data_processing.py and data_processing_header.py according to your system. I stated what you have to do in “TODO”.

./auto_data_processing.sh

8. What VMs need to do (You must implement this procedure for each VM. Therefore, I recommend that you execute the first VM flawlessly and then simply duplicate it.)

  • Install GO

sudo rm -rf /usr/local/go && go tar -C /usr/local -xzf go1.17.5.linux-amd64.tar.gz

export PATH=$PATH:/usr/local/go/bin

go version

  • Install Klaytn

cd klaytn/build

make (for ‘make’, make sure that you have gcc and make installed. If not, sudo apt install gcc && sudo apt install make)

  • After this, you can follow the link below and you can skip STEP0 and the extracting part of the STEP1.
  • clone the github repogitory
  • Modify some code

cd ~

mkdir SecData

cd ~/klaytn_CN_monitoring/VM_script

sudo nano rlpx.go

// Search for TODO and modify them based on your system.

cp ~/klaytn_CN_monitoring/VM_script/rlpx.go ~/klaytn/networks/p2p/rlpx.go

cd ~/klaytn

make

cp ~/klaytn_CN_monitoring/VM_script/script.sh ~/

// follow the link below to make auto-authentication with your host machine https://alvinalexander.com/linux-unix/how-use-scp-without-password-backups-copy/

// Modify script.sh based on your system.

nano ~/script.sh

// I recommend you to run script.sh all the time.

./script.sh

  • Setting is done. Run klaytn CN.

kcnd start

9. Grafana installation

7. Future works

A script that automates the installation of Klaytn CNs would be of great assistance to those who wish to conduct network experiments with Klaytn CNs.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published