65
Modular SDN Programming w/ Pyretic Joshua Reich Princeton University www.frenetic-lang.org/pyretic

Modular SDN Programming w/ Pyretic

  • Upload
    zlata

  • View
    144

  • Download
    0

Embed Size (px)

DESCRIPTION

Modular SDN Programming w/ Pyretic. Joshua Reich Princeton University www.frenetic-lang.org /pyretic . SDN I s Great!. Programming w/ OpenFlow ?. Not So Much. * We are huge fans of OpenFlow as a hardware-centric protocol/interface, - PowerPoint PPT Presentation

Citation preview

Page 1: Modular SDN Programming w/ Pyretic

Modular SDN Programming w/ Pyretic

Joshua ReichPrinceton University

www.frenetic-lang.org/pyretic

Page 2: Modular SDN Programming w/ Pyretic

2

SDN Is Great!

Page 3: Modular SDN Programming w/ Pyretic

3

Programming w/ OpenFlow? Not So Much.

* We are huge fans of OpenFlow as a hardware-centric protocol/interface, just not as the basis for an API for human programers.

Page 4: Modular SDN Programming w/ Pyretic

Example Network

4

InternetServers

B

A1

23

SDN Switchw/ labeled ports

Page 5: Modular SDN Programming w/ Pyretic

Counters for each rule - #bytes, #packets

A Simple OpenFlow Program

5

Pattern Action

Priority

Route: IP/fwd

B

A1

23

2:dstip=A -> fwd(2)1:* -> fwd(1)2:dstip=B -> fwd(3)

OpenFlowProgram

dstip=A

dstip=Bdstip!=Adstip!=B

Page 6: Modular SDN Programming w/ Pyretic

6

1:dstmac=A -> fwd(2)1:dstmac=B -> fwd(3)2:* -> fwd(1)

PatternSwitch: MAC/fwd

B

A1

23

One API, Many Uses PriorityOrdered

Action

Page 7: Modular SDN Programming w/ Pyretic

7

Load Balancer: IP/mod

B

A1

23

Pattern Action

srcip=0*,dstip=P -> mod(dstip=A) srcip=1*,dstip=P -> mod(dstip=B)

One API, Many Uses

Page 8: Modular SDN Programming w/ Pyretic

Controller Platform

Switch API (OpenFlow)

Monolithic Controller

Switches

App

Runtime

OpenFlow Programming Stack

Control Flow, Data Structures, etc.

*First Order Approximation

Page 9: Modular SDN Programming w/ Pyretic

Programming SDN w/ OpenFlow

9

Images by Billy Perkins

• The Good– Network-wide visibility– Direct control over the switches– Simple data-plane abstraction

• The Bad– Low-level programming interface– Functionality tied to hardware– Explicit resource control

• The Ugly– Non-modular, non-compositional– Challenging distributed programming

Page 10: Modular SDN Programming w/ Pyretic

Controller Platform

Switch API (OpenFlow)

Monolithic Controller

Switches

App

Runtime

Today: OpenDaylight, POX, etc.

Data and Control Flow

~ Registers, adders, etc.

~ Assembly language

Page 11: Modular SDN Programming w/ Pyretic

Pyretic Controller Platform

Switch API

Programmer API

(OpenFlow)

LBRouteMonitor FW

Switches

Apps

Runtime

(Pyretic)

Pyretic: Language & Platform

Page 12: Modular SDN Programming w/ Pyretic

12

{Frene,Pyre}tic?• Frenetic is a SDN umbrella project focused on

– Language design– Compiler implementation

• We’ve produced– Great (northbound) abstraction for programmers– Techniques for implementing these abstractions

• Two current members of the family– Pyretic: embedded & implemented in Python– Frenetic Ocaml: embedded & implemented in

OCaml

Page 13: Modular SDN Programming w/ Pyretic

13

Pyretic or Frenetic Ocaml?Pyretic Frenetic

OcamlTarget Community

Systems and Networking

Programming Languages

Primary Dev. Location

Princeton Cornell

Host Language Python OCaml

Page 14: Modular SDN Programming w/ Pyretic

14

Pyretic from 10,000 ft

Page 15: Modular SDN Programming w/ Pyretic

15

Pyretic Philosophy• Provide high-level programming

abstractions• Based on state-of-the-art PL

techniques• Implement w/ state-of-the-art

systems tech • Package for the networking

community• Focus on real world utility and cutting

edge features

Page 16: Modular SDN Programming w/ Pyretic

Open Source and Programmer-Friendly

• Embedded and Implemented in Python– Rich support for dynamic policies– Familiar constructs and environment– Python library / module system

• Default 3-clause BSD license• Active & growing developer

community– GitHub repository & wiki– Video tutorials and documentation

Page 17: Modular SDN Programming w/ Pyretic

17

HW Middleware QA Ops• WAN, Enterprise, DC, Home• Wireless & Optical • Systems Challenges

– Scalability– Fault-tolerance– Consistency– Upgradability– Performance

• Security• Virtualization

– of network– of services– of address space

• Hard and soft-switches– Network processors– Reconfigurable pipelines– Hardware accelerated features– Programmable x86 dataplane

• APIs and Languages• Traffic Monitoring/Sampling/QoS • Testing, Debugging, Verification• Experimentation & Testbeds• Integration & Orchestration

– End hosts– Legacy switches– Middleboxes– Network Services

Page 18: Modular SDN Programming w/ Pyretic

18

Where Pyretic Fits• Hard and soft-switches

– Network processors– Reconfigurable pipelines– Hardware accelerated features– Programmable x86 dataplane

• APIs and Languages• Traffic Monitoring/Sampling/QoS • Testing, Debugging, Verification• Experimentation & Testbeds• Integration & Orchestration

– End hosts– Legacy switches– Middleboxes– Network Services

• WAN, Enterprise, DC, Home• Wireless & Optical • Systems Challenges

– Scalability– Fault-tolerance– Consistency– Upgradability– Performance

• Security• Virtualization

– of network– of services– of address space

Page 19: Modular SDN Programming w/ Pyretic

19

Pyretic from 1,000 ft

Page 20: Modular SDN Programming w/ Pyretic

20

Basic Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent

modules • Query network state• Modify policy dynamically

Page 21: Modular SDN Programming w/ Pyretic

21

Pyretic =

* Our goal

Page 22: Modular SDN Programming w/ Pyretic

22

Pyretic Provides Feature Example

Concise policy encoding

• flood()

Boolean predicates • ~(match(dstip=10.0.0.1) | match(srcip=10.0.0.1) )

Composition operators

• (load_balance + monitor) >> route

Virtual header fields • match(switch)• modify(class=‘staff’)

Query Policies • count_packets()

Page 23: Modular SDN Programming w/ Pyretic

23

Pyretic from 500 ft

Page 24: Modular SDN Programming w/ Pyretic

24

Policy in OpenFlow• Defining “policy” is complicated

– All rules in all switches– Packet-in handlers– Polling of counters

• Programming “policy” is error-prone– Duplication between rules and handlers– Frequent changes in policy (e.g.,

flowmods)– Policy changes affect packets in flight

Page 25: Modular SDN Programming w/ Pyretic

25

From Rules to a Policy Function• Located packet

– A packet and its location (switch and port)• Policy function

– From located packet to set of located packets• Examples

– Original packet: identity– Drop the packet: drop– Modified header: modify(f=v)– New location: fwd(a)

Page 26: Modular SDN Programming w/ Pyretic

26

Pyretic at sea-level

Page 27: Modular SDN Programming w/ Pyretic

27

Why a set? Consider floodTo flood every packet:

from pyretic.lib.corelib import *

def main():return flood()

Page 28: Modular SDN Programming w/ Pyretic

28

No worrying about:

• Writing a separate handler for controller

• Constructing and sending OpenFlow rules

• Keeping track of each switch • Whether all switches supports the

OpenFlow “flood” action (portability!)

Page 29: Modular SDN Programming w/ Pyretic

29

Programmer Wishlist• Encode policy concisely• Specify traffic of interest• Write portable code• Compose code from independent

modules • Query network state• Modify policy dynamically

Page 30: Modular SDN Programming w/ Pyretic

30

From Bit Patterns to Predicates

• OpenFlow: bit patterns – No direct way to specify dstip!=10.0.0.1 – Requires two prioritized bitmatches

• Higher priority: dstip=10.0.0.1• Lower priority: *

• Pyretic: boolean predicates– Combined with &, |, and ~– E.g., ~match(dstip=10.0.0.1)

Page 31: Modular SDN Programming w/ Pyretic

31

Example: Access ControlBlock host 10.0.0.3

def access_control():return

~(match(srcip=‘10.0.0.3’) | match(dstip=‘10.0.0.3’) )

Page 32: Modular SDN Programming w/ Pyretic

32

Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent modules • Query network state• Modify policy dynamically

Page 33: Modular SDN Programming w/ Pyretic

33

OpenFlow Packets• Location specific code needs both

– The packet– The OF packet_in message*

• Tagging packets requires choosing – Header field (e.g., VLAN, MPLS, TOS bits)– Set of values

Neither concise nor portable* https://github.com/noxrepo/pox/tree/betta/pox/misc/of_tutorial.py

Page 34: Modular SDN Programming w/ Pyretic

34

Pyretic Virtual Header Fields• Unified abstraction

– Real headers: dstip, srcport, …– Packet location: switch and port– User-defined: e.g., traffic_class

• Simple operations, concise syntax– Match: match(f=v)– Modify: modify(f=v)

• Example– match(switch=A) & match(dstip=‘1.0.0.3’)

Page 35: Modular SDN Programming w/ Pyretic

35

Runtime Handles Implementation• Compiler chooses

– What set of header bits to use – What each value means

• Conceptual – no tying to particular mech.

• Portable – different hw, other modules • Efficient

– Don’t need same vlan value network-wide– Sometimes tags will ‘factor out’

Page 36: Modular SDN Programming w/ Pyretic

36

Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent

modules • Query network state• Modify policy dynamically

Page 37: Modular SDN Programming w/ Pyretic

37

Recall OpenFlow

Page 38: Modular SDN Programming w/ Pyretic

38

srcip=0*,dstip=P -> mod(dstip=A) srcip=1*,dstip=P -> mod(dstip=B)

dstip=A -> fwd(2)dstip=B -> fwd(3)* -> fwd(1)

Balance then Route (in Sequence)

Combined Rules?(only one match)

srcip=0*,dstip=P -> mod(dstip=A) srcip=1*,dstip=P -> mod(dstip=B) dstip=A -> fwd(2) dstip=B -> fwd(3) * -> fwd(1)

Balances w/oForwarding!srcip=0*,dstip=P -> mod(dstip=A)

srcip=1*,dstip=P -> mod(dstip=B)

dstip=A -> fwd(2) dstip=B -> fwd(3) * -> fwd(1) Forwards w/o

Balancing!

Page 39: Modular SDN Programming w/ Pyretic

39

dstip = 10.0.0.2 fwd(2)dstip = 10.0.0.3 fwd(3)* fwd(1)

srcip = 5.6.7.8 count dstip = 10.0.0.2 fwd(2)dstip = 10.0.0.3 fwd(3)* fwd(1)

Forwards but doesn’t count

Route and Monitor (in Parallel)

IP = 10.0.0.2

IP = 10.0.0.3

23

1

MonitorRoute

dstip = 10.0.0.2 fwd(2)dstip = 10.0.0.3 fwd(3)* fwd(1)srcip = 5.6.7.8 count

Counts but doesn’t forward

srcip = 5.6.7.8 countCombined rules installed on switch?

Page 40: Modular SDN Programming w/ Pyretic

40

srcip = 5.6.7.8 count dstip = 10.0.0.2 fwd(2)dstip = 10.0.0.3 fwd(3)* fwd(1)

Requires a Cross Product [ICFP’11, POPL’12]

IP = 10.0.0.2

IP = 10.0.0.3

23

1

