Wednesday, June 15, 2016

RAUCET - Raspberry Pi + FAUCET, controlling Zodiac FX

In this post, we will set up a Raspberry Pi 3, to control a Zodiac FX (we will cover NFV in the same combination in a future post).




Requirements

  • A Raspberry Pi 3 (a 2 might work) with power supply
  • A Zodiac FX
  • A USB Ethernet adaptor compatible with the Pi (I used a Mac 100M adaptor, but others may work)
You could also manage the Pi over WiFi, and just use the Pi's built in Ethernet to do OpenFlow, if you don't have an adaptor to spare.

Installation

  • Install at least v0.63 firmware on the ZodiacFX (see the ZodiacFX forums for firmware and user manual; you will need a x86 based computer to run the Atmel firmware updater tool, as the tool will not run on the Pi itself).
  • Configure a static IP address, on the Pi's interface that be the OpenFlow control plane network. We will use what the Zodiac FX expects for simplicity. Assuming that the adaptor is eth1, add this to your /etc/network/interfaces on the Pi. 

auto eth1
iface eth1 inet static
  address 10.0.1.8
  netmask 255.255.255.0 
  • Reboot to have the change take effect.
  • Connect cables to the ZodiacFX (as shown), and check that you can ping the Zodiac
ping 10.0.1.99
  • Install FAUCET's dependencies on the Pi.
sudo apt-get install git minicom libpython-dev python-yaml paramiko
sudo pip install ipaddr
sudo pip install --upgrade six
sudo pip install ryu
  • Install FAUCET itself, in /home/pi
git clone https://github.com/REANNZ/faucet
  • Obtain the ZodiacFX's MAC address from the label on the underside. Or, use minicom to obtain the address:
sudo minicom -s
(change serial port to /dev/ttyACM0, under serial port options - check dmesg)
(exit)

Then, via minicom:

config
show config

On my ZodiacFX, I have the following:

Zodiac_FX# config
Zodiac_FX(config)# show config

-------------------------------------------------------------------------
Configuration
 Name: Zodiac_FX
 MAC Address: 70:B3:D5:6C:D0:C0
 IP Address: 10.0.1.99
 Netmask: 255.255.255.0
 Gateway: 10.0.1.1
 OpenFlow Controller: 10.0.1.8
 OpenFlow Port: 6633
 Openflow Status: Enabled
 Failstate: Secure
 Force OpenFlow version: Disabled
 Stacking Select: MASTER
 Stacking Status: Unavailable

-------------------------------------------------------------------------
  • Back on the Pi (quit from minicom with control-A, Q), create a FAUCET config file.
mkdir /home/pi/zodiacfx
vi /home/pi/zodiacfx/faucet.yaml
  • Convert the ZodiacFX MAC address to a FAUCET DPID.  My ZodiacFX's MAC is 70:B3:D5:6C:D0:C0 which is a DPID of0x70b3d56cd0c0 (running all the digits together, removing the ":"s, and prepending 0x).
  • In the faucet.yaml file, add this (replacing dp_id as above), and save and exit.

version: 2
vlans:
    100:

        name: "100"
dps:
    zodiac-fx-1:
        dp_id: 0x70b3d56cd0c0 
        hardware: "ZodiacFX"
        interfaces:
        1:
            native_vlan: 100 
        2:
            native_vlan: 100
        3:
            native_vlan: 100

  • Now start FAUCET itself:

export FAUCET_CONFIG=~/zodiacfx/faucet.yaml
export FAUCET_LOG=~/zodiacfx/faucet.log
export FAUCET_EXCEPTION_LOG=~/zodiacfx/faucet_exception.log
/usr/local/bin/ryu-manager --ofp-listen-host=10.0.1.8 --ofp-tcp-listen-port=6633 ~/faucet/src/ryu_faucet/org/onfsdn/faucet/faucet.py --verbose

If it works, you will see the following. You now have a working FAUCET switch! If you connect hosts to ports 1, 2, or 3 they should be able to reach each other.

