Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Additional Mininet-WiFi Contributors
Eduardo Soares - https://github.com/eSoares
Patrick Große - https://github.com/patgrosse
Joaquin Alvarez - [email protected]
David Carrascal - https://github.com/davidcawork

Thanks also to everyone who has submitted issues and pull
requests on github, and to our friendly mininet-wifi-discuss
Expand Down
3 changes: 3 additions & 0 deletions examples/p4/basic-runtime/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BMV2_SWITCH_EXE = simple_switch_grpc

include ../util/Makefile
27 changes: 27 additions & 0 deletions examples/p4/basic-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Basic Runtime Example

Example where you can see the use of the [`P4RuntimeAP`](https://github.com/intrig-unicamp/mininet-wifi/blob/p4/mn_wifi/bmv2.py) class. This class manages the launch of the BMV2 and configures it via P4Runtime.

As already mentioned in the previous README, it is necessary to have the dependencies associated with the p4 environment installed to carry out the execution of this example.


To run the example, it is first necessary to compile the P4 program:

```bash

sudo make

```

Which will create a directory structure where useful information for the execution of the example will be stored, and it will compile our P4 program (storing it under the `build` directory).

Once the P4 program is compiled, you can run the `test.py` script which will build the topology in Mininet-Wifi.

```bash

sudo python test.py

```



184 changes: 184 additions & 0 deletions examples/p4/basic-runtime/basic.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/* -*- P4_16 -*- */
#include <core.p4>
#include <v1model.p4>

const bit<16> TYPE_IPV4 = 0x800;

/*************************************************************************
*********************** H E A D E R S ***********************************
*************************************************************************/

typedef bit<9> egressSpec_t;
typedef bit<48> macAddr_t;
typedef bit<32> ip4Addr_t;

header ethernet_t {
macAddr_t dstAddr;
macAddr_t srcAddr;
bit<16> etherType;
}

header ipv4_t {
bit<4> version;
bit<4> ihl;
bit<8> diffserv;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
ip4Addr_t srcAddr;
ip4Addr_t dstAddr;
}

struct metadata {
/* empty */
}

struct headers {
ethernet_t ethernet;
ipv4_t ipv4;
}

/*************************************************************************
*********************** P A R S E R ***********************************
*************************************************************************/

parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {

state start {
/* TODO: add parser logic */

transition parser_ethernet;
}

state parser_ethernet {
packet.extract(hdr.ethernet);
transition select (hdr.ethernet.etherType) {
TYPE_IPV4: parser_ipv4;
default: accept;
}
}

state parser_ipv4{
packet.extract(hdr.ipv4);
transition accept;
}
}


/*************************************************************************
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/

control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}


/*************************************************************************
************** I N G R E S S P R O C E S S I N G *******************
*************************************************************************/

control MyIngress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
action drop() {
mark_to_drop(standard_metadata);
}

action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
/* TODO: fill out code in action body */
standard_metadata.egress_spec = port;
hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
hdr.ethernet.dstAddr = dstAddr;
hdr.ipv4.ttl = hdr.ipv4.ttl - 1;

}

table ipv4_lpm {
key = {
hdr.ipv4.dstAddr: lpm;
}
actions = {
ipv4_forward;
drop;
NoAction;
}
size = 1024;
default_action = NoAction();
}

apply {
/* TODO: fix ingress control logic
* - ipv4_lpm should be applied only when IPv4 header is valid
*/
if(hdr.ipv4.isValid())
ipv4_lpm.apply();
}
}

/*************************************************************************
**************** E G R E S S P R O C E S S I N G *******************
*************************************************************************/

control MyEgress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
apply { }
}

/*************************************************************************
************* C H E C K S U M C O M P U T A T I O N **************
*************************************************************************/

control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply {
update_checksum(
hdr.ipv4.isValid(),
{ hdr.ipv4.version,
hdr.ipv4.ihl,
hdr.ipv4.diffserv,
hdr.ipv4.totalLen,
hdr.ipv4.identification,
hdr.ipv4.flags,
hdr.ipv4.fragOffset,
hdr.ipv4.ttl,
hdr.ipv4.protocol,
hdr.ipv4.srcAddr,
hdr.ipv4.dstAddr },
hdr.ipv4.hdrChecksum,
HashAlgorithm.csum16);
}
}


/*************************************************************************
*********************** D E P A R S E R *******************************
*************************************************************************/

control MyDeparser(packet_out packet, in headers hdr) {
apply {
/* TODO: add deparser logic */
packet.emit(hdr.ethernet);
packet.emit(hdr.ipv4);
}
}

/*************************************************************************
*********************** S W I T C H *******************************
*************************************************************************/

V1Switch(
MyParser(),
MyVerifyChecksum(),
MyIngress(),
MyEgress(),
MyComputeChecksum(),
MyDeparser()
) main;
35 changes: 35 additions & 0 deletions examples/p4/basic-runtime/runtime/ap1-runtime.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"target": "bmv2",
"p4info": "build/basic.p4.p4info.txt",
"bmv2_json": "build/basic.json",
"table_entries": [
{
"table": "MyIngress.ipv4_lpm",
"default_action": true,
"action_name": "MyIngress.drop",
"action_params": { }
},
{
"table": "MyIngress.ipv4_lpm",
"match": {
"hdr.ipv4.dstAddr": ["10.0.0.3", 32]
},
"action_name": "MyIngress.ipv4_forward",
"action_params": {
"dstAddr": "00:00:00:00:00:03",
"port": 2
}
},
{
"table": "MyIngress.ipv4_lpm",
"match": {
"hdr.ipv4.dstAddr": ["10.0.0.2", 32]
},
"action_name": "MyIngress.ipv4_forward",
"action_params": {
"dstAddr": "00:00:00:00:00:02",
"port": 1
}
}
]
}
43 changes: 43 additions & 0 deletions examples/p4/basic-runtime/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python

import os

from mininet.log import setLogLevel, info
from mn_wifi.cli import CLI
from mn_wifi.net import Mininet_wifi
from mn_wifi.bmv2 import P4RuntimeAP

def topology():
'Create a network.'
net = Mininet_wifi()

info('*** Adding stations/hosts\n')
sta1 = net.addStation('sta1', ip='10.0.0.2', mac='00:00:00:00:00:02')
h1 = net.addHost('h1', ip='10.0.0.3', mac='00:00:00:00:00:03')

info('*** Adding P4RuntimeAP\n')
ap1 = net.addAccessPoint('ap1', cls=P4RuntimeAP, json_path='build/basic.json', runtime_json_path='runtime/ap1-runtime.json',
log_console = True, log_dir = os.path.abspath('logs'), log_file = 'ap1.log', pcap_dump = os.path.abspath('pcaps'))

net.configureWifiNodes()


info('*** Creating links\n')
net.addLink(sta1, ap1)
net.addLink(h1, ap1)


info('*** Starting network\n')
net.start()
net.staticArp()

info('*** Running CLI\n')
CLI(net)

info('*** Stopping network\n')
net.stop()


if __name__ == '__main__':
setLogLevel('info')
topology()
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
table_set_default ipv4_lpm drop
table_add MyIngress.ipv4_lpm ipv4_forward 10.0.0.1 => 00:00:00:00:00:01 2
table_add MyIngress.ipv4_lpm ipv4_forward 10.0.0.3 => 00:00:00:00:00:03 1
table_add MyIngress.ipv4_lpm ipv4_forward 10.0.0.3 => 00:00:00:00:00:03 1
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/p4/bmv2-netns/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BMV2_SWITCH_EXE = simple_switch_grpc

include ../util/Makefile
29 changes: 29 additions & 0 deletions examples/p4/bmv2-netns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# BMv2 in Network Namespaces Example

Example where you can see the use of the [`P4RuntimeAP`](https://github.com/intrig-unicamp/mininet-wifi/blob/p4/mn_wifi/bmv2.py) class. This class manages the launch of the BMV2 and configures it via P4Runtime. Additionally, in this example you can see how it is possible to run the BMV2 in different Network Namespaces, this has been achieved by using the class [`Netns_mgmt`](https://github.com/intrig-unicamp/mininet-wifi/blob/p4/mn_wifi/node.py). This class allows us to execute python code at runtime on different Netns, thus managing to carry out the configuration via P4Runtime on each Netns. As a future work, we propose to carry out the configuration via P4Runtime from the root-Netns, assigning a control IP to each softswitch and establishing the control plane logic so that all softswitches are reachable by a hypothetical external controller.



As already mentioned in the previous README, it is necessary to have the dependencies associated with the p4 environment installed to carry out the execution of this example.


To run the example, it is first necessary to compile the P4 program:

```bash

sudo make

```

Which will create a directory structure where useful information for the execution of the example will be stored, and it will compile our P4 program (storing it under the `build` directory).

Once the P4 program is compiled, you can run the `test.py` script which will build the topology in Mininet-Wifi.

```bash

sudo python test.py

```



Loading