/* 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. */ #include #include // This program processes packets composed of an Ethernet and // an IPv4 header, performing forwarding based on the // destination IP address typedef bit<48> EthernetAddress; typedef bit<32> IPv4Address; // standard Ethernet header header Ethernet_h { EthernetAddress dstAddr; EthernetAddress srcAddr; bit<16> etherType; } // IPv4 header without options header Ipv4_h { bit<4> version; bit<4> ihl; bit<8> diffserv; bit<16> totalLen; bit<16> identification; bit<3> flags; bit<13> fragOffset; bit<8> ttl; bit<8> protocol; bit<16> hdrChecksum; IPv4Address srcAddr; IPv4Address dstAddr; } // Parser section // List of all recognized headers struct Headers { Ethernet_h ethernet; Ipv4_h ip; } struct Metadata { } parser P(packet_in b, out Headers p, inout Metadata meta, inout standard_metadata_t standard_meta) { state start { transition accept; } } // match-action pipeline section control Ing(inout Headers headers, inout Metadata meta, inout standard_metadata_t standard_meta) { register>(32w2) debug; apply { bit<8> n = 8w0b11111111; //debug.write(0, n); n[7:4] = 4w0; debug.write(1, n); standard_meta.egress_port = 0; } } control Eg(inout Headers hdrs, inout Metadata meta, inout standard_metadata_t standard_meta) { apply { } } // deparser section control DP(packet_out b, in Headers p) { apply { b.emit(p.ethernet); b.emit(p.ip); } } // Fillers control Verify(in Headers hdrs, inout Metadata meta) { apply {} } control Compute(inout Headers hdr, inout Metadata meta) { apply {} } // Instantiate the top-level V1 Model package. V1Switch(P(), Verify(), Ing(), Eg(), Compute(), DP()) main;