loading app /home/pi/faucet/src/ryu_faucet/org/onfsdn/faucet/faucet.py
loading app ryu.controller.ofp_handler
instantiating app None of DPSet
creating context dpset
instantiating app /home/pi/faucet/src/ryu_faucet/org/onfsdn/faucet/faucet.py of Faucet
instantiating app ryu.controller.ofp_handler of OFPHandler
BRICK dpset
  PROVIDES EventDPReconnected TO {'Faucet': set(['dpset'])}
  PROVIDES EventDP TO {'Faucet': set(['dpset'])}
  CONSUMES EventOFPPortStatus
  CONSUMES EventOFPSwitchFeatures
  CONSUMES EventOFPStateChange
BRICK Faucet
  CONSUMES EventOFPPortStatus
  CONSUMES EventOFPSwitchFeatures
  CONSUMES EventFaucetResolveGateways
  CONSUMES EventOFPErrorMsg
  CONSUMES EventFaucetReconfigure
  CONSUMES EventFaucetHostExpire
  CONSUMES EventOFPPacketIn
  CONSUMES EventDPReconnected
  CONSUMES EventDP
BRICK ofp_event
  PROVIDES EventOFPPortStatus TO {'dpset': set(['main']), 'Faucet': set(['main'])}
  PROVIDES EventOFPErrorMsg TO {'Faucet': set(['main'])}
  PROVIDES EventOFPSwitchFeatures TO {'dpset': set(['config']), 'Faucet': set(['config'])}
  PROVIDES EventOFPStateChange TO {'dpset': set(['main', 'dead'])}
  PROVIDES EventOFPPacketIn TO {'Faucet': set(['main'])}
  CONSUMES EventOFPEchoReply
  CONSUMES EventOFPPortStatus
  CONSUMES EventOFPErrorMsg
  CONSUMES EventOFPSwitchFeatures
  CONSUMES EventOFPPortDescStatsReply
  CONSUMES EventOFPHello
  CONSUMES EventOFPEchoRequest
EVENT Faucet->Faucet EventFaucetResolveGateways
EVENT Faucet->Faucet EventFaucetHostExpire
connected socket:<eventlet.greenio.base.GreenSocket object at 0x75cdc210> address:('10.0.1.99', 49946)
hello ev <ryu.controller.ofp_event.EventOFPHello object at 0x75cdc910>
move onto config mode
EVENT ofp_event->dpset EventOFPSwitchFeatures
EVENT ofp_event->Faucet EventOFPSwitchFeatures
switch features ev version=0x4,msg_type=0x6,msg_len=0x20,xid=0x5ce4692f,OFPSwitchFeatures(auxiliary_id=0,capabilities=7,datapath_id=123917682135232L,n_buffers=0,n_tables=10)
move onto main mode
EVENT ofp_event->dpset EventOFPStateChange
DPSET: register datapath <ryu.controller.controller.Datapath object at 0x75cdc510>
EVENT dpset->Faucet EventDP

Adding as a systemd service

Since Raspbian uses systemd, you can write a faucet.service file that causes FAUCET to be automatically run on boot.
  • Create a file /home/pi/zodiacfx/start-faucet.sh, made executable, containing:
#!/bin/bash
export FAUCET_CONFIG=~/zodiacfx/faucet.yaml
export FAUCET_LOG=~/zodiacfx/faucet.log
export FAUCET_EXCEPTION_LOG=~/zodiacfx/faucet_exception.log
/usr/local/bin/ryu-manager --ofp-listen-host=10.0.1.8 --ofp-tcp-listen-port=6633 ~/faucet/src/ryu_faucet/org/onfsdn/faucet/faucet.py --verbose


  • Create a file /etc/systemd/system/faucet.service, containing:
[Unit]
Description=FAUCET

[Service]
User=pi
TimeoutStartSec=0
ExecStart=/home/pi/zodiacfx/start-faucet.sh

[Install]
WantedBy=multi-user.target
  • Enable the service and start it:
sudo systemctl enable /etc/systemd/system/faucet.service
sudo systemctl start faucet.service








No comments:

Post a Comment

Note: Only a member of this blog may post a comment.