Comments (3)
I think you have to use the clone or clone3 function in order to do that.
Don't know what you are working with but, assuming you are working with p4-learning from nsg-ethz you can find some documentation for the clone function in v1model.p4 - clone3.
I believe this will also be useful:
- simple-switch doc - read
clone_spec
- example from p4utils p4-learning
from p4-utils.
Sorry for the late response.
As @machadoatz says, you have to use the clone or clone3 when you want to send packets to the controller by using another packet as a trigger. However, if you want to use a packet itself, meaning that it does not need to be forwarded, you can simply set the output port as the controller port.
However, I believe this was not what you were asking. You were asking how to even create a "cpu port", right? If you are using p4-utils, in the json configuration file you can enable a cpu port, that will add an "extra" port to the bmv2 switch that will be accessible from the main namespace, you can then listen to that port and send packets to it.
The best example where this is done is in the l2-learning exercise from p4-learning
from p4-utils.
Thank you for your responses.
Sorry, I didn't close the issue earlier.
This is what I ended up doing.
I added an extra port in the data plane and the other end in control-plane program to send packets.
In p4app.json
, I added a control_port like this:
{
...
"topology" : {
...
"s1": {
"cli_input": "s1-commands.txt",
"program": "forwarding.p4",
"control_port" : 31
},
...
}
}
Passed the control_port value to class P4Switch(Switch)
constructor, and in def start(self, controllers = None)
function, added following lines to bring port up:
def start(self, controllers = None):
...
if self.control_port is not None:
get_cp_intf_up(self.name+"-ethd", self.name+"-ethc")
args.extend(['-i', str(self.control_port) + "@" + self.name + "-ethd"])
...
In def stop(self)
, added the following line to bring down port:
def stop(self):
...
get_cp_intf_down(self.name+"-ethd", self.name+"-ethc")
The functions get_cp_intf_down
and get_cp_intf_up
are in p4utils/utils/utils.py
file:
def get_cp_intf_up(dp_intf, cp_intf):
bashCommand = "sudo ip link delete " + dp_intf + " > /dev/null 2>&1 || true"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo ip link delete " + cp_intf + " > /dev/null 2>&1 || true"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo ip link add " + dp_intf + " type veth peer name " + cp_intf
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo sysctl -q net.ipv6.conf." + dp_intf + ".disable_ipv6=1"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo sysctl -q net.ipv6.conf." + cp_intf + ".disable_ipv6=1"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo ifconfig " + dp_intf + " up promisc"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo ifconfig " + cp_intf + " up promisc"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
def get_cp_intf_down(dp_intf, cp_intf):
bashCommand = "sudo ip link delete " + dp_intf + " > /dev/null 2>&1 || true"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
bashCommand = "sudo ip link delete " + cp_intf + " > /dev/null 2>&1 || true"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
from p4-utils.
Related Issues (20)
- Hardware Interface
- Using @controller_header
- How to run multiple controllers HOT 6
- How to clone packets more than once back to back? HOT 2
- Tofino Example: no bf_swithcd for one of the switches HOT 3
- Why SimpleSwitchP4RuntimeAPI doesn't support reading and writing register? HOT 1
- Problem with the “sudo p4run --config p4app.json” command regarding ping between hosts HOT 3
- Read and write to registers HOT 6
- Installing issue HOT 6
- Username and password for pre-installed VM HOT 2
- Problem with switch_thrift_API.py file
- Graceful shutdown when stopping with Ctrl+C HOT 1
- Does P4Utils Support IPv6 ? HOT 3
- register cell size HOT 1
- p4run problem HOT 5
- virtualenv problem HOT 2
- Format for providing launch options for a P4 switch HOT 3
- FRR Router binary path /usr/local/sbin does not contain daemons
- Example cannot pingall after enough long time
- Install error libpiprotobuf.so: undefined references
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p4-utils.