void parse_ipv4(packet_in b, Parsed_packet p) { b.extract <Ipv4_h>(out p.ip); vss_model.VSSModel.verify((p.ip.version == 4), error.IPv4IncorrectVersion); vss_model.VSSModel.verify((p.ip.ihl == 5), error.IPv4OptionsNotSupported); ck.clear(); ck.update <Ipv4_h>(p.ip); vss_model.VSSModel.verify((ck.get() == 0), error.IPv4ChecksumError); accept(b, p); }
private void parse_ipv4(packet_in b, Parsed_packet p) { b.extract(out p.ip); verify.apply(p.ip.version == (bit4)4, new IPv4IncorrectVersion()); // FIXME how are we handling errors? D: NOTE P4 gives it as error.IPV4IncorrectVersion verify.apply(p.ip.ihl == (bit4)5, new IPv4OptionsNotSupported()); ck.clear(); ck.update(p.ip); verify.apply(ck.get() == (bit16)0, new IPv4ChecksumError()); // transition accept }
void start(packet_in b, Parsed_packet p) { b.extract <Ethernet_h>(out p.ethernet); switch ((System.UInt16)p.ethernet.etherType) { case 0x800: parse_ipv4(b, p); break; } }
private void start(packet_in b, Parsed_packet p) { // NOTE type unknown and no type arg specified b.extract(out p.ethernet); // NOTE P4 doesn't specify direction of argument, only of parameter at declaration (i.e. not at call site) switch (p.ethernet.etherType.Value) // NOTE P4 doesn't specify value { case 0x0800: // InfInt return(parse_ipv4(b, p)); // NOTE P4 just gives us parse_ipv4 - could it also give us more args? break; default: parseError = error.NoMatch; // no default rule: all other packets rejected FIXME do we need to generate code for this? } }