• p4 learningl2 basic forwarding


    /* -*- P4_16 -*- */
    #include <core.p4>
    #include <v1model.p4>
    
    /*************************************************************************
    *********************** H E A D E R S  ***********************************
    *************************************************************************/
    
    //TODO 1: Define ethernet header, metadata and headers struct
    struct ethernet_t {
    	bit<48> dstAddr;
    	bit<48> srcAddr;
    	bit<8>  ethernetType;
    }
    
    struct metadata {
    	
    }
    
    struct headers {
    	ethernet_t ethernet;
    }
    
    /*************************************************************************
    *********************** 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 2: parse ethernet header
    		packet.extract(hdr.ethernet);
            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);
        }
    
        //TODO 4: define an action to set the egress port
        action set_egress_port(bit<9> port) {
    	    standard_metadata.egress_spec = port;
    	}
        //TODO 3: define a l2 forwarding table and define a match to set the egress port
        table l2_forward {
    		key = {
    			hdr.ethernet.dstAddr;
    		}
    		actions = {
    			set_egress_port;
    			NoAction;
    		}
    		size = 512;
    		default_action = NoAction();
    	}
        apply {
            //TODO 5: call the forwarding table
    		l2_forward.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 {
    
        }
    }
    
    
    /*************************************************************************
    ***********************  D E P A R S E R  *******************************
    *************************************************************************/
    
    control MyDeparser(packet_out packet, in headers hdr) {
        apply {
            //TODO 6: deparse ethernet header
    		packet.emit(hdr.ethernet);
        }
    }
    
    /*************************************************************************
    ***********************  S W I T C H  *******************************
    *************************************************************************/
    
    //switch architecture
    V1Switch(
    MyParser(),
    MyVerifyChecksum(),
    MyIngress(),
    MyEgress(),
    MyComputeChecksum(),
    MyDeparser()
    ) main;
    

      

  • 相关阅读:
    SLAM+语音机器人DIY系列:(二)ROS入门——3.在ubuntu16.04中安装ROS kinetic
    SLAM+语音机器人DIY系列:(二)ROS入门——2.ROS系统整体架构
    2017年 年计划
    125. Valid Palindrome
    一道多树递归面试题
    顺序表查找和有序表查找
    c++中常见概念、关键字等的区别
    两个栈实现一个队列,两个队列实现一个栈
    150. Evaluate Reverse Polish Notation
    堆排序
  • 原文地址:https://www.cnblogs.com/grglym/p/16285390.html
Copyright © 2020-2023  润新知