p4lang / behavioral-model

The reference P4 software switch
Apache License 2.0
538 stars 328 forks source link

Is it possible to interact from the BMv2 mininet host to Ganache (Ethereum) server? #1207

Closed Robert-Patrick-Susin closed 1 year ago

Robert-Patrick-Susin commented 1 year ago

Hi, this topic/problem is part of my Master's degree project, which I am currently facing. The project is about doing different types of pre-processing in the P4 switch to compress IoT Data and then store them in the Blockchain as also being sent to the IoT Cloud simultaneously.

The problem relies on being unable to connect/send data from my Mininet hosts to the Blockchain Ethereum (Ganache), which runs outside the Mininet environment.

I will describe what I am doing and the outcomes to make it easier to understand. English is not my native language, so feel free to ask if anything is not understandable.

Consider Ethereum (Ganache) is already up and running outside Mininet on the address: HTTP://10.0.2.15:7545

After deploying my BMv2 mininet network, I open h1; Inside the h1, I run my Python script containing (It is working fine outside Mininet):

from web3 import Web3 (I've installed web3 locally)

For connecting to ganache

w3 = Web3(Web3.HTTPProvider("http://10.0.2.15:7545")) chain_id = 1337 ... The rest of the script interacts with Smart Contract

The Ganache has the following configuration and possible options: image

I get the following response after executing the script: image

This is the s1.log after executing the script: image

It may be possible to make the h1 somehow interact with the Ethereum (Ganache) by changing its interface or IP (I don't know how). However, this problem I am facing is just the first step to see if I can talk to the Ethereum (Ganache), my second move is going to put this script inside a receive.py, and for every received packet, I would take some headers, as strings and send them to Ethereum (Ganache) as transactions. This last observation is necessary to be said as If somehow h1 can communicate outside Mininet with Ethereum (Ganache), I would still need also to be able to receive packets from other hosts inside the Mininet.

jafingerhut commented 1 year ago

I would recommend asking your question on the web forum https://forum.p4.org

While it is true you are using the code in the p4lang/behavioral-model repo as part of the system you are working with, it is not clear to me that there is any bug or problem at all with the code in this repo that is causing it.

The web forum is frequented by (at least a few) people who use the code in this repo and other software like mininet in combination with it, to do similar things to what you are doing. You may even want to search the existing conversation threads there to see if anyone has done something similar, but simply asking your question in a new forum posting is perfectly fine.

Robert-Patrick-Susin commented 1 year ago

Thanks @jafingerhut. I will do this.