Labs / Automation / Models & controllers

Lab 2 of 2 · Models & controllers

SDN: a controller that programs the switches

An SDN controller programs two switches, takes a rule by API, then gets unplugged.

Start this lab 5 steps

The idea

Ines runs a festival's network from one controller. Watch its switches ask it what to do, read and write their flows through its API, then unplug it and see what keeps working.

One flow: when nothing matches, ask
One flow: when nothing matches, ask
Asked once, then forwarded alone
Asked once, then forwarded alone
Two sides of one controller
Two sides of one controller
The highest priority that matches wins
The highest priority that matches wins
Old flows work, new questions go unanswered
Old flows work, new questions go unanswered

Steps

  1. Two switches waiting for orders

    Ines runs the network at Lakeside Festival: three days of music on a lake shore, and a wristband for everyone who gets in. At the gate, a scanner checks wristbands and a kiosk charges phones. Backstage, the tickets server counts each scan, and stagePc runs the lights.

    Two switches join them, gate and backstage, and they aren't like the one under your desk. An ordinary switch works out for itself where to send each frame: which port leads to which MAC address, which links to leave unused. That deciding is its control plane, and moving frames by those decisions is its data plane.

    Here the deciding lives on one server, controller, and the switches only forward. Each one looks up every frame in its flow table, a list of rules the controller writes over OpenFlow: match these fields, then do this.

    Both switches run Open vSwitch, a software switch for Linux that calls each switch a bridge, and each has one, br0. On gate, ovs-vsctl show prints how the bridge is set up, and ovs-ofctl dump-flows br0 prints its flow table. Nobody has used the network yet.

    gate:~# ovs-vsctl show
    gate:~# ovs-ofctl -O OpenFlow13 --names dump-flows br0
  2. The first frame asks the controller

    The scanner is about to check its first wristband, so it needs the tickets server, 10.0.1.30. Before its first ping can leave, it has to learn the server's MAC address, so it sends an ARP request to everyone.

    That frame reaches gate, and only the table-miss flow matches. So gate wraps it in an OpenFlow packet-in message and asks the controller what to do.

    The controller runs os-ken, the maintained fork of the Ryu controller, with its sample learning-switch app: an ordinary switch's job, done from the middle. It notes that the scanner's MAC address lives behind gate's scanner port.

    It doesn't know yet where the server is, so it answers with a packet-out: send this frame out of every other port. At backstage the request misses too, and backstage asks the same question.

    A controller that answered every frame like that would be slow. Ping tickets from the scanner, then print gate's flow table again.

    scanner:~# ping -c 3 10.0.1.30
    gate:~# ovs-ofctl -O OpenFlow13 --names dump-flows br0
  3. Ask the controller, not the switch

    Logging in to each switch to read its flows is fine with two switches. Lakeside's big sister festival has forty, and nobody wants forty logins at 2 a.m.

    That's what a network controller is for: one place that knows every switch, with two sides. Its southbound side talks OpenFlow to the switches, as you saw. Its northbound side faces people and programs: here a REST API on port 8080, served by os-ken's ofctl_rest app.

    Ines works from her laptop, ops, on the management network next to the controller. The API answers in JSON, one long line of it, so Ines saves the answers to files with curl -o and reads them with jq, a command-line tool that picks fields out of JSON.

    Ask the controller which switches it knows: /stats/switches. Then read gate's flows through the API, and the list of its ports.

    ops:~# curl -s http://10.0.9.2:8080/stats/switches
    ops:~# curl -s -o /root/flows.json http://10.0.9.2:8080/stats/flow/1 -o /root/ports.json http://10.0.9.2:8080/stats/portdesc/1
    ops:~# jq -c '.["1"][] | {priority, match, actions}' /root/flows.json
    ops:~# jq -c '.["1"][] | {port_no, name}' /root/ports.json
  4. A rule from the laptop

    Saturday, 11 a.m.: the kiosk vendor's tablet keeps knocking on the ticket server's admin page, and the vendor can't say why. The kiosk has no business with tickets, so Ines wants it kept off for the weekend, without logging in to a switch.

    She writes the rule as JSON on ops, in /root/rules/kiosk.json:

    {
      "dpid": 1,
      "priority": 100,
      "match": { "eth_type": 2048, "ipv4_src": "10.0.1.22", "ipv4_dst": "10.0.1.30" },
      "actions": []
    }
    

    dpid says which switch: 1 is gate, the first switch the kiosk's packets reach, so they stop there. match picks IPv4 packets (eth_type 2048 is 0x0800, IPv4) from the kiosk to tickets. An empty actions list means drop.

    priority 100 puts the rule above the learned flows at 1, since the highest priority that matches wins.

    POST the file to the API's /stats/flowentry/add, then let the kiosk try the ticket server.

    ops:~# curl -si -X POST -d @/root/rules/kiosk.json http://10.0.9.2:8080/stats/flowentry/add
    kiosk:~# curl -sS -m 3 http://10.0.1.30/
    scanner:~# curl -sS -m 3 http://10.0.1.30/
    gate:~# ovs-ofctl -O OpenFlow13 --names dump-flows br0
  5. Unplug the controller

    Saturday, 9 p.m.: the headliner is on, and someone backstage kicks the controller's cable out. Every decision in this network came from that one box, and now nothing answers on 10.0.9.2.

    Two conversations put the network to the test. The scanner has talked to tickets all day, so both switches hold flows for that pair.

    stagePc has never talked to the scanner. Its first frame, an ARP request, will meet only the table-miss flow at backstage, and the table-miss flow says to ask the controller.

    Fetch the ticket page from the scanner, then ping the scanner from stagePc. Keep in mind fail_mode: secure, from the first step: it's what a switch does when its controller is gone.

    scanner:~# curl -sS -m 3 http://10.0.1.30/
    stagePc:~# ping -c 3 10.0.1.21

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab