behavioral-model icon indicating copy to clipboard operation
behavioral-model copied to clipboard

clone does not work?

Open vitor-l opened this issue 5 years ago • 5 comments

Hello!

I'm using a virtual machine from Sigcomm 2019 (you guys provide that) and my clone function does not work. I have already added the "mirror_add" as a cli_input in the JSON file, but nothing works.

The bigger problem is: no error appears on the terminal when I run 'make'. Can you guys help me? My repository is (https://github.com/vitor-l/p4-practice) and I think the error is in the 'utils folder', but I don't know how to solve it.

vitor-l avatar Jul 06 '20 14:07 vitor-l

If you can provide the P4 program, bmv2 JSON files, and some bmv2 logs that show what's happening, I am happy to look at this issue. Otherwise I will transfer it to the tutorials repo.

antoninbas avatar Jul 06 '20 18:07 antoninbas

@antoninbas, thank for answering my issue! So, I have provided my repository with code and bmv2 files. Do you want something more specific?

vitor-l avatar Jul 06 '20 18:07 vitor-l

Yes, the items I listed above. That saves me a lot of time compared to looking at your code and compiling the P4 code myself. If you share the logs, there may be something obvious there that would help us resolve the issue right away.

antoninbas avatar Jul 06 '20 19:07 antoninbas

I'm a rookie at P4, but I hope that I've provided everything you need. If not, can you detail a little better what you want, please?

So, here is the P4 code:

`/* -- P4_16 -- */ #include <core.p4> #include <v1model.p4>

/* Define constants for types of packets */ #define PKT_INSTANCE_TYPE_NORMAL 0 #define PKT_INSTANCE_TYPE_INGRESS_CLONE 1 #define PKT_INSTANCE_TYPE_EGRESS_CLONE 2 #define PKT_INSTANCE_TYPE_COALESCED 3 #define PKT_INSTANCE_TYPE_INGRESS_RECIRC 4 #define PKT_INSTANCE_TYPE_REPLICATION 5 #define PKT_INSTANCE_TYPE_RESUBMIT 6

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 {
    transition parse_ethernet;
}

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

state parse_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) {
    standard_metadata.egress_spec = port;
    hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
    hdr.ethernet.dstAddr = dstAddr;
    hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
}

action clone_packet() {
    const bit<32> REPORT_MIRROR_SESSION_ID = 500;
    // Clone from ingress to egress pipeline
    clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID);
}

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

apply {
    if (hdr.ipv4.isValid()) {
        ipv4_lpm.apply();
        // Clone every packet
        clone_packet();
    }
}

}

/************************************************************************* **************** 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) {

action clear_ttl() {
    // TTL can be set to 0 only when the packet does not traverse further devices
    // Otherwise compute it to be at least the #devices
    hdr.ipv4.ttl = 0;
}

action change_ipv4_addr() {
    // Simulate that the cloned packet came from h3 (10.0.3.3)
    // 10.0.3.3 == 0x0a000303
    hdr.ipv4.srcAddr = 0x0a000101;
}

apply {
    // In case the "instance type" is a cloned packet, modify its headers
    // Otherwise, do not further process
    if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) {
        change_ipv4_addr();
        clear_ttl();
    }
}

}

/************************************************************************* ************* 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 { packet.emit(hdr.ethernet); packet.emit(hdr.ipv4); } }

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

V1Switch( MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser() ) main;`

JSON topology:

{ "hosts": { "h1": {"ip": "10.0.1.1/24", "mac": "08:00:00:00:01:11", "commands":["route add default gw 10.0.1.10 dev eth0", "arp -i eth0 -s 10.0.1.10 08:00:00:00:01:00"]}, "h2": {"ip": "10.0.2.2/24", "mac": "08:00:00:00:02:22", "commands":["route add default gw 10.0.2.20 dev eth0", "arp -i eth0 -s 10.0.2.20 08:00:00:00:02:00"]} }, "switches": { "s1": { "cli_input" : "topology/s1-commands.txt", "runtime_json" : "topology/s1-runtime.json" } }, "links": [ ["h1", "s1-p1"], ["h2", "s1-p2"] ] }

S1 Jason: { "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.1.1", 32] }, "action_name": "MyIngress.ipv4_forward", "action_params": { "dstAddr": "08:00:00:00:01:11", "port": 1 } }, { "table": "MyIngress.ipv4_lpm", "match": { "hdr.ipv4.dstAddr": ["10.0.2.2", 32] }, "action_name": "MyIngress.ipv4_forward", "action_params": { "dstAddr": "08:00:00:00:02:22", "port": 2 } } ] }

And the cli_input for S1: mirroring_add 500 1

vitor-l avatar Jul 06 '20 19:07 vitor-l

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment, or this will be closed in 180 days

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]