1header_type ethernet_t { 2 fields { 3 dstAddr : 48; 4 srcAddr : 48; 5 etherType : 16; 6 } 7} 8 9header_type ipv4_t { 10 fields { 11 version : 4; 12 ihl : 4; 13 diffserv : 8; 14 totalLen : 16; 15 identification : 16; 16 flags : 3; 17 fragOffset : 13; 18 ttl : 8; 19 protocol : 8; 20 hdrChecksum : 16; 21 srcAddr : 32; 22 dstAddr: 32; 23 } 24} 25 26parser start { 27 return parse_ethernet; 28} 29 30header ethernet_t ethernet; 31 32parser parse_ethernet { 33 extract(ethernet); 34 return select(latest.etherType) { 35 0x800 : parse_ipv4; 36 default: ingress; 37 } 38} 39 40action nop() 41{} 42 43action forward(port) 44{ 45 modify_field(standard_metadata.egress_port, port); 46} 47 48header ipv4_t ipv4; 49 50parser parse_ipv4 { 51 extract(ipv4); 52 return ingress; 53} 54 55table routing { 56 reads { 57 ipv4.dstAddr: exact; 58 ipv4.srcAddr: exact; 59 } 60 actions { nop; forward; } 61 size : 512; 62} 63 64counter cnt { 65 type: bytes; 66 direct: routing; 67} 68 69control ingress 70{ 71 apply(routing); 72}