如何为EasyRoute协议编写P4程序?

时间:2017-02-17 10:11:23

标签: python json

我正在尝试在https://github.com/p4lang/tutorials/tree/master/SIGCOMM_2015#obtaining-required-software上实现一个Easyroute协议。在上面的github repo上有骨架程序。但由于我是P4语言的新学习者,我需要帮助来编写上面github存储库中给出的这个骨架程序。

任何已经编写并实施上述作业的人都可以通过发布所需的P4程序来帮助我。

骨架程序为

 /*
Copyright 2013-present Barefoot Networks, Inc. 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// TODO: define headers & header instances

parser start {
    // TODO
    return ingress;
}

// TODO: define parser states

action _drop() {
    drop();
}

action route() {
    modify_field(standard_metadata.egress_spec, /* TODO: port field from your header */);
    // TODO: update your header
}

control ingress {
    // TODO
}

control egress {
    // leave empty
}

3 个答案:

答案 0 :(得分:0)

Mininet environmeent可以使用3个交换机和3个主机进行测试。

//this code is available to use under Apache License on github
    header_type easyroute_head_t {
        fields {
            preamble: 64;
                //preambe is always set to zero, that is used 
                //to identify easyrout packets from other packets.
            num_valid: 32;
    //indicates the number of valid ports in header
        }
    }
    header easyroute_head_t easyroute_head;
    header_type easyroute_port_t
     {
        fields {
            port: 8;
        }
    }
    header easyroute_port_t easyroute_port;
    parser start
     {
        return select(current(0, 64))
           //call to current is used to examine the 1st 64 bits
     {
            0: parse_head;
            default: ingress;
        }
    }
    parser parse_head 
    {
        extract(easyroute_head);
        return select(latest.num_valid)
     {
            0: ingress;
            default: parse_port;
        }

    }

    parser parse_port {
        extract(easyroute_port);
        return ingress;
    }
    action _drop()
     {
        drop();
    }
    action route()
     {
        modify_field(standard_metadata.egress_spec, easyroute_port.port);
        add_to_field(easyroute_head.num_valid, -1);
        remove_header(easyroute_port);
                //update header, call to remove header for removing header
    }
    table route_pkt
     {
        reads
     {
            easyroute_port: valid;
        }
        actions
     {
            _drop;
            route;
        }
        size: 1;
    }
    control ingress 
    {
        apply(route_pkt);
          //route_pkt is the table
    }
    control egress
     {
    }

答案 1 :(得分:0)

[将自己置于源 routing_directory。 ./ run_demo.sh将编译您的代码并创建上述Mininet网络。它还将使用commands.txt配置每个交换机。网络启动并运行后,您应在Mininet CLI中键入以下内容:

xterm h1 xterm h3 这将在h1和h3为您打开一个终端。

在h3上运行:./ letce.py。

在h1上运行:./ send.py h1 h3。

然后,您应该能够在h1上键入消息并在h3上接收消息。 send.py程序使用Dijkstra找到h1和h3之间的最短路径,然后将正确格式化的数据包发送到h3到s1和s3] 1

.pcap files will be generated for every interface (9 files: 3 for each of the 3 switches). You can look at the appropriate files and check that your packets are being processed correctly

答案 2 :(得分:0)

https://github.com/p4lang/tutorials/tree/master/SIGCOMM_2015#obtaining-required-software处给出的代码在action route()方法中缺少'port'参数。下面给出了正确的代码。只需在p4代码文件中进行这一小改动,然后执行https://github.com/p4lang/tutorials/tree/master/SIGCOMM_2015#obtaining-required-software中给出的教程中提到的步骤。

 /*
Copyright 2013-present Barefoot Networks, Inc. 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// TODO: define headers & header instances

parser start {
    // TODO
    return ingress;
}

// TODO: define parser states

action _drop() {
    drop();
}

action route(port) {
    modify_field(standard_metadata.egress_spec, port);
    // TODO: update your header
}

control ingress {
    // TODO
}

control egress {
    // leave empty
}

所有最好的