iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 16
0
Software Development

A survey between OpenFlow Protocol and P4 in Software Defined Network(SDN)系列 第 16

[Day 16] P4 多跳路線檢查 Multi-Hop Route Inspection (MRI) -2

若是想要了解 SDN OpenFlow 以及 P4 請不要吝嗇點擊喜歡或是訂閱我喔!(訂閱又不收費XD)
未來有機會也可以跟大家分享我當網管的辛酸血淚史,可以讓人解決問題時可以參考我的文章。

話不多說,我們就累狗!!/images/emoticon/emoticon05.gif

首先 what's MRI?
多跳路由(或多跳路由)是無線電網絡中的一種通信,其中網絡覆蓋區域大於單個節點的無線電範圍。因此,要到達某個目的地,一個節點可以使用其他節點作為中繼。

多跳路由的典型應用:
1.無線傳感器網絡
2.無線網狀網絡
3.移動自組織網絡
4.智能手機自組織網絡
5.帶有固定多跳中繼的移動網絡

/*************************************************************************
************   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;
    }

    table ipv4_lpm {
        key = {
            hdr.ipv4.dstAddr: lpm;
        }
        actions = {
            ipv4_forward;
            drop;
            NoAction;
        }
        size = 1024;
        default_action = NoAction();
    }
    
    apply {
        if (hdr.ipv4.isValid()) {
            ipv4_lpm.apply();
        }
    }
}
control MyEgress(inout headers hdr,
                 inout metadata meta,
                 inout standard_metadata_t standard_metadata) {
    apply {
        /*
         * TODO:
         * - if ecn is 1 or 2
         *   - compare standard_metadata.enq_qdepth with threshold 
         *     and set hdr.ipv4.ecn to 3 if larger
         */
    }
}
control MyEgress(inout headers hdr,
                 inout metadata meta,
                 inout standard_metadata_t standard_metadata) {
    action mark_ecn() {
        hdr.ipv4.ecn = 3;
    }
    apply {
        if (hdr.ipv4.ecn == 1 || hdr.ipv4.ecn == 2){
            if (standard_metadata.enq_qdepth >= ECN_THRESHOLD){
                mark_ecn();
            }
        }
    }
}

在此付上我的 Reference,我將會以簡短白話的方式來講解 P4 這套語言,若是你/妳不嫌棄可以訂閱我的發文
每天就根據我自己了解的程度來做發文的動作,如果自己對於 P4也有興趣可以先來預習,那我們明天見!
Reference :
P4_turtorial
[(http://docs.google.com/presentation/d/1zliBqsS8IOD4nQUboRRmF_19poeLLDLadD5zLzrTkVc/edit#slide=id.g37fca2850e_6_1802)]


上一篇
[Day 15] P4 多跳路線檢查 Multi-Hop Route Inspection (MRI)
下一篇
[DAY17] P4 Link Monitoring 流量監測的目的與前言
系列文
A survey between OpenFlow Protocol and P4 in Software Defined Network(SDN)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言