MonitorRoute

srcip = 5.6.7.8 , dstip = 10.0.0.2 fwd(2) , countsrcip = 5.6.7.8 , dstip = 10.0.0.3 fwd(3) , countsrcip = 5.6.7.8 fwd(1) , count dstip = 10.0.0.2 fwd(2) dstip = 10.0.0.3 fwd(3) * fwd(1)

Page 41: Modular SDN Programming w/ Pyretic

41

Parallel ‘+’: Do both C1 and C2 simultaneously Sequential ‘>>’: First do C1 and then do C2

Policy Functions Enable Compositional Operators

Page 42: Modular SDN Programming w/ Pyretic

42

Example: Sequential CompositionTo first apply access control and then floodaccess_control() >> flood()

• Two totally independent policies• Combined w/o any change to either

Page 43: Modular SDN Programming w/ Pyretic

43

E.g., the ‘if_’ policy

def if_(F,P1,P2): return (F >> P1) + (~F >> P2)

Easily Define New Policies

Page 44: Modular SDN Programming w/ Pyretic

44

Or floodxfwd(a) = ~match(inport=a) >> fwd(a)

flood = parallel([match(switch=sw) >> parallel(map(xfwd,ports)) for sw,ports in MST])

• Portable: compiler chooses whether to implement using OpenFlow ‘flood’ or ‘forward’

Page 45: Modular SDN Programming w/ Pyretic

45

Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent modules • Query network state• Modify policy dynamically

Page 46: Modular SDN Programming w/ Pyretic

46

Querying In OpenFlow• Pre-install rules at the needed

granularity (so byte/packet counters are available)

• Issue queries to poll these counters• Parse the responses when they arrive• Combine counter values from multiple

rules• Keep track of any packets sent to

controller

Page 47: Modular SDN Programming w/ Pyretic

47

Queries in Pyretic• Just a special type of policy• Forwarding to a “bucket”

– q = packets(limit=1,group_by=['srcip'])

• Used like any other (>>, +)• w/ Callback function registration

– q.register_callback(printer)

Page 48: Modular SDN Programming w/ Pyretic

48

Example: Monitor

q = count_bytes(interval=1)q.register_callback(printer)monitor = match(srcip='10.0.0.1') >> q

Page 49: Modular SDN Programming w/ Pyretic

49

Query Policy Library Syntax Side Effectpackets( limit=n, group_by=[f1,f2,…])

callback on every packet received for up to n packets identical on fields f1,f2,...

count_packets( interval=t, group_by=[f1,f2,…])

count every packet received callback every t seconds providing count for each group

count_bytes( interval=t, group_by=[f1,f2,…])

count bytes receivedcallback every t seconds providing count for each group

Page 50: Modular SDN Programming w/ Pyretic

50

Recall OpenFlow ToyBalance Route Monitor

Page 51: Modular SDN Programming w/ Pyretic

51

In Pyreticbalance = (match(srcip=0*,dstip=P) >> modify(dstip=A)) + (match(srcip=1*,dstip=P) >> modify(dstip=B)) + (~match( dstip=P) >> identity)

route = (match(dstip=A) >> fwd(2)) + (match(dstip=B) >> fwd(3)) + (~(match(dstip=A) | match(dstip=B)) >> fwd(1))

b = count_bytes(interval=1)b.register_callback(print)monitor = match(srcip=X) >> b

mlb = (balance >> route) + monitor

1*

0*

B

A1

23

Page 52: Modular SDN Programming w/ Pyretic

52

Compared toinstall_flowmod(5,srcip=X & dstip=P,[mod(dstip=A), fwd(2)])install_flowmod(4,srcip=0* & dstip=P,[mod(dstip=A), fwd(2)])install_flowmod(4,srcip=1* & dstip=P,[mod(dstip=B), fwd(3)])install_flowmod(4,srcip=X & dstip=A ,[ fwd(2)])install_flowmod(4,srcip=X & dstip=B,[ fwd(3)])install_flowmod(3, dstip=A,[ fwd(2)])install_flowmod(3, dstip=B,[ fwd(3)])install_flowmod(2,srcip=X ,[ fwd(1)])install_flowmod(1,* ,[ fwd(3)])

