... | ... | @@ -48,4 +48,87 @@ More options are available using the JSON network configuration file: check them |
|
|
|
|
|
### Python Network Configuration
|
|
|
|
|
|
Beside having the JSON network configuration method, one can start and initialize the network using also the new Python `NetworkAPI`. |
|
|
\ No newline at end of file |
|
|
Beside having the JSON network configuration method, one can start and initialize the network using also the new Python `NetworkAPI`. Hereafter, we provide a simple example of how to use this new method and a comparison with the legacy JSON configuration file. If you need more information and instructions on how to exploit this functionality, please check out the documentation of *P4-Utils*.
|
|
|
|
|
|
```python
|
|
|
from p4utils.mininetlib.network_API import NetworkAPI
|
|
|
|
|
|
net = NetworkAPI()
|
|
|
|
|
|
# Network general options
|
|
|
net.setLogLevel('info')
|
|
|
net.enableCli()
|
|
|
|
|
|
# Network definition
|
|
|
net.addP4Switch('s1')
|
|
|
net.setP4CliInput('s1', 's1-commands.txt')
|
|
|
net.addP4Switch('s2')
|
|
|
net.setP4CliInput('s2', 's2-commands.txt')
|
|
|
net.addP4Switch('s3')
|
|
|
net.setP4CliInput('s3', 's3-commands.txt')
|
|
|
net.setP4SourceAll('program.p4')
|
|
|
|
|
|
net.addHost('h1')
|
|
|
net.addHost('h2')
|
|
|
net.addHost('h3')
|
|
|
net.addHost('h4')
|
|
|
|
|
|
net.addLink("h1", "s1", weight=5)
|
|
|
net.setBw('h1', 's1', 20)
|
|
|
net.setDelay('h1', 's1', 20)
|
|
|
net.setMaxQueueSize('h1', 's1', 100)
|
|
|
net.setLoss('h1', 's1', 0.01)
|
|
|
net.addLink("h2", "s2")
|
|
|
net.addLink("s1", "s2")
|
|
|
net.addLink("h3", "s3")
|
|
|
net.addLink("h4", "s3")
|
|
|
net.addLink("s1", "s3")
|
|
|
|
|
|
# Assignment strategy
|
|
|
net.mixed()
|
|
|
|
|
|
# Nodes general options
|
|
|
net.enablePcapDumpAll()
|
|
|
net.enableLogAll()
|
|
|
|
|
|
# Start the network
|
|
|
net.startNetwork()
|
|
|
```
|
|
|
|
|
|
The Python script shown above is equivalent to the following JSON network configuration file. Indeed, both snippets define the same network topology.
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
"p4_src": "program.p4",
|
|
|
"cli": true,
|
|
|
"pcap_dump": true,
|
|
|
"enable_log": true,
|
|
|
"topology": {
|
|
|
"assignment_strategy": "mixed",
|
|
|
"links": [
|
|
|
["h1", "s1", {"delay":"20ms", "loss": 1, "bw": 20, "max_queue_size": 100, "weight":5}], ["h2", "s2"], ["s1", "s2"], ["h3", "s3"],["h4", "s3"], ["s1", "s3"]
|
|
|
],
|
|
|
"hosts": {
|
|
|
"h1": {
|
|
|
},
|
|
|
"h2": {
|
|
|
},
|
|
|
"h3": {
|
|
|
},
|
|
|
"h4": {
|
|
|
}
|
|
|
},
|
|
|
"switches": {
|
|
|
"s1": {
|
|
|
"cli_input": "s1-commands.txt"
|
|
|
},
|
|
|
"s2": {
|
|
|
"cli_input": "s2-commands.txt"
|
|
|
},
|
|
|
"s3": {
|
|
|
"cli_input": "s3-commands.txt"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
``` |