Home | History | Annotate | Download | only in python
      1 // Copyright (c) PLUMgrid, Inc.
      2 // Licensed under the Apache License, Version 2.0 (the "License")
      3 
      4 #packed "true"
      5 
      6 struct ethernet {
      7   u64 dst:48;
      8   u64 src:48;
      9   u32 type:16;
     10 };
     11 
     12 state ethernet {
     13   switch $ethernet.type {
     14     case 0x0800 {
     15       next proto::ip;
     16     };
     17     case 0x8100 {
     18       next proto::dot1q;
     19     };
     20     case * {
     21       goto EOP;
     22     };
     23   }
     24 }
     25 
     26 
     27 struct dot1q {
     28   u32 pri:3;
     29   u32 cfi:1;
     30   u32 vlanid:12;
     31   u32 type:16;
     32 };
     33 
     34 state dot1q {
     35   switch $dot1q.type {
     36     case 0x0800 {
     37       next proto::ip;
     38     };
     39     case * {
     40       goto EOP;
     41     };
     42   }
     43 }
     44 
     45 
     46 struct ip {
     47   u32 ver:4;
     48   u32 hlen:4;
     49   u32 tos:8;
     50   u32 tlen:16;
     51   u32 identification:16;
     52   u32 ffo_unused:1;
     53   u32 df:1;
     54   u32 mf:1;
     55   u32 foffset:13;
     56   u32 ttl:8;
     57   u32 nextp:8;
     58   u32 hchecksum:16;
     59   u32 src:32;
     60   u32 dst:32;
     61 };
     62 
     63 state ip {
     64   switch $ip.nextp {
     65     case 6 {
     66       next proto::tcp;
     67     };
     68     case 17 {
     69       next proto::udp;
     70     };
     71     case 47 {
     72       next proto::gre;
     73     };
     74     case * {
     75       goto EOP;
     76     };
     77   }
     78 }
     79 
     80 
     81 struct udp {
     82   u32 sport:16;
     83   u32 dport:16;
     84   u32 length:16;
     85   u32 crc:16;
     86 };
     87 
     88 state udp {
     89   switch $udp.dport {
     90     case 8472 {
     91       next proto::vxlan;
     92     };
     93     case * {
     94       goto EOP;
     95     };
     96   }
     97 }
     98 
     99 struct tcp {
    100   u16 src_port:16;
    101   u16 dst_port:16;
    102   u32 seq_num:32;
    103   u32 ack_num:32;
    104   u8 offset:4;
    105   u8 reserved:4;
    106   u8 flag_cwr:1;
    107   u8 flag_ece:1;
    108   u8 flag_urg:1;
    109   u8 flag_ack:1;
    110   u8 flag_psh:1;
    111   u8 flag_rst:1;
    112   u8 flag_syn:1;
    113   u8 flag_fin:1;
    114   u16 rcv_wnd:16;
    115   u16 cksum:16;
    116   u16 urg_ptr:16;
    117 };
    118 
    119 state tcp {
    120   goto EOP;
    121 }
    122 
    123 struct vxlan {
    124   u32 rsv1:4;
    125   u32 iflag:1;
    126   u32 rsv2:3;
    127   u32 rsv3:24;
    128   u32 key:24;
    129   u32 rsv4:8;
    130 };
    131 
    132 state vxlan {
    133   goto EOP;
    134 }
    135 
    136 
    137 struct gre {
    138   u32 cflag:1;
    139   u32 rflag:1;
    140   u32 kflag:1;
    141   u32 snflag:1;
    142   u32 srflag:1;
    143   u32 recurflag:3;
    144   u32 reserved:5;
    145   u32 vflag:3;
    146   u32 protocol:16;
    147   u32 key:32;
    148 };
    149 
    150 state gre {
    151   switch $gre.protocol {
    152     case * {
    153       goto EOP;
    154     };
    155   }
    156 }
    157 
    158