Upgrade to Pro — share decks privately, control downloads, hide ads and more …

P4のはなし

Masakazu Asama
February 23, 2018

 P4のはなし

Masakazu Asama

February 23, 2018
Tweet

More Decks by Masakazu Asama

Other Decks in Technology

Transcript

  1. 1ͬͯʁ w 1SPHSBNNJOH1SPUPDPMJOEFQFOEFOU1BDLFU1SPDFTTPSTͷུ w ύέοτΛड͚औ͔ͬͯΒͦͷத਎ʹԠͯ͡ॲཧΛߦ͍ૹΓग़͢·Ͱ ͷಈ࡞Λهड़͢ΔͨΊͷϓϩάϥϛϯάݴޠ ‛ σʔλϓϨʔϯΛهड़͢ΔͨΊͷݴޠ w 1Ͱ͸ಛఆͷϓϩτίϧʹґଘ͠ͳ͍

    1SPUPDPMJOEFQFOEFOU  ύέοτॲཧܥʹର͢Δύέοτͷॲཧ಺༰Λ࣮૷͢Δ͜ͱ͕Ͱ͖Δ ‛ ৽͍͠ϓϩτίϧ͕ఆٛ͞ΕͨΒͦͷϓϩτίϧʹରԠ͢Δॲ ཧΛ1Ͱϓϩάϥϛϯά͢Δ͜ͱͰରԠ͢Δ͜ͱ͕Ͱ͖Δ w ݴޠ࢓༷Ͱ͸ωοτϫʔΫػثͷΞʔΩςΫνϟΛنఆ͠ͳ͍ ‛ ୠ͠ඪ४తͳΞʔΩςΫνϟ͸ࡦఆத 14"  w ݴޠ࢓༷ʹ͸ίϯτϩʔϧϓϨʔϯ͔ΒσʔλϓϨʔϯΛૢ࡞͢Δ"1* ͸ؚ·Εͳ͍ ‛ ୠ͠1ίϛϡχςΟͰ͸ίϯτϩʔϧϓϨʔϯ͔ΒσʔλϓϨʔ ϯΛૢ࡞͢ΔͨΊͷ"1*΋ࡦఆத 1* 2
  2. എܠ  w 0QFO'MPXͰ͸৽͍͠ϓϩτίϧʹରԠͰ͖ͳ͍ w ૿͑ଓ͚ΔϔομϑΟʔϧυ w େ͖͘ͳΓଓ͚Δ࢓༷ 3 1BU#PTTIBSU

    %BO%BMZ (MFO(JCC .BSUJO*[[BSE /JDL.D,FPXO +FOOJGFS 3FYGPSE $PMF4DIMFTJOHFS %BO5BMBZDP "NJO7BIEBU (FPSHF7BSHIFTF  %BWJE8BMLFS l1SPHSBNNJOH1SPUPDPMJOEFQFOEFOU1BDLFU1SPDFTTPST z IUUQTBSYJWPSHQEGQEG͔ΒҾ༻ Software-Defined Networking (SDN) gives operators pro- grammatic control over their networks. In SDN, the con- trol plane is physically separate from the forwarding plane, and one control plane controls multiple forwarding devices. While forwarding devices could be programmed in many ways, having a common, open, vendor-agnostic interface (like OpenFlow) enables a control plane to control forward- ing devices from di↵erent hardware and software vendors. Version Date Header Fields OF 1.0 Dec 2009 12 fields (Ethernet, TCP/IPv4) OF 1.1 Feb 2011 15 fields (MPLS, inter-table metadata) OF 1.2 Dec 2011 36 fields (ARP, ICMP, IPv6, etc.) OF 1.3 Jun 2012 40 fields OF 1.4 Oct 2013 41 fields Table 1: Fields recognized by the OpenFlow standard The OpenFlow interface started simple, with the abstrac- tion of a single table of rules that could match packets on a dozen header fields (e.g., MAC addresses, IP addresses, pro- tocol, TCP/UDP port numbers, etc.). Over the past five years, the specification has grown increasingly more com- Figur Recen be achie grammi easy. E microco sign of indepen relation it how p as Open tables i stractio arXiv:1312
  3. എܠ  4 ιϑτ΢ΣΞϧʔλ 1ΞʔΩςΫνϟ ϋʔυ΢ΣΞεΠον ॲཧ ൚༻ϓϩηοα $16 ϓϩάϥϚϒϧ"4*$

    '1("$16౳ ઐ༻ϓϩηοα "4*$ '1(" ੑೳ ϋʔυ΢ΣΞεΠον ͱൺֱ͢Δͱ௿଎ ߴ଎͔ͭେ༰ྔ $16ͷ৔߹͸আ͘ ߴ଎͔ͭେ༰ྔ ϙʔτີ౓ ௿͍ ߴ͍ $16ͷ৔߹͸আ͘ ߴ͍ ஗Ԇ2P4 อূͰ͖ͳ͍ อূ͠΍͍͢ $16ͷ৔߹͸আ͘ อূ͠΍͍͢ ৽͍͠ϓϩτίϧ ରԠ ιϑτ΢ΣΞͷॻ͖׵ ͑ͰରԠՄೳ 1ϓϩάϥϜͷॻ͖׵ ͑ͰରԠՄೳ "4*$Ͱ͸΄΅ෆՄೳ ϑϧ'1("ͷ৔߹Մೳ Ձ֨ ൺֱత͍҆ ͨͿΜߴ͍͆ $16ͷ৔߹͸আ͘ ൺֱతߴ͍
  4. 5 ར༻ऀ ϓϩάϥϚ Πϥετ $ ͍Β͢ͱ΍ λʔήοτ ΞʔΩςΫνϟ ػثϝʔΧʔ 1ίϛϡχςΟ

    DPSFQ QSPHSBNQ BSDIQ Πϯετʔϧ ίϯύΠϧ ొ৔ਓ෺ 1ϓϩάϥϜ
  5. 6 λʔήοτ ΞʔΩςΫνϟ ػثϝʔΧʔ QSPHSBNQ BSDIQ Πϯετʔϧ ίϯύΠϧ 1ϓϩάϥϜ ొ৔ਓ෺

    DPSFQ ར༻ऀ ϓϩάϥϚ 1ίϛϡχςΟ w ίΞϥΠϒϥϦ w ΤϥʔίʔυɺύέοτΛ ද͢ߏ଄ମɺͳͲͷΞʔΩ ςΫνϟͱ1ϓϩάϥϜ ͕ڞ௨Ͱ༻͍Δ΋ͷΛఆٛ Πϥετ $ ͍Β͢ͱ΍
  6. 7 QSPHSBNQ Πϯετʔϧ ίϯύΠϧ DPSFQ 1ίϛϡχςΟ 1ϓϩάϥϜ ػثϝʔΧʔ BSDIQ ར༻ऀ

    ϓϩάϥϚ ొ৔ਓ෺ Πϥετ $ ͍Β͢ͱ΍ λʔήοτ ΞʔΩςΫνϟ w ΞʔΩςΫνϟએݴ w λʔήοτ༻ʹ1ϓϩά ϥϜΛॻ͘ࡍʹ࣮૷͠ͳ͚ Ε͹ͳΒͳ͍΋ͷ ύʔα ΍ίϯτϩʔϧ౳ ͷએݴ
  7. 8 λʔήοτ ΞʔΩςΫνϟ ػثϝʔΧʔ BSDIQ Πϯετʔϧ ίϯύΠϧ DPSFQ 1ίϛϡχςΟ QSPHSBNQ

    ొ৔ਓ෺ ར༻ऀ ϓϩάϥϚ Πϥετ $ ͍Β͢ͱ΍ w 1ϓϩάϥϜ w ΞʔΩςΫνϟએݴͰએݴ ͞Εͨύʔαɺίϯτϩʔ ϧɺσύʔαΛ࣮૷ w ͦΕΒΛ·ͱΊͯΞʔΩς ΫνϟએݴͰએݴ͞Εͨύο έʔδͷΠϯελϯεͱ͠ ͯΠϯελϯεԽ 1ϓϩάϥϜ
  8. 9 ར༻ऀ ϓϩάϥϚ λʔήοτ ΞʔΩςΫνϟ ػثϝʔΧʔ 1ίϛϡχςΟ DPSFQ QSPHSBNQ BSDIQ

    Πϯετʔϧ ίϯύΠϧ ొ৔ਓ෺ Πϥετ $ ͍Β͢ͱ΍ 1ϓϩάϥϜ
  9. ΞʔΩςΫνϟ৭ʑ w 7.PEFM w 1ίϛϡχςΟʹΑͬͯϝϯςφϯε͞Ε͍ͯΔϏϔΠϏΞϞσϧ ιϑτ΢ΣΞ࣮૷εΠον ͕αϙʔτ͢ΔΞʔΩςΫνϟ w 1ϓϩάϥϜͷ࣮ݧΛ͢ΔҝͷΞʔΩςΫνϟʁ w

    1PSUBCMF4XJUDI"SDIJUFDUVSF 14"  w 1ίϛϡχςΟʹΑͬͯඪ४Խ͕ਐΊΒΕ͍ͯΔඪ४తͳωοτ ϫʔΫεΠονΛදݱ͢ΔΞʔΩςΫνϟ w 14"Λλʔήοτʹ͓͚ͯ͠͹14"ରԠͷػث͕ग़ͨ࣌ʹ༰қʹϙʔ ςΟϯάͰ͖Δʁ w 1ϓϩάϥϜͰ͸্هͷਫ৭ͷ࢛֯ͷ෦෼Λ࣮૷͢Δ 10 *OHSFTT 1BSTFS &HSFTT %FQBSTFS *OHSFTT *OHSFTT %FQBSTFS 1LU#VG 3FQMJDB &HSFTT 1BSTFS &HSFTT #VG2VFVF &OHJOF 5SB⒏D .BOBHFS 1BSTFS %FQBSTFS 7FSJGZ $IFDLTVN *OHSFTT &HSFTT $PNQVUF $IFDLTVN
  10. ΞʔΩςΫνϟ৭ʑ w 7.PEFM w 1ίϛϡχςΟʹΑͬͯϝϯςφϯε͞Ε͍ͯΔϏϔΠϏΞϞσϧ ιϑτ΢ΣΞ࣮૷εΠον ͕αϙʔτ͢ΔΞʔΩςΫνϟ w 1ϓϩάϥϜͷ࣮ݧΛ͢ΔҝͷΞʔΩςΫνϟʁ w

    1PSUBCMF4XJUDI"SDIJUFDUVSF 14"  w 1ίϛϡχςΟʹΑͬͯඪ४Խ͕ਐΊΒΕ͍ͯΔඪ४తͳωοτ ϫʔΫεΠονΛදݱ͢ΔΞʔΩςΫνϟ w 14"Λλʔήοτʹ͓͚ͯ͠͹14"ରԠͷػث͕ग़ͨ࣌ʹ༰қʹϙʔ ςΟϯάͰ͖Δʁ w 1ϓϩάϥϜͰ͸্هͷਫ৭ͷ࢛֯ͷ෦෼Λ࣮૷͢Δ 11 *OHSFTT 1BSTFS &HSFTT %FQBSTFS *OHSFTT *OHSFTT %FQBSTFS 1LU#VG 3FQMJDB &HSFTT 1BSTFS &HSFTT #VG2VFVF &OHJOF 5SB⒏D .BOBHFS 1BSTFS %FQBSTFS 7FSJGZ $IFDLTVN *OHSFTT &HSFTT $PNQVUF $IFDLTVN w ύʔα w ύέοτͷϔομΛղੳ͢Δ෦෼
  11. ΞʔΩςΫνϟ৭ʑ w 7.PEFM w 1ίϛϡχςΟʹΑͬͯϝϯςφϯε͞Ε͍ͯΔϏϔΠϏΞϞσϧ ιϑτ΢ΣΞ࣮૷εΠον ͕αϙʔτ͢ΔΞʔΩςΫνϟ w 1ϓϩάϥϜͷ࣮ݧΛ͢ΔҝͷΞʔΩςΫνϟʁ w

    1PSUBCMF4XJUDI"SDIJUFDUVSF 14"  w 1ίϛϡχςΟʹΑͬͯඪ४Խ͕ਐΊΒΕ͍ͯΔඪ४తͳωοτ ϫʔΫεΠονΛදݱ͢ΔΞʔΩςΫνϟ w 14"Λλʔήοτʹ͓͚ͯ͠͹14"ରԠͷػث͕ग़ͨ࣌ʹ༰қʹϙʔ ςΟϯάͰ͖Δʁ w 1ϓϩάϥϜͰ͸্هͷਫ৭ͷ࢛֯ͷ෦෼Λ࣮૷͢Δ 12 *OHSFTT 1BSTFS &HSFTT %FQBSTFS *OHSFTT *OHSFTT %FQBSTFS 1LU#VG 3FQMJDB &HSFTT 1BSTFS &HSFTT #VG2VFVF &OHJOF 5SB⒏D .BOBHFS 1BSTFS %FQBSTFS 7FSJGZ $IFDLTVN *OHSFTT &HSFTT $PNQVUF $IFDLTVN w ϚονΞΫγϣϯύΠϓϥΠϯ w ϔομͷ஋ʹԠͯ͡Կ͔ॲཧ ΞΫγϣϯ Λߦ͏෦෼
  12. ΞʔΩςΫνϟ৭ʑ w 7.PEFM w 1ίϛϡχςΟʹΑͬͯϝϯςφϯε͞Ε͍ͯΔϏϔΠϏΞϞσϧ ιϑτ΢ΣΞ࣮૷εΠον ͕αϙʔτ͢ΔΞʔΩςΫνϟ w 1ϓϩάϥϜͷ࣮ݧΛ͢ΔҝͷΞʔΩςΫνϟʁ w

    1PSUBCMF4XJUDI"SDIJUFDUVSF 14"  w 1ίϛϡχςΟʹΑͬͯඪ४Խ͕ਐΊΒΕ͍ͯΔඪ४తͳωοτ ϫʔΫεΠονΛදݱ͢ΔΞʔΩςΫνϟ w 14"Λλʔήοτʹ͓͚ͯ͠͹14"ରԠͷػث͕ग़ͨ࣌ʹ༰қʹϙʔ ςΟϯάͰ͖Δʁ w 1ϓϩάϥϜͰ͸্هͷਫ৭ͷ࢛֯ͷ෦෼Λ࣮૷͢Δ 13 *OHSFTT 1BSTFS &HSFTT %FQBSTFS *OHSFTT *OHSFTT %FQBSTFS 1LU#VG 3FQMJDB &HSFTT 1BSTFS &HSFTT #VG2VFVF &OHJOF 5SB⒏D .BOBHFS 1BSTFS %FQBSTFS 7FSJGZ $IFDLTVN *OHSFTT &HSFTT $PNQVUF $IFDLTVN w σύʔα w ϔομΛॻ͖׵͑Δ෦෼
  13. ίΞϥΠϒϥϦ 14 IUUQTHJUIVCDPNQMBOHQDCMPCNBTUFSQJODMVEFDPSFQ 22 /// Standard error codes. New error

    codes can be declared by users. 23 error { 24 NoError, /// No error. 25 PacketTooShort, /// Not enough bits in packet for 'extract'. 26 NoMatch, /// 'select' expression has no matches. 27 StackOutOfBounds, /// Reference to invalid element of a header stack. 28 HeaderTooShort, /// Extracting too many bits into a varbit field. 29 ParserTimeout /// Parser execution time limit exceeded. 30 } 66 /// Built-in action that does nothing. 67 action NoAction() {} 69 /// Standard match kinds for table key fields. 70 /// Some architectures may not support all these match kinds. 71 /// Architectures can declare additional match kinds. 72 match_kind { 73 /// Match bits exactly. 74 exact, 75 /// Ternary match, using a mask. 76 ternary, 77 /// Longest-prefix match. 78 lpm 79 }
  14. ίΞϥΠϒϥϦ 15 IUUQTHJUIVCDPNQMBOHQDCMPCNBTUFSQJODMVEFDPSFQ 32 extern packet_in { 33 /// Read

    a header from the packet into a fixed-sized header @hdr and advance the cursor. 34 /// May trigger error PacketTooShort or StackOutOfBounds. 35 /// @T must be a fixed-size header type 36 void extract<T>(out T hdr); 37 /// Read bits from the packet into a variable-sized header @variableSizeHeader 38 /// and advance the cursor. 39 /// @T must be a header containing exactly 1 varbit field. 40 /// May trigger errors PacketTooShort, StackOutOfBounds, or HeaderTooShort. 41 void extract<T>(out T variableSizeHeader, 42 in bit<32> variableFieldSizeInBits); 43 /// Read bits from the packet without advancing the cursor. 44 /// @returns: the bits read from the packet. 45 /// T may be an arbitrary fixed-size type. 46 T lookahead<T>(); 47 /// Advance the packet cursor by the specified number of bits. 48 void advance(in bit<32> sizeInBits); 49 /// @return packet length in bytes. This method may be unavailable on 50 /// some target architectures. 51 bit<32> length(); 52 }
  15. ίΞϥΠϒϥϦ 16 IUUQTHJUIVCDPNQMBOHQDCMPCNBTUFSQJODMVEFDPSFQ 54 extern packet_out { 55 /// Write

    @hdr into the output packet, advancing cursor. 56 /// @T can be a header type, a header stack, a header_union, or a struct 57 /// containing fields with such types. 58 void emit<T>(in T hdr); 59 } 61 // TODO: remove from this file, convert to built-in 62 /// Check a predicate @check in the parser; if the predicate is true do nothing, 63 /// otherwise set the parser error to @toSignal, and transition to the `reject` state. 64 extern void verify(in bool check, in error toSignal);
  16. ΞʔΩςΫνϟએݴ 7.PEFMͷྫ 17 IUUQTHJUIVCDPNQMBOHQDCMPCNBTUFSQJODMVEFWNPEFMQ 218 parser Parser<H, M>(packet_in b, 219

    out H parsedHdr, 220 inout M meta, 221 inout standard_metadata_t standard_metadata); ... লུ ... 229 @pipeline 230 control Ingress<H, M>(inout H hdr, 231 inout M meta, 232 inout standard_metadata_t standard_metadata); 233 @pipeline 234 control Egress<H, M>(inout H hdr, 235 inout M meta, 236 inout standard_metadata_t standard_metadata); ... লུ ... 244 @deparser 245 control Deparser<H>(packet_out b, in H hdr); 247 package V1Switch<H, M>(Parser<H, M> p, 248 VerifyChecksum<H, M> vr, 249 Ingress<H, M> ig, 250 Egress<H, M> eg, 251 ComputeChecksum<H, M> ck, 252 Deparser<H> dep 253 ); 5SB⒏D .BOBHFS 1BSTFS %FQBSTFS 7FSJGZ $IFDLTVN *OHSFTT &HSFTT $PNQVUF $IFDLTVN
  17. 1ϓϩάϥϜͷྫ 18 IUUQTHJUIVCDPNQMBOHUVUPSJBMTCMPCNBTUFS1%@@'BMMFYFSDJTFTCBTJDTPMVUJPOCBTJDQ 2 #include <core.p4> 3 #include <v1model.p4> 11

    typedef bit<9> egressSpec_t; 12 typedef bit<48> macAddr_t; 13 typedef bit<32> ip4Addr_t; 15 header ethernet_t { 16 macAddr_t dstAddr; 17 macAddr_t srcAddr; 18 bit<16> etherType; 19 } 21 header ipv4_t { 22 bit<4> version; 23 bit<4> ihl; ... লུ ... 29 bit<8> ttl; 30 bit<8> protocol; 31 bit<16> hdrChecksum; 32 ip4Addr_t srcAddr; 33 ip4Addr_t dstAddr; 34 } 40 struct headers { 41 ethernet_t ethernet; 42 ipv4_t ipv4; 43 }
  18. 1ϓϩάϥϜͷྫ 19 IUUQTHJUIVCDPNQMBOHUVUPSJBMTCMPCNBTUFS1%@@'BMMFYFSDJTFTCBTJDTPMVUJPOCBTJDQ 49 parser MyParser(packet_in packet, 50 out headers

    hdr, 51 inout metadata meta, 52 inout standard_metadata_t standard_metadata) { 53 54 state start { 55 transition parse_ethernet; 56 } 57 58 state parse_ethernet { 59 packet.extract(hdr.ethernet); 60 transition select(hdr.ethernet.etherType) { 61 TYPE_IPV4: parse_ipv4; 62 default: accept; 63 } 64 } 65 66 state parse_ipv4 { 67 packet.extract(hdr.ipv4); 68 transition accept; 69 } 70 71 } ࢀߟ) v1model.p4 218 parser Parser<H, M>(packet_in b, 219 out H parsedHdr, 220 inout M meta, 221 inout standard_metadata_t standard_metadata);
  19. 1ϓϩάϥϜͷྫ 20 IUUQTHJUIVCDPNQMBOHUVUPSJBMTCMPCNBTUFS1%@@'BMMFYFSDJTFTCBTJDTPMVUJPOCBTJDQ 86 control MyIngress(inout headers hdr, 87 inout

    metadata meta, 88 inout standard_metadata_t standard_metadata) { ... লུ ... 93 action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) { 94 standard_metadata.egress_spec = port; 95 hdr.ethernet.srcAddr = hdr.ethernet.dstAddr; 96 hdr.ethernet.dstAddr = dstAddr; 97 hdr.ipv4.ttl = hdr.ipv4.ttl - 1; 98 } 100 table ipv4_lpm { 101 key = { 102 hdr.ipv4.dstAddr: lpm; 103 } 104 actions = { 105 ipv4_forward; 106 drop; 107 NoAction; 108 } 109 size = 1024; 110 default_action = NoAction(); 111 } 113 apply { 114 if (hdr.ipv4.isValid()) { 115 ipv4_lpm.apply(); 116 } 117 } 118 } ࢀߟ) v1model.p4 229 @pipeline 230 control Ingress<H, M>(inout H hdr, 231 inout M meta, 232 inout standard_metadata_t standard_metadata);
  20. 1ϓϩάϥϜͷྫ 21 IUUQTHJUIVCDPNQMBOHUVUPSJBMTCMPCNBTUFS1%@@'BMMFYFSDJTFTCBTJDTPMVUJPOCBTJDQ 158 control MyDeparser(packet_out packet, in headers hdr)

    { 159 apply { 160 packet.emit(hdr.ethernet); 161 packet.emit(hdr.ipv4); 162 } 163 } ࢀߟ) v1model.p4 247 package V1Switch<H, M>(Parser<H, M> p, 248 VerifyChecksum<H, M> vr, 249 Ingress<H, M> ig, 250 Egress<H, M> eg, 251 ComputeChecksum<H, M> ck, 252 Deparser<H> dep 253 ); ࢀߟ) v1model.p4 244 @deparser 245 control Deparser<H>(packet_out b, in H hdr); 169 V1Switch( 170 MyParser(), 171 MyVerifyChecksum(), 172 MyIngress(), 173 MyEgress(), 174 MyComputeChecksum(), 175 MyDeparser() 176 ) main;
  21. ύʔα w ύέοτͷϔομΛղੳ͢Δ෦෼ w ύʔε͢Δύέοτ͸QBDLFU@JOͱͯ͠౉͞ΕΔ w QBDLFU@JOͷFYUSBDUϝιου΍MPPLBIFBEϝιου΍BEWBODFϝιο υΛ༻͍ͯϔομΛղੳ͠ϔομߏ଄ମʹͦͷ৘ใΛ֨ೲ͍ͯ͘͠ w QBDLFU@JOͷFYUSBDUϝιουΛ࣮


    ߦ͢ΔͱҾ਺ͷϑΟʔϧυ෼ύέ
 οτ͕ॖΈҾ਺ʹ஋͕֨ೲ͞ΕΔ
 ৄࡉޙड़  w ঢ়ଶػցΛ࣋ͪॳظঢ়ଶTUBSU͔Β
 ࠷ऴతʹ͸BDDFQU͔SFKFDUʹࢸΔ w USBOTJUJPOͰ࣍ͷঢ়ଶʹҠߦ͢Δ w TFMFDUΛ࣮ߦ͢ΔͱҾ਺ͷ஋ʹԠ
 ͨ͡ঢ়ଶΛฦ͢͜ͱ͕Ͱ͖Δ w ঢ়ଶ͸࠶ؼՄೳ 22 49 parser MyParser(packet_in packet, 50 out headers hdr, 51 inout metadata meta, 52 inout standard_metadata_t sta 53 54 state start { 55 transition parse_ethernet; 56 } 57 58 state parse_ethernet { 59 packet.extract(hdr.ethernet); 60 transition select(hdr.ethernet.etherT 61 TYPE_IPV4: parse_ipv4; 62 default: accept; 63 } 64 } 65 66 state parse_ipv4 { 67 packet.extract(hdr.ipv4); 68 transition accept; 69 } 70 71 }
  22. σύʔα w ύέοτͷϔομΛॻ͖׵͑Δ෦෼ w σύʔε͢Δύέοτ͸QBDLFU@PVUͱͯ͠౉͞ΕΔ w FNJUϝιουΛ༻͍ͯϔομߏ଄ମ͔ΒϔομΛ૊Έཱ͍ͯͯ͘ w ֎ଆͷϔομ͔ΒFNJUϝιουΛݺͼग़͍ͯ͘͠ w

    ϔομʹ͸WBMJEϑϥά͕͋Γ
 WBMJEͳ΋ͷͷΈ͕ॻ͖ग़͞ΕΔ w WBMJEϑϥά͸ύʔα΍ޙड़͢Δ
 ϚονΞΫγϣϯύΠϓϥΠϯ
 Ͱߋ৽͞ΕΔ 23 158 control MyDeparser(packet_out packet, in headers hdr) { 159 apply { 160 packet.emit(hdr.ethernet); 161 packet.emit(hdr.ipv4); 162 } 163 }
  23. FYUSBDUͱFNJU 24 packet.extract(hdr.ethernet); packet.extract(hdr.ipv4); IFBEFST FUIFSOFU@U JQW@U QBDLFU@JO 0010101101010111010101110101111010 ˣΧʔιϧ

    QBDLFU@JO 0010101101010111010101110101111010 ˣΧʔι IFBEFST FUIFSOFU@U JQW@U 00101011... 11010101... ✔WBMJE ✔WBMJE QBDLFU@JO 0010101101010111010101110101111010 ˣΧʔιϧ IFBEFST FUIFSOFU@U JQW@U 00101011... ✔WBMJE
  24. FYUSBDUͱFNJU 25 QBDLFU@PVU 0010101101010111010101110101111010 ˣΧʔιϧ packet.emit(hdr.ethernet); packet.emit(hdr.ipv4); QBDLFU 111010 ˣΧʔι

    IFBEFST FUIFSOFU@U JQW@U 00101011... 11010101... ✔WBMJE ✔WBMJE QBDLFU@PVU 11010101110101111010 ˣΧʔιϧ IFBEFST FUIFSOFU@U JQW@U 00101011... 11010101... ✔WBMJE ✔WBMJE IFBEFST FUIFSOFU@U JQW@U 00101011... 11010101... ✔WBMJE ✔WBMJE ˞FNJUͱ͸ٯॱͰWBMJEͳ΋ͷΛੵΜͰ͍͘
  25. MPPLBIFBEͱBEWBODF 26 hdr.ethernet = packet.lookahead<ethernet_t>(); packet.advance(14); IFBEFST FUIFSOFU@U JQW@U QBDLFU@JO

    0010101101010111010101110101111010 ˣΧʔιϧ QBDLFU@JO 0010101101010111010101110101111010 ˣΧʔιϧ IFBEFST FUIFSOFU@U JQW@U 00101011... ✔WBMJE QBDLFU@JO 0010101101010111010101110101111010 ˣΧʔιϧ IFBEFST FUIFSOFU@U JQW@U 00101011... ✔WBMJE
  26. ϚονΞΫγϣϯύΠϓϥΠϯ w ύʔαͰղੳͨ͠ϔομ৘ใ͔ΒςʔϒϧΛ୳ࡧ͠Ϛονͨ͠ΞΫγϣ ϯΛ࣮ߦ͢Δͱ͍͏Ұ࿈ͷॲཧͷྲྀΕΛهड़ͨ͠΋ͷ w BQQMZ w NBJOؔ਺ͷΑ͏ͳ΋ͷ w ςʔϒϧͷBQQMZ

    ϝιουΛ
 ݺͼग़͢͜ͱͰϔομ৘ใ͔Β
 ΞΫγϣϯΛݺͼग़͢ w UBCMF w LFZͰͲͷϔομ৘ใ͔Β୳ࡧ
 ͢Δ͔Λఆٛ w LFZʹ͸-1.΍&YBDUͳͲͷ
 NBUDI@LJOE ΞʔΩςΫνϟ
 ଆͰఆٛՄೳ Λࢦఆ͢Δ w BDUJPOTʹ͸ςʔϒϧʹొ࿥͞
 ΕಘΔΞΫγϣϯΛྻڍ 27 86 control MyIngress(inout headers hdr, 87 inout metadata meta, 88 inout standard_metadata_t s ... লུ ... 93 action ipv4_forward(macAddr_t dstAddr, eg 94 standard_metadata.egress_spec = port; 95 hdr.ethernet.srcAddr = hdr.ethernet.d 96 hdr.ethernet.dstAddr = dstAddr; 97 hdr.ipv4.ttl = hdr.ipv4.ttl - 1; 98 } 100 table ipv4_lpm { 101 key = { 102 hdr.ipv4.dstAddr: lpm; 103 } 104 actions = { 105 ipv4_forward; 106 drop; 107 NoAction; 108 } 109 size = 1024; 110 default_action = NoAction(); 111 } 113 apply { 114 if (hdr.ipv4.isValid()) { 115 ipv4_lpm.apply(); 116 } 117 } 118 }
  27. ϚονΞΫγϣϯύΠϓϥΠϯ w ύʔαͰղੳͨ͠ϔομ৘ใ͔ΒςʔϒϧΛ୳ࡧ͠Ϛονͨ͠ΞΫγϣ ϯΛ࣮ߦ͢Δͱ͍͏Ұ࿈ͷॲཧͷྲྀΕΛهड़ͨ͠΋ͷ w UBCMF DPOU  w LFZͱBDUJPOT͸ඪ४ςʔϒϧ


    ϓϩύςΟ w FOUSJFTͰఆ਺هड़΋Մೳ w EFGBVMU@BDUJPO͸Φϓγϣφϧ
 ςʔϒϧϓϩύςΟ w ͦΕҎ֎͸ΞʔΩςΫνϟґଘ w BDUJPO w ςʔϒϧʹϚονͨ࣌͠ʹݺͼ
 ग़͞ΕΔؔ਺ͷΑ͏ͳ΋ͷ w Ҿ਺ʹ͸ςʔϒϧʹ֨ೲ͞Εͨ
 ஋͕༻͍ΒΕΔ 28 86 control MyIngress(inout headers hdr, 87 inout metadata meta, 88 inout standard_metadata_t s ... লུ ... 93 action ipv4_forward(macAddr_t dstAddr, eg 94 standard_metadata.egress_spec = port; 95 hdr.ethernet.srcAddr = hdr.ethernet.d 96 hdr.ethernet.dstAddr = dstAddr; 97 hdr.ipv4.ttl = hdr.ipv4.ttl - 1; 98 } 100 table ipv4_lpm { 101 key = { 102 hdr.ipv4.dstAddr: lpm; 103 } 104 actions = { 105 ipv4_forward; 106 drop; 107 NoAction; 108 } 109 size = 1024; 110 default_action = NoAction(); 111 } 113 apply { 114 if (hdr.ipv4.isValid()) { 115 ipv4_lpm.apply(); 116 } 117 } 118 }
  28. ϚονΞΫγϣϯύΠϓϥΠϯ w .Z*OHSFTTͷྫͰ͸ҎԼͷॲཧ͕ߦΘΕΔ w ϔομͷIESJQW͕WBMJEͩͬͨΒETU"EESΛΩʔʹJQW@MQNςʔ ϒϧΛ୳ࡧ w ΋͠Ϛον͢ΔΤϯτϦʔ͕ଘࡏͨ͠ͳΒͦͷΞΫγϣϯΛొ࿥ ͞ΕͨҾ਺Ͱݺͼग़͢ w

    ͳ͚Ε͹EFGBVMU@BDUJPOͰ͋Δ/P"DUJPOΛݺͼग़͢ w Ͱɺ͜ͷςʔϒϧ͸Ͳ͏΍ͬͯ؅ཧ͢Δͷʁʁʁ 29 table ipv4_lpm IESJQWETU"EES ΞΫγϣϯ Ҿ਺  JQW@GPSXBSE ETU"EESEEC QPSU  JQW@GPSXBSE ETU"EESEEC QPSU
  29. ࢀߟ 13VOUJNF"1* 30 Copyright © 2017 – P4.org Control plane

    What is P4Runtime? • Framework for runtime control of P4 targets ◦ Open-source API + server implementation ▪ https://github.com/p4lang/PI ◦ Initial contribution by Google and Barefoot • Work-in-progress by the p4.org API WG • Protobuf-based API definition ◦ p4runtime.proto ◦ gRPC as a possible RPC transport • P4 program-independent ◦ API doesn’t change with the P4 program • Enables field-reconfigurability ◦ Ability to push new P4 program without recompiling deployed switches 46 p4runtime.proto (API) Program-independent server (e.g. gRPC) Target driver P4 target l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  30. ࢀߟ 13VOUJNF"1* 31 Copyright © 2017 – P4.org More details

    on the P4Runtime API 47 Full protobuf definition: https://github.com/p4lang/PI/blob/master/proto/p4/p4runtime.proto message TableEntry { uint32 table_id; repeated FieldMatch match; Action action; int32 priority; ... } message FieldMatch { uint32 field_id; message Exact { bytes value; } message Ternary { bytes value; bytes mask; } ... oneof field_match_type { Exact exact; Ternary ternary; ... } } message Action { uint32 action_id; message Param { uint32 param_id; bytes value; } repeated Param params; } p4runtime.proto simplified excerpts: To add a table entry, the control plane needs to know: • IDs of P4 entities ◦ Tables, field matches, actions, params, etc. • Field matches for the particular table ◦ Match type, bitwidth, etc. • Parameters for the particular action • Other P4 program attributes l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  31. ࢀߟ 13VOUJNF"1* 32 Copyright © 2017 – P4.org P4Runtime workflow

    48 test.p4 test.json Control plane p4runtime.proto P4Runtime server BMv2 driver BMv2 simple_switch p4c-bm2-ss (compiler) P4Info • Captures P4 program attributes needed at runtime ◦ IDs for tables, actions, params, etc. ◦ Table structure, action parameters, etc. • Protobuf-based format • Target-independent compiler output ◦ Same P4Info for BMv2, ASIC, etc. test.p4info Full P4Info protobuf specification: https://github.com/p4lang/PI/blob/master/proto/p4/config/p4info.proto l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  32. ࢀߟ 13VOUJNF"1* 33 Copyright © 2017 – P4.org P4Info example

    49 ... action ipv4_forward(bit<48> dstAddr, bit<9> port) { /* Action implementation */ } ... table ipv4_lpm { key = { hdr.ipv4.dstAddr: lpm; } actions = { ipv4_forward; ... } ... } basic_router.p4 actions { id: 16786453 name: "ipv4_forward" params { id: 1 name: "dstAddr" bitwidth: 48 ... id: 2 name: "port" bitwidth: 9 } } ... tables { id: 33581985 name: "ipv4_lpm" match_fields { id: 1 name: "hdr.ipv4.dstAddr" bitwidth: 32 match_type: LPM } action_ref_id: 16786453 } basic_router.p4info P4 compiler l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  33. ࢀߟ 13VOUJNF"1* 34 Copyright © 2017 – P4.org P4Runtime example

    50 table_entry { table_id: 33581985 match { field_id: 1 lpm { value: "\n\000\002\002" prefix_len: 32 } } action { action_id: 16786453 params { param_id: 1 value: "\000\000\000\000\000\n" } params { param_id: 2 value: "\000\007" } } } action ipv4_forward(bit<48> dstAddr, bit<9> port) { /* Action implementation */ } table ipv4_lpm { key = { hdr.ipv4.dstAddr: lpm; } actions = { ipv4_forward; ... } ... } hdr.ipv4.dstAddr=10.0.1.1/32 -> ipv4_forward(00:00:00:00:00:10, 7) basic_router.p4 Logical view of table entry Protobuf message Control plane generates l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  34. ࢀߟ 13VOUJNF"1* 35 Copyright © 2017 – P4.org Remote control

    51 P4Runtime control server Target driver Vendor A P4Runtime control server Target driver Vendor B P4Runtime control server Target driver Vendor C Remote control plane OSPF BGP P4-defined custom protocol etc. table_entry { table_id: 33581985 match { field_id: 1 lpm { value: "\f\000\... prefix_len: 8 } } action { action_id: 16786453 params { param_id: 1 value: "\000\0... } params { param_id: 2 value: 7 } } } Target-independent protobuf format p4info p4info p4info p4info l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  35. ࢀߟ 13VOUJNF"1* 36 Copyright © 2017 – P4.org Local control

    52 P4Runtime control server Target driver P4 target Local control plane OSPF BGP P4-defined protocol etc. table_entry { table_id: 33581985 match { field_id: 1 lpm { value: "\f\000\... prefix_len: 8 } } action { action_id: 16786453 params { param_id: 1 value: "\000\0... } params { param_id: 2 value: 7 } } } Same target-independent protobuf format p4info p4info The P4 Runtime API can be used equally well by a remote or local control plane l1-BOHVBHF5VUPSJBMzIUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS 1%@@'BMM1@UVUPSJBM@MBCTQEG͔ΒҾ༻
  36. ·ͱΊ w ϗϫΠτϘοΫεεΠονͷσʔλϓϨʔϯΛࣗ༝ʹΧελϚΠζͰ ͖ΔΑ͏ʹͳΔ࣌୅͕དྷΔ͔΋ w ͨͩ͠1PSUBCMF4XJUDI"SDIJUFDUVSFͱ3VOUJNF"1*͕ඪ४Խ͞ Εͯ४ڌ͢Δ૷ஔ͕ग़ճ͖ͬͯͨΒʁ w 3VOUJNF"1*Λ࢖͑͹0QFO'MPXͰ΍ͬͯͨΑ͏ͳ͜ͱ΋Ͱ͖ͦ͏ w

    ͱ͸͍͏΋ͷͷϑϧεΫϥον࣮૷͸͠ΜͲ͍ͷͰ1PSUBCMF4XJUDI "SDIJUFDUVSF޲͚ͷΧελϚΠζ༻-εΠον࣮૷͕ग़ͯདྷΔʁ w ͋ͱ͸ػثϝʔΧʔ͕ͲΕ͚ͩ৐ͬͯ͘ΕΔ͔ʜ w 0QFO'MPXΈ͍ͨʹόζͬͨΒ͋Δ͍͸ʜ 37 Πϥετ $ ͍Β͢ͱ΍
  37. ࢀߟ৘ใ w 1-BOHVBHF$POTPSUJVN w IUUQTQPSH w 1-BOHVBHF4QFDJpDBUJPO w IUUQTQMBOHHJUIVCJPQTQFDEPDT1WTQFDIUNM w

    11PSUBCMF4XJUDI"SDIJUFDUVSF 14"  w IUUQTQPSHQTQFDEPDT14"IUNM w 1%FWFMPQFS%BZ 1% 'BMM w IUUQTXXXZPVUVCFDPNQMBZMJTU MJTU1-G)(3."M+#[($(D:QJNZ*T%OV4PP w 1-BOHVBHF5VUPSJBM w IUUQTHJUIVCDPNQMBOHUVUPSJBMTSBXNBTUFS1%@@'BMM 1@UVUPSJBM@MBCTQEG w 1QSPUPUZQFDPNQJMFS w IUUQTHJUIVCDPNQMBOHQD w 3FXSJUFPGUIFCFIBWJPSBMNPEFMBTB$ QSPKFDUXJUIPVUBVUPHFOFSBUFEDPEF FYDFQUGPSUIF1%JOUFSGBDF  w IUUQTHJUIVCDPNQMBOHCFIBWJPSBMNPEFM w 13VOUJNFBDPOUSPMQMBOFGSBNFXPSLBOEUPPMTGPSUIF1QSPHSBNNJOHMBOHVBHF w IUUQTHJUIVCDPNQMBOH1* 38