public override void process_packet(int in_port, byte[] packet_data) { // Provided by the user - NOT generated var inCtrl = new InControl() { inputPort = (PortId)in_port }; var outCtrl = new OutControl(); packet_in packetIn = new packet_in(packet_data); H headers = null; // FIXME is this okay? error err = error.NoError; try { p.apply(packetIn, out headers); // FIXME where does the error come from? Catch? } catch (error ex) { err = ex; } map.apply(ref headers, err, inCtrl, out outCtrl); packet_out packetOut = new packet_out(); d.apply(ref headers, packetOut); this.send_packet((int)outCtrl.outputPort, packetOut.RawData, packetOut.Length); }
public void apply(packet_in b, out Parsed_packet p, out error parseError) { ck = new Ck16(); // FIXME how are we handling instantiation of externs? p = new Parsed_packet(); start(b, p); }
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); }
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 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 }
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? } }
void reject(packet_in b, Parsed_packet p) { }
void accept(packet_in b, Parsed_packet p) { }
public void apply(packet_in b, out Parsed_packet p) { p = new Parsed_packet(); start(b, p); }