Page 53: Modular SDN Programming w/ Pyretic

53

Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent modules • Query network state• Modify policy dynamically

Page 54: Modular SDN Programming w/ Pyretic

54

Functions Support Dynamism• Dynamic policies are also functions

of time• Value at current moment in self.policy

• Reassigning updates dynamic policy• Can be driven by queries

Page 55: Modular SDN Programming w/ Pyretic

Update current val Otherwise, policy unchanged

Example: MAC-Learningclass learn(DynamicPolicy): def init(self): q = packets(limit=1,[’srcmac’,’switch’]) q.register_callback(update) self.policy = flood() + q

def update(self,pkt): self.policy = if_(match(dstmac=pkt[’srcmac’], switch=pkt[’switch’]), fwd(pkt[’inport’]), self.policy) 55

First packet with uniquesrcmac, switch

Defined momentarily

to flood

If newly learned MAC

New Type of Dynamic Policy

and query Initialize currentvalue of time series

Forward directly tolearned port

Page 56: Modular SDN Programming w/ Pyretic

56

Dynamic Policies

Can also be driven by external events!

Page 57: Modular SDN Programming w/ Pyretic

57

Example: UI Firewall def __init__(self): print "initializing firewall" self.firewall = {} ... self.ui = threading.Thread( target=self.ui_loop) self.ui.daemon = True self.ui.start()

def update_policy (self): self.policy = ~union([(match(srcmac=mac1) & match(dstmac=mac2)) | (match(dstmac=mac1) & match(srcmac=mac2)) for (mac1,mac2) in self.firewall.keys()])

def AddRule (self, mac1, mac2): if (mac2,mac1) in self.firewall: return self.firewall[(mac1,mac2)]=True self.update_policy()

Page 58: Modular SDN Programming w/ Pyretic

58

Programmer Wishlist• Encode policy concisely• Write portable code• Specify traffic of interest• Compose code from independent

modules • Query network state• Modify policy dynamically

Page 59: Modular SDN Programming w/ Pyretic

59

Pyretic Platform

Page 60: Modular SDN Programming w/ Pyretic

Switches

OF Controller PlatformOF Controller Client

Pyretic Backend

Pyretic Runtime

Main App 1 App 2

OpenFlow Messages

Serialized Messages (TCP socket)

Controller Platform Architecture

Process 1

Process 2

Page 61: Modular SDN Programming w/ Pyretic

61

Modes of Operation• Interpreted (on controller)

– Fallback when rules haven’t been installed– Good for debugging

• Reactive– Rules installed in response to packets seen– Fallback when proactive isn’t feasible– Various flavors and optimizations

• Proactive– Analyze policy and push rules– Computation can be an issue– Currently nuclear and simple incremental

Page 62: Modular SDN Programming w/ Pyretic

HA &Scale Out

Interpreter, QoS, ACL, Topo

Runtime Architecture (in Progress)

Flow Table Cache ManagementConsistent UpdateIncrementalization

Classifier GenerationQueryMgmt

Page 63: Modular SDN Programming w/ Pyretic

63

Also in Progress• New features

– Policy access controls– QoS operators– Enhanced querying library

• Applications– Incorporation of RADIUS & DHCP

services – Wide-area traffic-management solutions

for ISPs at SDN-enabled Internet Exchange Points.

Page 64: Modular SDN Programming w/ Pyretic

64

Don’t Just Take Our Word• 2013 NSDI Community Award Winner• Featured in Coursera SDN MOOC

(~50K students, over 1K did assignments)• Georgia Tech Resonance Reimplementation

– Approximately one programmer-day – Six-fold reduction in code size (prev in NOX)– Short expressions replaced complex code

• Matching packets • Modifying and injecting packets • Constructing and installing OpenFlow rules

– Added new features too complex for NOX

Page 65: Modular SDN Programming w/ Pyretic

65

www.frenetic-lang.org/pyretic

Test It Out Yourself