Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect and not forward properly after adding switch role(with mininet) #228

Closed
Raymondma-public opened this issue Nov 23, 2016 · 3 comments
Assignees

Comments

@Raymondma-public
Copy link

I am adding a switch_role metadata in switch to let administrator to change role in run time CLI making switches perform differently for different role.

I was trying to use ECMP example to test it. However, after implemented, I test it in mininet. I find it make the switch not working.
(Before adding the code it work correctly in both mininet and localhost)
(After adding the code it seems perform correctly when running localhost as switch.
eg. switch role=0 , it work as ecmp,
eg. switch role =1, it do not perform actions(I will implement other role later
But not perform properly in mininet(cannot connect runtime CLI and not forward properly))

I loaded some commands into switch. It show commands are successfully loaded for the first time.
But the switch do not performs properly to forward the packets.
Then I run the run time CLI again it will shows the following error message

Could not connect to thrift client on port 9094
Make sure the switch is running and that you have the right port

The following is the code I added in ECMP example to try adding the switch role.
(I just using the register for tracking the whether switch role is set correctly)

header_type intrinsic_metadata_t {
    fields {
        switch_role : 4;
    }
}
metadata intrinsic_metadata_t intrinsic_metadata;


action init_switch_role(role_number){
    register_write(switch_role,1,role_number);  
    modify_field(intrinsic_metadata.switch_role,role_number);
}


register switch_role{
    width:32;
    static:switch_role_table;
    instance_count:16384 ;
}

table switch_role_table {
    actions {
        init_switch_role;
    }
    size : 16384;
}
control ingress {
    apply(switch_role_table);//get switch role
    if(intrinsic_metadata.switch_role==0){ //ECMP
        if(valid(ipv4) and ipv4.ttl > 0) {
            apply(ecmp_group);
            apply(forward);
        }
    }
}

control egress {
    if(intrinsic_metadata.switch_role==0){ //ECMP
        apply(send_frame);
    }
}
@antoninbas
Copy link
Member

I don't see anything with your code snippet. Usually, not being able to connect to the switch with the runtime_CLI means that the switch has crashed. A few things can cause the switch to crash (e.g. out-of-bound register access during packet processing).
You can check if the switch crashed by checking if the switch process started by Mininet is still alive (grep for simple_switch in the ps output).
If you need help, please provide a full P4 program (which can be compiled) as well as CLI commands.

@Raymondma-public
Copy link
Author

Raymondma-public commented Nov 24, 2016

Seems that the problem occurs due to the intrinsic_metadata.
I try to add all field in C++ to the meta data instead of only "switch_role" then everything seems working.
But I do not understand why, can you explain briefly why I can make it work like this?

header_type intrinsic_metadata_t {
    fields {
        mcast_grp : 4;
        egress_rid : 4;
        mcast_hash : 16;
        lf_field_list : 32;
        resubmit_flag : 16;
        switch_role:4;
    }
}

@antoninbas
Copy link
Member

antoninbas commented Nov 24, 2016

You are not supposed to use intrinsic_metadata to store your own metadata. Sorry for missing that in the snippet you submitted. Please use something like this:

header_type user_metadata_t {
    fields {
        switch_role : 4;
    }
}
metadata user_metadata_t user_metadata;

The names user_metadata_t / user_metadata are not important, you can use whatever you want so long as it is not intrinsic or standard. intrinsic_metadata fields have a special meaning for the switch, and you should not try to modify them. More information here: https://github.com/p4lang/behavioral-model/blob/master/docs/simple_switch.md

However, I think that the switch should probably not crash in your case, and I'll leave this issue open until I have time to try and improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants